Merge branches 'acpi-scan', 'acpi-drivers', 'acpi-pm' and 'acpi-resources'

* acpi-scan:
  ACPI: bus: Introduce acpi_dev_get() and reuse it in ACPI code
  ACPI: scan: Utilize match_string() API
  ACPI: scan: Call acpi_get_object_info() from acpi_set_pnp_ids()
  ACPI: scan: Drop sta argument from acpi_init_device_object()
  ACPI: scan: Drop sta argument from acpi_add_single_object()
  ACPI: scan: Rearrange checks in acpi_bus_check_add()
  ACPI: scan: Fold acpi_bus_type_and_status() into its caller

* acpi-drivers:
  ACPI: HED: Drop unused ACPI_MODULE_NAME() definition

* acpi-pm:
  ACPI: power: Turn off unused power resources unconditionally
  ACPI: scan: Turn off unused power resources during initialization

* acpi-resources:
  resource: Prevent irqresource_disabled() from erasing flags
This commit is contained in:
Rafael J. Wysocki 2021-04-26 17:03:46 +02:00
Коммит 0b2212596d
9 изменённых файлов: 90 добавлений и 129 удалений

Просмотреть файл

@ -376,12 +376,12 @@ eject_store(struct device *d, struct device_attribute *attr,
if (ACPI_FAILURE(status) || !acpi_device->flags.ejectable) if (ACPI_FAILURE(status) || !acpi_device->flags.ejectable)
return -ENODEV; return -ENODEV;
get_device(&acpi_device->dev); acpi_dev_get(acpi_device);
status = acpi_hotplug_schedule(acpi_device, ACPI_OST_EC_OSPM_EJECT); status = acpi_hotplug_schedule(acpi_device, ACPI_OST_EC_OSPM_EJECT);
if (ACPI_SUCCESS(status)) if (ACPI_SUCCESS(status))
return count; return count;
put_device(&acpi_device->dev); acpi_dev_put(acpi_device);
acpi_evaluate_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT, acpi_evaluate_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT,
ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL); ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL);
return status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN; return status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN;

Просмотреть файл

@ -190,7 +190,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
if (!acpi_dev) if (!acpi_dev)
return -EINVAL; return -EINVAL;
get_device(&acpi_dev->dev); acpi_dev_get(acpi_dev);
get_device(dev); get_device(dev);
physical_node = kzalloc(sizeof(*physical_node), GFP_KERNEL); physical_node = kzalloc(sizeof(*physical_node), GFP_KERNEL);
if (!physical_node) { if (!physical_node) {
@ -217,7 +217,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
goto err; goto err;
put_device(dev); put_device(dev);
put_device(&acpi_dev->dev); acpi_dev_put(acpi_dev);
return 0; return 0;
} }
if (pn->node_id == node_id) { if (pn->node_id == node_id) {
@ -257,7 +257,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
err: err:
ACPI_COMPANION_SET(dev, NULL); ACPI_COMPANION_SET(dev, NULL);
put_device(dev); put_device(dev);
put_device(&acpi_dev->dev); acpi_dev_put(acpi_dev);
return retval; return retval;
} }
EXPORT_SYMBOL_GPL(acpi_bind_one); EXPORT_SYMBOL_GPL(acpi_bind_one);
@ -285,7 +285,7 @@ int acpi_unbind_one(struct device *dev)
ACPI_COMPANION_SET(dev, NULL); ACPI_COMPANION_SET(dev, NULL);
/* Drop references taken by acpi_bind_one(). */ /* Drop references taken by acpi_bind_one(). */
put_device(dev); put_device(dev);
put_device(&acpi_dev->dev); acpi_dev_put(acpi_dev);
kfree(entry); kfree(entry);
break; break;
} }

Просмотреть файл

@ -74,7 +74,6 @@ static struct acpi_driver acpi_hed_driver = {
}; };
module_acpi_driver(acpi_hed_driver); module_acpi_driver(acpi_hed_driver);
ACPI_MODULE_NAME("hed");
MODULE_AUTHOR("Huang Ying"); MODULE_AUTHOR("Huang Ying");
MODULE_DESCRIPTION("ACPI Hardware Error Device Driver"); MODULE_DESCRIPTION("ACPI Hardware Error Device Driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");

Просмотреть файл

@ -109,8 +109,7 @@ struct acpi_device_bus_id {
int acpi_device_add(struct acpi_device *device, int acpi_device_add(struct acpi_device *device,
void (*release)(struct device *)); void (*release)(struct 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);
struct acpi_device_info *info);
int acpi_device_setup_files(struct acpi_device *dev); int acpi_device_setup_files(struct acpi_device *dev);
void acpi_device_remove_files(struct acpi_device *dev); void acpi_device_remove_files(struct acpi_device *dev);
void acpi_device_add_finalize(struct acpi_device *device); void acpi_device_add_finalize(struct acpi_device *device);
@ -143,6 +142,7 @@ int acpi_device_sleep_wake(struct acpi_device *dev,
int acpi_power_get_inferred_state(struct acpi_device *device, int *state); int acpi_power_get_inferred_state(struct acpi_device *device, int *state);
int acpi_power_on_resources(struct acpi_device *device, int state); int acpi_power_on_resources(struct acpi_device *device, int state);
int acpi_power_transition(struct acpi_device *device, int state); int acpi_power_transition(struct acpi_device *device, int state);
void acpi_turn_off_unused_power_resources(void);
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
Device Power Management Device Power Management

Просмотреть файл

@ -925,8 +925,7 @@ int acpi_add_power_resource(acpi_handle handle)
return -ENOMEM; return -ENOMEM;
device = &resource->device; device = &resource->device;
acpi_init_device_object(device, handle, ACPI_BUS_TYPE_POWER, acpi_init_device_object(device, handle, ACPI_BUS_TYPE_POWER);
ACPI_STA_DEFAULT, NULL);
mutex_init(&resource->resource_lock); mutex_init(&resource->resource_lock);
INIT_LIST_HEAD(&resource->list_node); INIT_LIST_HEAD(&resource->list_node);
INIT_LIST_HEAD(&resource->dependents); INIT_LIST_HEAD(&resource->dependents);
@ -996,6 +995,7 @@ void acpi_resume_power_resources(void)
mutex_unlock(&power_resource_list_lock); mutex_unlock(&power_resource_list_lock);
} }
#endif
void acpi_turn_off_unused_power_resources(void) void acpi_turn_off_unused_power_resources(void)
{ {
@ -1004,18 +1004,9 @@ void acpi_turn_off_unused_power_resources(void)
mutex_lock(&power_resource_list_lock); mutex_lock(&power_resource_list_lock);
list_for_each_entry_reverse(resource, &acpi_power_resource_list, list_node) { list_for_each_entry_reverse(resource, &acpi_power_resource_list, list_node) {
int result, state;
mutex_lock(&resource->resource_lock); mutex_lock(&resource->resource_lock);
result = acpi_power_get_state(resource->device.handle, &state); if (!resource->ref_count) {
if (result) {
mutex_unlock(&resource->resource_lock);
continue;
}
if (state == ACPI_POWER_RESOURCE_STATE_ON
&& !resource->ref_count) {
dev_info(&resource->device.dev, "Turning OFF\n"); dev_info(&resource->device.dev, "Turning OFF\n");
__acpi_power_off(resource); __acpi_power_off(resource);
} }
@ -1025,4 +1016,3 @@ void acpi_turn_off_unused_power_resources(void)
mutex_unlock(&power_resource_list_lock); mutex_unlock(&power_resource_list_lock);
} }
#endif

Просмотреть файл

@ -530,7 +530,7 @@ static void acpi_device_del_work_fn(struct work_struct *work_not_used)
* used by the device. * used by the device.
*/ */
acpi_power_transition(adev, ACPI_STATE_D3_COLD); acpi_power_transition(adev, ACPI_STATE_D3_COLD);
put_device(&adev->dev); acpi_dev_put(adev);
} }
} }
@ -604,8 +604,7 @@ EXPORT_SYMBOL(acpi_bus_get_device);
static void get_acpi_device(void *dev) static void get_acpi_device(void *dev)
{ {
if (dev) acpi_dev_get(dev);
get_device(&((struct acpi_device *)dev)->dev);
} }
struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle) struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)
@ -615,7 +614,7 @@ struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)
void acpi_bus_put_acpi_device(struct acpi_device *adev) void acpi_bus_put_acpi_device(struct acpi_device *adev)
{ {
put_device(&adev->dev); acpi_dev_put(adev);
} }
static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id) static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id)
@ -757,27 +756,25 @@ static bool acpi_info_matches_ids(struct acpi_device_info *info,
const char * const ids[]) const char * const ids[])
{ {
struct acpi_pnp_device_id_list *cid_list = NULL; struct acpi_pnp_device_id_list *cid_list = NULL;
int i; int i, index;
if (!(info->valid & ACPI_VALID_HID)) if (!(info->valid & ACPI_VALID_HID))
return false; return false;
index = match_string(ids, -1, info->hardware_id.string);
if (index >= 0)
return true;
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; ids[i]; i++) { if (!cid_list)
int j; return false;
if (!strcmp(info->hardware_id.string, ids[i])) for (i = 0; i < cid_list->count; i++) {
index = match_string(ids, -1, cid_list->ids[i].string);
if (index >= 0)
return true; return true;
if (!cid_list)
continue;
for (j = 0; j < cid_list->count; j++) {
if (!strcmp(cid_list->ids[j].string, ids[i]))
return true;
}
} }
return false; return false;
@ -1307,8 +1304,9 @@ static bool acpi_object_is_system_bus(acpi_handle handle)
} }
static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp, static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
int device_type, struct acpi_device_info *info) int device_type)
{ {
struct acpi_device_info *info = NULL;
struct acpi_pnp_device_id_list *cid_list; struct acpi_pnp_device_id_list *cid_list;
int i; int i;
@ -1319,6 +1317,7 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
break; break;
} }
acpi_get_object_info(handle, &info);
if (!info) { if (!info) {
pr_err(PREFIX "%s: Error reading device info\n", pr_err(PREFIX "%s: Error reading device info\n",
__func__); __func__);
@ -1344,6 +1343,8 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
if (info->valid & ACPI_VALID_CLS) if (info->valid & ACPI_VALID_CLS)
acpi_add_id(pnp, info->class_code.string); acpi_add_id(pnp, info->class_code.string);
kfree(info);
/* /*
* 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.
@ -1649,17 +1650,16 @@ static bool acpi_device_enumeration_by_parent(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)
struct acpi_device_info *info)
{ {
INIT_LIST_HEAD(&device->pnp.ids); INIT_LIST_HEAD(&device->pnp.ids);
device->device_type = type; device->device_type = type;
device->handle = handle; device->handle = handle;
device->parent = acpi_bus_get_parent(handle); device->parent = acpi_bus_get_parent(handle);
fwnode_init(&device->fwnode, &acpi_device_fwnode_ops); fwnode_init(&device->fwnode, &acpi_device_fwnode_ops);
acpi_set_device_status(device, sta); acpi_set_device_status(device, ACPI_STA_DEFAULT);
acpi_device_get_busid(device); acpi_device_get_busid(device);
acpi_set_pnp_ids(handle, &device->pnp, type, info); acpi_set_pnp_ids(handle, &device->pnp, type);
acpi_init_properties(device); acpi_init_properties(device);
acpi_bus_get_flags(device); acpi_bus_get_flags(device);
device->flags.match_driver = false; device->flags.match_driver = false;
@ -1680,33 +1680,30 @@ void acpi_device_add_finalize(struct acpi_device *device)
kobject_uevent(&device->dev.kobj, KOBJ_ADD); kobject_uevent(&device->dev.kobj, KOBJ_ADD);
} }
static int acpi_add_single_object(struct acpi_device **child, static void acpi_scan_init_status(struct acpi_device *adev)
acpi_handle handle, int type, {
unsigned long long sta) if (acpi_bus_get_status(adev))
acpi_set_device_status(adev, 0);
}
static int acpi_add_single_object(struct acpi_device **child,
acpi_handle handle, int type)
{ {
struct acpi_device_info *info = NULL;
struct acpi_device *device; struct acpi_device *device;
int result; int result;
if (handle != ACPI_ROOT_OBJECT && type == ACPI_BUS_TYPE_DEVICE)
acpi_get_object_info(handle, &info);
device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL); device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
if (!device) { if (!device)
kfree(info);
return -ENOMEM; return -ENOMEM;
}
acpi_init_device_object(device, handle, type, sta, info); acpi_init_device_object(device, handle, type);
kfree(info);
/* /*
* For ACPI_BUS_TYPE_DEVICE getting the status is delayed till here so * Getting the status is delayed till here so that we can call
* that we can call acpi_bus_get_status() and use its quirk handling. * acpi_bus_get_status() and use its quirk handling. Note that
* Note this must be done before the get power-/wakeup_dev-flags calls. * this must be done before the get power-/wakeup_dev-flags calls.
*/ */
if (type == ACPI_BUS_TYPE_DEVICE) if (type == ACPI_BUS_TYPE_DEVICE || type == ACPI_BUS_TYPE_PROCESSOR)
if (acpi_bus_get_status(device) < 0) acpi_scan_init_status(device);
acpi_set_device_status(device, 0);
acpi_bus_get_power_flags(device); acpi_bus_get_power_flags(device);
acpi_bus_get_wakeup_device_flags(device); acpi_bus_get_wakeup_device_flags(device);
@ -1763,50 +1760,6 @@ static bool acpi_device_should_be_hidden(acpi_handle handle)
return true; return true;
} }
static int acpi_bus_type_and_status(acpi_handle handle, int *type,
unsigned long long *sta)
{
acpi_status status;
acpi_object_type acpi_type;
status = acpi_get_type(handle, &acpi_type);
if (ACPI_FAILURE(status))
return -ENODEV;
switch (acpi_type) {
case ACPI_TYPE_ANY: /* for ACPI_ROOT_OBJECT */
case ACPI_TYPE_DEVICE:
if (acpi_device_should_be_hidden(handle))
return -ENODEV;
*type = ACPI_BUS_TYPE_DEVICE;
/*
* acpi_add_single_object updates this once we've an acpi_device
* so that acpi_bus_get_status' quirk handling can be used.
*/
*sta = ACPI_STA_DEFAULT;
break;
case ACPI_TYPE_PROCESSOR:
*type = ACPI_BUS_TYPE_PROCESSOR;
status = acpi_bus_get_status_handle(handle, sta);
if (ACPI_FAILURE(status))
return -ENODEV;
break;
case ACPI_TYPE_THERMAL:
*type = ACPI_BUS_TYPE_THERMAL;
*sta = ACPI_STA_DEFAULT;
break;
case ACPI_TYPE_POWER:
*type = ACPI_BUS_TYPE_POWER;
*sta = ACPI_STA_DEFAULT;
break;
default:
return -ENODEV;
}
return 0;
}
bool acpi_device_is_present(const struct acpi_device *adev) bool acpi_device_is_present(const struct acpi_device *adev)
{ {
return adev->status.present || adev->status.functional; return adev->status.present || adev->status.functional;
@ -1875,7 +1828,7 @@ static void acpi_scan_init_hotplug(struct acpi_device *adev)
} }
} }
static u32 acpi_scan_check_dep(acpi_handle handle) static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)
{ {
struct acpi_handle_list dep_devices; struct acpi_handle_list dep_devices;
acpi_status status; acpi_status status;
@ -1888,7 +1841,8 @@ static u32 acpi_scan_check_dep(acpi_handle handle)
* 2. ACPI nodes describing USB ports. * 2. ACPI nodes describing USB ports.
* Still, checking for _HID catches more then just these cases ... * Still, checking for _HID catches more then just these cases ...
*/ */
if (!acpi_has_method(handle, "_DEP") || !acpi_has_method(handle, "_HID")) if (!check_dep || !acpi_has_method(handle, "_DEP") ||
!acpi_has_method(handle, "_HID"))
return 0; return 0;
status = acpi_evaluate_reference(handle, "_DEP", NULL, &dep_devices); status = acpi_evaluate_reference(handle, "_DEP", NULL, &dep_devices);
@ -1953,33 +1907,48 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, bool check_dep,
struct acpi_device **adev_p) struct acpi_device **adev_p)
{ {
struct acpi_device *device = NULL; struct acpi_device *device = NULL;
unsigned long long sta; acpi_object_type acpi_type;
int type; int type;
int result;
acpi_bus_get_device(handle, &device); acpi_bus_get_device(handle, &device);
if (device) if (device)
goto out; goto out;
result = acpi_bus_type_and_status(handle, &type, &sta); if (ACPI_FAILURE(acpi_get_type(handle, &acpi_type)))
if (result)
return AE_OK; return AE_OK;
if (type == ACPI_BUS_TYPE_POWER) { switch (acpi_type) {
acpi_add_power_resource(handle); case ACPI_TYPE_DEVICE:
return AE_OK; if (acpi_device_should_be_hidden(handle))
} return AE_OK;
if (type == ACPI_BUS_TYPE_DEVICE && check_dep) { /* Bail out if there are dependencies. */
u32 count = acpi_scan_check_dep(handle); if (acpi_scan_check_dep(handle, check_dep) > 0) {
/* Bail out if the number of recorded dependencies is not 0. */
if (count > 0) {
acpi_bus_scan_second_pass = true; acpi_bus_scan_second_pass = true;
return AE_CTRL_DEPTH; return AE_CTRL_DEPTH;
} }
fallthrough;
case ACPI_TYPE_ANY: /* for ACPI_ROOT_OBJECT */
type = ACPI_BUS_TYPE_DEVICE;
break;
case ACPI_TYPE_PROCESSOR:
type = ACPI_BUS_TYPE_PROCESSOR;
break;
case ACPI_TYPE_THERMAL:
type = ACPI_BUS_TYPE_THERMAL;
break;
case ACPI_TYPE_POWER:
acpi_add_power_resource(handle);
fallthrough;
default:
return AE_OK;
} }
acpi_add_single_object(&device, handle, type, sta); acpi_add_single_object(&device, handle, type);
if (!device) if (!device)
return AE_CTRL_DEPTH; return AE_CTRL_DEPTH;
@ -2253,8 +2222,7 @@ int acpi_bus_register_early_device(int type)
struct acpi_device *device = NULL; struct acpi_device *device = NULL;
int result; int result;
result = acpi_add_single_object(&device, NULL, result = acpi_add_single_object(&device, NULL, type);
type, ACPI_STA_DEFAULT);
if (result) if (result)
return result; return result;
@ -2274,8 +2242,7 @@ static int acpi_bus_scan_fixed(void)
struct acpi_device *device = NULL; struct acpi_device *device = NULL;
result = acpi_add_single_object(&device, NULL, result = acpi_add_single_object(&device, NULL,
ACPI_BUS_TYPE_POWER_BUTTON, ACPI_BUS_TYPE_POWER_BUTTON);
ACPI_STA_DEFAULT);
if (result) if (result)
return result; return result;
@ -2291,8 +2258,7 @@ static int acpi_bus_scan_fixed(void)
struct acpi_device *device = NULL; struct acpi_device *device = NULL;
result = acpi_add_single_object(&device, NULL, result = acpi_add_single_object(&device, NULL,
ACPI_BUS_TYPE_SLEEP_BUTTON, ACPI_BUS_TYPE_SLEEP_BUTTON);
ACPI_STA_DEFAULT);
if (result) if (result)
return result; return result;
@ -2388,11 +2354,13 @@ int __init acpi_scan_init(void)
acpi_detach_data(acpi_root->handle, acpi_detach_data(acpi_root->handle,
acpi_scan_drop_device); acpi_scan_drop_device);
acpi_device_del(acpi_root); acpi_device_del(acpi_root);
put_device(&acpi_root->dev); acpi_bus_put_acpi_device(acpi_root);
goto out; goto out;
} }
} }
acpi_turn_off_unused_power_resources();
acpi_scan_initialized = true; acpi_scan_initialized = true;
out: out:

Просмотреть файл

@ -8,7 +8,6 @@ extern struct list_head acpi_wakeup_device_list;
extern struct mutex acpi_device_lock; extern struct mutex acpi_device_lock;
extern void acpi_resume_power_resources(void); extern void acpi_resume_power_resources(void);
extern void acpi_turn_off_unused_power_resources(void);
static inline acpi_status acpi_set_waking_vector(u32 wakeup_address) static inline acpi_status acpi_set_waking_vector(u32 wakeup_address)
{ {

Просмотреть файл

@ -694,6 +694,11 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
adev; \ adev; \
adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv)) adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv))
static inline struct acpi_device *acpi_dev_get(struct acpi_device *adev)
{
return adev ? to_acpi_device(get_device(&adev->dev)) : NULL;
}
static inline void acpi_dev_put(struct acpi_device *adev) static inline void acpi_dev_put(struct acpi_device *adev)
{ {
put_device(&adev->dev); put_device(&adev->dev);

Просмотреть файл

@ -331,7 +331,7 @@ static inline void irqresource_disabled(struct resource *res, u32 irq)
{ {
res->start = irq; res->start = irq;
res->end = irq; res->end = irq;
res->flags = IORESOURCE_IRQ | IORESOURCE_DISABLED | IORESOURCE_UNSET; res->flags |= IORESOURCE_IRQ | IORESOURCE_DISABLED | IORESOURCE_UNSET;
} }
extern struct address_space *iomem_get_mapping(void); extern struct address_space *iomem_get_mapping(void);