1c2c66affSColin Finck /******************************************************************************
2c2c66affSColin Finck  *
3c2c66affSColin Finck  * Module Name: exutils - interpreter/scanner utilities
4c2c66affSColin Finck  *
5c2c66affSColin Finck  *****************************************************************************/
6c2c66affSColin Finck 
7c2c66affSColin Finck /*
805926c7aSThomas Faber  * Copyright (C) 2000 - 2021, Intel Corp.
9c2c66affSColin Finck  * All rights reserved.
10c2c66affSColin Finck  *
11c2c66affSColin Finck  * Redistribution and use in source and binary forms, with or without
12c2c66affSColin Finck  * modification, are permitted provided that the following conditions
13c2c66affSColin Finck  * are met:
14c2c66affSColin Finck  * 1. Redistributions of source code must retain the above copyright
15c2c66affSColin Finck  *    notice, this list of conditions, and the following disclaimer,
16c2c66affSColin Finck  *    without modification.
17c2c66affSColin Finck  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18c2c66affSColin Finck  *    substantially similar to the "NO WARRANTY" disclaimer below
19c2c66affSColin Finck  *    ("Disclaimer") and any redistribution must be conditioned upon
20c2c66affSColin Finck  *    including a substantially similar Disclaimer requirement for further
21c2c66affSColin Finck  *    binary redistribution.
22c2c66affSColin Finck  * 3. Neither the names of the above-listed copyright holders nor the names
23c2c66affSColin Finck  *    of any contributors may be used to endorse or promote products derived
24c2c66affSColin Finck  *    from this software without specific prior written permission.
25c2c66affSColin Finck  *
26c2c66affSColin Finck  * Alternatively, this software may be distributed under the terms of the
27c2c66affSColin Finck  * GNU General Public License ("GPL") version 2 as published by the Free
28c2c66affSColin Finck  * Software Foundation.
29c2c66affSColin Finck  *
30c2c66affSColin Finck  * NO WARRANTY
31c2c66affSColin Finck  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32c2c66affSColin Finck  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*6eb8cc49SThomas Faber  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34c2c66affSColin Finck  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35c2c66affSColin Finck  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36c2c66affSColin Finck  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37c2c66affSColin Finck  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38c2c66affSColin Finck  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39c2c66affSColin Finck  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40c2c66affSColin Finck  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41c2c66affSColin Finck  * POSSIBILITY OF SUCH DAMAGES.
42c2c66affSColin Finck  */
43c2c66affSColin Finck 
44c2c66affSColin Finck /*
45c2c66affSColin Finck  * DEFINE_AML_GLOBALS is tested in amlcode.h
46c2c66affSColin Finck  * to determine whether certain global names should be "defined" or only
47c2c66affSColin Finck  * "declared" in the current compilation. This enhances maintainability
48c2c66affSColin Finck  * by enabling a single header file to embody all knowledge of the names
49c2c66affSColin Finck  * in question.
50c2c66affSColin Finck  *
51c2c66affSColin Finck  * Exactly one module of any executable should #define DEFINE_GLOBALS
52c2c66affSColin Finck  * before #including the header files which use this convention. The
53c2c66affSColin Finck  * names in question will be defined and initialized in that module,
54c2c66affSColin Finck  * and declared as extern in all other modules which #include those
55c2c66affSColin Finck  * header files.
56c2c66affSColin Finck  */
57c2c66affSColin Finck 
58c2c66affSColin Finck #define DEFINE_AML_GLOBALS
59c2c66affSColin Finck 
60c2c66affSColin Finck #include "acpi.h"
61c2c66affSColin Finck #include "accommon.h"
62c2c66affSColin Finck #include "acinterp.h"
63c2c66affSColin Finck #include "amlcode.h"
64c2c66affSColin Finck 
65c2c66affSColin Finck #define _COMPONENT          ACPI_EXECUTER
66c2c66affSColin Finck         ACPI_MODULE_NAME    ("exutils")
67c2c66affSColin Finck 
68c2c66affSColin Finck /* Local prototypes */
69c2c66affSColin Finck 
70c2c66affSColin Finck static UINT32
71c2c66affSColin Finck AcpiExDigitsNeeded (
72c2c66affSColin Finck     UINT64                  Value,
73c2c66affSColin Finck     UINT32                  Base);
74c2c66affSColin Finck 
75c2c66affSColin Finck 
76c2c66affSColin Finck /*******************************************************************************
77c2c66affSColin Finck  *
78c2c66affSColin Finck  * FUNCTION:    AcpiExEnterInterpreter
79c2c66affSColin Finck  *
80c2c66affSColin Finck  * PARAMETERS:  None
81c2c66affSColin Finck  *
82c2c66affSColin Finck  * RETURN:      None
83c2c66affSColin Finck  *
84c2c66affSColin Finck  * DESCRIPTION: Enter the interpreter execution region. Failure to enter
85c2c66affSColin Finck  *              the interpreter region is a fatal system error. Used in
86c2c66affSColin Finck  *              conjunction with ExitInterpreter.
87c2c66affSColin Finck  *
88c2c66affSColin Finck  ******************************************************************************/
89c2c66affSColin Finck 
90c2c66affSColin Finck void
91c2c66affSColin Finck AcpiExEnterInterpreter (
92c2c66affSColin Finck     void)
93c2c66affSColin Finck {
94c2c66affSColin Finck     ACPI_STATUS             Status;
95c2c66affSColin Finck 
96c2c66affSColin Finck 
97c2c66affSColin Finck     ACPI_FUNCTION_TRACE (ExEnterInterpreter);
98c2c66affSColin Finck 
99c2c66affSColin Finck 
100c2c66affSColin Finck     Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
101c2c66affSColin Finck     if (ACPI_FAILURE (Status))
102c2c66affSColin Finck     {
103c2c66affSColin Finck         ACPI_ERROR ((AE_INFO, "Could not acquire AML Interpreter mutex"));
104c2c66affSColin Finck     }
105c2c66affSColin Finck     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
106c2c66affSColin Finck     if (ACPI_FAILURE (Status))
107c2c66affSColin Finck     {
108c2c66affSColin Finck         ACPI_ERROR ((AE_INFO, "Could not acquire AML Namespace mutex"));
109c2c66affSColin Finck     }
110c2c66affSColin Finck 
111c2c66affSColin Finck     return_VOID;
112c2c66affSColin Finck }
113c2c66affSColin Finck 
114c2c66affSColin Finck 
115c2c66affSColin Finck /*******************************************************************************
116c2c66affSColin Finck  *
117c2c66affSColin Finck  * FUNCTION:    AcpiExExitInterpreter
118c2c66affSColin Finck  *
119c2c66affSColin Finck  * PARAMETERS:  None
120c2c66affSColin Finck  *
121c2c66affSColin Finck  * RETURN:      None
122c2c66affSColin Finck  *
123c2c66affSColin Finck  * DESCRIPTION: Exit the interpreter execution region. This is the top level
124c2c66affSColin Finck  *              routine used to exit the interpreter when all processing has
125c2c66affSColin Finck  *              been completed, or when the method blocks.
126c2c66affSColin Finck  *
127c2c66affSColin Finck  * Cases where the interpreter is unlocked internally:
128c2c66affSColin Finck  *      1) Method will be blocked on a Sleep() AML opcode
129c2c66affSColin Finck  *      2) Method will be blocked on an Acquire() AML opcode
130c2c66affSColin Finck  *      3) Method will be blocked on a Wait() AML opcode
131c2c66affSColin Finck  *      4) Method will be blocked to acquire the global lock
132c2c66affSColin Finck  *      5) Method will be blocked waiting to execute a serialized control
133c2c66affSColin Finck  *          method that is currently executing
134c2c66affSColin Finck  *      6) About to invoke a user-installed opregion handler
135c2c66affSColin Finck  *
136c2c66affSColin Finck  ******************************************************************************/
137c2c66affSColin Finck 
138c2c66affSColin Finck void
139c2c66affSColin Finck AcpiExExitInterpreter (
140c2c66affSColin Finck     void)
141c2c66affSColin Finck {
142c2c66affSColin Finck     ACPI_STATUS             Status;
143c2c66affSColin Finck 
144c2c66affSColin Finck 
145c2c66affSColin Finck     ACPI_FUNCTION_TRACE (ExExitInterpreter);
146c2c66affSColin Finck 
147c2c66affSColin Finck 
148c2c66affSColin Finck     Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
149c2c66affSColin Finck     if (ACPI_FAILURE (Status))
150c2c66affSColin Finck     {
151c2c66affSColin Finck         ACPI_ERROR ((AE_INFO, "Could not release AML Namespace mutex"));
152c2c66affSColin Finck     }
153c2c66affSColin Finck     Status = AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
154c2c66affSColin Finck     if (ACPI_FAILURE (Status))
155c2c66affSColin Finck     {
156c2c66affSColin Finck         ACPI_ERROR ((AE_INFO, "Could not release AML Interpreter mutex"));
157c2c66affSColin Finck     }
158c2c66affSColin Finck 
159c2c66affSColin Finck     return_VOID;
160c2c66affSColin Finck }
161c2c66affSColin Finck 
162c2c66affSColin Finck 
163c2c66affSColin Finck /*******************************************************************************
164c2c66affSColin Finck  *
165c2c66affSColin Finck  * FUNCTION:    AcpiExTruncateFor32bitTable
166c2c66affSColin Finck  *
167c2c66affSColin Finck  * PARAMETERS:  ObjDesc         - Object to be truncated
168c2c66affSColin Finck  *
169c2c66affSColin Finck  * RETURN:      TRUE if a truncation was performed, FALSE otherwise.
170c2c66affSColin Finck  *
171c2c66affSColin Finck  * DESCRIPTION: Truncate an ACPI Integer to 32 bits if the execution mode is
172c2c66affSColin Finck  *              32-bit, as determined by the revision of the DSDT.
173c2c66affSColin Finck  *
174c2c66affSColin Finck  ******************************************************************************/
175c2c66affSColin Finck 
176c2c66affSColin Finck BOOLEAN
177c2c66affSColin Finck AcpiExTruncateFor32bitTable (
178c2c66affSColin Finck     ACPI_OPERAND_OBJECT     *ObjDesc)
179c2c66affSColin Finck {
180c2c66affSColin Finck 
181c2c66affSColin Finck     ACPI_FUNCTION_ENTRY ();
182c2c66affSColin Finck 
183c2c66affSColin Finck 
184c2c66affSColin Finck     /*
185c2c66affSColin Finck      * Object must be a valid number and we must be executing
186c2c66affSColin Finck      * a control method. Object could be NS node for AML_INT_NAMEPATH_OP.
187c2c66affSColin Finck      */
188c2c66affSColin Finck     if ((!ObjDesc) ||
189c2c66affSColin Finck         (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND) ||
190c2c66affSColin Finck         (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
191c2c66affSColin Finck     {
192c2c66affSColin Finck         return (FALSE);
193c2c66affSColin Finck     }
194c2c66affSColin Finck 
195c2c66affSColin Finck     if ((AcpiGbl_IntegerByteWidth == 4) &&
196c2c66affSColin Finck         (ObjDesc->Integer.Value > (UINT64) ACPI_UINT32_MAX))
197c2c66affSColin Finck     {
198c2c66affSColin Finck         /*
199c2c66affSColin Finck          * We are executing in a 32-bit ACPI table. Truncate
200c2c66affSColin Finck          * the value to 32 bits by zeroing out the upper 32-bit field
201c2c66affSColin Finck          */
202c2c66affSColin Finck         ObjDesc->Integer.Value &= (UINT64) ACPI_UINT32_MAX;
203c2c66affSColin Finck         return (TRUE);
204c2c66affSColin Finck     }
205c2c66affSColin Finck 
206c2c66affSColin Finck     return (FALSE);
207c2c66affSColin Finck }
208c2c66affSColin Finck 
209c2c66affSColin Finck 
210c2c66affSColin Finck /*******************************************************************************
211c2c66affSColin Finck  *
212c2c66affSColin Finck  * FUNCTION:    AcpiExAcquireGlobalLock
213c2c66affSColin Finck  *
214c2c66affSColin Finck  * PARAMETERS:  FieldFlags            - Flags with Lock rule:
215c2c66affSColin Finck  *                                      AlwaysLock or NeverLock
216c2c66affSColin Finck  *
217c2c66affSColin Finck  * RETURN:      None
218c2c66affSColin Finck  *
219c2c66affSColin Finck  * DESCRIPTION: Obtain the ACPI hardware Global Lock, only if the field
2209d53c935SThomas Faber  *              flags specify that it is to be obtained before field access.
221c2c66affSColin Finck  *
222c2c66affSColin Finck  ******************************************************************************/
223c2c66affSColin Finck 
224c2c66affSColin Finck void
225c2c66affSColin Finck AcpiExAcquireGlobalLock (
226c2c66affSColin Finck     UINT32                  FieldFlags)
227c2c66affSColin Finck {
228c2c66affSColin Finck     ACPI_STATUS             Status;
229c2c66affSColin Finck 
230c2c66affSColin Finck 
231c2c66affSColin Finck     ACPI_FUNCTION_TRACE (ExAcquireGlobalLock);
232c2c66affSColin Finck 
233c2c66affSColin Finck 
234c2c66affSColin Finck     /* Only use the lock if the AlwaysLock bit is set */
235c2c66affSColin Finck 
236c2c66affSColin Finck     if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK))
237c2c66affSColin Finck     {
238c2c66affSColin Finck         return_VOID;
239c2c66affSColin Finck     }
240c2c66affSColin Finck 
241c2c66affSColin Finck     /* Attempt to get the global lock, wait forever */
242c2c66affSColin Finck 
243c2c66affSColin Finck     Status = AcpiExAcquireMutexObject (ACPI_WAIT_FOREVER,
244c2c66affSColin Finck         AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ());
245c2c66affSColin Finck 
246c2c66affSColin Finck     if (ACPI_FAILURE (Status))
247c2c66affSColin Finck     {
248c2c66affSColin Finck         ACPI_EXCEPTION ((AE_INFO, Status,
249c2c66affSColin Finck             "Could not acquire Global Lock"));
250c2c66affSColin Finck     }
251c2c66affSColin Finck 
252c2c66affSColin Finck     return_VOID;
253c2c66affSColin Finck }
254c2c66affSColin Finck 
255c2c66affSColin Finck 
256c2c66affSColin Finck /*******************************************************************************
257c2c66affSColin Finck  *
258c2c66affSColin Finck  * FUNCTION:    AcpiExReleaseGlobalLock
259c2c66affSColin Finck  *
260c2c66affSColin Finck  * PARAMETERS:  FieldFlags            - Flags with Lock rule:
261c2c66affSColin Finck  *                                      AlwaysLock or NeverLock
262c2c66affSColin Finck  *
263c2c66affSColin Finck  * RETURN:      None
264c2c66affSColin Finck  *
265c2c66affSColin Finck  * DESCRIPTION: Release the ACPI hardware Global Lock
266c2c66affSColin Finck  *
267c2c66affSColin Finck  ******************************************************************************/
268c2c66affSColin Finck 
269c2c66affSColin Finck void
270c2c66affSColin Finck AcpiExReleaseGlobalLock (
271c2c66affSColin Finck     UINT32                  FieldFlags)
272c2c66affSColin Finck {
273c2c66affSColin Finck     ACPI_STATUS             Status;
274c2c66affSColin Finck 
275c2c66affSColin Finck 
276c2c66affSColin Finck     ACPI_FUNCTION_TRACE (ExReleaseGlobalLock);
277c2c66affSColin Finck 
278c2c66affSColin Finck 
279c2c66affSColin Finck     /* Only use the lock if the AlwaysLock bit is set */
280c2c66affSColin Finck 
281c2c66affSColin Finck     if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK))
282c2c66affSColin Finck     {
283c2c66affSColin Finck         return_VOID;
284c2c66affSColin Finck     }
285c2c66affSColin Finck 
286c2c66affSColin Finck     /* Release the global lock */
287c2c66affSColin Finck 
288c2c66affSColin Finck     Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex);
289c2c66affSColin Finck     if (ACPI_FAILURE (Status))
290c2c66affSColin Finck     {
291c2c66affSColin Finck         /* Report the error, but there isn't much else we can do */
292c2c66affSColin Finck 
293c2c66affSColin Finck         ACPI_EXCEPTION ((AE_INFO, Status,
294c2c66affSColin Finck             "Could not release Global Lock"));
295c2c66affSColin Finck     }
296c2c66affSColin Finck 
297c2c66affSColin Finck     return_VOID;
298c2c66affSColin Finck }
299c2c66affSColin Finck 
300c2c66affSColin Finck 
301c2c66affSColin Finck /*******************************************************************************
302c2c66affSColin Finck  *
303c2c66affSColin Finck  * FUNCTION:    AcpiExDigitsNeeded
304c2c66affSColin Finck  *
305c2c66affSColin Finck  * PARAMETERS:  Value           - Value to be represented
306c2c66affSColin Finck  *              Base            - Base of representation
307c2c66affSColin Finck  *
308c2c66affSColin Finck  * RETURN:      The number of digits.
309c2c66affSColin Finck  *
310c2c66affSColin Finck  * DESCRIPTION: Calculate the number of digits needed to represent the Value
311c2c66affSColin Finck  *              in the given Base (Radix)
312c2c66affSColin Finck  *
313c2c66affSColin Finck  ******************************************************************************/
314c2c66affSColin Finck 
315c2c66affSColin Finck static UINT32
316c2c66affSColin Finck AcpiExDigitsNeeded (
317c2c66affSColin Finck     UINT64                  Value,
318c2c66affSColin Finck     UINT32                  Base)
319c2c66affSColin Finck {
320c2c66affSColin Finck     UINT32                  NumDigits;
321c2c66affSColin Finck     UINT64                  CurrentValue;
322c2c66affSColin Finck 
323c2c66affSColin Finck 
324c2c66affSColin Finck     ACPI_FUNCTION_TRACE (ExDigitsNeeded);
325c2c66affSColin Finck 
326c2c66affSColin Finck 
327c2c66affSColin Finck     /* UINT64 is unsigned, so we don't worry about a '-' prefix */
328c2c66affSColin Finck 
329c2c66affSColin Finck     if (Value == 0)
330c2c66affSColin Finck     {
331c2c66affSColin Finck         return_UINT32 (1);
332c2c66affSColin Finck     }
333c2c66affSColin Finck 
334c2c66affSColin Finck     CurrentValue = Value;
335c2c66affSColin Finck     NumDigits = 0;
336c2c66affSColin Finck 
337c2c66affSColin Finck     /* Count the digits in the requested base */
338c2c66affSColin Finck 
339c2c66affSColin Finck     while (CurrentValue)
340c2c66affSColin Finck     {
341c2c66affSColin Finck         (void) AcpiUtShortDivide (CurrentValue, Base, &CurrentValue, NULL);
342c2c66affSColin Finck         NumDigits++;
343c2c66affSColin Finck     }
344c2c66affSColin Finck 
345c2c66affSColin Finck     return_UINT32 (NumDigits);
346c2c66affSColin Finck }
347c2c66affSColin Finck 
348c2c66affSColin Finck 
349c2c66affSColin Finck /*******************************************************************************
350c2c66affSColin Finck  *
351c2c66affSColin Finck  * FUNCTION:    AcpiExEisaIdToString
352c2c66affSColin Finck  *
353c2c66affSColin Finck  * PARAMETERS:  OutString       - Where to put the converted string (8 bytes)
354c2c66affSColin Finck  *              CompressedId    - EISAID to be converted
355c2c66affSColin Finck  *
356c2c66affSColin Finck  * RETURN:      None
357c2c66affSColin Finck  *
358c2c66affSColin Finck  * DESCRIPTION: Convert a numeric EISAID to string representation. Return
359c2c66affSColin Finck  *              buffer must be large enough to hold the string. The string
360c2c66affSColin Finck  *              returned is always exactly of length ACPI_EISAID_STRING_SIZE
361c2c66affSColin Finck  *              (includes null terminator). The EISAID is always 32 bits.
362c2c66affSColin Finck  *
363c2c66affSColin Finck  ******************************************************************************/
364c2c66affSColin Finck 
365c2c66affSColin Finck void
366c2c66affSColin Finck AcpiExEisaIdToString (
367c2c66affSColin Finck     char                    *OutString,
368c2c66affSColin Finck     UINT64                  CompressedId)
369c2c66affSColin Finck {
370c2c66affSColin Finck     UINT32                  SwappedId;
371c2c66affSColin Finck 
372c2c66affSColin Finck 
373c2c66affSColin Finck     ACPI_FUNCTION_ENTRY ();
374c2c66affSColin Finck 
375c2c66affSColin Finck 
376c2c66affSColin Finck     /* The EISAID should be a 32-bit integer */
377c2c66affSColin Finck 
378c2c66affSColin Finck     if (CompressedId > ACPI_UINT32_MAX)
379c2c66affSColin Finck     {
380c2c66affSColin Finck         ACPI_WARNING ((AE_INFO,
381c2c66affSColin Finck             "Expected EISAID is larger than 32 bits: "
382c2c66affSColin Finck             "0x%8.8X%8.8X, truncating",
383c2c66affSColin Finck             ACPI_FORMAT_UINT64 (CompressedId)));
384c2c66affSColin Finck     }
385c2c66affSColin Finck 
386c2c66affSColin Finck     /* Swap ID to big-endian to get contiguous bits */
387c2c66affSColin Finck 
388c2c66affSColin Finck     SwappedId = AcpiUtDwordByteSwap ((UINT32) CompressedId);
389c2c66affSColin Finck 
390c2c66affSColin Finck     /* First 3 bytes are uppercase letters. Next 4 bytes are hexadecimal */
391c2c66affSColin Finck 
392c2c66affSColin Finck     OutString[0] = (char) (0x40 + (((unsigned long) SwappedId >> 26) & 0x1F));
393c2c66affSColin Finck     OutString[1] = (char) (0x40 + ((SwappedId >> 21) & 0x1F));
394c2c66affSColin Finck     OutString[2] = (char) (0x40 + ((SwappedId >> 16) & 0x1F));
395c2c66affSColin Finck     OutString[3] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 12);
396c2c66affSColin Finck     OutString[4] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 8);
397c2c66affSColin Finck     OutString[5] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 4);
398c2c66affSColin Finck     OutString[6] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 0);
399c2c66affSColin Finck     OutString[7] = 0;
400c2c66affSColin Finck }
401c2c66affSColin Finck 
402c2c66affSColin Finck 
403c2c66affSColin Finck /*******************************************************************************
404c2c66affSColin Finck  *
405c2c66affSColin Finck  * FUNCTION:    AcpiExIntegerToString
406c2c66affSColin Finck  *
407c2c66affSColin Finck  * PARAMETERS:  OutString       - Where to put the converted string. At least
408c2c66affSColin Finck  *                                21 bytes are needed to hold the largest
409c2c66affSColin Finck  *                                possible 64-bit integer.
410c2c66affSColin Finck  *              Value           - Value to be converted
411c2c66affSColin Finck  *
412c2c66affSColin Finck  * RETURN:      Converted string in OutString
413c2c66affSColin Finck  *
414c2c66affSColin Finck  * DESCRIPTION: Convert a 64-bit integer to decimal string representation.
415c2c66affSColin Finck  *              Assumes string buffer is large enough to hold the string. The
416c2c66affSColin Finck  *              largest string is (ACPI_MAX64_DECIMAL_DIGITS + 1).
417c2c66affSColin Finck  *
418c2c66affSColin Finck  ******************************************************************************/
419c2c66affSColin Finck 
420c2c66affSColin Finck void
421c2c66affSColin Finck AcpiExIntegerToString (
422c2c66affSColin Finck     char                    *OutString,
423c2c66affSColin Finck     UINT64                  Value)
424c2c66affSColin Finck {
425c2c66affSColin Finck     UINT32                  Count;
426c2c66affSColin Finck     UINT32                  DigitsNeeded;
427c2c66affSColin Finck     UINT32                  Remainder;
428c2c66affSColin Finck 
429c2c66affSColin Finck 
430c2c66affSColin Finck     ACPI_FUNCTION_ENTRY ();
431c2c66affSColin Finck 
432c2c66affSColin Finck 
433c2c66affSColin Finck     DigitsNeeded = AcpiExDigitsNeeded (Value, 10);
434c2c66affSColin Finck     OutString[DigitsNeeded] = 0;
435c2c66affSColin Finck 
436c2c66affSColin Finck     for (Count = DigitsNeeded; Count > 0; Count--)
437c2c66affSColin Finck     {
438c2c66affSColin Finck         (void) AcpiUtShortDivide (Value, 10, &Value, &Remainder);
439c2c66affSColin Finck         OutString[Count-1] = (char) ('0' + Remainder);\
440c2c66affSColin Finck     }
441c2c66affSColin Finck }
442c2c66affSColin Finck 
443c2c66affSColin Finck 
444c2c66affSColin Finck /*******************************************************************************
445c2c66affSColin Finck  *
446c2c66affSColin Finck  * FUNCTION:    AcpiExPciClsToString
447c2c66affSColin Finck  *
448c2c66affSColin Finck  * PARAMETERS:  OutString       - Where to put the converted string (7 bytes)
449c2c66affSColin Finck  *              ClassCode       - PCI class code to be converted (3 bytes)
450c2c66affSColin Finck  *
451c2c66affSColin Finck  * RETURN:      Converted string in OutString
452c2c66affSColin Finck  *
453c2c66affSColin Finck  * DESCRIPTION: Convert 3-bytes PCI class code to string representation.
454c2c66affSColin Finck  *              Return buffer must be large enough to hold the string. The
455c2c66affSColin Finck  *              string returned is always exactly of length
456c2c66affSColin Finck  *              ACPI_PCICLS_STRING_SIZE (includes null terminator).
457c2c66affSColin Finck  *
458c2c66affSColin Finck  ******************************************************************************/
459c2c66affSColin Finck 
460c2c66affSColin Finck void
461c2c66affSColin Finck AcpiExPciClsToString (
462c2c66affSColin Finck     char                    *OutString,
463c2c66affSColin Finck     UINT8                   ClassCode[3])
464c2c66affSColin Finck {
465c2c66affSColin Finck 
466c2c66affSColin Finck     ACPI_FUNCTION_ENTRY ();
467c2c66affSColin Finck 
468c2c66affSColin Finck 
469c2c66affSColin Finck     /* All 3 bytes are hexadecimal */
470c2c66affSColin Finck 
471c2c66affSColin Finck     OutString[0] = AcpiUtHexToAsciiChar ((UINT64) ClassCode[0], 4);
472c2c66affSColin Finck     OutString[1] = AcpiUtHexToAsciiChar ((UINT64) ClassCode[0], 0);
473c2c66affSColin Finck     OutString[2] = AcpiUtHexToAsciiChar ((UINT64) ClassCode[1], 4);
474c2c66affSColin Finck     OutString[3] = AcpiUtHexToAsciiChar ((UINT64) ClassCode[1], 0);
475c2c66affSColin Finck     OutString[4] = AcpiUtHexToAsciiChar ((UINT64) ClassCode[2], 4);
476c2c66affSColin Finck     OutString[5] = AcpiUtHexToAsciiChar ((UINT64) ClassCode[2], 0);
477c2c66affSColin Finck     OutString[6] = 0;
478c2c66affSColin Finck }
479c2c66affSColin Finck 
480c2c66affSColin Finck 
481c2c66affSColin Finck /*******************************************************************************
482c2c66affSColin Finck  *
483c2c66affSColin Finck  * FUNCTION:    AcpiIsValidSpaceId
484c2c66affSColin Finck  *
485c2c66affSColin Finck  * PARAMETERS:  SpaceId             - ID to be validated
486c2c66affSColin Finck  *
487c2c66affSColin Finck  * RETURN:      TRUE if SpaceId is a valid/supported ID.
488c2c66affSColin Finck  *
489c2c66affSColin Finck  * DESCRIPTION: Validate an operation region SpaceID.
490c2c66affSColin Finck  *
491c2c66affSColin Finck  ******************************************************************************/
492c2c66affSColin Finck 
493c2c66affSColin Finck BOOLEAN
494c2c66affSColin Finck AcpiIsValidSpaceId (
495c2c66affSColin Finck     UINT8                   SpaceId)
496c2c66affSColin Finck {
497c2c66affSColin Finck 
498c2c66affSColin Finck     if ((SpaceId >= ACPI_NUM_PREDEFINED_REGIONS) &&
499c2c66affSColin Finck         (SpaceId < ACPI_USER_REGION_BEGIN) &&
500c2c66affSColin Finck         (SpaceId != ACPI_ADR_SPACE_DATA_TABLE) &&
501c2c66affSColin Finck         (SpaceId != ACPI_ADR_SPACE_FIXED_HARDWARE))
502c2c66affSColin Finck     {
503c2c66affSColin Finck         return (FALSE);
504c2c66affSColin Finck     }
505c2c66affSColin Finck 
506c2c66affSColin Finck     return (TRUE);
507c2c66affSColin Finck }
508