ReactOS  0.4.14-dev-323-g6fe6a88
utmisc.c
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Module Name: utmisc - common utility procedures
4  *
5  ******************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2019, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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.
25  *
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.
29  *
30  * NO WARRANTY
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.
42  */
43 
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acnamesp.h"
47 
48 
49 #define _COMPONENT ACPI_UTILITIES
50  ACPI_MODULE_NAME ("utmisc")
51 
52 
53 /*******************************************************************************
54  *
55  * FUNCTION: AcpiUtIsPciRootBridge
56  *
57  * PARAMETERS: Id - The HID/CID in string format
58  *
59  * RETURN: TRUE if the Id is a match for a PCI/PCI-Express Root Bridge
60  *
61  * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID.
62  *
63  ******************************************************************************/
64 
65 BOOLEAN
67  char *Id)
68 {
69 
70  /*
71  * Check if this is a PCI root bridge.
72  * ACPI 3.0+: check for a PCI Express root also.
73  */
74  if (!(strcmp (Id,
76 
77  !(strcmp (Id,
79  {
80  return (TRUE);
81  }
82 
83  return (FALSE);
84 }
85 
86 
87 #if (defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP || defined ACPI_NAMES_APP)
88 /*******************************************************************************
89  *
90  * FUNCTION: AcpiUtIsAmlTable
91  *
92  * PARAMETERS: Table - An ACPI table
93  *
94  * RETURN: TRUE if table contains executable AML; FALSE otherwise
95  *
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.
99  *
100  ******************************************************************************/
101 
102 BOOLEAN
103 AcpiUtIsAmlTable (
105 {
106 
107  /* These are the only tables that contain executable AML */
108 
109  if (ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_DSDT) ||
110  ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_PSDT) ||
111  ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_SSDT) ||
112  ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_OSDT) ||
113  ACPI_IS_OEM_SIG (Table->Signature))
114  {
115  return (TRUE);
116  }
117 
118  return (FALSE);
119 }
120 #endif
121 
122 
123 /*******************************************************************************
124  *
125  * FUNCTION: AcpiUtDwordByteSwap
126  *
127  * PARAMETERS: Value - Value to be converted
128  *
129  * RETURN: UINT32 integer with bytes swapped
130  *
131  * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
132  *
133  ******************************************************************************/
134 
135 UINT32
137  UINT32 Value)
138 {
139  union
140  {
141  UINT32 Value;
142  UINT8 Bytes[4];
143  } Out;
144  union
145  {
146  UINT32 Value;
147  UINT8 Bytes[4];
148  } In;
149 
150 
152 
153 
154  In.Value = Value;
155 
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];
160 
161  return (Out.Value);
162 }
163 
164 
165 /*******************************************************************************
166  *
167  * FUNCTION: AcpiUtSetIntegerWidth
168  *
169  * PARAMETERS: Revision From DSDT header
170  *
171  * RETURN: None
172  *
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.
177  *
178  ******************************************************************************/
179 
180 void
182  UINT8 Revision)
183 {
184 
185  if (Revision < 2)
186  {
187  /* 32-bit case */
188 
189  AcpiGbl_IntegerBitWidth = 32;
190  AcpiGbl_IntegerNybbleWidth = 8;
191  AcpiGbl_IntegerByteWidth = 4;
192  }
193  else
194  {
195  /* 64-bit case (ACPI 2.0+) */
196 
197  AcpiGbl_IntegerBitWidth = 64;
198  AcpiGbl_IntegerNybbleWidth = 16;
199  AcpiGbl_IntegerByteWidth = 8;
200  }
201 }
202 
203 
204 /*******************************************************************************
205  *
206  * FUNCTION: AcpiUtCreateUpdateStateAndPush
207  *
208  * PARAMETERS: Object - Object to be added to the new state
209  * Action - Increment/Decrement
210  * StateList - List the state will be added to
211  *
212  * RETURN: Status
213  *
214  * DESCRIPTION: Create a new state and push it
215  *
216  ******************************************************************************/
217 
221  UINT16 Action,
222  ACPI_GENERIC_STATE **StateList)
223 {
225 
226 
228 
229 
230  /* Ignore null objects; these are expected */
231 
232  if (!Object)
233  {
234  return (AE_OK);
235  }
236 
238  if (!State)
239  {
240  return (AE_NO_MEMORY);
241  }
242 
243  AcpiUtPushGenericState (StateList, State);
244  return (AE_OK);
245 }
246 
247 
248 /*******************************************************************************
249  *
250  * FUNCTION: AcpiUtWalkPackageTree
251  *
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
256  *
257  * RETURN: Status
258  *
259  * DESCRIPTION: Walk through a package, including subpackages
260  *
261  ******************************************************************************/
262 
265  ACPI_OPERAND_OBJECT *SourceObject,
266  void *TargetObject,
267  ACPI_PKG_CALLBACK WalkCallback,
268  void *Context)
269 {
271  ACPI_GENERIC_STATE *StateList = NULL;
273  ACPI_OPERAND_OBJECT *ThisSourceObj;
274  UINT32 ThisIndex;
275 
276 
277  ACPI_FUNCTION_TRACE (UtWalkPackageTree);
278 
279 
280  State = AcpiUtCreatePkgState (SourceObject, TargetObject, 0);
281  if (!State)
282  {
284  }
285 
286  while (State)
287  {
288  /* Get one element of the package */
289 
290  ThisIndex = State->Pkg.Index;
291  ThisSourceObj =
292  State->Pkg.SourceObject->Package.Elements[ThisIndex];
293  State->Pkg.ThisTargetObj =
294  &State->Pkg.SourceObject->Package.Elements[ThisIndex];
295 
296  /*
297  * Check for:
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
302  * case below.
303  */
304  if ((!ThisSourceObj) ||
305  (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj) !=
307  (ThisSourceObj->Common.Type != ACPI_TYPE_PACKAGE))
308  {
309  Status = WalkCallback (ACPI_COPY_TYPE_SIMPLE, ThisSourceObj,
310  State, Context);
311  if (ACPI_FAILURE (Status))
312  {
314  }
315 
316  State->Pkg.Index++;
317  while (State->Pkg.Index >=
318  State->Pkg.SourceObject->Package.Count)
319  {
320  /*
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.
324  *
325  * Delete this state and pop the previous state (package).
326  */
328  State = AcpiUtPopGenericState (&StateList);
329 
330  /* Finished when there are no more states */
331 
332  if (!State)
333  {
334  /*
335  * We have handled all of the objects in the top level
336  * package just add the length of the package objects
337  * and exit
338  */
340  }
341 
342  /*
343  * Go back up a level and move the index past the just
344  * completed package object.
345  */
346  State->Pkg.Index++;
347  }
348  }
349  else
350  {
351  /* This is a subobject of type package */
352 
353  Status = WalkCallback (
354  ACPI_COPY_TYPE_PACKAGE, ThisSourceObj, State, Context);
355  if (ACPI_FAILURE (Status))
356  {
358  }
359 
360  /*
361  * Push the current state and create a new one
362  * The callback above returned a new target package object.
363  */
364  AcpiUtPushGenericState (&StateList, State);
366  ThisSourceObj, State->Pkg.ThisTargetObj, 0);
367  if (!State)
368  {
369  /* Free any stacked Update State objects */
370 
371  while (StateList)
372  {
373  State = AcpiUtPopGenericState (&StateList);
375  }
377  }
378  }
379  }
380 
381  /* We should never get here */
382 
384  "State list did not terminate correctly"));
385 
387 }
388 
389 
390 #ifdef ACPI_DEBUG_OUTPUT
391 /*******************************************************************************
392  *
393  * FUNCTION: AcpiUtDisplayInitPathname
394  *
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)
399  *
400  * RETURN: ACPI_STATUS
401  *
402  * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
403  *
404  ******************************************************************************/
405 
406 void
407 AcpiUtDisplayInitPathname (
408  UINT8 Type,
409  ACPI_NAMESPACE_NODE *ObjHandle,
410  const char *Path)
411 {
414 
415 
417 
418 
419  /* Only print the path if the appropriate debug level is enabled */
420 
421  if (!(AcpiDbgLevel & ACPI_LV_INIT_NAMES))
422  {
423  return;
424  }
425 
426  /* Get the full pathname to the node */
427 
429  Status = AcpiNsHandleToPathname (ObjHandle, &Buffer, TRUE);
430  if (ACPI_FAILURE (Status))
431  {
432  return;
433  }
434 
435  /* Print what we're doing */
436 
437  switch (Type)
438  {
439  case ACPI_TYPE_METHOD:
440 
441  AcpiOsPrintf ("Executing ");
442  break;
443 
444  default:
445 
446  AcpiOsPrintf ("Initializing ");
447  break;
448  }
449 
450  /* Print the object type and pathname */
451 
452  AcpiOsPrintf ("%-12s %s",
453  AcpiUtGetTypeName (Type), (char *) Buffer.Pointer);
454 
455  /* Extra path is used to append names like _STA, _INI, etc. */
456 
457  if (Path)
458  {
459  AcpiOsPrintf (".%s", Path);
460  }
461  AcpiOsPrintf ("\n");
462 
463  ACPI_FREE (Buffer.Pointer);
464 }
465 #endif
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define ACPI_FREE(a)
Definition: actypes.h:386
ASMGENDATA Table[]
Definition: genincdata.c:61
void AcpiUtDeleteGenericState(ACPI_GENERIC_STATE *State)
Definition: utstate.c:340
#define TRUE
Definition: types.h:120
ACPI_STATUS AcpiUtCreateUpdateStateAndPush(ACPI_OPERAND_OBJECT *Object, UINT16 Action, ACPI_GENERIC_STATE **StateList)
Definition: utmisc.c:219
Type
Definition: Type.h:6
#define ACPI_IS_OEM_SIG(a)
Definition: actypes.h:574
#define AE_NO_MEMORY
Definition: acexcep.h:112
UINT32 AcpiUtDwordByteSwap(UINT32 Value)
Definition: utmisc.c:136
#define AE_AML_INTERNAL
Definition: acexcep.h:194
_In_ UINT Bytes
Definition: mmcopy.h:9
void AcpiUtPushGenericState(ACPI_GENERIC_STATE **ListHead, ACPI_GENERIC_STATE *State)
Definition: utstate.c:65
UINT32 ACPI_STATUS
Definition: actypes.h:460
_In_ ULONG Revision
Definition: rtlfuncs.h:1104
DWORD Id
ACPI_GENERIC_STATE * AcpiUtPopGenericState(ACPI_GENERIC_STATE **ListHead)
Definition: utstate.c:93
#define ACPI_TYPE_PACKAGE
Definition: actypes.h:682
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
unsigned int UINT32
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
unsigned char BOOLEAN
#define AE_INFO
Definition: acoutput.h:230
smooth NULL
Definition: ftsmooth.c:416
#define ACPI_ALLOCATE_LOCAL_BUFFER
Definition: actypes.h:1036
Definition: bufpool.h:45
#define ACPI_FUNCTION_ENTRY()
Definition: acoutput.h:484
ACPI_STATUS(* ACPI_PKG_CALLBACK)(UINT8 ObjectType, ACPI_OPERAND_OBJECT *SourceObject, ACPI_GENERIC_STATE *State, void *Context)
Definition: acutils.h:163
ACPI_STATUS AcpiNsHandleToPathname(ACPI_HANDLE TargetHandle, ACPI_BUFFER *Buffer, BOOLEAN NoTrailing)
Definition: nsnames.c:193
#define ACPI_SIG_DSDT
Definition: actbl.h:67
#define ACPI_DESC_TYPE_OPERAND
Definition: acobject.h:573
#define ACPI_TYPE_METHOD
Definition: actypes.h:686
ACPI_GENERIC_STATE * AcpiUtCreatePkgState(void *InternalObject, void *ExternalObject, UINT32 Index)
Definition: utstate.c:255
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG Action
Definition: fsrtlfuncs.h:738
#define ACPI_SIG_OSDT
Definition: actbl.h:70
#define ACPI_COMPARE_NAMESEG(a, b)
Definition: actypes.h:561
static IUnknown Object
Definition: main.c:512
void ACPI_INTERNAL_VAR_XFACE AcpiOsPrintf(const char *Format,...)
Definition: osl.c:851
void AcpiUtSetIntegerWidth(UINT8 Revision)
Definition: utmisc.c:181
#define ACPI_SIG_SSDT
Definition: actbl.h:75
#define ACPI_COPY_TYPE_SIMPLE
Definition: aclocal.h:281
Status
Definition: gdiplustypes.h:24
ACPI_STATUS AcpiUtWalkPackageTree(ACPI_OPERAND_OBJECT *SourceObject, void *TargetObject, ACPI_PKG_CALLBACK WalkCallback, void *Context)
Definition: utmisc.c:264
enum State_ State
Definition: pofuncs.h:54
PRTL_UNICODE_STRING_BUFFER Path
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
ACPI_GENERIC_STATE * AcpiUtCreateUpdateState(ACPI_OPERAND_OBJECT *Object, UINT16 Action)
Definition: utstate.c:214
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
ACPI_OBJECT_COMMON Common
Definition: acobject.h:516
unsigned short UINT16
const char * AcpiUtGetTypeName(ACPI_OBJECT_TYPE Type)
Definition: utdecode.c:249
#define ACPI_LV_INIT_NAMES
Definition: acoutput.h:97
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
BOOLEAN AcpiUtIsPciRootBridge(char *Id)
Definition: utmisc.c:66
#define ACPI_SIG_PSDT
Definition: actbl.h:71
#define ACPI_COPY_TYPE_PACKAGE
Definition: aclocal.h:282
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
unsigned char UINT8
#define AE_OK
Definition: acexcep.h:97
#define PCI_ROOT_HID_STRING
Definition: actypes.h:426
#define PCI_EXPRESS_ROOT_HID_STRING
Definition: actypes.h:427
#define ACPI_GET_DESCRIPTOR_TYPE(d)
Definition: acmacros.h:414