1 /******************************************************************************
3 * Module Name: utxface - External interfaces for "global" ACPI functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acevents.h>
50 #include <contrib/dev/acpica/include/acnamesp.h>
51 #include <contrib/dev/acpica/include/acdebug.h>
52 #include <contrib/dev/acpica/include/actables.h>
54 #define _COMPONENT ACPI_UTILITIES
55 ACPI_MODULE_NAME ("utxface")
58 #ifndef ACPI_ASL_COMPILER
60 /*******************************************************************************
62 * FUNCTION: AcpiInitializeSubsystem
68 * DESCRIPTION: Initializes all global variables. This is the first function
69 * called, so any early initialization belongs here.
71 ******************************************************************************/
74 AcpiInitializeSubsystem (
80 ACPI_FUNCTION_TRACE (AcpiInitializeSubsystem);
83 AcpiGbl_StartupFlags = ACPI_SUBSYSTEM_INITIALIZE;
84 ACPI_DEBUG_EXEC (AcpiUtInitStackPtrTrace ());
86 /* Initialize the OS-Dependent layer */
88 Status = AcpiOsInitialize ();
89 if (ACPI_FAILURE (Status))
91 ACPI_EXCEPTION ((AE_INFO, Status, "During OSL initialization"));
92 return_ACPI_STATUS (Status);
95 /* Initialize all globals used by the subsystem */
97 Status = AcpiUtInitGlobals ();
98 if (ACPI_FAILURE (Status))
100 ACPI_EXCEPTION ((AE_INFO, Status, "During initialization of globals"));
101 return_ACPI_STATUS (Status);
104 /* Create the default mutex objects */
106 Status = AcpiUtMutexInitialize ();
107 if (ACPI_FAILURE (Status))
109 ACPI_EXCEPTION ((AE_INFO, Status, "During Global Mutex creation"));
110 return_ACPI_STATUS (Status);
114 * Initialize the namespace manager and
115 * the root of the namespace tree
117 Status = AcpiNsRootInitialize ();
118 if (ACPI_FAILURE (Status))
120 ACPI_EXCEPTION ((AE_INFO, Status, "During Namespace initialization"));
121 return_ACPI_STATUS (Status);
124 /* Initialize the global OSI interfaces list with the static names */
126 Status = AcpiUtInitializeInterfaces ();
127 if (ACPI_FAILURE (Status))
129 ACPI_EXCEPTION ((AE_INFO, Status, "During OSI interfaces initialization"));
130 return_ACPI_STATUS (Status);
133 /* If configured, initialize the AML debugger */
135 ACPI_DEBUGGER_EXEC (Status = AcpiDbInitialize ());
136 return_ACPI_STATUS (Status);
139 ACPI_EXPORT_SYMBOL (AcpiInitializeSubsystem)
142 /*******************************************************************************
144 * FUNCTION: AcpiEnableSubsystem
146 * PARAMETERS: Flags - Init/enable Options
150 * DESCRIPTION: Completes the subsystem initialization including hardware.
151 * Puts system into ACPI mode if it isn't already.
153 ******************************************************************************/
156 AcpiEnableSubsystem (
159 ACPI_STATUS Status = AE_OK;
162 ACPI_FUNCTION_TRACE (AcpiEnableSubsystem);
165 /* Enable ACPI mode */
167 if (!(Flags & ACPI_NO_ACPI_ENABLE))
169 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Going into ACPI mode\n"));
171 AcpiGbl_OriginalMode = AcpiHwGetMode();
173 Status = AcpiEnable ();
174 if (ACPI_FAILURE (Status))
176 ACPI_WARNING ((AE_INFO, "AcpiEnable failed"));
177 return_ACPI_STATUS (Status);
182 * Obtain a permanent mapping for the FACS. This is required for the
183 * Global Lock and the Firmware Waking Vector
185 Status = AcpiTbInitializeFacs ();
186 if (ACPI_FAILURE (Status))
188 ACPI_WARNING ((AE_INFO, "Could not map the FACS table"));
189 return_ACPI_STATUS (Status);
193 * Install the default OpRegion handlers. These are installed unless
194 * other handlers have already been installed via the
195 * InstallAddressSpaceHandler interface.
197 if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
199 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
200 "[Init] Installing default address space handlers\n"));
202 Status = AcpiEvInstallRegionHandlers ();
203 if (ACPI_FAILURE (Status))
205 return_ACPI_STATUS (Status);
210 * Initialize ACPI Event handling (Fixed and General Purpose)
212 * Note1: We must have the hardware and events initialized before we can
213 * execute any control methods safely. Any control method can require
214 * ACPI hardware support, so the hardware must be fully initialized before
215 * any method execution!
217 * Note2: Fixed events are initialized and enabled here. GPEs are
218 * initialized, but cannot be enabled until after the hardware is
219 * completely initialized (SCI and GlobalLock activated) and the various
220 * initialization control methods are run (_REG, _STA, _INI) on the
223 if (!(Flags & ACPI_NO_EVENT_INIT))
225 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
226 "[Init] Initializing ACPI events\n"));
228 Status = AcpiEvInitializeEvents ();
229 if (ACPI_FAILURE (Status))
231 return_ACPI_STATUS (Status);
236 * Install the SCI handler and Global Lock handler. This completes the
237 * hardware initialization.
239 if (!(Flags & ACPI_NO_HANDLER_INIT))
241 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
242 "[Init] Installing SCI/GL handlers\n"));
244 Status = AcpiEvInstallXruptHandlers ();
245 if (ACPI_FAILURE (Status))
247 return_ACPI_STATUS (Status);
251 return_ACPI_STATUS (Status);
254 ACPI_EXPORT_SYMBOL (AcpiEnableSubsystem)
257 /*******************************************************************************
259 * FUNCTION: AcpiInitializeObjects
261 * PARAMETERS: Flags - Init/enable Options
265 * DESCRIPTION: Completes namespace initialization by initializing device
266 * objects and executing AML code for Regions, buffers, etc.
268 ******************************************************************************/
271 AcpiInitializeObjects (
274 ACPI_STATUS Status = AE_OK;
277 ACPI_FUNCTION_TRACE (AcpiInitializeObjects);
281 * Run all _REG methods
283 * Note: Any objects accessed by the _REG methods will be automatically
284 * initialized, even if they contain executable AML (see the call to
285 * AcpiNsInitializeObjects below).
287 if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
289 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
290 "[Init] Executing _REG OpRegion methods\n"));
292 Status = AcpiEvInitializeOpRegions ();
293 if (ACPI_FAILURE (Status))
295 return_ACPI_STATUS (Status);
300 * Execute any module-level code that was detected during the table load
301 * phase. Although illegal since ACPI 2.0, there are many machines that
302 * contain this type of code. Each block of detected executable AML code
303 * outside of any control method is wrapped with a temporary control
304 * method object and placed on a global list. The methods on this list
305 * are executed below.
307 AcpiNsExecModuleCodeList ();
310 * Initialize the objects that remain uninitialized. This runs the
311 * executable AML that may be part of the declaration of these objects:
312 * OperationRegions, BufferFields, Buffers, and Packages.
314 if (!(Flags & ACPI_NO_OBJECT_INIT))
316 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
317 "[Init] Completing Initialization of ACPI Objects\n"));
319 Status = AcpiNsInitializeObjects ();
320 if (ACPI_FAILURE (Status))
322 return_ACPI_STATUS (Status);
327 * Initialize all device objects in the namespace. This runs the device
328 * _STA and _INI methods.
330 if (!(Flags & ACPI_NO_DEVICE_INIT))
332 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
333 "[Init] Initializing ACPI Devices\n"));
335 Status = AcpiNsInitializeDevices ();
336 if (ACPI_FAILURE (Status))
338 return_ACPI_STATUS (Status);
343 * Empty the caches (delete the cached objects) on the assumption that
344 * the table load filled them up more than they will be at runtime --
345 * thus wasting non-paged memory.
347 Status = AcpiPurgeCachedObjects ();
349 AcpiGbl_StartupFlags |= ACPI_INITIALIZED_OK;
350 return_ACPI_STATUS (Status);
353 ACPI_EXPORT_SYMBOL (AcpiInitializeObjects)
358 /*******************************************************************************
360 * FUNCTION: AcpiTerminate
366 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
368 ******************************************************************************/
377 ACPI_FUNCTION_TRACE (AcpiTerminate);
380 /* Just exit if subsystem is already shutdown */
382 if (AcpiGbl_Shutdown)
384 ACPI_ERROR ((AE_INFO, "ACPI Subsystem is already terminated"));
385 return_ACPI_STATUS (AE_OK);
388 /* Subsystem appears active, go ahead and shut it down */
390 AcpiGbl_Shutdown = TRUE;
391 AcpiGbl_StartupFlags = 0;
392 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
394 /* Terminate the AML Debugger if present */
396 ACPI_DEBUGGER_EXEC (AcpiGbl_DbTerminateThreads = TRUE);
398 /* Shutdown and free all resources */
400 AcpiUtSubsystemShutdown ();
402 /* Free the mutex objects */
404 AcpiUtMutexTerminate ();
409 /* Shut down the debugger */
414 /* Now we can shutdown the OS-dependent layer */
416 Status = AcpiOsTerminate ();
417 return_ACPI_STATUS (Status);
420 ACPI_EXPORT_SYMBOL (AcpiTerminate)
423 #ifndef ACPI_ASL_COMPILER
424 /*******************************************************************************
426 * FUNCTION: AcpiSubsystemStatus
430 * RETURN: Status of the ACPI subsystem
432 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
433 * before making any other calls, to ensure the subsystem
434 * initialized successfully.
436 ******************************************************************************/
439 AcpiSubsystemStatus (
443 if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
453 ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)
456 /*******************************************************************************
458 * FUNCTION: AcpiGetSystemInfo
460 * PARAMETERS: OutBuffer - A buffer to receive the resources for the
463 * RETURN: Status - the status of the call
465 * DESCRIPTION: This function is called to get information about the current
466 * state of the ACPI subsystem. It will return system information
469 * If the function fails an appropriate status will be returned
470 * and the value of OutBuffer is undefined.
472 ******************************************************************************/
476 ACPI_BUFFER *OutBuffer)
478 ACPI_SYSTEM_INFO *InfoPtr;
482 ACPI_FUNCTION_TRACE (AcpiGetSystemInfo);
485 /* Parameter validation */
487 Status = AcpiUtValidateBuffer (OutBuffer);
488 if (ACPI_FAILURE (Status))
490 return_ACPI_STATUS (Status);
493 /* Validate/Allocate/Clear caller buffer */
495 Status = AcpiUtInitializeBuffer (OutBuffer, sizeof (ACPI_SYSTEM_INFO));
496 if (ACPI_FAILURE (Status))
498 return_ACPI_STATUS (Status);
502 * Populate the return buffer
504 InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer;
506 InfoPtr->AcpiCaVersion = ACPI_CA_VERSION;
508 /* System flags (ACPI capabilities) */
510 InfoPtr->Flags = ACPI_SYS_MODE_ACPI;
512 /* Timer resolution - 24 or 32 bits */
514 if (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER)
516 InfoPtr->TimerResolution = 24;
520 InfoPtr->TimerResolution = 32;
523 /* Clear the reserved fields */
525 InfoPtr->Reserved1 = 0;
526 InfoPtr->Reserved2 = 0;
528 /* Current debug levels */
530 InfoPtr->DebugLayer = AcpiDbgLayer;
531 InfoPtr->DebugLevel = AcpiDbgLevel;
533 return_ACPI_STATUS (AE_OK);
536 ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo)
539 /*******************************************************************************
541 * FUNCTION: AcpiGetStatistics
543 * PARAMETERS: Stats - Where the statistics are returned
545 * RETURN: Status - the status of the call
547 * DESCRIPTION: Get the contents of the various system counters
549 ******************************************************************************/
553 ACPI_STATISTICS *Stats)
555 ACPI_FUNCTION_TRACE (AcpiGetStatistics);
558 /* Parameter validation */
562 return_ACPI_STATUS (AE_BAD_PARAMETER);
565 /* Various interrupt-based event counters */
567 Stats->SciCount = AcpiSciCount;
568 Stats->GpeCount = AcpiGpeCount;
570 ACPI_MEMCPY (Stats->FixedEventCount, AcpiFixedEventCount,
571 sizeof (AcpiFixedEventCount));
576 Stats->MethodCount = AcpiMethodCount;
578 return_ACPI_STATUS (AE_OK);
581 ACPI_EXPORT_SYMBOL (AcpiGetStatistics)
584 /*****************************************************************************
586 * FUNCTION: AcpiInstallInitializationHandler
588 * PARAMETERS: Handler - Callback procedure
589 * Function - Not (currently) used, see below
593 * DESCRIPTION: Install an initialization handler
595 * TBD: When a second function is added, must save the Function also.
597 ****************************************************************************/
600 AcpiInstallInitializationHandler (
601 ACPI_INIT_HANDLER Handler,
607 return (AE_BAD_PARAMETER);
610 if (AcpiGbl_InitHandler)
612 return (AE_ALREADY_EXISTS);
615 AcpiGbl_InitHandler = Handler;
619 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
622 /*****************************************************************************
624 * FUNCTION: AcpiPurgeCachedObjects
630 * DESCRIPTION: Empty all caches (delete the cached objects)
632 ****************************************************************************/
635 AcpiPurgeCachedObjects (
638 ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects);
640 (void) AcpiOsPurgeCache (AcpiGbl_StateCache);
641 (void) AcpiOsPurgeCache (AcpiGbl_OperandCache);
642 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);
643 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);
644 return_ACPI_STATUS (AE_OK);
647 ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)
650 /*****************************************************************************
652 * FUNCTION: AcpiInstallInterface
654 * PARAMETERS: InterfaceName - The interface to install
658 * DESCRIPTION: Install an _OSI interface to the global list
660 ****************************************************************************/
663 AcpiInstallInterface (
664 ACPI_STRING InterfaceName)
667 ACPI_INTERFACE_INFO *InterfaceInfo;
670 /* Parameter validation */
672 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
674 return (AE_BAD_PARAMETER);
677 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
679 /* Check if the interface name is already in the global list */
681 InterfaceInfo = AcpiUtGetInterface (InterfaceName);
685 * The interface already exists in the list. This is OK if the
686 * interface has been marked invalid -- just clear the bit.
688 if (InterfaceInfo->Flags & ACPI_OSI_INVALID)
690 InterfaceInfo->Flags &= ~ACPI_OSI_INVALID;
695 Status = AE_ALREADY_EXISTS;
700 /* New interface name, install into the global list */
702 Status = AcpiUtInstallInterface (InterfaceName);
705 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
709 ACPI_EXPORT_SYMBOL (AcpiInstallInterface)
712 /*****************************************************************************
714 * FUNCTION: AcpiRemoveInterface
716 * PARAMETERS: InterfaceName - The interface to remove
720 * DESCRIPTION: Remove an _OSI interface from the global list
722 ****************************************************************************/
725 AcpiRemoveInterface (
726 ACPI_STRING InterfaceName)
731 /* Parameter validation */
733 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
735 return (AE_BAD_PARAMETER);
738 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
740 Status = AcpiUtRemoveInterface (InterfaceName);
742 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
746 ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)
749 /*****************************************************************************
751 * FUNCTION: AcpiInstallInterfaceHandler
753 * PARAMETERS: Handler - The _OSI interface handler to install
754 * NULL means "remove existing handler"
758 * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
759 * invoked during execution of the internal implementation of
760 * _OSI. A NULL handler simply removes any existing handler.
762 ****************************************************************************/
765 AcpiInstallInterfaceHandler (
766 ACPI_INTERFACE_HANDLER Handler)
768 ACPI_STATUS Status = AE_OK;
771 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
773 if (Handler && AcpiGbl_InterfaceHandler)
775 Status = AE_ALREADY_EXISTS;
779 AcpiGbl_InterfaceHandler = Handler;
782 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
786 ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)
788 #endif /* !ACPI_ASL_COMPILER */