Lines Matching +full:device +full:- +full:handle
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * acpi_bus.c - ACPI Bus Driver ($Revision: 80 $)
17 #include <linux/device.h>
50 pr_notice("%s detected - force copy of DSDT to local memory\n", id->ident); in set_copy_dsdt()
58 * Invoke DSDT corruption work-around on all Toshiba Satellite.
73 /* --------------------------------------------------------------------------
74 Device Management
75 -------------------------------------------------------------------------- */
77 acpi_status acpi_bus_get_status_handle(acpi_handle handle, in acpi_bus_get_status_handle() argument
82 status = acpi_evaluate_integer(handle, "_STA", NULL, sta); in acpi_bus_get_status_handle()
95 int acpi_bus_get_status(struct acpi_device *device) in acpi_bus_get_status() argument
100 if (acpi_device_override_status(device, &sta)) { in acpi_bus_get_status()
101 acpi_set_device_status(device, sta); in acpi_bus_get_status()
106 if (acpi_device_is_battery(device) && device->dep_unmet) { in acpi_bus_get_status()
107 acpi_set_device_status(device, 0); in acpi_bus_get_status()
111 status = acpi_bus_get_status_handle(device->handle, &sta); in acpi_bus_get_status()
113 return -ENODEV; in acpi_bus_get_status()
115 if (!device->status.present && device->status.enabled) { in acpi_bus_get_status()
116 pr_info(FW_BUG "Device [%s] status [%08x]: not present and enabled\n", in acpi_bus_get_status()
117 device->pnp.bus_id, (u32)sta); in acpi_bus_get_status()
118 device->status.enabled = 0; in acpi_bus_get_status()
121 * well to avoid attempting to use the device. in acpi_bus_get_status()
123 device->status.functional = 0; in acpi_bus_get_status()
126 acpi_set_device_status(device, sta); in acpi_bus_get_status()
128 if (device->status.functional && !device->status.present) { in acpi_bus_get_status()
129 pr_debug("Device [%s] status [%08x]: functional but not present\n", in acpi_bus_get_status()
130 device->pnp.bus_id, (u32)sta); in acpi_bus_get_status()
133 pr_debug("Device [%s] status [%08x]\n", device->pnp.bus_id, (u32)sta); in acpi_bus_get_status()
138 void acpi_bus_private_data_handler(acpi_handle handle, in acpi_bus_private_data_handler() argument
145 int acpi_bus_attach_private_data(acpi_handle handle, void *data) in acpi_bus_attach_private_data() argument
149 status = acpi_attach_data(handle, in acpi_bus_attach_private_data()
152 acpi_handle_debug(handle, "Error attaching device data\n"); in acpi_bus_attach_private_data()
153 return -ENODEV; in acpi_bus_attach_private_data()
160 int acpi_bus_get_private_data(acpi_handle handle, void **data) in acpi_bus_get_private_data() argument
165 return -EINVAL; in acpi_bus_get_private_data()
167 status = acpi_get_data(handle, acpi_bus_private_data_handler, data); in acpi_bus_get_private_data()
169 acpi_handle_debug(handle, "No context for object\n"); in acpi_bus_get_private_data()
170 return -ENODEV; in acpi_bus_get_private_data()
177 void acpi_bus_detach_private_data(acpi_handle handle) in acpi_bus_detach_private_data() argument
179 acpi_detach_data(handle, acpi_bus_private_data_handler); in acpi_bus_detach_private_data()
183 static void acpi_print_osc_error(acpi_handle handle, in acpi_print_osc_error() argument
188 acpi_handle_debug(handle, "(%s): %s\n", context->uuid_str, error); in acpi_print_osc_error()
191 for (i = 0; i < context->cap.length; i += sizeof(u32)) in acpi_print_osc_error()
192 pr_debug(" %x", *((u32 *)(context->cap.pointer + i))); in acpi_print_osc_error()
197 acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context) in acpi_run_osc() argument
209 if (guid_parse(context->uuid_str, &guid)) in acpi_run_osc()
211 context->ret.length = ACPI_ALLOCATE_BUFFER; in acpi_run_osc()
212 context->ret.pointer = NULL; in acpi_run_osc()
221 in_params[1].integer.value = context->rev; in acpi_run_osc()
223 in_params[2].integer.value = context->cap.length/sizeof(u32); in acpi_run_osc()
225 in_params[3].buffer.length = context->cap.length; in acpi_run_osc()
226 in_params[3].buffer.pointer = context->cap.pointer; in acpi_run_osc()
228 status = acpi_evaluate_object(handle, "_OSC", &input, &output); in acpi_run_osc()
236 if (out_obj->type != ACPI_TYPE_BUFFER in acpi_run_osc()
237 || out_obj->buffer.length != context->cap.length) { in acpi_run_osc()
238 acpi_print_osc_error(handle, context, in acpi_run_osc()
244 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0); in acpi_run_osc()
247 acpi_print_osc_error(handle, context, in acpi_run_osc()
250 acpi_print_osc_error(handle, context, in acpi_run_osc()
253 acpi_print_osc_error(handle, context, in acpi_run_osc()
256 if (((u32 *)context->cap.pointer)[OSC_QUERY_DWORD] in acpi_run_osc()
266 context->ret.length = out_obj->buffer.length; in acpi_run_osc()
267 context->ret.pointer = kmemdup(out_obj->buffer.pointer, in acpi_run_osc()
268 context->ret.length, GFP_KERNEL); in acpi_run_osc()
269 if (!context->ret.pointer) { in acpi_run_osc()
291 * ACPI 6.2 Section 6.2.11.2 'Platform-Wide OSPM Capabilities':
298 * - PCC or Functional Fixed Hardware address space if defined
299 * - SystemMemory address space (NULL register) if not defined
312 static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
322 acpi_handle handle; in acpi_bus_osc_negotiate_platform_control() local
367 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle))) in acpi_bus_osc_negotiate_platform_control()
370 if (ACPI_FAILURE(acpi_run_osc(handle, &context))) in acpi_bus_osc_negotiate_platform_control()
387 if (ACPI_FAILURE(acpi_run_osc(handle, &context))) in acpi_bus_osc_negotiate_platform_control()
420 (bits & OSC_USB_USB3_TUNNELING) ? '+' : '-', in acpi_bus_decode_usb_osc()
421 (bits & OSC_USB_DP_TUNNELING) ? '+' : '-', in acpi_bus_decode_usb_osc()
422 (bits & OSC_USB_PCIE_TUNNELING) ? '+' : '-', in acpi_bus_decode_usb_osc()
423 (bits & OSC_USB_XDOMAIN) ? '+' : '-'); in acpi_bus_decode_usb_osc()
426 static u8 sb_usb_uuid_str[] = "23A0D13A-26AB-486C-9C5F-0FFA525A575A";
436 acpi_handle handle; in acpi_bus_osc_negotiate_usb_control() local
443 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle))) in acpi_bus_osc_negotiate_usb_control()
458 status = acpi_run_osc(handle, &context); in acpi_bus_osc_negotiate_usb_control()
479 status = acpi_run_osc(handle, &context); in acpi_bus_osc_negotiate_usb_control()
499 /* --------------------------------------------------------------------------
501 -------------------------------------------------------------------------- */
504 * acpi_bus_notify - Global system-level (0x00-0x7F) notifications handler
505 * @handle: Target ACPI object.
509 * This only handles notifications related to device hotplug.
511 static void acpi_bus_notify(acpi_handle handle, u32 type, void *data) in acpi_bus_notify() argument
517 acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n"); in acpi_bus_notify()
521 acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n"); in acpi_bus_notify()
525 acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_WAKE event\n"); in acpi_bus_notify()
529 acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n"); in acpi_bus_notify()
533 acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK_LIGHT event\n"); in acpi_bus_notify()
538 acpi_handle_err(handle, "Device cannot be configured due " in acpi_bus_notify()
543 acpi_handle_err(handle, "Device cannot be configured due " in acpi_bus_notify()
548 acpi_handle_err(handle, "Device has suffered a power fault\n"); in acpi_bus_notify()
552 acpi_handle_debug(handle, "Unknown event type 0x%x\n", type); in acpi_bus_notify()
556 adev = acpi_get_acpi_dev(handle); in acpi_bus_notify()
563 acpi_evaluate_ost(handle, type, ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL); in acpi_bus_notify()
566 static void acpi_notify_device(acpi_handle handle, u32 event, void *data) in acpi_notify_device() argument
568 struct acpi_device *device = data; in acpi_notify_device() local
569 struct acpi_driver *acpi_drv = to_acpi_driver(device->dev.driver); in acpi_notify_device()
571 acpi_drv->ops.notify(device, event); in acpi_notify_device()
574 static int acpi_device_install_notify_handler(struct acpi_device *device, in acpi_device_install_notify_handler() argument
577 u32 type = acpi_drv->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS ? in acpi_device_install_notify_handler()
581 status = acpi_install_notify_handler(device->handle, type, in acpi_device_install_notify_handler()
582 acpi_notify_device, device); in acpi_device_install_notify_handler()
584 return -EINVAL; in acpi_device_install_notify_handler()
589 static void acpi_device_remove_notify_handler(struct acpi_device *device, in acpi_device_remove_notify_handler() argument
592 u32 type = acpi_drv->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS ? in acpi_device_remove_notify_handler()
595 acpi_remove_notify_handler(device->handle, type, in acpi_device_remove_notify_handler()
607 status = acpi_install_notify_handler(adev->handle, handler_type, in acpi_dev_install_notify_handler()
610 return -ENODEV; in acpi_dev_install_notify_handler()
620 acpi_remove_notify_handler(adev->handle, handler_type, handler); in acpi_dev_remove_notify_handler()
625 /* Handle events targeting \_SB device (at present only graceful shutdown) */
650 static void acpi_sb_notify(acpi_handle handle, u32 event, void *data) in acpi_sb_notify() argument
658 pr_warn("event %x is not supported by \\_SB device\n", event); in acpi_sb_notify()
667 return -ENXIO; in acpi_setup_sb_notify_handler()
671 return -EINVAL; in acpi_setup_sb_notify_handler()
676 /* --------------------------------------------------------------------------
677 Device Matching
678 -------------------------------------------------------------------------- */
681 * acpi_get_first_physical_node - Get first physical node of an ACPI device
682 * @adev: ACPI device in question
684 * Return: First physical node of ACPI device @adev
686 struct device *acpi_get_first_physical_node(struct acpi_device *adev) in acpi_get_first_physical_node()
688 struct mutex *physical_node_lock = &adev->physical_node_lock; in acpi_get_first_physical_node()
689 struct device *phys_dev; in acpi_get_first_physical_node()
692 if (list_empty(&adev->physical_node_list)) { in acpi_get_first_physical_node()
697 node = list_first_entry(&adev->physical_node_list, in acpi_get_first_physical_node()
700 phys_dev = node->dev; in acpi_get_first_physical_node()
708 const struct device *dev) in acpi_primary_dev_companion()
710 const struct device *phys_dev = acpi_get_first_physical_node(adev); in acpi_primary_dev_companion()
716 * acpi_device_is_first_physical_node - Is given dev first physical node
717 * @adev: ACPI companion device
718 * @dev: Physical device to check
721 * the ACPI companion device. This distinction is needed in some cases
722 * where the same companion device is shared between many physical devices.
727 const struct device *dev) in acpi_device_is_first_physical_node()
733 * acpi_companion_match() - Can we match via ACPI companion device
734 * @dev: Device in question
736 * Check if the given device has an ACPI companion and if that companion has
737 * a valid list of PNP IDs, and if the device is the first (primary) physical
738 * device associated with it. Return the companion pointer if that's the case
744 * companion. A typical case is an MFD device where all the sub-devices share
746 * (first) physical device to be matched with the help of the companion's PNP
753 const struct acpi_device *acpi_companion_match(const struct device *dev) in acpi_companion_match()
761 if (list_empty(&adev->pnp.ids)) in acpi_companion_match()
768 * acpi_of_match_device - Match device object using the "compatible" property.
769 * @adev: ACPI device object to match.
770 * @of_match_table: List of device IDs to match against.
787 of_compatible = adev->data.of_compatible; in acpi_of_match_device()
791 if (of_compatible->type == ACPI_TYPE_PACKAGE) { in acpi_of_match_device()
792 nval = of_compatible->package.count; in acpi_of_match_device()
793 obj = of_compatible->package.elements; in acpi_of_match_device()
802 for (id = of_match_table; id->compatible[0]; id++) in acpi_of_match_device()
803 if (!strcasecmp(obj->string.pointer, id->compatible)) { in acpi_of_match_device()
820 of_compatible = adev->data.of_compatible; in acpi_of_modalias()
824 if (of_compatible->type == ACPI_TYPE_PACKAGE) in acpi_of_modalias()
825 obj = of_compatible->package.elements; in acpi_of_modalias()
829 str = obj->string.pointer; in acpi_of_modalias()
837 * acpi_set_modalias - Set modalias using "compatible" property or supplied ID
838 * @adev: ACPI device object to match
862 if (!id->cls) in __acpi_match_device_cls()
865 /* Apply class-code bitmask, before checking each class-code byte */ in __acpi_match_device_cls()
867 byte_shift = 8 * (3 - i); in __acpi_match_device_cls()
868 msk = (id->cls_msk >> byte_shift) & 0xFF; in __acpi_match_device_cls()
872 sprintf(buf, "%02x", (id->cls >> byte_shift) & msk); in __acpi_match_device_cls()
873 if (strncmp(buf, &hwid->id[(i - 1) * 2], 2)) in __acpi_match_device_cls()
879 static bool __acpi_match_device(const struct acpi_device *device, in __acpi_match_device() argument
889 * If the device is not present, it is unnecessary to load device in __acpi_match_device()
892 if (!device || !device->status.present) in __acpi_match_device()
895 list_for_each_entry(hwid, &device->pnp.ids, list) { in __acpi_match_device()
898 for (id = acpi_ids; id->id[0] || id->cls; id++) { in __acpi_match_device()
899 if (id->id[0] && !strcmp((char *)id->id, hwid->id)) in __acpi_match_device()
901 if (id->cls && __acpi_match_device_cls(id, hwid)) in __acpi_match_device()
910 if (!strcmp(ACPI_DT_NAMESPACE_HID, hwid->id)) in __acpi_match_device()
911 return acpi_of_match_device(device, of_ids, of_id); in __acpi_match_device()
922 * acpi_match_acpi_device - Match an ACPI device against a given list of ACPI IDs
924 * @adev: The ACPI device pointer to match.
926 * Match the ACPI device @adev against a given list of ACPI IDs @ids.
942 * acpi_match_device - Match a struct device against a given list of ACPI IDs
944 * @dev: The device structure to match.
946 * Check if @dev has a valid ACPI handle and if there is a struct acpi_device
947 * object for that handle and use that object to match against a given list of
948 * device IDs.
953 const struct device *dev) in acpi_match_device()
959 static const void *acpi_of_device_get_match_data(const struct device *dev) in acpi_of_device_get_match_data()
964 if (!acpi_of_match_device(adev, dev->driver->of_match_table, &match)) in acpi_of_device_get_match_data()
967 return match->data; in acpi_of_device_get_match_data()
970 const void *acpi_device_get_match_data(const struct device *dev) in acpi_device_get_match_data()
972 const struct acpi_device_id *acpi_ids = dev->driver->acpi_match_table; in acpi_device_get_match_data()
982 return (const void *)match->driver_data; in acpi_device_get_match_data()
986 int acpi_match_device_ids(struct acpi_device *device, in acpi_match_device_ids() argument
989 return __acpi_match_device(device, ids, NULL, NULL, NULL) ? 0 : -ENOENT; in acpi_match_device_ids()
993 bool acpi_driver_match_device(struct device *dev, in acpi_driver_match_device()
996 const struct acpi_device_id *acpi_ids = drv->acpi_match_table; in acpi_driver_match_device()
997 const struct of_device_id *of_ids = drv->of_match_table; in acpi_driver_match_device()
1006 /* --------------------------------------------------------------------------
1008 -------------------------------------------------------------------------- */
1011 * __acpi_bus_register_driver - register a driver with the ACPI bus
1022 return -ENODEV; in __acpi_bus_register_driver()
1023 driver->drv.name = driver->name; in __acpi_bus_register_driver()
1024 driver->drv.bus = &acpi_bus_type; in __acpi_bus_register_driver()
1025 driver->drv.owner = owner; in __acpi_bus_register_driver()
1027 return driver_register(&driver->drv); in __acpi_bus_register_driver()
1033 * acpi_bus_unregister_driver - unregisters a driver with the ACPI bus
1041 driver_unregister(&driver->drv); in acpi_bus_unregister_driver()
1046 /* --------------------------------------------------------------------------
1048 -------------------------------------------------------------------------- */
1050 static int acpi_bus_match(struct device *dev, const struct device_driver *drv) in acpi_bus_match()
1055 return acpi_dev->flags.match_driver in acpi_bus_match()
1056 && !acpi_match_device_ids(acpi_dev, acpi_drv->ids); in acpi_bus_match()
1059 static int acpi_device_uevent(const struct device *dev, struct kobj_uevent_env *env) in acpi_device_uevent()
1064 static int acpi_device_probe(struct device *dev) in acpi_device_probe()
1067 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver); in acpi_device_probe()
1070 if (acpi_dev->handler && !acpi_is_pnp_device(acpi_dev)) in acpi_device_probe()
1071 return -EINVAL; in acpi_device_probe()
1073 if (!acpi_drv->ops.add) in acpi_device_probe()
1074 return -ENOSYS; in acpi_device_probe()
1076 ret = acpi_drv->ops.add(acpi_dev); in acpi_device_probe()
1078 acpi_dev->driver_data = NULL; in acpi_device_probe()
1082 pr_debug("Driver [%s] successfully bound to device [%s]\n", in acpi_device_probe()
1083 acpi_drv->name, acpi_dev->pnp.bus_id); in acpi_device_probe()
1085 if (acpi_drv->ops.notify) { in acpi_device_probe()
1088 if (acpi_drv->ops.remove) in acpi_device_probe()
1089 acpi_drv->ops.remove(acpi_dev); in acpi_device_probe()
1091 acpi_dev->driver_data = NULL; in acpi_device_probe()
1096 pr_debug("Found driver [%s] for device [%s]\n", acpi_drv->name, in acpi_device_probe()
1097 acpi_dev->pnp.bus_id); in acpi_device_probe()
1103 static void acpi_device_remove(struct device *dev) in acpi_device_remove()
1106 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver); in acpi_device_remove()
1108 if (acpi_drv->ops.notify) in acpi_device_remove()
1111 if (acpi_drv->ops.remove) in acpi_device_remove()
1112 acpi_drv->ops.remove(acpi_dev); in acpi_device_remove()
1114 acpi_dev->driver_data = NULL; in acpi_device_remove()
1127 int acpi_bus_for_each_dev(int (*fn)(struct device *, void *), void *data) in acpi_bus_for_each_dev() argument
1138 static int acpi_dev_for_one_check(struct device *dev, void *context) in acpi_dev_for_one_check()
1142 if (dev->bus != &acpi_bus_type) in acpi_dev_for_one_check()
1145 return adwc->fn(to_acpi_device(dev), adwc->data); in acpi_dev_for_one_check()
1157 return device_for_each_child(&adev->dev, &adwc, acpi_dev_for_one_check); in acpi_dev_for_each_child()
1169 return device_for_each_child_reverse(&adev->dev, &adwc, acpi_dev_for_one_check); in acpi_dev_for_each_child_reverse()
1172 /* --------------------------------------------------------------------------
1174 -------------------------------------------------------------------------- */
1211 return -ENODEV; in acpi_bus_init_irq()
1219 return -ENODEV; in acpi_bus_init_irq()
1226 * acpi_early_init - Initialize ACPICA and populate the ACPI namespace.
1280 /* Set PIC-mode SCI trigger type */ in acpi_early_init()
1298 * acpi_subsystem_init - Finalize the early initialization of ACPI.
1351 * device is found in the namespace. in acpi_bus_init()
1409 * Register the for all standard device notifications. in acpi_bus_init()
1431 return -ENODEV; in acpi_bus_init()
1443 return -ENODEV; in acpi_init()