coresight: platform: Cleanup coresight connection handling
The platform code parses the component connections and populates a platform-description of the output connections in arrays of fields (which is never freed). This is later copied in the coresight_register to a newly allocated area, represented by coresight_connection(s). This patch cleans up the code dealing with connections by making use of the "coresight_connection" structure right at the platform code and lets the generic driver simply re-use information provided by the platform. Thus making it reader friendly as well as avoiding the wastage of unused memory. Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
2058224f54
commit
c2c729415b
|
@ -995,13 +995,11 @@ postcore_initcall(coresight_init);
|
||||||
|
|
||||||
struct coresight_device *coresight_register(struct coresight_desc *desc)
|
struct coresight_device *coresight_register(struct coresight_desc *desc)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int ret;
|
int ret;
|
||||||
int link_subtype;
|
int link_subtype;
|
||||||
int nr_refcnts = 1;
|
int nr_refcnts = 1;
|
||||||
atomic_t *refcnts = NULL;
|
atomic_t *refcnts = NULL;
|
||||||
struct coresight_device *csdev;
|
struct coresight_device *csdev;
|
||||||
struct coresight_connection *conns = NULL;
|
|
||||||
|
|
||||||
csdev = kzalloc(sizeof(*csdev), GFP_KERNEL);
|
csdev = kzalloc(sizeof(*csdev), GFP_KERNEL);
|
||||||
if (!csdev) {
|
if (!csdev) {
|
||||||
|
@ -1030,22 +1028,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
|
||||||
csdev->nr_inport = desc->pdata->nr_inport;
|
csdev->nr_inport = desc->pdata->nr_inport;
|
||||||
csdev->nr_outport = desc->pdata->nr_outport;
|
csdev->nr_outport = desc->pdata->nr_outport;
|
||||||
|
|
||||||
/* Initialise connections if there is at least one outport */
|
csdev->conns = desc->pdata->conns;
|
||||||
if (csdev->nr_outport) {
|
|
||||||
conns = kcalloc(csdev->nr_outport, sizeof(*conns), GFP_KERNEL);
|
|
||||||
if (!conns) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto err_free_refcnts;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < csdev->nr_outport; i++) {
|
|
||||||
conns[i].outport = desc->pdata->outports[i];
|
|
||||||
conns[i].child_name = desc->pdata->child_names[i];
|
|
||||||
conns[i].child_port = desc->pdata->child_ports[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
csdev->conns = conns;
|
|
||||||
|
|
||||||
csdev->type = desc->type;
|
csdev->type = desc->type;
|
||||||
csdev->subtype = desc->subtype;
|
csdev->subtype = desc->subtype;
|
||||||
|
@ -1078,8 +1061,6 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
|
||||||
|
|
||||||
return csdev;
|
return csdev;
|
||||||
|
|
||||||
err_free_refcnts:
|
|
||||||
kfree(refcnts);
|
|
||||||
err_free_csdev:
|
err_free_csdev:
|
||||||
kfree(csdev);
|
kfree(csdev);
|
||||||
err_out:
|
err_out:
|
||||||
|
|
|
@ -75,29 +75,13 @@ static void of_coresight_get_ports(const struct device_node *node,
|
||||||
static int of_coresight_alloc_memory(struct device *dev,
|
static int of_coresight_alloc_memory(struct device *dev,
|
||||||
struct coresight_platform_data *pdata)
|
struct coresight_platform_data *pdata)
|
||||||
{
|
{
|
||||||
/* List of output port on this component */
|
if (pdata->nr_outport) {
|
||||||
pdata->outports = devm_kcalloc(dev,
|
pdata->conns = devm_kzalloc(dev, pdata->nr_outport *
|
||||||
pdata->nr_outport,
|
sizeof(*pdata->conns),
|
||||||
sizeof(*pdata->outports),
|
GFP_KERNEL);
|
||||||
GFP_KERNEL);
|
if (!pdata->conns)
|
||||||
if (!pdata->outports)
|
return -ENOMEM;
|
||||||
return -ENOMEM;
|
}
|
||||||
|
|
||||||
/* Children connected to this component via @outports */
|
|
||||||
pdata->child_names = devm_kcalloc(dev,
|
|
||||||
pdata->nr_outport,
|
|
||||||
sizeof(*pdata->child_names),
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (!pdata->child_names)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
/* Port number on the child this component is connected to */
|
|
||||||
pdata->child_ports = devm_kcalloc(dev,
|
|
||||||
pdata->nr_outport,
|
|
||||||
sizeof(*pdata->child_ports),
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (!pdata->child_ports)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -121,7 +105,7 @@ EXPORT_SYMBOL_GPL(of_coresight_get_cpu);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* of_coresight_parse_endpoint : Parse the given output endpoint @ep
|
* of_coresight_parse_endpoint : Parse the given output endpoint @ep
|
||||||
* and fill the connection information in @pdata[@i].
|
* and fill the connection information in @conn
|
||||||
*
|
*
|
||||||
* Parses the local port, remote device name and the remote port.
|
* Parses the local port, remote device name and the remote port.
|
||||||
*
|
*
|
||||||
|
@ -133,8 +117,7 @@ EXPORT_SYMBOL_GPL(of_coresight_get_cpu);
|
||||||
*/
|
*/
|
||||||
static int of_coresight_parse_endpoint(struct device *dev,
|
static int of_coresight_parse_endpoint(struct device *dev,
|
||||||
struct device_node *ep,
|
struct device_node *ep,
|
||||||
struct coresight_platform_data *pdata,
|
struct coresight_connection *conn)
|
||||||
int i)
|
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct of_endpoint endpoint, rendpoint;
|
struct of_endpoint endpoint, rendpoint;
|
||||||
|
@ -166,11 +149,11 @@ static int of_coresight_parse_endpoint(struct device *dev,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdata->outports[i] = endpoint.port;
|
conn->outport = endpoint.port;
|
||||||
pdata->child_names[i] = devm_kstrdup(dev,
|
conn->child_name = devm_kstrdup(dev,
|
||||||
dev_name(rdev),
|
dev_name(rdev),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
pdata->child_ports[i] = rendpoint.port;
|
conn->child_port = rendpoint.port;
|
||||||
/* Connection record updated */
|
/* Connection record updated */
|
||||||
ret = 1;
|
ret = 1;
|
||||||
} while (0);
|
} while (0);
|
||||||
|
@ -189,8 +172,9 @@ struct coresight_platform_data *
|
||||||
of_get_coresight_platform_data(struct device *dev,
|
of_get_coresight_platform_data(struct device *dev,
|
||||||
const struct device_node *node)
|
const struct device_node *node)
|
||||||
{
|
{
|
||||||
int i = 0, ret = 0;
|
int ret = 0;
|
||||||
struct coresight_platform_data *pdata;
|
struct coresight_platform_data *pdata;
|
||||||
|
struct coresight_connection *conn;
|
||||||
struct device_node *ep = NULL;
|
struct device_node *ep = NULL;
|
||||||
|
|
||||||
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
|
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
|
||||||
|
@ -212,6 +196,7 @@ of_get_coresight_platform_data(struct device *dev,
|
||||||
if (ret)
|
if (ret)
|
||||||
return ERR_PTR(ret);
|
return ERR_PTR(ret);
|
||||||
|
|
||||||
|
conn = pdata->conns;
|
||||||
/* Iterate through each port to discover topology */
|
/* Iterate through each port to discover topology */
|
||||||
while ((ep = of_graph_get_next_endpoint(node, ep))) {
|
while ((ep = of_graph_get_next_endpoint(node, ep))) {
|
||||||
/*
|
/*
|
||||||
|
@ -221,10 +206,10 @@ of_get_coresight_platform_data(struct device *dev,
|
||||||
if (of_coresight_ep_is_input(ep))
|
if (of_coresight_ep_is_input(ep))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ret = of_coresight_parse_endpoint(dev, ep, pdata, i);
|
ret = of_coresight_parse_endpoint(dev, ep, conn);
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case 1:
|
case 1:
|
||||||
i++; /* Fall through */
|
conn++; /* Fall through */
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -94,20 +94,15 @@ union coresight_dev_subtype {
|
||||||
* @cpu: the CPU a source belongs to. Only applicable for ETM/PTMs.
|
* @cpu: the CPU a source belongs to. Only applicable for ETM/PTMs.
|
||||||
* @name: name of the component as shown under sysfs.
|
* @name: name of the component as shown under sysfs.
|
||||||
* @nr_inport: number of input ports for this component.
|
* @nr_inport: number of input ports for this component.
|
||||||
* @outports: list of remote endpoint port number.
|
|
||||||
* @child_names:name of all child components connected to this device.
|
|
||||||
* @child_ports:child component port number the current component is
|
|
||||||
connected to.
|
|
||||||
* @nr_outport: number of output ports for this component.
|
* @nr_outport: number of output ports for this component.
|
||||||
|
* @conns: Array of nr_outport connections from this component
|
||||||
*/
|
*/
|
||||||
struct coresight_platform_data {
|
struct coresight_platform_data {
|
||||||
int cpu;
|
int cpu;
|
||||||
const char *name;
|
const char *name;
|
||||||
int nr_inport;
|
int nr_inport;
|
||||||
int *outports;
|
|
||||||
const char **child_names;
|
|
||||||
int *child_ports;
|
|
||||||
int nr_outport;
|
int nr_outport;
|
||||||
|
struct coresight_connection *conns;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue