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()
295 acpi_evaluate_reference(acpi_handle handle, in acpi_evaluate_reference() argument
313 status = acpi_evaluate_object(handle, pathname, arguments, &buffer); in acpi_evaluate_reference()
321 acpi_util_eval_error(handle, pathname, status); in acpi_evaluate_reference()
324 if (package->type != ACPI_TYPE_PACKAGE) { in acpi_evaluate_reference()
326 acpi_util_eval_error(handle, pathname, status); in acpi_evaluate_reference()
329 if (!package->package.count) { in acpi_evaluate_reference()
331 acpi_util_eval_error(handle, pathname, status); in acpi_evaluate_reference()
335 if (package->package.count > ACPI_MAX_HANDLES) { in acpi_evaluate_reference()
339 list->count = package->package.count; in acpi_evaluate_reference()
343 for (i = 0; i < list->count; i++) { in acpi_evaluate_reference()
345 element = &(package->package.elements[i]); in acpi_evaluate_reference()
347 if (element->type != ACPI_TYPE_LOCAL_REFERENCE) { in acpi_evaluate_reference()
349 acpi_util_eval_error(handle, pathname, status); in acpi_evaluate_reference()
353 if (!element->reference.handle) { in acpi_evaluate_reference()
355 acpi_util_eval_error(handle, pathname, status); in acpi_evaluate_reference()
360 list->handles[i] = element->reference.handle; in acpi_evaluate_reference()
361 acpi_handle_debug(list->handles[i], "Found in reference list\n"); in acpi_evaluate_reference()
366 list->count = 0; in acpi_evaluate_reference()
367 //kfree(list->handles); in acpi_evaluate_reference()
378 acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld) in acpi_get_physical_device_location() argument
384 status = acpi_evaluate_object(handle, "_PLD", NULL, &buffer); in acpi_get_physical_device_location()
391 if (!output || output->type != ACPI_TYPE_PACKAGE in acpi_get_physical_device_location()
392 || !output->package.count in acpi_get_physical_device_location()
393 || output->package.elements[0].type != ACPI_TYPE_BUFFER in acpi_get_physical_device_location()
394 || output->package.elements[0].buffer.length < ACPI_PLD_REV1_BUFFER_SIZE) { in acpi_get_physical_device_location()
400 output->package.elements[0].buffer.pointer, in acpi_get_physical_device_location()
401 output->package.elements[0].buffer.length, in acpi_get_physical_device_location()
412 * @handle: ACPI device handle
422 acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code, in acpi_evaluate_ost() argument
435 params[2].buffer.pointer = status_buf->pointer; in acpi_evaluate_ost()
436 params[2].buffer.length = status_buf->length; in acpi_evaluate_ost()
442 return acpi_evaluate_object(handle, "_OST", &arg_list, NULL); in acpi_evaluate_ost()
447 * acpi_handle_path: Return the object path of handle
448 * @handle: ACPI device handle
452 static char *acpi_handle_path(acpi_handle handle) in acpi_handle_path() argument
460 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer) != AE_OK) in acpi_handle_path()
468 * @handle: ACPI device handle
477 acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...) in acpi_handle_printk() argument
487 path = acpi_handle_path(handle); in acpi_handle_printk()
499 * @handle: ACPI device handle
508 __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, in __acpi_handle_debug() argument
519 path = acpi_handle_path(handle); in __acpi_handle_debug()
529 * acpi_evaluation_failure_warn - Log evaluation failure warning.
530 * @handle: Parent object handle.
534 void acpi_evaluation_failure_warn(acpi_handle handle, const char *name, in acpi_evaluation_failure_warn() argument
537 acpi_handle_warn(handle, "%s evaluation failed: %s\n", name, in acpi_evaluation_failure_warn()
543 * acpi_has_method: Check whether @handle has a method named @name
544 * @handle: ACPI device handle
547 * Check whether @handle has a method named @name.
549 bool acpi_has_method(acpi_handle handle, char *name) in acpi_has_method() argument
553 return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp)); in acpi_has_method()
557 acpi_status acpi_execute_simple_method(acpi_handle handle, char *method, in acpi_execute_simple_method() argument
565 return acpi_evaluate_object(handle, method, &arg_list, NULL); in acpi_execute_simple_method()
571 * @handle: ACPI device handle
573 * Evaluate device's _EJ0 method for hotplug operations.
575 acpi_status acpi_evaluate_ej0(acpi_handle handle) in acpi_evaluate_ej0() argument
579 status = acpi_execute_simple_method(handle, "_EJ0", 1); in acpi_evaluate_ej0()
581 acpi_handle_warn(handle, "No _EJ0 support for device\n"); in acpi_evaluate_ej0()
583 acpi_handle_warn(handle, "Eject failed (0x%x)\n", status); in acpi_evaluate_ej0()
589 * acpi_evaluate_lck: Evaluate _LCK method to lock/unlock device
590 * @handle: ACPI device handle
591 * @lock: lock device if non-zero, otherwise unlock device
593 * Evaluate device's _LCK method if present to lock/unlock device
595 acpi_status acpi_evaluate_lck(acpi_handle handle, int lock) in acpi_evaluate_lck() argument
599 status = acpi_execute_simple_method(handle, "_LCK", !!lock); in acpi_evaluate_lck()
602 acpi_handle_warn(handle, in acpi_evaluate_lck()
603 "Locking device failed (0x%x)\n", status); in acpi_evaluate_lck()
605 acpi_handle_warn(handle, in acpi_evaluate_lck()
606 "Unlocking device failed (0x%x)\n", status); in acpi_evaluate_lck()
614 * @handle: ACPI device handle
619 * Evaluate device's _REG method to register OpRegion presence.
621 acpi_status acpi_evaluate_reg(acpi_handle handle, u8 space_id, u32 function) in acpi_evaluate_reg() argument
633 return acpi_evaluate_object(handle, "_REG", &arg_list, NULL); in acpi_evaluate_reg()
638 * acpi_evaluate_dsm - evaluate device's _DSM method
639 * @handle: ACPI device handle
645 * Evaluate device's _DSM method with specified GUID, revision id and
652 acpi_evaluate_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 func, in acpi_evaluate_dsm() argument
678 ret = acpi_evaluate_object(handle, "_DSM", &input, &buf); in acpi_evaluate_dsm()
683 acpi_handle_warn(handle, in acpi_evaluate_dsm()
691 * acpi_check_dsm - check if _DSM method supports requested functions.
692 * @handle: ACPI device handle
697 * Evaluate device's _DSM method to check whether it supports requested
701 bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs) in acpi_check_dsm() argument
710 obj = acpi_evaluate_dsm(handle, guid, rev, 0, NULL); in acpi_check_dsm()
715 if (obj->type == ACPI_TYPE_INTEGER) in acpi_check_dsm()
716 mask = obj->integer.value; in acpi_check_dsm()
717 else if (obj->type == ACPI_TYPE_BUFFER) in acpi_check_dsm()
718 for (i = 0; i < obj->buffer.length && i < 8; i++) in acpi_check_dsm()
719 mask |= (((u64)obj->buffer.pointer[i]) << (i * 8)); in acpi_check_dsm()
734 * acpi_dev_hid_uid_match - Match device by supplied HID and UID
735 * @adev: ACPI device to match.
736 * @hid2: Hardware ID of the device.
737 * @uid2: Unique ID of the device, pass NULL to not check _UID.
759 * acpi_dev_found - Detect presence of a given ACPI device in the namespace.
760 * @hid: Hardware ID of the device.
762 * Return %true if the device was present at the moment of invocation.
763 * Note that if the device is pluggable, it may since have disappeared.
778 if (!strcmp(acpi_device_bus_id->bus_id, hid)) { in acpi_dev_found()
794 static int acpi_dev_match_cb(struct device *dev, const void *data) in acpi_dev_match_cb()
801 if (acpi_match_device_ids(adev, match->hid)) in acpi_dev_match_cb()
804 if (match->uid && (!adev->pnp.unique_id || in acpi_dev_match_cb()
805 strcmp(adev->pnp.unique_id, match->uid))) in acpi_dev_match_cb()
808 if (match->hrv == -1) in acpi_dev_match_cb()
811 status = acpi_evaluate_integer(adev->handle, "_HRV", NULL, &hrv); in acpi_dev_match_cb()
815 return hrv == match->hrv; in acpi_dev_match_cb()
819 * acpi_dev_present - Detect that a given ACPI device is present
820 * @hid: Hardware ID of the device.
821 * @uid: Unique ID of the device, pass NULL to not check _UID
822 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
824 * Return %true if a matching device was present at the moment of invocation.
825 * Note that if the device is pluggable, it may since have disappeared.
828 * of the device. So for devices which are present in the DSDT, but
841 struct device *dev; in acpi_dev_present()
854 * acpi_dev_get_next_match_dev - Return the next match of ACPI device
855 * @adev: Pointer to the previous ACPI device matching this @hid, @uid and @hrv
856 * @hid: Hardware ID of the device.
857 * @uid: Unique ID of the device, pass NULL to not check _UID
858 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
860 * Return the next match of ACPI device if another matching device was present
863 * The caller is responsible for invoking acpi_dev_put() on the returned device.
872 struct device *start = adev ? &adev->dev : NULL; in acpi_dev_get_next_match_dev()
874 struct device *dev; in acpi_dev_get_next_match_dev()
887 * acpi_dev_get_first_match_dev - Return the first match of ACPI device
888 * @hid: Hardware ID of the device.
889 * @uid: Unique ID of the device, pass NULL to not check _UID
890 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
892 * Return the first match of ACPI device if a matching device was present
895 * The caller is responsible for invoking acpi_dev_put() on the returned device.
907 * acpi_reduced_hardware - Return if this is an ACPI-reduced-hw machine
909 * Return true when running on an ACPI-reduced-hw machine, false otherwise.
933 * acpi_match_platform_list - Check if the system matches with a given list
945 return -ENODEV; in acpi_match_platform_list()
947 for (; plat->oem_id[0]; plat++, idx++) { in acpi_match_platform_list()
948 if (ACPI_FAILURE(acpi_get_table_header(plat->table, 0, &hdr))) in acpi_match_platform_list()
951 if (strncmp(plat->oem_id, hdr.oem_id, ACPI_OEM_ID_SIZE)) in acpi_match_platform_list()
954 if (strncmp(plat->oem_table_id, hdr.oem_table_id, ACPI_OEM_TABLE_ID_SIZE)) in acpi_match_platform_list()
957 if ((plat->pred == all_versions) || in acpi_match_platform_list()
958 (plat->pred == less_than_or_equal && hdr.oem_revision <= plat->oem_revision) || in acpi_match_platform_list()
959 (plat->pred == greater_than_or_equal && hdr.oem_revision >= plat->oem_revision) || in acpi_match_platform_list()
960 (plat->pred == equal && hdr.oem_revision == plat->oem_revision)) in acpi_match_platform_list()
964 return -ENODEV; in acpi_match_platform_list()