Skip to content

Commit a561477

Browse files
mikel-armbbgregkh
authored andcommitted
coresight: cti: Add device tree support for custom CTI
Adds support for CTIs whose connections are implementation defined at hardware design time, and not constrained by v8 architecture. These CTIs have no standard connection setup, all the settings have to be defined in the device tree files. The patch creates a set of connections and trigger signals based on the information provided. 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-8-mathieu.poirier@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cffd054 commit a561477

2 files changed

Lines changed: 241 additions & 4 deletions

File tree

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

Lines changed: 231 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@
1313
#define NR_V8PE_OUT_SIGS 3
1414
#define NR_V8ETM_INOUT_SIGS 4
1515

16+
/* CTI device tree trigger connection node keyword */
17+
#define CTI_DT_CONNS "trig-conns"
18+
1619
/* CTI device tree connection property keywords */
1720
#define CTI_DT_V8ARCH_COMPAT "arm,coresight-cti-v8-arch"
1821
#define CTI_DT_CSDEV_ASSOC "arm,cs-dev-assoc"
22+
#define CTI_DT_TRIGIN_SIGS "arm,trig-in-sigs"
23+
#define CTI_DT_TRIGOUT_SIGS "arm,trig-out-sigs"
24+
#define CTI_DT_TRIGIN_TYPES "arm,trig-in-types"
25+
#define CTI_DT_TRIGOUT_TYPES "arm,trig-out-types"
26+
#define CTI_DT_FILTER_OUT_SIGS "arm,trig-filters"
27+
#define CTI_DT_CONN_NAME "arm,trig-conn-name"
28+
#define CTI_DT_CTM_ID "arm,cti-ctm-id"
1929

2030
#ifdef CONFIG_OF
2131
/*
@@ -87,6 +97,14 @@ cti_plat_get_csdev_or_node_name(struct fwnode_handle *fwnode,
8797
return name;
8898
}
8999

100+
static bool cti_plat_node_name_eq(struct fwnode_handle *fwnode,
101+
const char *name)
102+
{
103+
if (is_of_node(fwnode))
104+
return of_node_name_eq(to_of_node(fwnode), name);
105+
return false;
106+
}
107+
90108
static int cti_plat_create_v8_etm_connection(struct device *dev,
91109
struct cti_drvdata *drvdata)
92110
{
@@ -205,19 +223,228 @@ static int cti_plat_check_v8_arch_compatible(struct device *dev)
205223
return 0;
206224
}
207225

226+
static int cti_plat_count_sig_elements(const struct fwnode_handle *fwnode,
227+
const char *name)
228+
{
229+
int nr_elem = fwnode_property_count_u32(fwnode, name);
230+
231+
return (nr_elem < 0 ? 0 : nr_elem);
232+
}
233+
234+
static int cti_plat_read_trig_group(struct cti_trig_grp *tgrp,
235+
const struct fwnode_handle *fwnode,
236+
const char *grp_name)
237+
{
238+
int idx, err = 0;
239+
u32 *values;
240+
241+
if (!tgrp->nr_sigs)
242+
return 0;
243+
244+
values = kcalloc(tgrp->nr_sigs, sizeof(u32), GFP_KERNEL);
245+
if (!values)
246+
return -ENOMEM;
247+
248+
err = fwnode_property_read_u32_array(fwnode, grp_name,
249+
values, tgrp->nr_sigs);
250+
251+
if (!err) {
252+
/* set the signal usage mask */
253+
for (idx = 0; idx < tgrp->nr_sigs; idx++)
254+
tgrp->used_mask |= BIT(values[idx]);
255+
}
256+
257+
kfree(values);
258+
return err;
259+
}
260+
261+
static int cti_plat_read_trig_types(struct cti_trig_grp *tgrp,
262+
const struct fwnode_handle *fwnode,
263+
const char *type_name)
264+
{
265+
int items, err = 0, nr_sigs;
266+
u32 *values = NULL, i;
267+
268+
/* allocate an array according to number of signals in connection */
269+
nr_sigs = tgrp->nr_sigs;
270+
if (!nr_sigs)
271+
return 0;
272+
273+
/* see if any types have been included in the device description */
274+
items = cti_plat_count_sig_elements(fwnode, type_name);
275+
if (items > nr_sigs)
276+
return -EINVAL;
277+
278+
/* need an array to store the values iff there are any */
279+
if (items) {
280+
values = kcalloc(items, sizeof(u32), GFP_KERNEL);
281+
if (!values)
282+
return -ENOMEM;
283+
284+
err = fwnode_property_read_u32_array(fwnode, type_name,
285+
values, items);
286+
if (err)
287+
goto read_trig_types_out;
288+
}
289+
290+
/*
291+
* Match type id to signal index, 1st type to 1st index etc.
292+
* If fewer types than signals default remainder to GEN_IO.
293+
*/
294+
for (i = 0; i < nr_sigs; i++) {
295+
if (i < items) {
296+
tgrp->sig_types[i] =
297+
values[i] < CTI_TRIG_MAX ? values[i] : GEN_IO;
298+
} else {
299+
tgrp->sig_types[i] = GEN_IO;
300+
}
301+
}
302+
303+
read_trig_types_out:
304+
kfree(values);
305+
return err;
306+
}
307+
308+
static int cti_plat_process_filter_sigs(struct cti_drvdata *drvdata,
309+
const struct fwnode_handle *fwnode)
310+
{
311+
struct cti_trig_grp *tg = NULL;
312+
int err = 0, nr_filter_sigs;
313+
314+
nr_filter_sigs = cti_plat_count_sig_elements(fwnode,
315+
CTI_DT_FILTER_OUT_SIGS);
316+
if (nr_filter_sigs == 0)
317+
return 0;
318+
319+
if (nr_filter_sigs > drvdata->config.nr_trig_max)
320+
return -EINVAL;
321+
322+
tg = kzalloc(sizeof(*tg), GFP_KERNEL);
323+
if (!tg)
324+
return -ENOMEM;
325+
326+
err = cti_plat_read_trig_group(tg, fwnode, CTI_DT_FILTER_OUT_SIGS);
327+
if (!err)
328+
drvdata->config.trig_out_filter |= tg->used_mask;
329+
330+
kfree(tg);
331+
return err;
332+
}
333+
334+
static int cti_plat_create_connection(struct device *dev,
335+
struct cti_drvdata *drvdata,
336+
struct fwnode_handle *fwnode)
337+
{
338+
struct cti_trig_con *tc = NULL;
339+
int cpuid = -1, err = 0;
340+
struct fwnode_handle *cs_fwnode = NULL;
341+
struct coresight_device *csdev = NULL;
342+
const char *assoc_name = "unknown";
343+
char cpu_name_str[16];
344+
int nr_sigs_in, nr_sigs_out;
345+
346+
/* look to see how many in and out signals we have */
347+
nr_sigs_in = cti_plat_count_sig_elements(fwnode, CTI_DT_TRIGIN_SIGS);
348+
nr_sigs_out = cti_plat_count_sig_elements(fwnode, CTI_DT_TRIGOUT_SIGS);
349+
350+
if ((nr_sigs_in > drvdata->config.nr_trig_max) ||
351+
(nr_sigs_out > drvdata->config.nr_trig_max))
352+
return -EINVAL;
353+
354+
tc = cti_allocate_trig_con(dev, nr_sigs_in, nr_sigs_out);
355+
if (!tc)
356+
return -ENOMEM;
357+
358+
/* look for the signals properties. */
359+
err = cti_plat_read_trig_group(tc->con_in, fwnode,
360+
CTI_DT_TRIGIN_SIGS);
361+
if (err)
362+
goto create_con_err;
363+
364+
err = cti_plat_read_trig_types(tc->con_in, fwnode,
365+
CTI_DT_TRIGIN_TYPES);
366+
if (err)
367+
goto create_con_err;
368+
369+
err = cti_plat_read_trig_group(tc->con_out, fwnode,
370+
CTI_DT_TRIGOUT_SIGS);
371+
if (err)
372+
goto create_con_err;
373+
374+
err = cti_plat_read_trig_types(tc->con_out, fwnode,
375+
CTI_DT_TRIGOUT_TYPES);
376+
if (err)
377+
goto create_con_err;
378+
379+
err = cti_plat_process_filter_sigs(drvdata, fwnode);
380+
if (err)
381+
goto create_con_err;
382+
383+
/* read the connection name if set - may be overridden by later */
384+
fwnode_property_read_string(fwnode, CTI_DT_CONN_NAME, &assoc_name);
385+
386+
/* associated cpu ? */
387+
cpuid = cti_plat_get_cpu_at_node(fwnode);
388+
if (cpuid >= 0) {
389+
drvdata->ctidev.cpu = cpuid;
390+
scnprintf(cpu_name_str, sizeof(cpu_name_str), "cpu%d", cpuid);
391+
assoc_name = cpu_name_str;
392+
} else {
393+
/* associated device ? */
394+
cs_fwnode = fwnode_find_reference(fwnode,
395+
CTI_DT_CSDEV_ASSOC, 0);
396+
if (!IS_ERR_OR_NULL(cs_fwnode)) {
397+
assoc_name = cti_plat_get_csdev_or_node_name(cs_fwnode,
398+
&csdev);
399+
fwnode_handle_put(cs_fwnode);
400+
}
401+
}
402+
/* set up a connection */
403+
err = cti_add_connection_entry(dev, drvdata, tc, csdev, assoc_name);
404+
405+
create_con_err:
406+
return err;
407+
}
408+
409+
static int cti_plat_create_impdef_connections(struct device *dev,
410+
struct cti_drvdata *drvdata)
411+
{
412+
int rc = 0;
413+
struct fwnode_handle *fwnode = dev_fwnode(dev);
414+
struct fwnode_handle *child = NULL;
415+
416+
if (IS_ERR_OR_NULL(fwnode))
417+
return -EINVAL;
418+
419+
fwnode_for_each_child_node(fwnode, child) {
420+
if (cti_plat_node_name_eq(child, CTI_DT_CONNS))
421+
rc = cti_plat_create_connection(dev, drvdata,
422+
child);
423+
if (rc != 0)
424+
break;
425+
}
426+
fwnode_handle_put(child);
427+
428+
return rc;
429+
}
430+
208431
/* get the hardware configuration & connection data. */
209432
int cti_plat_get_hw_data(struct device *dev,
210433
struct cti_drvdata *drvdata)
211434
{
212435
int rc = 0;
213436
struct cti_device *cti_dev = &drvdata->ctidev;
214437

438+
/* get any CTM ID - defaults to 0 */
439+
device_property_read_u32(dev, CTI_DT_CTM_ID, &cti_dev->ctm_id);
440+
215441
/* check for a v8 architectural CTI device */
216-
if (cti_plat_check_v8_arch_compatible(dev)) {
442+
if (cti_plat_check_v8_arch_compatible(dev))
217443
rc = cti_plat_create_v8_connections(dev, drvdata);
218-
if (rc)
219-
return rc;
220-
}
444+
else
445+
rc = cti_plat_create_impdef_connections(dev, drvdata);
446+
if (rc)
447+
return rc;
221448

222449
/* if no connections, just add a single default based on max IN-OUT */
223450
if (cti_dev->nr_trig_con == 0)

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,20 @@ static ssize_t powered_show(struct device *dev,
6666
}
6767
static DEVICE_ATTR_RO(powered);
6868

69+
static ssize_t ctmid_show(struct device *dev,
70+
struct device_attribute *attr, char *buf)
71+
{
72+
struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
73+
74+
return sprintf(buf, "%d\n", drvdata->ctidev.ctm_id);
75+
}
76+
static DEVICE_ATTR_RO(ctmid);
77+
6978
/* attribute and group sysfs tables. */
7079
static struct attribute *coresight_cti_attrs[] = {
7180
&dev_attr_enable.attr,
7281
&dev_attr_powered.attr,
82+
&dev_attr_ctmid.attr,
7383
NULL,
7484
};
7585

0 commit comments

Comments
 (0)