1 /******************************************************************************
3 * Module Name: cmxface - External interfaces for "global" ACPI functions
6 *****************************************************************************/
9 * Copyright (C) 2000, 2001 R. Byron Moore
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.
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.
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
29 #define _COMPONENT ACPI_UTILITIES
30 MODULE_NAME ("cmxface")
33 /*******************************************************************************
35 * FUNCTION: Acpi_initialize_subsystem
41 * DESCRIPTION: Initializes all global variables. This is the first function
42 * called, so any early initialization belongs here.
44 ******************************************************************************/
47 acpi_initialize_subsystem (
53 /* Initialize all globals used by the subsystem */
55 acpi_cm_init_globals ();
57 /* Initialize the OS-Dependent layer */
59 status
= acpi_os_initialize ();
60 if (ACPI_FAILURE (status
)) {
61 REPORT_ERROR (("OSD failed to initialize, %s\n",
62 acpi_cm_format_exception (status
)));
66 /* Create the default mutex objects */
68 status
= acpi_cm_mutex_initialize ();
69 if (ACPI_FAILURE (status
)) {
70 REPORT_ERROR (("Global mutex creation failure, %s\n",
71 acpi_cm_format_exception (status
)));
76 * Initialize the namespace manager and
77 * the root of the namespace tree
80 status
= acpi_ns_root_initialize ();
81 if (ACPI_FAILURE (status
)) {
82 REPORT_ERROR (("Namespace initialization failure, %s\n",
83 acpi_cm_format_exception (status
)));
88 /* If configured, initialize the AML debugger */
90 DEBUGGER_EXEC (acpi_db_initialize ());
96 /*******************************************************************************
98 * FUNCTION: Acpi_enable_subsystem
100 * PARAMETERS: Flags - Init/enable Options
104 * DESCRIPTION: Completes the subsystem initialization including hardware.
105 * Puts system into ACPI mode if it isn't already.
107 ******************************************************************************/
110 acpi_enable_subsystem (
113 ACPI_STATUS status
= AE_OK
;
116 /* Sanity check the FADT for valid values */
118 status
= acpi_cm_validate_fadt ();
119 if (ACPI_FAILURE (status
)) {
124 * Install the default Op_region handlers. These are
125 * installed unless other handlers have already been
126 * installed via the Install_address_space_handler interface
129 if (!(flags
& ACPI_NO_ADDRESS_SPACE_INIT
)) {
130 status
= acpi_ev_install_default_address_space_handlers ();
131 if (ACPI_FAILURE (status
)) {
137 * We must initialize the hardware before we can enable ACPI.
140 if (!(flags
& ACPI_NO_HARDWARE_INIT
)) {
141 status
= acpi_hw_initialize ();
142 if (ACPI_FAILURE (status
)) {
148 * Enable ACPI on this platform
151 if (!(flags
& ACPI_NO_ACPI_ENABLE
)) {
152 status
= acpi_enable ();
153 if (ACPI_FAILURE (status
)) {
160 * We must have the hardware AND events initialized before we can execute
161 * ANY control methods SAFELY. Any control method can require ACPI hardware
162 * support, so the hardware MUST be initialized before execution!
165 if (!(flags
& ACPI_NO_EVENT_INIT
)) {
166 status
= acpi_ev_initialize ();
167 if (ACPI_FAILURE (status
)) {
174 * Initialize all device objects in the namespace
175 * This runs the _STA and _INI methods.
178 if (!(flags
& ACPI_NO_DEVICE_INIT
)) {
179 status
= acpi_ns_initialize_devices ();
180 if (ACPI_FAILURE (status
)) {
187 * Initialize the objects that remain uninitialized. This
188 * runs the executable AML that is part of the declaration of Op_regions
192 if (!(flags
& ACPI_NO_OBJECT_INIT
)) {
193 status
= acpi_ns_initialize_objects ();
194 if (ACPI_FAILURE (status
)) {
204 /*******************************************************************************
206 * FUNCTION: Acpi_terminate
212 * DESCRIPTION: Shutdown the ACPI subsystem. Release all resources.
214 ******************************************************************************/
217 acpi_terminate (void)
220 /* Terminate the AML Debuger if present */
222 DEBUGGER_EXEC(acpi_gbl_db_terminate_threads
= TRUE
);
224 /* TBD: [Investigate] This is no longer needed?*/
225 /* Acpi_cm_release_mutex (ACPI_MTX_DEBUG_CMD_READY); */
228 /* Shutdown and free all resources */
230 acpi_cm_subsystem_shutdown ();
233 /* Free the mutex objects */
235 acpi_cm_mutex_terminate ();
238 /* Now we can shutdown the OS-dependent layer */
240 acpi_os_terminate ();
246 /******************************************************************************
248 * FUNCTION: Acpi_get_system_info
250 * PARAMETERS: Out_buffer - a pointer to a buffer to receive the
251 * resources for the device
252 * Buffer_length - the number of bytes available in the buffer
254 * RETURN: Status - the status of the call
256 * DESCRIPTION: This function is called to get information about the current
257 * state of the ACPI subsystem. It will return system information
260 * If the function fails an appropriate status will be returned
261 * and the value of Out_buffer is undefined.
263 ******************************************************************************/
266 acpi_get_system_info (
267 ACPI_BUFFER
*out_buffer
)
269 ACPI_SYSTEM_INFO
*info_ptr
;
274 * Must have a valid buffer
277 (!out_buffer
->pointer
)) {
278 return (AE_BAD_PARAMETER
);
281 if (out_buffer
->length
< sizeof (ACPI_SYSTEM_INFO
)) {
283 * Caller's buffer is too small
285 out_buffer
->length
= sizeof (ACPI_SYSTEM_INFO
);
287 return (AE_BUFFER_OVERFLOW
);
292 * Set return length and get data
294 out_buffer
->length
= sizeof (ACPI_SYSTEM_INFO
);
295 info_ptr
= (ACPI_SYSTEM_INFO
*) out_buffer
->pointer
;
297 info_ptr
->acpi_ca_version
= ACPI_CA_VERSION
;
299 /* System flags (ACPI capabilities) */
301 info_ptr
->flags
= acpi_gbl_system_flags
;
303 /* Timer resolution - 24 or 32 bits */
304 if (!acpi_gbl_FADT
) {
305 info_ptr
->timer_resolution
= 0;
307 else if (acpi_gbl_FADT
->tmr_val_ext
== 0) {
308 info_ptr
->timer_resolution
= 24;
311 info_ptr
->timer_resolution
= 32;
314 /* Clear the reserved fields */
316 info_ptr
->reserved1
= 0;
317 info_ptr
->reserved2
= 0;
319 /* Current debug levels */
321 info_ptr
->debug_layer
= acpi_dbg_layer
;
322 info_ptr
->debug_level
= acpi_dbg_level
;
324 /* Current status of the ACPI tables, per table type */
326 info_ptr
->num_table_types
= NUM_ACPI_TABLES
;
327 for (i
= 0; i
< NUM_ACPI_TABLES
; i
++) {
328 info_ptr
->table_info
[i
].count
= acpi_gbl_acpi_tables
[i
].count
;
335 /******************************************************************************
337 * FUNCTION: Acpi_format_exception
339 * PARAMETERS: Out_buffer - a pointer to a buffer to receive the
342 * RETURN: Status - the status of the call
344 * DESCRIPTION: This function translates an ACPI exception into an ASCII string.
346 ******************************************************************************/
349 acpi_format_exception (
350 ACPI_STATUS exception
,
351 ACPI_BUFFER
*out_buffer
)
354 NATIVE_CHAR
*formatted_exception
;
358 * Must have a valid buffer
361 (!out_buffer
->pointer
)) {
362 return (AE_BAD_PARAMETER
);
366 /* Convert the exception code (Handles bad exception codes) */
368 formatted_exception
= acpi_cm_format_exception (exception
);
371 * Get length of string and check if it will fit in caller's buffer
374 length
= STRLEN (formatted_exception
);
375 if (out_buffer
->length
< length
) {
376 out_buffer
->length
= length
;
377 return (AE_BUFFER_OVERFLOW
);
381 /* Copy the string, all done */
383 STRCPY (out_buffer
->pointer
, formatted_exception
);
389 /*****************************************************************************
391 * FUNCTION: Acpi_allocate
393 * PARAMETERS: Size - Size of the allocation
395 * RETURN: Address of the allocated memory on success, NULL on failure.
397 * DESCRIPTION: The subsystem's equivalent of malloc.
398 * External front-end to the Cm* memory manager
400 ****************************************************************************/
407 return (acpi_cm_allocate (size
));
411 /*****************************************************************************
413 * FUNCTION: Acpi_callocate
415 * PARAMETERS: Size - Size of the allocation
417 * RETURN: Address of the allocated memory on success, NULL on failure.
419 * DESCRIPTION: The subsystem's equivalent of calloc.
420 * External front-end to the Cm* memory manager
422 ****************************************************************************/
429 return (acpi_cm_callocate (size
));
433 /*****************************************************************************
435 * FUNCTION: Acpi_free
437 * PARAMETERS: Address - Address of the memory to deallocate
441 * DESCRIPTION: Frees the memory at Address
442 * External front-end to the Cm* memory manager
444 ****************************************************************************/
451 acpi_cm_free (address
);