utmisc.c revision 1.13 1 1.1 jruoho /*******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: utmisc - common utility procedures
4 1.1 jruoho *
5 1.1 jruoho ******************************************************************************/
6 1.1 jruoho
7 1.3 jruoho /*
8 1.12 christos * Copyright (C) 2000 - 2018, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.3 jruoho * Redistribution and use in source and binary forms, with or without
12 1.3 jruoho * modification, are permitted provided that the following conditions
13 1.3 jruoho * are met:
14 1.3 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.3 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.3 jruoho * without modification.
17 1.3 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.3 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.3 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.3 jruoho * including a substantially similar Disclaimer requirement for further
21 1.3 jruoho * binary redistribution.
22 1.3 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.3 jruoho * of any contributors may be used to endorse or promote products derived
24 1.3 jruoho * from this software without specific prior written permission.
25 1.3 jruoho *
26 1.3 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.3 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.3 jruoho * Software Foundation.
29 1.3 jruoho *
30 1.3 jruoho * NO WARRANTY
31 1.3 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.3 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.3 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.3 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.3 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.3 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.3 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.3 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.3 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.3 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.3 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.3 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "acpi.h"
45 1.1 jruoho #include "accommon.h"
46 1.1 jruoho #include "acnamesp.h"
47 1.1 jruoho
48 1.1 jruoho
49 1.1 jruoho #define _COMPONENT ACPI_UTILITIES
50 1.1 jruoho ACPI_MODULE_NAME ("utmisc")
51 1.1 jruoho
52 1.1 jruoho
53 1.1 jruoho /*******************************************************************************
54 1.1 jruoho *
55 1.1 jruoho * FUNCTION: AcpiUtIsPciRootBridge
56 1.1 jruoho *
57 1.1 jruoho * PARAMETERS: Id - The HID/CID in string format
58 1.1 jruoho *
59 1.1 jruoho * RETURN: TRUE if the Id is a match for a PCI/PCI-Express Root Bridge
60 1.1 jruoho *
61 1.1 jruoho * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID.
62 1.1 jruoho *
63 1.1 jruoho ******************************************************************************/
64 1.1 jruoho
65 1.1 jruoho BOOLEAN
66 1.1 jruoho AcpiUtIsPciRootBridge (
67 1.1 jruoho char *Id)
68 1.1 jruoho {
69 1.1 jruoho
70 1.1 jruoho /*
71 1.1 jruoho * Check if this is a PCI root bridge.
72 1.1 jruoho * ACPI 3.0+: check for a PCI Express root also.
73 1.1 jruoho */
74 1.8 christos if (!(strcmp (Id,
75 1.9 christos PCI_ROOT_HID_STRING)) ||
76 1.1 jruoho
77 1.8 christos !(strcmp (Id,
78 1.9 christos PCI_EXPRESS_ROOT_HID_STRING)))
79 1.1 jruoho {
80 1.4 christos return (TRUE);
81 1.1 jruoho }
82 1.1 jruoho
83 1.4 christos return (FALSE);
84 1.1 jruoho }
85 1.1 jruoho
86 1.1 jruoho
87 1.9 christos #if (defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP || defined ACPI_NAMES_APP)
88 1.1 jruoho /*******************************************************************************
89 1.1 jruoho *
90 1.4 christos * FUNCTION: AcpiUtIsAmlTable
91 1.1 jruoho *
92 1.4 christos * PARAMETERS: Table - An ACPI table
93 1.1 jruoho *
94 1.4 christos * RETURN: TRUE if table contains executable AML; FALSE otherwise
95 1.1 jruoho *
96 1.4 christos * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
97 1.4 christos * Currently, these are DSDT,SSDT,PSDT. All other table types are
98 1.4 christos * data tables that do not contain AML code.
99 1.1 jruoho *
100 1.1 jruoho ******************************************************************************/
101 1.1 jruoho
102 1.1 jruoho BOOLEAN
103 1.4 christos AcpiUtIsAmlTable (
104 1.4 christos ACPI_TABLE_HEADER *Table)
105 1.1 jruoho {
106 1.1 jruoho
107 1.4 christos /* These are the only tables that contain executable AML */
108 1.1 jruoho
109 1.4 christos if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) ||
110 1.4 christos ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_PSDT) ||
111 1.8 christos ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT) ||
112 1.13 christos ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_OSDT) ||
113 1.13 christos ACPI_IS_OEM_SIG (Table->Signature))
114 1.1 jruoho {
115 1.4 christos return (TRUE);
116 1.1 jruoho }
117 1.1 jruoho
118 1.4 christos return (FALSE);
119 1.1 jruoho }
120 1.7 christos #endif
121 1.1 jruoho
122 1.1 jruoho
123 1.1 jruoho /*******************************************************************************
124 1.1 jruoho *
125 1.4 christos * FUNCTION: AcpiUtDwordByteSwap
126 1.1 jruoho *
127 1.4 christos * PARAMETERS: Value - Value to be converted
128 1.1 jruoho *
129 1.4 christos * RETURN: UINT32 integer with bytes swapped
130 1.1 jruoho *
131 1.4 christos * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
132 1.1 jruoho *
133 1.1 jruoho ******************************************************************************/
134 1.1 jruoho
135 1.4 christos UINT32
136 1.4 christos AcpiUtDwordByteSwap (
137 1.4 christos UINT32 Value)
138 1.1 jruoho {
139 1.4 christos union
140 1.4 christos {
141 1.4 christos UINT32 Value;
142 1.4 christos UINT8 Bytes[4];
143 1.4 christos } Out;
144 1.4 christos union
145 1.4 christos {
146 1.4 christos UINT32 Value;
147 1.4 christos UINT8 Bytes[4];
148 1.4 christos } In;
149 1.1 jruoho
150 1.1 jruoho
151 1.4 christos ACPI_FUNCTION_ENTRY ();
152 1.1 jruoho
153 1.1 jruoho
154 1.4 christos In.Value = Value;
155 1.1 jruoho
156 1.4 christos Out.Bytes[0] = In.Bytes[3];
157 1.4 christos Out.Bytes[1] = In.Bytes[2];
158 1.4 christos Out.Bytes[2] = In.Bytes[1];
159 1.4 christos Out.Bytes[3] = In.Bytes[0];
160 1.1 jruoho
161 1.4 christos return (Out.Value);
162 1.1 jruoho }
163 1.1 jruoho
164 1.1 jruoho
165 1.1 jruoho /*******************************************************************************
166 1.1 jruoho *
167 1.4 christos * FUNCTION: AcpiUtSetIntegerWidth
168 1.4 christos *
169 1.4 christos * PARAMETERS: Revision From DSDT header
170 1.4 christos *
171 1.4 christos * RETURN: None
172 1.1 jruoho *
173 1.4 christos * DESCRIPTION: Set the global integer bit width based upon the revision
174 1.4 christos * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
175 1.4 christos * For Revision 2 and above, Integers are 64 bits. Yes, this
176 1.4 christos * makes a difference.
177 1.1 jruoho *
178 1.1 jruoho ******************************************************************************/
179 1.1 jruoho
180 1.4 christos void
181 1.4 christos AcpiUtSetIntegerWidth (
182 1.4 christos UINT8 Revision)
183 1.1 jruoho {
184 1.1 jruoho
185 1.4 christos if (Revision < 2)
186 1.1 jruoho {
187 1.4 christos /* 32-bit case */
188 1.1 jruoho
189 1.9 christos AcpiGbl_IntegerBitWidth = 32;
190 1.4 christos AcpiGbl_IntegerNybbleWidth = 8;
191 1.9 christos AcpiGbl_IntegerByteWidth = 4;
192 1.1 jruoho }
193 1.4 christos else
194 1.1 jruoho {
195 1.4 christos /* 64-bit case (ACPI 2.0+) */
196 1.1 jruoho
197 1.9 christos AcpiGbl_IntegerBitWidth = 64;
198 1.4 christos AcpiGbl_IntegerNybbleWidth = 16;
199 1.9 christos AcpiGbl_IntegerByteWidth = 8;
200 1.1 jruoho }
201 1.1 jruoho }
202 1.1 jruoho
203 1.1 jruoho
204 1.1 jruoho /*******************************************************************************
205 1.1 jruoho *
206 1.1 jruoho * FUNCTION: AcpiUtCreateUpdateStateAndPush
207 1.1 jruoho *
208 1.1 jruoho * PARAMETERS: Object - Object to be added to the new state
209 1.1 jruoho * Action - Increment/Decrement
210 1.1 jruoho * StateList - List the state will be added to
211 1.1 jruoho *
212 1.1 jruoho * RETURN: Status
213 1.1 jruoho *
214 1.1 jruoho * DESCRIPTION: Create a new state and push it
215 1.1 jruoho *
216 1.1 jruoho ******************************************************************************/
217 1.1 jruoho
218 1.1 jruoho ACPI_STATUS
219 1.1 jruoho AcpiUtCreateUpdateStateAndPush (
220 1.1 jruoho ACPI_OPERAND_OBJECT *Object,
221 1.1 jruoho UINT16 Action,
222 1.1 jruoho ACPI_GENERIC_STATE **StateList)
223 1.1 jruoho {
224 1.1 jruoho ACPI_GENERIC_STATE *State;
225 1.1 jruoho
226 1.1 jruoho
227 1.1 jruoho ACPI_FUNCTION_ENTRY ();
228 1.1 jruoho
229 1.1 jruoho
230 1.1 jruoho /* Ignore null objects; these are expected */
231 1.1 jruoho
232 1.1 jruoho if (!Object)
233 1.1 jruoho {
234 1.1 jruoho return (AE_OK);
235 1.1 jruoho }
236 1.1 jruoho
237 1.1 jruoho State = AcpiUtCreateUpdateState (Object, Action);
238 1.1 jruoho if (!State)
239 1.1 jruoho {
240 1.1 jruoho return (AE_NO_MEMORY);
241 1.1 jruoho }
242 1.1 jruoho
243 1.1 jruoho AcpiUtPushGenericState (StateList, State);
244 1.1 jruoho return (AE_OK);
245 1.1 jruoho }
246 1.1 jruoho
247 1.1 jruoho
248 1.1 jruoho /*******************************************************************************
249 1.1 jruoho *
250 1.1 jruoho * FUNCTION: AcpiUtWalkPackageTree
251 1.1 jruoho *
252 1.1 jruoho * PARAMETERS: SourceObject - The package to walk
253 1.1 jruoho * TargetObject - Target object (if package is being copied)
254 1.1 jruoho * WalkCallback - Called once for each package element
255 1.1 jruoho * Context - Passed to the callback function
256 1.1 jruoho *
257 1.1 jruoho * RETURN: Status
258 1.1 jruoho *
259 1.11 christos * DESCRIPTION: Walk through a package, including subpackages
260 1.1 jruoho *
261 1.1 jruoho ******************************************************************************/
262 1.1 jruoho
263 1.1 jruoho ACPI_STATUS
264 1.1 jruoho AcpiUtWalkPackageTree (
265 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObject,
266 1.1 jruoho void *TargetObject,
267 1.1 jruoho ACPI_PKG_CALLBACK WalkCallback,
268 1.1 jruoho void *Context)
269 1.1 jruoho {
270 1.1 jruoho ACPI_STATUS Status = AE_OK;
271 1.1 jruoho ACPI_GENERIC_STATE *StateList = NULL;
272 1.1 jruoho ACPI_GENERIC_STATE *State;
273 1.11 christos ACPI_OPERAND_OBJECT *ThisSourceObj;
274 1.1 jruoho UINT32 ThisIndex;
275 1.1 jruoho
276 1.1 jruoho
277 1.1 jruoho ACPI_FUNCTION_TRACE (UtWalkPackageTree);
278 1.1 jruoho
279 1.1 jruoho
280 1.1 jruoho State = AcpiUtCreatePkgState (SourceObject, TargetObject, 0);
281 1.1 jruoho if (!State)
282 1.1 jruoho {
283 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
284 1.1 jruoho }
285 1.1 jruoho
286 1.1 jruoho while (State)
287 1.1 jruoho {
288 1.1 jruoho /* Get one element of the package */
289 1.1 jruoho
290 1.9 christos ThisIndex = State->Pkg.Index;
291 1.11 christos ThisSourceObj =
292 1.9 christos State->Pkg.SourceObject->Package.Elements[ThisIndex];
293 1.11 christos State->Pkg.ThisTargetObj =
294 1.11 christos &State->Pkg.SourceObject->Package.Elements[ThisIndex];
295 1.1 jruoho
296 1.1 jruoho /*
297 1.1 jruoho * Check for:
298 1.4 christos * 1) An uninitialized package element. It is completely
299 1.1 jruoho * legal to declare a package and leave it uninitialized
300 1.1 jruoho * 2) Not an internal object - can be a namespace node instead
301 1.4 christos * 3) Any type other than a package. Packages are handled in else
302 1.1 jruoho * case below.
303 1.1 jruoho */
304 1.1 jruoho if ((!ThisSourceObj) ||
305 1.9 christos (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj) !=
306 1.9 christos ACPI_DESC_TYPE_OPERAND) ||
307 1.1 jruoho (ThisSourceObj->Common.Type != ACPI_TYPE_PACKAGE))
308 1.1 jruoho {
309 1.1 jruoho Status = WalkCallback (ACPI_COPY_TYPE_SIMPLE, ThisSourceObj,
310 1.11 christos State, Context);
311 1.1 jruoho if (ACPI_FAILURE (Status))
312 1.1 jruoho {
313 1.1 jruoho return_ACPI_STATUS (Status);
314 1.1 jruoho }
315 1.1 jruoho
316 1.1 jruoho State->Pkg.Index++;
317 1.9 christos while (State->Pkg.Index >=
318 1.9 christos State->Pkg.SourceObject->Package.Count)
319 1.1 jruoho {
320 1.1 jruoho /*
321 1.1 jruoho * We've handled all of the objects at this level, This means
322 1.4 christos * that we have just completed a package. That package may
323 1.1 jruoho * have contained one or more packages itself.
324 1.1 jruoho *
325 1.1 jruoho * Delete this state and pop the previous state (package).
326 1.1 jruoho */
327 1.1 jruoho AcpiUtDeleteGenericState (State);
328 1.1 jruoho State = AcpiUtPopGenericState (&StateList);
329 1.1 jruoho
330 1.1 jruoho /* Finished when there are no more states */
331 1.1 jruoho
332 1.1 jruoho if (!State)
333 1.1 jruoho {
334 1.1 jruoho /*
335 1.1 jruoho * We have handled all of the objects in the top level
336 1.1 jruoho * package just add the length of the package objects
337 1.1 jruoho * and exit
338 1.1 jruoho */
339 1.1 jruoho return_ACPI_STATUS (AE_OK);
340 1.1 jruoho }
341 1.1 jruoho
342 1.1 jruoho /*
343 1.1 jruoho * Go back up a level and move the index past the just
344 1.1 jruoho * completed package object.
345 1.1 jruoho */
346 1.1 jruoho State->Pkg.Index++;
347 1.1 jruoho }
348 1.1 jruoho }
349 1.1 jruoho else
350 1.1 jruoho {
351 1.1 jruoho /* This is a subobject of type package */
352 1.1 jruoho
353 1.9 christos Status = WalkCallback (
354 1.9 christos ACPI_COPY_TYPE_PACKAGE, ThisSourceObj, State, Context);
355 1.1 jruoho if (ACPI_FAILURE (Status))
356 1.1 jruoho {
357 1.1 jruoho return_ACPI_STATUS (Status);
358 1.1 jruoho }
359 1.1 jruoho
360 1.1 jruoho /*
361 1.1 jruoho * Push the current state and create a new one
362 1.1 jruoho * The callback above returned a new target package object.
363 1.1 jruoho */
364 1.1 jruoho AcpiUtPushGenericState (&StateList, State);
365 1.9 christos State = AcpiUtCreatePkgState (
366 1.9 christos ThisSourceObj, State->Pkg.ThisTargetObj, 0);
367 1.1 jruoho if (!State)
368 1.1 jruoho {
369 1.1 jruoho /* Free any stacked Update State objects */
370 1.1 jruoho
371 1.1 jruoho while (StateList)
372 1.1 jruoho {
373 1.1 jruoho State = AcpiUtPopGenericState (&StateList);
374 1.1 jruoho AcpiUtDeleteGenericState (State);
375 1.1 jruoho }
376 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
377 1.1 jruoho }
378 1.1 jruoho }
379 1.1 jruoho }
380 1.1 jruoho
381 1.1 jruoho /* We should never get here */
382 1.1 jruoho
383 1.11 christos ACPI_ERROR ((AE_INFO,
384 1.11 christos "State list did not terminate correctly"));
385 1.11 christos
386 1.1 jruoho return_ACPI_STATUS (AE_AML_INTERNAL);
387 1.1 jruoho }
388 1.1 jruoho
389 1.1 jruoho
390 1.4 christos #ifdef ACPI_DEBUG_OUTPUT
391 1.4 christos /*******************************************************************************
392 1.4 christos *
393 1.4 christos * FUNCTION: AcpiUtDisplayInitPathname
394 1.4 christos *
395 1.4 christos * PARAMETERS: Type - Object type of the node
396 1.4 christos * ObjHandle - Handle whose pathname will be displayed
397 1.4 christos * Path - Additional path string to be appended.
398 1.4 christos * (NULL if no extra path)
399 1.4 christos *
400 1.4 christos * RETURN: ACPI_STATUS
401 1.4 christos *
402 1.4 christos * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
403 1.4 christos *
404 1.4 christos ******************************************************************************/
405 1.4 christos
406 1.4 christos void
407 1.4 christos AcpiUtDisplayInitPathname (
408 1.4 christos UINT8 Type,
409 1.4 christos ACPI_NAMESPACE_NODE *ObjHandle,
410 1.5 christos const char *Path)
411 1.4 christos {
412 1.4 christos ACPI_STATUS Status;
413 1.4 christos ACPI_BUFFER Buffer;
414 1.4 christos
415 1.4 christos
416 1.4 christos ACPI_FUNCTION_ENTRY ();
417 1.4 christos
418 1.4 christos
419 1.4 christos /* Only print the path if the appropriate debug level is enabled */
420 1.4 christos
421 1.4 christos if (!(AcpiDbgLevel & ACPI_LV_INIT_NAMES))
422 1.4 christos {
423 1.4 christos return;
424 1.4 christos }
425 1.4 christos
426 1.4 christos /* Get the full pathname to the node */
427 1.4 christos
428 1.4 christos Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
429 1.9 christos Status = AcpiNsHandleToPathname (ObjHandle, &Buffer, TRUE);
430 1.4 christos if (ACPI_FAILURE (Status))
431 1.4 christos {
432 1.4 christos return;
433 1.4 christos }
434 1.4 christos
435 1.4 christos /* Print what we're doing */
436 1.4 christos
437 1.4 christos switch (Type)
438 1.4 christos {
439 1.4 christos case ACPI_TYPE_METHOD:
440 1.4 christos
441 1.4 christos AcpiOsPrintf ("Executing ");
442 1.4 christos break;
443 1.4 christos
444 1.4 christos default:
445 1.4 christos
446 1.4 christos AcpiOsPrintf ("Initializing ");
447 1.4 christos break;
448 1.4 christos }
449 1.4 christos
450 1.4 christos /* Print the object type and pathname */
451 1.4 christos
452 1.4 christos AcpiOsPrintf ("%-12s %s",
453 1.4 christos AcpiUtGetTypeName (Type), (char *) Buffer.Pointer);
454 1.4 christos
455 1.4 christos /* Extra path is used to append names like _STA, _INI, etc. */
456 1.4 christos
457 1.4 christos if (Path)
458 1.4 christos {
459 1.4 christos AcpiOsPrintf (".%s", Path);
460 1.4 christos }
461 1.4 christos AcpiOsPrintf ("\n");
462 1.4 christos
463 1.4 christos ACPI_FREE (Buffer.Pointer);
464 1.4 christos }
465 1.4 christos #endif
466