Merge branch 'acpi-scan' into acpi-messages
This commit is contained in:
commit
c888065119
|
@ -578,29 +578,31 @@ static void acpi_scan_drop_device(acpi_handle handle, void *context)
|
||||||
mutex_unlock(&acpi_device_del_lock);
|
mutex_unlock(&acpi_device_del_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int acpi_get_device_data(acpi_handle handle, struct acpi_device **device,
|
static struct acpi_device *handle_to_device(acpi_handle handle,
|
||||||
void (*callback)(void *))
|
void (*callback)(void *))
|
||||||
{
|
{
|
||||||
|
struct acpi_device *adev = NULL;
|
||||||
acpi_status status;
|
acpi_status status;
|
||||||
|
|
||||||
if (!device)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
*device = NULL;
|
|
||||||
|
|
||||||
status = acpi_get_data_full(handle, acpi_scan_drop_device,
|
status = acpi_get_data_full(handle, acpi_scan_drop_device,
|
||||||
(void **)device, callback);
|
(void **)&adev, callback);
|
||||||
if (ACPI_FAILURE(status) || !*device) {
|
if (ACPI_FAILURE(status) || !adev) {
|
||||||
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
|
acpi_handle_debug(handle, "No context!\n");
|
||||||
handle));
|
return NULL;
|
||||||
return -ENODEV;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return adev;
|
||||||
}
|
}
|
||||||
|
|
||||||
int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
|
int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
|
||||||
{
|
{
|
||||||
return acpi_get_device_data(handle, device, NULL);
|
if (!device)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
*device = handle_to_device(handle, NULL);
|
||||||
|
if (!*device)
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(acpi_bus_get_device);
|
EXPORT_SYMBOL(acpi_bus_get_device);
|
||||||
|
|
||||||
|
@ -612,10 +614,7 @@ static void get_acpi_device(void *dev)
|
||||||
|
|
||||||
struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)
|
struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)
|
||||||
{
|
{
|
||||||
struct acpi_device *adev = NULL;
|
return handle_to_device(handle, get_acpi_device);
|
||||||
|
|
||||||
acpi_get_device_data(handle, &adev, get_acpi_device);
|
|
||||||
return adev;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void acpi_bus_put_acpi_device(struct acpi_device *adev)
|
void acpi_bus_put_acpi_device(struct acpi_device *adev)
|
||||||
|
@ -623,12 +622,23 @@ void acpi_bus_put_acpi_device(struct acpi_device *adev)
|
||||||
put_device(&adev->dev);
|
put_device(&adev->dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id)
|
||||||
|
{
|
||||||
|
struct acpi_device_bus_id *acpi_device_bus_id;
|
||||||
|
|
||||||
|
/* Find suitable bus_id and instance number in acpi_bus_id_list. */
|
||||||
|
list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
|
||||||
|
if (!strcmp(acpi_device_bus_id->bus_id, dev_id))
|
||||||
|
return acpi_device_bus_id;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int acpi_device_add(struct acpi_device *device,
|
int acpi_device_add(struct acpi_device *device,
|
||||||
void (*release)(struct device *))
|
void (*release)(struct device *))
|
||||||
{
|
{
|
||||||
|
struct acpi_device_bus_id *acpi_device_bus_id;
|
||||||
int result;
|
int result;
|
||||||
struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
|
|
||||||
int found = 0;
|
|
||||||
|
|
||||||
if (device->handle) {
|
if (device->handle) {
|
||||||
acpi_status status;
|
acpi_status status;
|
||||||
|
@ -654,38 +664,26 @@ int acpi_device_add(struct acpi_device *device,
|
||||||
INIT_LIST_HEAD(&device->del_list);
|
INIT_LIST_HEAD(&device->del_list);
|
||||||
mutex_init(&device->physical_node_lock);
|
mutex_init(&device->physical_node_lock);
|
||||||
|
|
||||||
new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
|
|
||||||
if (!new_bus_id) {
|
|
||||||
pr_err(PREFIX "Memory allocation error\n");
|
|
||||||
result = -ENOMEM;
|
|
||||||
goto err_detach;
|
|
||||||
}
|
|
||||||
|
|
||||||
mutex_lock(&acpi_device_lock);
|
mutex_lock(&acpi_device_lock);
|
||||||
/*
|
|
||||||
* Find suitable bus_id and instance number in acpi_bus_id_list
|
acpi_device_bus_id = acpi_device_bus_id_match(acpi_device_hid(device));
|
||||||
* If failed, create one and link it into acpi_bus_id_list
|
if (acpi_device_bus_id) {
|
||||||
*/
|
acpi_device_bus_id->instance_no++;
|
||||||
list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
|
} else {
|
||||||
if (!strcmp(acpi_device_bus_id->bus_id,
|
acpi_device_bus_id = kzalloc(sizeof(*acpi_device_bus_id),
|
||||||
acpi_device_hid(device))) {
|
GFP_KERNEL);
|
||||||
acpi_device_bus_id->instance_no++;
|
if (!acpi_device_bus_id) {
|
||||||
found = 1;
|
result = -ENOMEM;
|
||||||
kfree(new_bus_id);
|
goto err_unlock;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
acpi_device_bus_id = new_bus_id;
|
|
||||||
acpi_device_bus_id->bus_id =
|
acpi_device_bus_id->bus_id =
|
||||||
kstrdup_const(acpi_device_hid(device), GFP_KERNEL);
|
kstrdup_const(acpi_device_hid(device), GFP_KERNEL);
|
||||||
if (!acpi_device_bus_id->bus_id) {
|
if (!acpi_device_bus_id->bus_id) {
|
||||||
pr_err(PREFIX "Memory allocation error for bus id\n");
|
kfree(acpi_device_bus_id);
|
||||||
result = -ENOMEM;
|
result = -ENOMEM;
|
||||||
goto err_free_new_bus_id;
|
goto err_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
acpi_device_bus_id->instance_no = 0;
|
|
||||||
list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
|
list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
|
||||||
}
|
}
|
||||||
dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
|
dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
|
||||||
|
@ -695,10 +693,12 @@ int acpi_device_add(struct acpi_device *device,
|
||||||
|
|
||||||
if (device->wakeup.flags.valid)
|
if (device->wakeup.flags.valid)
|
||||||
list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
|
list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
|
||||||
|
|
||||||
mutex_unlock(&acpi_device_lock);
|
mutex_unlock(&acpi_device_lock);
|
||||||
|
|
||||||
if (device->parent)
|
if (device->parent)
|
||||||
device->dev.parent = &device->parent->dev;
|
device->dev.parent = &device->parent->dev;
|
||||||
|
|
||||||
device->dev.bus = &acpi_bus_type;
|
device->dev.bus = &acpi_bus_type;
|
||||||
device->dev.release = release;
|
device->dev.release = release;
|
||||||
result = device_add(&device->dev);
|
result = device_add(&device->dev);
|
||||||
|
@ -714,20 +714,19 @@ int acpi_device_add(struct acpi_device *device,
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
mutex_lock(&acpi_device_lock);
|
mutex_lock(&acpi_device_lock);
|
||||||
|
|
||||||
if (device->parent)
|
if (device->parent)
|
||||||
list_del(&device->node);
|
list_del(&device->node);
|
||||||
|
|
||||||
list_del(&device->wakeup_list);
|
list_del(&device->wakeup_list);
|
||||||
|
|
||||||
err_free_new_bus_id:
|
err_unlock:
|
||||||
if (!found)
|
|
||||||
kfree(new_bus_id);
|
|
||||||
|
|
||||||
mutex_unlock(&acpi_device_lock);
|
mutex_unlock(&acpi_device_lock);
|
||||||
|
|
||||||
err_detach:
|
|
||||||
acpi_detach_data(device->handle, acpi_scan_drop_device);
|
acpi_detach_data(device->handle, acpi_scan_drop_device);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue