diff options
author | Suzuki K Poulose <suzuki.poulose@arm.com> | 2019-07-23 18:18:34 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-07-30 07:07:42 -0400 |
commit | 67843bbaf36eb087714f40e783ee78e99e9e4b86 (patch) | |
tree | cd2b2839bd3510dfd05d2185346a57988fb93c8a | |
parent | cfba5de9b99f8bbb8b4ea11b3049784e78b8759b (diff) |
drivers: Introduce device lookup variants by fwnode
Add a helper to match the firmware node handle of a device and provide
wrappers for {bus/class/driver}_find_device() APIs to avoid proliferation
of duplicate custom match functions.
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Doug Ledford <dledford@redhat.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: linux-usb@vger.kernel.org
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Joe Perches <joe@perches.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Joerg Roedel <joro@8bytes.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Acked-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20190723221838.12024-4-suzuki.poulose@arm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/base/core.c | 6 | ||||
-rw-r--r-- | drivers/base/devcon.c | 8 | ||||
-rw-r--r-- | drivers/hwtracing/coresight/coresight-platform.c | 11 | ||||
-rw-r--r-- | drivers/hwtracing/coresight/coresight-priv.h | 2 | ||||
-rw-r--r-- | drivers/hwtracing/coresight/coresight.c | 4 | ||||
-rw-r--r-- | drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 8 | ||||
-rw-r--r-- | drivers/iommu/arm-smmu-v3.c | 9 | ||||
-rw-r--r-- | drivers/iommu/arm-smmu.c | 9 | ||||
-rw-r--r-- | drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 8 | ||||
-rw-r--r-- | drivers/usb/roles/class.c | 8 | ||||
-rw-r--r-- | drivers/usb/typec/class.c | 8 | ||||
-rw-r--r-- | include/linux/device.h | 39 |
12 files changed, 57 insertions, 63 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index fb83647d685a..e8f81a667545 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -3368,3 +3368,9 @@ int device_match_of_node(struct device *dev, const void *np) | |||
3368 | return dev->of_node == np; | 3368 | return dev->of_node == np; |
3369 | } | 3369 | } |
3370 | EXPORT_SYMBOL_GPL(device_match_of_node); | 3370 | EXPORT_SYMBOL_GPL(device_match_of_node); |
3371 | |||
3372 | int device_match_fwnode(struct device *dev, const void *fwnode) | ||
3373 | { | ||
3374 | return dev_fwnode(dev) == fwnode; | ||
3375 | } | ||
3376 | EXPORT_SYMBOL_GPL(device_match_fwnode); | ||
diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c index 09f28479b243..1d488dc5dd0c 100644 --- a/drivers/base/devcon.c +++ b/drivers/base/devcon.c | |||
@@ -133,19 +133,13 @@ static struct bus_type *generic_match_buses[] = { | |||
133 | NULL, | 133 | NULL, |
134 | }; | 134 | }; |
135 | 135 | ||
136 | static int device_fwnode_match(struct device *dev, const void *fwnode) | ||
137 | { | ||
138 | return dev_fwnode(dev) == fwnode; | ||
139 | } | ||
140 | |||
141 | static void *device_connection_fwnode_match(struct device_connection *con) | 136 | static void *device_connection_fwnode_match(struct device_connection *con) |
142 | { | 137 | { |
143 | struct bus_type *bus; | 138 | struct bus_type *bus; |
144 | struct device *dev; | 139 | struct device *dev; |
145 | 140 | ||
146 | for (bus = generic_match_buses[0]; bus; bus++) { | 141 | for (bus = generic_match_buses[0]; bus; bus++) { |
147 | dev = bus_find_device(bus, NULL, (void *)con->fwnode, | 142 | dev = bus_find_device_by_fwnode(bus, con->fwnode); |
148 | device_fwnode_match); | ||
149 | if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id))) | 143 | if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id))) |
150 | return dev; | 144 | return dev; |
151 | 145 | ||
diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c index dad7d96c5943..3c5bee429105 100644 --- a/drivers/hwtracing/coresight/coresight-platform.c +++ b/drivers/hwtracing/coresight/coresight-platform.c | |||
@@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev, | |||
37 | return 0; | 37 | return 0; |
38 | } | 38 | } |
39 | 39 | ||
40 | int coresight_device_fwnode_match(struct device *dev, const void *fwnode) | ||
41 | { | ||
42 | return dev_fwnode(dev) == fwnode; | ||
43 | } | ||
44 | |||
45 | static struct device * | 40 | static struct device * |
46 | coresight_find_device_by_fwnode(struct fwnode_handle *fwnode) | 41 | coresight_find_device_by_fwnode(struct fwnode_handle *fwnode) |
47 | { | 42 | { |
@@ -51,8 +46,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode) | |||
51 | * If we have a non-configurable replicator, it will be found on the | 46 | * If we have a non-configurable replicator, it will be found on the |
52 | * platform bus. | 47 | * platform bus. |
53 | */ | 48 | */ |
54 | dev = bus_find_device(&platform_bus_type, NULL, | 49 | dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode); |
55 | fwnode, coresight_device_fwnode_match); | ||
56 | if (dev) | 50 | if (dev) |
57 | return dev; | 51 | return dev; |
58 | 52 | ||
@@ -60,8 +54,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode) | |||
60 | * We have a configurable component - circle through the AMBA bus | 54 | * We have a configurable component - circle through the AMBA bus |
61 | * looking for the device that matches the endpoint node. | 55 | * looking for the device that matches the endpoint node. |
62 | */ | 56 | */ |
63 | return bus_find_device(&amba_bustype, NULL, | 57 | return bus_find_device_by_fwnode(&amba_bustype, fwnode); |
64 | fwnode, coresight_device_fwnode_match); | ||
65 | } | 58 | } |
66 | 59 | ||
67 | #ifdef CONFIG_OF | 60 | #ifdef CONFIG_OF |
diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h index 7d401790dd7e..61d7f9ff054d 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h | |||
@@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id) | |||
202 | 202 | ||
203 | void coresight_release_platform_data(struct coresight_platform_data *pdata); | 203 | void coresight_release_platform_data(struct coresight_platform_data *pdata); |
204 | 204 | ||
205 | int coresight_device_fwnode_match(struct device *dev, const void *fwnode); | ||
206 | |||
207 | #endif | 205 | #endif |
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index 55db77f6410b..6453c67a4d01 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c | |||
@@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev) | |||
1046 | struct coresight_connection *conn = &csdev->pdata->conns[i]; | 1046 | struct coresight_connection *conn = &csdev->pdata->conns[i]; |
1047 | struct device *dev = NULL; | 1047 | struct device *dev = NULL; |
1048 | 1048 | ||
1049 | dev = bus_find_device(&coresight_bustype, NULL, | 1049 | dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode); |
1050 | (void *)conn->child_fwnode, | ||
1051 | coresight_device_fwnode_match); | ||
1052 | if (dev) { | 1050 | if (dev) { |
1053 | conn->child_dev = to_coresight_device(dev); | 1051 | conn->child_dev = to_coresight_device(dev); |
1054 | /* and put reference from 'bus_find_device()' */ | 1052 | /* and put reference from 'bus_find_device()' */ |
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c index 81e6dedb1e02..fa05e943038a 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c | |||
@@ -4499,19 +4499,13 @@ static const struct acpi_device_id hns_roce_acpi_match[] = { | |||
4499 | }; | 4499 | }; |
4500 | MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match); | 4500 | MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match); |
4501 | 4501 | ||
4502 | static int hns_roce_node_match(struct device *dev, const void *fwnode) | ||
4503 | { | ||
4504 | return dev->fwnode == fwnode; | ||
4505 | } | ||
4506 | |||
4507 | static struct | 4502 | static struct |
4508 | platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode) | 4503 | platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode) |
4509 | { | 4504 | { |
4510 | struct device *dev; | 4505 | struct device *dev; |
4511 | 4506 | ||
4512 | /* get the 'device' corresponding to the matching 'fwnode' */ | 4507 | /* get the 'device' corresponding to the matching 'fwnode' */ |
4513 | dev = bus_find_device(&platform_bus_type, NULL, | 4508 | dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode); |
4514 | fwnode, hns_roce_node_match); | ||
4515 | /* get the platform device */ | 4509 | /* get the platform device */ |
4516 | return dev ? to_platform_device(dev) : NULL; | 4510 | return dev ? to_platform_device(dev) : NULL; |
4517 | } | 4511 | } |
diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index a9a9fabd3968..6f0e13fa5e1a 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c | |||
@@ -2034,16 +2034,11 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova) | |||
2034 | 2034 | ||
2035 | static struct platform_driver arm_smmu_driver; | 2035 | static struct platform_driver arm_smmu_driver; |
2036 | 2036 | ||
2037 | static int arm_smmu_match_node(struct device *dev, const void *data) | ||
2038 | { | ||
2039 | return dev->fwnode == data; | ||
2040 | } | ||
2041 | |||
2042 | static | 2037 | static |
2043 | struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) | 2038 | struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) |
2044 | { | 2039 | { |
2045 | struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL, | 2040 | struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver, |
2046 | fwnode, arm_smmu_match_node); | 2041 | fwnode); |
2047 | put_device(dev); | 2042 | put_device(dev); |
2048 | return dev ? dev_get_drvdata(dev) : NULL; | 2043 | return dev ? dev_get_drvdata(dev) : NULL; |
2049 | } | 2044 | } |
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 64977c131ee6..aa06498f291d 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c | |||
@@ -1426,16 +1426,11 @@ static bool arm_smmu_capable(enum iommu_cap cap) | |||
1426 | } | 1426 | } |
1427 | } | 1427 | } |
1428 | 1428 | ||
1429 | static int arm_smmu_match_node(struct device *dev, const void *data) | ||
1430 | { | ||
1431 | return dev->fwnode == data; | ||
1432 | } | ||
1433 | |||
1434 | static | 1429 | static |
1435 | struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) | 1430 | struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) |
1436 | { | 1431 | { |
1437 | struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL, | 1432 | struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver, |
1438 | fwnode, arm_smmu_match_node); | 1433 | fwnode); |
1439 | put_device(dev); | 1434 | put_device(dev); |
1440 | return dev ? dev_get_drvdata(dev) : NULL; | 1435 | return dev ? dev_get_drvdata(dev) : NULL; |
1441 | } | 1436 | } |
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c index bb6586d0e5af..ed3829ae4ef1 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | |||
@@ -754,17 +754,11 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev) | |||
754 | return (void *)misc_op; | 754 | return (void *)misc_op; |
755 | } | 755 | } |
756 | 756 | ||
757 | static int hns_dsaf_dev_match(struct device *dev, const void *fwnode) | ||
758 | { | ||
759 | return dev->fwnode == fwnode; | ||
760 | } | ||
761 | |||
762 | struct | 757 | struct |
763 | platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode) | 758 | platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode) |
764 | { | 759 | { |
765 | struct device *dev; | 760 | struct device *dev; |
766 | 761 | ||
767 | dev = bus_find_device(&platform_bus_type, NULL, | 762 | dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode); |
768 | fwnode, hns_dsaf_dev_match); | ||
769 | return dev ? to_platform_device(dev) : NULL; | 763 | return dev ? to_platform_device(dev) : NULL; |
770 | } | 764 | } |
diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index c8efe60e2465..0526efbc4922 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c | |||
@@ -85,11 +85,6 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw) | |||
85 | } | 85 | } |
86 | EXPORT_SYMBOL_GPL(usb_role_switch_get_role); | 86 | EXPORT_SYMBOL_GPL(usb_role_switch_get_role); |
87 | 87 | ||
88 | static int switch_fwnode_match(struct device *dev, const void *fwnode) | ||
89 | { | ||
90 | return dev_fwnode(dev) == fwnode; | ||
91 | } | ||
92 | |||
93 | static void *usb_role_switch_match(struct device_connection *con, int ep, | 88 | static void *usb_role_switch_match(struct device_connection *con, int ep, |
94 | void *data) | 89 | void *data) |
95 | { | 90 | { |
@@ -99,8 +94,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep, | |||
99 | if (con->id && !fwnode_property_present(con->fwnode, con->id)) | 94 | if (con->id && !fwnode_property_present(con->fwnode, con->id)) |
100 | return NULL; | 95 | return NULL; |
101 | 96 | ||
102 | dev = class_find_device(role_class, NULL, con->fwnode, | 97 | dev = class_find_device_by_fwnode(role_class, con->fwnode); |
103 | switch_fwnode_match); | ||
104 | } else { | 98 | } else { |
105 | dev = class_find_device_by_name(role_class, con->endpoint[ep]); | 99 | dev = class_find_device_by_name(role_class, con->endpoint[ep]); |
106 | } | 100 | } |
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 9b0d15b487e5..94a3eda62add 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c | |||
@@ -205,11 +205,6 @@ static void typec_altmode_put_partner(struct altmode *altmode) | |||
205 | put_device(&adev->dev); | 205 | put_device(&adev->dev); |
206 | } | 206 | } |
207 | 207 | ||
208 | static int typec_port_fwnode_match(struct device *dev, const void *fwnode) | ||
209 | { | ||
210 | return dev_fwnode(dev) == fwnode; | ||
211 | } | ||
212 | |||
213 | static void *typec_port_match(struct device_connection *con, int ep, void *data) | 208 | static void *typec_port_match(struct device_connection *con, int ep, void *data) |
214 | { | 209 | { |
215 | struct device *dev; | 210 | struct device *dev; |
@@ -219,8 +214,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data) | |||
219 | * we need to return ERR_PTR(-PROBE_DEFER) when there is no device. | 214 | * we need to return ERR_PTR(-PROBE_DEFER) when there is no device. |
220 | */ | 215 | */ |
221 | if (con->fwnode) | 216 | if (con->fwnode) |
222 | return class_find_device(typec_class, NULL, con->fwnode, | 217 | return class_find_device_by_fwnode(typec_class, con->fwnode); |
223 | typec_port_fwnode_match); | ||
224 | 218 | ||
225 | dev = class_find_device_by_name(typec_class, con->endpoint[ep]); | 219 | dev = class_find_device_by_name(typec_class, con->endpoint[ep]); |
226 | 220 | ||
diff --git a/include/linux/device.h b/include/linux/device.h index 29d8d7ad41e6..7133fc1c285d 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter); | |||
166 | 166 | ||
167 | int device_match_name(struct device *dev, const void *name); | 167 | int device_match_name(struct device *dev, const void *name); |
168 | int device_match_of_node(struct device *dev, const void *np); | 168 | int device_match_of_node(struct device *dev, const void *np); |
169 | int device_match_fwnode(struct device *dev, const void *fwnode); | ||
169 | 170 | ||
170 | int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, | 171 | int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, |
171 | int (*fn)(struct device *dev, void *data)); | 172 | int (*fn)(struct device *dev, void *data)); |
@@ -198,6 +199,18 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np) | |||
198 | return bus_find_device(bus, NULL, np, device_match_of_node); | 199 | return bus_find_device(bus, NULL, np, device_match_of_node); |
199 | } | 200 | } |
200 | 201 | ||
202 | /** | ||
203 | * bus_find_device_by_fwnode : device iterator for locating a particular device | ||
204 | * matching the fwnode. | ||
205 | * @bus: bus type | ||
206 | * @fwnode: fwnode of the device to match. | ||
207 | */ | ||
208 | static inline struct device * | ||
209 | bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode) | ||
210 | { | ||
211 | return bus_find_device(bus, NULL, fwnode, device_match_fwnode); | ||
212 | } | ||
213 | |||
201 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, | 214 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, |
202 | struct device *hint); | 215 | struct device *hint); |
203 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, | 216 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, |
@@ -391,6 +404,19 @@ driver_find_device_by_of_node(struct device_driver *drv, | |||
391 | return driver_find_device(drv, NULL, np, device_match_of_node); | 404 | return driver_find_device(drv, NULL, np, device_match_of_node); |
392 | } | 405 | } |
393 | 406 | ||
407 | /** | ||
408 | * driver_find_device_by_fwnode- device iterator for locating a particular device | ||
409 | * by fwnode pointer. | ||
410 | * @driver: the driver we're iterating | ||
411 | * @fwnode: fwnode pointer to match. | ||
412 | */ | ||
413 | static inline struct device * | ||
414 | driver_find_device_by_fwnode(struct device_driver *drv, | ||
415 | const struct fwnode_handle *fwnode) | ||
416 | { | ||
417 | return driver_find_device(drv, NULL, fwnode, device_match_fwnode); | ||
418 | } | ||
419 | |||
394 | void driver_deferred_probe_add(struct device *dev); | 420 | void driver_deferred_probe_add(struct device *dev); |
395 | int driver_deferred_probe_check_state(struct device *dev); | 421 | int driver_deferred_probe_check_state(struct device *dev); |
396 | int driver_deferred_probe_check_state_continue(struct device *dev); | 422 | int driver_deferred_probe_check_state_continue(struct device *dev); |
@@ -544,6 +570,19 @@ class_find_device_by_of_node(struct class *class, const struct device_node *np) | |||
544 | return class_find_device(class, NULL, np, device_match_of_node); | 570 | return class_find_device(class, NULL, np, device_match_of_node); |
545 | } | 571 | } |
546 | 572 | ||
573 | /** | ||
574 | * class_find_device_by_fwnode : device iterator for locating a particular device | ||
575 | * matching the fwnode. | ||
576 | * @class: class type | ||
577 | * @fwnode: fwnode of the device to match. | ||
578 | */ | ||
579 | static inline struct device * | ||
580 | class_find_device_by_fwnode(struct class *class, | ||
581 | const struct fwnode_handle *fwnode) | ||
582 | { | ||
583 | return class_find_device(class, NULL, fwnode, device_match_fwnode); | ||
584 | } | ||
585 | |||
547 | struct class_attribute { | 586 | struct class_attribute { |
548 | struct attribute attr; | 587 | struct attribute attr; |
549 | ssize_t (*show)(struct class *class, struct class_attribute *attr, | 588 | ssize_t (*show)(struct class *class, struct class_attribute *attr, |