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>
51 pr_notice("%s detected - force copy of DSDT to local memory\n", id->ident); in set_copy_dsdt()
59 * Invoke DSDT corruption work-around on all Toshiba Satellite.
74 /* --------------------------------------------------------------------------
75 Device Management
76 -------------------------------------------------------------------------- */
78 acpi_status acpi_bus_get_status_handle(acpi_handle handle, in acpi_bus_get_status_handle() argument
83 status = acpi_evaluate_integer(handle, "_STA", NULL, sta); in acpi_bus_get_status_handle()
96 int acpi_bus_get_status(struct acpi_device *device) in acpi_bus_get_status() argument
101 if (acpi_device_always_present(device)) { in acpi_bus_get_status()
102 acpi_set_device_status(device, ACPI_STA_DEFAULT); in acpi_bus_get_status()
107 if (acpi_device_is_battery(device) && device->dep_unmet) { in acpi_bus_get_status()
108 acpi_set_device_status(device, 0); in acpi_bus_get_status()
112 status = acpi_bus_get_status_handle(device->handle, &sta); in acpi_bus_get_status()
114 return -ENODEV; in acpi_bus_get_status()
116 acpi_set_device_status(device, sta); in acpi_bus_get_status()
118 if (device->status.functional && !device->status.present) { in acpi_bus_get_status()
119 pr_debug("Device [%s] status [%08x]: functional but not present\n", in acpi_bus_get_status()
120 device->pnp.bus_id, (u32)sta); in acpi_bus_get_status()
123 pr_debug("Device [%s] status [%08x]\n", device->pnp.bus_id, (u32)sta); in acpi_bus_get_status()
128 void acpi_bus_private_data_handler(acpi_handle handle, in acpi_bus_private_data_handler() argument
135 int acpi_bus_attach_private_data(acpi_handle handle, void *data) in acpi_bus_attach_private_data() argument
139 status = acpi_attach_data(handle, in acpi_bus_attach_private_data()
142 acpi_handle_debug(handle, "Error attaching device data\n"); in acpi_bus_attach_private_data()
143 return -ENODEV; in acpi_bus_attach_private_data()
150 int acpi_bus_get_private_data(acpi_handle handle, void **data) in acpi_bus_get_private_data() argument
155 return -EINVAL; in acpi_bus_get_private_data()
157 status = acpi_get_data(handle, acpi_bus_private_data_handler, data); in acpi_bus_get_private_data()
159 acpi_handle_debug(handle, "No context for object\n"); in acpi_bus_get_private_data()
160 return -ENODEV; in acpi_bus_get_private_data()
167 void acpi_bus_detach_private_data(acpi_handle handle) in acpi_bus_detach_private_data() argument
169 acpi_detach_data(handle, acpi_bus_private_data_handler); in acpi_bus_detach_private_data()
173 static void acpi_print_osc_error(acpi_handle handle, in acpi_print_osc_error() argument
178 acpi_handle_debug(handle, "(%s): %s\n", context->uuid_str, error); in acpi_print_osc_error()
181 for (i = 0; i < context->cap.length; i += sizeof(u32)) in acpi_print_osc_error()
182 pr_debug(" %x", *((u32 *)(context->cap.pointer + i))); in acpi_print_osc_error()
187 acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context) in acpi_run_osc() argument
199 if (guid_parse(context->uuid_str, &guid)) in acpi_run_osc()
201 context->ret.length = ACPI_ALLOCATE_BUFFER; in acpi_run_osc()
202 context->ret.pointer = NULL; in acpi_run_osc()
211 in_params[1].integer.value = context->rev; in acpi_run_osc()
213 in_params[2].integer.value = context->cap.length/sizeof(u32); in acpi_run_osc()
215 in_params[3].buffer.length = context->cap.length; in acpi_run_osc()
216 in_params[3].buffer.pointer = context->cap.pointer; in acpi_run_osc()
218 status = acpi_evaluate_object(handle, "_OSC", &input, &output); in acpi_run_osc()
226 if (out_obj->type != ACPI_TYPE_BUFFER in acpi_run_osc()
227 || out_obj->buffer.length != context->cap.length) { in acpi_run_osc()
228 acpi_print_osc_error(handle, context, in acpi_run_osc()
234 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0); in acpi_run_osc()
237 acpi_print_osc_error(handle, context, in acpi_run_osc()
240 acpi_print_osc_error(handle, context, in acpi_run_osc()
243 acpi_print_osc_error(handle, context, in acpi_run_osc()
246 if (((u32 *)context->cap.pointer)[OSC_QUERY_DWORD] in acpi_run_osc()
256 context->ret.length = out_obj->buffer.length; in acpi_run_osc()
257 context->ret.pointer = kmemdup(out_obj->buffer.pointer, in acpi_run_osc()
258 context->ret.length, GFP_KERNEL); in acpi_run_osc()
259 if (!context->ret.pointer) { in acpi_run_osc()
286 static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
296 acpi_handle handle; in acpi_bus_osc_negotiate_platform_control() local
329 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle))) in acpi_bus_osc_negotiate_platform_control()
332 if (ACPI_FAILURE(acpi_run_osc(handle, &context))) in acpi_bus_osc_negotiate_platform_control()
340 if (ACPI_FAILURE(acpi_run_osc(handle, &context))) in acpi_bus_osc_negotiate_platform_control()
365 (bits & OSC_USB_USB3_TUNNELING) ? '+' : '-', in acpi_bus_decode_usb_osc()
366 (bits & OSC_USB_DP_TUNNELING) ? '+' : '-', in acpi_bus_decode_usb_osc()
367 (bits & OSC_USB_PCIE_TUNNELING) ? '+' : '-', in acpi_bus_decode_usb_osc()
368 (bits & OSC_USB_XDOMAIN) ? '+' : '-'); in acpi_bus_decode_usb_osc()
371 static u8 sb_usb_uuid_str[] = "23A0D13A-26AB-486C-9C5F-0FFA525A575A";
381 acpi_handle handle; in acpi_bus_osc_negotiate_usb_control() local
388 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle))) in acpi_bus_osc_negotiate_usb_control()
398 status = acpi_run_osc(handle, &context); in acpi_bus_osc_negotiate_usb_control()
418 /* --------------------------------------------------------------------------
420 -------------------------------------------------------------------------- */
424 * ---------------
425 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
427 static void acpi_bus_notify(acpi_handle handle, u32 type, void *data) in acpi_bus_notify() argument
436 acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n"); in acpi_bus_notify()
441 acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n"); in acpi_bus_notify()
446 acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_WAKE event\n"); in acpi_bus_notify()
450 acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n"); in acpi_bus_notify()
455 acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK_LIGHT event\n"); in acpi_bus_notify()
460 acpi_handle_err(handle, "Device cannot be configured due " in acpi_bus_notify()
465 acpi_handle_err(handle, "Device cannot be configured due " in acpi_bus_notify()
470 acpi_handle_err(handle, "Device has suffered a power fault\n"); in acpi_bus_notify()
474 acpi_handle_debug(handle, "Unknown event type 0x%x\n", type); in acpi_bus_notify()
478 adev = acpi_bus_get_acpi_device(handle); in acpi_bus_notify()
482 driver = adev->driver; in acpi_bus_notify()
483 if (driver && driver->ops.notify && in acpi_bus_notify()
484 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS)) in acpi_bus_notify()
485 driver->ops.notify(adev, type); in acpi_bus_notify()
498 acpi_evaluate_ost(handle, type, ost_code, NULL); in acpi_bus_notify()
501 static void acpi_notify_device(acpi_handle handle, u32 event, void *data) in acpi_notify_device() argument
503 struct acpi_device *device = data; in acpi_notify_device() local
505 device->driver->ops.notify(device, event); in acpi_notify_device()
510 struct acpi_device *device = data; in acpi_notify_device_fixed() local
513 acpi_notify_device(NULL, ACPI_FIXED_HARDWARE_EVENT, device); in acpi_notify_device_fixed()
522 static int acpi_device_install_notify_handler(struct acpi_device *device) in acpi_device_install_notify_handler() argument
526 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) in acpi_device_install_notify_handler()
530 device); in acpi_device_install_notify_handler()
531 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON) in acpi_device_install_notify_handler()
535 device); in acpi_device_install_notify_handler()
537 status = acpi_install_notify_handler(device->handle, in acpi_device_install_notify_handler()
540 device); in acpi_device_install_notify_handler()
543 return -EINVAL; in acpi_device_install_notify_handler()
547 static void acpi_device_remove_notify_handler(struct acpi_device *device) in acpi_device_remove_notify_handler() argument
549 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) in acpi_device_remove_notify_handler()
552 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON) in acpi_device_remove_notify_handler()
556 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, in acpi_device_remove_notify_handler()
560 /* Handle events targeting \_SB device (at present only graceful shutdown) */
585 static void acpi_sb_notify(acpi_handle handle, u32 event, void *data) in acpi_sb_notify() argument
593 pr_warn("event %x is not supported by \\_SB device\n", event); in acpi_sb_notify()
601 return -ENXIO; in acpi_setup_sb_notify_handler()
605 return -EINVAL; in acpi_setup_sb_notify_handler()
610 /* --------------------------------------------------------------------------
611 Device Matching
612 -------------------------------------------------------------------------- */
615 * acpi_get_first_physical_node - Get first physical node of an ACPI device
616 * @adev: ACPI device in question
618 * Return: First physical node of ACPI device @adev
620 struct device *acpi_get_first_physical_node(struct acpi_device *adev) in acpi_get_first_physical_node()
622 struct mutex *physical_node_lock = &adev->physical_node_lock; in acpi_get_first_physical_node()
623 struct device *phys_dev; in acpi_get_first_physical_node()
626 if (list_empty(&adev->physical_node_list)) { in acpi_get_first_physical_node()
631 node = list_first_entry(&adev->physical_node_list, in acpi_get_first_physical_node()
634 phys_dev = node->dev; in acpi_get_first_physical_node()
642 const struct device *dev) in acpi_primary_dev_companion()
644 const struct device *phys_dev = acpi_get_first_physical_node(adev); in acpi_primary_dev_companion()
650 * acpi_device_is_first_physical_node - Is given dev first physical node
651 * @adev: ACPI companion device
652 * @dev: Physical device to check
655 * the ACPI companion device. This distinction is needed in some cases
656 * where the same companion device is shared between many physical devices.
661 const struct device *dev) in acpi_device_is_first_physical_node()
667 * acpi_companion_match() - Can we match via ACPI companion device
668 * @dev: Device in question
670 * Check if the given device has an ACPI companion and if that companion has
671 * a valid list of PNP IDs, and if the device is the first (primary) physical
672 * device associated with it. Return the companion pointer if that's the case
678 * companion. A typical case is an MFD device where all the sub-devices share
680 * (first) physical device to be matched with the help of the companion's PNP
687 struct acpi_device *acpi_companion_match(const struct device *dev) in acpi_companion_match()
695 if (list_empty(&adev->pnp.ids)) in acpi_companion_match()
702 * acpi_of_match_device - Match device object using the "compatible" property.
703 * @adev: ACPI device object to match.
704 * @of_match_table: List of device IDs to match against.
721 of_compatible = adev->data.of_compatible; in acpi_of_match_device()
725 if (of_compatible->type == ACPI_TYPE_PACKAGE) { in acpi_of_match_device()
726 nval = of_compatible->package.count; in acpi_of_match_device()
727 obj = of_compatible->package.elements; in acpi_of_match_device()
736 for (id = of_match_table; id->compatible[0]; id++) in acpi_of_match_device()
737 if (!strcasecmp(obj->string.pointer, id->compatible)) { in acpi_of_match_device()
754 of_compatible = adev->data.of_compatible; in acpi_of_modalias()
758 if (of_compatible->type == ACPI_TYPE_PACKAGE) in acpi_of_modalias()
759 obj = of_compatible->package.elements; in acpi_of_modalias()
763 str = obj->string.pointer; in acpi_of_modalias()
771 * acpi_set_modalias - Set modalias using "compatible" property or supplied ID
772 * @adev: ACPI device object to match
795 if (!id->cls) in __acpi_match_device_cls()
798 /* Apply class-code bitmask, before checking each class-code byte */ in __acpi_match_device_cls()
800 byte_shift = 8 * (3 - i); in __acpi_match_device_cls()
801 msk = (id->cls_msk >> byte_shift) & 0xFF; in __acpi_match_device_cls()
805 sprintf(buf, "%02x", (id->cls >> byte_shift) & msk); in __acpi_match_device_cls()
806 if (strncmp(buf, &hwid->id[(i - 1) * 2], 2)) in __acpi_match_device_cls()
812 static bool __acpi_match_device(struct acpi_device *device, in __acpi_match_device() argument
822 * If the device is not present, it is unnecessary to load device in __acpi_match_device()
825 if (!device || !device->status.present) in __acpi_match_device()
828 list_for_each_entry(hwid, &device->pnp.ids, list) { in __acpi_match_device()
831 for (id = acpi_ids; id->id[0] || id->cls; id++) { in __acpi_match_device()
832 if (id->id[0] && !strcmp((char *)id->id, hwid->id)) in __acpi_match_device()
834 if (id->cls && __acpi_match_device_cls(id, hwid)) in __acpi_match_device()
843 if (!strcmp(ACPI_DT_NAMESPACE_HID, hwid->id)) in __acpi_match_device()
844 return acpi_of_match_device(device, of_ids, of_id); in __acpi_match_device()
855 * acpi_match_device - Match a struct device against a given list of ACPI IDs
857 * @dev: The device structure to match.
859 * Check if @dev has a valid ACPI handle and if there is a struct acpi_device
860 * object for that handle and use that object to match against a given list of
861 * device IDs.
866 const struct device *dev) in acpi_match_device()
875 static const void *acpi_of_device_get_match_data(const struct device *dev) in acpi_of_device_get_match_data()
880 if (!acpi_of_match_device(adev, dev->driver->of_match_table, &match)) in acpi_of_device_get_match_data()
883 return match->data; in acpi_of_device_get_match_data()
886 const void *acpi_device_get_match_data(const struct device *dev) in acpi_device_get_match_data()
890 if (!dev->driver->acpi_match_table) in acpi_device_get_match_data()
893 match = acpi_match_device(dev->driver->acpi_match_table, dev); in acpi_device_get_match_data()
897 return (const void *)match->driver_data; in acpi_device_get_match_data()
901 int acpi_match_device_ids(struct acpi_device *device, in acpi_match_device_ids() argument
904 return __acpi_match_device(device, ids, NULL, NULL, NULL) ? 0 : -ENOENT; in acpi_match_device_ids()
908 bool acpi_driver_match_device(struct device *dev, in acpi_driver_match_device()
911 if (!drv->acpi_match_table) in acpi_driver_match_device()
913 drv->of_match_table, in acpi_driver_match_device()
917 drv->acpi_match_table, drv->of_match_table, in acpi_driver_match_device()
922 /* --------------------------------------------------------------------------
924 -------------------------------------------------------------------------- */
927 * acpi_bus_register_driver - register a driver with the ACPI bus
939 return -ENODEV; in acpi_bus_register_driver()
940 driver->drv.name = driver->name; in acpi_bus_register_driver()
941 driver->drv.bus = &acpi_bus_type; in acpi_bus_register_driver()
942 driver->drv.owner = driver->owner; in acpi_bus_register_driver()
944 ret = driver_register(&driver->drv); in acpi_bus_register_driver()
951 * acpi_bus_unregister_driver - unregisters a driver with the ACPI bus
959 driver_unregister(&driver->drv); in acpi_bus_unregister_driver()
964 /* --------------------------------------------------------------------------
966 -------------------------------------------------------------------------- */
968 static int acpi_bus_match(struct device *dev, struct device_driver *drv) in acpi_bus_match()
973 return acpi_dev->flags.match_driver in acpi_bus_match()
974 && !acpi_match_device_ids(acpi_dev, acpi_drv->ids); in acpi_bus_match()
977 static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env) in acpi_device_uevent()
982 static int acpi_device_probe(struct device *dev) in acpi_device_probe()
985 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver); in acpi_device_probe()
988 if (acpi_dev->handler && !acpi_is_pnp_device(acpi_dev)) in acpi_device_probe()
989 return -EINVAL; in acpi_device_probe()
991 if (!acpi_drv->ops.add) in acpi_device_probe()
992 return -ENOSYS; in acpi_device_probe()
994 ret = acpi_drv->ops.add(acpi_dev); in acpi_device_probe()
998 acpi_dev->driver = acpi_drv; in acpi_device_probe()
1000 pr_debug("Driver [%s] successfully bound to device [%s]\n", in acpi_device_probe()
1001 acpi_drv->name, acpi_dev->pnp.bus_id); in acpi_device_probe()
1003 if (acpi_drv->ops.notify) { in acpi_device_probe()
1006 if (acpi_drv->ops.remove) in acpi_device_probe()
1007 acpi_drv->ops.remove(acpi_dev); in acpi_device_probe()
1009 acpi_dev->driver = NULL; in acpi_device_probe()
1010 acpi_dev->driver_data = NULL; in acpi_device_probe()
1015 pr_debug("Found driver [%s] for device [%s]\n", acpi_drv->name, in acpi_device_probe()
1016 acpi_dev->pnp.bus_id); in acpi_device_probe()
1022 static void acpi_device_remove(struct device *dev) in acpi_device_remove()
1025 struct acpi_driver *acpi_drv = acpi_dev->driver; in acpi_device_remove()
1028 if (acpi_drv->ops.notify) in acpi_device_remove()
1030 if (acpi_drv->ops.remove) in acpi_device_remove()
1031 acpi_drv->ops.remove(acpi_dev); in acpi_device_remove()
1033 acpi_dev->driver = NULL; in acpi_device_remove()
1034 acpi_dev->driver_data = NULL; in acpi_device_remove()
1047 /* --------------------------------------------------------------------------
1049 -------------------------------------------------------------------------- */
1080 return -ENODEV; in acpi_bus_init_irq()
1088 return -ENODEV; in acpi_bus_init_irq()
1095 * acpi_early_init - Initialize ACPICA and populate the ACPI namespace.
1149 /* Set PIC-mode SCI trigger type */ in acpi_early_init()
1167 * acpi_subsystem_init - Finalize the early initialization of ACPI.
1220 * device is found in the namespace. in acpi_bus_init()
1281 * Register the for all standard device notifications. in acpi_bus_init()
1303 return -ENODEV; in acpi_bus_init()
1315 return -ENODEV; in acpi_init()