aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-11-29 10:27:34 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-12-06 19:05:50 -0500
commite3f02c5228c4b600abf6ca243301176f25553bd5 (patch)
treea3b5372f137fb8396ffe036e4c0c3cabea06b838
parent9c5ad36d987a1b06f6b0b9dc7bc61a45d277455d (diff)
ACPI / bind: Rework struct acpi_bus_type
Replace the .find_device function pointer in struct acpi_bus_type with a new one, .find_companion, that is supposed to point to a function returning struct acpi_device pointer (instead of an int) and takes one argument (instead of two). This way the role of this callback is more clear and the implementation of it can be more straightforward. Update all of the users of struct acpi_bus_type (PCI, PNP/ACPI and USB) to reflect the structure change. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Tested-by: Lan Tianyu <tianyu.lan@intel.com> # for USB/ACPI
-rw-r--r--drivers/acpi/glue.c12
-rw-r--r--drivers/pci/pci-acpi.c12
-rw-r--r--drivers/pnp/pnpacpi/core.c21
-rw-r--r--drivers/usb/core/usb-acpi.c40
-rw-r--r--include/acpi/acpi_bus.h2
5 files changed, 39 insertions, 48 deletions
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index c0d18b2145c1..7608d66f289b 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -37,7 +37,7 @@ int register_acpi_bus_type(struct acpi_bus_type *type)
37{ 37{
38 if (acpi_disabled) 38 if (acpi_disabled)
39 return -ENODEV; 39 return -ENODEV;
40 if (type && type->match && type->find_device) { 40 if (type && type->match && type->find_companion) {
41 down_write(&bus_type_sem); 41 down_write(&bus_type_sem);
42 list_add_tail(&type->list, &bus_type_list); 42 list_add_tail(&type->list, &bus_type_list);
43 up_write(&bus_type_sem); 43 up_write(&bus_type_sem);
@@ -302,17 +302,19 @@ EXPORT_SYMBOL_GPL(acpi_unbind_one);
302static int acpi_platform_notify(struct device *dev) 302static int acpi_platform_notify(struct device *dev)
303{ 303{
304 struct acpi_bus_type *type = acpi_get_bus_type(dev); 304 struct acpi_bus_type *type = acpi_get_bus_type(dev);
305 acpi_handle handle;
306 int ret; 305 int ret;
307 306
308 ret = acpi_bind_one(dev, NULL); 307 ret = acpi_bind_one(dev, NULL);
309 if (ret && type) { 308 if (ret && type) {
310 ret = type->find_device(dev, &handle); 309 struct acpi_device *adev;
311 if (ret) { 310
311 adev = type->find_companion(dev);
312 if (!adev) {
312 DBG("Unable to get handle for %s\n", dev_name(dev)); 313 DBG("Unable to get handle for %s\n", dev_name(dev));
314 ret = -ENODEV;
313 goto out; 315 goto out;
314 } 316 }
315 ret = acpi_bind_one(dev, handle); 317 ret = acpi_bind_one(dev, adev->handle);
316 if (ret) 318 if (ret)
317 goto out; 319 goto out;
318 } 320 }
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index adbf34003995..ce31eb0cdca7 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -303,10 +303,9 @@ void acpi_pci_remove_bus(struct pci_bus *bus)
303} 303}
304 304
305/* ACPI bus type */ 305/* ACPI bus type */
306static int acpi_pci_find_device(struct device *dev, acpi_handle *handle) 306static struct acpi_device *acpi_pci_find_companion(struct device *dev)
307{ 307{
308 struct pci_dev *pci_dev = to_pci_dev(dev); 308 struct pci_dev *pci_dev = to_pci_dev(dev);
309 struct acpi_device *adev;
310 bool check_children; 309 bool check_children;
311 u64 addr; 310 u64 addr;
312 311
@@ -319,13 +318,8 @@ static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
319 || pci_dev->hdr_type == PCI_HEADER_TYPE_CARDBUS; 318 || pci_dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
320 /* Please ref to ACPI spec for the syntax of _ADR */ 319 /* Please ref to ACPI spec for the syntax of _ADR */
321 addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn); 320 addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
322 adev = acpi_find_child_device(ACPI_COMPANION(dev->parent), addr, 321 return acpi_find_child_device(ACPI_COMPANION(dev->parent), addr,
323 check_children); 322 check_children);
324 if (adev) {
325 *handle = adev->handle;
326 return 0;
327 }
328 return -ENODEV;
329} 323}
330 324
331static void pci_acpi_setup(struct device *dev) 325static void pci_acpi_setup(struct device *dev)
@@ -365,7 +359,7 @@ static bool pci_acpi_bus_match(struct device *dev)
365static struct acpi_bus_type acpi_pci_bus = { 359static struct acpi_bus_type acpi_pci_bus = {
366 .name = "PCI", 360 .name = "PCI",
367 .match = pci_acpi_bus_match, 361 .match = pci_acpi_bus_match,
368 .find_device = acpi_pci_find_device, 362 .find_companion = acpi_pci_find_companion,
369 .setup = pci_acpi_setup, 363 .setup = pci_acpi_setup,
370 .cleanup = pci_acpi_cleanup, 364 .cleanup = pci_acpi_cleanup,
371}; 365};
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index e869ba698ac0..156d14e2587e 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -328,20 +328,15 @@ static int __init acpi_pnp_match(struct device *dev, void *_pnp)
328 && compare_pnp_id(pnp->id, acpi_device_hid(acpi)); 328 && compare_pnp_id(pnp->id, acpi_device_hid(acpi));
329} 329}
330 330
331static int __init acpi_pnp_find_device(struct device *dev, acpi_handle * handle) 331static struct acpi_device * __init acpi_pnp_find_companion(struct device *dev)
332{ 332{
333 struct device *adev; 333 dev = bus_find_device(&acpi_bus_type, NULL, to_pnp_dev(dev),
334 struct acpi_device *acpi; 334 acpi_pnp_match);
335 335 if (!dev)
336 adev = bus_find_device(&acpi_bus_type, NULL, 336 return NULL;
337 to_pnp_dev(dev), acpi_pnp_match);
338 if (!adev)
339 return -ENODEV;
340 337
341 acpi = to_acpi_device(adev); 338 put_device(dev);
342 *handle = acpi->handle; 339 return to_acpi_device(dev);
343 put_device(adev);
344 return 0;
345} 340}
346 341
347/* complete initialization of a PNPACPI device includes having 342/* complete initialization of a PNPACPI device includes having
@@ -355,7 +350,7 @@ static bool acpi_pnp_bus_match(struct device *dev)
355static struct acpi_bus_type __initdata acpi_pnp_bus = { 350static struct acpi_bus_type __initdata acpi_pnp_bus = {
356 .name = "PNP", 351 .name = "PNP",
357 .match = acpi_pnp_bus_match, 352 .match = acpi_pnp_bus_match,
358 .find_device = acpi_pnp_find_device, 353 .find_companion = acpi_pnp_find_companion,
359}; 354};
360 355
361int pnpacpi_disabled __initdata; 356int pnpacpi_disabled __initdata;
diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c
index 11c656976cb5..f0155a39aaa3 100644
--- a/drivers/usb/core/usb-acpi.c
+++ b/drivers/usb/core/usb-acpi.c
@@ -126,7 +126,7 @@ out:
126 return ret; 126 return ret;
127} 127}
128 128
129static int usb_acpi_find_device(struct device *dev, acpi_handle *handle) 129static struct acpi_device *usb_acpi_find_companion(struct device *dev)
130{ 130{
131 struct usb_device *udev; 131 struct usb_device *udev;
132 acpi_handle *parent_handle; 132 acpi_handle *parent_handle;
@@ -168,16 +168,15 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
168 break; 168 break;
169 } 169 }
170 170
171 return -ENODEV; 171 return NULL;
172 } 172 }
173 173
174 /* root hub's parent is the usb hcd. */ 174 /* root hub's parent is the usb hcd. */
175 parent_handle = ACPI_HANDLE(dev->parent); 175 return acpi_find_child_device(ACPI_COMPANION(dev->parent),
176 *handle = acpi_get_child(parent_handle, udev->portnum); 176 udev->portnum, false);
177 if (!*handle)
178 return -ENODEV;
179 return 0;
180 } else if (is_usb_port(dev)) { 177 } else if (is_usb_port(dev)) {
178 struct acpi_device *adev = NULL;
179
181 sscanf(dev_name(dev), "port%d", &port_num); 180 sscanf(dev_name(dev), "port%d", &port_num);
182 /* Get the struct usb_device point of port's hub */ 181 /* Get the struct usb_device point of port's hub */
183 udev = to_usb_device(dev->parent->parent); 182 udev = to_usb_device(dev->parent->parent);
@@ -193,26 +192,27 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
193 192
194 raw_port_num = usb_hcd_find_raw_port_number(hcd, 193 raw_port_num = usb_hcd_find_raw_port_number(hcd,
195 port_num); 194 port_num);
196 *handle = acpi_get_child(ACPI_HANDLE(&udev->dev), 195 adev = acpi_find_child_device(ACPI_COMPANION(&udev->dev),
197 raw_port_num); 196 raw_port_num, false);
198 if (!*handle) 197 if (!adev)
199 return -ENODEV; 198 return NULL;
200 } else { 199 } else {
201 parent_handle = 200 parent_handle =
202 usb_get_hub_port_acpi_handle(udev->parent, 201 usb_get_hub_port_acpi_handle(udev->parent,
203 udev->portnum); 202 udev->portnum);
204 if (!parent_handle) 203 if (!parent_handle)
205 return -ENODEV; 204 return NULL;
206 205
207 *handle = acpi_get_child(parent_handle, port_num); 206 acpi_bus_get_device(parent_handle, &adev);
208 if (!*handle) 207 adev = acpi_find_child_device(adev, port_num, false);
209 return -ENODEV; 208 if (!adev)
209 return NULL;
210 } 210 }
211 usb_acpi_check_port_connect_type(udev, *handle, port_num); 211 usb_acpi_check_port_connect_type(udev, adev->handle, port_num);
212 } else 212 return adev;
213 return -ENODEV; 213 }
214 214
215 return 0; 215 return NULL;
216} 216}
217 217
218static bool usb_acpi_bus_match(struct device *dev) 218static bool usb_acpi_bus_match(struct device *dev)
@@ -223,7 +223,7 @@ static bool usb_acpi_bus_match(struct device *dev)
223static struct acpi_bus_type usb_acpi_bus = { 223static struct acpi_bus_type usb_acpi_bus = {
224 .name = "USB", 224 .name = "USB",
225 .match = usb_acpi_bus_match, 225 .match = usb_acpi_bus_match,
226 .find_device = usb_acpi_find_device, 226 .find_companion = usb_acpi_find_companion,
227}; 227};
228 228
229int usb_acpi_register(void) 229int usb_acpi_register(void)
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 918eaab892e1..a50898e67a68 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -412,7 +412,7 @@ struct acpi_bus_type {
412 struct list_head list; 412 struct list_head list;
413 const char *name; 413 const char *name;
414 bool (*match)(struct device *dev); 414 bool (*match)(struct device *dev);
415 int (*find_device) (struct device *, acpi_handle *); 415 struct acpi_device * (*find_companion)(struct device *);
416 void (*setup)(struct device *); 416 void (*setup)(struct device *);
417 void (*cleanup)(struct device *); 417 void (*cleanup)(struct device *);
418}; 418};