utmisc.c revision 1.7 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.7 christos * Copyright (C) 2000 - 2015, 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.1 jruoho if (!(ACPI_STRCMP (Id,
75 1.1 jruoho PCI_ROOT_HID_STRING)) ||
76 1.1 jruoho
77 1.4 christos !(ACPI_STRCMP (Id,
78 1.4 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.7 christos #if (defined ACPI_ASL_COMPILER || defined ACPI_EXEC_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.4 christos ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
112 1.1 jruoho {
113 1.4 christos return (TRUE);
114 1.1 jruoho }
115 1.1 jruoho
116 1.4 christos return (FALSE);
117 1.1 jruoho }
118 1.7 christos #endif
119 1.1 jruoho
120 1.1 jruoho
121 1.1 jruoho /*******************************************************************************
122 1.1 jruoho *
123 1.4 christos * FUNCTION: AcpiUtDwordByteSwap
124 1.1 jruoho *
125 1.4 christos * PARAMETERS: Value - Value to be converted
126 1.1 jruoho *
127 1.4 christos * RETURN: UINT32 integer with bytes swapped
128 1.1 jruoho *
129 1.4 christos * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
130 1.1 jruoho *
131 1.1 jruoho ******************************************************************************/
132 1.1 jruoho
133 1.4 christos UINT32
134 1.4 christos AcpiUtDwordByteSwap (
135 1.4 christos UINT32 Value)
136 1.1 jruoho {
137 1.4 christos union
138 1.4 christos {
139 1.4 christos UINT32 Value;
140 1.4 christos UINT8 Bytes[4];
141 1.4 christos } Out;
142 1.4 christos union
143 1.4 christos {
144 1.4 christos UINT32 Value;
145 1.4 christos UINT8 Bytes[4];
146 1.4 christos } In;
147 1.1 jruoho
148 1.1 jruoho
149 1.4 christos ACPI_FUNCTION_ENTRY ();
150 1.1 jruoho
151 1.1 jruoho
152 1.4 christos In.Value = Value;
153 1.1 jruoho
154 1.4 christos Out.Bytes[0] = In.Bytes[3];
155 1.4 christos Out.Bytes[1] = In.Bytes[2];
156 1.4 christos Out.Bytes[2] = In.Bytes[1];
157 1.4 christos Out.Bytes[3] = In.Bytes[0];
158 1.1 jruoho
159 1.4 christos return (Out.Value);
160 1.1 jruoho }
161 1.1 jruoho
162 1.1 jruoho
163 1.1 jruoho /*******************************************************************************
164 1.1 jruoho *
165 1.4 christos * FUNCTION: AcpiUtSetIntegerWidth
166 1.4 christos *
167 1.4 christos * PARAMETERS: Revision From DSDT header
168 1.4 christos *
169 1.4 christos * RETURN: None
170 1.1 jruoho *
171 1.4 christos * DESCRIPTION: Set the global integer bit width based upon the revision
172 1.4 christos * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
173 1.4 christos * For Revision 2 and above, Integers are 64 bits. Yes, this
174 1.4 christos * makes a difference.
175 1.1 jruoho *
176 1.1 jruoho ******************************************************************************/
177 1.1 jruoho
178 1.4 christos void
179 1.4 christos AcpiUtSetIntegerWidth (
180 1.4 christos UINT8 Revision)
181 1.1 jruoho {
182 1.1 jruoho
183 1.4 christos if (Revision < 2)
184 1.1 jruoho {
185 1.4 christos /* 32-bit case */
186 1.1 jruoho
187 1.4 christos AcpiGbl_IntegerBitWidth = 32;
188 1.4 christos AcpiGbl_IntegerNybbleWidth = 8;
189 1.4 christos AcpiGbl_IntegerByteWidth = 4;
190 1.1 jruoho }
191 1.4 christos else
192 1.1 jruoho {
193 1.4 christos /* 64-bit case (ACPI 2.0+) */
194 1.1 jruoho
195 1.4 christos AcpiGbl_IntegerBitWidth = 64;
196 1.4 christos AcpiGbl_IntegerNybbleWidth = 16;
197 1.4 christos AcpiGbl_IntegerByteWidth = 8;
198 1.1 jruoho }
199 1.1 jruoho }
200 1.1 jruoho
201 1.1 jruoho
202 1.1 jruoho /*******************************************************************************
203 1.1 jruoho *
204 1.1 jruoho * FUNCTION: AcpiUtCreateUpdateStateAndPush
205 1.1 jruoho *
206 1.1 jruoho * PARAMETERS: Object - Object to be added to the new state
207 1.1 jruoho * Action - Increment/Decrement
208 1.1 jruoho * StateList - List the state will be added to
209 1.1 jruoho *
210 1.1 jruoho * RETURN: Status
211 1.1 jruoho *
212 1.1 jruoho * DESCRIPTION: Create a new state and push it
213 1.1 jruoho *
214 1.1 jruoho ******************************************************************************/
215 1.1 jruoho
216 1.1 jruoho ACPI_STATUS
217 1.1 jruoho AcpiUtCreateUpdateStateAndPush (
218 1.1 jruoho ACPI_OPERAND_OBJECT *Object,
219 1.1 jruoho UINT16 Action,
220 1.1 jruoho ACPI_GENERIC_STATE **StateList)
221 1.1 jruoho {
222 1.1 jruoho ACPI_GENERIC_STATE *State;
223 1.1 jruoho
224 1.1 jruoho
225 1.1 jruoho ACPI_FUNCTION_ENTRY ();
226 1.1 jruoho
227 1.1 jruoho
228 1.1 jruoho /* Ignore null objects; these are expected */
229 1.1 jruoho
230 1.1 jruoho if (!Object)
231 1.1 jruoho {
232 1.1 jruoho return (AE_OK);
233 1.1 jruoho }
234 1.1 jruoho
235 1.1 jruoho State = AcpiUtCreateUpdateState (Object, Action);
236 1.1 jruoho if (!State)
237 1.1 jruoho {
238 1.1 jruoho return (AE_NO_MEMORY);
239 1.1 jruoho }
240 1.1 jruoho
241 1.1 jruoho AcpiUtPushGenericState (StateList, State);
242 1.1 jruoho return (AE_OK);
243 1.1 jruoho }
244 1.1 jruoho
245 1.1 jruoho
246 1.1 jruoho /*******************************************************************************
247 1.1 jruoho *
248 1.1 jruoho * FUNCTION: AcpiUtWalkPackageTree
249 1.1 jruoho *
250 1.1 jruoho * PARAMETERS: SourceObject - The package to walk
251 1.1 jruoho * TargetObject - Target object (if package is being copied)
252 1.1 jruoho * WalkCallback - Called once for each package element
253 1.1 jruoho * Context - Passed to the callback function
254 1.1 jruoho *
255 1.1 jruoho * RETURN: Status
256 1.1 jruoho *
257 1.1 jruoho * DESCRIPTION: Walk through a package
258 1.1 jruoho *
259 1.1 jruoho ******************************************************************************/
260 1.1 jruoho
261 1.1 jruoho ACPI_STATUS
262 1.1 jruoho AcpiUtWalkPackageTree (
263 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObject,
264 1.1 jruoho void *TargetObject,
265 1.1 jruoho ACPI_PKG_CALLBACK WalkCallback,
266 1.1 jruoho void *Context)
267 1.1 jruoho {
268 1.1 jruoho ACPI_STATUS Status = AE_OK;
269 1.1 jruoho ACPI_GENERIC_STATE *StateList = NULL;
270 1.1 jruoho ACPI_GENERIC_STATE *State;
271 1.1 jruoho UINT32 ThisIndex;
272 1.1 jruoho ACPI_OPERAND_OBJECT *ThisSourceObj;
273 1.1 jruoho
274 1.1 jruoho
275 1.1 jruoho ACPI_FUNCTION_TRACE (UtWalkPackageTree);
276 1.1 jruoho
277 1.1 jruoho
278 1.1 jruoho State = AcpiUtCreatePkgState (SourceObject, TargetObject, 0);
279 1.1 jruoho if (!State)
280 1.1 jruoho {
281 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
282 1.1 jruoho }
283 1.1 jruoho
284 1.1 jruoho while (State)
285 1.1 jruoho {
286 1.1 jruoho /* Get one element of the package */
287 1.1 jruoho
288 1.1 jruoho ThisIndex = State->Pkg.Index;
289 1.1 jruoho ThisSourceObj = (ACPI_OPERAND_OBJECT *)
290 1.1 jruoho State->Pkg.SourceObject->Package.Elements[ThisIndex];
291 1.1 jruoho
292 1.1 jruoho /*
293 1.1 jruoho * Check for:
294 1.4 christos * 1) An uninitialized package element. It is completely
295 1.1 jruoho * legal to declare a package and leave it uninitialized
296 1.1 jruoho * 2) Not an internal object - can be a namespace node instead
297 1.4 christos * 3) Any type other than a package. Packages are handled in else
298 1.1 jruoho * case below.
299 1.1 jruoho */
300 1.1 jruoho if ((!ThisSourceObj) ||
301 1.1 jruoho (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj) != ACPI_DESC_TYPE_OPERAND) ||
302 1.1 jruoho (ThisSourceObj->Common.Type != ACPI_TYPE_PACKAGE))
303 1.1 jruoho {
304 1.1 jruoho Status = WalkCallback (ACPI_COPY_TYPE_SIMPLE, ThisSourceObj,
305 1.1 jruoho State, Context);
306 1.1 jruoho if (ACPI_FAILURE (Status))
307 1.1 jruoho {
308 1.1 jruoho return_ACPI_STATUS (Status);
309 1.1 jruoho }
310 1.1 jruoho
311 1.1 jruoho State->Pkg.Index++;
312 1.1 jruoho while (State->Pkg.Index >= State->Pkg.SourceObject->Package.Count)
313 1.1 jruoho {
314 1.1 jruoho /*
315 1.1 jruoho * We've handled all of the objects at this level, This means
316 1.4 christos * that we have just completed a package. That package may
317 1.1 jruoho * have contained one or more packages itself.
318 1.1 jruoho *
319 1.1 jruoho * Delete this state and pop the previous state (package).
320 1.1 jruoho */
321 1.1 jruoho AcpiUtDeleteGenericState (State);
322 1.1 jruoho State = AcpiUtPopGenericState (&StateList);
323 1.1 jruoho
324 1.1 jruoho /* Finished when there are no more states */
325 1.1 jruoho
326 1.1 jruoho if (!State)
327 1.1 jruoho {
328 1.1 jruoho /*
329 1.1 jruoho * We have handled all of the objects in the top level
330 1.1 jruoho * package just add the length of the package objects
331 1.1 jruoho * and exit
332 1.1 jruoho */
333 1.1 jruoho return_ACPI_STATUS (AE_OK);
334 1.1 jruoho }
335 1.1 jruoho
336 1.1 jruoho /*
337 1.1 jruoho * Go back up a level and move the index past the just
338 1.1 jruoho * completed package object.
339 1.1 jruoho */
340 1.1 jruoho State->Pkg.Index++;
341 1.1 jruoho }
342 1.1 jruoho }
343 1.1 jruoho else
344 1.1 jruoho {
345 1.1 jruoho /* This is a subobject of type package */
346 1.1 jruoho
347 1.1 jruoho Status = WalkCallback (ACPI_COPY_TYPE_PACKAGE, ThisSourceObj,
348 1.1 jruoho State, Context);
349 1.1 jruoho if (ACPI_FAILURE (Status))
350 1.1 jruoho {
351 1.1 jruoho return_ACPI_STATUS (Status);
352 1.1 jruoho }
353 1.1 jruoho
354 1.1 jruoho /*
355 1.1 jruoho * Push the current state and create a new one
356 1.1 jruoho * The callback above returned a new target package object.
357 1.1 jruoho */
358 1.1 jruoho AcpiUtPushGenericState (&StateList, State);
359 1.1 jruoho State = AcpiUtCreatePkgState (ThisSourceObj,
360 1.1 jruoho State->Pkg.ThisTargetObj, 0);
361 1.1 jruoho if (!State)
362 1.1 jruoho {
363 1.1 jruoho /* Free any stacked Update State objects */
364 1.1 jruoho
365 1.1 jruoho while (StateList)
366 1.1 jruoho {
367 1.1 jruoho State = AcpiUtPopGenericState (&StateList);
368 1.1 jruoho AcpiUtDeleteGenericState (State);
369 1.1 jruoho }
370 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
371 1.1 jruoho }
372 1.1 jruoho }
373 1.1 jruoho }
374 1.1 jruoho
375 1.1 jruoho /* We should never get here */
376 1.1 jruoho
377 1.1 jruoho return_ACPI_STATUS (AE_AML_INTERNAL);
378 1.1 jruoho }
379 1.1 jruoho
380 1.1 jruoho
381 1.4 christos #ifdef ACPI_DEBUG_OUTPUT
382 1.4 christos /*******************************************************************************
383 1.4 christos *
384 1.4 christos * FUNCTION: AcpiUtDisplayInitPathname
385 1.4 christos *
386 1.4 christos * PARAMETERS: Type - Object type of the node
387 1.4 christos * ObjHandle - Handle whose pathname will be displayed
388 1.4 christos * Path - Additional path string to be appended.
389 1.4 christos * (NULL if no extra path)
390 1.4 christos *
391 1.4 christos * RETURN: ACPI_STATUS
392 1.4 christos *
393 1.4 christos * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
394 1.4 christos *
395 1.4 christos ******************************************************************************/
396 1.4 christos
397 1.4 christos void
398 1.4 christos AcpiUtDisplayInitPathname (
399 1.4 christos UINT8 Type,
400 1.4 christos ACPI_NAMESPACE_NODE *ObjHandle,
401 1.5 christos const char *Path)
402 1.4 christos {
403 1.4 christos ACPI_STATUS Status;
404 1.4 christos ACPI_BUFFER Buffer;
405 1.4 christos
406 1.4 christos
407 1.4 christos ACPI_FUNCTION_ENTRY ();
408 1.4 christos
409 1.4 christos
410 1.4 christos /* Only print the path if the appropriate debug level is enabled */
411 1.4 christos
412 1.4 christos if (!(AcpiDbgLevel & ACPI_LV_INIT_NAMES))
413 1.4 christos {
414 1.4 christos return;
415 1.4 christos }
416 1.4 christos
417 1.4 christos /* Get the full pathname to the node */
418 1.4 christos
419 1.4 christos Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
420 1.4 christos Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
421 1.4 christos if (ACPI_FAILURE (Status))
422 1.4 christos {
423 1.4 christos return;
424 1.4 christos }
425 1.4 christos
426 1.4 christos /* Print what we're doing */
427 1.4 christos
428 1.4 christos switch (Type)
429 1.4 christos {
430 1.4 christos case ACPI_TYPE_METHOD:
431 1.4 christos
432 1.4 christos AcpiOsPrintf ("Executing ");
433 1.4 christos break;
434 1.4 christos
435 1.4 christos default:
436 1.4 christos
437 1.4 christos AcpiOsPrintf ("Initializing ");
438 1.4 christos break;
439 1.4 christos }
440 1.4 christos
441 1.4 christos /* Print the object type and pathname */
442 1.4 christos
443 1.4 christos AcpiOsPrintf ("%-12s %s",
444 1.4 christos AcpiUtGetTypeName (Type), (char *) Buffer.Pointer);
445 1.4 christos
446 1.4 christos /* Extra path is used to append names like _STA, _INI, etc. */
447 1.4 christos
448 1.4 christos if (Path)
449 1.4 christos {
450 1.4 christos AcpiOsPrintf (".%s", Path);
451 1.4 christos }
452 1.4 christos AcpiOsPrintf ("\n");
453 1.4 christos
454 1.4 christos ACPI_FREE (Buffer.Pointer);
455 1.4 christos }
456 1.4 christos #endif
457