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
36 #define _COMPONENT ACPI_UTILITIES
37 MODULE_NAME ("cmxface")
40 /*******************************************************************************
42 * FUNCTION: Acpi_initialize_subsystem
48 * DESCRIPTION: Initializes all global variables. This is the first function
49 * called, so any early initialization belongs here.
51 ******************************************************************************/
54 acpi_initialize_subsystem (
60 /* Initialize all globals used by the subsystem */
62 acpi_cm_init_globals ();
64 /* Initialize the OS-Dependent layer */
66 status
= acpi_os_initialize ();
67 if (ACPI_FAILURE (status
)) {
68 REPORT_ERROR (("OSD failed to initialize, %s\n",
69 acpi_cm_format_exception (status
)));
73 /* Create the default mutex objects */
75 status
= acpi_cm_mutex_initialize ();
76 if (ACPI_FAILURE (status
)) {
77 REPORT_ERROR (("Global mutex creation failure, %s\n",
78 acpi_cm_format_exception (status
)));
83 * Initialize the namespace manager and
84 * the root of the namespace tree
87 status
= acpi_ns_root_initialize ();
88 if (ACPI_FAILURE (status
)) {
89 REPORT_ERROR (("Namespace initialization failure, %s\n",
90 acpi_cm_format_exception (status
)));
95 /* If configured, initialize the AML debugger */
97 DEBUGGER_EXEC (acpi_db_initialize ());
103 /*******************************************************************************
105 * FUNCTION: Acpi_enable_subsystem
107 * PARAMETERS: Flags - Init/enable Options
111 * DESCRIPTION: Completes the subsystem initialization including hardware.
112 * Puts system into ACPI mode if it isn't already.
114 ******************************************************************************/
117 acpi_enable_subsystem (
120 ACPI_STATUS status
= AE_OK
;
123 /* Sanity check the FADT for valid values */
125 status
= acpi_cm_validate_fadt ();
126 if (ACPI_FAILURE (status
)) {
131 * Install the default Op_region handlers. These are
132 * installed unless other handlers have already been
133 * installed via the Install_address_space_handler interface
136 if (!(flags
& ACPI_NO_ADDRESS_SPACE_INIT
)) {
137 status
= acpi_ev_install_default_address_space_handlers ();
138 if (ACPI_FAILURE (status
)) {
144 * We must initialize the hardware before we can enable ACPI.
147 if (!(flags
& ACPI_NO_HARDWARE_INIT
)) {
148 status
= acpi_hw_initialize ();
149 if (ACPI_FAILURE (status
)) {
155 * Enable ACPI on this platform
158 if (!(flags
& ACPI_NO_ACPI_ENABLE
)) {
159 status
= acpi_enable ();
160 if (ACPI_FAILURE (status
)) {
167 * We must have the hardware AND events initialized before we can execute
168 * ANY control methods SAFELY. Any control method can require ACPI hardware
169 * support, so the hardware MUST be initialized before execution!
172 if (!(flags
& ACPI_NO_EVENT_INIT
)) {
173 status
= acpi_ev_initialize ();
174 if (ACPI_FAILURE (status
)) {
181 * Initialize all device objects in the namespace
182 * This runs the _STA and _INI methods.
185 if (!(flags
& ACPI_NO_DEVICE_INIT
)) {
186 status
= acpi_ns_initialize_devices ();
187 if (ACPI_FAILURE (status
)) {
194 * Initialize the objects that remain uninitialized. This
195 * runs the executable AML that is part of the declaration of Op_regions
199 if (!(flags
& ACPI_NO_OBJECT_INIT
)) {
200 status
= acpi_ns_initialize_objects ();
201 if (ACPI_FAILURE (status
)) {
211 /*******************************************************************************
213 * FUNCTION: Acpi_terminate
219 * DESCRIPTION: Shutdown the ACPI subsystem. Release all resources.
221 ******************************************************************************/
224 acpi_terminate (void)
227 /* Terminate the AML Debuger if present */
229 DEBUGGER_EXEC(acpi_gbl_db_terminate_threads
= TRUE
);
231 /* TBD: [Investigate] This is no longer needed?*/
232 /* Acpi_cm_release_mutex (ACPI_MTX_DEBUG_CMD_READY); */
235 /* Shutdown and free all resources */
237 acpi_cm_subsystem_shutdown ();
240 /* Free the mutex objects */
242 acpi_cm_mutex_terminate ();
245 /* Now we can shutdown the OS-dependent layer */
247 acpi_os_terminate ();
253 /******************************************************************************
255 * FUNCTION: Acpi_get_system_info
257 * PARAMETERS: Out_buffer - a pointer to a buffer to receive the
258 * resources for the device
259 * Buffer_length - the number of bytes available in the buffer
261 * RETURN: Status - the status of the call
263 * DESCRIPTION: This function is called to get information about the current
264 * state of the ACPI subsystem. It will return system information
267 * If the function fails an appropriate status will be returned
268 * and the value of Out_buffer is undefined.
270 ******************************************************************************/
273 acpi_get_system_info (
274 ACPI_BUFFER
*out_buffer
)
276 ACPI_SYSTEM_INFO
*info_ptr
;
281 * Must have a valid buffer
284 (!out_buffer
->pointer
)) {
285 return (AE_BAD_PARAMETER
);
288 if (out_buffer
->length
< sizeof (ACPI_SYSTEM_INFO
)) {
290 * Caller's buffer is too small
292 out_buffer
->length
= sizeof (ACPI_SYSTEM_INFO
);
294 return (AE_BUFFER_OVERFLOW
);
299 * Set return length and get data
301 out_buffer
->length
= sizeof (ACPI_SYSTEM_INFO
);
302 info_ptr
= (ACPI_SYSTEM_INFO
*) out_buffer
->pointer
;
304 info_ptr
->acpi_ca_version
= ACPI_CA_VERSION
;
306 /* System flags (ACPI capabilities) */
308 info_ptr
->flags
= acpi_gbl_system_flags
;
310 /* Timer resolution - 24 or 32 bits */
311 if (!acpi_gbl_FADT
) {
312 info_ptr
->timer_resolution
= 0;
314 else if (acpi_gbl_FADT
->tmr_val_ext
== 0) {
315 info_ptr
->timer_resolution
= 24;
318 info_ptr
->timer_resolution
= 32;
321 /* Clear the reserved fields */
323 info_ptr
->reserved1
= 0;
324 info_ptr
->reserved2
= 0;
326 /* Current debug levels */
328 info_ptr
->debug_layer
= acpi_dbg_layer
;
329 info_ptr
->debug_level
= acpi_dbg_level
;
331 /* Current status of the ACPI tables, per table type */
333 info_ptr
->num_table_types
= NUM_ACPI_TABLES
;
334 for (i
= 0; i
< NUM_ACPI_TABLES
; i
++) {
335 info_ptr
->table_info
[i
].count
= acpi_gbl_acpi_tables
[i
].count
;
342 /******************************************************************************
344 * FUNCTION: Acpi_format_exception
346 * PARAMETERS: Out_buffer - a pointer to a buffer to receive the
349 * RETURN: Status - the status of the call
351 * DESCRIPTION: This function translates an ACPI exception into an ASCII string.
353 ******************************************************************************/
356 acpi_format_exception (
357 ACPI_STATUS exception
,
358 ACPI_BUFFER
*out_buffer
)
361 NATIVE_CHAR
*formatted_exception
;
365 * Must have a valid buffer
368 (!out_buffer
->pointer
)) {
369 return (AE_BAD_PARAMETER
);
373 /* Convert the exception code (Handles bad exception codes) */
375 formatted_exception
= acpi_cm_format_exception (exception
);
378 * Get length of string and check if it will fit in caller's buffer
381 length
= STRLEN (formatted_exception
);
382 if (out_buffer
->length
< length
) {
383 out_buffer
->length
= length
;
384 return (AE_BUFFER_OVERFLOW
);
388 /* Copy the string, all done */
390 STRCPY (out_buffer
->pointer
, formatted_exception
);
396 /*****************************************************************************
398 * FUNCTION: Acpi_allocate
400 * PARAMETERS: Size - Size of the allocation
402 * RETURN: Address of the allocated memory on success, NULL on failure.
404 * DESCRIPTION: The subsystem's equivalent of malloc.
405 * External front-end to the Cm* memory manager
407 ****************************************************************************/
414 return (acpi_cm_allocate (size
));
418 /*****************************************************************************
420 * FUNCTION: Acpi_callocate
422 * PARAMETERS: Size - Size of the allocation
424 * RETURN: Address of the allocated memory on success, NULL on failure.
426 * DESCRIPTION: The subsystem's equivalent of calloc.
427 * External front-end to the Cm* memory manager
429 ****************************************************************************/
436 return (acpi_cm_callocate (size
));
440 /*****************************************************************************
442 * FUNCTION: Acpi_free
444 * PARAMETERS: Address - Address of the memory to deallocate
448 * DESCRIPTION: Frees the memory at Address
449 * External front-end to the Cm* memory manager
451 ****************************************************************************/
458 acpi_cm_free (address
);