vserver 1.9.3
[linux-2.6.git] / drivers / acpi / utilities / utglobal.c
1 /******************************************************************************
2  *
3  * Module Name: utglobal - Global variables for the ACPI subsystem
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2004, R. Byron Moore
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 DEFINE_ACPI_GLOBALS
45
46 #include <acpi/acpi.h>
47 #include <acpi/acnamesp.h>
48
49 #define _COMPONENT          ACPI_UTILITIES
50          ACPI_MODULE_NAME    ("utglobal")
51
52
53 /******************************************************************************
54  *
55  * FUNCTION:    acpi_format_exception
56  *
57  * PARAMETERS:  Status       - The acpi_status code to be formatted
58  *
59  * RETURN:      A string containing the exception  text
60  *
61  * DESCRIPTION: This function translates an ACPI exception into an ASCII string.
62  *
63  ******************************************************************************/
64
65 const char *
66 acpi_format_exception (
67         acpi_status                     status)
68 {
69         const char                      *exception = "UNKNOWN_STATUS_CODE";
70         acpi_status                     sub_status;
71
72
73         ACPI_FUNCTION_NAME ("format_exception");
74
75
76         sub_status = (status & ~AE_CODE_MASK);
77
78         switch (status & AE_CODE_MASK) {
79         case AE_CODE_ENVIRONMENTAL:
80
81                 if (sub_status <= AE_CODE_ENV_MAX) {
82                         exception = acpi_gbl_exception_names_env [sub_status];
83                         break;
84                 }
85                 goto unknown;
86
87         case AE_CODE_PROGRAMMER:
88
89                 if (sub_status <= AE_CODE_PGM_MAX) {
90                         exception = acpi_gbl_exception_names_pgm [sub_status -1];
91                         break;
92                 }
93                 goto unknown;
94
95         case AE_CODE_ACPI_TABLES:
96
97                 if (sub_status <= AE_CODE_TBL_MAX) {
98                         exception = acpi_gbl_exception_names_tbl [sub_status -1];
99                         break;
100                 }
101                 goto unknown;
102
103         case AE_CODE_AML:
104
105                 if (sub_status <= AE_CODE_AML_MAX) {
106                         exception = acpi_gbl_exception_names_aml [sub_status -1];
107                         break;
108                 }
109                 goto unknown;
110
111         case AE_CODE_CONTROL:
112
113                 if (sub_status <= AE_CODE_CTRL_MAX) {
114                         exception = acpi_gbl_exception_names_ctrl [sub_status -1];
115                         break;
116                 }
117                 goto unknown;
118
119         default:
120                 goto unknown;
121         }
122
123
124         return ((const char *) exception);
125
126 unknown:
127
128         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown exception code: 0x%8.8X\n", status));
129         return ((const char *) exception);
130 }
131
132
133 /******************************************************************************
134  *
135  * Static global variable initialization.
136  *
137  ******************************************************************************/
138
139 /*
140  * We want the debug switches statically initialized so they
141  * are already set when the debugger is entered.
142  */
143
144 /* Debug switch - level and trace mask */
145 u32                                 acpi_dbg_level = 0;
146
147 /* Debug switch - layer (component) mask */
148
149 u32                                 acpi_dbg_layer = 0;
150 u32                                 acpi_gbl_nesting_level = 0;
151
152
153 /* Debugger globals */
154
155 u8                                  acpi_gbl_db_terminate_threads = FALSE;
156 u8                                  acpi_gbl_abort_method = FALSE;
157 u8                                  acpi_gbl_method_executing = FALSE;
158
159 /* System flags */
160
161 u32                                 acpi_gbl_startup_flags = 0;
162
163 /* System starts uninitialized */
164
165 u8                                  acpi_gbl_shutdown = TRUE;
166
167 const u8                            acpi_gbl_decode_to8bit [8] = {1,2,4,8,16,32,64,128};
168
169 const char                          *acpi_gbl_sleep_state_names[ACPI_S_STATE_COUNT] =
170 {
171         "\\_S0_",
172         "\\_S1_",
173         "\\_S2_",
174         "\\_S3_",
175         "\\_S4_",
176         "\\_S5_"
177 };
178
179 const char                          *acpi_gbl_highest_dstate_names[4] =
180 {
181         "_S1D",
182         "_S2D",
183         "_S3D",
184         "_S4D"
185 };
186
187 /*
188  * Strings supported by the _OSI predefined (internal) method.
189  * When adding strings, be sure to update ACPI_NUM_OSI_STRINGS.
190  */
191 const char                          *acpi_gbl_valid_osi_strings[ACPI_NUM_OSI_STRINGS] =
192 {
193         "Linux",
194         "Windows 2000",
195         "Windows 2001",
196         "Windows 2001.1",
197         "Windows 2001 SP0",
198         "Windows 2001 SP1",
199         "Windows 2001 SP2",
200         "Windows 2001 SP3",
201         "Windows 2001 SP4"
202 };
203
204
205 /******************************************************************************
206  *
207  * Namespace globals
208  *
209  ******************************************************************************/
210
211
212 /*
213  * Predefined ACPI Names (Built-in to the Interpreter)
214  *
215  * NOTES:
216  * 1) _SB_ is defined to be a device to allow \_SB_._INI to be run
217  *    during the initialization sequence.
218  */
219 const struct acpi_predefined_names      acpi_gbl_pre_defined_names[] =
220 { {"_GPE",    ACPI_TYPE_LOCAL_SCOPE,      NULL},
221         {"_PR_",    ACPI_TYPE_LOCAL_SCOPE,      NULL},
222         {"_SB_",    ACPI_TYPE_DEVICE,           NULL},
223         {"_SI_",    ACPI_TYPE_LOCAL_SCOPE,      NULL},
224         {"_TZ_",    ACPI_TYPE_THERMAL,          NULL},
225         {"_REV",    ACPI_TYPE_INTEGER,          "2"},
226         {"_OS_",    ACPI_TYPE_STRING,           ACPI_OS_NAME},
227         {"_GL_",    ACPI_TYPE_MUTEX,            "0"},
228
229 #if !defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY)
230         {"_OSI",    ACPI_TYPE_METHOD,           "1"},
231 #endif
232         {NULL,      ACPI_TYPE_ANY,              NULL}              /* Table terminator */
233 };
234
235
236 /*
237  * Properties of the ACPI Object Types, both internal and external.
238  * The table is indexed by values of acpi_object_type
239  */
240 const u8                                acpi_gbl_ns_properties[] =
241 {
242         ACPI_NS_NORMAL,                     /* 00 Any              */
243         ACPI_NS_NORMAL,                     /* 01 Number           */
244         ACPI_NS_NORMAL,                     /* 02 String           */
245         ACPI_NS_NORMAL,                     /* 03 Buffer           */
246         ACPI_NS_NORMAL,                     /* 04 Package          */
247         ACPI_NS_NORMAL,                     /* 05 field_unit       */
248         ACPI_NS_NEWSCOPE,                   /* 06 Device           */
249         ACPI_NS_NORMAL,                     /* 07 Event            */
250         ACPI_NS_NEWSCOPE,                   /* 08 Method           */
251         ACPI_NS_NORMAL,                     /* 09 Mutex            */
252         ACPI_NS_NORMAL,                     /* 10 Region           */
253         ACPI_NS_NEWSCOPE,                   /* 11 Power            */
254         ACPI_NS_NEWSCOPE,                   /* 12 Processor        */
255         ACPI_NS_NEWSCOPE,                   /* 13 Thermal          */
256         ACPI_NS_NORMAL,                     /* 14 buffer_field     */
257         ACPI_NS_NORMAL,                     /* 15 ddb_handle       */
258         ACPI_NS_NORMAL,                     /* 16 Debug Object     */
259         ACPI_NS_NORMAL,                     /* 17 def_field        */
260         ACPI_NS_NORMAL,                     /* 18 bank_field       */
261         ACPI_NS_NORMAL,                     /* 19 index_field      */
262         ACPI_NS_NORMAL,                     /* 20 Reference        */
263         ACPI_NS_NORMAL,                     /* 21 Alias            */
264         ACPI_NS_NORMAL,                     /* 22 method_alias     */
265         ACPI_NS_NORMAL,                     /* 23 Notify           */
266         ACPI_NS_NORMAL,                     /* 24 Address Handler  */
267         ACPI_NS_NEWSCOPE | ACPI_NS_LOCAL,   /* 25 Resource Desc    */
268         ACPI_NS_NEWSCOPE | ACPI_NS_LOCAL,   /* 26 Resource Field   */
269         ACPI_NS_NEWSCOPE,                   /* 27 Scope            */
270         ACPI_NS_NORMAL,                     /* 28 Extra            */
271         ACPI_NS_NORMAL,                     /* 29 Data             */
272         ACPI_NS_NORMAL                      /* 30 Invalid          */
273 };
274
275
276 /* Hex to ASCII conversion table */
277
278 static const char                   acpi_gbl_hex_to_ascii[] =
279                           {'0','1','2','3','4','5','6','7',
280                                          '8','9','A','B','C','D','E','F'};
281
282 /*****************************************************************************
283  *
284  * FUNCTION:    acpi_ut_hex_to_ascii_char
285  *
286  * PARAMETERS:  Integer             - Contains the hex digit
287  *              Position            - bit position of the digit within the
288  *                                    integer
289  *
290  * RETURN:      Ascii character
291  *
292  * DESCRIPTION: Convert a hex digit to an ascii character
293  *
294  ****************************************************************************/
295
296 char
297 acpi_ut_hex_to_ascii_char (
298         acpi_integer                    integer,
299         u32                             position)
300 {
301
302         return (acpi_gbl_hex_to_ascii[(integer >> position) & 0xF]);
303 }
304
305
306 /******************************************************************************
307  *
308  * Table name globals
309  *
310  * NOTE: This table includes ONLY the ACPI tables that the subsystem consumes.
311  * it is NOT an exhaustive list of all possible ACPI tables.  All ACPI tables
312  * that are not used by the subsystem are simply ignored.
313  *
314  * Do NOT add any table to this list that is not consumed directly by this
315  * subsystem.
316  *
317  ******************************************************************************/
318
319 struct acpi_table_list              acpi_gbl_table_lists[NUM_ACPI_TABLE_TYPES];
320
321 struct acpi_table_support           acpi_gbl_table_data[NUM_ACPI_TABLE_TYPES] =
322 {
323         /***********    Name,   Signature, Global typed pointer     Signature size,      Type                  How many allowed?,    Contains valid AML? */
324
325         /* RSDP 0 */ {RSDP_NAME, RSDP_SIG, NULL,                    sizeof (RSDP_SIG)-1, ACPI_TABLE_ROOT     | ACPI_TABLE_SINGLE},
326         /* DSDT 1 */ {DSDT_SIG,  DSDT_SIG, (void *) &acpi_gbl_DSDT, sizeof (DSDT_SIG)-1, ACPI_TABLE_SECONDARY| ACPI_TABLE_SINGLE   | ACPI_TABLE_EXECUTABLE},
327         /* FADT 2 */ {FADT_SIG,  FADT_SIG, (void *) &acpi_gbl_FADT, sizeof (FADT_SIG)-1, ACPI_TABLE_PRIMARY  | ACPI_TABLE_SINGLE},
328         /* FACS 3 */ {FACS_SIG,  FACS_SIG, (void *) &acpi_gbl_FACS, sizeof (FACS_SIG)-1, ACPI_TABLE_SECONDARY| ACPI_TABLE_SINGLE},
329         /* PSDT 4 */ {PSDT_SIG,  PSDT_SIG, NULL,                    sizeof (PSDT_SIG)-1, ACPI_TABLE_PRIMARY  | ACPI_TABLE_MULTIPLE | ACPI_TABLE_EXECUTABLE},
330         /* SSDT 5 */ {SSDT_SIG,  SSDT_SIG, NULL,                    sizeof (SSDT_SIG)-1, ACPI_TABLE_PRIMARY  | ACPI_TABLE_MULTIPLE | ACPI_TABLE_EXECUTABLE},
331         /* XSDT 6 */ {XSDT_SIG,  XSDT_SIG, NULL,                    sizeof (RSDT_SIG)-1, ACPI_TABLE_ROOT     | ACPI_TABLE_SINGLE},
332 };
333
334
335 /******************************************************************************
336  *
337  * Event and Hardware globals
338  *
339  ******************************************************************************/
340
341 struct acpi_bit_register_info       acpi_gbl_bit_register_info[ACPI_NUM_BITREG] =
342 {
343         /* Name                                     Parent Register             Register Bit Position                   Register Bit Mask       */
344
345         /* ACPI_BITREG_TIMER_STATUS         */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_TIMER_STATUS,          ACPI_BITMASK_TIMER_STATUS},
346         /* ACPI_BITREG_BUS_MASTER_STATUS    */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_BUS_MASTER_STATUS,     ACPI_BITMASK_BUS_MASTER_STATUS},
347         /* ACPI_BITREG_GLOBAL_LOCK_STATUS   */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_GLOBAL_LOCK_STATUS,    ACPI_BITMASK_GLOBAL_LOCK_STATUS},
348         /* ACPI_BITREG_POWER_BUTTON_STATUS  */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_POWER_BUTTON_STATUS,   ACPI_BITMASK_POWER_BUTTON_STATUS},
349         /* ACPI_BITREG_SLEEP_BUTTON_STATUS  */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_SLEEP_BUTTON_STATUS,   ACPI_BITMASK_SLEEP_BUTTON_STATUS},
350         /* ACPI_BITREG_RT_CLOCK_STATUS      */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_RT_CLOCK_STATUS,       ACPI_BITMASK_RT_CLOCK_STATUS},
351         /* ACPI_BITREG_WAKE_STATUS          */   {ACPI_REGISTER_PM1_STATUS,   ACPI_BITPOSITION_WAKE_STATUS,           ACPI_BITMASK_WAKE_STATUS},
352
353         /* ACPI_BITREG_TIMER_ENABLE         */   {ACPI_REGISTER_PM1_ENABLE,   ACPI_BITPOSITION_TIMER_ENABLE,          ACPI_BITMASK_TIMER_ENABLE},
354         /* ACPI_BITREG_GLOBAL_LOCK_ENABLE   */   {ACPI_REGISTER_PM1_ENABLE,   ACPI_BITPOSITION_GLOBAL_LOCK_ENABLE,    ACPI_BITMASK_GLOBAL_LOCK_ENABLE},
355         /* ACPI_BITREG_POWER_BUTTON_ENABLE  */   {ACPI_REGISTER_PM1_ENABLE,   ACPI_BITPOSITION_POWER_BUTTON_ENABLE,   ACPI_BITMASK_POWER_BUTTON_ENABLE},
356         /* ACPI_BITREG_SLEEP_BUTTON_ENABLE  */   {ACPI_REGISTER_PM1_ENABLE,   ACPI_BITPOSITION_SLEEP_BUTTON_ENABLE,   ACPI_BITMASK_SLEEP_BUTTON_ENABLE},
357         /* ACPI_BITREG_RT_CLOCK_ENABLE      */   {ACPI_REGISTER_PM1_ENABLE,   ACPI_BITPOSITION_RT_CLOCK_ENABLE,       ACPI_BITMASK_RT_CLOCK_ENABLE},
358         /* ACPI_BITREG_WAKE_ENABLE          */   {ACPI_REGISTER_PM1_ENABLE,   0,                                      0},
359
360         /* ACPI_BITREG_SCI_ENABLE           */   {ACPI_REGISTER_PM1_CONTROL,  ACPI_BITPOSITION_SCI_ENABLE,            ACPI_BITMASK_SCI_ENABLE},
361         /* ACPI_BITREG_BUS_MASTER_RLD       */   {ACPI_REGISTER_PM1_CONTROL,  ACPI_BITPOSITION_BUS_MASTER_RLD,        ACPI_BITMASK_BUS_MASTER_RLD},
362         /* ACPI_BITREG_GLOBAL_LOCK_RELEASE  */   {ACPI_REGISTER_PM1_CONTROL,  ACPI_BITPOSITION_GLOBAL_LOCK_RELEASE,   ACPI_BITMASK_GLOBAL_LOCK_RELEASE},
363         /* ACPI_BITREG_SLEEP_TYPE_A         */   {ACPI_REGISTER_PM1_CONTROL,  ACPI_BITPOSITION_SLEEP_TYPE_X,          ACPI_BITMASK_SLEEP_TYPE_X},
364         /* ACPI_BITREG_SLEEP_TYPE_B         */   {ACPI_REGISTER_PM1_CONTROL,  ACPI_BITPOSITION_SLEEP_TYPE_X,          ACPI_BITMASK_SLEEP_TYPE_X},
365         /* ACPI_BITREG_SLEEP_ENABLE         */   {ACPI_REGISTER_PM1_CONTROL,  ACPI_BITPOSITION_SLEEP_ENABLE,          ACPI_BITMASK_SLEEP_ENABLE},
366
367         /* ACPI_BITREG_ARB_DIS              */   {ACPI_REGISTER_PM2_CONTROL,  ACPI_BITPOSITION_ARB_DISABLE,           ACPI_BITMASK_ARB_DISABLE}
368 };
369
370
371 struct acpi_fixed_event_info        acpi_gbl_fixed_event_info[ACPI_NUM_FIXED_EVENTS] =
372 {
373         /* ACPI_EVENT_PMTIMER       */  {ACPI_BITREG_TIMER_STATUS,          ACPI_BITREG_TIMER_ENABLE,        ACPI_BITMASK_TIMER_STATUS,          ACPI_BITMASK_TIMER_ENABLE},
374         /* ACPI_EVENT_GLOBAL        */  {ACPI_BITREG_GLOBAL_LOCK_STATUS,    ACPI_BITREG_GLOBAL_LOCK_ENABLE,  ACPI_BITMASK_GLOBAL_LOCK_STATUS,    ACPI_BITMASK_GLOBAL_LOCK_ENABLE},
375         /* ACPI_EVENT_POWER_BUTTON  */  {ACPI_BITREG_POWER_BUTTON_STATUS,   ACPI_BITREG_POWER_BUTTON_ENABLE, ACPI_BITMASK_POWER_BUTTON_STATUS,   ACPI_BITMASK_POWER_BUTTON_ENABLE},
376         /* ACPI_EVENT_SLEEP_BUTTON  */  {ACPI_BITREG_SLEEP_BUTTON_STATUS,   ACPI_BITREG_SLEEP_BUTTON_ENABLE, ACPI_BITMASK_SLEEP_BUTTON_STATUS,   ACPI_BITMASK_SLEEP_BUTTON_ENABLE},
377         /* ACPI_EVENT_RTC           */  {ACPI_BITREG_RT_CLOCK_STATUS,       ACPI_BITREG_RT_CLOCK_ENABLE,     ACPI_BITMASK_RT_CLOCK_STATUS,       ACPI_BITMASK_RT_CLOCK_ENABLE},
378 };
379
380 /*****************************************************************************
381  *
382  * FUNCTION:    acpi_ut_get_region_name
383  *
384  * PARAMETERS:  None.
385  *
386  * RETURN:      Status
387  *
388  * DESCRIPTION: Translate a Space ID into a name string (Debug only)
389  *
390  ****************************************************************************/
391
392 /* Region type decoding */
393
394 const char                *acpi_gbl_region_types[ACPI_NUM_PREDEFINED_REGIONS] =
395 {
396 /*! [Begin] no source code translation (keep these ASL Keywords as-is) */
397         "SystemMemory",
398         "SystemIO",
399         "PCI_Config",
400         "EmbeddedControl",
401         "SMBus",
402         "CMOS",
403         "PCIBARTarget",
404         "DataTable"
405 /*! [End] no source code translation !*/
406 };
407
408
409 char *
410 acpi_ut_get_region_name (
411         u8                              space_id)
412 {
413
414         if (space_id >= ACPI_USER_REGION_BEGIN)
415         {
416                 return ("user_defined_region");
417         }
418
419         else if (space_id >= ACPI_NUM_PREDEFINED_REGIONS)
420         {
421                 return ("invalid_space_id");
422         }
423
424         return ((char *) acpi_gbl_region_types[space_id]);
425 }
426
427
428 /*****************************************************************************
429  *
430  * FUNCTION:    acpi_ut_get_event_name
431  *
432  * PARAMETERS:  None.
433  *
434  * RETURN:      Status
435  *
436  * DESCRIPTION: Translate a Event ID into a name string (Debug only)
437  *
438  ****************************************************************************/
439
440 /* Event type decoding */
441
442 static const char                *acpi_gbl_event_types[ACPI_NUM_FIXED_EVENTS] =
443 {
444         "PM_Timer",
445         "global_lock",
446         "power_button",
447         "sleep_button",
448         "real_time_clock",
449 };
450
451
452 char *
453 acpi_ut_get_event_name (
454         u32                             event_id)
455 {
456
457         if (event_id > ACPI_EVENT_MAX)
458         {
459                 return ("invalid_event_iD");
460         }
461
462         return ((char *) acpi_gbl_event_types[event_id]);
463 }
464
465
466 /*****************************************************************************
467  *
468  * FUNCTION:    acpi_ut_get_type_name
469  *
470  * PARAMETERS:  None.
471  *
472  * RETURN:      Status
473  *
474  * DESCRIPTION: Translate a Type ID into a name string (Debug only)
475  *
476  ****************************************************************************/
477
478 /*
479  * Elements of acpi_gbl_ns_type_names below must match
480  * one-to-one with values of acpi_object_type
481  *
482  * The type ACPI_TYPE_ANY (Untyped) is used as a "don't care" when searching; when
483  * stored in a table it really means that we have thus far seen no evidence to
484  * indicate what type is actually going to be stored for this entry.
485  */
486 static const char                   acpi_gbl_bad_type[] = "UNDEFINED";
487 #define TYPE_NAME_LENGTH    12                           /* Maximum length of each string */
488
489 static const char                   *acpi_gbl_ns_type_names[] = /* printable names of ACPI types */
490 {
491         /* 00 */ "Untyped",
492         /* 01 */ "Integer",
493         /* 02 */ "String",
494         /* 03 */ "Buffer",
495         /* 04 */ "Package",
496         /* 05 */ "field_unit",
497         /* 06 */ "Device",
498         /* 07 */ "Event",
499         /* 08 */ "Method",
500         /* 09 */ "Mutex",
501         /* 10 */ "Region",
502         /* 11 */ "Power",
503         /* 12 */ "Processor",
504         /* 13 */ "Thermal",
505         /* 14 */ "buffer_field",
506         /* 15 */ "ddb_handle",
507         /* 16 */ "debug_object",
508         /* 17 */ "region_field",
509         /* 18 */ "bank_field",
510         /* 19 */ "index_field",
511         /* 20 */ "Reference",
512         /* 21 */ "Alias",
513         /* 22 */ "method_alias",
514         /* 23 */ "Notify",
515         /* 24 */ "addr_handler",
516         /* 25 */ "resource_desc",
517         /* 26 */ "resource_fld",
518         /* 27 */ "Scope",
519         /* 28 */ "Extra",
520         /* 29 */ "Data",
521         /* 30 */ "Invalid"
522 };
523
524
525 char *
526 acpi_ut_get_type_name (
527         acpi_object_type                type)
528 {
529
530         if (type > ACPI_TYPE_INVALID)
531         {
532                 return ((char *) acpi_gbl_bad_type);
533         }
534
535         return ((char *) acpi_gbl_ns_type_names[type]);
536 }
537
538
539 char *
540 acpi_ut_get_object_type_name (
541         union acpi_operand_object       *obj_desc)
542 {
543
544         if (!obj_desc)
545         {
546                 return ("[NULL Object Descriptor]");
547         }
548
549         return (acpi_ut_get_type_name (ACPI_GET_OBJECT_TYPE (obj_desc)));
550 }
551
552
553 /*****************************************************************************
554  *
555  * FUNCTION:    acpi_ut_get_node_name
556  *
557  * PARAMETERS:  Object               - A namespace node
558  *
559  * RETURN:      Pointer to a string
560  *
561  * DESCRIPTION: Validate the node and return the node's ACPI name.
562  *
563  ****************************************************************************/
564
565 char *
566 acpi_ut_get_node_name (
567         void                            *object)
568 {
569         struct acpi_namespace_node      *node = (struct acpi_namespace_node *) object;
570
571
572         /* Must return a string of exactly 4 characters == ACPI_NAME_SIZE */
573
574         if (!object)
575         {
576                 return ("NULL");
577         }
578
579         /* Check for Root node */
580
581         if ((object == ACPI_ROOT_OBJECT) ||
582                 (object == acpi_gbl_root_node))
583         {
584                 return ("\"\\\" ");
585         }
586
587         /* Descriptor must be a namespace node */
588
589         if (node->descriptor != ACPI_DESC_TYPE_NAMED)
590         {
591                 return ("####");
592         }
593
594         /* Name must be a valid ACPI name */
595
596         if (!acpi_ut_valid_acpi_name (* (u32 *) node->name.ascii))
597         {
598                 return ("????");
599         }
600
601         /* Return the name */
602
603         return (node->name.ascii);
604 }
605
606
607 /*****************************************************************************
608  *
609  * FUNCTION:    acpi_ut_get_descriptor_name
610  *
611  * PARAMETERS:  Object               - An ACPI object
612  *
613  * RETURN:      Pointer to a string
614  *
615  * DESCRIPTION: Validate object and return the descriptor type
616  *
617  ****************************************************************************/
618
619 static const char                   *acpi_gbl_desc_type_names[] = /* printable names of descriptor types */
620 {
621         /* 00 */ "Invalid",
622         /* 01 */ "Cached",
623         /* 02 */ "State-Generic",
624         /* 03 */ "State-Update",
625         /* 04 */ "State-Package",
626         /* 05 */ "State-Control",
627         /* 06 */ "State-root_parse_scope",
628         /* 07 */ "State-parse_scope",
629         /* 08 */ "State-walk_scope",
630         /* 09 */ "State-Result",
631         /* 10 */ "State-Notify",
632         /* 11 */ "State-Thread",
633         /* 12 */ "Walk",
634         /* 13 */ "Parser",
635         /* 14 */ "Operand",
636         /* 15 */ "Node"
637 };
638
639
640 char *
641 acpi_ut_get_descriptor_name (
642         void                            *object)
643 {
644
645         if (!object)
646         {
647                 return ("NULL OBJECT");
648         }
649
650         if (ACPI_GET_DESCRIPTOR_TYPE (object) > ACPI_DESC_TYPE_MAX)
651         {
652                 return ((char *) acpi_gbl_bad_type);
653         }
654
655         return ((char *) acpi_gbl_desc_type_names[ACPI_GET_DESCRIPTOR_TYPE (object)]);
656
657 }
658
659
660 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
661 /*
662  * Strings and procedures used for debug only
663  */
664
665 /*****************************************************************************
666  *
667  * FUNCTION:    acpi_ut_get_mutex_name
668  *
669  * PARAMETERS:  None.
670  *
671  * RETURN:      Status
672  *
673  * DESCRIPTION: Translate a mutex ID into a name string (Debug only)
674  *
675  ****************************************************************************/
676
677 char *
678 acpi_ut_get_mutex_name (
679         u32                             mutex_id)
680 {
681
682         if (mutex_id > MAX_MUTEX)
683         {
684                 return ("Invalid Mutex ID");
685         }
686
687         return (acpi_gbl_mutex_names[mutex_id]);
688 }
689
690 #endif
691
692
693 /*****************************************************************************
694  *
695  * FUNCTION:    acpi_ut_valid_object_type
696  *
697  * PARAMETERS:  Type            - Object type to be validated
698  *
699  * RETURN:      TRUE if valid object type
700  *
701  * DESCRIPTION: Validate an object type
702  *
703  ****************************************************************************/
704
705 u8
706 acpi_ut_valid_object_type (
707         acpi_object_type                type)
708 {
709
710         if (type > ACPI_TYPE_LOCAL_MAX)
711         {
712                 /* Note: Assumes all TYPEs are contiguous (external/local) */
713
714                 return (FALSE);
715         }
716
717         return (TRUE);
718 }
719
720
721 /****************************************************************************
722  *
723  * FUNCTION:    acpi_ut_allocate_owner_id
724  *
725  * PARAMETERS:  id_type         - Type of ID (method or table)
726  *
727  * DESCRIPTION: Allocate a table or method owner id
728  *
729  ***************************************************************************/
730
731 acpi_owner_id
732 acpi_ut_allocate_owner_id (
733         u32                             id_type)
734 {
735         acpi_owner_id                   owner_id = 0xFFFF;
736
737
738         ACPI_FUNCTION_TRACE ("ut_allocate_owner_id");
739
740
741         if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_CACHES)))
742         {
743                 return (0);
744         }
745
746         switch (id_type)
747         {
748         case ACPI_OWNER_TYPE_TABLE:
749
750                 owner_id = acpi_gbl_next_table_owner_id;
751                 acpi_gbl_next_table_owner_id++;
752
753                 /* Check for wraparound */
754
755                 if (acpi_gbl_next_table_owner_id == ACPI_FIRST_METHOD_ID)
756                 {
757                         acpi_gbl_next_table_owner_id = ACPI_FIRST_TABLE_ID;
758                         ACPI_REPORT_WARNING (("Table owner ID wraparound\n"));
759                 }
760                 break;
761
762
763         case ACPI_OWNER_TYPE_METHOD:
764
765                 owner_id = acpi_gbl_next_method_owner_id;
766                 acpi_gbl_next_method_owner_id++;
767
768                 if (acpi_gbl_next_method_owner_id == ACPI_FIRST_TABLE_ID)
769                 {
770                         /* Check for wraparound */
771
772                         acpi_gbl_next_method_owner_id = ACPI_FIRST_METHOD_ID;
773                 }
774                 break;
775
776         default:
777                 break;
778         }
779
780         (void) acpi_ut_release_mutex (ACPI_MTX_CACHES);
781         return_VALUE (owner_id);
782 }
783
784
785 /****************************************************************************
786  *
787  * FUNCTION:    acpi_ut_init_globals
788  *
789  * PARAMETERS:  none
790  *
791  * DESCRIPTION: Init library globals.  All globals that require specific
792  *              initialization should be initialized here!
793  *
794  ***************************************************************************/
795
796 void
797 acpi_ut_init_globals (
798         void)
799 {
800         u32                             i;
801
802
803         ACPI_FUNCTION_TRACE ("ut_init_globals");
804
805
806         /* Memory allocation and cache lists */
807
808         ACPI_MEMSET (acpi_gbl_memory_lists, 0, sizeof (struct acpi_memory_list) * ACPI_NUM_MEM_LISTS);
809
810         acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].link_offset      = (u16) ACPI_PTR_DIFF (&(((union acpi_generic_state *) NULL)->common.next), NULL);
811         acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].link_offset     = (u16) ACPI_PTR_DIFF (&(((union acpi_parse_object *) NULL)->common.next), NULL);
812         acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].link_offset = (u16) ACPI_PTR_DIFF (&(((union acpi_parse_object *) NULL)->common.next), NULL);
813         acpi_gbl_memory_lists[ACPI_MEM_LIST_OPERAND].link_offset    = (u16) ACPI_PTR_DIFF (&(((union acpi_operand_object *) NULL)->cache.next), NULL);
814         acpi_gbl_memory_lists[ACPI_MEM_LIST_WALK].link_offset       = (u16) ACPI_PTR_DIFF (&(((struct acpi_walk_state *) NULL)->next), NULL);
815
816         acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].object_size     = sizeof (struct acpi_namespace_node);
817         acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].object_size      = sizeof (union acpi_generic_state);
818         acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].object_size     = sizeof (struct acpi_parse_obj_common);
819         acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].object_size = sizeof (struct acpi_parse_obj_named);
820         acpi_gbl_memory_lists[ACPI_MEM_LIST_OPERAND].object_size    = sizeof (union acpi_operand_object);
821         acpi_gbl_memory_lists[ACPI_MEM_LIST_WALK].object_size       = sizeof (struct acpi_walk_state);
822
823         acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].max_cache_depth  = ACPI_MAX_STATE_CACHE_DEPTH;
824         acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].max_cache_depth = ACPI_MAX_PARSE_CACHE_DEPTH;
825         acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].max_cache_depth = ACPI_MAX_EXTPARSE_CACHE_DEPTH;
826         acpi_gbl_memory_lists[ACPI_MEM_LIST_OPERAND].max_cache_depth = ACPI_MAX_OBJECT_CACHE_DEPTH;
827         acpi_gbl_memory_lists[ACPI_MEM_LIST_WALK].max_cache_depth   = ACPI_MAX_WALK_CACHE_DEPTH;
828
829         ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].list_name    = "Global Memory Allocation");
830         ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].list_name    = "Namespace Nodes");
831         ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].list_name     = "State Object Cache");
832         ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].list_name    = "Parse Node Cache");
833         ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].list_name = "Extended Parse Node Cache");
834         ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_OPERAND].list_name   = "Operand Object Cache");
835         ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_WALK].list_name      = "Tree Walk Node Cache");
836
837         /* ACPI table structure */
838
839         for (i = 0; i < NUM_ACPI_TABLE_TYPES; i++)
840         {
841                 acpi_gbl_table_lists[i].next        = NULL;
842                 acpi_gbl_table_lists[i].count       = 0;
843         }
844
845         /* Mutex locked flags */
846
847         for (i = 0; i < NUM_MUTEX; i++)
848         {
849                 acpi_gbl_mutex_info[i].mutex        = NULL;
850                 acpi_gbl_mutex_info[i].owner_id     = ACPI_MUTEX_NOT_ACQUIRED;
851                 acpi_gbl_mutex_info[i].use_count    = 0;
852         }
853
854         /* GPE support */
855
856         acpi_gbl_gpe_xrupt_list_head        = NULL;
857         acpi_gbl_gpe_fadt_blocks[0]         = NULL;
858         acpi_gbl_gpe_fadt_blocks[1]         = NULL;
859
860         /* Global notify handlers */
861
862         acpi_gbl_system_notify.handler      = NULL;
863         acpi_gbl_device_notify.handler      = NULL;
864         acpi_gbl_init_handler               = NULL;
865
866         /* Global "typed" ACPI table pointers */
867
868         acpi_gbl_RSDP                       = NULL;
869         acpi_gbl_XSDT                       = NULL;
870         acpi_gbl_FACS                       = NULL;
871         acpi_gbl_FADT                       = NULL;
872         acpi_gbl_DSDT                       = NULL;
873
874         /* Global Lock support */
875
876         acpi_gbl_global_lock_acquired       = FALSE;
877         acpi_gbl_global_lock_thread_count   = 0;
878         acpi_gbl_global_lock_handle         = 0;
879
880         /* Miscellaneous variables */
881
882         acpi_gbl_table_flags                = ACPI_PHYSICAL_POINTER;
883         acpi_gbl_rsdp_original_location     = 0;
884         acpi_gbl_cm_single_step             = FALSE;
885         acpi_gbl_db_terminate_threads       = FALSE;
886         acpi_gbl_shutdown                   = FALSE;
887         acpi_gbl_ns_lookup_count            = 0;
888         acpi_gbl_ps_find_count              = 0;
889         acpi_gbl_acpi_hardware_present      = TRUE;
890         acpi_gbl_next_table_owner_id        = ACPI_FIRST_TABLE_ID;
891         acpi_gbl_next_method_owner_id       = ACPI_FIRST_METHOD_ID;
892         acpi_gbl_debugger_configuration     = DEBUGGER_THREADING;
893         acpi_gbl_db_output_flags            = ACPI_DB_CONSOLE_OUTPUT;
894
895         /* Hardware oriented */
896
897         acpi_gbl_events_initialized         = FALSE;
898         acpi_gbl_system_awake_and_running   = TRUE;
899
900         /* Namespace */
901
902         acpi_gbl_root_node                  = NULL;
903
904         acpi_gbl_root_node_struct.name.integer = ACPI_ROOT_NAME;
905         acpi_gbl_root_node_struct.descriptor = ACPI_DESC_TYPE_NAMED;
906         acpi_gbl_root_node_struct.type      = ACPI_TYPE_DEVICE;
907         acpi_gbl_root_node_struct.child     = NULL;
908         acpi_gbl_root_node_struct.peer      = NULL;
909         acpi_gbl_root_node_struct.object    = NULL;
910         acpi_gbl_root_node_struct.flags     = ANOBJ_END_OF_PEER_LIST;
911
912
913 #ifdef ACPI_DEBUG_OUTPUT
914         acpi_gbl_lowest_stack_pointer       = ACPI_SIZE_MAX;
915 #endif
916
917         return_VOID;
918 }
919
920