1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: exutils - interpreter/scanner utilities
4433d6423SLionel Sambuc *
5433d6423SLionel Sambuc *****************************************************************************/
6433d6423SLionel Sambuc
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc * All rights reserved.
10433d6423SLionel Sambuc *
11*29492bb7SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek * are met:
14*29492bb7SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek * notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek * without modification.
17*29492bb7SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek * substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek * ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek * including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek * binary redistribution.
22*29492bb7SDavid van Moolenbroek * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek * of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek * from this software without specific prior written permission.
25433d6423SLionel Sambuc *
26*29492bb7SDavid van Moolenbroek * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek * Software Foundation.
29433d6423SLionel Sambuc *
30*29492bb7SDavid van Moolenbroek * NO WARRANTY
31*29492bb7SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek */
43433d6423SLionel Sambuc
44433d6423SLionel Sambuc /*
45433d6423SLionel Sambuc * DEFINE_AML_GLOBALS is tested in amlcode.h
46433d6423SLionel Sambuc * to determine whether certain global names should be "defined" or only
47433d6423SLionel Sambuc * "declared" in the current compilation. This enhances maintainability
48433d6423SLionel Sambuc * by enabling a single header file to embody all knowledge of the names
49433d6423SLionel Sambuc * in question.
50433d6423SLionel Sambuc *
51433d6423SLionel Sambuc * Exactly one module of any executable should #define DEFINE_GLOBALS
52433d6423SLionel Sambuc * before #including the header files which use this convention. The
53433d6423SLionel Sambuc * names in question will be defined and initialized in that module,
54433d6423SLionel Sambuc * and declared as extern in all other modules which #include those
55433d6423SLionel Sambuc * header files.
56433d6423SLionel Sambuc */
57433d6423SLionel Sambuc
58433d6423SLionel Sambuc #define DEFINE_AML_GLOBALS
59433d6423SLionel Sambuc
60433d6423SLionel Sambuc #include "acpi.h"
61433d6423SLionel Sambuc #include "accommon.h"
62433d6423SLionel Sambuc #include "acinterp.h"
63433d6423SLionel Sambuc #include "amlcode.h"
64433d6423SLionel Sambuc
65433d6423SLionel Sambuc #define _COMPONENT ACPI_EXECUTER
66433d6423SLionel Sambuc ACPI_MODULE_NAME ("exutils")
67433d6423SLionel Sambuc
68433d6423SLionel Sambuc /* Local prototypes */
69433d6423SLionel Sambuc
70433d6423SLionel Sambuc static UINT32
71433d6423SLionel Sambuc AcpiExDigitsNeeded (
72433d6423SLionel Sambuc UINT64 Value,
73433d6423SLionel Sambuc UINT32 Base);
74433d6423SLionel Sambuc
75433d6423SLionel Sambuc
76433d6423SLionel Sambuc #ifndef ACPI_NO_METHOD_EXECUTION
77433d6423SLionel Sambuc /*******************************************************************************
78433d6423SLionel Sambuc *
79433d6423SLionel Sambuc * FUNCTION: AcpiExEnterInterpreter
80433d6423SLionel Sambuc *
81433d6423SLionel Sambuc * PARAMETERS: None
82433d6423SLionel Sambuc *
83433d6423SLionel Sambuc * RETURN: None
84433d6423SLionel Sambuc *
85433d6423SLionel Sambuc * DESCRIPTION: Enter the interpreter execution region. Failure to enter
86433d6423SLionel Sambuc * the interpreter region is a fatal system error. Used in
87433d6423SLionel Sambuc * conjunction with ExitInterpreter.
88433d6423SLionel Sambuc *
89433d6423SLionel Sambuc ******************************************************************************/
90433d6423SLionel Sambuc
91433d6423SLionel Sambuc void
AcpiExEnterInterpreter(void)92433d6423SLionel Sambuc AcpiExEnterInterpreter (
93433d6423SLionel Sambuc void)
94433d6423SLionel Sambuc {
95433d6423SLionel Sambuc ACPI_STATUS Status;
96433d6423SLionel Sambuc
97433d6423SLionel Sambuc
98433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (ExEnterInterpreter);
99433d6423SLionel Sambuc
100433d6423SLionel Sambuc
101433d6423SLionel Sambuc Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
102433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
103433d6423SLionel Sambuc {
104433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Could not acquire AML Interpreter mutex"));
105433d6423SLionel Sambuc }
106433d6423SLionel Sambuc
107433d6423SLionel Sambuc return_VOID;
108433d6423SLionel Sambuc }
109433d6423SLionel Sambuc
110433d6423SLionel Sambuc
111433d6423SLionel Sambuc /*******************************************************************************
112433d6423SLionel Sambuc *
113433d6423SLionel Sambuc * FUNCTION: AcpiExExitInterpreter
114433d6423SLionel Sambuc *
115433d6423SLionel Sambuc * PARAMETERS: None
116433d6423SLionel Sambuc *
117433d6423SLionel Sambuc * RETURN: None
118433d6423SLionel Sambuc *
119433d6423SLionel Sambuc * DESCRIPTION: Exit the interpreter execution region. This is the top level
120433d6423SLionel Sambuc * routine used to exit the interpreter when all processing has
121*29492bb7SDavid van Moolenbroek * been completed, or when the method blocks.
122*29492bb7SDavid van Moolenbroek *
123*29492bb7SDavid van Moolenbroek * Cases where the interpreter is unlocked internally:
124*29492bb7SDavid van Moolenbroek * 1) Method will be blocked on a Sleep() AML opcode
125*29492bb7SDavid van Moolenbroek * 2) Method will be blocked on an Acquire() AML opcode
126*29492bb7SDavid van Moolenbroek * 3) Method will be blocked on a Wait() AML opcode
127*29492bb7SDavid van Moolenbroek * 4) Method will be blocked to acquire the global lock
128*29492bb7SDavid van Moolenbroek * 5) Method will be blocked waiting to execute a serialized control
129*29492bb7SDavid van Moolenbroek * method that is currently executing
130*29492bb7SDavid van Moolenbroek * 6) About to invoke a user-installed opregion handler
131433d6423SLionel Sambuc *
132433d6423SLionel Sambuc ******************************************************************************/
133433d6423SLionel Sambuc
134433d6423SLionel Sambuc void
AcpiExExitInterpreter(void)135433d6423SLionel Sambuc AcpiExExitInterpreter (
136433d6423SLionel Sambuc void)
137433d6423SLionel Sambuc {
138433d6423SLionel Sambuc ACPI_STATUS Status;
139433d6423SLionel Sambuc
140433d6423SLionel Sambuc
141433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (ExExitInterpreter);
142433d6423SLionel Sambuc
143433d6423SLionel Sambuc
144433d6423SLionel Sambuc Status = AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
145433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
146433d6423SLionel Sambuc {
147433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Could not release AML Interpreter mutex"));
148433d6423SLionel Sambuc }
149433d6423SLionel Sambuc
150433d6423SLionel Sambuc return_VOID;
151433d6423SLionel Sambuc }
152433d6423SLionel Sambuc
153433d6423SLionel Sambuc
154433d6423SLionel Sambuc /*******************************************************************************
155433d6423SLionel Sambuc *
156433d6423SLionel Sambuc * FUNCTION: AcpiExTruncateFor32bitTable
157433d6423SLionel Sambuc *
158433d6423SLionel Sambuc * PARAMETERS: ObjDesc - Object to be truncated
159433d6423SLionel Sambuc *
160*29492bb7SDavid van Moolenbroek * RETURN: TRUE if a truncation was performed, FALSE otherwise.
161433d6423SLionel Sambuc *
162433d6423SLionel Sambuc * DESCRIPTION: Truncate an ACPI Integer to 32 bits if the execution mode is
163433d6423SLionel Sambuc * 32-bit, as determined by the revision of the DSDT.
164433d6423SLionel Sambuc *
165433d6423SLionel Sambuc ******************************************************************************/
166433d6423SLionel Sambuc
167*29492bb7SDavid van Moolenbroek BOOLEAN
AcpiExTruncateFor32bitTable(ACPI_OPERAND_OBJECT * ObjDesc)168433d6423SLionel Sambuc AcpiExTruncateFor32bitTable (
169433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ObjDesc)
170433d6423SLionel Sambuc {
171433d6423SLionel Sambuc
172433d6423SLionel Sambuc ACPI_FUNCTION_ENTRY ();
173433d6423SLionel Sambuc
174433d6423SLionel Sambuc
175433d6423SLionel Sambuc /*
176433d6423SLionel Sambuc * Object must be a valid number and we must be executing
177*29492bb7SDavid van Moolenbroek * a control method. Object could be NS node for AML_INT_NAMEPATH_OP.
178433d6423SLionel Sambuc */
179433d6423SLionel Sambuc if ((!ObjDesc) ||
180433d6423SLionel Sambuc (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND) ||
181433d6423SLionel Sambuc (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
182433d6423SLionel Sambuc {
183*29492bb7SDavid van Moolenbroek return (FALSE);
184433d6423SLionel Sambuc }
185433d6423SLionel Sambuc
186*29492bb7SDavid van Moolenbroek if ((AcpiGbl_IntegerByteWidth == 4) &&
187*29492bb7SDavid van Moolenbroek (ObjDesc->Integer.Value > (UINT64) ACPI_UINT32_MAX))
188433d6423SLionel Sambuc {
189433d6423SLionel Sambuc /*
190*29492bb7SDavid van Moolenbroek * We are executing in a 32-bit ACPI table.
191433d6423SLionel Sambuc * Truncate the value to 32 bits by zeroing out the upper 32-bit field
192433d6423SLionel Sambuc */
193433d6423SLionel Sambuc ObjDesc->Integer.Value &= (UINT64) ACPI_UINT32_MAX;
194*29492bb7SDavid van Moolenbroek return (TRUE);
195433d6423SLionel Sambuc }
196*29492bb7SDavid van Moolenbroek
197*29492bb7SDavid van Moolenbroek return (FALSE);
198433d6423SLionel Sambuc }
199433d6423SLionel Sambuc
200433d6423SLionel Sambuc
201433d6423SLionel Sambuc /*******************************************************************************
202433d6423SLionel Sambuc *
203433d6423SLionel Sambuc * FUNCTION: AcpiExAcquireGlobalLock
204433d6423SLionel Sambuc *
205433d6423SLionel Sambuc * PARAMETERS: FieldFlags - Flags with Lock rule:
206433d6423SLionel Sambuc * AlwaysLock or NeverLock
207433d6423SLionel Sambuc *
208433d6423SLionel Sambuc * RETURN: None
209433d6423SLionel Sambuc *
210433d6423SLionel Sambuc * DESCRIPTION: Obtain the ACPI hardware Global Lock, only if the field
211433d6423SLionel Sambuc * flags specifiy that it is to be obtained before field access.
212433d6423SLionel Sambuc *
213433d6423SLionel Sambuc ******************************************************************************/
214433d6423SLionel Sambuc
215433d6423SLionel Sambuc void
AcpiExAcquireGlobalLock(UINT32 FieldFlags)216433d6423SLionel Sambuc AcpiExAcquireGlobalLock (
217433d6423SLionel Sambuc UINT32 FieldFlags)
218433d6423SLionel Sambuc {
219433d6423SLionel Sambuc ACPI_STATUS Status;
220433d6423SLionel Sambuc
221433d6423SLionel Sambuc
222433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (ExAcquireGlobalLock);
223433d6423SLionel Sambuc
224433d6423SLionel Sambuc
225433d6423SLionel Sambuc /* Only use the lock if the AlwaysLock bit is set */
226433d6423SLionel Sambuc
227433d6423SLionel Sambuc if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK))
228433d6423SLionel Sambuc {
229433d6423SLionel Sambuc return_VOID;
230433d6423SLionel Sambuc }
231433d6423SLionel Sambuc
232433d6423SLionel Sambuc /* Attempt to get the global lock, wait forever */
233433d6423SLionel Sambuc
234433d6423SLionel Sambuc Status = AcpiExAcquireMutexObject (ACPI_WAIT_FOREVER,
235433d6423SLionel Sambuc AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ());
236433d6423SLionel Sambuc
237433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
238433d6423SLionel Sambuc {
239433d6423SLionel Sambuc ACPI_EXCEPTION ((AE_INFO, Status,
240433d6423SLionel Sambuc "Could not acquire Global Lock"));
241433d6423SLionel Sambuc }
242433d6423SLionel Sambuc
243433d6423SLionel Sambuc return_VOID;
244433d6423SLionel Sambuc }
245433d6423SLionel Sambuc
246433d6423SLionel Sambuc
247433d6423SLionel Sambuc /*******************************************************************************
248433d6423SLionel Sambuc *
249433d6423SLionel Sambuc * FUNCTION: AcpiExReleaseGlobalLock
250433d6423SLionel Sambuc *
251433d6423SLionel Sambuc * PARAMETERS: FieldFlags - Flags with Lock rule:
252433d6423SLionel Sambuc * AlwaysLock or NeverLock
253433d6423SLionel Sambuc *
254433d6423SLionel Sambuc * RETURN: None
255433d6423SLionel Sambuc *
256433d6423SLionel Sambuc * DESCRIPTION: Release the ACPI hardware Global Lock
257433d6423SLionel Sambuc *
258433d6423SLionel Sambuc ******************************************************************************/
259433d6423SLionel Sambuc
260433d6423SLionel Sambuc void
AcpiExReleaseGlobalLock(UINT32 FieldFlags)261433d6423SLionel Sambuc AcpiExReleaseGlobalLock (
262433d6423SLionel Sambuc UINT32 FieldFlags)
263433d6423SLionel Sambuc {
264433d6423SLionel Sambuc ACPI_STATUS Status;
265433d6423SLionel Sambuc
266433d6423SLionel Sambuc
267433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (ExReleaseGlobalLock);
268433d6423SLionel Sambuc
269433d6423SLionel Sambuc
270433d6423SLionel Sambuc /* Only use the lock if the AlwaysLock bit is set */
271433d6423SLionel Sambuc
272433d6423SLionel Sambuc if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK))
273433d6423SLionel Sambuc {
274433d6423SLionel Sambuc return_VOID;
275433d6423SLionel Sambuc }
276433d6423SLionel Sambuc
277433d6423SLionel Sambuc /* Release the global lock */
278433d6423SLionel Sambuc
279433d6423SLionel Sambuc Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex);
280433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
281433d6423SLionel Sambuc {
282433d6423SLionel Sambuc /* Report the error, but there isn't much else we can do */
283433d6423SLionel Sambuc
284433d6423SLionel Sambuc ACPI_EXCEPTION ((AE_INFO, Status,
285433d6423SLionel Sambuc "Could not release Global Lock"));
286433d6423SLionel Sambuc }
287433d6423SLionel Sambuc
288433d6423SLionel Sambuc return_VOID;
289433d6423SLionel Sambuc }
290433d6423SLionel Sambuc
291433d6423SLionel Sambuc
292433d6423SLionel Sambuc /*******************************************************************************
293433d6423SLionel Sambuc *
294433d6423SLionel Sambuc * FUNCTION: AcpiExDigitsNeeded
295433d6423SLionel Sambuc *
296433d6423SLionel Sambuc * PARAMETERS: Value - Value to be represented
297433d6423SLionel Sambuc * Base - Base of representation
298433d6423SLionel Sambuc *
299433d6423SLionel Sambuc * RETURN: The number of digits.
300433d6423SLionel Sambuc *
301433d6423SLionel Sambuc * DESCRIPTION: Calculate the number of digits needed to represent the Value
302433d6423SLionel Sambuc * in the given Base (Radix)
303433d6423SLionel Sambuc *
304433d6423SLionel Sambuc ******************************************************************************/
305433d6423SLionel Sambuc
306433d6423SLionel Sambuc static UINT32
AcpiExDigitsNeeded(UINT64 Value,UINT32 Base)307433d6423SLionel Sambuc AcpiExDigitsNeeded (
308433d6423SLionel Sambuc UINT64 Value,
309433d6423SLionel Sambuc UINT32 Base)
310433d6423SLionel Sambuc {
311433d6423SLionel Sambuc UINT32 NumDigits;
312433d6423SLionel Sambuc UINT64 CurrentValue;
313433d6423SLionel Sambuc
314433d6423SLionel Sambuc
315433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (ExDigitsNeeded);
316433d6423SLionel Sambuc
317433d6423SLionel Sambuc
318433d6423SLionel Sambuc /* UINT64 is unsigned, so we don't worry about a '-' prefix */
319433d6423SLionel Sambuc
320433d6423SLionel Sambuc if (Value == 0)
321433d6423SLionel Sambuc {
322433d6423SLionel Sambuc return_UINT32 (1);
323433d6423SLionel Sambuc }
324433d6423SLionel Sambuc
325433d6423SLionel Sambuc CurrentValue = Value;
326433d6423SLionel Sambuc NumDigits = 0;
327433d6423SLionel Sambuc
328433d6423SLionel Sambuc /* Count the digits in the requested base */
329433d6423SLionel Sambuc
330433d6423SLionel Sambuc while (CurrentValue)
331433d6423SLionel Sambuc {
332433d6423SLionel Sambuc (void) AcpiUtShortDivide (CurrentValue, Base, &CurrentValue, NULL);
333433d6423SLionel Sambuc NumDigits++;
334433d6423SLionel Sambuc }
335433d6423SLionel Sambuc
336433d6423SLionel Sambuc return_UINT32 (NumDigits);
337433d6423SLionel Sambuc }
338433d6423SLionel Sambuc
339433d6423SLionel Sambuc
340433d6423SLionel Sambuc /*******************************************************************************
341433d6423SLionel Sambuc *
342433d6423SLionel Sambuc * FUNCTION: AcpiExEisaIdToString
343433d6423SLionel Sambuc *
344433d6423SLionel Sambuc * PARAMETERS: CompressedId - EISAID to be converted
345433d6423SLionel Sambuc * OutString - Where to put the converted string (8 bytes)
346433d6423SLionel Sambuc *
347433d6423SLionel Sambuc * RETURN: None
348433d6423SLionel Sambuc *
349433d6423SLionel Sambuc * DESCRIPTION: Convert a numeric EISAID to string representation. Return
350433d6423SLionel Sambuc * buffer must be large enough to hold the string. The string
351433d6423SLionel Sambuc * returned is always exactly of length ACPI_EISAID_STRING_SIZE
352433d6423SLionel Sambuc * (includes null terminator). The EISAID is always 32 bits.
353433d6423SLionel Sambuc *
354433d6423SLionel Sambuc ******************************************************************************/
355433d6423SLionel Sambuc
356433d6423SLionel Sambuc void
AcpiExEisaIdToString(char * OutString,UINT64 CompressedId)357433d6423SLionel Sambuc AcpiExEisaIdToString (
358433d6423SLionel Sambuc char *OutString,
359433d6423SLionel Sambuc UINT64 CompressedId)
360433d6423SLionel Sambuc {
361433d6423SLionel Sambuc UINT32 SwappedId;
362433d6423SLionel Sambuc
363433d6423SLionel Sambuc
364433d6423SLionel Sambuc ACPI_FUNCTION_ENTRY ();
365433d6423SLionel Sambuc
366433d6423SLionel Sambuc
367433d6423SLionel Sambuc /* The EISAID should be a 32-bit integer */
368433d6423SLionel Sambuc
369433d6423SLionel Sambuc if (CompressedId > ACPI_UINT32_MAX)
370433d6423SLionel Sambuc {
371433d6423SLionel Sambuc ACPI_WARNING ((AE_INFO,
372433d6423SLionel Sambuc "Expected EISAID is larger than 32 bits: 0x%8.8X%8.8X, truncating",
373433d6423SLionel Sambuc ACPI_FORMAT_UINT64 (CompressedId)));
374433d6423SLionel Sambuc }
375433d6423SLionel Sambuc
376433d6423SLionel Sambuc /* Swap ID to big-endian to get contiguous bits */
377433d6423SLionel Sambuc
378433d6423SLionel Sambuc SwappedId = AcpiUtDwordByteSwap ((UINT32) CompressedId);
379433d6423SLionel Sambuc
380433d6423SLionel Sambuc /* First 3 bytes are uppercase letters. Next 4 bytes are hexadecimal */
381433d6423SLionel Sambuc
382433d6423SLionel Sambuc OutString[0] = (char) (0x40 + (((unsigned long) SwappedId >> 26) & 0x1F));
383433d6423SLionel Sambuc OutString[1] = (char) (0x40 + ((SwappedId >> 21) & 0x1F));
384433d6423SLionel Sambuc OutString[2] = (char) (0x40 + ((SwappedId >> 16) & 0x1F));
385433d6423SLionel Sambuc OutString[3] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 12);
386433d6423SLionel Sambuc OutString[4] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 8);
387433d6423SLionel Sambuc OutString[5] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 4);
388433d6423SLionel Sambuc OutString[6] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 0);
389433d6423SLionel Sambuc OutString[7] = 0;
390433d6423SLionel Sambuc }
391433d6423SLionel Sambuc
392433d6423SLionel Sambuc
393433d6423SLionel Sambuc /*******************************************************************************
394433d6423SLionel Sambuc *
395433d6423SLionel Sambuc * FUNCTION: AcpiExIntegerToString
396433d6423SLionel Sambuc *
397433d6423SLionel Sambuc * PARAMETERS: OutString - Where to put the converted string. At least
398433d6423SLionel Sambuc * 21 bytes are needed to hold the largest
399433d6423SLionel Sambuc * possible 64-bit integer.
400433d6423SLionel Sambuc * Value - Value to be converted
401433d6423SLionel Sambuc *
402433d6423SLionel Sambuc * RETURN: None, string
403433d6423SLionel Sambuc *
404433d6423SLionel Sambuc * DESCRIPTION: Convert a 64-bit integer to decimal string representation.
405433d6423SLionel Sambuc * Assumes string buffer is large enough to hold the string. The
406433d6423SLionel Sambuc * largest string is (ACPI_MAX64_DECIMAL_DIGITS + 1).
407433d6423SLionel Sambuc *
408433d6423SLionel Sambuc ******************************************************************************/
409433d6423SLionel Sambuc
410433d6423SLionel Sambuc void
AcpiExIntegerToString(char * OutString,UINT64 Value)411433d6423SLionel Sambuc AcpiExIntegerToString (
412433d6423SLionel Sambuc char *OutString,
413433d6423SLionel Sambuc UINT64 Value)
414433d6423SLionel Sambuc {
415433d6423SLionel Sambuc UINT32 Count;
416433d6423SLionel Sambuc UINT32 DigitsNeeded;
417433d6423SLionel Sambuc UINT32 Remainder;
418433d6423SLionel Sambuc
419433d6423SLionel Sambuc
420433d6423SLionel Sambuc ACPI_FUNCTION_ENTRY ();
421433d6423SLionel Sambuc
422433d6423SLionel Sambuc
423433d6423SLionel Sambuc DigitsNeeded = AcpiExDigitsNeeded (Value, 10);
424433d6423SLionel Sambuc OutString[DigitsNeeded] = 0;
425433d6423SLionel Sambuc
426433d6423SLionel Sambuc for (Count = DigitsNeeded; Count > 0; Count--)
427433d6423SLionel Sambuc {
428433d6423SLionel Sambuc (void) AcpiUtShortDivide (Value, 10, &Value, &Remainder);
429433d6423SLionel Sambuc OutString[Count-1] = (char) ('0' + Remainder);\
430433d6423SLionel Sambuc }
431433d6423SLionel Sambuc }
432433d6423SLionel Sambuc
433*29492bb7SDavid van Moolenbroek
434*29492bb7SDavid van Moolenbroek /*******************************************************************************
435*29492bb7SDavid van Moolenbroek *
436*29492bb7SDavid van Moolenbroek * FUNCTION: AcpiIsValidSpaceId
437*29492bb7SDavid van Moolenbroek *
438*29492bb7SDavid van Moolenbroek * PARAMETERS: SpaceId - ID to be validated
439*29492bb7SDavid van Moolenbroek *
440*29492bb7SDavid van Moolenbroek * RETURN: TRUE if valid/supported ID.
441*29492bb7SDavid van Moolenbroek *
442*29492bb7SDavid van Moolenbroek * DESCRIPTION: Validate an operation region SpaceID.
443*29492bb7SDavid van Moolenbroek *
444*29492bb7SDavid van Moolenbroek ******************************************************************************/
445*29492bb7SDavid van Moolenbroek
446*29492bb7SDavid van Moolenbroek BOOLEAN
AcpiIsValidSpaceId(UINT8 SpaceId)447*29492bb7SDavid van Moolenbroek AcpiIsValidSpaceId (
448*29492bb7SDavid van Moolenbroek UINT8 SpaceId)
449*29492bb7SDavid van Moolenbroek {
450*29492bb7SDavid van Moolenbroek
451*29492bb7SDavid van Moolenbroek if ((SpaceId >= ACPI_NUM_PREDEFINED_REGIONS) &&
452*29492bb7SDavid van Moolenbroek (SpaceId < ACPI_USER_REGION_BEGIN) &&
453*29492bb7SDavid van Moolenbroek (SpaceId != ACPI_ADR_SPACE_DATA_TABLE) &&
454*29492bb7SDavid van Moolenbroek (SpaceId != ACPI_ADR_SPACE_FIXED_HARDWARE))
455*29492bb7SDavid van Moolenbroek {
456*29492bb7SDavid van Moolenbroek return (FALSE);
457*29492bb7SDavid van Moolenbroek }
458*29492bb7SDavid van Moolenbroek
459*29492bb7SDavid van Moolenbroek return (TRUE);
460*29492bb7SDavid van Moolenbroek }
461*29492bb7SDavid van Moolenbroek
462*29492bb7SDavid van Moolenbroek
463433d6423SLionel Sambuc #endif
464