Subject: [PATCH] [acpi driver model] Add compatability hooks for ACPI devices - Add struct acpi_device::ad for pointing to the new-skool struct acpi_dev. - Add acpi_device_create_add() which the current core can use to create and add devices to the new tree. - Add a declaration of that function to include/acpi/acpi_bus.h. Signed-off-by: Patrick Mochel --- drivers/acpi/drivers/core/device.c | 56 ++++++++++++++++++++++++++++++++++++ include/acpi/acpi_bus.h | 5 +++ 2 files changed, 60 insertions(+), 1 deletions(-) applies-to: 122bbead5597af6eab8a0a364bb21560e43c9757 e283f8d32d97c9e4a291c567d70ba8843819732a diff --git a/drivers/acpi/drivers/core/device.c b/drivers/acpi/drivers/core/device.c index 79c03e8..d91116b 100644 --- a/drivers/acpi/drivers/core/device.c +++ b/drivers/acpi/drivers/core/device.c @@ -31,3 +31,59 @@ void acpi_device_unregister(struct acpi_ { device_unregister(&ad->dev); } + + +/** + * acpi_allocate_device - Allocate and initialize acpi_dev + * @acpi_device: The old-skool acpi object to initialize from. + * + */ + +static struct acpi_dev * acpi_alloc_device(struct acpi_device * acpi_device) +{ + struct acpi_dev * ad; + + ad = kzalloc(sizeof(struct acpi_dev), GFP_KERNEL); + if (ad) { + strncpy(ad->dev.bus_id, acpi_device->pnp.bus_id, BUS_ID_SIZE); + + if (acpi_device->parent) + ad->dev.parent = &acpi_device->parent->ad->dev; + ad->acpi_device = acpi_device; + acpi_device->ad = ad; + } + return ad; +} + + +/** + * acpi_device_create_add - Create and add a new-skool acpi device. + * @acpi_device: The old-skool device to use a template. + * + * This function is meant as an intermediate interface for + * the old-skool ACPI bus driver (drivers/base/scan.c) to use + * to create and add devices conforming to the new interface + * (devices that use the core Linux driver model, instead of + * the similar-but-incomplete ACPI driver model. + * + * This interface should go away once the conversion to the + * core driver model is complete and the ACPI scanning code + * can create and add devices on their own. + */ + +int acpi_device_create_add(struct acpi_device * acpi_device) +{ + struct acpi_dev * ad; + int ret; + + ad = acpi_alloc_device(acpi_device); + if (!ad) + return -ENOMEM; + + ret = acpi_device_register(ad); + if (ret) + kfree(ad); + return ret; +} + + diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 0b54e9a..24e02c8 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -26,7 +26,7 @@ #ifndef __ACPI_BUS_H__ #define __ACPI_BUS_H__ -#include +#include #include @@ -296,10 +296,13 @@ struct acpi_device { struct acpi_driver *driver; void *driver_data; struct kobject kobj; + struct acpi_dev * ad; }; #define acpi_driver_data(d) ((d)->driver_data) +extern int acpi_device_create_add(struct acpi_device *); + /* * Events * ------ --- 0.99.9.GIT