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