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