utmisc.c revision 1.3.2.2 1 1.3.2.2 bouyer /*******************************************************************************
2 1.3.2.2 bouyer *
3 1.3.2.2 bouyer * Module Name: utmisc - common utility procedures
4 1.3.2.2 bouyer *
5 1.3.2.2 bouyer ******************************************************************************/
6 1.3.2.2 bouyer
7 1.3.2.2 bouyer /*
8 1.3.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
9 1.3.2.2 bouyer * All rights reserved.
10 1.3.2.2 bouyer *
11 1.3.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.3.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.3.2.2 bouyer * are met:
14 1.3.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.3.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.3.2.2 bouyer * without modification.
17 1.3.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.3.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.3.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.3.2.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.3.2.2 bouyer * binary redistribution.
22 1.3.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.3.2.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.3.2.2 bouyer * from this software without specific prior written permission.
25 1.3.2.2 bouyer *
26 1.3.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.3.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.3.2.2 bouyer * Software Foundation.
29 1.3.2.2 bouyer *
30 1.3.2.2 bouyer * NO WARRANTY
31 1.3.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.3.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.3.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.3.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.3.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.3.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.3.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.3.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.3.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.3.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.3.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.3.2.2 bouyer */
43 1.3.2.2 bouyer
44 1.3.2.2 bouyer
45 1.3.2.2 bouyer #define __UTMISC_C__
46 1.3.2.2 bouyer
47 1.3.2.2 bouyer #include "acpi.h"
48 1.3.2.2 bouyer #include "accommon.h"
49 1.3.2.2 bouyer #include "acnamesp.h"
50 1.3.2.2 bouyer
51 1.3.2.2 bouyer
52 1.3.2.2 bouyer #define _COMPONENT ACPI_UTILITIES
53 1.3.2.2 bouyer ACPI_MODULE_NAME ("utmisc")
54 1.3.2.2 bouyer
55 1.3.2.2 bouyer
56 1.3.2.2 bouyer /*******************************************************************************
57 1.3.2.2 bouyer *
58 1.3.2.2 bouyer * FUNCTION: AcpiUtValidateException
59 1.3.2.2 bouyer *
60 1.3.2.2 bouyer * PARAMETERS: Status - The ACPI_STATUS code to be formatted
61 1.3.2.2 bouyer *
62 1.3.2.2 bouyer * RETURN: A string containing the exception text. NULL if exception is
63 1.3.2.2 bouyer * not valid.
64 1.3.2.2 bouyer *
65 1.3.2.2 bouyer * DESCRIPTION: This function validates and translates an ACPI exception into
66 1.3.2.2 bouyer * an ASCII string.
67 1.3.2.2 bouyer *
68 1.3.2.2 bouyer ******************************************************************************/
69 1.3.2.2 bouyer
70 1.3.2.2 bouyer const char *
71 1.3.2.2 bouyer AcpiUtValidateException (
72 1.3.2.2 bouyer ACPI_STATUS Status)
73 1.3.2.2 bouyer {
74 1.3.2.2 bouyer UINT32 SubStatus;
75 1.3.2.2 bouyer const char *Exception = NULL;
76 1.3.2.2 bouyer
77 1.3.2.2 bouyer
78 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
79 1.3.2.2 bouyer
80 1.3.2.2 bouyer
81 1.3.2.2 bouyer /*
82 1.3.2.2 bouyer * Status is composed of two parts, a "type" and an actual code
83 1.3.2.2 bouyer */
84 1.3.2.2 bouyer SubStatus = (Status & ~AE_CODE_MASK);
85 1.3.2.2 bouyer
86 1.3.2.2 bouyer switch (Status & AE_CODE_MASK)
87 1.3.2.2 bouyer {
88 1.3.2.2 bouyer case AE_CODE_ENVIRONMENTAL:
89 1.3.2.2 bouyer
90 1.3.2.2 bouyer if (SubStatus <= AE_CODE_ENV_MAX)
91 1.3.2.2 bouyer {
92 1.3.2.2 bouyer Exception = AcpiGbl_ExceptionNames_Env [SubStatus];
93 1.3.2.2 bouyer }
94 1.3.2.2 bouyer break;
95 1.3.2.2 bouyer
96 1.3.2.2 bouyer case AE_CODE_PROGRAMMER:
97 1.3.2.2 bouyer
98 1.3.2.2 bouyer if (SubStatus <= AE_CODE_PGM_MAX)
99 1.3.2.2 bouyer {
100 1.3.2.2 bouyer Exception = AcpiGbl_ExceptionNames_Pgm [SubStatus];
101 1.3.2.2 bouyer }
102 1.3.2.2 bouyer break;
103 1.3.2.2 bouyer
104 1.3.2.2 bouyer case AE_CODE_ACPI_TABLES:
105 1.3.2.2 bouyer
106 1.3.2.2 bouyer if (SubStatus <= AE_CODE_TBL_MAX)
107 1.3.2.2 bouyer {
108 1.3.2.2 bouyer Exception = AcpiGbl_ExceptionNames_Tbl [SubStatus];
109 1.3.2.2 bouyer }
110 1.3.2.2 bouyer break;
111 1.3.2.2 bouyer
112 1.3.2.2 bouyer case AE_CODE_AML:
113 1.3.2.2 bouyer
114 1.3.2.2 bouyer if (SubStatus <= AE_CODE_AML_MAX)
115 1.3.2.2 bouyer {
116 1.3.2.2 bouyer Exception = AcpiGbl_ExceptionNames_Aml [SubStatus];
117 1.3.2.2 bouyer }
118 1.3.2.2 bouyer break;
119 1.3.2.2 bouyer
120 1.3.2.2 bouyer case AE_CODE_CONTROL:
121 1.3.2.2 bouyer
122 1.3.2.2 bouyer if (SubStatus <= AE_CODE_CTRL_MAX)
123 1.3.2.2 bouyer {
124 1.3.2.2 bouyer Exception = AcpiGbl_ExceptionNames_Ctrl [SubStatus];
125 1.3.2.2 bouyer }
126 1.3.2.2 bouyer break;
127 1.3.2.2 bouyer
128 1.3.2.2 bouyer default:
129 1.3.2.2 bouyer break;
130 1.3.2.2 bouyer }
131 1.3.2.2 bouyer
132 1.3.2.2 bouyer return (ACPI_CAST_PTR (const char, Exception));
133 1.3.2.2 bouyer }
134 1.3.2.2 bouyer
135 1.3.2.2 bouyer
136 1.3.2.2 bouyer /*******************************************************************************
137 1.3.2.2 bouyer *
138 1.3.2.2 bouyer * FUNCTION: AcpiUtIsPciRootBridge
139 1.3.2.2 bouyer *
140 1.3.2.2 bouyer * PARAMETERS: Id - The HID/CID in string format
141 1.3.2.2 bouyer *
142 1.3.2.2 bouyer * RETURN: TRUE if the Id is a match for a PCI/PCI-Express Root Bridge
143 1.3.2.2 bouyer *
144 1.3.2.2 bouyer * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID.
145 1.3.2.2 bouyer *
146 1.3.2.2 bouyer ******************************************************************************/
147 1.3.2.2 bouyer
148 1.3.2.2 bouyer BOOLEAN
149 1.3.2.2 bouyer AcpiUtIsPciRootBridge (
150 1.3.2.2 bouyer char *Id)
151 1.3.2.2 bouyer {
152 1.3.2.2 bouyer
153 1.3.2.2 bouyer /*
154 1.3.2.2 bouyer * Check if this is a PCI root bridge.
155 1.3.2.2 bouyer * ACPI 3.0+: check for a PCI Express root also.
156 1.3.2.2 bouyer */
157 1.3.2.2 bouyer if (!(ACPI_STRCMP (Id,
158 1.3.2.2 bouyer PCI_ROOT_HID_STRING)) ||
159 1.3.2.2 bouyer
160 1.3.2.2 bouyer !(ACPI_STRCMP (Id,
161 1.3.2.2 bouyer PCI_EXPRESS_ROOT_HID_STRING)))
162 1.3.2.2 bouyer {
163 1.3.2.2 bouyer return (TRUE);
164 1.3.2.2 bouyer }
165 1.3.2.2 bouyer
166 1.3.2.2 bouyer return (FALSE);
167 1.3.2.2 bouyer }
168 1.3.2.2 bouyer
169 1.3.2.2 bouyer
170 1.3.2.2 bouyer /*******************************************************************************
171 1.3.2.2 bouyer *
172 1.3.2.2 bouyer * FUNCTION: AcpiUtIsAmlTable
173 1.3.2.2 bouyer *
174 1.3.2.2 bouyer * PARAMETERS: Table - An ACPI table
175 1.3.2.2 bouyer *
176 1.3.2.2 bouyer * RETURN: TRUE if table contains executable AML; FALSE otherwise
177 1.3.2.2 bouyer *
178 1.3.2.2 bouyer * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
179 1.3.2.2 bouyer * Currently, these are DSDT,SSDT,PSDT. All other table types are
180 1.3.2.2 bouyer * data tables that do not contain AML code.
181 1.3.2.2 bouyer *
182 1.3.2.2 bouyer ******************************************************************************/
183 1.3.2.2 bouyer
184 1.3.2.2 bouyer BOOLEAN
185 1.3.2.2 bouyer AcpiUtIsAmlTable (
186 1.3.2.2 bouyer ACPI_TABLE_HEADER *Table)
187 1.3.2.2 bouyer {
188 1.3.2.2 bouyer
189 1.3.2.2 bouyer /* These are the only tables that contain executable AML */
190 1.3.2.2 bouyer
191 1.3.2.2 bouyer if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) ||
192 1.3.2.2 bouyer ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_PSDT) ||
193 1.3.2.2 bouyer ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
194 1.3.2.2 bouyer {
195 1.3.2.2 bouyer return (TRUE);
196 1.3.2.2 bouyer }
197 1.3.2.2 bouyer
198 1.3.2.2 bouyer return (FALSE);
199 1.3.2.2 bouyer }
200 1.3.2.2 bouyer
201 1.3.2.2 bouyer
202 1.3.2.2 bouyer /*******************************************************************************
203 1.3.2.2 bouyer *
204 1.3.2.2 bouyer * FUNCTION: AcpiUtAllocateOwnerId
205 1.3.2.2 bouyer *
206 1.3.2.2 bouyer * PARAMETERS: OwnerId - Where the new owner ID is returned
207 1.3.2.2 bouyer *
208 1.3.2.2 bouyer * RETURN: Status
209 1.3.2.2 bouyer *
210 1.3.2.2 bouyer * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
211 1.3.2.2 bouyer * track objects created by the table or method, to be deleted
212 1.3.2.2 bouyer * when the method exits or the table is unloaded.
213 1.3.2.2 bouyer *
214 1.3.2.2 bouyer ******************************************************************************/
215 1.3.2.2 bouyer
216 1.3.2.2 bouyer ACPI_STATUS
217 1.3.2.2 bouyer AcpiUtAllocateOwnerId (
218 1.3.2.2 bouyer ACPI_OWNER_ID *OwnerId)
219 1.3.2.2 bouyer {
220 1.3.2.2 bouyer UINT32 i;
221 1.3.2.2 bouyer UINT32 j;
222 1.3.2.2 bouyer UINT32 k;
223 1.3.2.2 bouyer ACPI_STATUS Status;
224 1.3.2.2 bouyer
225 1.3.2.2 bouyer
226 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (UtAllocateOwnerId);
227 1.3.2.2 bouyer
228 1.3.2.2 bouyer
229 1.3.2.2 bouyer /* Guard against multiple allocations of ID to the same location */
230 1.3.2.2 bouyer
231 1.3.2.2 bouyer if (*OwnerId)
232 1.3.2.2 bouyer {
233 1.3.2.2 bouyer ACPI_ERROR ((AE_INFO, "Owner ID [0x%2.2X] already exists", *OwnerId));
234 1.3.2.2 bouyer return_ACPI_STATUS (AE_ALREADY_EXISTS);
235 1.3.2.2 bouyer }
236 1.3.2.2 bouyer
237 1.3.2.2 bouyer /* Mutex for the global ID mask */
238 1.3.2.2 bouyer
239 1.3.2.2 bouyer Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
240 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
241 1.3.2.2 bouyer {
242 1.3.2.2 bouyer return_ACPI_STATUS (Status);
243 1.3.2.2 bouyer }
244 1.3.2.2 bouyer
245 1.3.2.2 bouyer /*
246 1.3.2.2 bouyer * Find a free owner ID, cycle through all possible IDs on repeated
247 1.3.2.2 bouyer * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have
248 1.3.2.2 bouyer * to be scanned twice.
249 1.3.2.2 bouyer */
250 1.3.2.2 bouyer for (i = 0, j = AcpiGbl_LastOwnerIdIndex;
251 1.3.2.2 bouyer i < (ACPI_NUM_OWNERID_MASKS + 1);
252 1.3.2.2 bouyer i++, j++)
253 1.3.2.2 bouyer {
254 1.3.2.2 bouyer if (j >= ACPI_NUM_OWNERID_MASKS)
255 1.3.2.2 bouyer {
256 1.3.2.2 bouyer j = 0; /* Wraparound to start of mask array */
257 1.3.2.2 bouyer }
258 1.3.2.2 bouyer
259 1.3.2.2 bouyer for (k = AcpiGbl_NextOwnerIdOffset; k < 32; k++)
260 1.3.2.2 bouyer {
261 1.3.2.2 bouyer if (AcpiGbl_OwnerIdMask[j] == ACPI_UINT32_MAX)
262 1.3.2.2 bouyer {
263 1.3.2.2 bouyer /* There are no free IDs in this mask */
264 1.3.2.2 bouyer
265 1.3.2.2 bouyer break;
266 1.3.2.2 bouyer }
267 1.3.2.2 bouyer
268 1.3.2.2 bouyer if (!(AcpiGbl_OwnerIdMask[j] & (1 << k)))
269 1.3.2.2 bouyer {
270 1.3.2.2 bouyer /*
271 1.3.2.2 bouyer * Found a free ID. The actual ID is the bit index plus one,
272 1.3.2.2 bouyer * making zero an invalid Owner ID. Save this as the last ID
273 1.3.2.2 bouyer * allocated and update the global ID mask.
274 1.3.2.2 bouyer */
275 1.3.2.2 bouyer AcpiGbl_OwnerIdMask[j] |= (1 << k);
276 1.3.2.2 bouyer
277 1.3.2.2 bouyer AcpiGbl_LastOwnerIdIndex = (UINT8) j;
278 1.3.2.2 bouyer AcpiGbl_NextOwnerIdOffset = (UINT8) (k + 1);
279 1.3.2.2 bouyer
280 1.3.2.2 bouyer /*
281 1.3.2.2 bouyer * Construct encoded ID from the index and bit position
282 1.3.2.2 bouyer *
283 1.3.2.2 bouyer * Note: Last [j].k (bit 255) is never used and is marked
284 1.3.2.2 bouyer * permanently allocated (prevents +1 overflow)
285 1.3.2.2 bouyer */
286 1.3.2.2 bouyer *OwnerId = (ACPI_OWNER_ID) ((k + 1) + ACPI_MUL_32 (j));
287 1.3.2.2 bouyer
288 1.3.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_VALUES,
289 1.3.2.2 bouyer "Allocated OwnerId: %2.2X\n", (unsigned int) *OwnerId));
290 1.3.2.2 bouyer goto Exit;
291 1.3.2.2 bouyer }
292 1.3.2.2 bouyer }
293 1.3.2.2 bouyer
294 1.3.2.2 bouyer AcpiGbl_NextOwnerIdOffset = 0;
295 1.3.2.2 bouyer }
296 1.3.2.2 bouyer
297 1.3.2.2 bouyer /*
298 1.3.2.2 bouyer * All OwnerIds have been allocated. This typically should
299 1.3.2.2 bouyer * not happen since the IDs are reused after deallocation. The IDs are
300 1.3.2.2 bouyer * allocated upon table load (one per table) and method execution, and
301 1.3.2.2 bouyer * they are released when a table is unloaded or a method completes
302 1.3.2.2 bouyer * execution.
303 1.3.2.2 bouyer *
304 1.3.2.2 bouyer * If this error happens, there may be very deep nesting of invoked control
305 1.3.2.2 bouyer * methods, or there may be a bug where the IDs are not released.
306 1.3.2.2 bouyer */
307 1.3.2.2 bouyer Status = AE_OWNER_ID_LIMIT;
308 1.3.2.2 bouyer ACPI_ERROR ((AE_INFO,
309 1.3.2.2 bouyer "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
310 1.3.2.2 bouyer
311 1.3.2.2 bouyer Exit:
312 1.3.2.2 bouyer (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
313 1.3.2.2 bouyer return_ACPI_STATUS (Status);
314 1.3.2.2 bouyer }
315 1.3.2.2 bouyer
316 1.3.2.2 bouyer
317 1.3.2.2 bouyer /*******************************************************************************
318 1.3.2.2 bouyer *
319 1.3.2.2 bouyer * FUNCTION: AcpiUtReleaseOwnerId
320 1.3.2.2 bouyer *
321 1.3.2.2 bouyer * PARAMETERS: OwnerIdPtr - Pointer to a previously allocated OwnerID
322 1.3.2.2 bouyer *
323 1.3.2.2 bouyer * RETURN: None. No error is returned because we are either exiting a
324 1.3.2.2 bouyer * control method or unloading a table. Either way, we would
325 1.3.2.2 bouyer * ignore any error anyway.
326 1.3.2.2 bouyer *
327 1.3.2.2 bouyer * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255
328 1.3.2.2 bouyer *
329 1.3.2.2 bouyer ******************************************************************************/
330 1.3.2.2 bouyer
331 1.3.2.2 bouyer void
332 1.3.2.2 bouyer AcpiUtReleaseOwnerId (
333 1.3.2.2 bouyer ACPI_OWNER_ID *OwnerIdPtr)
334 1.3.2.2 bouyer {
335 1.3.2.2 bouyer ACPI_OWNER_ID OwnerId = *OwnerIdPtr;
336 1.3.2.2 bouyer ACPI_STATUS Status;
337 1.3.2.2 bouyer UINT32 Index;
338 1.3.2.2 bouyer UINT32 Bit;
339 1.3.2.2 bouyer
340 1.3.2.2 bouyer
341 1.3.2.2 bouyer ACPI_FUNCTION_TRACE_U32 (UtReleaseOwnerId, OwnerId);
342 1.3.2.2 bouyer
343 1.3.2.2 bouyer
344 1.3.2.2 bouyer /* Always clear the input OwnerId (zero is an invalid ID) */
345 1.3.2.2 bouyer
346 1.3.2.2 bouyer *OwnerIdPtr = 0;
347 1.3.2.2 bouyer
348 1.3.2.2 bouyer /* Zero is not a valid OwnerID */
349 1.3.2.2 bouyer
350 1.3.2.2 bouyer if (OwnerId == 0)
351 1.3.2.2 bouyer {
352 1.3.2.2 bouyer ACPI_ERROR ((AE_INFO, "Invalid OwnerId: 0x%2.2X", OwnerId));
353 1.3.2.2 bouyer return_VOID;
354 1.3.2.2 bouyer }
355 1.3.2.2 bouyer
356 1.3.2.2 bouyer /* Mutex for the global ID mask */
357 1.3.2.2 bouyer
358 1.3.2.2 bouyer Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
359 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
360 1.3.2.2 bouyer {
361 1.3.2.2 bouyer return_VOID;
362 1.3.2.2 bouyer }
363 1.3.2.2 bouyer
364 1.3.2.2 bouyer /* Normalize the ID to zero */
365 1.3.2.2 bouyer
366 1.3.2.2 bouyer OwnerId--;
367 1.3.2.2 bouyer
368 1.3.2.2 bouyer /* Decode ID to index/offset pair */
369 1.3.2.2 bouyer
370 1.3.2.2 bouyer Index = ACPI_DIV_32 (OwnerId);
371 1.3.2.2 bouyer Bit = 1 << ACPI_MOD_32 (OwnerId);
372 1.3.2.2 bouyer
373 1.3.2.2 bouyer /* Free the owner ID only if it is valid */
374 1.3.2.2 bouyer
375 1.3.2.2 bouyer if (AcpiGbl_OwnerIdMask[Index] & Bit)
376 1.3.2.2 bouyer {
377 1.3.2.2 bouyer AcpiGbl_OwnerIdMask[Index] ^= Bit;
378 1.3.2.2 bouyer }
379 1.3.2.2 bouyer else
380 1.3.2.2 bouyer {
381 1.3.2.2 bouyer ACPI_ERROR ((AE_INFO,
382 1.3.2.2 bouyer "Release of non-allocated OwnerId: 0x%2.2X", OwnerId + 1));
383 1.3.2.2 bouyer }
384 1.3.2.2 bouyer
385 1.3.2.2 bouyer (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
386 1.3.2.2 bouyer return_VOID;
387 1.3.2.2 bouyer }
388 1.3.2.2 bouyer
389 1.3.2.2 bouyer
390 1.3.2.2 bouyer /*******************************************************************************
391 1.3.2.2 bouyer *
392 1.3.2.2 bouyer * FUNCTION: AcpiUtStrupr (strupr)
393 1.3.2.2 bouyer *
394 1.3.2.2 bouyer * PARAMETERS: SrcString - The source string to convert
395 1.3.2.2 bouyer *
396 1.3.2.2 bouyer * RETURN: None
397 1.3.2.2 bouyer *
398 1.3.2.2 bouyer * DESCRIPTION: Convert string to uppercase
399 1.3.2.2 bouyer *
400 1.3.2.2 bouyer * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
401 1.3.2.2 bouyer *
402 1.3.2.2 bouyer ******************************************************************************/
403 1.3.2.2 bouyer
404 1.3.2.2 bouyer void
405 1.3.2.2 bouyer AcpiUtStrupr (
406 1.3.2.2 bouyer char *SrcString)
407 1.3.2.2 bouyer {
408 1.3.2.2 bouyer char *String;
409 1.3.2.2 bouyer
410 1.3.2.2 bouyer
411 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
412 1.3.2.2 bouyer
413 1.3.2.2 bouyer
414 1.3.2.2 bouyer if (!SrcString)
415 1.3.2.2 bouyer {
416 1.3.2.2 bouyer return;
417 1.3.2.2 bouyer }
418 1.3.2.2 bouyer
419 1.3.2.2 bouyer /* Walk entire string, uppercasing the letters */
420 1.3.2.2 bouyer
421 1.3.2.2 bouyer for (String = SrcString; *String; String++)
422 1.3.2.2 bouyer {
423 1.3.2.2 bouyer *String = (char) ACPI_TOUPPER (*String);
424 1.3.2.2 bouyer }
425 1.3.2.2 bouyer
426 1.3.2.2 bouyer return;
427 1.3.2.2 bouyer }
428 1.3.2.2 bouyer
429 1.3.2.2 bouyer
430 1.3.2.2 bouyer #ifdef ACPI_ASL_COMPILER
431 1.3.2.2 bouyer /*******************************************************************************
432 1.3.2.2 bouyer *
433 1.3.2.2 bouyer * FUNCTION: AcpiUtStrlwr (strlwr)
434 1.3.2.2 bouyer *
435 1.3.2.2 bouyer * PARAMETERS: SrcString - The source string to convert
436 1.3.2.2 bouyer *
437 1.3.2.2 bouyer * RETURN: None
438 1.3.2.2 bouyer *
439 1.3.2.2 bouyer * DESCRIPTION: Convert string to lowercase
440 1.3.2.2 bouyer *
441 1.3.2.2 bouyer * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
442 1.3.2.2 bouyer *
443 1.3.2.2 bouyer ******************************************************************************/
444 1.3.2.2 bouyer
445 1.3.2.2 bouyer void
446 1.3.2.2 bouyer AcpiUtStrlwr (
447 1.3.2.2 bouyer char *SrcString)
448 1.3.2.2 bouyer {
449 1.3.2.2 bouyer char *String;
450 1.3.2.2 bouyer
451 1.3.2.2 bouyer
452 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
453 1.3.2.2 bouyer
454 1.3.2.2 bouyer
455 1.3.2.2 bouyer if (!SrcString)
456 1.3.2.2 bouyer {
457 1.3.2.2 bouyer return;
458 1.3.2.2 bouyer }
459 1.3.2.2 bouyer
460 1.3.2.2 bouyer /* Walk entire string, lowercasing the letters */
461 1.3.2.2 bouyer
462 1.3.2.2 bouyer for (String = SrcString; *String; String++)
463 1.3.2.2 bouyer {
464 1.3.2.2 bouyer *String = (char) ACPI_TOLOWER (*String);
465 1.3.2.2 bouyer }
466 1.3.2.2 bouyer
467 1.3.2.2 bouyer return;
468 1.3.2.2 bouyer }
469 1.3.2.2 bouyer #endif
470 1.3.2.2 bouyer
471 1.3.2.2 bouyer
472 1.3.2.2 bouyer /*******************************************************************************
473 1.3.2.2 bouyer *
474 1.3.2.2 bouyer * FUNCTION: AcpiUtPrintString
475 1.3.2.2 bouyer *
476 1.3.2.2 bouyer * PARAMETERS: String - Null terminated ASCII string
477 1.3.2.2 bouyer * MaxLength - Maximum output length
478 1.3.2.2 bouyer *
479 1.3.2.2 bouyer * RETURN: None
480 1.3.2.2 bouyer *
481 1.3.2.2 bouyer * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
482 1.3.2.2 bouyer * sequences.
483 1.3.2.2 bouyer *
484 1.3.2.2 bouyer ******************************************************************************/
485 1.3.2.2 bouyer
486 1.3.2.2 bouyer void
487 1.3.2.2 bouyer AcpiUtPrintString (
488 1.3.2.2 bouyer char *String,
489 1.3.2.2 bouyer UINT8 MaxLength)
490 1.3.2.2 bouyer {
491 1.3.2.2 bouyer UINT32 i;
492 1.3.2.2 bouyer
493 1.3.2.2 bouyer
494 1.3.2.2 bouyer if (!String)
495 1.3.2.2 bouyer {
496 1.3.2.2 bouyer AcpiOsPrintf ("<\"NULL STRING PTR\">");
497 1.3.2.2 bouyer return;
498 1.3.2.2 bouyer }
499 1.3.2.2 bouyer
500 1.3.2.2 bouyer AcpiOsPrintf ("\"");
501 1.3.2.2 bouyer for (i = 0; String[i] && (i < MaxLength); i++)
502 1.3.2.2 bouyer {
503 1.3.2.2 bouyer /* Escape sequences */
504 1.3.2.2 bouyer
505 1.3.2.2 bouyer switch (String[i])
506 1.3.2.2 bouyer {
507 1.3.2.2 bouyer case 0x07:
508 1.3.2.2 bouyer AcpiOsPrintf ("\\a"); /* BELL */
509 1.3.2.2 bouyer break;
510 1.3.2.2 bouyer
511 1.3.2.2 bouyer case 0x08:
512 1.3.2.2 bouyer AcpiOsPrintf ("\\b"); /* BACKSPACE */
513 1.3.2.2 bouyer break;
514 1.3.2.2 bouyer
515 1.3.2.2 bouyer case 0x0C:
516 1.3.2.2 bouyer AcpiOsPrintf ("\\f"); /* FORMFEED */
517 1.3.2.2 bouyer break;
518 1.3.2.2 bouyer
519 1.3.2.2 bouyer case 0x0A:
520 1.3.2.2 bouyer AcpiOsPrintf ("\\n"); /* LINEFEED */
521 1.3.2.2 bouyer break;
522 1.3.2.2 bouyer
523 1.3.2.2 bouyer case 0x0D:
524 1.3.2.2 bouyer AcpiOsPrintf ("\\r"); /* CARRIAGE RETURN*/
525 1.3.2.2 bouyer break;
526 1.3.2.2 bouyer
527 1.3.2.2 bouyer case 0x09:
528 1.3.2.2 bouyer AcpiOsPrintf ("\\t"); /* HORIZONTAL TAB */
529 1.3.2.2 bouyer break;
530 1.3.2.2 bouyer
531 1.3.2.2 bouyer case 0x0B:
532 1.3.2.2 bouyer AcpiOsPrintf ("\\v"); /* VERTICAL TAB */
533 1.3.2.2 bouyer break;
534 1.3.2.2 bouyer
535 1.3.2.2 bouyer case '\'': /* Single Quote */
536 1.3.2.2 bouyer case '\"': /* Double Quote */
537 1.3.2.2 bouyer case '\\': /* Backslash */
538 1.3.2.2 bouyer AcpiOsPrintf ("\\%c", (int) String[i]);
539 1.3.2.2 bouyer break;
540 1.3.2.2 bouyer
541 1.3.2.2 bouyer default:
542 1.3.2.2 bouyer
543 1.3.2.2 bouyer /* Check for printable character or hex escape */
544 1.3.2.2 bouyer
545 1.3.2.2 bouyer if (ACPI_IS_PRINT (String[i]))
546 1.3.2.2 bouyer {
547 1.3.2.2 bouyer /* This is a normal character */
548 1.3.2.2 bouyer
549 1.3.2.2 bouyer AcpiOsPrintf ("%c", (int) String[i]);
550 1.3.2.2 bouyer }
551 1.3.2.2 bouyer else
552 1.3.2.2 bouyer {
553 1.3.2.2 bouyer /* All others will be Hex escapes */
554 1.3.2.2 bouyer
555 1.3.2.2 bouyer AcpiOsPrintf ("\\x%2.2X", (INT32) String[i]);
556 1.3.2.2 bouyer }
557 1.3.2.2 bouyer break;
558 1.3.2.2 bouyer }
559 1.3.2.2 bouyer }
560 1.3.2.2 bouyer AcpiOsPrintf ("\"");
561 1.3.2.2 bouyer
562 1.3.2.2 bouyer if (i == MaxLength && String[i])
563 1.3.2.2 bouyer {
564 1.3.2.2 bouyer AcpiOsPrintf ("...");
565 1.3.2.2 bouyer }
566 1.3.2.2 bouyer }
567 1.3.2.2 bouyer
568 1.3.2.2 bouyer
569 1.3.2.2 bouyer /*******************************************************************************
570 1.3.2.2 bouyer *
571 1.3.2.2 bouyer * FUNCTION: AcpiUtDwordByteSwap
572 1.3.2.2 bouyer *
573 1.3.2.2 bouyer * PARAMETERS: Value - Value to be converted
574 1.3.2.2 bouyer *
575 1.3.2.2 bouyer * RETURN: UINT32 integer with bytes swapped
576 1.3.2.2 bouyer *
577 1.3.2.2 bouyer * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
578 1.3.2.2 bouyer *
579 1.3.2.2 bouyer ******************************************************************************/
580 1.3.2.2 bouyer
581 1.3.2.2 bouyer UINT32
582 1.3.2.2 bouyer AcpiUtDwordByteSwap (
583 1.3.2.2 bouyer UINT32 Value)
584 1.3.2.2 bouyer {
585 1.3.2.2 bouyer union
586 1.3.2.2 bouyer {
587 1.3.2.2 bouyer UINT32 Value;
588 1.3.2.2 bouyer UINT8 Bytes[4];
589 1.3.2.2 bouyer } Out;
590 1.3.2.2 bouyer union
591 1.3.2.2 bouyer {
592 1.3.2.2 bouyer UINT32 Value;
593 1.3.2.2 bouyer UINT8 Bytes[4];
594 1.3.2.2 bouyer } In;
595 1.3.2.2 bouyer
596 1.3.2.2 bouyer
597 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
598 1.3.2.2 bouyer
599 1.3.2.2 bouyer
600 1.3.2.2 bouyer In.Value = Value;
601 1.3.2.2 bouyer
602 1.3.2.2 bouyer Out.Bytes[0] = In.Bytes[3];
603 1.3.2.2 bouyer Out.Bytes[1] = In.Bytes[2];
604 1.3.2.2 bouyer Out.Bytes[2] = In.Bytes[1];
605 1.3.2.2 bouyer Out.Bytes[3] = In.Bytes[0];
606 1.3.2.2 bouyer
607 1.3.2.2 bouyer return (Out.Value);
608 1.3.2.2 bouyer }
609 1.3.2.2 bouyer
610 1.3.2.2 bouyer
611 1.3.2.2 bouyer /*******************************************************************************
612 1.3.2.2 bouyer *
613 1.3.2.2 bouyer * FUNCTION: AcpiUtSetIntegerWidth
614 1.3.2.2 bouyer *
615 1.3.2.2 bouyer * PARAMETERS: Revision From DSDT header
616 1.3.2.2 bouyer *
617 1.3.2.2 bouyer * RETURN: None
618 1.3.2.2 bouyer *
619 1.3.2.2 bouyer * DESCRIPTION: Set the global integer bit width based upon the revision
620 1.3.2.2 bouyer * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
621 1.3.2.2 bouyer * For Revision 2 and above, Integers are 64 bits. Yes, this
622 1.3.2.2 bouyer * makes a difference.
623 1.3.2.2 bouyer *
624 1.3.2.2 bouyer ******************************************************************************/
625 1.3.2.2 bouyer
626 1.3.2.2 bouyer void
627 1.3.2.2 bouyer AcpiUtSetIntegerWidth (
628 1.3.2.2 bouyer UINT8 Revision)
629 1.3.2.2 bouyer {
630 1.3.2.2 bouyer
631 1.3.2.2 bouyer if (Revision < 2)
632 1.3.2.2 bouyer {
633 1.3.2.2 bouyer /* 32-bit case */
634 1.3.2.2 bouyer
635 1.3.2.2 bouyer AcpiGbl_IntegerBitWidth = 32;
636 1.3.2.2 bouyer AcpiGbl_IntegerNybbleWidth = 8;
637 1.3.2.2 bouyer AcpiGbl_IntegerByteWidth = 4;
638 1.3.2.2 bouyer }
639 1.3.2.2 bouyer else
640 1.3.2.2 bouyer {
641 1.3.2.2 bouyer /* 64-bit case (ACPI 2.0+) */
642 1.3.2.2 bouyer
643 1.3.2.2 bouyer AcpiGbl_IntegerBitWidth = 64;
644 1.3.2.2 bouyer AcpiGbl_IntegerNybbleWidth = 16;
645 1.3.2.2 bouyer AcpiGbl_IntegerByteWidth = 8;
646 1.3.2.2 bouyer }
647 1.3.2.2 bouyer }
648 1.3.2.2 bouyer
649 1.3.2.2 bouyer
650 1.3.2.2 bouyer #ifdef ACPI_DEBUG_OUTPUT
651 1.3.2.2 bouyer /*******************************************************************************
652 1.3.2.2 bouyer *
653 1.3.2.2 bouyer * FUNCTION: AcpiUtDisplayInitPathname
654 1.3.2.2 bouyer *
655 1.3.2.2 bouyer * PARAMETERS: Type - Object type of the node
656 1.3.2.2 bouyer * ObjHandle - Handle whose pathname will be displayed
657 1.3.2.2 bouyer * Path - Additional path string to be appended.
658 1.3.2.2 bouyer * (NULL if no extra path)
659 1.3.2.2 bouyer *
660 1.3.2.2 bouyer * RETURN: ACPI_STATUS
661 1.3.2.2 bouyer *
662 1.3.2.2 bouyer * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
663 1.3.2.2 bouyer *
664 1.3.2.2 bouyer ******************************************************************************/
665 1.3.2.2 bouyer
666 1.3.2.2 bouyer void
667 1.3.2.2 bouyer AcpiUtDisplayInitPathname (
668 1.3.2.2 bouyer UINT8 Type,
669 1.3.2.2 bouyer ACPI_NAMESPACE_NODE *ObjHandle,
670 1.3.2.2 bouyer const char *Path)
671 1.3.2.2 bouyer {
672 1.3.2.2 bouyer ACPI_STATUS Status;
673 1.3.2.2 bouyer ACPI_BUFFER Buffer;
674 1.3.2.2 bouyer
675 1.3.2.2 bouyer
676 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
677 1.3.2.2 bouyer
678 1.3.2.2 bouyer
679 1.3.2.2 bouyer /* Only print the path if the appropriate debug level is enabled */
680 1.3.2.2 bouyer
681 1.3.2.2 bouyer if (!(AcpiDbgLevel & ACPI_LV_INIT_NAMES))
682 1.3.2.2 bouyer {
683 1.3.2.2 bouyer return;
684 1.3.2.2 bouyer }
685 1.3.2.2 bouyer
686 1.3.2.2 bouyer /* Get the full pathname to the node */
687 1.3.2.2 bouyer
688 1.3.2.2 bouyer Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
689 1.3.2.2 bouyer Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
690 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
691 1.3.2.2 bouyer {
692 1.3.2.2 bouyer return;
693 1.3.2.2 bouyer }
694 1.3.2.2 bouyer
695 1.3.2.2 bouyer /* Print what we're doing */
696 1.3.2.2 bouyer
697 1.3.2.2 bouyer switch (Type)
698 1.3.2.2 bouyer {
699 1.3.2.2 bouyer case ACPI_TYPE_METHOD:
700 1.3.2.2 bouyer AcpiOsPrintf ("Executing ");
701 1.3.2.2 bouyer break;
702 1.3.2.2 bouyer
703 1.3.2.2 bouyer default:
704 1.3.2.2 bouyer AcpiOsPrintf ("Initializing ");
705 1.3.2.2 bouyer break;
706 1.3.2.2 bouyer }
707 1.3.2.2 bouyer
708 1.3.2.2 bouyer /* Print the object type and pathname */
709 1.3.2.2 bouyer
710 1.3.2.2 bouyer AcpiOsPrintf ("%-12s %s",
711 1.3.2.2 bouyer AcpiUtGetTypeName (Type), (char *) Buffer.Pointer);
712 1.3.2.2 bouyer
713 1.3.2.2 bouyer /* Extra path is used to append names like _STA, _INI, etc. */
714 1.3.2.2 bouyer
715 1.3.2.2 bouyer if (Path)
716 1.3.2.2 bouyer {
717 1.3.2.2 bouyer AcpiOsPrintf (".%s", Path);
718 1.3.2.2 bouyer }
719 1.3.2.2 bouyer AcpiOsPrintf ("\n");
720 1.3.2.2 bouyer
721 1.3.2.2 bouyer ACPI_FREE (Buffer.Pointer);
722 1.3.2.2 bouyer }
723 1.3.2.2 bouyer #endif
724 1.3.2.2 bouyer
725 1.3.2.2 bouyer
726 1.3.2.2 bouyer /*******************************************************************************
727 1.3.2.2 bouyer *
728 1.3.2.2 bouyer * FUNCTION: AcpiUtValidAcpiChar
729 1.3.2.2 bouyer *
730 1.3.2.2 bouyer * PARAMETERS: Char - The character to be examined
731 1.3.2.2 bouyer * Position - Byte position (0-3)
732 1.3.2.2 bouyer *
733 1.3.2.2 bouyer * RETURN: TRUE if the character is valid, FALSE otherwise
734 1.3.2.2 bouyer *
735 1.3.2.2 bouyer * DESCRIPTION: Check for a valid ACPI character. Must be one of:
736 1.3.2.2 bouyer * 1) Upper case alpha
737 1.3.2.2 bouyer * 2) numeric
738 1.3.2.2 bouyer * 3) underscore
739 1.3.2.2 bouyer *
740 1.3.2.2 bouyer * We allow a '!' as the last character because of the ASF! table
741 1.3.2.2 bouyer *
742 1.3.2.2 bouyer ******************************************************************************/
743 1.3.2.2 bouyer
744 1.3.2.2 bouyer BOOLEAN
745 1.3.2.2 bouyer AcpiUtValidAcpiChar (
746 1.3.2.2 bouyer char Character,
747 1.3.2.2 bouyer UINT32 Position)
748 1.3.2.2 bouyer {
749 1.3.2.2 bouyer
750 1.3.2.2 bouyer if (!((Character >= 'A' && Character <= 'Z') ||
751 1.3.2.2 bouyer (Character >= '0' && Character <= '9') ||
752 1.3.2.2 bouyer (Character == '_')))
753 1.3.2.2 bouyer {
754 1.3.2.2 bouyer /* Allow a '!' in the last position */
755 1.3.2.2 bouyer
756 1.3.2.2 bouyer if (Character == '!' && Position == 3)
757 1.3.2.2 bouyer {
758 1.3.2.2 bouyer return (TRUE);
759 1.3.2.2 bouyer }
760 1.3.2.2 bouyer
761 1.3.2.2 bouyer return (FALSE);
762 1.3.2.2 bouyer }
763 1.3.2.2 bouyer
764 1.3.2.2 bouyer return (TRUE);
765 1.3.2.2 bouyer }
766 1.3.2.2 bouyer
767 1.3.2.2 bouyer
768 1.3.2.2 bouyer /*******************************************************************************
769 1.3.2.2 bouyer *
770 1.3.2.2 bouyer * FUNCTION: AcpiUtValidAcpiName
771 1.3.2.2 bouyer *
772 1.3.2.2 bouyer * PARAMETERS: Name - The name to be examined
773 1.3.2.2 bouyer *
774 1.3.2.2 bouyer * RETURN: TRUE if the name is valid, FALSE otherwise
775 1.3.2.2 bouyer *
776 1.3.2.2 bouyer * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
777 1.3.2.2 bouyer * 1) Upper case alpha
778 1.3.2.2 bouyer * 2) numeric
779 1.3.2.2 bouyer * 3) underscore
780 1.3.2.2 bouyer *
781 1.3.2.2 bouyer ******************************************************************************/
782 1.3.2.2 bouyer
783 1.3.2.2 bouyer BOOLEAN
784 1.3.2.2 bouyer AcpiUtValidAcpiName (
785 1.3.2.2 bouyer UINT32 Name)
786 1.3.2.2 bouyer {
787 1.3.2.2 bouyer UINT32 i;
788 1.3.2.2 bouyer
789 1.3.2.2 bouyer
790 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
791 1.3.2.2 bouyer
792 1.3.2.2 bouyer
793 1.3.2.2 bouyer for (i = 0; i < ACPI_NAME_SIZE; i++)
794 1.3.2.2 bouyer {
795 1.3.2.2 bouyer if (!AcpiUtValidAcpiChar ((ACPI_CAST_PTR (char, &Name))[i], i))
796 1.3.2.2 bouyer {
797 1.3.2.2 bouyer return (FALSE);
798 1.3.2.2 bouyer }
799 1.3.2.2 bouyer }
800 1.3.2.2 bouyer
801 1.3.2.2 bouyer return (TRUE);
802 1.3.2.2 bouyer }
803 1.3.2.2 bouyer
804 1.3.2.2 bouyer
805 1.3.2.2 bouyer /*******************************************************************************
806 1.3.2.2 bouyer *
807 1.3.2.2 bouyer * FUNCTION: AcpiUtRepairName
808 1.3.2.2 bouyer *
809 1.3.2.2 bouyer * PARAMETERS: Name - The ACPI name to be repaired
810 1.3.2.2 bouyer *
811 1.3.2.2 bouyer * RETURN: Repaired version of the name
812 1.3.2.2 bouyer *
813 1.3.2.2 bouyer * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
814 1.3.2.2 bouyer * return the new name. NOTE: the Name parameter must reside in
815 1.3.2.2 bouyer * read/write memory, cannot be a const.
816 1.3.2.2 bouyer *
817 1.3.2.2 bouyer * An ACPI Name must consist of valid ACPI characters. We will repair the name
818 1.3.2.2 bouyer * if necessary because we don't want to abort because of this, but we want
819 1.3.2.2 bouyer * all namespace names to be printable. A warning message is appropriate.
820 1.3.2.2 bouyer *
821 1.3.2.2 bouyer * This issue came up because there are in fact machines that exhibit
822 1.3.2.2 bouyer * this problem, and we want to be able to enable ACPI support for them,
823 1.3.2.2 bouyer * even though there are a few bad names.
824 1.3.2.2 bouyer *
825 1.3.2.2 bouyer ******************************************************************************/
826 1.3.2.2 bouyer
827 1.3.2.2 bouyer void
828 1.3.2.2 bouyer AcpiUtRepairName (
829 1.3.2.2 bouyer char *Name)
830 1.3.2.2 bouyer {
831 1.3.2.2 bouyer UINT32 i;
832 1.3.2.2 bouyer BOOLEAN FoundBadChar = FALSE;
833 1.3.2.2 bouyer
834 1.3.2.2 bouyer
835 1.3.2.2 bouyer ACPI_FUNCTION_NAME (UtRepairName);
836 1.3.2.2 bouyer
837 1.3.2.2 bouyer
838 1.3.2.2 bouyer /* Check each character in the name */
839 1.3.2.2 bouyer
840 1.3.2.2 bouyer for (i = 0; i < ACPI_NAME_SIZE; i++)
841 1.3.2.2 bouyer {
842 1.3.2.2 bouyer if (AcpiUtValidAcpiChar (Name[i], i))
843 1.3.2.2 bouyer {
844 1.3.2.2 bouyer continue;
845 1.3.2.2 bouyer }
846 1.3.2.2 bouyer
847 1.3.2.2 bouyer /*
848 1.3.2.2 bouyer * Replace a bad character with something printable, yet technically
849 1.3.2.2 bouyer * still invalid. This prevents any collisions with existing "good"
850 1.3.2.2 bouyer * names in the namespace.
851 1.3.2.2 bouyer */
852 1.3.2.2 bouyer Name[i] = '*';
853 1.3.2.2 bouyer FoundBadChar = TRUE;
854 1.3.2.2 bouyer }
855 1.3.2.2 bouyer
856 1.3.2.2 bouyer if (FoundBadChar)
857 1.3.2.2 bouyer {
858 1.3.2.2 bouyer /* Report warning only if in strict mode or debug mode */
859 1.3.2.2 bouyer
860 1.3.2.2 bouyer if (!AcpiGbl_EnableInterpreterSlack)
861 1.3.2.2 bouyer {
862 1.3.2.2 bouyer ACPI_WARNING ((AE_INFO,
863 1.3.2.2 bouyer "Found bad character(s) in name, repaired: [%4.4s]\n", Name));
864 1.3.2.2 bouyer }
865 1.3.2.2 bouyer else
866 1.3.2.2 bouyer {
867 1.3.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
868 1.3.2.2 bouyer "Found bad character(s) in name, repaired: [%4.4s]\n", Name));
869 1.3.2.2 bouyer }
870 1.3.2.2 bouyer }
871 1.3.2.2 bouyer }
872 1.3.2.2 bouyer
873 1.3.2.2 bouyer
874 1.3.2.2 bouyer /*******************************************************************************
875 1.3.2.2 bouyer *
876 1.3.2.2 bouyer * FUNCTION: AcpiUtStrtoul64
877 1.3.2.2 bouyer *
878 1.3.2.2 bouyer * PARAMETERS: String - Null terminated string
879 1.3.2.2 bouyer * Base - Radix of the string: 16 or ACPI_ANY_BASE;
880 1.3.2.2 bouyer * ACPI_ANY_BASE means 'in behalf of ToInteger'
881 1.3.2.2 bouyer * RetInteger - Where the converted integer is returned
882 1.3.2.2 bouyer *
883 1.3.2.2 bouyer * RETURN: Status and Converted value
884 1.3.2.2 bouyer *
885 1.3.2.2 bouyer * DESCRIPTION: Convert a string into an unsigned value. Performs either a
886 1.3.2.2 bouyer * 32-bit or 64-bit conversion, depending on the current mode
887 1.3.2.2 bouyer * of the interpreter.
888 1.3.2.2 bouyer * NOTE: Does not support Octal strings, not needed.
889 1.3.2.2 bouyer *
890 1.3.2.2 bouyer ******************************************************************************/
891 1.3.2.2 bouyer
892 1.3.2.2 bouyer ACPI_STATUS
893 1.3.2.2 bouyer AcpiUtStrtoul64 (
894 1.3.2.2 bouyer char *String,
895 1.3.2.2 bouyer UINT32 Base,
896 1.3.2.2 bouyer UINT64 *RetInteger)
897 1.3.2.2 bouyer {
898 1.3.2.2 bouyer UINT32 ThisDigit = 0;
899 1.3.2.2 bouyer UINT64 ReturnValue = 0;
900 1.3.2.2 bouyer UINT64 Quotient;
901 1.3.2.2 bouyer UINT64 Dividend;
902 1.3.2.2 bouyer UINT32 ToIntegerOp = (Base == ACPI_ANY_BASE);
903 1.3.2.2 bouyer UINT32 Mode32 = (AcpiGbl_IntegerByteWidth == 4);
904 1.3.2.2 bouyer UINT8 ValidDigits = 0;
905 1.3.2.2 bouyer UINT8 SignOf0x = 0;
906 1.3.2.2 bouyer UINT8 Term = 0;
907 1.3.2.2 bouyer
908 1.3.2.2 bouyer
909 1.3.2.2 bouyer ACPI_FUNCTION_TRACE_STR (UtStroul64, String);
910 1.3.2.2 bouyer
911 1.3.2.2 bouyer
912 1.3.2.2 bouyer switch (Base)
913 1.3.2.2 bouyer {
914 1.3.2.2 bouyer case ACPI_ANY_BASE:
915 1.3.2.2 bouyer case 16:
916 1.3.2.2 bouyer break;
917 1.3.2.2 bouyer
918 1.3.2.2 bouyer default:
919 1.3.2.2 bouyer /* Invalid Base */
920 1.3.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
921 1.3.2.2 bouyer }
922 1.3.2.2 bouyer
923 1.3.2.2 bouyer if (!String)
924 1.3.2.2 bouyer {
925 1.3.2.2 bouyer goto ErrorExit;
926 1.3.2.2 bouyer }
927 1.3.2.2 bouyer
928 1.3.2.2 bouyer /* Skip over any white space in the buffer */
929 1.3.2.2 bouyer
930 1.3.2.2 bouyer while ((*String) && (ACPI_IS_SPACE (*String) || *String == '\t'))
931 1.3.2.2 bouyer {
932 1.3.2.2 bouyer String++;
933 1.3.2.2 bouyer }
934 1.3.2.2 bouyer
935 1.3.2.2 bouyer if (ToIntegerOp)
936 1.3.2.2 bouyer {
937 1.3.2.2 bouyer /*
938 1.3.2.2 bouyer * Base equal to ACPI_ANY_BASE means 'ToInteger operation case'.
939 1.3.2.2 bouyer * We need to determine if it is decimal or hexadecimal.
940 1.3.2.2 bouyer */
941 1.3.2.2 bouyer if ((*String == '0') && (ACPI_TOLOWER (*(String + 1)) == 'x'))
942 1.3.2.2 bouyer {
943 1.3.2.2 bouyer SignOf0x = 1;
944 1.3.2.2 bouyer Base = 16;
945 1.3.2.2 bouyer
946 1.3.2.2 bouyer /* Skip over the leading '0x' */
947 1.3.2.2 bouyer String += 2;
948 1.3.2.2 bouyer }
949 1.3.2.2 bouyer else
950 1.3.2.2 bouyer {
951 1.3.2.2 bouyer Base = 10;
952 1.3.2.2 bouyer }
953 1.3.2.2 bouyer }
954 1.3.2.2 bouyer
955 1.3.2.2 bouyer /* Any string left? Check that '0x' is not followed by white space. */
956 1.3.2.2 bouyer
957 1.3.2.2 bouyer if (!(*String) || ACPI_IS_SPACE (*String) || *String == '\t')
958 1.3.2.2 bouyer {
959 1.3.2.2 bouyer if (ToIntegerOp)
960 1.3.2.2 bouyer {
961 1.3.2.2 bouyer goto ErrorExit;
962 1.3.2.2 bouyer }
963 1.3.2.2 bouyer else
964 1.3.2.2 bouyer {
965 1.3.2.2 bouyer goto AllDone;
966 1.3.2.2 bouyer }
967 1.3.2.2 bouyer }
968 1.3.2.2 bouyer
969 1.3.2.2 bouyer /*
970 1.3.2.2 bouyer * Perform a 32-bit or 64-bit conversion, depending upon the current
971 1.3.2.2 bouyer * execution mode of the interpreter
972 1.3.2.2 bouyer */
973 1.3.2.2 bouyer Dividend = (Mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
974 1.3.2.2 bouyer
975 1.3.2.2 bouyer /* Main loop: convert the string to a 32- or 64-bit integer */
976 1.3.2.2 bouyer
977 1.3.2.2 bouyer while (*String)
978 1.3.2.2 bouyer {
979 1.3.2.2 bouyer if (ACPI_IS_DIGIT (*String))
980 1.3.2.2 bouyer {
981 1.3.2.2 bouyer /* Convert ASCII 0-9 to Decimal value */
982 1.3.2.2 bouyer
983 1.3.2.2 bouyer ThisDigit = ((UINT8) *String) - '0';
984 1.3.2.2 bouyer }
985 1.3.2.2 bouyer else if (Base == 10)
986 1.3.2.2 bouyer {
987 1.3.2.2 bouyer /* Digit is out of range; possible in ToInteger case only */
988 1.3.2.2 bouyer
989 1.3.2.2 bouyer Term = 1;
990 1.3.2.2 bouyer }
991 1.3.2.2 bouyer else
992 1.3.2.2 bouyer {
993 1.3.2.2 bouyer ThisDigit = (UINT8) ACPI_TOUPPER (*String);
994 1.3.2.2 bouyer if (ACPI_IS_XDIGIT ((char) ThisDigit))
995 1.3.2.2 bouyer {
996 1.3.2.2 bouyer /* Convert ASCII Hex char to value */
997 1.3.2.2 bouyer
998 1.3.2.2 bouyer ThisDigit = ThisDigit - 'A' + 10;
999 1.3.2.2 bouyer }
1000 1.3.2.2 bouyer else
1001 1.3.2.2 bouyer {
1002 1.3.2.2 bouyer Term = 1;
1003 1.3.2.2 bouyer }
1004 1.3.2.2 bouyer }
1005 1.3.2.2 bouyer
1006 1.3.2.2 bouyer if (Term)
1007 1.3.2.2 bouyer {
1008 1.3.2.2 bouyer if (ToIntegerOp)
1009 1.3.2.2 bouyer {
1010 1.3.2.2 bouyer goto ErrorExit;
1011 1.3.2.2 bouyer }
1012 1.3.2.2 bouyer else
1013 1.3.2.2 bouyer {
1014 1.3.2.2 bouyer break;
1015 1.3.2.2 bouyer }
1016 1.3.2.2 bouyer }
1017 1.3.2.2 bouyer else if ((ValidDigits == 0) && (ThisDigit == 0) && !SignOf0x)
1018 1.3.2.2 bouyer {
1019 1.3.2.2 bouyer /* Skip zeros */
1020 1.3.2.2 bouyer String++;
1021 1.3.2.2 bouyer continue;
1022 1.3.2.2 bouyer }
1023 1.3.2.2 bouyer
1024 1.3.2.2 bouyer ValidDigits++;
1025 1.3.2.2 bouyer
1026 1.3.2.2 bouyer if (SignOf0x && ((ValidDigits > 16) || ((ValidDigits > 8) && Mode32)))
1027 1.3.2.2 bouyer {
1028 1.3.2.2 bouyer /*
1029 1.3.2.2 bouyer * This is ToInteger operation case.
1030 1.3.2.2 bouyer * No any restrictions for string-to-integer conversion,
1031 1.3.2.2 bouyer * see ACPI spec.
1032 1.3.2.2 bouyer */
1033 1.3.2.2 bouyer goto ErrorExit;
1034 1.3.2.2 bouyer }
1035 1.3.2.2 bouyer
1036 1.3.2.2 bouyer /* Divide the digit into the correct position */
1037 1.3.2.2 bouyer
1038 1.3.2.2 bouyer (void) AcpiUtShortDivide ((Dividend - (UINT64) ThisDigit),
1039 1.3.2.2 bouyer Base, &Quotient, NULL);
1040 1.3.2.2 bouyer
1041 1.3.2.2 bouyer if (ReturnValue > Quotient)
1042 1.3.2.2 bouyer {
1043 1.3.2.2 bouyer if (ToIntegerOp)
1044 1.3.2.2 bouyer {
1045 1.3.2.2 bouyer goto ErrorExit;
1046 1.3.2.2 bouyer }
1047 1.3.2.2 bouyer else
1048 1.3.2.2 bouyer {
1049 1.3.2.2 bouyer break;
1050 1.3.2.2 bouyer }
1051 1.3.2.2 bouyer }
1052 1.3.2.2 bouyer
1053 1.3.2.2 bouyer ReturnValue *= Base;
1054 1.3.2.2 bouyer ReturnValue += ThisDigit;
1055 1.3.2.2 bouyer String++;
1056 1.3.2.2 bouyer }
1057 1.3.2.2 bouyer
1058 1.3.2.2 bouyer /* All done, normal exit */
1059 1.3.2.2 bouyer
1060 1.3.2.2 bouyer AllDone:
1061 1.3.2.2 bouyer
1062 1.3.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
1063 1.3.2.2 bouyer ACPI_FORMAT_UINT64 (ReturnValue)));
1064 1.3.2.2 bouyer
1065 1.3.2.2 bouyer *RetInteger = ReturnValue;
1066 1.3.2.2 bouyer return_ACPI_STATUS (AE_OK);
1067 1.3.2.2 bouyer
1068 1.3.2.2 bouyer
1069 1.3.2.2 bouyer ErrorExit:
1070 1.3.2.2 bouyer /* Base was set/validated above */
1071 1.3.2.2 bouyer
1072 1.3.2.2 bouyer if (Base == 10)
1073 1.3.2.2 bouyer {
1074 1.3.2.2 bouyer return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT);
1075 1.3.2.2 bouyer }
1076 1.3.2.2 bouyer else
1077 1.3.2.2 bouyer {
1078 1.3.2.2 bouyer return_ACPI_STATUS (AE_BAD_HEX_CONSTANT);
1079 1.3.2.2 bouyer }
1080 1.3.2.2 bouyer }
1081 1.3.2.2 bouyer
1082 1.3.2.2 bouyer
1083 1.3.2.2 bouyer /*******************************************************************************
1084 1.3.2.2 bouyer *
1085 1.3.2.2 bouyer * FUNCTION: AcpiUtCreateUpdateStateAndPush
1086 1.3.2.2 bouyer *
1087 1.3.2.2 bouyer * PARAMETERS: Object - Object to be added to the new state
1088 1.3.2.2 bouyer * Action - Increment/Decrement
1089 1.3.2.2 bouyer * StateList - List the state will be added to
1090 1.3.2.2 bouyer *
1091 1.3.2.2 bouyer * RETURN: Status
1092 1.3.2.2 bouyer *
1093 1.3.2.2 bouyer * DESCRIPTION: Create a new state and push it
1094 1.3.2.2 bouyer *
1095 1.3.2.2 bouyer ******************************************************************************/
1096 1.3.2.2 bouyer
1097 1.3.2.2 bouyer ACPI_STATUS
1098 1.3.2.2 bouyer AcpiUtCreateUpdateStateAndPush (
1099 1.3.2.2 bouyer ACPI_OPERAND_OBJECT *Object,
1100 1.3.2.2 bouyer UINT16 Action,
1101 1.3.2.2 bouyer ACPI_GENERIC_STATE **StateList)
1102 1.3.2.2 bouyer {
1103 1.3.2.2 bouyer ACPI_GENERIC_STATE *State;
1104 1.3.2.2 bouyer
1105 1.3.2.2 bouyer
1106 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
1107 1.3.2.2 bouyer
1108 1.3.2.2 bouyer
1109 1.3.2.2 bouyer /* Ignore null objects; these are expected */
1110 1.3.2.2 bouyer
1111 1.3.2.2 bouyer if (!Object)
1112 1.3.2.2 bouyer {
1113 1.3.2.2 bouyer return (AE_OK);
1114 1.3.2.2 bouyer }
1115 1.3.2.2 bouyer
1116 1.3.2.2 bouyer State = AcpiUtCreateUpdateState (Object, Action);
1117 1.3.2.2 bouyer if (!State)
1118 1.3.2.2 bouyer {
1119 1.3.2.2 bouyer return (AE_NO_MEMORY);
1120 1.3.2.2 bouyer }
1121 1.3.2.2 bouyer
1122 1.3.2.2 bouyer AcpiUtPushGenericState (StateList, State);
1123 1.3.2.2 bouyer return (AE_OK);
1124 1.3.2.2 bouyer }
1125 1.3.2.2 bouyer
1126 1.3.2.2 bouyer
1127 1.3.2.2 bouyer /*******************************************************************************
1128 1.3.2.2 bouyer *
1129 1.3.2.2 bouyer * FUNCTION: AcpiUtWalkPackageTree
1130 1.3.2.2 bouyer *
1131 1.3.2.2 bouyer * PARAMETERS: SourceObject - The package to walk
1132 1.3.2.2 bouyer * TargetObject - Target object (if package is being copied)
1133 1.3.2.2 bouyer * WalkCallback - Called once for each package element
1134 1.3.2.2 bouyer * Context - Passed to the callback function
1135 1.3.2.2 bouyer *
1136 1.3.2.2 bouyer * RETURN: Status
1137 1.3.2.2 bouyer *
1138 1.3.2.2 bouyer * DESCRIPTION: Walk through a package
1139 1.3.2.2 bouyer *
1140 1.3.2.2 bouyer ******************************************************************************/
1141 1.3.2.2 bouyer
1142 1.3.2.2 bouyer ACPI_STATUS
1143 1.3.2.2 bouyer AcpiUtWalkPackageTree (
1144 1.3.2.2 bouyer ACPI_OPERAND_OBJECT *SourceObject,
1145 1.3.2.2 bouyer void *TargetObject,
1146 1.3.2.2 bouyer ACPI_PKG_CALLBACK WalkCallback,
1147 1.3.2.2 bouyer void *Context)
1148 1.3.2.2 bouyer {
1149 1.3.2.2 bouyer ACPI_STATUS Status = AE_OK;
1150 1.3.2.2 bouyer ACPI_GENERIC_STATE *StateList = NULL;
1151 1.3.2.2 bouyer ACPI_GENERIC_STATE *State;
1152 1.3.2.2 bouyer UINT32 ThisIndex;
1153 1.3.2.2 bouyer ACPI_OPERAND_OBJECT *ThisSourceObj;
1154 1.3.2.2 bouyer
1155 1.3.2.2 bouyer
1156 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (UtWalkPackageTree);
1157 1.3.2.2 bouyer
1158 1.3.2.2 bouyer
1159 1.3.2.2 bouyer State = AcpiUtCreatePkgState (SourceObject, TargetObject, 0);
1160 1.3.2.2 bouyer if (!State)
1161 1.3.2.2 bouyer {
1162 1.3.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
1163 1.3.2.2 bouyer }
1164 1.3.2.2 bouyer
1165 1.3.2.2 bouyer while (State)
1166 1.3.2.2 bouyer {
1167 1.3.2.2 bouyer /* Get one element of the package */
1168 1.3.2.2 bouyer
1169 1.3.2.2 bouyer ThisIndex = State->Pkg.Index;
1170 1.3.2.2 bouyer ThisSourceObj = (ACPI_OPERAND_OBJECT *)
1171 1.3.2.2 bouyer State->Pkg.SourceObject->Package.Elements[ThisIndex];
1172 1.3.2.2 bouyer
1173 1.3.2.2 bouyer /*
1174 1.3.2.2 bouyer * Check for:
1175 1.3.2.2 bouyer * 1) An uninitialized package element. It is completely
1176 1.3.2.2 bouyer * legal to declare a package and leave it uninitialized
1177 1.3.2.2 bouyer * 2) Not an internal object - can be a namespace node instead
1178 1.3.2.2 bouyer * 3) Any type other than a package. Packages are handled in else
1179 1.3.2.2 bouyer * case below.
1180 1.3.2.2 bouyer */
1181 1.3.2.2 bouyer if ((!ThisSourceObj) ||
1182 1.3.2.2 bouyer (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj) != ACPI_DESC_TYPE_OPERAND) ||
1183 1.3.2.2 bouyer (ThisSourceObj->Common.Type != ACPI_TYPE_PACKAGE))
1184 1.3.2.2 bouyer {
1185 1.3.2.2 bouyer Status = WalkCallback (ACPI_COPY_TYPE_SIMPLE, ThisSourceObj,
1186 1.3.2.2 bouyer State, Context);
1187 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
1188 1.3.2.2 bouyer {
1189 1.3.2.2 bouyer return_ACPI_STATUS (Status);
1190 1.3.2.2 bouyer }
1191 1.3.2.2 bouyer
1192 1.3.2.2 bouyer State->Pkg.Index++;
1193 1.3.2.2 bouyer while (State->Pkg.Index >= State->Pkg.SourceObject->Package.Count)
1194 1.3.2.2 bouyer {
1195 1.3.2.2 bouyer /*
1196 1.3.2.2 bouyer * We've handled all of the objects at this level, This means
1197 1.3.2.2 bouyer * that we have just completed a package. That package may
1198 1.3.2.2 bouyer * have contained one or more packages itself.
1199 1.3.2.2 bouyer *
1200 1.3.2.2 bouyer * Delete this state and pop the previous state (package).
1201 1.3.2.2 bouyer */
1202 1.3.2.2 bouyer AcpiUtDeleteGenericState (State);
1203 1.3.2.2 bouyer State = AcpiUtPopGenericState (&StateList);
1204 1.3.2.2 bouyer
1205 1.3.2.2 bouyer /* Finished when there are no more states */
1206 1.3.2.2 bouyer
1207 1.3.2.2 bouyer if (!State)
1208 1.3.2.2 bouyer {
1209 1.3.2.2 bouyer /*
1210 1.3.2.2 bouyer * We have handled all of the objects in the top level
1211 1.3.2.2 bouyer * package just add the length of the package objects
1212 1.3.2.2 bouyer * and exit
1213 1.3.2.2 bouyer */
1214 1.3.2.2 bouyer return_ACPI_STATUS (AE_OK);
1215 1.3.2.2 bouyer }
1216 1.3.2.2 bouyer
1217 1.3.2.2 bouyer /*
1218 1.3.2.2 bouyer * Go back up a level and move the index past the just
1219 1.3.2.2 bouyer * completed package object.
1220 1.3.2.2 bouyer */
1221 1.3.2.2 bouyer State->Pkg.Index++;
1222 1.3.2.2 bouyer }
1223 1.3.2.2 bouyer }
1224 1.3.2.2 bouyer else
1225 1.3.2.2 bouyer {
1226 1.3.2.2 bouyer /* This is a subobject of type package */
1227 1.3.2.2 bouyer
1228 1.3.2.2 bouyer Status = WalkCallback (ACPI_COPY_TYPE_PACKAGE, ThisSourceObj,
1229 1.3.2.2 bouyer State, Context);
1230 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
1231 1.3.2.2 bouyer {
1232 1.3.2.2 bouyer return_ACPI_STATUS (Status);
1233 1.3.2.2 bouyer }
1234 1.3.2.2 bouyer
1235 1.3.2.2 bouyer /*
1236 1.3.2.2 bouyer * Push the current state and create a new one
1237 1.3.2.2 bouyer * The callback above returned a new target package object.
1238 1.3.2.2 bouyer */
1239 1.3.2.2 bouyer AcpiUtPushGenericState (&StateList, State);
1240 1.3.2.2 bouyer State = AcpiUtCreatePkgState (ThisSourceObj,
1241 1.3.2.2 bouyer State->Pkg.ThisTargetObj, 0);
1242 1.3.2.2 bouyer if (!State)
1243 1.3.2.2 bouyer {
1244 1.3.2.2 bouyer /* Free any stacked Update State objects */
1245 1.3.2.2 bouyer
1246 1.3.2.2 bouyer while (StateList)
1247 1.3.2.2 bouyer {
1248 1.3.2.2 bouyer State = AcpiUtPopGenericState (&StateList);
1249 1.3.2.2 bouyer AcpiUtDeleteGenericState (State);
1250 1.3.2.2 bouyer }
1251 1.3.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
1252 1.3.2.2 bouyer }
1253 1.3.2.2 bouyer }
1254 1.3.2.2 bouyer }
1255 1.3.2.2 bouyer
1256 1.3.2.2 bouyer /* We should never get here */
1257 1.3.2.2 bouyer
1258 1.3.2.2 bouyer return_ACPI_STATUS (AE_AML_INTERNAL);
1259 1.3.2.2 bouyer }
1260 1.3.2.2 bouyer
1261 1.3.2.2 bouyer
1262