--- zzzz-none-000/linux-4.4.271/drivers/hwtracing/coresight/of_coresight.c 2021-06-03 06:22:09.000000000 +0000 +++ hawkeye-5590-750/linux-4.4.271/drivers/hwtracing/coresight/of_coresight.c 2023-04-19 10:22:28.000000000 +0000 @@ -1,4 +1,4 @@ -/* Copyright (c) 2012, The Linux Foundation. All rights reserved. +/* Copyright (c) 2012, 2016 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -58,16 +59,22 @@ { struct device_node *ep = NULL; int in = 0, out = 0; + struct of_endpoint endpoint; do { ep = of_graph_get_next_endpoint(node, ep); if (!ep) break; + if (of_graph_parse_endpoint(ep, &endpoint)) + continue; + if (of_property_read_bool(ep, "slave-mode")) - in++; + in = (endpoint.port + 1 > in) ? + endpoint.port + 1 : in; else - out++; + out = (endpoint.port + 1) > out ? + endpoint.port + 1 : out; } while (ep); @@ -118,8 +125,9 @@ if (!pdata) return ERR_PTR(-ENOMEM); - /* Use device name as sysfs handle */ - pdata->name = dev_name(dev); + ret = of_property_read_string(node, "coresight-name", &pdata->name); + if (ret) + return ERR_PTR(ret); /* Get the number of input and output port for this component */ of_coresight_get_ports(node, &pdata->nr_inport, &pdata->nr_outport); @@ -169,15 +177,19 @@ if (!rdev) continue; - pdata->child_names[i] = dev_name(rdev); + ret = of_property_read_string(rparent, "coresight-name", + &pdata->child_names[i]); + if (ret) + pdata->child_names[i] = dev_name(rdev); + pdata->child_ports[i] = rendpoint.id; i++; } while (ep); } - /* Affinity defaults to CPU0 */ - pdata->cpu = 0; + /* Affinity defaults to -1 (invalid) */ + pdata->cpu = -1; dn = of_parse_phandle(node, "cpu", 0); for (cpu = 0; dn && cpu < nr_cpu_ids; cpu++) { if (dn == of_get_cpu_node(cpu, NULL)) { @@ -189,3 +201,45 @@ return pdata; } EXPORT_SYMBOL_GPL(of_get_coresight_platform_data); + +struct coresight_cti_data *of_get_coresight_cti_data( + struct device *dev, struct device_node *node) +{ + int i, ret; + uint32_t ctis_len; + struct device_node *child_node; + struct coresight_cti_data *ctidata; + + ctidata = devm_kzalloc(dev, sizeof(*ctidata), GFP_KERNEL); + if (!ctidata) + return ERR_PTR(-ENOMEM); + + if (of_get_property(node, "coresight-ctis", &ctis_len)) + ctidata->nr_ctis = ctis_len/sizeof(uint32_t); + else + return ERR_PTR(-EINVAL); + + if (ctidata->nr_ctis) { + ctidata->names = devm_kzalloc(dev, ctidata->nr_ctis * + sizeof(*ctidata->names), + GFP_KERNEL); + if (!ctidata->names) + return ERR_PTR(-ENOMEM); + + for (i = 0; i < ctidata->nr_ctis; i++) { + child_node = of_parse_phandle(node, "coresight-ctis", + i); + if (!child_node) + return ERR_PTR(-EINVAL); + + ret = of_property_read_string(child_node, + "coresight-name", + &ctidata->names[i]); + of_node_put(child_node); + if (ret) + return ERR_PTR(ret); + } + } + return ctidata; +} +EXPORT_SYMBOL(of_get_coresight_cti_data);