|
3 | 3 | * Copyright (c) 2019, The Linaro Limited. All rights reserved. |
4 | 4 | */ |
5 | 5 |
|
| 6 | +#include <dt-bindings/arm/coresight-cti-dt.h> |
6 | 7 | #include <linux/of.h> |
7 | 8 |
|
8 | 9 | #include "coresight-cti.h" |
9 | 10 |
|
| 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 | + |
10 | 208 | /* get the hardware configuration & connection data. */ |
11 | 209 | int cti_plat_get_hw_data(struct device *dev, |
12 | 210 | struct cti_drvdata *drvdata) |
13 | 211 | { |
14 | 212 | int rc = 0; |
15 | 213 | struct cti_device *cti_dev = &drvdata->ctidev; |
16 | 214 |
|
| 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 | + |
17 | 222 | /* if no connections, just add a single default based on max IN-OUT */ |
18 | 223 | if (cti_dev->nr_trig_con == 0) |
19 | 224 | rc = cti_add_default_connection(dev, drvdata); |
|
0 commit comments