utglobal.c revision 217365
1/******************************************************************************
2 *
3 * Module Name: utglobal - Global variables for the ACPI subsystem
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2011, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions, and the following disclaimer,
16 *    without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 *    substantially similar to the "NO WARRANTY" disclaimer below
19 *    ("Disclaimer") and any redistribution must be conditioned upon
20 *    including a substantially similar Disclaimer requirement for further
21 *    binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 *    of any contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#define __UTGLOBAL_C__
45#define DEFINE_ACPI_GLOBALS
46
47#include <contrib/dev/acpica/include/acpi.h>
48#include <contrib/dev/acpica/include/accommon.h>
49#include <contrib/dev/acpica/include/acnamesp.h>
50
51#define _COMPONENT          ACPI_UTILITIES
52        ACPI_MODULE_NAME    ("utglobal")
53
54
55/*******************************************************************************
56 *
57 * Static global variable initialization.
58 *
59 ******************************************************************************/
60
61/*
62 * We want the debug switches statically initialized so they
63 * are already set when the debugger is entered.
64 */
65
66/* Debug switch - level and trace mask */
67
68#ifdef ACPI_DEBUG_OUTPUT
69UINT32                      AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
70#else
71UINT32                      AcpiDbgLevel = ACPI_NORMAL_DEFAULT;
72#endif
73
74/* Debug switch - layer (component) mask */
75
76UINT32                      AcpiDbgLayer = ACPI_COMPONENT_DEFAULT;
77UINT32                      AcpiGbl_NestingLevel = 0;
78
79/* Debugger globals */
80
81BOOLEAN                     AcpiGbl_DbTerminateThreads = FALSE;
82BOOLEAN                     AcpiGbl_AbortMethod = FALSE;
83BOOLEAN                     AcpiGbl_MethodExecuting = FALSE;
84
85/* System flags */
86
87UINT32                      AcpiGbl_StartupFlags = 0;
88
89/* System starts uninitialized */
90
91BOOLEAN                     AcpiGbl_Shutdown = TRUE;
92
93const char                  *AcpiGbl_SleepStateNames[ACPI_S_STATE_COUNT] =
94{
95    "\\_S0_",
96    "\\_S1_",
97    "\\_S2_",
98    "\\_S3_",
99    "\\_S4_",
100    "\\_S5_"
101};
102
103const char                  *AcpiGbl_LowestDstateNames[ACPI_NUM_SxW_METHODS] =
104{
105    "_S0W",
106    "_S1W",
107    "_S2W",
108    "_S3W",
109    "_S4W"
110};
111
112const char                  *AcpiGbl_HighestDstateNames[ACPI_NUM_SxD_METHODS] =
113{
114    "_S1D",
115    "_S2D",
116    "_S3D",
117    "_S4D"
118};
119
120
121/*******************************************************************************
122 *
123 * FUNCTION:    AcpiFormatException
124 *
125 * PARAMETERS:  Status       - The ACPI_STATUS code to be formatted
126 *
127 * RETURN:      A string containing the exception text. A valid pointer is
128 *              always returned.
129 *
130 * DESCRIPTION: This function translates an ACPI exception into an ASCII string
131 *              It is here instead of utxface.c so it is always present.
132 *
133 ******************************************************************************/
134
135const char *
136AcpiFormatException (
137    ACPI_STATUS             Status)
138{
139    const char              *Exception = NULL;
140
141
142    ACPI_FUNCTION_ENTRY ();
143
144
145    Exception = AcpiUtValidateException (Status);
146    if (!Exception)
147    {
148        /* Exception code was not recognized */
149
150        ACPI_ERROR ((AE_INFO,
151            "Unknown exception code: 0x%8.8X", Status));
152
153        Exception = "UNKNOWN_STATUS_CODE";
154    }
155
156    return (ACPI_CAST_PTR (const char, Exception));
157}
158
159ACPI_EXPORT_SYMBOL (AcpiFormatException)
160
161
162/*******************************************************************************
163 *
164 * Namespace globals
165 *
166 ******************************************************************************/
167
168/*
169 * Predefined ACPI Names (Built-in to the Interpreter)
170 *
171 * NOTES:
172 * 1) _SB_ is defined to be a device to allow \_SB_._INI to be run
173 *    during the initialization sequence.
174 * 2) _TZ_ is defined to be a thermal zone in order to allow ASL code to
175 *    perform a Notify() operation on it. 09/2010: Changed to type Device.
176 *    This still allows notifies, but does not confuse host code that
177 *    searches for valid ThermalZone objects.
178 */
179const ACPI_PREDEFINED_NAMES     AcpiGbl_PreDefinedNames[] =
180{
181    {"_GPE",    ACPI_TYPE_LOCAL_SCOPE,      NULL},
182    {"_PR_",    ACPI_TYPE_LOCAL_SCOPE,      NULL},
183    {"_SB_",    ACPI_TYPE_DEVICE,           NULL},
184    {"_SI_",    ACPI_TYPE_LOCAL_SCOPE,      NULL},
185    {"_TZ_",    ACPI_TYPE_DEVICE,           NULL},
186    {"_REV",    ACPI_TYPE_INTEGER,          (char *) ACPI_CA_SUPPORT_LEVEL},
187    {"_OS_",    ACPI_TYPE_STRING,           ACPI_OS_NAME},
188    {"_GL_",    ACPI_TYPE_MUTEX,            (char *) 1},
189
190#if !defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY)
191    {"_OSI",    ACPI_TYPE_METHOD,           (char *) 1},
192#endif
193
194    /* Table terminator */
195
196    {NULL,      ACPI_TYPE_ANY,              NULL}
197};
198
199/*
200 * Properties of the ACPI Object Types, both internal and external.
201 * The table is indexed by values of ACPI_OBJECT_TYPE
202 */
203const UINT8                     AcpiGbl_NsProperties[ACPI_NUM_NS_TYPES] =
204{
205    ACPI_NS_NORMAL,                     /* 00 Any              */
206    ACPI_NS_NORMAL,                     /* 01 Number           */
207    ACPI_NS_NORMAL,                     /* 02 String           */
208    ACPI_NS_NORMAL,                     /* 03 Buffer           */
209    ACPI_NS_NORMAL,                     /* 04 Package          */
210    ACPI_NS_NORMAL,                     /* 05 FieldUnit        */
211    ACPI_NS_NEWSCOPE,                   /* 06 Device           */
212    ACPI_NS_NORMAL,                     /* 07 Event            */
213    ACPI_NS_NEWSCOPE,                   /* 08 Method           */
214    ACPI_NS_NORMAL,                     /* 09 Mutex            */
215    ACPI_NS_NORMAL,                     /* 10 Region           */
216    ACPI_NS_NEWSCOPE,                   /* 11 Power            */
217    ACPI_NS_NEWSCOPE,                   /* 12 Processor        */
218    ACPI_NS_NEWSCOPE,                   /* 13 Thermal          */
219    ACPI_NS_NORMAL,                     /* 14 BufferField      */
220    ACPI_NS_NORMAL,                     /* 15 DdbHandle        */
221    ACPI_NS_NORMAL,                     /* 16 Debug Object     */
222    ACPI_NS_NORMAL,                     /* 17 DefField         */
223    ACPI_NS_NORMAL,                     /* 18 BankField        */
224    ACPI_NS_NORMAL,                     /* 19 IndexField       */
225    ACPI_NS_NORMAL,                     /* 20 Reference        */
226    ACPI_NS_NORMAL,                     /* 21 Alias            */
227    ACPI_NS_NORMAL,                     /* 22 MethodAlias      */
228    ACPI_NS_NORMAL,                     /* 23 Notify           */
229    ACPI_NS_NORMAL,                     /* 24 Address Handler  */
230    ACPI_NS_NEWSCOPE | ACPI_NS_LOCAL,   /* 25 Resource Desc    */
231    ACPI_NS_NEWSCOPE | ACPI_NS_LOCAL,   /* 26 Resource Field   */
232    ACPI_NS_NEWSCOPE,                   /* 27 Scope            */
233    ACPI_NS_NORMAL,                     /* 28 Extra            */
234    ACPI_NS_NORMAL,                     /* 29 Data             */
235    ACPI_NS_NORMAL                      /* 30 Invalid          */
236};
237
238
239/* Hex to ASCII conversion table */
240
241static const char           AcpiGbl_HexToAscii[] =
242{
243    '0','1','2','3','4','5','6','7',
244    '8','9','A','B','C','D','E','F'
245};
246
247
248/*******************************************************************************
249 *
250 * FUNCTION:    AcpiUtHexToAsciiChar
251 *
252 * PARAMETERS:  Integer             - Contains the hex digit
253 *              Position            - bit position of the digit within the
254 *                                    integer (multiple of 4)
255 *
256 * RETURN:      The converted Ascii character
257 *
258 * DESCRIPTION: Convert a hex digit to an Ascii character
259 *
260 ******************************************************************************/
261
262char
263AcpiUtHexToAsciiChar (
264    UINT64                  Integer,
265    UINT32                  Position)
266{
267
268    return (AcpiGbl_HexToAscii[(Integer >> Position) & 0xF]);
269}
270
271
272/******************************************************************************
273 *
274 * Event and Hardware globals
275 *
276 ******************************************************************************/
277
278ACPI_BIT_REGISTER_INFO      AcpiGbl_BitRegisterInfo[ACPI_NUM_BITREG] =
279{
280    /* Name                                     Parent Register             Register Bit Position                   Register Bit Mask       */
281
282    /* ACPI_BITREG_TIMER_STATUS         */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_TIMER_STATUS,          ACPI_BITMASK_TIMER_STATUS},
283    /* ACPI_BITREG_BUS_MASTER_STATUS    */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_BUS_MASTER_STATUS,     ACPI_BITMASK_BUS_MASTER_STATUS},
284    /* ACPI_BITREG_GLOBAL_LOCK_STATUS   */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_GLOBAL_LOCK_STATUS,    ACPI_BITMASK_GLOBAL_LOCK_STATUS},
285    /* ACPI_BITREG_POWER_BUTTON_STATUS  */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_POWER_BUTTON_STATUS,   ACPI_BITMASK_POWER_BUTTON_STATUS},
286    /* ACPI_BITREG_SLEEP_BUTTON_STATUS  */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_SLEEP_BUTTON_STATUS,   ACPI_BITMASK_SLEEP_BUTTON_STATUS},
287    /* ACPI_BITREG_RT_CLOCK_STATUS      */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_RT_CLOCK_STATUS,       ACPI_BITMASK_RT_CLOCK_STATUS},
288    /* ACPI_BITREG_WAKE_STATUS          */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_WAKE_STATUS,           ACPI_BITMASK_WAKE_STATUS},
289    /* ACPI_BITREG_PCIEXP_WAKE_STATUS   */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_PCIEXP_WAKE_STATUS,    ACPI_BITMASK_PCIEXP_WAKE_STATUS},
290
291    /* ACPI_BITREG_TIMER_ENABLE         */   {ACPI_REGISTER_PM1_ENABLE,   ACPI_BITPOSITION_TIMER_ENABLE,          ACPI_BITMASK_TIMER_ENABLE},
292    /* ACPI_BITREG_GLOBAL_LOCK_ENABLE   */   {ACPI_REGISTER_PM1_ENABLE,   ACPI_BITPOSITION_GLOBAL_LOCK_ENABLE,    ACPI_BITMASK_GLOBAL_LOCK_ENABLE},
293    /* ACPI_BITREG_POWER_BUTTON_ENABLE  */   {ACPI_REGISTER_PM1_ENABLE,   ACPI_BITPOSITION_POWER_BUTTON_ENABLE,   ACPI_BITMASK_POWER_BUTTON_ENABLE},
294    /* ACPI_BITREG_SLEEP_BUTTON_ENABLE  */   {ACPI_REGISTER_PM1_ENABLE,   ACPI_BITPOSITION_SLEEP_BUTTON_ENABLE,   ACPI_BITMASK_SLEEP_BUTTON_ENABLE},
295    /* ACPI_BITREG_RT_CLOCK_ENABLE      */   {ACPI_REGISTER_PM1_ENABLE,   ACPI_BITPOSITION_RT_CLOCK_ENABLE,       ACPI_BITMASK_RT_CLOCK_ENABLE},
296    /* ACPI_BITREG_PCIEXP_WAKE_DISABLE  */   {ACPI_REGISTER_PM1_ENABLE,   ACPI_BITPOSITION_PCIEXP_WAKE_DISABLE,   ACPI_BITMASK_PCIEXP_WAKE_DISABLE},
297
298    /* ACPI_BITREG_SCI_ENABLE           */   {ACPI_REGISTER_PM1_CONTROL,  ACPI_BITPOSITION_SCI_ENABLE,            ACPI_BITMASK_SCI_ENABLE},
299    /* ACPI_BITREG_BUS_MASTER_RLD       */   {ACPI_REGISTER_PM1_CONTROL,  ACPI_BITPOSITION_BUS_MASTER_RLD,        ACPI_BITMASK_BUS_MASTER_RLD},
300    /* ACPI_BITREG_GLOBAL_LOCK_RELEASE  */   {ACPI_REGISTER_PM1_CONTROL,  ACPI_BITPOSITION_GLOBAL_LOCK_RELEASE,   ACPI_BITMASK_GLOBAL_LOCK_RELEASE},
301    /* ACPI_BITREG_SLEEP_TYPE           */   {ACPI_REGISTER_PM1_CONTROL,  ACPI_BITPOSITION_SLEEP_TYPE,            ACPI_BITMASK_SLEEP_TYPE},
302    /* ACPI_BITREG_SLEEP_ENABLE         */   {ACPI_REGISTER_PM1_CONTROL,  ACPI_BITPOSITION_SLEEP_ENABLE,          ACPI_BITMASK_SLEEP_ENABLE},
303
304    /* ACPI_BITREG_ARB_DIS              */   {ACPI_REGISTER_PM2_CONTROL,  ACPI_BITPOSITION_ARB_DISABLE,           ACPI_BITMASK_ARB_DISABLE}
305};
306
307
308ACPI_FIXED_EVENT_INFO       AcpiGbl_FixedEventInfo[ACPI_NUM_FIXED_EVENTS] =
309{
310    /* ACPI_EVENT_PMTIMER       */  {ACPI_BITREG_TIMER_STATUS,          ACPI_BITREG_TIMER_ENABLE,        ACPI_BITMASK_TIMER_STATUS,          ACPI_BITMASK_TIMER_ENABLE},
311    /* ACPI_EVENT_GLOBAL        */  {ACPI_BITREG_GLOBAL_LOCK_STATUS,    ACPI_BITREG_GLOBAL_LOCK_ENABLE,  ACPI_BITMASK_GLOBAL_LOCK_STATUS,    ACPI_BITMASK_GLOBAL_LOCK_ENABLE},
312    /* ACPI_EVENT_POWER_BUTTON  */  {ACPI_BITREG_POWER_BUTTON_STATUS,   ACPI_BITREG_POWER_BUTTON_ENABLE, ACPI_BITMASK_POWER_BUTTON_STATUS,   ACPI_BITMASK_POWER_BUTTON_ENABLE},
313    /* ACPI_EVENT_SLEEP_BUTTON  */  {ACPI_BITREG_SLEEP_BUTTON_STATUS,   ACPI_BITREG_SLEEP_BUTTON_ENABLE, ACPI_BITMASK_SLEEP_BUTTON_STATUS,   ACPI_BITMASK_SLEEP_BUTTON_ENABLE},
314    /* ACPI_EVENT_RTC           */  {ACPI_BITREG_RT_CLOCK_STATUS,       ACPI_BITREG_RT_CLOCK_ENABLE,     ACPI_BITMASK_RT_CLOCK_STATUS,       ACPI_BITMASK_RT_CLOCK_ENABLE},
315};
316
317/*******************************************************************************
318 *
319 * FUNCTION:    AcpiUtGetRegionName
320 *
321 * PARAMETERS:  None.
322 *
323 * RETURN:      Status
324 *
325 * DESCRIPTION: Translate a Space ID into a name string (Debug only)
326 *
327 ******************************************************************************/
328
329/* Region type decoding */
330
331const char        *AcpiGbl_RegionTypes[ACPI_NUM_PREDEFINED_REGIONS] =
332{
333    "SystemMemory",
334    "SystemIO",
335    "PCI_Config",
336    "EmbeddedControl",
337    "SMBus",
338    "SystemCMOS",
339    "PCIBARTarget",
340    "IPMI",
341    "DataTable"
342};
343
344
345char *
346AcpiUtGetRegionName (
347    UINT8                   SpaceId)
348{
349
350    if (SpaceId >= ACPI_USER_REGION_BEGIN)
351    {
352        return ("UserDefinedRegion");
353    }
354    else if (SpaceId >= ACPI_NUM_PREDEFINED_REGIONS)
355    {
356        return ("InvalidSpaceId");
357    }
358
359    return (ACPI_CAST_PTR (char, AcpiGbl_RegionTypes[SpaceId]));
360}
361
362
363/*******************************************************************************
364 *
365 * FUNCTION:    AcpiUtGetEventName
366 *
367 * PARAMETERS:  None.
368 *
369 * RETURN:      Status
370 *
371 * DESCRIPTION: Translate a Event ID into a name string (Debug only)
372 *
373 ******************************************************************************/
374
375/* Event type decoding */
376
377static const char        *AcpiGbl_EventTypes[ACPI_NUM_FIXED_EVENTS] =
378{
379    "PM_Timer",
380    "GlobalLock",
381    "PowerButton",
382    "SleepButton",
383    "RealTimeClock",
384};
385
386
387char *
388AcpiUtGetEventName (
389    UINT32                  EventId)
390{
391
392    if (EventId > ACPI_EVENT_MAX)
393    {
394        return ("InvalidEventID");
395    }
396
397    return (ACPI_CAST_PTR (char, AcpiGbl_EventTypes[EventId]));
398}
399
400
401/*******************************************************************************
402 *
403 * FUNCTION:    AcpiUtGetTypeName
404 *
405 * PARAMETERS:  None.
406 *
407 * RETURN:      Status
408 *
409 * DESCRIPTION: Translate a Type ID into a name string (Debug only)
410 *
411 ******************************************************************************/
412
413/*
414 * Elements of AcpiGbl_NsTypeNames below must match
415 * one-to-one with values of ACPI_OBJECT_TYPE
416 *
417 * The type ACPI_TYPE_ANY (Untyped) is used as a "don't care" when searching;
418 * when stored in a table it really means that we have thus far seen no
419 * evidence to indicate what type is actually going to be stored for this entry.
420 */
421static const char           AcpiGbl_BadType[] = "UNDEFINED";
422
423/* Printable names of the ACPI object types */
424
425static const char           *AcpiGbl_NsTypeNames[] =
426{
427    /* 00 */ "Untyped",
428    /* 01 */ "Integer",
429    /* 02 */ "String",
430    /* 03 */ "Buffer",
431    /* 04 */ "Package",
432    /* 05 */ "FieldUnit",
433    /* 06 */ "Device",
434    /* 07 */ "Event",
435    /* 08 */ "Method",
436    /* 09 */ "Mutex",
437    /* 10 */ "Region",
438    /* 11 */ "Power",
439    /* 12 */ "Processor",
440    /* 13 */ "Thermal",
441    /* 14 */ "BufferField",
442    /* 15 */ "DdbHandle",
443    /* 16 */ "DebugObject",
444    /* 17 */ "RegionField",
445    /* 18 */ "BankField",
446    /* 19 */ "IndexField",
447    /* 20 */ "Reference",
448    /* 21 */ "Alias",
449    /* 22 */ "MethodAlias",
450    /* 23 */ "Notify",
451    /* 24 */ "AddrHandler",
452    /* 25 */ "ResourceDesc",
453    /* 26 */ "ResourceFld",
454    /* 27 */ "Scope",
455    /* 28 */ "Extra",
456    /* 29 */ "Data",
457    /* 30 */ "Invalid"
458};
459
460
461char *
462AcpiUtGetTypeName (
463    ACPI_OBJECT_TYPE        Type)
464{
465
466    if (Type > ACPI_TYPE_INVALID)
467    {
468        return (ACPI_CAST_PTR (char, AcpiGbl_BadType));
469    }
470
471    return (ACPI_CAST_PTR (char, AcpiGbl_NsTypeNames[Type]));
472}
473
474
475char *
476AcpiUtGetObjectTypeName (
477    ACPI_OPERAND_OBJECT     *ObjDesc)
478{
479
480    if (!ObjDesc)
481    {
482        return ("[NULL Object Descriptor]");
483    }
484
485    return (AcpiUtGetTypeName (ObjDesc->Common.Type));
486}
487
488
489/*******************************************************************************
490 *
491 * FUNCTION:    AcpiUtGetNodeName
492 *
493 * PARAMETERS:  Object               - A namespace node
494 *
495 * RETURN:      Pointer to a string
496 *
497 * DESCRIPTION: Validate the node and return the node's ACPI name.
498 *
499 ******************************************************************************/
500
501char *
502AcpiUtGetNodeName (
503    void                    *Object)
504{
505    ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) Object;
506
507
508    /* Must return a string of exactly 4 characters == ACPI_NAME_SIZE */
509
510    if (!Object)
511    {
512        return ("NULL");
513    }
514
515    /* Check for Root node */
516
517    if ((Object == ACPI_ROOT_OBJECT) ||
518        (Object == AcpiGbl_RootNode))
519    {
520        return ("\"\\\" ");
521    }
522
523    /* Descriptor must be a namespace node */
524
525    if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
526    {
527        return ("####");
528    }
529
530    /*
531     * Ensure name is valid. The name was validated/repaired when the node
532     * was created, but make sure it has not been corrupted.
533     */
534    AcpiUtRepairName (Node->Name.Ascii);
535
536    /* Return the name */
537
538    return (Node->Name.Ascii);
539}
540
541
542/*******************************************************************************
543 *
544 * FUNCTION:    AcpiUtGetDescriptorName
545 *
546 * PARAMETERS:  Object               - An ACPI object
547 *
548 * RETURN:      Pointer to a string
549 *
550 * DESCRIPTION: Validate object and return the descriptor type
551 *
552 ******************************************************************************/
553
554/* Printable names of object descriptor types */
555
556static const char           *AcpiGbl_DescTypeNames[] =
557{
558    /* 00 */ "Not a Descriptor",
559    /* 01 */ "Cached",
560    /* 02 */ "State-Generic",
561    /* 03 */ "State-Update",
562    /* 04 */ "State-Package",
563    /* 05 */ "State-Control",
564    /* 06 */ "State-RootParseScope",
565    /* 07 */ "State-ParseScope",
566    /* 08 */ "State-WalkScope",
567    /* 09 */ "State-Result",
568    /* 10 */ "State-Notify",
569    /* 11 */ "State-Thread",
570    /* 12 */ "Walk",
571    /* 13 */ "Parser",
572    /* 14 */ "Operand",
573    /* 15 */ "Node"
574};
575
576
577char *
578AcpiUtGetDescriptorName (
579    void                    *Object)
580{
581
582    if (!Object)
583    {
584        return ("NULL OBJECT");
585    }
586
587    if (ACPI_GET_DESCRIPTOR_TYPE (Object) > ACPI_DESC_TYPE_MAX)
588    {
589        return ("Not a Descriptor");
590    }
591
592    return (ACPI_CAST_PTR (char,
593        AcpiGbl_DescTypeNames[ACPI_GET_DESCRIPTOR_TYPE (Object)]));
594
595}
596
597
598/*******************************************************************************
599 *
600 * FUNCTION:    AcpiUtGetReferenceName
601 *
602 * PARAMETERS:  Object               - An ACPI reference object
603 *
604 * RETURN:      Pointer to a string
605 *
606 * DESCRIPTION: Decode a reference object sub-type to a string.
607 *
608 ******************************************************************************/
609
610/* Printable names of reference object sub-types */
611
612static const char           *AcpiGbl_RefClassNames[] =
613{
614    /* 00 */ "Local",
615    /* 01 */ "Argument",
616    /* 02 */ "RefOf",
617    /* 03 */ "Index",
618    /* 04 */ "DdbHandle",
619    /* 05 */ "Named Object",
620    /* 06 */ "Debug"
621};
622
623const char *
624AcpiUtGetReferenceName (
625    ACPI_OPERAND_OBJECT     *Object)
626{
627
628    if (!Object)
629    {
630        return ("NULL Object");
631    }
632
633    if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
634    {
635        return ("Not an Operand object");
636    }
637
638    if (Object->Common.Type != ACPI_TYPE_LOCAL_REFERENCE)
639    {
640        return ("Not a Reference object");
641    }
642
643    if (Object->Reference.Class > ACPI_REFCLASS_MAX)
644    {
645        return ("Unknown Reference class");
646    }
647
648    return (AcpiGbl_RefClassNames[Object->Reference.Class]);
649}
650
651
652#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
653/*
654 * Strings and procedures used for debug only
655 */
656
657/*******************************************************************************
658 *
659 * FUNCTION:    AcpiUtGetMutexName
660 *
661 * PARAMETERS:  MutexId         - The predefined ID for this mutex.
662 *
663 * RETURN:      String containing the name of the mutex. Always returns a valid
664 *              pointer.
665 *
666 * DESCRIPTION: Translate a mutex ID into a name string (Debug only)
667 *
668 ******************************************************************************/
669
670char *
671AcpiUtGetMutexName (
672    UINT32                  MutexId)
673{
674
675    if (MutexId > ACPI_MAX_MUTEX)
676    {
677        return ("Invalid Mutex ID");
678    }
679
680    return (AcpiGbl_MutexNames[MutexId]);
681}
682
683
684/*******************************************************************************
685 *
686 * FUNCTION:    AcpiUtGetNotifyName
687 *
688 * PARAMETERS:  NotifyValue     - Value from the Notify() request
689 *
690 * RETURN:      String corresponding to the Notify Value.
691 *
692 * DESCRIPTION: Translate a Notify Value to a notify namestring.
693 *
694 ******************************************************************************/
695
696/* Names for Notify() values, used for debug output */
697
698static const char        *AcpiGbl_NotifyValueNames[] =
699{
700    "Bus Check",
701    "Device Check",
702    "Device Wake",
703    "Eject Request",
704    "Device Check Light",
705    "Frequency Mismatch",
706    "Bus Mode Mismatch",
707    "Power Fault",
708    "Capabilities Check",
709    "Device PLD Check",
710    "Reserved",
711    "System Locality Update"
712};
713
714const char *
715AcpiUtGetNotifyName (
716    UINT32                  NotifyValue)
717{
718
719    if (NotifyValue <= ACPI_NOTIFY_MAX)
720    {
721        return (AcpiGbl_NotifyValueNames[NotifyValue]);
722    }
723    else if (NotifyValue <= ACPI_MAX_SYS_NOTIFY)
724    {
725        return ("Reserved");
726    }
727    else /* Greater or equal to 0x80 */
728    {
729        return ("**Device Specific**");
730    }
731}
732#endif
733
734
735/*******************************************************************************
736 *
737 * FUNCTION:    AcpiUtValidObjectType
738 *
739 * PARAMETERS:  Type            - Object type to be validated
740 *
741 * RETURN:      TRUE if valid object type, FALSE otherwise
742 *
743 * DESCRIPTION: Validate an object type
744 *
745 ******************************************************************************/
746
747BOOLEAN
748AcpiUtValidObjectType (
749    ACPI_OBJECT_TYPE        Type)
750{
751
752    if (Type > ACPI_TYPE_LOCAL_MAX)
753    {
754        /* Note: Assumes all TYPEs are contiguous (external/local) */
755
756        return (FALSE);
757    }
758
759    return (TRUE);
760}
761
762
763/*******************************************************************************
764 *
765 * FUNCTION:    AcpiUtInitGlobals
766 *
767 * PARAMETERS:  None
768 *
769 * RETURN:      Status
770 *
771 * DESCRIPTION: Init library globals.  All globals that require specific
772 *              initialization should be initialized here!
773 *
774 ******************************************************************************/
775
776ACPI_STATUS
777AcpiUtInitGlobals (
778    void)
779{
780    ACPI_STATUS             Status;
781    UINT32                  i;
782
783
784    ACPI_FUNCTION_TRACE (UtInitGlobals);
785
786
787    /* Create all memory caches */
788
789    Status = AcpiUtCreateCaches ();
790    if (ACPI_FAILURE (Status))
791    {
792        return_ACPI_STATUS (Status);
793    }
794
795    /* Mutex locked flags */
796
797    for (i = 0; i < ACPI_NUM_MUTEX; i++)
798    {
799        AcpiGbl_MutexInfo[i].Mutex          = NULL;
800        AcpiGbl_MutexInfo[i].ThreadId       = ACPI_MUTEX_NOT_ACQUIRED;
801        AcpiGbl_MutexInfo[i].UseCount       = 0;
802    }
803
804    for (i = 0; i < ACPI_NUM_OWNERID_MASKS; i++)
805    {
806        AcpiGbl_OwnerIdMask[i]              = 0;
807    }
808
809    /* Last OwnerID is never valid */
810
811    AcpiGbl_OwnerIdMask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000;
812
813    /* Event counters */
814
815    AcpiMethodCount                     = 0;
816    AcpiSciCount                        = 0;
817    AcpiGpeCount                        = 0;
818
819    for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
820    {
821        AcpiFixedEventCount[i]              = 0;
822    }
823
824    /* GPE support */
825
826    AcpiGbl_AllGpesInitialized          = FALSE;
827    AcpiGbl_GpeXruptListHead            = NULL;
828    AcpiGbl_GpeFadtBlocks[0]            = NULL;
829    AcpiGbl_GpeFadtBlocks[1]            = NULL;
830    AcpiCurrentGpeCount                 = 0;
831
832    /* Global handlers */
833
834    AcpiGbl_SystemNotify.Handler        = NULL;
835    AcpiGbl_DeviceNotify.Handler        = NULL;
836    AcpiGbl_ExceptionHandler            = NULL;
837    AcpiGbl_InitHandler                 = NULL;
838    AcpiGbl_TableHandler                = NULL;
839    AcpiGbl_InterfaceHandler            = NULL;
840    AcpiGbl_GlobalEventHandler          = NULL;
841
842    /* Global Lock support */
843
844    AcpiGbl_GlobalLockSemaphore         = NULL;
845    AcpiGbl_GlobalLockMutex             = NULL;
846    AcpiGbl_GlobalLockAcquired          = FALSE;
847    AcpiGbl_GlobalLockHandle            = 0;
848    AcpiGbl_GlobalLockPresent           = FALSE;
849
850    /* Miscellaneous variables */
851
852    AcpiGbl_DSDT                        = NULL;
853    AcpiGbl_CmSingleStep                = FALSE;
854    AcpiGbl_DbTerminateThreads          = FALSE;
855    AcpiGbl_Shutdown                    = FALSE;
856    AcpiGbl_NsLookupCount               = 0;
857    AcpiGbl_PsFindCount                 = 0;
858    AcpiGbl_AcpiHardwarePresent         = TRUE;
859    AcpiGbl_LastOwnerIdIndex            = 0;
860    AcpiGbl_NextOwnerIdOffset           = 0;
861    AcpiGbl_TraceMethodName             = 0;
862    AcpiGbl_TraceDbgLevel               = 0;
863    AcpiGbl_TraceDbgLayer               = 0;
864    AcpiGbl_DebuggerConfiguration       = DEBUGGER_THREADING;
865    AcpiGbl_DbOutputFlags               = ACPI_DB_CONSOLE_OUTPUT;
866    AcpiGbl_OsiData                     = 0;
867    AcpiGbl_OsiMutex                    = NULL;
868
869    /* Hardware oriented */
870
871    AcpiGbl_EventsInitialized           = FALSE;
872    AcpiGbl_SystemAwakeAndRunning       = TRUE;
873
874    /* Namespace */
875
876    AcpiGbl_ModuleCodeList              = NULL;
877    AcpiGbl_RootNode                    = NULL;
878    AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
879    AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
880    AcpiGbl_RootNodeStruct.Type         = ACPI_TYPE_DEVICE;
881    AcpiGbl_RootNodeStruct.Parent       = NULL;
882    AcpiGbl_RootNodeStruct.Child        = NULL;
883    AcpiGbl_RootNodeStruct.Peer         = NULL;
884    AcpiGbl_RootNodeStruct.Object       = NULL;
885
886
887#ifdef ACPI_DISASSEMBLER
888    AcpiGbl_ExternalList                = NULL;
889#endif
890
891#ifdef ACPI_DEBUG_OUTPUT
892    AcpiGbl_LowestStackPointer          = ACPI_CAST_PTR (ACPI_SIZE, ACPI_SIZE_MAX);
893#endif
894
895#ifdef ACPI_DBG_TRACK_ALLOCATIONS
896    AcpiGbl_DisplayFinalMemStats        = FALSE;
897    AcpiGbl_DisableMemTracking          = FALSE;
898#endif
899
900    return_ACPI_STATUS (AE_OK);
901}
902
903/* Public globals */
904
905ACPI_EXPORT_SYMBOL (AcpiGbl_FADT)
906ACPI_EXPORT_SYMBOL (AcpiDbgLevel)
907ACPI_EXPORT_SYMBOL (AcpiDbgLayer)
908ACPI_EXPORT_SYMBOL (AcpiGpeCount)
909ACPI_EXPORT_SYMBOL (AcpiCurrentGpeCount)
910
911
912