^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Module Name: exutils - interpreter/scanner utilities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 - 2020, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * DEFINE_AML_GLOBALS is tested in amlcode.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * to determine whether certain global names should be "defined" or only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * "declared" in the current compilation. This enhances maintainability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * by enabling a single header file to embody all knowledge of the names
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * in question.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Exactly one module of any executable should #define DEFINE_GLOBALS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * before #including the header files which use this convention. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * names in question will be defined and initialized in that module,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * and declared as extern in all other modules which #include those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * header files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define DEFINE_AML_GLOBALS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "acinterp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "amlcode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define _COMPONENT ACPI_EXECUTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ACPI_MODULE_NAME("exutils")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* Local prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static u32 acpi_ex_digits_needed(u64 value, u32 base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * FUNCTION: acpi_ex_enter_interpreter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * PARAMETERS: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * DESCRIPTION: Enter the interpreter execution region. Failure to enter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * the interpreter region is a fatal system error. Used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * conjunction with exit_interpreter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) void acpi_ex_enter_interpreter(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ACPI_FUNCTION_TRACE(ex_enter_interpreter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) "Could not acquire AML Interpreter mutex"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ACPI_ERROR((AE_INFO, "Could not acquire AML Namespace mutex"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * FUNCTION: acpi_ex_exit_interpreter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * PARAMETERS: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * DESCRIPTION: Exit the interpreter execution region. This is the top level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * routine used to exit the interpreter when all processing has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * been completed, or when the method blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * Cases where the interpreter is unlocked internally:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * 1) Method will be blocked on a Sleep() AML opcode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * 2) Method will be blocked on an Acquire() AML opcode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * 3) Method will be blocked on a Wait() AML opcode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * 4) Method will be blocked to acquire the global lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * 5) Method will be blocked waiting to execute a serialized control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * method that is currently executing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * 6) About to invoke a user-installed opregion handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) void acpi_ex_exit_interpreter(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ACPI_FUNCTION_TRACE(ex_exit_interpreter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) ACPI_ERROR((AE_INFO, "Could not release AML Namespace mutex"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) status = acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) "Could not release AML Interpreter mutex"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * FUNCTION: acpi_ex_truncate_for32bit_table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * PARAMETERS: obj_desc - Object to be truncated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * RETURN: TRUE if a truncation was performed, FALSE otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * DESCRIPTION: Truncate an ACPI Integer to 32 bits if the execution mode is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * 32-bit, as determined by the revision of the DSDT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) u8 acpi_ex_truncate_for32bit_table(union acpi_operand_object *obj_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ACPI_FUNCTION_ENTRY();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * Object must be a valid number and we must be executing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * a control method. Object could be NS node for AML_INT_NAMEPATH_OP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if ((!obj_desc) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_OPERAND) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) (obj_desc->common.type != ACPI_TYPE_INTEGER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return (FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if ((acpi_gbl_integer_byte_width == 4) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) (obj_desc->integer.value > (u64)ACPI_UINT32_MAX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * We are executing in a 32-bit ACPI table. Truncate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * the value to 32 bits by zeroing out the upper 32-bit field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) obj_desc->integer.value &= (u64)ACPI_UINT32_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return (TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return (FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * FUNCTION: acpi_ex_acquire_global_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * PARAMETERS: field_flags - Flags with Lock rule:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * always_lock or never_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * DESCRIPTION: Obtain the ACPI hardware Global Lock, only if the field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * flags specify that it is to be obtained before field access.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) void acpi_ex_acquire_global_lock(u32 field_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ACPI_FUNCTION_TRACE(ex_acquire_global_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* Only use the lock if the always_lock bit is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (!(field_flags & AML_FIELD_LOCK_RULE_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /* Attempt to get the global lock, wait forever */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) status = acpi_ex_acquire_mutex_object(ACPI_WAIT_FOREVER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) acpi_gbl_global_lock_mutex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) acpi_os_get_thread_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ACPI_EXCEPTION((AE_INFO, status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) "Could not acquire Global Lock"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * FUNCTION: acpi_ex_release_global_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * PARAMETERS: field_flags - Flags with Lock rule:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * always_lock or never_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * DESCRIPTION: Release the ACPI hardware Global Lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) void acpi_ex_release_global_lock(u32 field_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) ACPI_FUNCTION_TRACE(ex_release_global_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* Only use the lock if the always_lock bit is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (!(field_flags & AML_FIELD_LOCK_RULE_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /* Release the global lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Report the error, but there isn't much else we can do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) ACPI_EXCEPTION((AE_INFO, status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) "Could not release Global Lock"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * FUNCTION: acpi_ex_digits_needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * PARAMETERS: value - Value to be represented
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * base - Base of representation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * RETURN: The number of digits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * DESCRIPTION: Calculate the number of digits needed to represent the Value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * in the given Base (Radix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static u32 acpi_ex_digits_needed(u64 value, u32 base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) u32 num_digits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) u64 current_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ACPI_FUNCTION_TRACE(ex_digits_needed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* u64 is unsigned, so we don't worry about a '-' prefix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (value == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return_UINT32(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) current_value = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) num_digits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /* Count the digits in the requested base */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) while (current_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) (void)acpi_ut_short_divide(current_value, base, ¤t_value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) num_digits++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return_UINT32(num_digits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * FUNCTION: acpi_ex_eisa_id_to_string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * PARAMETERS: out_string - Where to put the converted string (8 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * compressed_id - EISAID to be converted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * DESCRIPTION: Convert a numeric EISAID to string representation. Return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * buffer must be large enough to hold the string. The string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * returned is always exactly of length ACPI_EISAID_STRING_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * (includes null terminator). The EISAID is always 32 bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) void acpi_ex_eisa_id_to_string(char *out_string, u64 compressed_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) u32 swapped_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ACPI_FUNCTION_ENTRY();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* The EISAID should be a 32-bit integer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (compressed_id > ACPI_UINT32_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) ACPI_WARNING((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) "Expected EISAID is larger than 32 bits: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) "0x%8.8X%8.8X, truncating",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) ACPI_FORMAT_UINT64(compressed_id)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /* Swap ID to big-endian to get contiguous bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) swapped_id = acpi_ut_dword_byte_swap((u32)compressed_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /* First 3 bytes are uppercase letters. Next 4 bytes are hexadecimal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) out_string[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) (char)(0x40 + (((unsigned long)swapped_id >> 26) & 0x1F));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) out_string[1] = (char)(0x40 + ((swapped_id >> 21) & 0x1F));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) out_string[2] = (char)(0x40 + ((swapped_id >> 16) & 0x1F));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) out_string[3] = acpi_ut_hex_to_ascii_char((u64) swapped_id, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) out_string[4] = acpi_ut_hex_to_ascii_char((u64) swapped_id, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) out_string[5] = acpi_ut_hex_to_ascii_char((u64) swapped_id, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) out_string[6] = acpi_ut_hex_to_ascii_char((u64) swapped_id, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) out_string[7] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * FUNCTION: acpi_ex_integer_to_string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * PARAMETERS: out_string - Where to put the converted string. At least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * 21 bytes are needed to hold the largest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * possible 64-bit integer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * value - Value to be converted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * RETURN: Converted string in out_string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * DESCRIPTION: Convert a 64-bit integer to decimal string representation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * Assumes string buffer is large enough to hold the string. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * largest string is (ACPI_MAX64_DECIMAL_DIGITS + 1).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) void acpi_ex_integer_to_string(char *out_string, u64 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) u32 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) u32 digits_needed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) u32 remainder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ACPI_FUNCTION_ENTRY();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) digits_needed = acpi_ex_digits_needed(value, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) out_string[digits_needed] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) for (count = digits_needed; count > 0; count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) (void)acpi_ut_short_divide(value, 10, &value, &remainder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) out_string[count - 1] = (char)('0' + remainder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * FUNCTION: acpi_ex_pci_cls_to_string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * PARAMETERS: out_string - Where to put the converted string (7 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * class_code - PCI class code to be converted (3 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * RETURN: Converted string in out_string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * DESCRIPTION: Convert 3-bytes PCI class code to string representation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * Return buffer must be large enough to hold the string. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * string returned is always exactly of length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * ACPI_PCICLS_STRING_SIZE (includes null terminator).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) void acpi_ex_pci_cls_to_string(char *out_string, u8 class_code[3])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) ACPI_FUNCTION_ENTRY();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /* All 3 bytes are hexadecimal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) out_string[0] = acpi_ut_hex_to_ascii_char((u64)class_code[0], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) out_string[1] = acpi_ut_hex_to_ascii_char((u64)class_code[0], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) out_string[2] = acpi_ut_hex_to_ascii_char((u64)class_code[1], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) out_string[3] = acpi_ut_hex_to_ascii_char((u64)class_code[1], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) out_string[4] = acpi_ut_hex_to_ascii_char((u64)class_code[2], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) out_string[5] = acpi_ut_hex_to_ascii_char((u64)class_code[2], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) out_string[6] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) * FUNCTION: acpi_is_valid_space_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) * PARAMETERS: space_id - ID to be validated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * RETURN: TRUE if space_id is a valid/supported ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * DESCRIPTION: Validate an operation region space_ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) u8 acpi_is_valid_space_id(u8 space_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if ((space_id >= ACPI_NUM_PREDEFINED_REGIONS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) (space_id < ACPI_USER_REGION_BEGIN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) (space_id != ACPI_ADR_SPACE_DATA_TABLE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) (space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return (FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return (TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }