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