Skip to content

Commit 37ea1ff

Browse files
Suzuki K Poulosegregkh
Suzuki K Poulose
authored andcommitted
coresight: Use fwnode handle instead of device names
We rely on the device names to find a CoreSight device on the coresight bus. The device name however is obtained from the platform, which is bound to the real platform/amba device. As we are about to use different naming scheme for the coresight devices, we can't rely on the platform device name to find the corresponding coresight device. Instead we use the platform agnostic "fwnode handle" of the parent device to find the devices. We also reuse the same fwnode as the parent for the Coresight device we create. Signed-off-by: Suzuki K Poulose <[email protected]> Signed-off-by: Mathieu Poirier <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 20961ae commit 37ea1ff

File tree

4 files changed

+49
-17
lines changed

4 files changed

+49
-17
lines changed

drivers/hwtracing/coresight/coresight-platform.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static int coresight_alloc_conns(struct device *dev,
3636
return 0;
3737
}
3838

39-
static int coresight_device_fwnode_match(struct device *dev, void *fwnode)
39+
int coresight_device_fwnode_match(struct device *dev, void *fwnode)
4040
{
4141
return dev_fwnode(dev) == fwnode;
4242
}
@@ -219,9 +219,15 @@ static int of_coresight_parse_endpoint(struct device *dev,
219219
}
220220

221221
conn->outport = endpoint.port;
222-
conn->child_name = devm_kstrdup(dev,
223-
dev_name(rdev),
224-
GFP_KERNEL);
222+
/*
223+
* Hold the refcount to the target device. This could be
224+
* released via:
225+
* 1) coresight_release_platform_data() if the probe fails or
226+
* this device is unregistered.
227+
* 2) While removing the target device via
228+
* coresight_remove_match()
229+
*/
230+
conn->child_fwnode = fwnode_handle_get(rdev_fwnode);
225231
conn->child_port = rendpoint.port;
226232
/* Connection record updated */
227233
ret = 1;

drivers/hwtracing/coresight/coresight-priv.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
200200
return 0;
201201
}
202202

203-
static inline void
204-
coresight_release_platform_data(struct coresight_platform_data *pdata)
205-
{}
203+
void coresight_release_platform_data(struct coresight_platform_data *pdata);
204+
205+
int coresight_device_fwnode_match(struct device *dev, void *fwnode);
206206

207207
#endif

drivers/hwtracing/coresight/coresight.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ static void coresight_device_release(struct device *dev)
978978
{
979979
struct coresight_device *csdev = to_coresight_device(dev);
980980

981+
fwnode_handle_put(csdev->dev.fwnode);
981982
kfree(csdev->refcnt);
982983
kfree(csdev);
983984
}
@@ -1009,13 +1010,11 @@ static int coresight_orphan_match(struct device *dev, void *data)
10091010
/* We have found at least one orphan connection */
10101011
if (conn->child_dev == NULL) {
10111012
/* Does it match this newly added device? */
1012-
if (conn->child_name &&
1013-
!strcmp(dev_name(&csdev->dev), conn->child_name)) {
1013+
if (conn->child_fwnode == csdev->dev.fwnode)
10141014
conn->child_dev = csdev;
1015-
} else {
1015+
else
10161016
/* This component still has an orphan */
10171017
still_orphan = true;
1018-
}
10191018
}
10201019
}
10211020

@@ -1047,9 +1046,9 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
10471046
struct coresight_connection *conn = &csdev->pdata->conns[i];
10481047
struct device *dev = NULL;
10491048

1050-
if (conn->child_name)
1051-
dev = bus_find_device_by_name(&coresight_bustype, NULL,
1052-
conn->child_name);
1049+
dev = bus_find_device(&coresight_bustype, NULL,
1050+
(void *)conn->child_fwnode,
1051+
coresight_device_fwnode_match);
10531052
if (dev) {
10541053
conn->child_dev = to_coresight_device(dev);
10551054
/* and put reference from 'bus_find_device()' */
@@ -1084,9 +1083,15 @@ static int coresight_remove_match(struct device *dev, void *data)
10841083
if (conn->child_dev == NULL)
10851084
continue;
10861085

1087-
if (!strcmp(dev_name(&csdev->dev), conn->child_name)) {
1086+
if (csdev->dev.fwnode == conn->child_fwnode) {
10881087
iterator->orphan = true;
10891088
conn->child_dev = NULL;
1089+
/*
1090+
* Drop the reference to the handle for the remote
1091+
* device acquired in parsing the connections from
1092+
* platform data.
1093+
*/
1094+
fwnode_handle_put(conn->child_fwnode);
10901095
/* No need to continue */
10911096
break;
10921097
}
@@ -1166,6 +1171,22 @@ static int __init coresight_init(void)
11661171
}
11671172
postcore_initcall(coresight_init);
11681173

1174+
/*
1175+
* coresight_release_platform_data: Release references to the devices connected
1176+
* to the output port of this device.
1177+
*/
1178+
void coresight_release_platform_data(struct coresight_platform_data *pdata)
1179+
{
1180+
int i;
1181+
1182+
for (i = 0; i < pdata->nr_outport; i++) {
1183+
if (pdata->conns[i].child_fwnode) {
1184+
fwnode_handle_put(pdata->conns[i].child_fwnode);
1185+
pdata->conns[i].child_fwnode = NULL;
1186+
}
1187+
}
1188+
}
1189+
11691190
struct coresight_device *coresight_register(struct coresight_desc *desc)
11701191
{
11711192
int ret;
@@ -1210,6 +1231,11 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
12101231
csdev->dev.parent = desc->dev;
12111232
csdev->dev.release = coresight_device_release;
12121233
csdev->dev.bus = &coresight_bustype;
1234+
/*
1235+
* Hold the reference to our parent device. This will be
1236+
* dropped only in coresight_device_release().
1237+
*/
1238+
csdev->dev.fwnode = fwnode_handle_get(dev_fwnode(desc->dev));
12131239
dev_set_name(&csdev->dev, "%s", desc->name);
12141240

12151241
ret = device_register(&csdev->dev);

include/linux/coresight.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ struct coresight_desc {
126126
/**
127127
* struct coresight_connection - representation of a single connection
128128
* @outport: a connection's output port number.
129-
* @chid_name: remote component's name.
130129
* @child_port: remote component's port number @output is connected to.
130+
* @chid_fwnode: remote component's fwnode handle.
131131
* @child_dev: a @coresight_device representation of the component
132132
connected to @outport.
133133
*/
134134
struct coresight_connection {
135135
int outport;
136-
const char *child_name;
137136
int child_port;
137+
struct fwnode_handle *child_fwnode;
138138
struct coresight_device *child_dev;
139139
};
140140

0 commit comments

Comments
 (0)