aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/scan.c
diff options
context:
space:
mode:
authorMika Westerberg <mika.westerberg@linux.intel.com>2012-10-31 17:44:41 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2012-11-14 18:28:00 -0500
commitcf761af9ee0f2c172710ad2b7ca029016b5d4c45 (patch)
treec73b0ccfd422545508188fd8ee31ea2d192e1a82 /drivers/acpi/scan.c
parent06f64c8f239a47b359c60301914c783b56b32c13 (diff)
ACPI: Provide generic functions for matching ACPI device nodes
Introduce function acpi_match_device() allowing callers to match struct device objects with populated acpi_handle fields against arrays of ACPI device IDs. Also introduce function acpi_driver_match_device() using acpi_match_device() internally and allowing callers to match a struct device object against an array of ACPI device IDs provided by a device driver. Additionally, introduce macro ACPI_PTR() that may be used by device drivers to escape pointers to data structures whose definitions depend on CONFIG_ACPI. Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: H. Peter Anvin <hpa@zytor.com> Acked-by: Tony Luck <tony.luck@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/scan.c')
-rw-r--r--drivers/acpi/scan.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 1fcb8678665c..a0dfdffe54d4 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -340,8 +340,8 @@ static void acpi_device_remove_files(struct acpi_device *dev)
340 ACPI Bus operations 340 ACPI Bus operations
341 -------------------------------------------------------------------------- */ 341 -------------------------------------------------------------------------- */
342 342
343int acpi_match_device_ids(struct acpi_device *device, 343static const struct acpi_device_id *__acpi_match_device(
344 const struct acpi_device_id *ids) 344 struct acpi_device *device, const struct acpi_device_id *ids)
345{ 345{
346 const struct acpi_device_id *id; 346 const struct acpi_device_id *id;
347 struct acpi_hardware_id *hwid; 347 struct acpi_hardware_id *hwid;
@@ -351,14 +351,44 @@ int acpi_match_device_ids(struct acpi_device *device,
351 * driver for it. 351 * driver for it.
352 */ 352 */
353 if (!device->status.present) 353 if (!device->status.present)
354 return -ENODEV; 354 return NULL;
355 355
356 for (id = ids; id->id[0]; id++) 356 for (id = ids; id->id[0]; id++)
357 list_for_each_entry(hwid, &device->pnp.ids, list) 357 list_for_each_entry(hwid, &device->pnp.ids, list)
358 if (!strcmp((char *) id->id, hwid->id)) 358 if (!strcmp((char *) id->id, hwid->id))
359 return 0; 359 return id;
360
361 return NULL;
362}
360 363
361 return -ENOENT; 364/**
365 * acpi_match_device - Match a struct device against a given list of ACPI IDs
366 * @ids: Array of struct acpi_device_id object to match against.
367 * @dev: The device structure to match.
368 *
369 * Check if @dev has a valid ACPI handle and if there is a struct acpi_device
370 * object for that handle and use that object to match against a given list of
371 * device IDs.
372 *
373 * Return a pointer to the first matching ID on success or %NULL on failure.
374 */
375const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
376 const struct device *dev)
377{
378 struct acpi_device *adev;
379
380 if (!ids || !dev->acpi_handle
381 || ACPI_FAILURE(acpi_bus_get_device(dev->acpi_handle, &adev)))
382 return NULL;
383
384 return __acpi_match_device(adev, ids);
385}
386EXPORT_SYMBOL_GPL(acpi_match_device);
387
388int acpi_match_device_ids(struct acpi_device *device,
389 const struct acpi_device_id *ids)
390{
391 return __acpi_match_device(device, ids) ? 0 : -ENOENT;
362} 392}
363EXPORT_SYMBOL(acpi_match_device_ids); 393EXPORT_SYMBOL(acpi_match_device_ids);
364 394