1 /*******************************************************************************
3 * Module Name: utmisc - common utility procedures
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2018, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME("utmisc")
51 /*******************************************************************************
53 * FUNCTION: acpi_ut_is_pci_root_bridge
55 * PARAMETERS: id - The HID/CID in string format
57 * RETURN: TRUE if the Id is a match for a PCI/PCI-Express Root Bridge
59 * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID.
61 ******************************************************************************/
62 u8
acpi_ut_is_pci_root_bridge(char *id
)
66 * Check if this is a PCI root bridge.
67 * ACPI 3.0+: check for a PCI Express root also.
70 PCI_ROOT_HID_STRING
)) ||
71 !(strcmp(id
, PCI_EXPRESS_ROOT_HID_STRING
))) {
78 #if (defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP || defined ACPI_NAMES_APP)
79 /*******************************************************************************
81 * FUNCTION: acpi_ut_is_aml_table
83 * PARAMETERS: table - An ACPI table
85 * RETURN: TRUE if table contains executable AML; FALSE otherwise
87 * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
88 * Currently, these are DSDT,SSDT,PSDT. All other table types are
89 * data tables that do not contain AML code.
91 ******************************************************************************/
93 u8
acpi_ut_is_aml_table(struct acpi_table_header
*table
)
96 /* These are the only tables that contain executable AML */
98 if (ACPI_COMPARE_NAME(table
->signature
, ACPI_SIG_DSDT
) ||
99 ACPI_COMPARE_NAME(table
->signature
, ACPI_SIG_PSDT
) ||
100 ACPI_COMPARE_NAME(table
->signature
, ACPI_SIG_SSDT
) ||
101 ACPI_COMPARE_NAME(table
->signature
, ACPI_SIG_OSDT
)) {
109 /*******************************************************************************
111 * FUNCTION: acpi_ut_dword_byte_swap
113 * PARAMETERS: value - Value to be converted
115 * RETURN: u32 integer with bytes swapped
117 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
119 ******************************************************************************/
121 u32
acpi_ut_dword_byte_swap(u32 value
)
132 ACPI_FUNCTION_ENTRY();
136 out
.bytes
[0] = in
.bytes
[3];
137 out
.bytes
[1] = in
.bytes
[2];
138 out
.bytes
[2] = in
.bytes
[1];
139 out
.bytes
[3] = in
.bytes
[0];
144 /*******************************************************************************
146 * FUNCTION: acpi_ut_set_integer_width
148 * PARAMETERS: Revision From DSDT header
152 * DESCRIPTION: Set the global integer bit width based upon the revision
153 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
154 * For Revision 2 and above, Integers are 64 bits. Yes, this
155 * makes a difference.
157 ******************************************************************************/
159 void acpi_ut_set_integer_width(u8 revision
)
166 acpi_gbl_integer_bit_width
= 32;
167 acpi_gbl_integer_nybble_width
= 8;
168 acpi_gbl_integer_byte_width
= 4;
170 /* 64-bit case (ACPI 2.0+) */
172 acpi_gbl_integer_bit_width
= 64;
173 acpi_gbl_integer_nybble_width
= 16;
174 acpi_gbl_integer_byte_width
= 8;
178 /*******************************************************************************
180 * FUNCTION: acpi_ut_create_update_state_and_push
182 * PARAMETERS: object - Object to be added to the new state
183 * action - Increment/Decrement
184 * state_list - List the state will be added to
188 * DESCRIPTION: Create a new state and push it
190 ******************************************************************************/
193 acpi_ut_create_update_state_and_push(union acpi_operand_object
*object
,
195 union acpi_generic_state
**state_list
)
197 union acpi_generic_state
*state
;
199 ACPI_FUNCTION_ENTRY();
201 /* Ignore null objects; these are expected */
207 state
= acpi_ut_create_update_state(object
, action
);
209 return (AE_NO_MEMORY
);
212 acpi_ut_push_generic_state(state_list
, state
);
216 /*******************************************************************************
218 * FUNCTION: acpi_ut_walk_package_tree
220 * PARAMETERS: source_object - The package to walk
221 * target_object - Target object (if package is being copied)
222 * walk_callback - Called once for each package element
223 * context - Passed to the callback function
227 * DESCRIPTION: Walk through a package, including subpackages
229 ******************************************************************************/
232 acpi_ut_walk_package_tree(union acpi_operand_object
*source_object
,
234 acpi_pkg_callback walk_callback
, void *context
)
236 acpi_status status
= AE_OK
;
237 union acpi_generic_state
*state_list
= NULL
;
238 union acpi_generic_state
*state
;
239 union acpi_operand_object
*this_source_obj
;
242 ACPI_FUNCTION_TRACE(ut_walk_package_tree
);
244 state
= acpi_ut_create_pkg_state(source_object
, target_object
, 0);
246 return_ACPI_STATUS(AE_NO_MEMORY
);
251 /* Get one element of the package */
253 this_index
= state
->pkg
.index
;
255 state
->pkg
.source_object
->package
.elements
[this_index
];
256 state
->pkg
.this_target_obj
=
257 &state
->pkg
.source_object
->package
.elements
[this_index
];
261 * 1) An uninitialized package element. It is completely
262 * legal to declare a package and leave it uninitialized
263 * 2) Not an internal object - can be a namespace node instead
264 * 3) Any type other than a package. Packages are handled in else
267 if ((!this_source_obj
) ||
268 (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj
) !=
269 ACPI_DESC_TYPE_OPERAND
) ||
270 (this_source_obj
->common
.type
!= ACPI_TYPE_PACKAGE
)) {
272 walk_callback(ACPI_COPY_TYPE_SIMPLE
,
273 this_source_obj
, state
, context
);
274 if (ACPI_FAILURE(status
)) {
275 return_ACPI_STATUS(status
);
279 while (state
->pkg
.index
>=
280 state
->pkg
.source_object
->package
.count
) {
282 * We've handled all of the objects at this level, This means
283 * that we have just completed a package. That package may
284 * have contained one or more packages itself.
286 * Delete this state and pop the previous state (package).
288 acpi_ut_delete_generic_state(state
);
289 state
= acpi_ut_pop_generic_state(&state_list
);
291 /* Finished when there are no more states */
295 * We have handled all of the objects in the top level
296 * package just add the length of the package objects
299 return_ACPI_STATUS(AE_OK
);
303 * Go back up a level and move the index past the just
304 * completed package object.
309 /* This is a subobject of type package */
312 walk_callback(ACPI_COPY_TYPE_PACKAGE
,
313 this_source_obj
, state
, context
);
314 if (ACPI_FAILURE(status
)) {
315 return_ACPI_STATUS(status
);
319 * Push the current state and create a new one
320 * The callback above returned a new target package object.
322 acpi_ut_push_generic_state(&state_list
, state
);
324 acpi_ut_create_pkg_state(this_source_obj
,
325 state
->pkg
.this_target_obj
,
329 /* Free any stacked Update State objects */
333 acpi_ut_pop_generic_state
335 acpi_ut_delete_generic_state(state
);
337 return_ACPI_STATUS(AE_NO_MEMORY
);
342 /* We should never get here */
344 ACPI_ERROR((AE_INFO
, "State list did not terminate correctly"));
346 return_ACPI_STATUS(AE_AML_INTERNAL
);
349 #ifdef ACPI_DEBUG_OUTPUT
350 /*******************************************************************************
352 * FUNCTION: acpi_ut_display_init_pathname
354 * PARAMETERS: type - Object type of the node
355 * obj_handle - Handle whose pathname will be displayed
356 * path - Additional path string to be appended.
357 * (NULL if no extra path)
359 * RETURN: acpi_status
361 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
363 ******************************************************************************/
366 acpi_ut_display_init_pathname(u8 type
,
367 struct acpi_namespace_node
*obj_handle
,
371 struct acpi_buffer buffer
;
373 ACPI_FUNCTION_ENTRY();
375 /* Only print the path if the appropriate debug level is enabled */
377 if (!(acpi_dbg_level
& ACPI_LV_INIT_NAMES
)) {
381 /* Get the full pathname to the node */
383 buffer
.length
= ACPI_ALLOCATE_LOCAL_BUFFER
;
384 status
= acpi_ns_handle_to_pathname(obj_handle
, &buffer
, TRUE
);
385 if (ACPI_FAILURE(status
)) {
389 /* Print what we're doing */
392 case ACPI_TYPE_METHOD
:
394 acpi_os_printf("Executing ");
399 acpi_os_printf("Initializing ");
403 /* Print the object type and pathname */
405 acpi_os_printf("%-12s %s",
406 acpi_ut_get_type_name(type
), (char *)buffer
.pointer
);
408 /* Extra path is used to append names like _STA, _INI, etc. */
411 acpi_os_printf(".%s", path
);
413 acpi_os_printf("\n");
415 ACPI_FREE(buffer
.pointer
);