ACPI: Update PNPID set/free interfaces

This patch introduces acpi_set_pnp_ids() and acpi_free_pnp_ids(),
which are updated from acpi_device_set_id() and acpi_free_ids(),
to setup and free acpi_device_pnp for a given acpi_handle.  They
can be called without acpi_device.

Signed-off-by: Toshi Kani <toshi.kani@hp.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Toshi Kani 2013-03-04 21:30:42 +00:00 committed by Rafael J. Wysocki
parent d4e1a692e9
commit c0af41757f
3 changed files with 45 additions and 44 deletions

View File

@ -71,7 +71,7 @@ int acpi_device_add(struct acpi_device *device,
void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
int type, unsigned long long sta); int type, unsigned long long sta);
void acpi_device_add_finalize(struct acpi_device *device); void acpi_device_add_finalize(struct acpi_device *device);
void acpi_free_ids(struct acpi_device *device); void acpi_free_pnp_ids(struct acpi_device_pnp *pnp);
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
Power Resource Power Resource

View File

@ -824,7 +824,7 @@ static void acpi_release_power_resource(struct device *dev)
list_del(&resource->list_node); list_del(&resource->list_node);
mutex_unlock(&power_resource_list_lock); mutex_unlock(&power_resource_list_lock);
acpi_free_ids(device); acpi_free_pnp_ids(&device->pnp);
kfree(resource); kfree(resource);
} }

View File

@ -662,17 +662,6 @@ int acpi_match_device_ids(struct acpi_device *device,
} }
EXPORT_SYMBOL(acpi_match_device_ids); EXPORT_SYMBOL(acpi_match_device_ids);
void acpi_free_ids(struct acpi_device *device)
{
struct acpi_hardware_id *id, *tmp;
list_for_each_entry_safe(id, tmp, &device->pnp.ids, list) {
kfree(id->id);
kfree(id);
}
kfree(device->pnp.unique_id);
}
static void acpi_free_power_resources_lists(struct acpi_device *device) static void acpi_free_power_resources_lists(struct acpi_device *device)
{ {
int i; int i;
@ -693,7 +682,7 @@ static void acpi_device_release(struct device *dev)
{ {
struct acpi_device *acpi_dev = to_acpi_device(dev); struct acpi_device *acpi_dev = to_acpi_device(dev);
acpi_free_ids(acpi_dev); acpi_free_pnp_ids(&acpi_dev->pnp);
acpi_free_power_resources_lists(acpi_dev); acpi_free_power_resources_lists(acpi_dev);
kfree(acpi_dev); kfree(acpi_dev);
} }
@ -1513,39 +1502,41 @@ static int acpi_ibm_smbus_match(acpi_handle handle)
return result; return result;
} }
static void acpi_device_set_id(struct acpi_device *device) static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
int device_type)
{ {
acpi_status status; acpi_status status;
struct acpi_device_info *info; struct acpi_device_info *info;
struct acpi_pnp_device_id_list *cid_list; struct acpi_pnp_device_id_list *cid_list;
int i; int i;
switch (device->device_type) { switch (device_type) {
case ACPI_BUS_TYPE_DEVICE: case ACPI_BUS_TYPE_DEVICE:
if (ACPI_IS_ROOT_DEVICE(device)) { if (handle == ACPI_ROOT_OBJECT) {
acpi_add_id(&device->pnp, ACPI_SYSTEM_HID); acpi_add_id(pnp, ACPI_SYSTEM_HID);
break; break;
} }
status = acpi_get_object_info(device->handle, &info); status = acpi_get_object_info(handle, &info);
if (ACPI_FAILURE(status)) { if (ACPI_FAILURE(status)) {
printk(KERN_ERR PREFIX "%s: Error reading device info\n", __func__); pr_err(PREFIX "%s: Error reading device info\n",
__func__);
return; return;
} }
if (info->valid & ACPI_VALID_HID) if (info->valid & ACPI_VALID_HID)
acpi_add_id(&device->pnp, info->hardware_id.string); acpi_add_id(pnp, info->hardware_id.string);
if (info->valid & ACPI_VALID_CID) { if (info->valid & ACPI_VALID_CID) {
cid_list = &info->compatible_id_list; cid_list = &info->compatible_id_list;
for (i = 0; i < cid_list->count; i++) for (i = 0; i < cid_list->count; i++)
acpi_add_id(&device->pnp, cid_list->ids[i].string); acpi_add_id(pnp, cid_list->ids[i].string);
} }
if (info->valid & ACPI_VALID_ADR) { if (info->valid & ACPI_VALID_ADR) {
device->pnp.bus_address = info->address; pnp->bus_address = info->address;
device->pnp.type.bus_address = 1; pnp->type.bus_address = 1;
} }
if (info->valid & ACPI_VALID_UID) if (info->valid & ACPI_VALID_UID)
device->pnp.unique_id = kstrdup(info->unique_id.string, pnp->unique_id = kstrdup(info->unique_id.string,
GFP_KERNEL); GFP_KERNEL);
kfree(info); kfree(info);
@ -1554,40 +1545,50 @@ static void acpi_device_set_id(struct acpi_device *device)
* Some devices don't reliably have _HIDs & _CIDs, so add * Some devices don't reliably have _HIDs & _CIDs, so add
* synthetic HIDs to make sure drivers can find them. * synthetic HIDs to make sure drivers can find them.
*/ */
if (acpi_is_video_device(device->handle)) if (acpi_is_video_device(handle))
acpi_add_id(&device->pnp, ACPI_VIDEO_HID); acpi_add_id(pnp, ACPI_VIDEO_HID);
else if (ACPI_SUCCESS(acpi_bay_match(device->handle))) else if (ACPI_SUCCESS(acpi_bay_match(handle)))
acpi_add_id(&device->pnp, ACPI_BAY_HID); acpi_add_id(pnp, ACPI_BAY_HID);
else if (ACPI_SUCCESS(acpi_dock_match(device->handle))) else if (ACPI_SUCCESS(acpi_dock_match(handle)))
acpi_add_id(&device->pnp, ACPI_DOCK_HID); acpi_add_id(pnp, ACPI_DOCK_HID);
else if (!acpi_ibm_smbus_match(device->handle)) else if (!acpi_ibm_smbus_match(handle))
acpi_add_id(&device->pnp, ACPI_SMBUS_IBM_HID); acpi_add_id(pnp, ACPI_SMBUS_IBM_HID);
else if (list_empty(&device->pnp.ids) && else if (list_empty(&pnp->ids) && handle == ACPI_ROOT_OBJECT) {
ACPI_IS_ROOT_DEVICE(device->parent)) { acpi_add_id(pnp, ACPI_BUS_HID); /* \_SB, LNXSYBUS */
acpi_add_id(&device->pnp, ACPI_BUS_HID); /* \_SB, LNXSYBUS */ strcpy(pnp->device_name, ACPI_BUS_DEVICE_NAME);
strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME); strcpy(pnp->device_class, ACPI_BUS_CLASS);
strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
} }
break; break;
case ACPI_BUS_TYPE_POWER: case ACPI_BUS_TYPE_POWER:
acpi_add_id(&device->pnp, ACPI_POWER_HID); acpi_add_id(pnp, ACPI_POWER_HID);
break; break;
case ACPI_BUS_TYPE_PROCESSOR: case ACPI_BUS_TYPE_PROCESSOR:
acpi_add_id(&device->pnp, ACPI_PROCESSOR_OBJECT_HID); acpi_add_id(pnp, ACPI_PROCESSOR_OBJECT_HID);
break; break;
case ACPI_BUS_TYPE_THERMAL: case ACPI_BUS_TYPE_THERMAL:
acpi_add_id(&device->pnp, ACPI_THERMAL_HID); acpi_add_id(pnp, ACPI_THERMAL_HID);
break; break;
case ACPI_BUS_TYPE_POWER_BUTTON: case ACPI_BUS_TYPE_POWER_BUTTON:
acpi_add_id(&device->pnp, ACPI_BUTTON_HID_POWERF); acpi_add_id(pnp, ACPI_BUTTON_HID_POWERF);
break; break;
case ACPI_BUS_TYPE_SLEEP_BUTTON: case ACPI_BUS_TYPE_SLEEP_BUTTON:
acpi_add_id(&device->pnp, ACPI_BUTTON_HID_SLEEPF); acpi_add_id(pnp, ACPI_BUTTON_HID_SLEEPF);
break; break;
} }
} }
void acpi_free_pnp_ids(struct acpi_device_pnp *pnp)
{
struct acpi_hardware_id *id, *tmp;
list_for_each_entry_safe(id, tmp, &pnp->ids, list) {
kfree(id->id);
kfree(id);
}
kfree(pnp->unique_id);
}
void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
int type, unsigned long long sta) int type, unsigned long long sta)
{ {
@ -1597,7 +1598,7 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
device->parent = acpi_bus_get_parent(handle); device->parent = acpi_bus_get_parent(handle);
STRUCT_TO_INT(device->status) = sta; STRUCT_TO_INT(device->status) = sta;
acpi_device_get_busid(device); acpi_device_get_busid(device);
acpi_device_set_id(device); acpi_set_pnp_ids(handle, &device->pnp, type);
acpi_bus_get_flags(device); acpi_bus_get_flags(device);
device->flags.match_driver = false; device->flags.match_driver = false;
device_initialize(&device->dev); device_initialize(&device->dev);