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.
49 #define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utmisc")
53 /*******************************************************************************
55 * FUNCTION: AcpiUtIsPciRootBridge
57 * PARAMETERS: Id - The HID/CID in string format
59 * RETURN: TRUE if the Id is a match for a PCI/PCI-Express Root Bridge
61 * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID.
63 ******************************************************************************/
66 AcpiUtIsPciRootBridge (
71 * Check if this is a PCI root bridge.
72 * ACPI 3.0+: check for a PCI Express root also.
75 PCI_ROOT_HID_STRING
)) ||
78 PCI_EXPRESS_ROOT_HID_STRING
)))
87 #if (defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP || defined ACPI_NAMES_APP)
88 /*******************************************************************************
90 * FUNCTION: AcpiUtIsAmlTable
92 * PARAMETERS: Table - An ACPI table
94 * RETURN: TRUE if table contains executable AML; FALSE otherwise
96 * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
97 * Currently, these are DSDT,SSDT,PSDT. All other table types are
98 * data tables that do not contain AML code.
100 ******************************************************************************/
104 ACPI_TABLE_HEADER
*Table
)
107 /* These are the only tables that contain executable AML */
109 if (ACPI_COMPARE_NAME (Table
->Signature
, ACPI_SIG_DSDT
) ||
110 ACPI_COMPARE_NAME (Table
->Signature
, ACPI_SIG_PSDT
) ||
111 ACPI_COMPARE_NAME (Table
->Signature
, ACPI_SIG_SSDT
) ||
112 ACPI_COMPARE_NAME (Table
->Signature
, ACPI_SIG_OSDT
) ||
113 ACPI_IS_OEM_SIG (Table
->Signature
))
123 /*******************************************************************************
125 * FUNCTION: AcpiUtDwordByteSwap
127 * PARAMETERS: Value - Value to be converted
129 * RETURN: UINT32 integer with bytes swapped
131 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
133 ******************************************************************************/
136 AcpiUtDwordByteSwap (
151 ACPI_FUNCTION_ENTRY ();
156 Out
.Bytes
[0] = In
.Bytes
[3];
157 Out
.Bytes
[1] = In
.Bytes
[2];
158 Out
.Bytes
[2] = In
.Bytes
[1];
159 Out
.Bytes
[3] = In
.Bytes
[0];
165 /*******************************************************************************
167 * FUNCTION: AcpiUtSetIntegerWidth
169 * PARAMETERS: Revision From DSDT header
173 * DESCRIPTION: Set the global integer bit width based upon the revision
174 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
175 * For Revision 2 and above, Integers are 64 bits. Yes, this
176 * makes a difference.
178 ******************************************************************************/
181 AcpiUtSetIntegerWidth (
189 AcpiGbl_IntegerBitWidth
= 32;
190 AcpiGbl_IntegerNybbleWidth
= 8;
191 AcpiGbl_IntegerByteWidth
= 4;
195 /* 64-bit case (ACPI 2.0+) */
197 AcpiGbl_IntegerBitWidth
= 64;
198 AcpiGbl_IntegerNybbleWidth
= 16;
199 AcpiGbl_IntegerByteWidth
= 8;
204 /*******************************************************************************
206 * FUNCTION: AcpiUtCreateUpdateStateAndPush
208 * PARAMETERS: Object - Object to be added to the new state
209 * Action - Increment/Decrement
210 * StateList - List the state will be added to
214 * DESCRIPTION: Create a new state and push it
216 ******************************************************************************/
219 AcpiUtCreateUpdateStateAndPush (
220 ACPI_OPERAND_OBJECT
*Object
,
222 ACPI_GENERIC_STATE
**StateList
)
224 ACPI_GENERIC_STATE
*State
;
227 ACPI_FUNCTION_ENTRY ();
230 /* Ignore null objects; these are expected */
237 State
= AcpiUtCreateUpdateState (Object
, Action
);
240 return (AE_NO_MEMORY
);
243 AcpiUtPushGenericState (StateList
, State
);
248 /*******************************************************************************
250 * FUNCTION: AcpiUtWalkPackageTree
252 * PARAMETERS: SourceObject - The package to walk
253 * TargetObject - Target object (if package is being copied)
254 * WalkCallback - Called once for each package element
255 * Context - Passed to the callback function
259 * DESCRIPTION: Walk through a package, including subpackages
261 ******************************************************************************/
264 AcpiUtWalkPackageTree (
265 ACPI_OPERAND_OBJECT
*SourceObject
,
267 ACPI_PKG_CALLBACK WalkCallback
,
270 ACPI_STATUS Status
= AE_OK
;
271 ACPI_GENERIC_STATE
*StateList
= NULL
;
272 ACPI_GENERIC_STATE
*State
;
273 ACPI_OPERAND_OBJECT
*ThisSourceObj
;
277 ACPI_FUNCTION_TRACE (UtWalkPackageTree
);
280 State
= AcpiUtCreatePkgState (SourceObject
, TargetObject
, 0);
283 return_ACPI_STATUS (AE_NO_MEMORY
);
288 /* Get one element of the package */
290 ThisIndex
= State
->Pkg
.Index
;
292 State
->Pkg
.SourceObject
->Package
.Elements
[ThisIndex
];
293 State
->Pkg
.ThisTargetObj
=
294 &State
->Pkg
.SourceObject
->Package
.Elements
[ThisIndex
];
298 * 1) An uninitialized package element. It is completely
299 * legal to declare a package and leave it uninitialized
300 * 2) Not an internal object - can be a namespace node instead
301 * 3) Any type other than a package. Packages are handled in else
304 if ((!ThisSourceObj
) ||
305 (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj
) !=
306 ACPI_DESC_TYPE_OPERAND
) ||
307 (ThisSourceObj
->Common
.Type
!= ACPI_TYPE_PACKAGE
))
309 Status
= WalkCallback (ACPI_COPY_TYPE_SIMPLE
, ThisSourceObj
,
311 if (ACPI_FAILURE (Status
))
313 return_ACPI_STATUS (Status
);
317 while (State
->Pkg
.Index
>=
318 State
->Pkg
.SourceObject
->Package
.Count
)
321 * We've handled all of the objects at this level, This means
322 * that we have just completed a package. That package may
323 * have contained one or more packages itself.
325 * Delete this state and pop the previous state (package).
327 AcpiUtDeleteGenericState (State
);
328 State
= AcpiUtPopGenericState (&StateList
);
330 /* Finished when there are no more states */
335 * We have handled all of the objects in the top level
336 * package just add the length of the package objects
339 return_ACPI_STATUS (AE_OK
);
343 * Go back up a level and move the index past the just
344 * completed package object.
351 /* This is a subobject of type package */
353 Status
= WalkCallback (
354 ACPI_COPY_TYPE_PACKAGE
, ThisSourceObj
, State
, Context
);
355 if (ACPI_FAILURE (Status
))
357 return_ACPI_STATUS (Status
);
361 * Push the current state and create a new one
362 * The callback above returned a new target package object.
364 AcpiUtPushGenericState (&StateList
, State
);
365 State
= AcpiUtCreatePkgState (
366 ThisSourceObj
, State
->Pkg
.ThisTargetObj
, 0);
369 /* Free any stacked Update State objects */
373 State
= AcpiUtPopGenericState (&StateList
);
374 AcpiUtDeleteGenericState (State
);
376 return_ACPI_STATUS (AE_NO_MEMORY
);
381 /* We should never get here */
383 ACPI_ERROR ((AE_INFO
,
384 "State list did not terminate correctly"));
386 return_ACPI_STATUS (AE_AML_INTERNAL
);
390 #ifdef ACPI_DEBUG_OUTPUT
391 /*******************************************************************************
393 * FUNCTION: AcpiUtDisplayInitPathname
395 * PARAMETERS: Type - Object type of the node
396 * ObjHandle - Handle whose pathname will be displayed
397 * Path - Additional path string to be appended.
398 * (NULL if no extra path)
400 * RETURN: ACPI_STATUS
402 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
404 ******************************************************************************/
407 AcpiUtDisplayInitPathname (
409 ACPI_NAMESPACE_NODE
*ObjHandle
,
416 ACPI_FUNCTION_ENTRY ();
419 /* Only print the path if the appropriate debug level is enabled */
421 if (!(AcpiDbgLevel
& ACPI_LV_INIT_NAMES
))
426 /* Get the full pathname to the node */
428 Buffer
.Length
= ACPI_ALLOCATE_LOCAL_BUFFER
;
429 Status
= AcpiNsHandleToPathname (ObjHandle
, &Buffer
, TRUE
);
430 if (ACPI_FAILURE (Status
))
435 /* Print what we're doing */
439 case ACPI_TYPE_METHOD
:
441 AcpiOsPrintf ("Executing ");
446 AcpiOsPrintf ("Initializing ");
450 /* Print the object type and pathname */
452 AcpiOsPrintf ("%-12s %s",
453 AcpiUtGetTypeName (Type
), (char *) Buffer
.Pointer
);
455 /* Extra path is used to append names like _STA, _INI, etc. */
459 AcpiOsPrintf (".%s", Path
);
463 ACPI_FREE (Buffer
.Pointer
);