Skip to content

Commit cffd054

Browse files
mikel-armbbgregkh
authored andcommitted
coresight: cti: Add device tree support for v8 arch CTI
The v8 architecture defines the relationship between a PE, its optional ETM and a CTI. Unlike non-architectural CTIs which are implementation defined, this has a fixed set of connections which can therefore be represented as a simple tag in the device tree. This patch defines the tags needed to create an entry for this PE/ETM/CTI relationship, and provides functionality to implement the connection model in the CTI driver. Signed-off-by: Mike Leach <mike.leach@linaro.org> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Link: https://lore.kernel.org/r/20200320165303.13681-7-mathieu.poirier@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b39b46f commit cffd054

4 files changed

Lines changed: 230 additions & 9 deletions

File tree

‎drivers/hwtracing/coresight/coresight-cti-platform.c‎

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,222 @@
33
* Copyright (c) 2019, The Linaro Limited. All rights reserved.
44
*/
55

6+
#include <dt-bindings/arm/coresight-cti-dt.h>
67
#include <linux/of.h>
78

89
#include "coresight-cti.h"
910

11+
/* Number of CTI signals in the v8 architecturally defined connection */
12+
#define NR_V8PE_IN_SIGS 2
13+
#define NR_V8PE_OUT_SIGS 3
14+
#define NR_V8ETM_INOUT_SIGS 4
15+
16+
/* CTI device tree connection property keywords */
17+
#define CTI_DT_V8ARCH_COMPAT "arm,coresight-cti-v8-arch"
18+
#define CTI_DT_CSDEV_ASSOC "arm,cs-dev-assoc"
19+
20+
#ifdef CONFIG_OF
21+
/*
22+
* CTI can be bound to a CPU, or a system device.
23+
* CPU can be declared at the device top level or in a connections node
24+
* so need to check relative to node not device.
25+
*/
26+
static int of_cti_get_cpu_at_node(const struct device_node *node)
27+
{
28+
int cpu;
29+
struct device_node *dn;
30+
31+
if (node == NULL)
32+
return -1;
33+
34+
dn = of_parse_phandle(node, "cpu", 0);
35+
/* CTI affinity defaults to no cpu */
36+
if (!dn)
37+
return -1;
38+
cpu = of_cpu_node_to_id(dn);
39+
of_node_put(dn);
40+
41+
/* No Affinity if no cpu nodes are found */
42+
return (cpu < 0) ? -1 : cpu;
43+
}
44+
45+
#else
46+
static int of_cti_get_cpu_at_node(const struct device_node *node)
47+
{
48+
return -1;
49+
}
50+
51+
#endif
52+
53+
/*
54+
* CTI can be bound to a CPU, or a system device.
55+
* CPU can be declared at the device top level or in a connections node
56+
* so need to check relative to node not device.
57+
*/
58+
static int cti_plat_get_cpu_at_node(struct fwnode_handle *fwnode)
59+
{
60+
if (is_of_node(fwnode))
61+
return of_cti_get_cpu_at_node(to_of_node(fwnode));
62+
return -1;
63+
}
64+
65+
const char *cti_plat_get_node_name(struct fwnode_handle *fwnode)
66+
{
67+
if (is_of_node(fwnode))
68+
return of_node_full_name(to_of_node(fwnode));
69+
return "unknown";
70+
}
71+
72+
/*
73+
* Extract a name from the fwnode.
74+
* If the device associated with the node is a coresight_device, then return
75+
* that name and the coresight_device pointer, otherwise return the node name.
76+
*/
77+
static const char *
78+
cti_plat_get_csdev_or_node_name(struct fwnode_handle *fwnode,
79+
struct coresight_device **csdev)
80+
{
81+
const char *name = NULL;
82+
*csdev = coresight_find_csdev_by_fwnode(fwnode);
83+
if (*csdev)
84+
name = dev_name(&(*csdev)->dev);
85+
else
86+
name = cti_plat_get_node_name(fwnode);
87+
return name;
88+
}
89+
90+
static int cti_plat_create_v8_etm_connection(struct device *dev,
91+
struct cti_drvdata *drvdata)
92+
{
93+
int ret = -ENOMEM, i;
94+
struct fwnode_handle *root_fwnode, *cs_fwnode;
95+
const char *assoc_name = NULL;
96+
struct coresight_device *csdev;
97+
struct cti_trig_con *tc = NULL;
98+
99+
root_fwnode = dev_fwnode(dev);
100+
if (IS_ERR_OR_NULL(root_fwnode))
101+
return -EINVAL;
102+
103+
/* Can optionally have an etm node - return if not */
104+
cs_fwnode = fwnode_find_reference(root_fwnode, CTI_DT_CSDEV_ASSOC, 0);
105+
if (IS_ERR_OR_NULL(cs_fwnode))
106+
return 0;
107+
108+
/* allocate memory */
109+
tc = cti_allocate_trig_con(dev, NR_V8ETM_INOUT_SIGS,
110+
NR_V8ETM_INOUT_SIGS);
111+
if (!tc)
112+
goto create_v8_etm_out;
113+
114+
/* build connection data */
115+
tc->con_in->used_mask = 0xF0; /* sigs <4,5,6,7> */
116+
tc->con_out->used_mask = 0xF0; /* sigs <4,5,6,7> */
117+
118+
/*
119+
* The EXTOUT type signals from the ETM are connected to a set of input
120+
* triggers on the CTI, the EXTIN being connected to output triggers.
121+
*/
122+
for (i = 0; i < NR_V8ETM_INOUT_SIGS; i++) {
123+
tc->con_in->sig_types[i] = ETM_EXTOUT;
124+
tc->con_out->sig_types[i] = ETM_EXTIN;
125+
}
126+
127+
/*
128+
* We look to see if the ETM coresight device associated with this
129+
* handle has been registered with the system - i.e. probed before
130+
* this CTI. If so csdev will be non NULL and we can use the device
131+
* name and pass the csdev to the connection entry function where
132+
* the association will be recorded.
133+
* If not, then simply record the name in the connection data, the
134+
* probing of the ETM will call into the CTI driver API to update the
135+
* association then.
136+
*/
137+
assoc_name = cti_plat_get_csdev_or_node_name(cs_fwnode, &csdev);
138+
ret = cti_add_connection_entry(dev, drvdata, tc, csdev, assoc_name);
139+
140+
create_v8_etm_out:
141+
fwnode_handle_put(cs_fwnode);
142+
return ret;
143+
}
144+
145+
/*
146+
* Create an architecturally defined v8 connection
147+
* must have a cpu, can have an ETM.
148+
*/
149+
static int cti_plat_create_v8_connections(struct device *dev,
150+
struct cti_drvdata *drvdata)
151+
{
152+
struct cti_device *cti_dev = &drvdata->ctidev;
153+
struct cti_trig_con *tc = NULL;
154+
int cpuid = 0;
155+
char cpu_name_str[16];
156+
int ret = -ENOMEM;
157+
158+
/* Must have a cpu node */
159+
cpuid = cti_plat_get_cpu_at_node(dev_fwnode(dev));
160+
if (cpuid < 0) {
161+
dev_warn(dev,
162+
"ARM v8 architectural CTI connection: missing cpu\n");
163+
return -EINVAL;
164+
}
165+
cti_dev->cpu = cpuid;
166+
167+
/* Allocate the v8 cpu connection memory */
168+
tc = cti_allocate_trig_con(dev, NR_V8PE_IN_SIGS, NR_V8PE_OUT_SIGS);
169+
if (!tc)
170+
goto of_create_v8_out;
171+
172+
/* Set the v8 PE CTI connection data */
173+
tc->con_in->used_mask = 0x3; /* sigs <0 1> */
174+
tc->con_in->sig_types[0] = PE_DBGTRIGGER;
175+
tc->con_in->sig_types[1] = PE_PMUIRQ;
176+
tc->con_out->used_mask = 0x7; /* sigs <0 1 2 > */
177+
tc->con_out->sig_types[0] = PE_EDBGREQ;
178+
tc->con_out->sig_types[1] = PE_DBGRESTART;
179+
tc->con_out->sig_types[2] = PE_CTIIRQ;
180+
scnprintf(cpu_name_str, sizeof(cpu_name_str), "cpu%d", cpuid);
181+
182+
ret = cti_add_connection_entry(dev, drvdata, tc, NULL, cpu_name_str);
183+
if (ret)
184+
goto of_create_v8_out;
185+
186+
/* Create the v8 ETM associated connection */
187+
ret = cti_plat_create_v8_etm_connection(dev, drvdata);
188+
if (ret)
189+
goto of_create_v8_out;
190+
191+
/* filter pe_edbgreq - PE trigout sig <0> */
192+
drvdata->config.trig_out_filter |= 0x1;
193+
194+
of_create_v8_out:
195+
return ret;
196+
}
197+
198+
static int cti_plat_check_v8_arch_compatible(struct device *dev)
199+
{
200+
struct fwnode_handle *fwnode = dev_fwnode(dev);
201+
202+
if (is_of_node(fwnode))
203+
return of_device_is_compatible(to_of_node(fwnode),
204+
CTI_DT_V8ARCH_COMPAT);
205+
return 0;
206+
}
207+
10208
/* get the hardware configuration & connection data. */
11209
int cti_plat_get_hw_data(struct device *dev,
12210
struct cti_drvdata *drvdata)
13211
{
14212
int rc = 0;
15213
struct cti_device *cti_dev = &drvdata->ctidev;
16214

215+
/* check for a v8 architectural CTI device */
216+
if (cti_plat_check_v8_arch_compatible(dev)) {
217+
rc = cti_plat_create_v8_connections(dev, drvdata);
218+
if (rc)
219+
return rc;
220+
}
221+
17222
/* if no connections, just add a single default based on max IN-OUT */
18223
if (cti_dev->nr_trig_con == 0)
19224
rc = cti_add_default_connection(dev, drvdata);

‎drivers/hwtracing/coresight/coresight-platform.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
5757
return bus_find_device_by_fwnode(&amba_bustype, fwnode);
5858
}
5959

60+
/*
61+
* Find a registered coresight device from a device fwnode.
62+
* The node info is associated with the AMBA parent, but the
63+
* csdev keeps a copy so iterate round the coresight bus to
64+
* find the device.
65+
*/
66+
struct coresight_device *
67+
coresight_find_csdev_by_fwnode(struct fwnode_handle *r_fwnode)
68+
{
69+
struct device *dev;
70+
struct coresight_device *csdev = NULL;
71+
72+
dev = bus_find_device_by_fwnode(&coresight_bustype, r_fwnode);
73+
if (dev) {
74+
csdev = to_coresight_device(dev);
75+
put_device(dev);
76+
}
77+
return csdev;
78+
}
79+
6080
#ifdef CONFIG_OF
6181
static inline bool of_coresight_legacy_ep_is_input(struct device_node *ep)
6282
{

‎drivers/hwtracing/coresight/coresight-priv.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,7 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
202202
}
203203

204204
void coresight_release_platform_data(struct coresight_platform_data *pdata);
205+
struct coresight_device *
206+
coresight_find_csdev_by_fwnode(struct fwnode_handle *r_fwnode);
205207

206208
#endif

‎drivers/hwtracing/coresight/coresight.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,17 +1030,11 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
10301030

10311031
for (i = 0; i < csdev->pdata->nr_outport; i++) {
10321032
struct coresight_connection *conn = &csdev->pdata->conns[i];
1033-
struct device *dev = NULL;
10341033

1035-
dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode);
1036-
if (dev) {
1037-
conn->child_dev = to_coresight_device(dev);
1038-
/* and put reference from 'bus_find_device()' */
1039-
put_device(dev);
1040-
} else {
1034+
conn->child_dev =
1035+
coresight_find_csdev_by_fwnode(conn->child_fwnode);
1036+
if (!conn->child_dev)
10411037
csdev->orphan = true;
1042-
conn->child_dev = NULL;
1043-
}
10441038
}
10451039
}
10461040

0 commit comments

Comments
 (0)