Skip to content

Commit

Permalink
Merge branch 'acpi-scan' into acpi-x86
Browse files Browse the repository at this point in the history
Merge recent device enumeration changes to satisfy dependencies.
  • Loading branch information
Rafael J. Wysocki committed Jan 4, 2022
2 parents 9f68756 + 0890186 commit 8e0feb2
Show file tree
Hide file tree
Showing 18 changed files with 238 additions and 82 deletions.
5 changes: 2 additions & 3 deletions drivers/acpi/acpi_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -1733,13 +1733,12 @@ acpi_video_bus_match(acpi_handle handle, u32 level, void *context,
{
struct acpi_device *device = context;
struct acpi_device *sibling;
int result;

if (handle == device->handle)
return AE_CTRL_TERMINATE;

result = acpi_bus_get_device(handle, &sibling);
if (result)
sibling = acpi_fetch_acpi_dev(handle);
if (!sibling)
return AE_OK;

if (!strcmp(acpi_device_name(sibling), ACPI_VIDEO_BUS_NAME))
Expand Down
31 changes: 13 additions & 18 deletions drivers/acpi/device_pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,12 @@ EXPORT_SYMBOL(acpi_device_set_power);

int acpi_bus_set_power(acpi_handle handle, int state)
{
struct acpi_device *device;
int result;
struct acpi_device *device = acpi_fetch_acpi_dev(handle);

result = acpi_bus_get_device(handle, &device);
if (result)
return result;
if (device)
return acpi_device_set_power(device, state);

return acpi_device_set_power(device, state);
return -ENODEV;
}
EXPORT_SYMBOL(acpi_bus_set_power);

Expand Down Expand Up @@ -410,21 +408,20 @@ EXPORT_SYMBOL_GPL(acpi_device_update_power);

int acpi_bus_update_power(acpi_handle handle, int *state_p)
{
struct acpi_device *device;
int result;
struct acpi_device *device = acpi_fetch_acpi_dev(handle);

result = acpi_bus_get_device(handle, &device);
return result ? result : acpi_device_update_power(device, state_p);
if (device)
return acpi_device_update_power(device, state_p);

return -ENODEV;
}
EXPORT_SYMBOL_GPL(acpi_bus_update_power);

bool acpi_bus_power_manageable(acpi_handle handle)
{
struct acpi_device *device;
int result;
struct acpi_device *device = acpi_fetch_acpi_dev(handle);

result = acpi_bus_get_device(handle, &device);
return result ? false : device->flags.power_manageable;
return device && device->flags.power_manageable;
}
EXPORT_SYMBOL(acpi_bus_power_manageable);

Expand Down Expand Up @@ -543,11 +540,9 @@ acpi_status acpi_remove_pm_notifier(struct acpi_device *adev)

bool acpi_bus_can_wakeup(acpi_handle handle)
{
struct acpi_device *device;
int result;
struct acpi_device *device = acpi_fetch_acpi_dev(handle);

result = acpi_bus_get_device(handle, &device);
return result ? false : device->wakeup.flags.valid;
return device && device->wakeup.flags.valid;
}
EXPORT_SYMBOL(acpi_bus_can_wakeup);

Expand Down
3 changes: 1 addition & 2 deletions drivers/acpi/dock.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,8 @@ static ssize_t docked_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dock_station *dock_station = dev->platform_data;
struct acpi_device *adev = NULL;
struct acpi_device *adev = acpi_fetch_acpi_dev(dock_station->handle);

acpi_bus_get_device(dock_station->handle, &adev);
return sysfs_emit(buf, "%u\n", acpi_device_enumerated(adev));
}
static DEVICE_ATTR_RO(docked);
Expand Down
12 changes: 4 additions & 8 deletions drivers/acpi/pci_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,12 +606,10 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering,
int *polarity, char **name)
{
int result;
struct acpi_device *device;
struct acpi_device *device = acpi_fetch_acpi_dev(handle);
struct acpi_pci_link *link;

result = acpi_bus_get_device(handle, &device);
if (result) {
if (!device) {
acpi_handle_err(handle, "Invalid link device\n");
return -1;
}
Expand Down Expand Up @@ -658,12 +656,10 @@ int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering,
*/
int acpi_pci_link_free_irq(acpi_handle handle)
{
struct acpi_device *device;
struct acpi_device *device = acpi_fetch_acpi_dev(handle);
struct acpi_pci_link *link;
acpi_status result;

result = acpi_bus_get_device(handle, &device);
if (result) {
if (!device) {
acpi_handle_err(handle, "Invalid link device\n");
return -1;
}
Expand Down
10 changes: 4 additions & 6 deletions drivers/acpi/pci_root.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ static struct acpi_scan_handler pci_root_handler = {
*/
int acpi_is_root_bridge(acpi_handle handle)
{
struct acpi_device *device = acpi_fetch_acpi_dev(handle);
int ret;
struct acpi_device *device;

ret = acpi_bus_get_device(handle, &device);
if (ret)
if (!device)
return 0;

ret = acpi_match_device_ids(device, root_device_ids);
Expand Down Expand Up @@ -215,11 +214,10 @@ static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root,

struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle)
{
struct acpi_device *device = acpi_fetch_acpi_dev(handle);
struct acpi_pci_root *root;
struct acpi_device *device;

if (acpi_bus_get_device(handle, &device) ||
acpi_match_device_ids(device, root_device_ids))
if (!device || acpi_match_device_ids(device, root_device_ids))
return NULL;

root = acpi_driver_data(device);
Expand Down
7 changes: 3 additions & 4 deletions drivers/acpi/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ struct acpi_power_resource *to_power_resource(struct acpi_device *device)

static struct acpi_power_resource *acpi_power_get_context(acpi_handle handle)
{
struct acpi_device *device;
struct acpi_device *device = acpi_fetch_acpi_dev(handle);

if (acpi_bus_get_device(handle, &device))
if (!device)
return NULL;

return to_power_resource(device);
Expand Down Expand Up @@ -916,15 +916,14 @@ static void acpi_power_add_resource_to_list(struct acpi_power_resource *resource

struct acpi_device *acpi_add_power_resource(acpi_handle handle)
{
struct acpi_device *device = acpi_fetch_acpi_dev(handle);
struct acpi_power_resource *resource;
struct acpi_device *device = NULL;
union acpi_object acpi_object;
struct acpi_buffer buffer = { sizeof(acpi_object), &acpi_object };
acpi_status status;
u8 state_dummy;
int result;

acpi_bus_get_device(handle, &device);
if (device)
return device;

Expand Down
10 changes: 7 additions & 3 deletions drivers/acpi/processor_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ static int acpi_soft_cpu_online(unsigned int cpu)
struct acpi_processor *pr = per_cpu(processors, cpu);
struct acpi_device *device;

if (!pr || acpi_bus_get_device(pr->handle, &device))
if (!pr)
return 0;

device = acpi_fetch_acpi_dev(pr->handle);
if (!device)
return 0;

/*
* CPU got physically hotplugged and onlined for the first time:
* Initialize missing things.
Expand All @@ -125,9 +130,8 @@ static int acpi_soft_cpu_online(unsigned int cpu)
static int acpi_soft_cpu_dead(unsigned int cpu)
{
struct acpi_processor *pr = per_cpu(processors, cpu);
struct acpi_device *device;

if (!pr || acpi_bus_get_device(pr->handle, &device))
if (!pr || !acpi_fetch_acpi_dev(pr->handle))
return 0;

acpi_processor_reevaluate_tstate(pr, true);
Expand Down
2 changes: 1 addition & 1 deletion drivers/acpi/processor_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ static int acpi_processor_get_lpi_info(struct acpi_processor *pr)

status = acpi_get_parent(handle, &pr_ahandle);
while (ACPI_SUCCESS(status)) {
acpi_bus_get_device(pr_ahandle, &d);
d = acpi_fetch_acpi_dev(pr_ahandle);
handle = pr_ahandle;

if (strcmp(acpi_device_hid(d), ACPI_PROCESSOR_CONTAINER_HID))
Expand Down
11 changes: 5 additions & 6 deletions drivers/acpi/property.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,9 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,
if (index)
return -EINVAL;

ret = acpi_bus_get_device(obj->reference.handle, &device);
if (ret)
return ret == -ENODEV ? -EINVAL : ret;
device = acpi_fetch_acpi_dev(obj->reference.handle);
if (!device)
return -EINVAL;

args->fwnode = acpi_fwnode_handle(device);
args->nargs = 0;
Expand Down Expand Up @@ -719,9 +719,8 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,
if (element->type == ACPI_TYPE_LOCAL_REFERENCE) {
struct fwnode_handle *ref_fwnode;

ret = acpi_bus_get_device(element->reference.handle,
&device);
if (ret)
device = acpi_fetch_acpi_dev(element->reference.handle);
if (!device)
return -EINVAL;

nargs = 0;
Expand Down
4 changes: 2 additions & 2 deletions drivers/acpi/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,9 @@ static acpi_status acpi_res_consumer_cb(acpi_handle handle, u32 depth,
{
struct resource *res = context;
struct acpi_device **consumer = (struct acpi_device **) ret;
struct acpi_device *adev;
struct acpi_device *adev = acpi_fetch_acpi_dev(handle);

if (acpi_bus_get_device(handle, &adev))
if (!adev)
return AE_OK;

if (acpi_dev_consumes_res(adev, res)) {
Expand Down
57 changes: 39 additions & 18 deletions drivers/acpi/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent)
static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data,
void **ret_p)
{
struct acpi_device *device = NULL;
struct acpi_device *device = acpi_fetch_acpi_dev(handle);
struct acpi_device_physical_node *pn;
bool second_pass = (bool)data;
acpi_status status = AE_OK;

if (acpi_bus_get_device(handle, &device))
if (!device)
return AE_OK;

if (device->handler && !device->handler->hotplug.enabled) {
Expand Down Expand Up @@ -180,10 +180,10 @@ static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data,
static acpi_status acpi_bus_online(acpi_handle handle, u32 lvl, void *data,
void **ret_p)
{
struct acpi_device *device = NULL;
struct acpi_device *device = acpi_fetch_acpi_dev(handle);
struct acpi_device_physical_node *pn;

if (acpi_bus_get_device(handle, &device))
if (!device)
return AE_OK;

mutex_lock(&device->physical_node_lock);
Expand Down Expand Up @@ -599,6 +599,19 @@ int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
}
EXPORT_SYMBOL(acpi_bus_get_device);

/**
* acpi_fetch_acpi_dev - Retrieve ACPI device object.
* @handle: ACPI handle associated with the requested ACPI device object.
*
* Return a pointer to the ACPI device object associated with @handle, if
* present, or NULL otherwise.
*/
struct acpi_device *acpi_fetch_acpi_dev(acpi_handle handle)
{
return handle_to_device(handle, NULL);
}
EXPORT_SYMBOL_GPL(acpi_fetch_acpi_dev);

static void get_acpi_device(void *dev)
{
acpi_dev_get(dev);
Expand Down Expand Up @@ -799,7 +812,7 @@ static const char * const acpi_ignore_dep_ids[] = {

static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)
{
struct acpi_device *device = NULL;
struct acpi_device *device;
acpi_status status;

/*
Expand All @@ -814,7 +827,9 @@ static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)
status = acpi_get_parent(handle, &handle);
if (ACPI_FAILURE(status))
return status == AE_NULL_ENTRY ? NULL : acpi_root;
} while (acpi_bus_get_device(handle, &device));

device = acpi_fetch_acpi_dev(handle);
} while (!device);
return device;
}

Expand Down Expand Up @@ -1340,11 +1355,11 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
if (info->valid & ACPI_VALID_HID) {
acpi_add_id(pnp, info->hardware_id.string);
pnp->type.platform_id = 1;
}
if (info->valid & ACPI_VALID_CID) {
cid_list = &info->compatible_id_list;
for (i = 0; i < cid_list->count; i++)
acpi_add_id(pnp, cid_list->ids[i].string);
if (info->valid & ACPI_VALID_CID) {
cid_list = &info->compatible_id_list;
for (i = 0; i < cid_list->count; i++)
acpi_add_id(pnp, cid_list->ids[i].string);
}
}
if (info->valid & ACPI_VALID_ADR) {
pnp->bus_address = info->address;
Expand Down Expand Up @@ -1695,6 +1710,7 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device)
{
struct list_head resource_list;
bool is_serial_bus_slave = false;
static const struct acpi_device_id ignore_serial_bus_ids[] = {
/*
* These devices have multiple I2cSerialBus resources and an i2c-client
* must be instantiated for each, each with its own i2c_device_id.
Expand All @@ -1703,11 +1719,18 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device)
* drivers/platform/x86/i2c-multi-instantiate.c driver, which knows
* which i2c_device_id to use for each resource.
*/
static const struct acpi_device_id i2c_multi_instantiate_ids[] = {
{"BSG1160", },
{"BSG2150", },
{"INT33FE", },
{"INT3515", },
/*
* HIDs of device with an UartSerialBusV2 resource for which userspace
* expects a regular tty cdev to be created (instead of the in kernel
* serdev) and which have a kernel driver which expects a platform_dev
* such as the rfkill-gpio driver.
*/
{"BCM4752", },
{"LNV4752", },
{}
};

Expand All @@ -1721,8 +1744,7 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device)
fwnode_property_present(&device->fwnode, "baud")))
return true;

/* Instantiate a pdev for the i2c-multi-instantiate drv to bind to */
if (!acpi_match_device_ids(device, i2c_multi_instantiate_ids))
if (!acpi_match_device_ids(device, ignore_serial_bus_ids))
return false;

INIT_LIST_HEAD(&resource_list);
Expand Down Expand Up @@ -2003,11 +2025,10 @@ static bool acpi_bus_scan_second_pass;
static acpi_status acpi_bus_check_add(acpi_handle handle, bool check_dep,
struct acpi_device **adev_p)
{
struct acpi_device *device = NULL;
struct acpi_device *device = acpi_fetch_acpi_dev(handle);
acpi_object_type acpi_type;
int type;

acpi_bus_get_device(handle, &device);
if (device)
goto out;

Expand Down Expand Up @@ -2548,8 +2569,8 @@ int __init acpi_scan_init(void)
if (result)
goto out;

result = acpi_bus_get_device(ACPI_ROOT_OBJECT, &acpi_root);
if (result)
acpi_root = acpi_fetch_acpi_dev(ACPI_ROOT_OBJECT);
if (!acpi_root)
goto out;

/* Fixed feature devices do not exist on HW-reduced platform */
Expand Down
Loading

0 comments on commit 8e0feb2

Please sign in to comment.