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