Lines Matching +full:device +full:- +full:handle
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * acpi_utils.c - ACPI Utility Functions ($Revision: 10 $)
23 /* --------------------------------------------------------------------------
25 -------------------------------------------------------------------------- */
44 if (!package || (package->type != ACPI_TYPE_PACKAGE) in acpi_extract_package()
45 || (package->package.count < 1)) { in acpi_extract_package()
50 if (!format || !format->pointer || (format->length < 1)) { in acpi_extract_package()
60 format_count = (format->length / sizeof(char)) - 1; in acpi_extract_package()
61 if (format_count > package->package.count) { in acpi_extract_package()
63 format_count, package->package.count); in acpi_extract_package()
67 format_string = format->pointer; in acpi_extract_package()
74 union acpi_object *element = &(package->package.elements[i]); in acpi_extract_package()
76 switch (element->type) { in acpi_extract_package()
103 (element->string.length * sizeof(char)) + in acpi_extract_package()
109 sizeof(u8 *) + element->buffer.length; in acpi_extract_package()
134 /* TBD: handle nested packages... */ in acpi_extract_package()
142 if (buffer->length == ACPI_ALLOCATE_BUFFER) { in acpi_extract_package()
143 buffer->pointer = ACPI_ALLOCATE_ZEROED(size_required); in acpi_extract_package()
144 if (!buffer->pointer) in acpi_extract_package()
146 buffer->length = size_required; in acpi_extract_package()
148 if (buffer->length < size_required) { in acpi_extract_package()
149 buffer->length = size_required; in acpi_extract_package()
151 } else if (buffer->length != size_required || in acpi_extract_package()
152 !buffer->pointer) { in acpi_extract_package()
157 head = buffer->pointer; in acpi_extract_package()
158 tail = buffer->pointer + tail_offset; in acpi_extract_package()
166 union acpi_object *element = &(package->package.elements[i]); in acpi_extract_package()
168 switch (element->type) { in acpi_extract_package()
174 element->integer.value; in acpi_extract_package()
181 element->integer.value; in acpi_extract_package()
200 memcpy(tail, element->string.pointer, in acpi_extract_package()
201 element->string.length); in acpi_extract_package()
203 tail += element->string.length * sizeof(char); in acpi_extract_package()
211 memcpy(tail, element->buffer.pointer, in acpi_extract_package()
212 element->buffer.length); in acpi_extract_package()
214 tail += element->buffer.length; in acpi_extract_package()
225 (void *)element->reference.handle; in acpi_extract_package()
234 /* TBD: handle nested packages... */ in acpi_extract_package()
247 acpi_evaluate_integer(acpi_handle handle, in acpi_evaluate_integer() argument
260 status = acpi_evaluate_object(handle, pathname, arguments, &buffer); in acpi_evaluate_integer()
262 acpi_util_eval_error(handle, pathname, status); in acpi_evaluate_integer()
267 acpi_util_eval_error(handle, pathname, AE_BAD_DATA); in acpi_evaluate_integer()
273 acpi_handle_debug(handle, "Return value [%llu]\n", *data); in acpi_evaluate_integer()
280 int acpi_get_local_address(acpi_handle handle, u32 *addr) in acpi_get_local_address() argument
285 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr); in acpi_get_local_address()
287 return -ENODATA; in acpi_get_local_address()
296 const char *acpi_get_subsystem_id(acpi_handle handle) in acpi_get_subsystem_id() argument
304 status = acpi_evaluate_object(handle, METHOD_NAME__SUB, NULL, &buffer); in acpi_get_subsystem_id()
306 acpi_handle_debug(handle, "Reading ACPI _SUB failed: %#x\n", status); in acpi_get_subsystem_id()
307 return ERR_PTR(-ENODATA); in acpi_get_subsystem_id()
311 if (obj->type == ACPI_TYPE_STRING) { in acpi_get_subsystem_id()
312 len = strlen(obj->string.pointer); in acpi_get_subsystem_id()
314 sub = kstrdup(obj->string.pointer, GFP_KERNEL); in acpi_get_subsystem_id()
316 sub = ERR_PTR(-ENOMEM); in acpi_get_subsystem_id()
318 acpi_handle_err(handle, "ACPI _SUB Length %zu is Invalid\n", len); in acpi_get_subsystem_id()
319 sub = ERR_PTR(-ENODATA); in acpi_get_subsystem_id()
322 acpi_handle_warn(handle, "Warning ACPI _SUB did not return a string\n"); in acpi_get_subsystem_id()
323 sub = ERR_PTR(-ENODATA); in acpi_get_subsystem_id()
333 acpi_evaluate_reference(acpi_handle handle, in acpi_evaluate_reference() argument
351 status = acpi_evaluate_object(handle, pathname, arguments, &buffer); in acpi_evaluate_reference()
359 acpi_util_eval_error(handle, pathname, status); in acpi_evaluate_reference()
362 if (package->type != ACPI_TYPE_PACKAGE) { in acpi_evaluate_reference()
364 acpi_util_eval_error(handle, pathname, status); in acpi_evaluate_reference()
367 if (!package->package.count) { in acpi_evaluate_reference()
369 acpi_util_eval_error(handle, pathname, status); in acpi_evaluate_reference()
373 if (package->package.count > ACPI_MAX_HANDLES) { in acpi_evaluate_reference()
377 list->count = package->package.count; in acpi_evaluate_reference()
381 for (i = 0; i < list->count; i++) { in acpi_evaluate_reference()
383 element = &(package->package.elements[i]); in acpi_evaluate_reference()
385 if (element->type != ACPI_TYPE_LOCAL_REFERENCE) { in acpi_evaluate_reference()
387 acpi_util_eval_error(handle, pathname, status); in acpi_evaluate_reference()
391 if (!element->reference.handle) { in acpi_evaluate_reference()
393 acpi_util_eval_error(handle, pathname, status); in acpi_evaluate_reference()
398 list->handles[i] = element->reference.handle; in acpi_evaluate_reference()
399 acpi_handle_debug(list->handles[i], "Found in reference list\n"); in acpi_evaluate_reference()
404 list->count = 0; in acpi_evaluate_reference()
405 //kfree(list->handles); in acpi_evaluate_reference()
416 acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld) in acpi_get_physical_device_location() argument
422 status = acpi_evaluate_object(handle, "_PLD", NULL, &buffer); in acpi_get_physical_device_location()
429 if (!output || output->type != ACPI_TYPE_PACKAGE in acpi_get_physical_device_location()
430 || !output->package.count in acpi_get_physical_device_location()
431 || output->package.elements[0].type != ACPI_TYPE_BUFFER in acpi_get_physical_device_location()
432 || output->package.elements[0].buffer.length < ACPI_PLD_REV1_BUFFER_SIZE) { in acpi_get_physical_device_location()
438 output->package.elements[0].buffer.pointer, in acpi_get_physical_device_location()
439 output->package.elements[0].buffer.length, in acpi_get_physical_device_location()
450 * @handle: ACPI device handle
460 acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code, in acpi_evaluate_ost() argument
473 params[2].buffer.pointer = status_buf->pointer; in acpi_evaluate_ost()
474 params[2].buffer.length = status_buf->length; in acpi_evaluate_ost()
480 return acpi_evaluate_object(handle, "_OST", &arg_list, NULL); in acpi_evaluate_ost()
485 * acpi_handle_path: Return the object path of handle
486 * @handle: ACPI device handle
490 static char *acpi_handle_path(acpi_handle handle) in acpi_handle_path() argument
498 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer) != AE_OK) in acpi_handle_path()
506 * @handle: ACPI device handle
515 acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...) in acpi_handle_printk() argument
525 path = acpi_handle_path(handle); in acpi_handle_printk()
537 * @handle: ACPI device handle
546 __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, in __acpi_handle_debug() argument
557 path = acpi_handle_path(handle); in __acpi_handle_debug()
567 * acpi_evaluation_failure_warn - Log evaluation failure warning.
568 * @handle: Parent object handle.
572 void acpi_evaluation_failure_warn(acpi_handle handle, const char *name, in acpi_evaluation_failure_warn() argument
575 acpi_handle_warn(handle, "%s evaluation failed: %s\n", name, in acpi_evaluation_failure_warn()
581 * acpi_has_method: Check whether @handle has a method named @name
582 * @handle: ACPI device handle
585 * Check whether @handle has a method named @name.
587 bool acpi_has_method(acpi_handle handle, char *name) in acpi_has_method() argument
591 return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp)); in acpi_has_method()
595 acpi_status acpi_execute_simple_method(acpi_handle handle, char *method, in acpi_execute_simple_method() argument
603 return acpi_evaluate_object(handle, method, &arg_list, NULL); in acpi_execute_simple_method()
609 * @handle: ACPI device handle
611 * Evaluate device's _EJ0 method for hotplug operations.
613 acpi_status acpi_evaluate_ej0(acpi_handle handle) in acpi_evaluate_ej0() argument
617 status = acpi_execute_simple_method(handle, "_EJ0", 1); in acpi_evaluate_ej0()
619 acpi_handle_warn(handle, "No _EJ0 support for device\n"); in acpi_evaluate_ej0()
621 acpi_handle_warn(handle, "Eject failed (0x%x)\n", status); in acpi_evaluate_ej0()
627 * acpi_evaluate_lck: Evaluate _LCK method to lock/unlock device
628 * @handle: ACPI device handle
629 * @lock: lock device if non-zero, otherwise unlock device
631 * Evaluate device's _LCK method if present to lock/unlock device
633 acpi_status acpi_evaluate_lck(acpi_handle handle, int lock) in acpi_evaluate_lck() argument
637 status = acpi_execute_simple_method(handle, "_LCK", !!lock); in acpi_evaluate_lck()
640 acpi_handle_warn(handle, in acpi_evaluate_lck()
641 "Locking device failed (0x%x)\n", status); in acpi_evaluate_lck()
643 acpi_handle_warn(handle, in acpi_evaluate_lck()
644 "Unlocking device failed (0x%x)\n", status); in acpi_evaluate_lck()
652 * @handle: ACPI device handle
657 * Evaluate device's _REG method to register OpRegion presence.
659 acpi_status acpi_evaluate_reg(acpi_handle handle, u8 space_id, u32 function) in acpi_evaluate_reg() argument
671 return acpi_evaluate_object(handle, "_REG", &arg_list, NULL); in acpi_evaluate_reg()
676 * acpi_evaluate_dsm - evaluate device's _DSM method
677 * @handle: ACPI device handle
683 * Evaluate device's _DSM method with specified GUID, revision id and
690 acpi_evaluate_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 func, in acpi_evaluate_dsm() argument
716 ret = acpi_evaluate_object(handle, "_DSM", &input, &buf); in acpi_evaluate_dsm()
721 acpi_handle_warn(handle, in acpi_evaluate_dsm()
729 * acpi_check_dsm - check if _DSM method supports requested functions.
730 * @handle: ACPI device handle
735 * Evaluate device's _DSM method to check whether it supports requested
739 bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs) in acpi_check_dsm() argument
748 obj = acpi_evaluate_dsm(handle, guid, rev, 0, NULL); in acpi_check_dsm()
753 if (obj->type == ACPI_TYPE_INTEGER) in acpi_check_dsm()
754 mask = obj->integer.value; in acpi_check_dsm()
755 else if (obj->type == ACPI_TYPE_BUFFER) in acpi_check_dsm()
756 for (i = 0; i < obj->buffer.length && i < 8; i++) in acpi_check_dsm()
757 mask |= (((u64)obj->buffer.pointer[i]) << (i * 8)); in acpi_check_dsm()
772 * acpi_dev_hid_uid_match - Match device by supplied HID and UID
773 * @adev: ACPI device to match.
774 * @hid2: Hardware ID of the device.
775 * @uid2: Unique ID of the device, pass NULL to not check _UID.
797 * acpi_dev_uid_to_integer - treat ACPI device _UID as integer
798 * @adev: ACPI device to get _UID from
810 return -ENODEV; in acpi_dev_uid_to_integer()
814 return -ENODATA; in acpi_dev_uid_to_integer()
821 * acpi_dev_found - Detect presence of a given ACPI device in the namespace.
822 * @hid: Hardware ID of the device.
824 * Return %true if the device was present at the moment of invocation.
825 * Note that if the device is pluggable, it may since have disappeared.
840 if (!strcmp(acpi_device_bus_id->bus_id, hid)) { in acpi_dev_found()
856 static int acpi_dev_match_cb(struct device *dev, const void *data) in acpi_dev_match_cb()
863 if (acpi_match_device_ids(adev, match->hid)) in acpi_dev_match_cb()
866 if (match->uid && (!adev->pnp.unique_id || in acpi_dev_match_cb()
867 strcmp(adev->pnp.unique_id, match->uid))) in acpi_dev_match_cb()
870 if (match->hrv == -1) in acpi_dev_match_cb()
873 status = acpi_evaluate_integer(adev->handle, "_HRV", NULL, &hrv); in acpi_dev_match_cb()
877 return hrv == match->hrv; in acpi_dev_match_cb()
881 * acpi_dev_present - Detect that a given ACPI device is present
882 * @hid: Hardware ID of the device.
883 * @uid: Unique ID of the device, pass NULL to not check _UID
884 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
886 * Return %true if a matching device was present at the moment of invocation.
887 * Note that if the device is pluggable, it may since have disappeared.
890 * of the device. So for devices which are present in the DSDT, but
903 struct device *dev; in acpi_dev_present()
916 * acpi_dev_get_next_match_dev - Return the next match of ACPI device
917 * @adev: Pointer to the previous ACPI device matching this @hid, @uid and @hrv
918 * @hid: Hardware ID of the device.
919 * @uid: Unique ID of the device, pass NULL to not check _UID
920 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
922 * Return the next match of ACPI device if another matching device was present
925 * The caller is responsible for invoking acpi_dev_put() on the returned device.
934 struct device *start = adev ? &adev->dev : NULL; in acpi_dev_get_next_match_dev()
936 struct device *dev; in acpi_dev_get_next_match_dev()
949 * acpi_dev_get_first_match_dev - Return the first match of ACPI device
950 * @hid: Hardware ID of the device.
951 * @uid: Unique ID of the device, pass NULL to not check _UID
952 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
954 * Return the first match of ACPI device if a matching device was present
957 * The caller is responsible for invoking acpi_dev_put() on the returned device.
969 * acpi_reduced_hardware - Return if this is an ACPI-reduced-hw machine
971 * Return true when running on an ACPI-reduced-hw machine, false otherwise.
995 * acpi_match_platform_list - Check if the system matches with a given list
1007 return -ENODEV; in acpi_match_platform_list()
1009 for (; plat->oem_id[0]; plat++, idx++) { in acpi_match_platform_list()
1010 if (ACPI_FAILURE(acpi_get_table_header(plat->table, 0, &hdr))) in acpi_match_platform_list()
1013 if (strncmp(plat->oem_id, hdr.oem_id, ACPI_OEM_ID_SIZE)) in acpi_match_platform_list()
1016 if (strncmp(plat->oem_table_id, hdr.oem_table_id, ACPI_OEM_TABLE_ID_SIZE)) in acpi_match_platform_list()
1019 if ((plat->pred == all_versions) || in acpi_match_platform_list()
1020 (plat->pred == less_than_or_equal && hdr.oem_revision <= plat->oem_revision) || in acpi_match_platform_list()
1021 (plat->pred == greater_than_or_equal && hdr.oem_revision >= plat->oem_revision) || in acpi_match_platform_list()
1022 (plat->pred == equal && hdr.oem_revision == plat->oem_revision)) in acpi_match_platform_list()
1026 return -ENODEV; in acpi_match_platform_list()