Hi Mathieu,
New patch has extended comments per your suggestion. As mentioned - this patch and the next re-written to maximise use of fwnode functionality.
Thanks
Mike
On Tue, 1 Oct 2019 at 20:47, Mathieu Poirier mathieu.poirier@linaro.org wrote:
On Mon, Aug 19, 2019 at 10:13:52PM +0100, Mike Leach wrote:
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
.../coresight/coresight-cti-platform.c | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+)
diff --git a/drivers/hwtracing/coresight/coresight-cti-platform.c b/drivers/hwtracing/coresight/coresight-cti-platform.c index eb4f8a835c10..3ee5b8f8d245 100644 --- a/drivers/hwtracing/coresight/coresight-cti-platform.c +++ b/drivers/hwtracing/coresight/coresight-cti-platform.c @@ -3,11 +3,159 @@
- Copyright (c) 2019, The Linux Foundation. All rights reserved.
*/
+#include <dt-bindings/arm/coresight-cti-dt.h> #include <linux/of.h>
#include "coresight-cti.h"
+/* Number of CTI signals in the v8 architecturally defined connection */ +#define NR_V8PE_IN_SIGS 2 +#define NR_V8PE_OUT_SIGS 3 +#define NR_V8ETM_INOUT_SIGS 4
+/* CTI device tree connection property keywords */ +#define CTI_DT_V8ARCH "arm,cti-v8-arch" +#define CTI_DT_CSDEV_ASSOC "arm,cs-dev-assoc"
+/*
- Find a registered coresight device from a device fwnode.
- The node info is associated with the AMBA parent, but the
- csdev keeps a copy so iterate round the coresight bus to
- find the device.
- */
+static struct coresight_device * +cti_get_assoc_csdev_by_fwnode(struct fwnode_handle *r_fwnode) +{
struct device *dev;struct coresight_device *csdev = NULL;dev = bus_find_device_by_fwnode(&coresight_bustype, r_fwnode);if (dev) {csdev = to_coresight_device(dev);put_device(dev);}return csdev;+}
#ifdef CONFIG_OF +/*
- CTI can be bound to a CPU, or a system device.
- CPU can be declared at the device top level or in a connections node
- so need to check relative to node not device.
- */
+static int of_cti_get_cpu_at_node(const struct device_node *node) +{
int cpu;struct device_node *dn;dn = of_parse_phandle(node, "cpu", 0);/* CTI affinity defaults to no cpu */if (!dn)return -1;cpu = of_cpu_node_to_id(dn);of_node_put(dn);/* No Affinity if no cpu nodes are found */return (cpu < 0) ? -1 : cpu;+}
+static int of_cti_create_v8_etm_connection(struct device *dev,
struct cti_drvdata *drvdata,struct device_node *np)+{
int ret = -ENOMEM, i;struct device_node *cs_np;const char *assoc_name = NULL;struct coresight_device *csdev;struct fwnode_handle *r_fwnode;struct cti_trig_con *tc = NULL;/* Can optionally have an etm node - return if not */cs_np = of_parse_phandle(np, CTI_DT_CSDEV_ASSOC, 0);extra space after "np,"
if (!cs_np)return 0;/* allocate memory */tc = cti_allocate_trig_con(dev, NR_V8ETM_INOUT_SIGS,NR_V8ETM_INOUT_SIGS);if (!tc)goto of_create_v8_etm_out;/* build connection data */tc->con_in->used_mask = 0xF0; /* sigs <4,5,6,7> */tc->con_out->used_mask = 0xF0; /* sigs <4,5,6,7> */for (i = 0; i < NR_V8ETM_INOUT_SIGS; i++) {tc->con_in->sig_types[i] = ETM_EXTOUT;tc->con_out->sig_types[i] = ETM_EXTIN;}So far I understand that connection names (and the processing going with them) has been centered on the CTI itself. Either the above is a mistake and should read: tc->con_in->sig_types[i] = ETM_EXTIN; tc->con_out->sig_types[i] = ETM_EXTOUT;
or the logic is that ETM_EXTOUT becomes an input for the CTI. If so please add a comment to make it clear that a CTI IN is an ETM OUT and vice versa. Otherwise I can already see patches to correct the "bug" accumulating in my inbox.
r_fwnode = of_fwnode_handle(cs_np);csdev = cti_get_assoc_csdev_by_fwnode(r_fwnode);if (csdev)assoc_name = dev_name(&csdev->dev);elseassoc_name = cs_np->full_name;I understand what is happening here only because I am familiar with CS and the chicken-and-egg conundrum inherent to device discovery. Please add a comment describing what is happening and exactly where, i.e function name, things are fixed in the future.
ret = cti_add_connection_entry(dev, drvdata, tc, csdev, assoc_name);+of_create_v8_etm_out:
of_node_put(cs_np);return ret;+}
+/*
- Create an architecturally defined v8 connection
- must have a cpu, can have an ETM.
- */
+static int of_cti_create_v8_connections(struct device *dev,
struct cti_drvdata *drvdata,struct device_node *np)+{
struct cti_device *cti_dev = &drvdata->ctidev;struct cti_trig_con *tc = NULL;int cpuid = 0;char cpu_name_str[16];int ret = -ENOMEM;/* Must have a cpu node */cpuid = of_cti_get_cpu_at_node(np);if (cpuid < 0) {dev_warn(dev, "CTI v8 DT binding no cpu\n");return -EINVAL;}cti_dev->cpu = cpuid;/* Allocate the v8 cpu connection memory */tc = cti_allocate_trig_con(dev, NR_V8PE_IN_SIGS, NR_V8PE_OUT_SIGS);if (!tc)goto of_create_v8_out;/* Set the v8 PE CTI connection data */tc->con_in->used_mask = 0x3; /* sigs <0 1> */tc->con_in->sig_types[0] = PE_DBGTRIGGER;tc->con_in->sig_types[1] = PE_PMUIRQ;tc->con_out->used_mask = 0x7; /* sigs <0 1 2 > */tc->con_out->sig_types[0] = PE_EDBGREQ;tc->con_out->sig_types[1] = PE_DBGRESTART;tc->con_out->sig_types[2] = PE_CTIIRQ;scnprintf(cpu_name_str, sizeof(cpu_name_str), "cpu%d", cpuid);ret = cti_add_connection_entry(dev, drvdata, tc, NULL, cpu_name_str);if (ret)goto of_create_v8_out;/* Create the v8 ETM associated connection */ret = of_cti_create_v8_etm_connection(dev, drvdata, np);if (ret)goto of_create_v8_out;/* filter pe_edbgreq - PE trigout sig <0> */drvdata->config.trig_out_filter |= 0x1;+of_create_v8_out:
return ret;+}
/* get the hardware configuration & connection data. */ int of_cti_get_hw_data(struct device *dev, struct device_node *np, @@ -16,6 +164,13 @@ int of_cti_get_hw_data(struct device *dev, int rc = 0; struct cti_device *cti_dev = &drvdata->ctidev;
/* check for a v8 architectural CTI device */if (of_property_read_bool(np, CTI_DT_V8ARCH)) {rc = of_cti_create_v8_connections(dev, drvdata, np);Please refer to the new comment I posted in patch 01 about making functions generic to lessen the burden of adding ACPI support.
Thanks, Mathieu
if (rc)return rc;}/* if no connections, just add a single default based on max IN-OUT */ if (cti_dev->nr_trig_con == 0) rc = cti_add_default_connection(dev, drvdata);-- 2.17.1
-- Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK