^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * acpi_bus.c - ACPI Bus Driver ($Revision: 80 $)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/regulator/machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #ifdef CONFIG_X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/mpspec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/acpi_iort.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <acpi/apei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define _COMPONENT ACPI_BUS_COMPONENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) ACPI_MODULE_NAME("bus");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct acpi_device *acpi_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct proc_dir_entry *acpi_root_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) EXPORT_SYMBOL(acpi_root_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #ifdef CONFIG_X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #ifdef CONFIG_ACPI_CUSTOM_DSDT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static inline int set_copy_dsdt(const struct dmi_system_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static int set_copy_dsdt(const struct dmi_system_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) printk(KERN_NOTICE "%s detected - "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) "force copy of DSDT to local memory\n", id->ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) acpi_gbl_copy_dsdt_locally = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static const struct dmi_system_id dsdt_dmi_table[] __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * Invoke DSDT corruption work-around on all Toshiba Satellite.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * https://bugzilla.kernel.org/show_bug.cgi?id=14679
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .callback = set_copy_dsdt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .ident = "TOSHIBA Satellite",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) Device Management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) acpi_status acpi_bus_get_status_handle(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned long long *sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (status == AE_NOT_FOUND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) EXPORT_SYMBOL_GPL(acpi_bus_get_status_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int acpi_bus_get_status(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) unsigned long long sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (acpi_device_override_status(device, &sta)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) acpi_set_device_status(device, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* Battery devices must have their deps met before calling _STA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (acpi_device_is_battery(device) && device->dep_unmet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) acpi_set_device_status(device, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) status = acpi_bus_get_status_handle(device->handle, &sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) acpi_set_device_status(device, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (device->status.functional && !device->status.present) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) "functional but not present;\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) device->pnp.bus_id, (u32)sta));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) device->pnp.bus_id, (u32)sta));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) EXPORT_SYMBOL(acpi_bus_get_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void acpi_bus_private_data_handler(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) EXPORT_SYMBOL(acpi_bus_private_data_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int acpi_bus_attach_private_data(acpi_handle handle, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) status = acpi_attach_data(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) acpi_bus_private_data_handler, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) acpi_handle_debug(handle, "Error attaching device data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) EXPORT_SYMBOL_GPL(acpi_bus_attach_private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int acpi_bus_get_private_data(acpi_handle handle, void **data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) acpi_handle_debug(handle, "No context for object\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) EXPORT_SYMBOL_GPL(acpi_bus_get_private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) void acpi_bus_detach_private_data(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) acpi_detach_data(handle, acpi_bus_private_data_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) EXPORT_SYMBOL_GPL(acpi_bus_detach_private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static void acpi_print_osc_error(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct acpi_osc_context *context, char *error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) acpi_handle_debug(handle, "(%s): %s\n", context->uuid_str, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) pr_debug("_OSC request data:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) for (i = 0; i < context->cap.length; i += sizeof(u32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) pr_debug(" %x", *((u32 *)(context->cap.pointer + i)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) pr_debug("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct acpi_object_list input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) union acpi_object in_params[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) union acpi_object *out_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) guid_t guid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) u32 errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (!context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return AE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (guid_parse(context->uuid_str, &guid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return AE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) context->ret.length = ACPI_ALLOCATE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) context->ret.pointer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* Setting up input parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) input.count = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) input.pointer = in_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) in_params[0].type = ACPI_TYPE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) in_params[0].buffer.length = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) in_params[0].buffer.pointer = (u8 *)&guid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) in_params[1].type = ACPI_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) in_params[1].integer.value = context->rev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) in_params[2].type = ACPI_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) in_params[2].integer.value = context->cap.length/sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) in_params[3].type = ACPI_TYPE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) in_params[3].buffer.length = context->cap.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) in_params[3].buffer.pointer = context->cap.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) status = acpi_evaluate_object(handle, "_OSC", &input, &output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (!output.length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return AE_NULL_OBJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) out_obj = output.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (out_obj->type != ACPI_TYPE_BUFFER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) || out_obj->buffer.length != context->cap.length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) acpi_print_osc_error(handle, context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) "_OSC evaluation returned wrong type");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) status = AE_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) goto out_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* Need to ignore the bit0 in result code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (errors) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (errors & OSC_REQUEST_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) acpi_print_osc_error(handle, context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) "_OSC request failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (errors & OSC_INVALID_UUID_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) acpi_print_osc_error(handle, context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) "_OSC invalid UUID");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (errors & OSC_INVALID_REVISION_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) acpi_print_osc_error(handle, context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) "_OSC invalid revision");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (errors & OSC_CAPABILITIES_MASK_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (((u32 *)context->cap.pointer)[OSC_QUERY_DWORD]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) & OSC_QUERY_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) goto out_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) status = AE_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) goto out_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) status = AE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) goto out_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) out_success:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) context->ret.length = out_obj->buffer.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) context->ret.pointer = kmemdup(out_obj->buffer.pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) context->ret.length, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (!context->ret.pointer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) status = AE_NO_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) goto out_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) out_kfree:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) kfree(output.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (status != AE_OK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) context->ret.pointer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) EXPORT_SYMBOL(acpi_run_osc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) bool osc_sb_apei_support_acked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * ACPI 6.0 Section 8.4.4.2 Idle State Coordination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * OSPM supports platform coordinated low power idle(LPI) states
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) bool osc_pc_lpi_support_confirmed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) EXPORT_SYMBOL_GPL(osc_pc_lpi_support_confirmed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static void acpi_bus_osc_support(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) u32 capbuf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct acpi_osc_context context = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) .uuid_str = sb_uuid_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) .rev = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) .cap.length = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .cap.pointer = capbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) acpi_handle handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) capbuf[OSC_QUERY_DWORD] = OSC_QUERY_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) capbuf[OSC_SUPPORT_DWORD] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (IS_ENABLED(CONFIG_ACPI_PROCESSOR_AGGREGATOR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PAD_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (IS_ENABLED(CONFIG_ACPI_PROCESSOR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PPC_OST_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_HOTPLUG_OST_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PCLPI_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #ifdef CONFIG_ARM64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_GENERIC_INITIATOR_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) #ifdef CONFIG_X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_GENERIC_INITIATOR_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (boot_cpu_has(X86_FEATURE_HWP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_CPC_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_CPCV2_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (IS_ENABLED(CONFIG_SCHED_MC_PRIO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_CPC_DIVERSE_HIGH_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (!ghes_disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_APEI_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) u32 *capbuf_ret = context.ret.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (context.ret.length > OSC_SUPPORT_DWORD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) osc_sb_apei_support_acked =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_APEI_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) osc_pc_lpi_support_confirmed =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_PCLPI_SUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) kfree(context.ret.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /* do we need to check other returned cap? Sounds no */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /* --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) Notification Handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * acpi_bus_notify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * ---------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * Callback for all 'system-level' device notifications (values 0x00-0x7F).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct acpi_device *adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct acpi_driver *driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) bool hotplug_event = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) case ACPI_NOTIFY_BUS_CHECK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) hotplug_event = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) case ACPI_NOTIFY_DEVICE_CHECK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) hotplug_event = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) case ACPI_NOTIFY_DEVICE_WAKE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_WAKE event\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) case ACPI_NOTIFY_EJECT_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) hotplug_event = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK_LIGHT event\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /* TBD: Exactly what does 'light' mean? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) case ACPI_NOTIFY_FREQUENCY_MISMATCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) acpi_handle_err(handle, "Device cannot be configured due "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) "to a frequency mismatch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) case ACPI_NOTIFY_BUS_MODE_MISMATCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) acpi_handle_err(handle, "Device cannot be configured due "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) "to a bus mode mismatch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) case ACPI_NOTIFY_POWER_FAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) acpi_handle_err(handle, "Device has suffered a power fault\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) acpi_handle_debug(handle, "Unknown event type 0x%x\n", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) adev = acpi_bus_get_acpi_device(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (!adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) driver = adev->driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (driver && driver->ops.notify &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) driver->ops.notify(adev, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (!hotplug_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) acpi_bus_put_acpi_device(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (ACPI_SUCCESS(acpi_hotplug_schedule(adev, type)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) acpi_bus_put_acpi_device(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) acpi_evaluate_ost(handle, type, ost_code, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static void acpi_device_notify(acpi_handle handle, u32 event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) struct acpi_device *device = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) device->driver->ops.notify(device, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static void acpi_device_notify_fixed(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) struct acpi_device *device = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) /* Fixed hardware devices have no handles */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) acpi_device_notify(NULL, ACPI_FIXED_HARDWARE_EVENT, device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static u32 acpi_device_fixed_event(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_device_notify_fixed, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) return ACPI_INTERRUPT_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static int acpi_device_install_notify_handler(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) acpi_device_fixed_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) acpi_device_fixed_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) status = acpi_install_notify_handler(device->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) ACPI_DEVICE_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) acpi_device_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) static void acpi_device_remove_notify_handler(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) acpi_device_fixed_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) acpi_device_fixed_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) acpi_device_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) /* Handle events targeting \_SB device (at present only graceful shutdown) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) #define ACPI_SB_NOTIFY_SHUTDOWN_REQUEST 0x81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) #define ACPI_SB_INDICATE_INTERVAL 10000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static void sb_notify_work(struct work_struct *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) acpi_handle sb_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) orderly_poweroff(true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) * After initiating graceful shutdown, the ACPI spec requires OSPM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) * to evaluate _OST method once every 10seconds to indicate that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) * the shutdown is in progress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) acpi_get_handle(NULL, "\\_SB", &sb_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) pr_info("Graceful shutdown in progress.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) acpi_evaluate_ost(sb_handle, ACPI_OST_EC_OSPM_SHUTDOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) ACPI_OST_SC_OS_SHUTDOWN_IN_PROGRESS, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) msleep(ACPI_SB_INDICATE_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static void acpi_sb_notify(acpi_handle handle, u32 event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) static DECLARE_WORK(acpi_sb_work, sb_notify_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if (event == ACPI_SB_NOTIFY_SHUTDOWN_REQUEST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (!work_busy(&acpi_sb_work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) schedule_work(&acpi_sb_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) pr_warn("event %x is not supported by \\_SB device\n", event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) static int __init acpi_setup_sb_notify_handler(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) acpi_handle sb_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &sb_handle)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (ACPI_FAILURE(acpi_install_notify_handler(sb_handle, ACPI_DEVICE_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) acpi_sb_notify, NULL)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /* --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) Device Matching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * acpi_get_first_physical_node - Get first physical node of an ACPI device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) * @adev: ACPI device in question
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) * Return: First physical node of ACPI device @adev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) struct device *acpi_get_first_physical_node(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) struct mutex *physical_node_lock = &adev->physical_node_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) struct device *phys_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) mutex_lock(physical_node_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (list_empty(&adev->physical_node_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) phys_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) const struct acpi_device_physical_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) node = list_first_entry(&adev->physical_node_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) struct acpi_device_physical_node, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) phys_dev = node->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) mutex_unlock(physical_node_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return phys_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) EXPORT_SYMBOL_GPL(acpi_get_first_physical_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) static struct acpi_device *acpi_primary_dev_companion(struct acpi_device *adev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) const struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) const struct device *phys_dev = acpi_get_first_physical_node(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return phys_dev && phys_dev == dev ? adev : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * acpi_device_is_first_physical_node - Is given dev first physical node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) * @adev: ACPI companion device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) * @dev: Physical device to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * Function checks if given @dev is the first physical devices attached to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * the ACPI companion device. This distinction is needed in some cases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * where the same companion device is shared between many physical devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * Note that the caller have to provide valid @adev pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) bool acpi_device_is_first_physical_node(struct acpi_device *adev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) const struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) return !!acpi_primary_dev_companion(adev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) * acpi_companion_match() - Can we match via ACPI companion device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) * @dev: Device in question
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) * Check if the given device has an ACPI companion and if that companion has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * a valid list of PNP IDs, and if the device is the first (primary) physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) * device associated with it. Return the companion pointer if that's the case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) * or NULL otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) * If multiple physical devices are attached to a single ACPI companion, we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) * to be careful. The usage scenario for this kind of relationship is that all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * of the physical devices in question use resources provided by the ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) * companion. A typical case is an MFD device where all the sub-devices share
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) * the parent's ACPI companion. In such cases we can only allow the primary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) * (first) physical device to be matched with the help of the companion's PNP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) * IDs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) * Additional physical devices sharing the ACPI companion can still use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) * resources available from it but they will be matched normally using functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) * provided by their bus types (and analogously for their modalias).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct acpi_device *acpi_companion_match(const struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) struct acpi_device *adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) adev = ACPI_COMPANION(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (!adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (list_empty(&adev->pnp.ids))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) return acpi_primary_dev_companion(adev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) * acpi_of_match_device - Match device object using the "compatible" property.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) * @adev: ACPI device object to match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) * @of_match_table: List of device IDs to match against.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) * @of_id: OF ID if matched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) * If @dev has an ACPI companion which has ACPI_DT_NAMESPACE_HID in its list of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) * identifiers and a _DSD object with the "compatible" property, use that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) * property to match against the given list of identifiers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) static bool acpi_of_match_device(struct acpi_device *adev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) const struct of_device_id *of_match_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) const struct of_device_id **of_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) const union acpi_object *of_compatible, *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) int i, nval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (!adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) of_compatible = adev->data.of_compatible;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (!of_match_table || !of_compatible)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (of_compatible->type == ACPI_TYPE_PACKAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) nval = of_compatible->package.count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) obj = of_compatible->package.elements;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) } else { /* Must be ACPI_TYPE_STRING. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) nval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) obj = of_compatible;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /* Now we can look for the driver DT compatible strings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) for (i = 0; i < nval; i++, obj++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) const struct of_device_id *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) for (id = of_match_table; id->compatible[0]; id++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) if (!strcasecmp(obj->string.pointer, id->compatible)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) if (of_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) *of_id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) static bool acpi_of_modalias(struct acpi_device *adev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) char *modalias, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) const union acpi_object *of_compatible;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) const union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) const char *str, *chr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) of_compatible = adev->data.of_compatible;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (!of_compatible)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) if (of_compatible->type == ACPI_TYPE_PACKAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) obj = of_compatible->package.elements;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) else /* Must be ACPI_TYPE_STRING. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) obj = of_compatible;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) str = obj->string.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) chr = strchr(str, ',');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) strlcpy(modalias, chr ? chr + 1 : str, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) * acpi_set_modalias - Set modalias using "compatible" property or supplied ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) * @adev: ACPI device object to match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) * @default_id: ID string to use as default if no compatible string found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) * @modalias: Pointer to buffer that modalias value will be copied into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) * @len: Length of modalias buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) * This is a counterpart of of_modalias_node() for struct acpi_device objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) * If there is a compatible string for @adev, it will be copied to @modalias
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) * with the vendor prefix stripped; otherwise, @default_id will be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) void acpi_set_modalias(struct acpi_device *adev, const char *default_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) char *modalias, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (!acpi_of_modalias(adev, modalias, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) strlcpy(modalias, default_id, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) EXPORT_SYMBOL_GPL(acpi_set_modalias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) static bool __acpi_match_device_cls(const struct acpi_device_id *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) struct acpi_hardware_id *hwid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) int i, msk, byte_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) char buf[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (!id->cls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) /* Apply class-code bitmask, before checking each class-code byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) for (i = 1; i <= 3; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) byte_shift = 8 * (3 - i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) msk = (id->cls_msk >> byte_shift) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) if (!msk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) sprintf(buf, "%02x", (id->cls >> byte_shift) & msk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) if (strncmp(buf, &hwid->id[(i - 1) * 2], 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) static bool __acpi_match_device(struct acpi_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) const struct acpi_device_id *acpi_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) const struct of_device_id *of_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) const struct acpi_device_id **acpi_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) const struct of_device_id **of_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) const struct acpi_device_id *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) struct acpi_hardware_id *hwid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) * If the device is not present, it is unnecessary to load device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) * driver for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (!device || !device->status.present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) list_for_each_entry(hwid, &device->pnp.ids, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) /* First, check the ACPI/PNP IDs provided by the caller. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (acpi_ids) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) for (id = acpi_ids; id->id[0] || id->cls; id++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) if (id->id[0] && !strcmp((char *)id->id, hwid->id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) goto out_acpi_match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if (id->cls && __acpi_match_device_cls(id, hwid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) goto out_acpi_match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) * Next, check ACPI_DT_NAMESPACE_HID and try to match the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) * "compatible" property if found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (!strcmp(ACPI_DT_NAMESPACE_HID, hwid->id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) return acpi_of_match_device(device, of_ids, of_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) out_acpi_match:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) if (acpi_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) *acpi_id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) * acpi_match_device - Match a struct device against a given list of ACPI IDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) * @ids: Array of struct acpi_device_id object to match against.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * @dev: The device structure to match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) * Check if @dev has a valid ACPI handle and if there is a struct acpi_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) * object for that handle and use that object to match against a given list of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) * device IDs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) * Return a pointer to the first matching ID on success or %NULL on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) const struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) const struct acpi_device_id *id = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) __acpi_match_device(acpi_companion_match(dev), ids, NULL, &id, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) return id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) EXPORT_SYMBOL_GPL(acpi_match_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) static const void *acpi_of_device_get_match_data(const struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) struct acpi_device *adev = ACPI_COMPANION(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) const struct of_device_id *match = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) if (!acpi_of_match_device(adev, dev->driver->of_match_table, &match))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) return match->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) const void *acpi_device_get_match_data(const struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) const struct acpi_device_id *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (!dev->driver->acpi_match_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) return acpi_of_device_get_match_data(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) match = acpi_match_device(dev->driver->acpi_match_table, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if (!match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) return (const void *)match->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) EXPORT_SYMBOL_GPL(acpi_device_get_match_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) int acpi_match_device_ids(struct acpi_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) const struct acpi_device_id *ids)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) return __acpi_match_device(device, ids, NULL, NULL, NULL) ? 0 : -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) EXPORT_SYMBOL(acpi_match_device_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) bool acpi_driver_match_device(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) const struct device_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (!drv->acpi_match_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) return acpi_of_match_device(ACPI_COMPANION(dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) drv->of_match_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) return __acpi_match_device(acpi_companion_match(dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) drv->acpi_match_table, drv->of_match_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) EXPORT_SYMBOL_GPL(acpi_driver_match_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) /* --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) ACPI Driver Management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) * acpi_bus_register_driver - register a driver with the ACPI bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) * @driver: driver being registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) * Registers a driver with the ACPI bus. Searches the namespace for all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) * devices that match the driver's criteria and binds. Returns zero for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) * success or a negative error status for failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) int acpi_bus_register_driver(struct acpi_driver *driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) if (acpi_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) driver->drv.name = driver->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) driver->drv.bus = &acpi_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) driver->drv.owner = driver->owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) ret = driver_register(&driver->drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) EXPORT_SYMBOL(acpi_bus_register_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) * acpi_bus_unregister_driver - unregisters a driver with the ACPI bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) * @driver: driver to unregister
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) * Unregisters a driver with the ACPI bus. Searches the namespace for all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) * devices that match the driver's criteria and unbinds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) void acpi_bus_unregister_driver(struct acpi_driver *driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) driver_unregister(&driver->drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) EXPORT_SYMBOL(acpi_bus_unregister_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) /* --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) ACPI Bus operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) static int acpi_bus_match(struct device *dev, struct device_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) struct acpi_device *acpi_dev = to_acpi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) struct acpi_driver *acpi_drv = to_acpi_driver(drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) return acpi_dev->flags.match_driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) && !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) return __acpi_device_uevent_modalias(to_acpi_device(dev), env);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) static int acpi_device_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) struct acpi_device *acpi_dev = to_acpi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) if (acpi_dev->handler && !acpi_is_pnp_device(acpi_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if (!acpi_drv->ops.add)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) ret = acpi_drv->ops.add(acpi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) acpi_dev->driver = acpi_drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) ACPI_DEBUG_PRINT((ACPI_DB_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) "Driver [%s] successfully bound to device [%s]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) acpi_drv->name, acpi_dev->pnp.bus_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) if (acpi_drv->ops.notify) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) ret = acpi_device_install_notify_handler(acpi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) if (acpi_drv->ops.remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) acpi_drv->ops.remove(acpi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) acpi_dev->driver = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) acpi_dev->driver_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) acpi_drv->name, acpi_dev->pnp.bus_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) get_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) static int acpi_device_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) struct acpi_device *acpi_dev = to_acpi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) struct acpi_driver *acpi_drv = acpi_dev->driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) if (acpi_drv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) if (acpi_drv->ops.notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) acpi_device_remove_notify_handler(acpi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) if (acpi_drv->ops.remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) acpi_drv->ops.remove(acpi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) acpi_dev->driver = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) acpi_dev->driver_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) struct bus_type acpi_bus_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) .name = "acpi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) .match = acpi_bus_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) .probe = acpi_device_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) .remove = acpi_device_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) .uevent = acpi_device_uevent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) /* --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) Initialization/Cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) static int __init acpi_bus_init_irq(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) char *message = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) * Let the system know what interrupt model we are using by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) * evaluating the \_PIC object, if exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) switch (acpi_irq_model) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) case ACPI_IRQ_MODEL_PIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) message = "PIC";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) case ACPI_IRQ_MODEL_IOAPIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) message = "IOAPIC";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) case ACPI_IRQ_MODEL_IOSAPIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) message = "IOSAPIC";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) case ACPI_IRQ_MODEL_GIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) message = "GIC";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) case ACPI_IRQ_MODEL_PLATFORM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) message = "platform specific model";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) status = acpi_execute_simple_method(NULL, "\\_PIC", acpi_irq_model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) * acpi_early_init - Initialize ACPICA and populate the ACPI namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) * The ACPI tables are accessible after this, but the handling of events has not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) * been initialized and the global lock is not available yet, so AML should not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) * be executed at this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) * Doing this before switching the EFI runtime services to virtual mode allows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) * the EfiBootServices memory to be freed slightly earlier on boot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) void __init acpi_early_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) if (acpi_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) /* enable workarounds, unless strict ACPI spec. compliance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) if (!acpi_strict)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) acpi_gbl_enable_interpreter_slack = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) acpi_permanent_mmap = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) #ifdef CONFIG_X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) * If the machine falls into the DMI check table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) * DSDT will be copied to memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) * Note that calling dmi_check_system() here on other architectures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) * would not be OK because only x86 initializes dmi early enough.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) * Thankfully only x86 systems need such quirks for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) dmi_check_system(dsdt_dmi_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) status = acpi_reallocate_root_table();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) printk(KERN_ERR PREFIX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) "Unable to reallocate ACPI tables\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) goto error0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) status = acpi_initialize_subsystem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) printk(KERN_ERR PREFIX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) "Unable to initialize the ACPI Interpreter\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) goto error0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) #ifdef CONFIG_X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) if (!acpi_ioapic) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) /* compatible (0) means level (3) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) /* Set PIC-mode SCI trigger type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) * now that acpi_gbl_FADT is initialized,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) * update it with result from INT_SRC_OVR parsing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) error0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) disable_acpi();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) * acpi_subsystem_init - Finalize the early initialization of ACPI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) * Switch over the platform to the ACPI mode (if possible).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) * Doing this too early is generally unsafe, but at the same time it needs to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) * done before all things that really depend on ACPI. The right spot appears to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) * be before finalizing the EFI initialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) void __init acpi_subsystem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) if (acpi_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) disable_acpi();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) * If the system is using ACPI then we can be reasonably
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) * confident that any regulators are managed by the firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) * so tell the regulator core it has everything it needs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) * know.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) regulator_has_full_constraints();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) static acpi_status acpi_bus_table_handler(u32 event, void *table, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) acpi_scan_table_handler(event, table, context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) return acpi_sysfs_table_handler(event, table, context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) static int __init acpi_bus_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) acpi_os_initialize1();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) status = acpi_load_tables();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) printk(KERN_ERR PREFIX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) "Unable to load the System Description Tables\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) goto error1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) * ACPI 2.0 requires the EC driver to be loaded and work before the EC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) * device is found in the namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) * This is accomplished by looking for the ECDT table and getting the EC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) * parameters out of that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) * Do that before calling acpi_initialize_objects() which may trigger EC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) * address space accesses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) acpi_ec_ecdt_probe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) printk(KERN_ERR PREFIX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) "Unable to start the ACPI Interpreter\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) goto error1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) goto error1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) /* Set capability bits for _OSC under processor scope */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) acpi_early_processor_osc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) * _OSC method may exist in module level code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) * so it must be run after ACPI_FULL_INITIALIZATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) acpi_bus_osc_support();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) * _PDC control method may load dynamic SSDT tables,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) * and we need to install the table handler before that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) status = acpi_install_table_handler(acpi_bus_table_handler, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) acpi_sysfs_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) acpi_early_processor_set_pdc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) * Maybe EC region is required at bus_scan/acpi_get_devices. So it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) * is necessary to enable it as early as possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) acpi_ec_dsdt_probe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) printk(KERN_INFO PREFIX "Interpreter enabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) /* Initialize sleep structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) acpi_sleep_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) * Get the system interrupt model and evaluate \_PIC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) result = acpi_bus_init_irq();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) goto error1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) * Register the for all standard device notifications.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) &acpi_bus_notify, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) printk(KERN_ERR PREFIX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) "Unable to register for device notifications\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) goto error1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) * Create the top ACPI proc directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) result = bus_register(&acpi_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) if (!result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) /* Mimic structured exception handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) error1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) acpi_terminate();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) struct kobject *acpi_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) EXPORT_SYMBOL_GPL(acpi_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) static int __init acpi_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) if (acpi_disabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) printk(KERN_INFO PREFIX "Interpreter disabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) if (!acpi_kobj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) printk(KERN_WARNING "%s: kset create error\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) acpi_kobj = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) result = acpi_bus_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) kobject_put(acpi_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) disable_acpi();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) pci_mmcfg_late_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) acpi_iort_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) acpi_scan_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) acpi_ec_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) acpi_debugfs_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) acpi_sleep_proc_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) acpi_wakeup_device_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) acpi_debugger_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) acpi_setup_sb_notify_handler();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) subsys_initcall(acpi_init);