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_u64_address(acpi_handle handle, u64 *addr) in acpi_get_local_u64_address() argument
284 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, addr); in acpi_get_local_u64_address()
286 return -ENODATA; in acpi_get_local_u64_address()
291 int acpi_get_local_address(acpi_handle handle, u32 *addr) in acpi_get_local_address() argument
296 ret = acpi_get_local_u64_address(handle, &adr); in acpi_get_local_address()
306 const char *acpi_get_subsystem_id(acpi_handle handle) in acpi_get_subsystem_id() argument
314 status = acpi_evaluate_object(handle, METHOD_NAME__SUB, NULL, &buffer); in acpi_get_subsystem_id()
316 acpi_handle_debug(handle, "Reading ACPI _SUB failed: %#x\n", status); in acpi_get_subsystem_id()
317 return ERR_PTR(-ENODATA); in acpi_get_subsystem_id()
321 if (obj->type == ACPI_TYPE_STRING) { in acpi_get_subsystem_id()
322 len = strlen(obj->string.pointer); in acpi_get_subsystem_id()
324 sub = kstrdup(obj->string.pointer, GFP_KERNEL); in acpi_get_subsystem_id()
326 sub = ERR_PTR(-ENOMEM); in acpi_get_subsystem_id()
328 acpi_handle_err(handle, "ACPI _SUB Length %zu is Invalid\n", len); in acpi_get_subsystem_id()
329 sub = ERR_PTR(-ENODATA); in acpi_get_subsystem_id()
332 acpi_handle_warn(handle, "Warning ACPI _SUB did not return a string\n"); in acpi_get_subsystem_id()
333 sub = ERR_PTR(-ENODATA); in acpi_get_subsystem_id()
342 bool acpi_evaluate_reference(acpi_handle handle, acpi_string pathname, in acpi_evaluate_reference() argument
357 status = acpi_evaluate_object(handle, pathname, arguments, &buffer); in acpi_evaluate_reference()
364 package->type != ACPI_TYPE_PACKAGE || !package->package.count) in acpi_evaluate_reference()
367 list->count = package->package.count; in acpi_evaluate_reference()
368 list->handles = kcalloc(list->count, sizeof(*list->handles), GFP_KERNEL); in acpi_evaluate_reference()
369 if (!list->handles) in acpi_evaluate_reference()
374 for (i = 0; i < list->count; i++) { in acpi_evaluate_reference()
375 union acpi_object *element = &(package->package.elements[i]); in acpi_evaluate_reference()
377 if (element->type != ACPI_TYPE_LOCAL_REFERENCE || in acpi_evaluate_reference()
378 !element->reference.handle) in acpi_evaluate_reference()
383 list->handles[i] = element->reference.handle; in acpi_evaluate_reference()
384 acpi_handle_debug(list->handles[i], "Found in reference list\n"); in acpi_evaluate_reference()
395 kfree(list->handles); in acpi_evaluate_reference()
396 list->handles = NULL; in acpi_evaluate_reference()
399 list->count = 0; in acpi_evaluate_reference()
402 acpi_util_eval_error(handle, pathname, status); in acpi_evaluate_reference()
409 * acpi_handle_list_equal - Check if two ACPI handle lists are the same
413 * Return true if the given ACPI handle lists are of the same size and
419 return list1->count == list2->count && in acpi_handle_list_equal()
420 !memcmp(list1->handles, list2->handles, in acpi_handle_list_equal()
421 list1->count * sizeof(*list1->handles)); in acpi_handle_list_equal()
426 * acpi_handle_list_replace - Replace one ACPI handle list with another
427 * @dst: ACPI handle list to replace.
428 * @src: Source ACPI handle list.
436 if (dst->count) in acpi_handle_list_replace()
437 kfree(dst->handles); in acpi_handle_list_replace()
439 dst->count = src->count; in acpi_handle_list_replace()
440 dst->handles = src->handles; in acpi_handle_list_replace()
442 src->handles = NULL; in acpi_handle_list_replace()
443 src->count = 0; in acpi_handle_list_replace()
448 * acpi_handle_list_free - Free the handles table in an ACPI handle list
449 * @list: ACPI handle list to free.
455 if (!list->count) in acpi_handle_list_free()
458 kfree(list->handles); in acpi_handle_list_free()
459 list->count = 0; in acpi_handle_list_free()
464 * acpi_device_dep - Check ACPI device dependency
465 * @target: ACPI handle of the target ACPI device.
466 * @match: ACPI handle to look up in the target's _DEP list.
498 acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld) in acpi_get_physical_device_location() argument
504 status = acpi_evaluate_object(handle, "_PLD", NULL, &buffer); in acpi_get_physical_device_location()
511 if (!output || output->type != ACPI_TYPE_PACKAGE in acpi_get_physical_device_location()
512 || !output->package.count in acpi_get_physical_device_location()
513 || output->package.elements[0].type != ACPI_TYPE_BUFFER in acpi_get_physical_device_location()
514 || output->package.elements[0].buffer.length < ACPI_PLD_REV1_BUFFER_SIZE) { in acpi_get_physical_device_location()
520 output->package.elements[0].buffer.pointer, in acpi_get_physical_device_location()
521 output->package.elements[0].buffer.length, in acpi_get_physical_device_location()
532 * @handle: ACPI device handle
542 acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code, in acpi_evaluate_ost() argument
555 params[2].buffer.pointer = status_buf->pointer; in acpi_evaluate_ost()
556 params[2].buffer.length = status_buf->length; in acpi_evaluate_ost()
562 return acpi_evaluate_object(handle, "_OST", &arg_list, NULL); in acpi_evaluate_ost()
567 * acpi_handle_path: Return the object path of handle
568 * @handle: ACPI device handle
572 char *acpi_handle_path(acpi_handle handle) in acpi_handle_path() argument
580 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer) != AE_OK) in acpi_handle_path()
588 * @handle: ACPI device handle
597 acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...) in acpi_handle_printk() argument
607 path = acpi_handle_path(handle); in acpi_handle_printk()
619 * @handle: ACPI device handle
628 __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, in __acpi_handle_debug() argument
639 path = acpi_handle_path(handle); in __acpi_handle_debug()
649 * acpi_evaluation_failure_warn - Log evaluation failure warning.
650 * @handle: Parent object handle.
654 void acpi_evaluation_failure_warn(acpi_handle handle, const char *name, in acpi_evaluation_failure_warn() argument
657 acpi_handle_warn(handle, "%s evaluation failed: %s\n", name, in acpi_evaluation_failure_warn()
663 * acpi_has_method: Check whether @handle has a method named @name
664 * @handle: ACPI device handle
667 * Check whether @handle has a method named @name.
669 bool acpi_has_method(acpi_handle handle, char *name) in acpi_has_method() argument
673 return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp)); in acpi_has_method()
677 acpi_status acpi_execute_simple_method(acpi_handle handle, char *method, in acpi_execute_simple_method() argument
685 return acpi_evaluate_object(handle, method, &arg_list, NULL); in acpi_execute_simple_method()
691 * @handle: ACPI device handle
693 * Evaluate device's _EJ0 method for hotplug operations.
695 acpi_status acpi_evaluate_ej0(acpi_handle handle) in acpi_evaluate_ej0() argument
699 status = acpi_execute_simple_method(handle, "_EJ0", 1); in acpi_evaluate_ej0()
701 acpi_handle_warn(handle, "No _EJ0 support for device\n"); in acpi_evaluate_ej0()
703 acpi_handle_warn(handle, "Eject failed (0x%x)\n", status); in acpi_evaluate_ej0()
709 * acpi_evaluate_lck: Evaluate _LCK method to lock/unlock device
710 * @handle: ACPI device handle
711 * @lock: lock device if non-zero, otherwise unlock device
713 * Evaluate device's _LCK method if present to lock/unlock device
715 acpi_status acpi_evaluate_lck(acpi_handle handle, int lock) in acpi_evaluate_lck() argument
719 status = acpi_execute_simple_method(handle, "_LCK", !!lock); in acpi_evaluate_lck()
722 acpi_handle_warn(handle, in acpi_evaluate_lck()
723 "Locking device failed (0x%x)\n", status); in acpi_evaluate_lck()
725 acpi_handle_warn(handle, in acpi_evaluate_lck()
726 "Unlocking device failed (0x%x)\n", status); in acpi_evaluate_lck()
734 * @handle: ACPI device handle
739 * Evaluate device's _REG method to register OpRegion presence.
741 acpi_status acpi_evaluate_reg(acpi_handle handle, u8 space_id, u32 function) in acpi_evaluate_reg() argument
753 return acpi_evaluate_object(handle, "_REG", &arg_list, NULL); in acpi_evaluate_reg()
758 * acpi_evaluate_dsm - evaluate device's _DSM method
759 * @handle: ACPI device handle
765 * Evaluate device's _DSM method with specified GUID, revision id and
772 acpi_evaluate_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 func, in acpi_evaluate_dsm() argument
798 ret = acpi_evaluate_object(handle, "_DSM", &input, &buf); in acpi_evaluate_dsm()
803 acpi_handle_warn(handle, in acpi_evaluate_dsm()
812 * acpi_check_dsm - check if _DSM method supports requested functions.
813 * @handle: ACPI device handle
818 * Evaluate device's _DSM method to check whether it supports requested
822 bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs) in acpi_check_dsm() argument
831 obj = acpi_evaluate_dsm(handle, guid, rev, 0, NULL); in acpi_check_dsm()
836 if (obj->type == ACPI_TYPE_INTEGER) in acpi_check_dsm()
837 mask = obj->integer.value; in acpi_check_dsm()
838 else if (obj->type == ACPI_TYPE_BUFFER) in acpi_check_dsm()
839 for (i = 0; i < obj->buffer.length && i < 8; i++) in acpi_check_dsm()
840 mask |= (((u64)obj->buffer.pointer[i]) << (i * 8)); in acpi_check_dsm()
855 * acpi_dev_uid_to_integer - treat ACPI device _UID as integer
856 * @adev: ACPI device to get _UID from
868 return -ENODEV; in acpi_dev_uid_to_integer()
872 return -ENODATA; in acpi_dev_uid_to_integer()
879 * acpi_dev_found - Detect presence of a given ACPI device in the namespace.
880 * @hid: Hardware ID of the device.
882 * Return %true if the device was present at the moment of invocation.
883 * Note that if the device is pluggable, it may since have disappeared.
898 if (!strcmp(acpi_device_bus_id->bus_id, hid)) { in acpi_dev_found()
914 static int acpi_dev_match_cb(struct device *dev, const void *data) in acpi_dev_match_cb()
921 if (acpi_match_device_ids(adev, match->hid)) in acpi_dev_match_cb()
924 if (match->uid && !acpi_dev_uid_match(adev, match->uid)) in acpi_dev_match_cb()
927 if (match->hrv == -1) in acpi_dev_match_cb()
930 status = acpi_evaluate_integer(adev->handle, "_HRV", NULL, &hrv); in acpi_dev_match_cb()
934 return hrv == match->hrv; in acpi_dev_match_cb()
938 * acpi_dev_present - Detect that a given ACPI device is present
939 * @hid: Hardware ID of the device.
940 * @uid: Unique ID of the device, pass NULL to not check _UID
941 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
943 * Return %true if a matching device was present at the moment of invocation.
944 * Note that if the device is pluggable, it may since have disappeared.
947 * of the device. So for devices which are present in the DSDT, but
960 struct device *dev; in acpi_dev_present()
973 * acpi_dev_get_next_match_dev - Return the next match of ACPI device
974 * @adev: Pointer to the previous ACPI device matching this @hid, @uid and @hrv
975 * @hid: Hardware ID of the device.
976 * @uid: Unique ID of the device, pass NULL to not check _UID
977 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
979 * Return the next match of ACPI device if another matching device was present
982 * The caller is responsible for invoking acpi_dev_put() on the returned device.
991 struct device *start = adev ? &adev->dev : NULL; in acpi_dev_get_next_match_dev()
993 struct device *dev; in acpi_dev_get_next_match_dev()
1006 * acpi_dev_get_first_match_dev - Return the first match of ACPI device
1007 * @hid: Hardware ID of the device.
1008 * @uid: Unique ID of the device, pass NULL to not check _UID
1009 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
1011 * Return the first match of ACPI device if a matching device was present
1014 * The caller is responsible for invoking acpi_dev_put() on the returned device.
1026 * acpi_reduced_hardware - Return if this is an ACPI-reduced-hw machine
1028 * Return true when running on an ACPI-reduced-hw machine, false otherwise.
1052 * acpi_match_platform_list - Check if the system matches with a given list
1064 return -ENODEV; in acpi_match_platform_list()
1066 for (; plat->oem_id[0]; plat++, idx++) { in acpi_match_platform_list()
1067 if (ACPI_FAILURE(acpi_get_table_header(plat->table, 0, &hdr))) in acpi_match_platform_list()
1070 if (strncmp(plat->oem_id, hdr.oem_id, ACPI_OEM_ID_SIZE)) in acpi_match_platform_list()
1073 if (strncmp(plat->oem_table_id, hdr.oem_table_id, ACPI_OEM_TABLE_ID_SIZE)) in acpi_match_platform_list()
1076 if ((plat->pred == all_versions) || in acpi_match_platform_list()
1077 (plat->pred == less_than_or_equal && hdr.oem_revision <= plat->oem_revision) || in acpi_match_platform_list()
1078 (plat->pred == greater_than_or_equal && hdr.oem_revision >= plat->oem_revision) || in acpi_match_platform_list()
1079 (plat->pred == equal && hdr.oem_revision == plat->oem_revision)) in acpi_match_platform_list()
1083 return -ENODEV; in acpi_match_platform_list()