/* * The UART device described by the SPCR table is the only object which needs * special-casing. Everything else is covered by ACPI namespace paths in STAO * table.
*/ static u64 spcr_uart_addr;
/* * acpi_container_offline() calls this for all of the container's * children under the container's physical_node_lock lock.
*/
mutex_lock_nested(&adev->physical_node_lock, SINGLE_DEPTH_NESTING);
list_for_each_entry(pn, &adev->physical_node_list, node) if (device_supports_offline(pn->dev) && !pn->dev->offline) { if (uevent)
kobject_uevent_env(&pn->dev->kobj, KOBJ_CHANGE, envp);
/* * Carry out two passes here and ignore errors in the first pass, * because if the devices in question are memory blocks and * CONFIG_MEMCG is set, one of the blocks may hold data structures * that the other blocks depend on, but it is not known in advance which * block holds them. * * If the first pass is successful, the second one isn't needed, though.
*/
status = acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
NULL, acpi_bus_offline, (void *)false,
(void **)&errdev); if (status == AE_SUPPORT) {
dev_warn(errdev, "Offline disabled.\n");
acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
acpi_bus_online, NULL, NULL, NULL); return -EPERM;
}
acpi_bus_offline(handle, 0, (void *)false, (void **)&errdev); if (errdev) {
errdev = NULL;
acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
NULL, acpi_bus_offline, (void *)true,
(void **)&errdev); if (!errdev)
acpi_bus_offline(handle, 0, (void *)true,
(void **)&errdev);
if (flags & ACPI_SCAN_CHECK_FLAG_STATUS) {
acpi_bus_get_status(adev); /* * Skip devices that are still there and take the enabled * flag into account.
*/ if (acpi_device_is_enabled(adev)) return 0;
/* Skip device that have not been enumerated. */ if (!acpi_device_enumerated(adev)) {
dev_dbg(&adev->dev, "Still not enumerated\n"); return 0;
}
}
adev->flags.match_driver = false; if (handler) { if (handler->detach)
handler->detach(adev);
} else {
device_release_driver(&adev->dev);
} /* * Most likely, the device is going away, so put it into D3cold before * that.
*/
acpi_device_set_power(adev, ACPI_STATE_D3_COLD);
adev->flags.initialized = false;
/* For eject this is deferred to acpi_bus_post_eject() */ if (!(flags & ACPI_SCAN_CHECK_FLAG_EJECT)) {
adev->handler = NULL;
acpi_device_clear_enumerated(adev);
} return 0;
}
/* * Verify if eject was indeed successful. If not, log an error * message. No need to call _OST since _EJ0 call was made OK.
*/
status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); if (ACPI_FAILURE(status)) {
acpi_handle_warn(handle, "Status check after eject failed (0x%x)\n", status);
} elseif (sta & ACPI_STA_DEVICE_ENABLED) {
acpi_handle_warn(handle, "Eject incomplete - status 0x%llx\n", sta);
} else {
acpi_bus_post_eject(device, NULL);
}
/* * This function is only called for device objects for which matching * scan handlers exist. The only situation in which the scan handler * is not attached to this device object yet is when the device has * just appeared (either it wasn't present at all before or it was * removed and then added again).
*/ if (adev->handler) {
dev_dbg(&adev->dev, "Already enumerated\n"); return 0;
}
parent = acpi_dev_parent(adev); if (!parent)
parent = adev;
/* * The device object's ACPI handle cannot become invalid as long as we * are holding acpi_scan_lock, but it might have become invalid before * that lock was acquired.
*/ if (adev->handle == INVALID_ACPI_HANDLE) goto err_out;
acpi_device_del(adev); /* * Drop references to all power resources that might have been * used by the device.
*/
acpi_power_transition(adev, ACPI_STATE_D3_COLD);
acpi_dev_put(adev);
}
}
/** * acpi_scan_drop_device - Drop an ACPI device object. * @handle: Handle of an ACPI namespace node, not used. * @context: Address of the ACPI device object to drop. * * This is invoked by acpi_ns_delete_node() during the removal of the ACPI * namespace node the device object pointed to by @context is attached to. * * The unregistration is carried out asynchronously to avoid running * acpi_device_del() under the ACPICA's namespace mutex and the list is used to * ensure the correct ordering (the device objects must be unregistered in the * same order in which the corresponding namespace nodes are deleted).
*/ staticvoid acpi_scan_drop_device(acpi_handle handle, void *context)
{ static DECLARE_WORK(work, acpi_device_del_work_fn); struct acpi_device *adev = context;
mutex_lock(&acpi_device_del_lock);
/* * Use the ACPI hotplug workqueue which is ordered, so this work item * won't run after any hotplug work items submitted subsequently. That * prevents attempts to register device objects identical to those being * deleted from happening concurrently (such attempts result from * hotplug events handled via the ACPI hotplug workqueue). It also will * run after all of the work items submitted previously, which helps * those work items to ensure that they are not accessing stale device * objects.
*/ if (list_empty(&acpi_device_del_list))
acpi_queue_hotplug_work(&work);
list_add_tail(&adev->del_list, &acpi_device_del_list); /* Make acpi_ns_validate_handle() return NULL for this handle. */
adev->handle = INVALID_ACPI_HANDLE;
/** * acpi_get_acpi_dev - Retrieve ACPI device object and reference count it. * @handle: ACPI handle associated with the requested ACPI device object. * * Return a pointer to the ACPI device object associated with @handle and bump * up that object's reference counter (under the ACPI Namespace lock), if * present, or return NULL otherwise. * * The ACPI device object reference acquired by this function needs to be * dropped via acpi_dev_put().
*/ struct acpi_device *acpi_get_acpi_dev(acpi_handle handle)
{ return handle_to_device(handle, get_acpi_device);
}
EXPORT_SYMBOL_GPL(acpi_get_acpi_dev);
int acpi_device_add(struct acpi_device *device)
{ struct acpi_device_bus_id *acpi_device_bus_id; int result;
/* * Linkage * ------- * Link this device to its parent and siblings.
*/
INIT_LIST_HEAD(&device->wakeup_list);
INIT_LIST_HEAD(&device->physical_node_list);
INIT_LIST_HEAD(&device->del_list);
mutex_init(&device->physical_node_lock);
mutex_lock(&acpi_device_lock);
acpi_device_bus_id = acpi_device_bus_id_match(acpi_device_hid(device)); if (acpi_device_bus_id) {
result = acpi_device_set_name(device, acpi_device_bus_id); if (result) goto err_unlock;
} else {
acpi_device_bus_id = kzalloc(sizeof(*acpi_device_bus_id),
GFP_KERNEL); if (!acpi_device_bus_id) {
result = -ENOMEM; goto err_unlock;
}
acpi_device_bus_id->bus_id =
kstrdup_const(acpi_device_hid(device), GFP_KERNEL); if (!acpi_device_bus_id->bus_id) {
kfree(acpi_device_bus_id);
result = -ENOMEM; goto err_unlock;
}
ida_init(&acpi_device_bus_id->instance_ida);
result = acpi_device_set_name(device, acpi_device_bus_id); if (result) {
kfree_const(acpi_device_bus_id->bus_id);
kfree(acpi_device_bus_id); goto err_unlock;
}
index = match_string(ids, -1, info->hardware_id.string); if (index >= 0) returntrue;
if (info->valid & ACPI_VALID_CID)
cid_list = &info->compatible_id_list;
if (!cid_list) returnfalse;
for (i = 0; i < cid_list->count; i++) {
index = match_string(ids, -1, cid_list->ids[i].string); if (index >= 0) returntrue;
}
returnfalse;
}
/* List of HIDs for which we ignore matching ACPI devices, when checking _DEP lists. */ staticconstchar * const acpi_ignore_dep_ids[] = { "PNP0D80", /* Windows-compatible System Power Management Controller */ "INT33BD", /* Intel Baytrail Mailbox Device */ "INTC10DE", /* Intel CVS LNL */ "INTC10E0", /* Intel CVS ARL */ "LATT2021", /* Lattice FW Update Client Driver */
NULL
};
/* List of HIDs for which we honor deps of matching ACPI devs, when checking _DEP lists. */ staticconstchar * const acpi_honor_dep_ids[] = { "INT3472", /* Camera sensor PMIC / clk and regulator info */ "INTC1059", /* IVSC (TGL) driver must be loaded to allow i2c access to camera sensors */ "INTC1095", /* IVSC (ADL) driver must be loaded to allow i2c access to camera sensors */ "INTC100A", /* IVSC (RPL) driver must be loaded to allow i2c access to camera sensors */ "INTC10CF", /* IVSC (MTL) driver must be loaded to allow i2c access to camera sensors */ "RSCV0001", /* RISC-V PLIC */ "RSCV0002", /* RISC-V APLIC */ "RSCV0005", /* RISC-V SBI MPXY MBOX */ "RSCV0006", /* RISC-V RPMI SYSMSI */ "PNP0C0F", /* PCI Link Device */
NULL
};
/* * Fixed hardware devices do not appear in the namespace and do not * have handles, but we fabricate acpi_devices for them, so we have * to deal with them specially.
*/ if (!handle) return acpi_root;
do {
acpi_status status;
status = acpi_get_parent(handle, &handle); if (ACPI_FAILURE(status)) { if (status != AE_NULL_ENTRY) return acpi_root;
element = &(package->package.elements[1]); if (element->type != ACPI_TYPE_INTEGER) goto out;
wakeup->sleep_state = element->integer.value;
err = acpi_extract_power_resources(package, 2, &wakeup->resources); if (err) goto out;
if (!list_empty(&wakeup->resources)) { int sleep_state;
err = acpi_power_wakeup_list_init(&wakeup->resources,
&sleep_state); if (err) {
acpi_handle_warn(handle, "Retrieving current states " "of wakeup power resources failed\n");
acpi_power_resources_list_free(&wakeup->resources); goto out;
} if (sleep_state < wakeup->sleep_state) {
acpi_handle_warn(handle, "Overriding _PRW sleep state " "(S%d) by S%d from power resources\n",
(int)wakeup->sleep_state, sleep_state);
wakeup->sleep_state = sleep_state;
}
}
out:
kfree(buffer.pointer); return err;
}
/* Do not use a button for S5 wakeup */ #define ACPI_AVOID_WAKE_FROM_S5 BIT(0)
/* Power button, Lid switch always enable wakeup */
match = acpi_match_acpi_device(button_device_ids, device); if (match) { if ((match->driver_data & ACPI_AVOID_WAKE_FROM_S5) &&
wakeup->sleep_state == ACPI_STATE_S5)
wakeup->sleep_state = ACPI_STATE_S4;
acpi_mark_gpe_for_wake(wakeup->gpe_device, wakeup->gpe_number);
device_set_wakeup_capable(&device->dev, true); returntrue;
}
status = acpi_setup_gpe_for_wake(device->handle, wakeup->gpe_device,
wakeup->gpe_number); return ACPI_SUCCESS(status);
}
staticvoid acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
{ int err;
/* Presence of _PRW indicates wake capable */ if (!acpi_has_method(device->handle, "_PRW")) return;
err = acpi_bus_extract_wakeup_device_power_package(device); if (err) {
dev_err(&device->dev, "Unable to extract wakeup power resources"); return;
}
device->wakeup.flags.valid = acpi_wakeup_gpe_init(device);
device->wakeup.prepare_count = 0; /* * Call _PSW/_DSW object to disable its ability to wake the sleeping * system for the ACPI device with the _PRW object. * The _PSW object is deprecated in ACPI 3.0 and is replaced by _DSW. * So it is necessary to call _DSW object first. Only when it is not * present will the _PSW object used.
*/
err = acpi_device_sleep_wake(device, 0, 0, 0); if (err)
pr_debug("error in _DSW or _PSW evaluation\n");
}
/* Evaluate "_PRx" to get referenced power resources */
status = acpi_evaluate_object(device->handle, pathname, NULL, &buffer); if (ACPI_SUCCESS(status)) { union acpi_object *package = buffer.pointer;
/* Set the defaults for D0 and D3hot (always supported). */
device->power.states[ACPI_STATE_D0].flags.valid = 1;
device->power.states[ACPI_STATE_D0].power = 100;
device->power.states[ACPI_STATE_D3_HOT].flags.valid = 1;
/* * Use power resources only if the D0 list of them is populated, because * some platforms may provide _PR3 only to indicate D3cold support and * in those cases the power resources list returned by it may be bogus.
*/ if (!list_empty(&device->power.states[ACPI_STATE_D0].resources)) {
device->power.flags.power_resources = 1; /* * D3cold is supported if the D3hot list of power resources is * not empty.
*/ if (!list_empty(&device->power.states[ACPI_STATE_D3_HOT].resources))
device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1;
}
if (acpi_bus_init_power(device))
device->flags.power_manageable = 0;
}
staticvoid acpi_bus_get_flags(struct acpi_device *device)
{ /* Presence of _STA indicates 'dynamic_status' */ if (acpi_has_method(device->handle, "_STA"))
device->flags.dynamic_status = 1;
/* Presence of _RMV indicates 'removable' */ if (acpi_has_method(device->handle, "_RMV"))
device->flags.removable = 1;
/* Presence of _EJD|_EJ0 indicates 'ejectable' */ if (acpi_has_method(device->handle, "_EJD") ||
acpi_has_method(device->handle, "_EJ0"))
device->flags.ejectable = 1;
}
/* * Bus ID * ------ * The device's Bus ID is simply the object name. * TBD: Shouldn't this value be unique (within the ACPI namespace)?
*/ if (!acpi_dev_parent(device)) {
strscpy(device->pnp.bus_id, "ACPI"); return;
}
switch (device->device_type) { case ACPI_BUS_TYPE_POWER_BUTTON:
strscpy(device->pnp.bus_id, "PWRF"); break; case ACPI_BUS_TYPE_SLEEP_BUTTON:
strscpy(device->pnp.bus_id, "SLPF"); break; case ACPI_BUS_TYPE_ECDT_EC:
strscpy(device->pnp.bus_id, "ECDT"); break; default:
acpi_get_name(device->handle, ACPI_SINGLE_NAME, &buffer); /* Clean up trailing underscores (if any) */ for (i = 3; i > 1; i--) { if (bus_id[i] == '_')
bus_id[i] = '\0'; else break;
}
strscpy(device->pnp.bus_id, bus_id); break;
}
}
/* * acpi_ata_match - see if an acpi object is an ATA device * * If an acpi object has one of the ACPI ATA methods defined, * then we can safely call it an ATA device.
*/ bool acpi_ata_match(acpi_handle handle)
{ return acpi_has_method(handle, "_GTF") ||
acpi_has_method(handle, "_GTM") ||
acpi_has_method(handle, "_STM") ||
acpi_has_method(handle, "_SDD");
}
/* * acpi_bay_match - see if an acpi object is an ejectable driver bay * * If an acpi object is ejectable and has one of the ACPI ATA methods defined, * then we can safely call it an ejectable drive bay
*/ bool acpi_bay_match(acpi_handle handle)
{
acpi_handle phandle;
if (!acpi_has_method(handle, "_EJ0")) returnfalse; if (acpi_ata_match(handle)) returntrue; if (ACPI_FAILURE(acpi_get_parent(handle, &phandle))) returnfalse;
if (acpi_has_method(handle, "_BCM") &&
acpi_has_method(handle, "_BCL")) {
acpi_handle_debug(handle, "Found generic backlight support\n");
*cap |= ACPI_VIDEO_BACKLIGHT; /* We have backlight support, no need to scan further */ return AE_CTRL_TERMINATE;
} return 0;
}
/* Returns true if the ACPI object is a video device which can be * handled by video.ko. * The device will get a Linux specific CID added in scan.c to * identify the device as an ACPI graphics device * Be aware that the graphics device may not be physically present * Use acpi_video_get_capabilities() to detect general ACPI video * capabilities of present cards
*/ long acpi_is_video_device(acpi_handle handle)
{ long video_caps = 0;
/* Is this device able to support video switching ? */ if (acpi_has_method(handle, "_DOD") || acpi_has_method(handle, "_DOS"))
video_caps |= ACPI_VIDEO_OUTPUT_SWITCHING;
/* Is this device able to retrieve a video ROM ? */ if (acpi_has_method(handle, "_ROM"))
video_caps |= ACPI_VIDEO_ROM_AVAILABLE;
/* Is this device able to configure which video head to be POSTed ? */ if (acpi_has_method(handle, "_VPO") &&
acpi_has_method(handle, "_GPD") &&
acpi_has_method(handle, "_SPD"))
video_caps |= ACPI_VIDEO_DEVICE_POSTING;
/* Only check for backlight functionality if one of the above hit. */ if (video_caps)
acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
ACPI_UINT32_MAX, acpi_backlight_cap_match, NULL,
&video_caps, NULL);
/* * Old IBM workstations have a DSDT bug wherein the SMBus object * lacks the SMBUS01 HID and the methods do not have the necessary "_" * prefix. Work around this.
*/ staticbool acpi_ibm_smbus_match(acpi_handle handle)
{ char node_name[ACPI_PATH_SEGMENT_LENGTH]; struct acpi_buffer path = { sizeof(node_name), node_name };
if (!dmi_name_in_vendors("IBM")) returnfalse;
/* Look for SMBS object */ if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &path)) ||
strcmp("SMBS", path.pointer)) returnfalse;
/* Does it have the necessary (but misnamed) methods? */ if (acpi_has_method(handle, "SBI") &&
acpi_has_method(handle, "SBR") &&
acpi_has_method(handle, "SBW")) returntrue;
/** * acpi_dma_supported - Check DMA support for the specified device. * @adev: The pointer to acpi device * * Return false if DMA is not supported. Otherwise, return true
*/ bool acpi_dma_supported(conststruct acpi_device *adev)
{ if (!adev) returnfalse;
if (adev->flags.cca_seen) returntrue;
/* * Per ACPI 6.0 sec 6.2.17, assume devices can do cache-coherent * DMA on "Intel platforms". Presumably that includes all x86 and * ia64, and other arches will set CONFIG_ACPI_CCA_REQUIRED=y.
*/ if (!IS_ENABLED(CONFIG_ACPI_CCA_REQUIRED)) returntrue;
returnfalse;
}
/** * acpi_get_dma_attr - Check the supported DMA attr for the specified device. * @adev: The pointer to acpi device * * Return enum dev_dma_attr.
*/ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
{ if (!acpi_dma_supported(adev)) return DEV_DMA_NOT_SUPPORTED;
if (adev->flags.coherent_dma) return DEV_DMA_COHERENT; else return DEV_DMA_NON_COHERENT;
}
/** * acpi_dma_get_range() - Get device DMA parameters. * * @dev: device to configure * @map: pointer to DMA ranges result * * Evaluate DMA regions and return pointer to DMA regions on * parsing success; it does not update the passed in values on failure. * * Return 0 on success, < 0 on failure.
*/ int acpi_dma_get_range(struct device *dev, conststruct bus_dma_region **map)
{ struct acpi_device *adev;
LIST_HEAD(list); struct resource_entry *rentry; int ret; struct device *dma_dev = dev; struct bus_dma_region *r;
/* * Walk the device tree chasing an ACPI companion with a _DMA * object while we go. Stop if we find a device with an ACPI * companion containing a _DMA method.
*/ do {
adev = ACPI_COMPANION(dma_dev); if (adev && acpi_has_method(adev->handle, METHOD_NAME__DMA)) break;
dma_dev = dma_dev->parent;
} while (dma_dev);
if (!dma_dev) return -ENODEV;
if (!acpi_has_method(adev->handle, METHOD_NAME__CRS)) {
acpi_handle_warn(adev->handle, "_DMA is valid only if _CRS is present\n"); return -EINVAL;
}
ret = acpi_dev_get_dma_resources(adev, &list); if (ret > 0) {
r = kcalloc(ret + 1, sizeof(*r), GFP_KERNEL); if (!r) {
ret = -ENOMEM; goto out;
}
*map = r;
list_for_each_entry(rentry, &list, node) { if (rentry->res->start >= rentry->res->end) {
kfree(*map);
*map = NULL;
ret = -EINVAL;
dev_dbg(dma_dev, "Invalid DMA regions configuration\n"); goto out;
}
#ifdef CONFIG_IOMMU_API int acpi_iommu_fwspec_init(struct device *dev, u32 id, struct fwnode_handle *fwnode)
{ int ret;
ret = iommu_fwspec_init(dev, fwnode); if (ret) return ret;
return iommu_fwspec_add_ids(dev, &id, 1);
}
staticint acpi_iommu_configure_id(struct device *dev, const u32 *id_in)
{ int err;
/* Serialise to make dev->iommu stable under our potential fwspec */
mutex_lock(&iommu_probe_device_lock); /* If we already translated the fwspec there is nothing left to do */ if (dev_iommu_fwspec_get(dev)) {
mutex_unlock(&iommu_probe_device_lock); return 0;
}
/** * acpi_dma_configure_id - Set-up DMA configuration for the device. * @dev: The pointer to the device * @attr: device dma attributes * @input_id: input device id const value pointer
*/ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, const u32 *input_id)
{ int ret;
if (attr == DEV_DMA_NOT_SUPPORTED) {
set_dma_ops(dev, &dma_dummy_ops); return 0;
}
acpi_arch_dma_setup(dev);
/* Ignore all other errors apart from EPROBE_DEFER */
ret = acpi_iommu_configure_id(dev, input_id); if (ret == -EPROBE_DEFER) return -EPROBE_DEFER; if (ret)
dev_dbg(dev, "Adding to IOMMU failed: %d\n", ret);
if (parent && parent->flags.cca_seen) { /* * From ACPI spec, OSPM will ignore _CCA if an ancestor * already saw one.
*/
adev->flags.cca_seen = 1;
cca = parent->flags.coherent_dma;
} else {
status = acpi_evaluate_integer(adev->handle, "_CCA",
NULL, &cca); if (ACPI_SUCCESS(status))
adev->flags.cca_seen = 1; elseif (!IS_ENABLED(CONFIG_ACPI_CCA_REQUIRED)) /* * If architecture does not specify that _CCA is * required for DMA-able devices (e.g. x86), * we default to _CCA=1.
*/
cca = 1; else
acpi_handle_debug(adev->handle, "ACPI device is missing _CCA.\n");
}
staticbool acpi_device_enumeration_by_parent(struct acpi_device *device)
{ struct list_head resource_list; bool is_serial_bus_slave = false; staticconststruct acpi_device_id ignore_serial_bus_ids[] = { /* * These devices have multiple SerialBus resources and a client * device must be instantiated for each of them, each with * its own device id. * Normally we only instantiate one client device for the first * resource, using the ACPI HID as id. These special cases are handled * by the drivers/platform/x86/serial-multi-instantiate.c driver, which * knows which client device id to use for each resource.
*/
{"BSG1160", },
{"BSG2150", },
{"CSC3551", },
{"CSC3554", },
{"CSC3556", },
{"CSC3557", },
{"INT33FE", },
{"INT3515", },
{"TXNW2781", }, /* Non-conforming _HID for Cirrus Logic already released */
{"CLSA0100", },
{"CLSA0101", }, /* * Some ACPI devs contain SerialBus resources even though they are not * attached to a serial bus at all.
*/
{ACPI_VIDEO_HID, },
{"MSHW0028", }, /* * 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", },
{}
};
if (acpi_is_indirect_io_slave(device)) returntrue;
/* Macs use device properties in lieu of _CRS resources */ if (x86_apple_machine &&
(fwnode_property_present(&device->fwnode, "spiSclkPeriod") ||
fwnode_property_present(&device->fwnode, "i2cAddress") ||
fwnode_property_present(&device->fwnode, "baud"))) returntrue;
if (!acpi_match_device_ids(device, ignore_serial_bus_ids)) returnfalse;
staticvoid acpi_scan_init_status(struct acpi_device *adev)
{ if (acpi_bus_get_status(adev))
acpi_set_device_status(adev, 0);
}
staticint acpi_add_single_object(struct acpi_device **child,
acpi_handle handle, int type, bool dep_init)
{ struct acpi_device *device; bool release_dep_lock = false; int result;
device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL); if (!device) return -ENOMEM;
acpi_init_device_object(device, handle, type, acpi_device_release); /* * Getting the status is delayed till here so that we can call * acpi_bus_get_status() and use its quirk handling. Note that * this must be done before the get power-/wakeup_dev-flags calls.
*/ if (type == ACPI_BUS_TYPE_DEVICE || type == ACPI_BUS_TYPE_PROCESSOR) { if (dep_init) {
mutex_lock(&acpi_dep_list_lock); /* * Hold the lock until the acpi_tie_acpi_dev() call * below to prevent concurrent acpi_scan_clear_dep() * from deleting a dependency list entry without * updating dep_unmet for the device.
*/
release_dep_lock = true;
acpi_scan_dep_init(device);
}
acpi_scan_init_status(device);
}
/* Check if it should ignore the UART device */ if (!(spcr_uart_addr && acpi_has_method(handle, METHOD_NAME__CRS))) returnfalse;
/* * The UART device described in SPCR table is assumed to have only one * memory resource present. So we only look for the first one here.
*/
status = acpi_walk_resources(handle, METHOD_NAME__CRS,
acpi_get_resource_memory, &res); if (ACPI_FAILURE(status) || res.start != spcr_uart_addr) returnfalse;
acpi_handle_info(handle, "The UART device @%pa in SPCR table will be hidden\n",
&res.start);
/* * Some architectures like RISC-V need to add dependencies for * all devices which use GSI to the interrupt controller so that * interrupt controller is probed before any of those devices. * Instead of mandating _DEP on all the devices, detect the * dependency and add automatically.
*/
count += arch_acpi_add_auto_dep(handle);
/* * Check for _HID here to avoid deferring the enumeration of: * 1. PCI devices. * 2. ACPI nodes describing USB ports. * Still, checking for _HID catches more then just these cases ...
*/ if (!acpi_has_method(handle, "_DEP") || !acpi_has_method(handle, "_HID")) return count;
if (!acpi_evaluate_reference(handle, "_DEP", NULL, &dep_devices)) {
acpi_handle_debug(handle, "Failed to evaluate _DEP.\n"); return count;
}
if (ACPI_FAILURE(acpi_get_type(handle, &acpi_type))) return AE_OK;
switch (acpi_type) { case ACPI_TYPE_DEVICE: if (acpi_device_should_be_hidden(handle)) return AE_OK;
if (first_pass) {
acpi_mipi_check_crs_csi2(handle);
/* Bail out if there are dependencies. */ if (acpi_scan_check_dep(handle) > 0) { /* * The entire CSI-2 connection graph needs to be * extracted before any drivers or scan handlers * are bound to struct device objects, so scan * _CRS CSI-2 resource descriptors for all * devices below the current handle.
*/
acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
ACPI_UINT32_MAX,
acpi_scan_check_crs_csi2_cb,
NULL, NULL, NULL); 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;
}
/* * If first_pass is true at this point, the device has no dependencies, * or the creation of the device object would have been postponed above.
*/
acpi_add_single_object(&device, handle, type, !first_pass); if (!device) return AE_CTRL_DEPTH;
staticvoid acpi_default_enumeration(struct acpi_device *device)
{ /* * Do not enumerate devices with enumeration_by_parent flag set as * they will be enumerated by their respective parents.
*/ if (!device->flags.enumeration_by_parent) {
acpi_create_platform_device(device, NULL);
acpi_device_set_enumerated(device);
} else {
blocking_notifier_call_chain(&acpi_reconfig_chain,
ACPI_RECONFIG_DEVICE_ADD, device);
}
}
staticint acpi_generic_device_attach(struct acpi_device *adev, conststruct acpi_device_id *not_used)
{ /* * Since ACPI_DT_NAMESPACE_HID is the only ID handled here, the test * below can be unconditional.
*/ if (adev->data.of_compatible)
acpi_default_enumeration(adev);
if (ACPI_SUCCESS(acpi_bus_get_ejd(device->handle, &ejd)))
register_dock_dependent_device(device, ejd);
acpi_bus_get_status(device); /* Skip devices that are not ready for enumeration (e.g. not present) */ if (!acpi_dev_ready_for_enumeration(device)) {
device->flags.initialized = false;
acpi_device_clear_enumerated(device);
device->flags.power_manageable = 0; return 0;
} if (device->handler) goto ok;
acpi_ec_register_opregions(device);
if (!device->flags.initialized) {
device->flags.power_manageable =
device->power.states[ACPI_STATE_D0].flags.valid; if (acpi_bus_init_power(device))
device->flags.power_manageable = 0;
/* * If we're passed a 'previous' consumer device then we need to skip * any consumers until we meet the previous one, and then NULL @data * so the next one can be returned.
*/ if (adev) { if (dep->consumer == adev->handle)
*adev_p = NULL;
return 0;
}
adev = acpi_get_acpi_dev(dep->consumer); if (adev) {
*(struct acpi_device **)data = adev; return 1;
} /* Continue parsing if the device object is not present. */ return 0;
}
cdw = kmalloc(sizeof(*cdw), GFP_KERNEL); if (!cdw) returnfalse;
cdw->adev = adev;
INIT_WORK(&cdw->work, acpi_scan_clear_dep_fn); /* * Since the work function may block on the lock until the entire * initial enumeration of devices is complete, put it into the unbound * workqueue.
*/
queue_work(system_unbound_wq, &cdw->work);
if (adev) {
adev->dep_unmet--; if (!acpi_scan_clear_dep_queue(adev))
acpi_dev_put(adev);
}
if (dep->free_when_met)
acpi_scan_delete_dep_data(dep); else
dep->met = true;
return 0;
}
/** * acpi_walk_dep_device_list - Apply a callback to every entry in acpi_dep_list * @handle: The ACPI handle of the supplier device * @callback: Pointer to the callback function to apply * @data: Pointer to some data to pass to the callback * * The return value of the callback determines this function's behaviour. If 0 * is returned we continue to iterate over acpi_dep_list. If a positive value * is returned then the loop is broken but this function returns 0. If a * negative value is returned by the callback then the loop is broken and that * value is returned as the final error.
*/ staticint acpi_walk_dep_device_list(acpi_handle handle, int (*callback)(struct acpi_dep_data *, void *), void *data)
{ struct acpi_dep_data *dep, *tmp; int ret = 0;
mutex_lock(&acpi_dep_list_lock);
list_for_each_entry_safe(dep, tmp, &acpi_dep_list, node) { if (dep->supplier == handle) {
ret = callback(dep, data); if (ret) break;
}
}
mutex_unlock(&acpi_dep_list_lock);
return ret > 0 ? 0 : ret;
}
/** * acpi_dev_clear_dependencies - Inform consumers that the device is now active * @supplier: Pointer to the supplier &struct acpi_device * * Clear dependencies on the given device.
*/ void acpi_dev_clear_dependencies(struct acpi_device *supplier)
{
acpi_walk_dep_device_list(supplier->handle, acpi_scan_clear_dep, NULL);
}
EXPORT_SYMBOL_GPL(acpi_dev_clear_dependencies);
/** * acpi_dev_ready_for_enumeration - Check if the ACPI device is ready for enumeration * @device: Pointer to the &struct acpi_device to check * * Check if the device is present and has no unmet dependencies. * * Return true if the device is ready for enumeratino. Otherwise, return false.
*/ bool acpi_dev_ready_for_enumeration(conststruct acpi_device *device)
{ if (device->flags.honor_deps && device->dep_unmet) returnfalse;
/** * acpi_dev_get_next_consumer_dev - Return the next adev dependent on @supplier * @supplier: Pointer to the dependee device * @start: Pointer to the current dependent device * * Returns the next &struct acpi_device which declares itself dependent on * @supplier via the _DEP buffer, parsed from the acpi_dep_list. * * If the returned adev is not passed as @start to this function, the caller is * responsible for putting the reference to adev when it is no longer needed.
*/ struct acpi_device *acpi_dev_get_next_consumer_dev(struct acpi_device *supplier, struct acpi_device *start)
{ struct acpi_device *adev = start;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.