1 /******************************************************************************
3 * Module Name: cmxface - External interfaces for "global" ACPI functions
6 *****************************************************************************/
9 * Copyright (C) 2000 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 MISCELLANEOUS
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
)) {
161 /* TBD: workaround. Old Lions don't enable properly */
168 * We must have the hardware AND events initialized before we can execute
169 * ANY control methods SAFELY. Any control method can require ACPI hardware
170 * support, so the hardware MUST be initialized before execution!
173 if (!(flags
& ACPI_NO_EVENT_INIT
)) {
174 status
= acpi_ev_initialize ();
175 if (ACPI_FAILURE (status
)) {
182 * Initialize all device objects in the namespace
183 * This runs the _STA, _INI, and _HID methods, and detects
184 * the PCI root bus(es)
187 if (!(flags
& ACPI_NO_DEVICE_INIT
)) {
188 status
= acpi_ns_initialize_devices (flags
& ACPI_NO_PCI_INIT
);
189 if (ACPI_FAILURE (status
)) {
196 * Initialize the objects that remain unitialized. This
197 * runs the executable AML that is part of the declaration of Op_regions
201 if (!(flags
& ACPI_NO_OBJECT_INIT
)) {
202 status
= acpi_ns_initialize_objects ();
203 if (ACPI_FAILURE (status
)) {
213 /*******************************************************************************
215 * FUNCTION: Acpi_terminate
221 * DESCRIPTION: Shutdown the ACPI subsystem. Release all resources.
223 ******************************************************************************/
226 acpi_terminate (void)
229 /* Terminate the AML Debuger if present */
231 DEBUGGER_EXEC(acpi_gbl_db_terminate_threads
= TRUE
);
233 /* TBD: [Investigate] This is no longer needed?*/
234 /* Acpi_cm_release_mutex (ACPI_MTX_DEBUG_CMD_READY); */
237 /* Shutdown and free all resources */
239 acpi_cm_subsystem_shutdown ();
242 /* Free the mutex objects */
244 acpi_cm_mutex_terminate ();
247 /* Now we can shutdown the OS-dependent layer */
249 acpi_os_terminate ();
255 /******************************************************************************
257 * FUNCTION: Acpi_get_system_info
259 * PARAMETERS: Out_buffer - a pointer to a buffer to receive the
260 * resources for the device
261 * Buffer_length - the number of bytes available in the buffer
263 * RETURN: Status - the status of the call
265 * DESCRIPTION: This function is called to get information about the current
266 * state of the ACPI subsystem. It will return system information
269 * If the function fails an appropriate status will be returned
270 * and the value of Out_buffer is undefined.
272 ******************************************************************************/
275 acpi_get_system_info (
276 ACPI_BUFFER
*out_buffer
)
278 ACPI_SYSTEM_INFO
*info_ptr
;
283 * Must have a valid buffer
286 (!out_buffer
->pointer
))
288 return (AE_BAD_PARAMETER
);
291 if (out_buffer
->length
< sizeof (ACPI_SYSTEM_INFO
)) {
293 * Caller's buffer is too small
295 out_buffer
->length
= sizeof (ACPI_SYSTEM_INFO
);
297 return (AE_BUFFER_OVERFLOW
);
302 * Set return length and get data
304 out_buffer
->length
= sizeof (ACPI_SYSTEM_INFO
);
305 info_ptr
= (ACPI_SYSTEM_INFO
*) out_buffer
->pointer
;
307 /* TBD [Future]: need a version number, or use the version string */
308 info_ptr
->acpi_ca_version
= 0x1234;
310 /* System flags (ACPI capabilities) */
312 info_ptr
->flags
= acpi_gbl_system_flags
;
314 /* Timer resolution - 24 or 32 bits */
316 info_ptr
->timer_resolution
= acpi_hw_pmt_resolution ();
318 /* Clear the reserved fields */
320 info_ptr
->reserved1
= 0;
321 info_ptr
->reserved2
= 0;
323 /* Current debug levels */
325 info_ptr
->debug_layer
= acpi_dbg_layer
;
326 info_ptr
->debug_level
= acpi_dbg_level
;
328 /* Current status of the ACPI tables, per table type */
330 info_ptr
->num_table_types
= NUM_ACPI_TABLES
;
331 for (i
= 0; i
< NUM_ACPI_TABLES
; i
++) {
332 info_ptr
->table_info
[i
].count
= acpi_gbl_acpi_tables
[i
].count
;
339 /******************************************************************************
341 * FUNCTION: Acpi_format_exception
343 * PARAMETERS: Out_buffer - a pointer to a buffer to receive the
346 * RETURN: Status - the status of the call
348 * DESCRIPTION: This function translates an ACPI exception into an ASCII string.
350 ******************************************************************************/
353 acpi_format_exception (
354 ACPI_STATUS exception
,
355 ACPI_BUFFER
*out_buffer
)
358 NATIVE_CHAR
*formatted_exception
;
362 * Must have a valid buffer
365 (!out_buffer
->pointer
))
367 return (AE_BAD_PARAMETER
);
371 /* Convert the exception code (Handles bad exception codes) */
373 formatted_exception
= acpi_cm_format_exception (exception
);
376 * Get length of string and check if it will fit in caller's buffer
379 length
= STRLEN (formatted_exception
);
380 if (out_buffer
->length
< length
) {
381 out_buffer
->length
= length
;
382 return (AE_BUFFER_OVERFLOW
);
386 /* Copy the string, all done */
388 STRCPY (out_buffer
->pointer
, formatted_exception
);