:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / drivers / bus / acpi / utils / cmglobal.c
1 /******************************************************************************
2  *
3  * Module Name: cmglobal - Global variables for the ACPI subsystem
4  *              $Revision$
5  *
6  *****************************************************************************/
7
8 /*
9  *  Copyright (C) 2000, 2001 R. Byron Moore
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25
26 #define DEFINE_ACPI_GLOBALS
27
28 #include "acpi.h"
29 #include "acevents.h"
30 #include "acnamesp.h"
31 #include "acinterp.h"
32 #include "amlcode.h"
33
34
35 #define _COMPONENT          ACPI_UTILITIES
36          MODULE_NAME         ("cmglobal")
37
38
39 /******************************************************************************
40  *
41  * Static global variable initialization.
42  *
43  ******************************************************************************/
44
45 /*
46  * We want the debug switches statically initialized so they
47  * are already set when the debugger is entered.
48  */
49
50 /* Debug switch - level and trace mask */
51
52 u32                         acpi_dbg_level = NORMAL_DEFAULT;
53
54 /* Debug switch - layer (component) mask */
55
56 u32                         acpi_dbg_layer = ACPI_COMPONENT_DEFAULT;
57 u32                         acpi_gbl_nesting_level = 0;
58
59
60 /* Debugger globals */
61
62 u8                          acpi_gbl_db_terminate_threads = FALSE;
63 u8                          acpi_gbl_method_executing = FALSE;
64
65 /* System flags */
66
67 u32                         acpi_gbl_system_flags = 0;
68 u32                         acpi_gbl_startup_flags = 0;
69
70 /* System starts unitialized! */
71 u8                          acpi_gbl_shutdown = TRUE;
72
73
74 u8                          acpi_gbl_decode_to8bit [8] = {1,2,4,8,16,32,64,128};
75
76
77 /******************************************************************************
78  *
79  * Namespace globals
80  *
81  ******************************************************************************/
82
83
84 /*
85  * Names built-in to the interpreter
86  *
87  * Initial values are currently supported only for types String and Number.
88  * To avoid type punning, both are specified as strings in this table.
89  *
90  * NOTES:
91  * 1) _SB_ is defined to be a device to allow _SB_/_INI to be run
92  *    during the initialization sequence.
93  */
94
95 PREDEFINED_NAMES            acpi_gbl_pre_defined_names[] =
96 { {"_GPE",    INTERNAL_TYPE_DEF_ANY},
97         {"_PR_",    INTERNAL_TYPE_DEF_ANY},
98         {"_SB_",    ACPI_TYPE_DEVICE},
99         {"_SI_",    INTERNAL_TYPE_DEF_ANY},
100         {"_TZ_",    INTERNAL_TYPE_DEF_ANY},
101         {"_REV",    ACPI_TYPE_INTEGER, "2"},
102         {"_OS_",    ACPI_TYPE_STRING, ACPI_OS_NAME},
103         {"_GL_",    ACPI_TYPE_MUTEX, "0"},
104         {NULL,      ACPI_TYPE_ANY}           /* Table terminator */
105 };
106
107
108 /*
109  * Properties of the ACPI Object Types, both internal and external.
110  *
111  * Elements of Acpi_ns_properties are bit significant
112  * and the table is indexed by values of ACPI_OBJECT_TYPE
113  */
114
115 u8                          acpi_gbl_ns_properties[] =
116 {
117         NSP_NORMAL,                 /* 00 Any              */
118         NSP_NORMAL,                 /* 01 Number           */
119         NSP_NORMAL,                 /* 02 String           */
120         NSP_NORMAL,                 /* 03 Buffer           */
121         NSP_LOCAL,                  /* 04 Package          */
122         NSP_NORMAL,                 /* 05 Field_unit       */
123         NSP_NEWSCOPE | NSP_LOCAL,   /* 06 Device           */
124         NSP_LOCAL,                  /* 07 Acpi_event       */
125         NSP_NEWSCOPE | NSP_LOCAL,   /* 08 Method           */
126         NSP_LOCAL,                  /* 09 Mutex            */
127         NSP_LOCAL,                  /* 10 Region           */
128         NSP_NEWSCOPE | NSP_LOCAL,   /* 11 Power            */
129         NSP_NEWSCOPE | NSP_LOCAL,   /* 12 Processor        */
130         NSP_NEWSCOPE | NSP_LOCAL,   /* 13 Thermal          */
131         NSP_NORMAL,                 /* 14 Buffer_field     */
132         NSP_NORMAL,                 /* 15 Ddb_handle       */
133         NSP_NORMAL,                 /* 16 Debug Object     */
134         NSP_NORMAL,                 /* 17 Def_field        */
135         NSP_NORMAL,                 /* 18 Bank_field       */
136         NSP_NORMAL,                 /* 19 Index_field      */
137         NSP_NORMAL,                 /* 20 Reference        */
138         NSP_NORMAL,                 /* 21 Alias            */
139         NSP_NORMAL,                 /* 22 Notify           */
140         NSP_NORMAL,                 /* 23 Address Handler  */
141         NSP_NEWSCOPE | NSP_LOCAL,   /* 24 Resource         */
142         NSP_NORMAL,                 /* 25 Def_field_defn   */
143         NSP_NORMAL,                 /* 26 Bank_field_defn  */
144         NSP_NORMAL,                 /* 27 Index_field_defn */
145         NSP_NORMAL,                 /* 28 If               */
146         NSP_NORMAL,                 /* 29 Else             */
147         NSP_NORMAL,                 /* 30 While            */
148         NSP_NEWSCOPE,               /* 31 Scope            */
149         NSP_LOCAL,                  /* 32 Def_any          */
150         NSP_NORMAL,                 /* 33 Extra            */
151         NSP_NORMAL                  /* 34 Invalid          */
152 };
153
154
155 /* Hex to ASCII conversion table */
156
157 NATIVE_CHAR                 acpi_gbl_hex_to_ascii[] =
158                           {'0','1','2','3','4','5','6','7',
159                           '8','9','A','B','C','D','E','F'};
160
161
162 /******************************************************************************
163  *
164  * Table globals
165  *
166  * NOTE: This table includes ONLY the ACPI tables that the subsystem consumes.
167  * it is NOT an exhaustive list of all possible ACPI tables.  All ACPI tables
168  * that are not used by the subsystem are simply ignored.
169  *
170  ******************************************************************************/
171
172
173 ACPI_TABLE_DESC             acpi_gbl_acpi_tables[NUM_ACPI_TABLES];
174
175
176 ACPI_TABLE_SUPPORT          acpi_gbl_acpi_table_data[NUM_ACPI_TABLES] =
177 {
178         /***********    Name,    Signature,  Signature size,    How many allowed?,   Supported?  Global typed pointer */
179
180         /* RSDP 0 */ {RSDP_NAME, RSDP_SIG, sizeof (RSDP_SIG)-1, ACPI_TABLE_SINGLE,   AE_OK,      NULL},
181         /* DSDT 1 */ {DSDT_SIG,  DSDT_SIG, sizeof (DSDT_SIG)-1, ACPI_TABLE_SINGLE,   AE_OK,      (void **) &acpi_gbl_DSDT},
182         /* FADT 2 */ {FADT_SIG,  FADT_SIG, sizeof (FADT_SIG)-1, ACPI_TABLE_SINGLE,   AE_OK,      (void **) &acpi_gbl_FADT},
183         /* FACS 3 */ {FACS_SIG,  FACS_SIG, sizeof (FACS_SIG)-1, ACPI_TABLE_SINGLE,   AE_OK,      (void **) &acpi_gbl_FACS},
184         /* PSDT 4 */ {PSDT_SIG,  PSDT_SIG, sizeof (PSDT_SIG)-1, ACPI_TABLE_MULTIPLE, AE_OK,      NULL},
185         /* SSDT 5 */ {SSDT_SIG,  SSDT_SIG, sizeof (SSDT_SIG)-1, ACPI_TABLE_MULTIPLE, AE_OK,      NULL},
186         /* XSDT 6 */ {XSDT_SIG,  XSDT_SIG, sizeof (RSDT_SIG)-1, ACPI_TABLE_SINGLE,   AE_OK,      NULL},
187 };
188
189
190 /*****************************************************************************
191  *
192  * FUNCTION:    Acpi_cm_valid_object_type
193  *
194  * PARAMETERS:  None.
195  *
196  * RETURN:      TRUE if valid object type
197  *
198  * DESCRIPTION: Validate an object type
199  *
200  ****************************************************************************/
201
202 u8
203 acpi_cm_valid_object_type (
204         u32                     type)
205 {
206
207         if (type > ACPI_TYPE_MAX)
208         {
209                 if ((type < INTERNAL_TYPE_BEGIN) ||
210                         (type > INTERNAL_TYPE_MAX))
211                 {
212                         return (FALSE);
213                 }
214         }
215
216         return (TRUE);
217 }
218
219
220 /*****************************************************************************
221  *
222  * FUNCTION:    Acpi_cm_format_exception
223  *
224  * PARAMETERS:  Status              - Acpi status to be formatted
225  *
226  * RETURN:      Formatted status string
227  *
228  * DESCRIPTION: Convert an ACPI exception to a string
229  *
230  ****************************************************************************/
231
232 NATIVE_CHAR *
233 acpi_cm_format_exception (
234         ACPI_STATUS             status)
235 {
236         NATIVE_CHAR             *exception = "UNKNOWN_STATUS";
237         ACPI_STATUS             sub_status;
238
239
240         sub_status = (status & ~AE_CODE_MASK);
241
242
243         switch (status & AE_CODE_MASK)
244         {
245         case AE_CODE_ENVIRONMENTAL:
246
247                 if (sub_status <= AE_CODE_ENV_MAX)
248                 {
249                         exception = acpi_gbl_exception_names_env [sub_status];
250                 }
251                 break;
252
253         case AE_CODE_PROGRAMMER:
254
255                 if (sub_status <= AE_CODE_PGM_MAX)
256                 {
257                         exception = acpi_gbl_exception_names_pgm [sub_status -1];
258                 }
259                 break;
260
261         case AE_CODE_ACPI_TABLES:
262
263                 if (sub_status <= AE_CODE_TBL_MAX)
264                 {
265                         exception = acpi_gbl_exception_names_tbl [sub_status -1];
266                 }
267                 break;
268
269         case AE_CODE_AML:
270
271                 if (sub_status <= AE_CODE_AML_MAX)
272                 {
273                         exception = acpi_gbl_exception_names_aml [sub_status -1];
274                 }
275                 break;
276
277         case AE_CODE_CONTROL:
278
279                 if (sub_status <= AE_CODE_CTRL_MAX)
280                 {
281                         exception = acpi_gbl_exception_names_ctrl [sub_status -1];
282                 }
283                 break;
284
285         default:
286                 break;
287         }
288
289
290         return (exception);
291 }
292
293
294 /****************************************************************************
295  *
296  * FUNCTION:    Acpi_cm_allocate_owner_id
297  *
298  * PARAMETERS:  Id_type         - Type of ID (method or table)
299  *
300  * DESCRIPTION: Allocate a table or method owner id
301  *
302  ***************************************************************************/
303
304 ACPI_OWNER_ID
305 acpi_cm_allocate_owner_id (
306         u32                     id_type)
307 {
308         ACPI_OWNER_ID           owner_id = 0xFFFF;
309
310
311         acpi_cm_acquire_mutex (ACPI_MTX_CACHES);
312
313         switch (id_type)
314         {
315         case OWNER_TYPE_TABLE:
316
317                 owner_id = acpi_gbl_next_table_owner_id;
318                 acpi_gbl_next_table_owner_id++;
319
320                 if (acpi_gbl_next_table_owner_id == FIRST_METHOD_ID)
321                 {
322                         acpi_gbl_next_table_owner_id = FIRST_TABLE_ID;
323                 }
324                 break;
325
326
327         case OWNER_TYPE_METHOD:
328
329                 owner_id = acpi_gbl_next_method_owner_id;
330                 acpi_gbl_next_method_owner_id++;
331
332                 if (acpi_gbl_next_method_owner_id == FIRST_TABLE_ID)
333                 {
334                         acpi_gbl_next_method_owner_id = FIRST_METHOD_ID;
335                 }
336                 break;
337         }
338
339
340         acpi_cm_release_mutex (ACPI_MTX_CACHES);
341
342         return (owner_id);
343 }
344
345
346 /****************************************************************************
347  *
348  * FUNCTION:    Acpi_cm_init_globals
349  *
350  * PARAMETERS:  none
351  *
352  * DESCRIPTION: Init library globals.  All globals that require specific
353  *              initialization should be initialized here!
354  *
355  ***************************************************************************/
356
357 void
358 acpi_cm_init_globals (
359         void)
360 {
361         u32                     i;
362
363
364         /* ACPI table structure */
365
366         for (i = 0; i < NUM_ACPI_TABLES; i++)
367         {
368                 acpi_gbl_acpi_tables[i].prev        = &acpi_gbl_acpi_tables[i];
369                 acpi_gbl_acpi_tables[i].next        = &acpi_gbl_acpi_tables[i];
370                 acpi_gbl_acpi_tables[i].pointer     = NULL;
371                 acpi_gbl_acpi_tables[i].length      = 0;
372                 acpi_gbl_acpi_tables[i].allocation  = ACPI_MEM_NOT_ALLOCATED;
373                 acpi_gbl_acpi_tables[i].count       = 0;
374         }
375
376
377         /* Address Space handler array */
378
379         for (i = 0; i < ACPI_NUM_ADDRESS_SPACES; i++)
380         {
381                 acpi_gbl_address_spaces[i].handler  = NULL;
382                 acpi_gbl_address_spaces[i].context  = NULL;
383         }
384
385         /* Mutex locked flags */
386
387         for (i = 0; i < NUM_MTX; i++)
388         {
389                 acpi_gbl_acpi_mutex_info[i].mutex   = NULL;
390                 acpi_gbl_acpi_mutex_info[i].locked  = FALSE;
391                 acpi_gbl_acpi_mutex_info[i].use_count = 0;
392         }
393
394         /* Global notify handlers */
395
396         acpi_gbl_sys_notify.handler         = NULL;
397         acpi_gbl_drv_notify.handler         = NULL;
398
399         /* Global "typed" ACPI table pointers */
400
401         acpi_gbl_RSDP                       = NULL;
402         acpi_gbl_XSDT                       = NULL;
403         acpi_gbl_FACS                       = NULL;
404         acpi_gbl_FADT                       = NULL;
405         acpi_gbl_DSDT                       = NULL;
406
407
408         /* Global Lock support */
409
410         acpi_gbl_global_lock_acquired       = FALSE;
411         acpi_gbl_global_lock_thread_count   = 0;
412
413         /* Miscellaneous variables */
414
415         acpi_gbl_system_flags               = 0;
416         acpi_gbl_startup_flags              = 0;
417         acpi_gbl_rsdp_original_location     = 0;
418         acpi_gbl_cm_single_step             = FALSE;
419         acpi_gbl_db_terminate_threads       = FALSE;
420         acpi_gbl_shutdown                   = FALSE;
421         acpi_gbl_ns_lookup_count            = 0;
422         acpi_gbl_ps_find_count              = 0;
423         acpi_gbl_acpi_hardware_present      = TRUE;
424         acpi_gbl_next_table_owner_id        = FIRST_TABLE_ID;
425         acpi_gbl_next_method_owner_id       = FIRST_METHOD_ID;
426         acpi_gbl_debugger_configuration     = DEBUGGER_THREADING;
427
428         /* Cache of small "state" objects */
429
430         acpi_gbl_generic_state_cache        = NULL;
431         acpi_gbl_generic_state_cache_depth  = 0;
432         acpi_gbl_state_cache_requests       = 0;
433         acpi_gbl_state_cache_hits           = 0;
434
435         acpi_gbl_parse_cache                = NULL;
436         acpi_gbl_parse_cache_depth          = 0;
437         acpi_gbl_parse_cache_requests       = 0;
438         acpi_gbl_parse_cache_hits           = 0;
439
440         acpi_gbl_ext_parse_cache            = NULL;
441         acpi_gbl_ext_parse_cache_depth      = 0;
442         acpi_gbl_ext_parse_cache_requests   = 0;
443         acpi_gbl_ext_parse_cache_hits       = 0;
444
445         acpi_gbl_object_cache               = NULL;
446         acpi_gbl_object_cache_depth         = 0;
447         acpi_gbl_object_cache_requests      = 0;
448         acpi_gbl_object_cache_hits          = 0;
449
450         acpi_gbl_walk_state_cache           = NULL;
451         acpi_gbl_walk_state_cache_depth     = 0;
452         acpi_gbl_walk_state_cache_requests  = 0;
453         acpi_gbl_walk_state_cache_hits      = 0;
454
455         /* Hardware oriented */
456
457         acpi_gbl_gpe0enable_register_save   = NULL;
458         acpi_gbl_gpe1_enable_register_save  = NULL;
459         acpi_gbl_original_mode              = SYS_MODE_UNKNOWN;   /*  original ACPI/legacy mode   */
460         acpi_gbl_gpe_registers              = NULL;
461         acpi_gbl_gpe_info                   = NULL;
462
463         /* Namespace */
464
465         acpi_gbl_root_node                  = NULL;
466
467         acpi_gbl_root_node_struct.name      = ACPI_ROOT_NAME;
468         acpi_gbl_root_node_struct.data_type = ACPI_DESC_TYPE_NAMED;
469         acpi_gbl_root_node_struct.type      = ACPI_TYPE_ANY;
470         acpi_gbl_root_node_struct.child     = NULL;
471         acpi_gbl_root_node_struct.peer      = NULL;
472         acpi_gbl_root_node_struct.object    = NULL;
473         acpi_gbl_root_node_struct.flags     = ANOBJ_END_OF_PEER_LIST;
474
475         /* Memory allocation metrics - compiled out in non-debug mode. */
476
477         INITIALIZE_ALLOCATION_METRICS();
478
479         return;
480 }
481
482