/* * Add an entry to the connection list and assign @conn's contents to it. * * If the output port is already assigned on this device, return -EINVAL
*/ struct coresight_connection *
coresight_add_out_conn(struct device *dev, struct coresight_platform_data *pdata, conststruct coresight_connection *new_conn)
{ int i; struct coresight_connection *conn;
/* * Warn on any existing duplicate output port.
*/ for (i = 0; i < pdata->nr_outconns; ++i) {
conn = pdata->out_conns[i]; /* Output == -1 means ignore the port for example for helpers */ if (conn->src_port != -1 &&
conn->src_port == new_conn->src_port) {
dev_warn(dev, "Duplicate output port %d\n",
conn->src_port); return ERR_PTR(-EINVAL);
}
}
conn = devm_kmalloc(dev, sizeof(struct coresight_connection),
GFP_KERNEL); if (!conn) return ERR_PTR(-ENOMEM);
/* * Copy the new connection into the allocation, save the pointer to the * end of the connection array and also return it in case it needs to be * used right away.
*/
*conn = *new_conn;
pdata->out_conns[pdata->nr_outconns - 1] = conn; return conn;
}
EXPORT_SYMBOL_GPL(coresight_add_out_conn);
/* * Add an input connection reference to @out_conn in the target's in_conns array * * @out_conn: Existing output connection to store as an input on the * connection's remote device.
*/ int coresight_add_in_conn(struct coresight_connection *out_conn)
{ int i; struct device *dev = out_conn->dest_dev->dev.parent; struct coresight_platform_data *pdata = out_conn->dest_dev->pdata;
for (i = 0; i < pdata->nr_inconns; ++i) if (!pdata->in_conns[i]) {
pdata->in_conns[i] = out_conn; return 0;
}
/* * If we have a non-configurable replicator, it will be found on the * platform bus.
*/
dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode); if (dev) return dev;
/* * We have a configurable component - circle through the AMBA bus * looking for the device that matches the endpoint node.
*/ return bus_find_device_by_fwnode(&amba_bustype, fwnode);
}
/* * 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.
*/ struct coresight_device *
coresight_find_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;
}
EXPORT_SYMBOL_GPL(coresight_find_csdev_by_fwnode);
/* * Skip one-level up to the real device node, if we * are using the new bindings.
*/ if (of_node_name_eq(parent, "in-ports") ||
of_node_name_eq(parent, "out-ports"))
parent = of_get_next_parent(parent);
staticint of_coresight_get_cpu(struct device *dev)
{ int cpu; struct device_node *dn;
if (!dev->of_node) return -ENODEV;
dn = of_parse_phandle(dev->of_node, "cpu", 0); if (!dn) return -ENODEV;
cpu = of_cpu_node_to_id(dn);
of_node_put(dn);
return cpu;
}
/* * of_coresight_parse_endpoint : Parse the given output endpoint @ep * and fill the connection information in @pdata->out_conns * * Parses the local port, remote device name and the remote port. * * Returns : * 0 - If the parsing completed without any fatal errors. * -Errno - Fatal error, abort the scanning.
*/ staticint of_coresight_parse_endpoint(struct device *dev, struct device_node *ep, struct coresight_platform_data *pdata)
{ int ret = 0; struct of_endpoint endpoint, rendpoint; struct device_node *rparent = NULL; struct device_node *rep = NULL; struct device *rdev = NULL; struct fwnode_handle *rdev_fwnode; struct coresight_connection conn = {}; struct coresight_connection *new_conn;
do { /* Parse the local port details */ if (of_graph_parse_endpoint(ep, &endpoint)) break; /* * Get a handle on the remote endpoint and the device it is * attached to.
*/
rep = of_graph_get_remote_endpoint(ep); if (!rep) break;
rparent = of_coresight_get_port_parent(rep); if (!rparent) break; if (of_graph_parse_endpoint(rep, &rendpoint)) break;
rdev_fwnode = of_fwnode_handle(rparent); /* If the remote device is not available, defer probing */
rdev = coresight_find_device_by_fwnode(rdev_fwnode); if (!rdev) {
ret = -EPROBE_DEFER; break;
}
conn.src_port = endpoint.port; /* * Hold the refcount to the target device. This could be * released via: * 1) coresight_release_platform_data() if the probe fails or * this device is unregistered. * 2) While removing the target device via * coresight_remove_match()
*/
conn.dest_fwnode = fwnode_handle_get(rdev_fwnode);
conn.dest_port = rendpoint.port;
/* * Get the firmware node of the filter source through the * reference. This could be used to filter the source in * building path.
*/
conn.filter_src_fwnode =
fwnode_find_reference(&ep->fwnode, "filter-source", 0); if (IS_ERR(conn.filter_src_fwnode)) {
conn.filter_src_fwnode = NULL;
} else {
conn.filter_src_dev =
coresight_find_csdev_by_fwnode(conn.filter_src_fwnode); if (conn.filter_src_dev &&
!coresight_is_device_source(conn.filter_src_dev)) {
dev_warn(dev, "port %d: Filter handle is not a trace source : %s\n",
conn.src_port, dev_name(&conn.filter_src_dev->dev));
conn.filter_src_dev = NULL;
conn.filter_src_fwnode = NULL;
}
}
new_conn = coresight_add_out_conn(dev, pdata, &conn); if (IS_ERR_VALUE(new_conn)) {
fwnode_handle_put(conn.dest_fwnode); return PTR_ERR(new_conn);
} /* Connection record updated */
} while (0);
parent = of_coresight_get_output_ports_node(node); /* * If the DT uses obsoleted bindings, the ports are listed * under the device and we need to filter out the input * ports.
*/ if (!parent) { /* * Avoid warnings in for_each_endpoint_of_node() * if the device doesn't have any graph connections
*/ if (!of_graph_is_present(node)) return 0;
legacy_binding = true;
parent = node;
dev_warn_once(dev, "Uses obsolete Coresight DT bindings\n");
}
/* Iterate through each output port to discover topology */
for_each_endpoint_of_node(parent, ep) { /* * Legacy binding mixes input/output ports under the * same parent. So, skip the input ports if we are dealing * with legacy binding, as they processed with their * connected output ports.
*/ if (legacy_binding && of_coresight_legacy_ep_is_input(ep)) continue;
ret = of_coresight_parse_endpoint(dev, ep, pdata); if (ret) {
of_node_put(ep); return ret;
}
}
/* * acpi_guid_matches - Checks if the given object is a GUID object and * that it matches the supplied the GUID.
*/ staticbool acpi_guid_matches(constunion acpi_object *obj, const guid_t *guid)
{ return is_acpi_guid(obj) &&
guid_equal((guid_t *)obj->buffer.pointer, guid);
}
if (rev->type != ACPI_TYPE_INTEGER ||
nr_graphs->type != ACPI_TYPE_INTEGER) returnfalse;
/* We only support revision 0 */ if (rev->integer.value != 0) returnfalse;
n = nr_graphs->integer.value; /* CoreSight devices are only part of a single Graph */ if (n != 1) returnfalse;
/* Make sure the ACPI graph package has right number of elements */ if (graph->package.count != (n + 2)) returnfalse;
/* * Each entry must be a graph package with at least 3 members : * { GraphID, UUID, NumberOfLinks(n), Links[.],... }
*/ for (i = 2; i < n + 2; i++) { constunion acpi_object *obj = &graph->package.elements[i];
if (obj->type != ACPI_TYPE_PACKAGE ||
obj->package.count < 3) returnfalse;
}
returntrue;
}
/* acpi_get_dsd_graph - Find the _DSD Graph property for the given device. */ staticconstunion acpi_object *
acpi_get_dsd_graph(struct acpi_device *adev, struct acpi_buffer *buf)
{ int i;
acpi_status status; constunion acpi_object *dsd;
status = acpi_evaluate_object_typed(adev->handle, "_DSD", NULL,
buf, ACPI_TYPE_PACKAGE); if (ACPI_FAILURE(status)) return NULL;
dsd = buf->pointer;
/* * _DSD property consists tuples { Prop_UUID, Package() } * Iterate through all the packages and find the Graph.
*/ for (i = 0; i + 1 < dsd->package.count; i += 2) { constunion acpi_object *guid, *package;
/* All _DSD elements must have a UUID and a Package */ if (!is_acpi_guid(guid) || package->type != ACPI_TYPE_PACKAGE) break; /* Skip the non-Graph _DSD packages */ if (!is_acpi_dsd_graph_guid(guid)) continue; if (acpi_validate_dsd_graph(package)) return package; /* Invalid graph format, continue */
dev_warn(&adev->dev, "Invalid Graph _DSD property\n");
}
return NULL;
}
staticbool
acpi_validate_coresight_graph(constunion acpi_object *cs_graph)
{ int nlinks;
nlinks = cs_graph->package.elements[2].integer.value; /* * Graph must have the following fields : * { GraphID, GraphUUID, NumberOfLinks, Links... }
*/ if (cs_graph->package.count != (nlinks + 3)) returnfalse; /* The links are validated in acpi_coresight_parse_link() */ returntrue;
}
/* * acpi_get_coresight_graph - Parse the device _DSD tables and find * the Graph property matching the CoreSight Graphs. * * Returns the pointer to the CoreSight Graph Package when found. Otherwise * returns NULL.
*/ staticconstunion acpi_object *
acpi_get_coresight_graph(struct acpi_device *adev, struct acpi_buffer *buf)
{ constunion acpi_object *graph_list, *graph; int i, nr_graphs;
graph_list = acpi_get_dsd_graph(adev, buf); if (!graph_list) return graph_list;
for (i = 2; i < nr_graphs + 2; i++) {
graph = &graph_list->package.elements[i]; if (!is_acpi_coresight_graph(graph)) continue; if (acpi_validate_coresight_graph(graph)) return graph; /* Invalid graph format */ break;
}
return NULL;
}
/* * acpi_coresight_parse_link - Parse the given Graph connection * of the device and populate the coresight_connection for an output * connection. * * CoreSight Graph specification mandates that the direction of the data * flow must be specified in the link. i.e, * * SourcePortAddress, // Integer * DestinationPortAddress, // Integer * DestinationDeviceName, // Reference to another device * DirectionOfFlow, // 1 for output(master), 0 for input(slave) * * Returns the direction of the data flow [ Input(slave) or Output(master) ] * upon success. * Returns an negative error number otherwise.
*/ staticint acpi_coresight_parse_link(struct acpi_device *adev, constunion acpi_object *link, struct coresight_connection *conn)
{ int dir; constunion acpi_object *fields; struct acpi_device *r_adev; struct device *rdev;
if (link->type != ACPI_TYPE_PACKAGE ||
link->package.count != 4) return -EINVAL;
r_adev = acpi_fetch_acpi_dev(fields[2].reference.handle); if (!r_adev) return -ENODEV;
dir = fields[3].integer.value; if (dir == ACPI_CORESIGHT_LINK_MASTER) {
conn->src_port = fields[0].integer.value;
conn->dest_port = fields[1].integer.value;
rdev = coresight_find_device_by_fwnode(&r_adev->fwnode); if (!rdev) return -EPROBE_DEFER; /* * Hold the refcount to the target device. This could be * released via: * 1) coresight_release_platform_data() if the probe fails or * this device is unregistered. * 2) While removing the target device via * coresight_remove_match().
*/
conn->dest_fwnode = fwnode_handle_get(&r_adev->fwnode);
} elseif (dir == ACPI_CORESIGHT_LINK_SLAVE) { /* * We are only interested in the port number * for the input ports at this component. * Store the port number in child_port.
*/
conn->dest_port = fields[0].integer.value;
} else { /* Invalid direction */ return -EINVAL;
}
return dir;
}
/* * acpi_coresight_parse_graph - Parse the _DSD CoreSight graph * connection information and populate the supplied coresight_platform_data * instance.
*/ staticint acpi_coresight_parse_graph(struct device *dev, struct acpi_device *adev, struct coresight_platform_data *pdata)
{ int ret = 0; int i, nlinks; constunion acpi_object *graph; struct coresight_connection conn, zero_conn = {}; struct coresight_connection *new_conn; struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
graph = acpi_get_coresight_graph(adev, &buf); /* * There are no graph connections, which is fine for some components. * e.g., ETE
*/ if (!graph) goto free;
nlinks = graph->package.elements[2].integer.value; if (!nlinks) goto free;
for (i = 0; i < nlinks; i++) { constunion acpi_object *link = &graph->package.elements[3 + i]; int dir;
conn = zero_conn;
dir = acpi_coresight_parse_link(adev, link, &conn); if (dir < 0) {
ret = dir; goto free;
}
if (dir == ACPI_CORESIGHT_LINK_MASTER) {
new_conn = coresight_add_out_conn(dev, pdata, &conn); if (IS_ERR(new_conn)) {
ret = PTR_ERR(new_conn); goto free;
}
}
}
free: /* * When ACPI fails to alloc a buffer, it will free the buffer * created via ACPI_ALLOCATE_BUFFER and set to NULL. * ACPI_FREE can handle NULL pointers, so free it directly.
*/
ACPI_FREE(buf.pointer); return ret;
}
/* * acpi_handle_to_logical_cpuid - Map a given acpi_handle to the * logical CPU id of the corresponding CPU device. * * Returns the logical CPU id when found. Otherwise returns >= nr_cpus_id.
*/ staticint
acpi_handle_to_logical_cpuid(acpi_handle handle)
{ int i; struct acpi_processor *pr;
/* * acpi_coresigh_get_cpu - Find the logical CPU id of the CPU associated * with this coresight device. With ACPI bindings, the CoreSight components * are listed as child device of the associated CPU. * * Returns the logical CPU id when found. Otherwise returns 0.
*/ staticint acpi_coresight_get_cpu(struct device *dev)
{ int cpu;
acpi_handle cpu_handle;
acpi_status status; struct acpi_device *adev = ACPI_COMPANION(dev);
if (!adev) return -ENODEV;
status = acpi_get_parent(adev->handle, &cpu_handle); if (ACPI_FAILURE(status)) return -ENODEV;
cpu = acpi_handle_to_logical_cpuid(cpu_handle); if (cpu >= nr_cpu_ids) return -ENODEV; return cpu;
}
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) {
ret = -ENOMEM; goto error;
}
if (is_of_node(fwnode))
ret = of_get_coresight_platform_data(dev, pdata); elseif (is_acpi_device_node(fwnode))
ret = acpi_get_coresight_platform_data(dev, pdata);
if (!ret) return pdata;
error: if (!IS_ERR_OR_NULL(pdata)) /* Cleanup the connection information */
coresight_release_platform_data(NULL, dev, pdata); return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(coresight_get_platform_data);
Messung V0.5
¤ Dauer der Verarbeitung: 0.3 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.