Lines Matching +full:integer +full:- +full:n
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * acpi_utils.c - ACPI Utility Functions ($Revision: 10 $)
23 /* --------------------------------------------------------------------------
25 -------------------------------------------------------------------------- */
28 acpi_handle_debug(h, "Evaluate [%s]: %s\n", p, acpi_format_exception(s)); in acpi_util_eval_error()
44 if (!package || (package->type != ACPI_TYPE_PACKAGE) in acpi_extract_package()
45 || (package->package.count < 1)) { in acpi_extract_package()
46 pr_debug("Invalid package argument\n"); in acpi_extract_package()
50 if (!format || !format->pointer || (format->length < 1)) { in acpi_extract_package()
51 pr_debug("Invalid format argument\n"); in acpi_extract_package()
56 pr_debug("Invalid buffer argument\n"); 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()
62 pr_debug("Format specifies more objects [%d] than present [%d]\n", 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()
80 case 'N': in acpi_extract_package()
91 pr_debug("Invalid package element [%d]: got number, expected [%c]\n", in acpi_extract_package()
103 (element->string.length * sizeof(char)) + in acpi_extract_package()
109 sizeof(u8 *) + element->buffer.length; in acpi_extract_package()
113 pr_debug("Invalid package element [%d] got string/buffer, expected [%c]\n", in acpi_extract_package()
125 pr_debug("Invalid package element [%d] got reference, expected [%c]\n", in acpi_extract_package()
133 pr_debug("Unsupported element at index=%d\n", i); 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()
172 case 'N': 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()
271 *data = element.integer.value; in acpi_evaluate_integer()
273 acpi_handle_debug(handle, "Return value [%llu]\n", *data); in acpi_evaluate_integer()
286 return -ENODATA; in acpi_get_local_u64_address()
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()
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()
409 * acpi_handle_list_equal - Check if two ACPI handle lists are the same
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
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
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
481 acpi_handle_debug(target, "Failed to evaluate _DEP.\n"); in acpi_device_dep()
510 if (!output || output->type != ACPI_TYPE_PACKAGE in acpi_get_physical_device_location()
511 || !output->package.count in acpi_get_physical_device_location()
512 || output->package.elements[0].type != ACPI_TYPE_BUFFER in acpi_get_physical_device_location()
513 || output->package.elements[0].buffer.length < ACPI_PLD_REV1_BUFFER_SIZE) { in acpi_get_physical_device_location()
519 output->package.elements[0].buffer.pointer, in acpi_get_physical_device_location()
520 output->package.elements[0].buffer.length, in acpi_get_physical_device_location()
551 params[0].integer.value = source_event; in acpi_evaluate_ost()
552 params[1].integer.value = status_code; in acpi_evaluate_ost()
554 params[2].buffer.pointer = status_buf->pointer; in acpi_evaluate_ost()
555 params[2].buffer.length = status_buf->length; in acpi_evaluate_ost()
593 * context, it shows the object path as <n/a>.
607 printk("%sACPI: %s: %pV", level, path ? path : "<n/a>", &vaf); in acpi_handle_printk()
624 * interrupt context, it shows the object path as <n/a>.
639 __dynamic_pr_debug(descriptor, "ACPI: %s: %pV", path ? path : "<n/a>", &vaf); in __acpi_handle_debug()
648 * acpi_evaluation_failure_warn - Log evaluation failure warning.
656 acpi_handle_warn(handle, "%s evaluation failed: %s\n", name, in acpi_evaluation_failure_warn()
682 obj.integer.value = arg; in acpi_execute_simple_method()
700 acpi_handle_warn(handle, "No _EJ0 support for device\n"); in acpi_evaluate_ej0()
702 acpi_handle_warn(handle, "Eject failed (0x%x)\n", status); in acpi_evaluate_ej0()
710 * @lock: lock device if non-zero, otherwise unlock device
722 "Locking device failed (0x%x)\n", status); in acpi_evaluate_lck()
725 "Unlocking device failed (0x%x)\n", status); in acpi_evaluate_lck()
746 params[0].integer.value = space_id; in acpi_evaluate_reg()
748 params[1].integer.value = function; in acpi_evaluate_reg()
757 * acpi_evaluate_dsm - evaluate device's _DSM method
768 * some old BIOSes do expect a buffer or an integer etc.
786 params[1].integer.value = rev; in acpi_evaluate_dsm()
788 params[2].integer.value = func; in acpi_evaluate_dsm()
803 "failed to evaluate _DSM %pUb rev:%lld func:%lld (0x%x)\n", in acpi_evaluate_dsm()
811 * acpi_check_dsm - check if _DSM method supports requested functions.
834 /* For compatibility, old BIOSes may return an integer */ in acpi_check_dsm()
835 if (obj->type == ACPI_TYPE_INTEGER) in acpi_check_dsm()
836 mask = obj->integer.value; in acpi_check_dsm()
837 else if (obj->type == ACPI_TYPE_BUFFER) in acpi_check_dsm()
838 for (i = 0; i < obj->buffer.length && i < 8; i++) in acpi_check_dsm()
839 mask |= (((u64)obj->buffer.pointer[i]) << (i * 8)); in acpi_check_dsm()
854 * acpi_dev_uid_to_integer - treat ACPI device _UID as integer
856 * @integer: output buffer for integer
858 * Considers _UID as integer and converts it to @integer.
862 int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer) in acpi_dev_uid_to_integer() argument
867 return -ENODEV; in acpi_dev_uid_to_integer()
871 return -ENODATA; in acpi_dev_uid_to_integer()
873 return kstrtou64(uid, 0, integer); in acpi_dev_uid_to_integer()
878 * acpi_dev_found - Detect presence of a given ACPI device in the namespace.
897 if (!strcmp(acpi_device_bus_id->bus_id, hid)) { in acpi_dev_found()
920 if (acpi_match_device_ids(adev, match->hid)) in acpi_dev_match_cb()
923 if (match->uid && !acpi_dev_uid_match(adev, match->uid)) in acpi_dev_match_cb()
926 if (match->hrv == -1) in acpi_dev_match_cb()
929 status = acpi_evaluate_integer(adev->handle, "_HRV", NULL, &hrv); in acpi_dev_match_cb()
933 return hrv == match->hrv; in acpi_dev_match_cb()
937 * acpi_dev_present - Detect that a given ACPI device is present
940 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
972 * acpi_dev_get_next_match_dev - Return the next match of ACPI device
976 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
990 struct device *start = adev ? &adev->dev : NULL; in acpi_dev_get_next_match_dev()
1005 * acpi_dev_get_first_match_dev - Return the first match of ACPI device
1008 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
1025 * acpi_reduced_hardware - Return if this is an ACPI-reduced-hw machine
1027 * Return true when running on an ACPI-reduced-hw machine, false otherwise.
1051 * acpi_match_platform_list - Check if the system matches with a given list
1063 return -ENODEV; in acpi_match_platform_list()
1065 for (; plat->oem_id[0]; plat++, idx++) { in acpi_match_platform_list()
1066 if (ACPI_FAILURE(acpi_get_table_header(plat->table, 0, &hdr))) in acpi_match_platform_list()
1069 if (strncmp(plat->oem_id, hdr.oem_id, ACPI_OEM_ID_SIZE)) in acpi_match_platform_list()
1072 if (strncmp(plat->oem_table_id, hdr.oem_table_id, ACPI_OEM_TABLE_ID_SIZE)) in acpi_match_platform_list()
1075 if ((plat->pred == all_versions) || in acpi_match_platform_list()
1076 (plat->pred == less_than_or_equal && hdr.oem_revision <= plat->oem_revision) || in acpi_match_platform_list()
1077 (plat->pred == greater_than_or_equal && hdr.oem_revision >= plat->oem_revision) || in acpi_match_platform_list()
1078 (plat->pred == equal && hdr.oem_revision == plat->oem_revision)) in acpi_match_platform_list()
1082 return -ENODEV; in acpi_match_platform_list()