1 /******************************************************************************
3 * Module Name: utxface - External interfaces for "global" ACPI functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, 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
59 /*******************************************************************************
61 * FUNCTION: AcpiInitializeSubsystem
67 * DESCRIPTION: Initializes all global variables. This is the first function
68 * called, so any early initialization belongs here.
70 ******************************************************************************/
73 AcpiInitializeSubsystem (
79 ACPI_FUNCTION_TRACE (AcpiInitializeSubsystem);
82 AcpiGbl_StartupFlags = ACPI_SUBSYSTEM_INITIALIZE;
83 ACPI_DEBUG_EXEC (AcpiUtInitStackPtrTrace ());
85 /* Initialize the OS-Dependent layer */
87 Status = AcpiOsInitialize ();
88 if (ACPI_FAILURE (Status))
90 ACPI_EXCEPTION ((AE_INFO, Status, "During OSL initialization"));
91 return_ACPI_STATUS (Status);
94 /* Initialize all globals used by the subsystem */
96 Status = AcpiUtInitGlobals ();
97 if (ACPI_FAILURE (Status))
99 ACPI_EXCEPTION ((AE_INFO, Status, "During initialization of globals"));
100 return_ACPI_STATUS (Status);
103 /* Create the default mutex objects */
105 Status = AcpiUtMutexInitialize ();
106 if (ACPI_FAILURE (Status))
108 ACPI_EXCEPTION ((AE_INFO, Status, "During Global Mutex creation"));
109 return_ACPI_STATUS (Status);
113 * Initialize the namespace manager and
114 * the root of the namespace tree
116 Status = AcpiNsRootInitialize ();
117 if (ACPI_FAILURE (Status))
119 ACPI_EXCEPTION ((AE_INFO, Status, "During Namespace initialization"));
120 return_ACPI_STATUS (Status);
123 /* Initialize the global OSI interfaces list with the static names */
125 Status = AcpiUtInitializeInterfaces ();
126 if (ACPI_FAILURE (Status))
128 ACPI_EXCEPTION ((AE_INFO, Status, "During OSI interfaces initialization"));
129 return_ACPI_STATUS (Status);
132 /* If configured, initialize the AML debugger */
134 ACPI_DEBUGGER_EXEC (Status = AcpiDbInitialize ());
135 return_ACPI_STATUS (Status);
138 ACPI_EXPORT_SYMBOL (AcpiInitializeSubsystem)
141 /*******************************************************************************
143 * FUNCTION: AcpiEnableSubsystem
145 * PARAMETERS: Flags - Init/enable Options
149 * DESCRIPTION: Completes the subsystem initialization including hardware.
150 * Puts system into ACPI mode if it isn't already.
152 ******************************************************************************/
155 AcpiEnableSubsystem (
158 ACPI_STATUS Status = AE_OK;
161 ACPI_FUNCTION_TRACE (AcpiEnableSubsystem);
164 #if (!ACPI_REDUCED_HARDWARE)
166 /* Enable ACPI mode */
168 if (!(Flags & ACPI_NO_ACPI_ENABLE))
170 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Going into ACPI mode\n"));
172 AcpiGbl_OriginalMode = AcpiHwGetMode();
174 Status = AcpiEnable ();
175 if (ACPI_FAILURE (Status))
177 ACPI_WARNING ((AE_INFO, "AcpiEnable failed"));
178 return_ACPI_STATUS (Status);
183 * Obtain a permanent mapping for the FACS. This is required for the
184 * Global Lock and the Firmware Waking Vector
186 Status = AcpiTbInitializeFacs ();
187 if (ACPI_FAILURE (Status))
189 ACPI_WARNING ((AE_INFO, "Could not map the FACS table"));
190 return_ACPI_STATUS (Status);
193 #endif /* !ACPI_REDUCED_HARDWARE */
196 * Install the default OpRegion handlers. These are installed unless
197 * other handlers have already been installed via the
198 * InstallAddressSpaceHandler interface.
200 if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
202 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
203 "[Init] Installing default address space handlers\n"));
205 Status = AcpiEvInstallRegionHandlers ();
206 if (ACPI_FAILURE (Status))
208 return_ACPI_STATUS (Status);
212 #if (!ACPI_REDUCED_HARDWARE)
214 * Initialize ACPI Event handling (Fixed and General Purpose)
216 * Note1: We must have the hardware and events initialized before we can
217 * execute any control methods safely. Any control method can require
218 * ACPI hardware support, so the hardware must be fully initialized before
219 * any method execution!
221 * Note2: Fixed events are initialized and enabled here. GPEs are
222 * initialized, but cannot be enabled until after the hardware is
223 * completely initialized (SCI and GlobalLock activated) and the various
224 * initialization control methods are run (_REG, _STA, _INI) on the
227 if (!(Flags & ACPI_NO_EVENT_INIT))
229 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
230 "[Init] Initializing ACPI events\n"));
232 Status = AcpiEvInitializeEvents ();
233 if (ACPI_FAILURE (Status))
235 return_ACPI_STATUS (Status);
240 * Install the SCI handler and Global Lock handler. This completes the
241 * hardware initialization.
243 if (!(Flags & ACPI_NO_HANDLER_INIT))
245 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
246 "[Init] Installing SCI/GL handlers\n"));
248 Status = AcpiEvInstallXruptHandlers ();
249 if (ACPI_FAILURE (Status))
251 return_ACPI_STATUS (Status);
255 #endif /* !ACPI_REDUCED_HARDWARE */
257 return_ACPI_STATUS (Status);
260 ACPI_EXPORT_SYMBOL (AcpiEnableSubsystem)
263 /*******************************************************************************
265 * FUNCTION: AcpiInitializeObjects
267 * PARAMETERS: Flags - Init/enable Options
271 * DESCRIPTION: Completes namespace initialization by initializing device
272 * objects and executing AML code for Regions, buffers, etc.
274 ******************************************************************************/
277 AcpiInitializeObjects (
280 ACPI_STATUS Status = AE_OK;
283 ACPI_FUNCTION_TRACE (AcpiInitializeObjects);
287 * Run all _REG methods
289 * Note: Any objects accessed by the _REG methods will be automatically
290 * initialized, even if they contain executable AML (see the call to
291 * AcpiNsInitializeObjects below).
293 if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
295 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
296 "[Init] Executing _REG OpRegion methods\n"));
298 Status = AcpiEvInitializeOpRegions ();
299 if (ACPI_FAILURE (Status))
301 return_ACPI_STATUS (Status);
306 * Execute any module-level code that was detected during the table load
307 * phase. Although illegal since ACPI 2.0, there are many machines that
308 * contain this type of code. Each block of detected executable AML code
309 * outside of any control method is wrapped with a temporary control
310 * method object and placed on a global list. The methods on this list
311 * are executed below.
313 AcpiNsExecModuleCodeList ();
316 * Initialize the objects that remain uninitialized. This runs the
317 * executable AML that may be part of the declaration of these objects:
318 * OperationRegions, BufferFields, Buffers, and Packages.
320 if (!(Flags & ACPI_NO_OBJECT_INIT))
322 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
323 "[Init] Completing Initialization of ACPI Objects\n"));
325 Status = AcpiNsInitializeObjects ();
326 if (ACPI_FAILURE (Status))
328 return_ACPI_STATUS (Status);
333 * Initialize all device objects in the namespace. This runs the device
334 * _STA and _INI methods.
336 if (!(Flags & ACPI_NO_DEVICE_INIT))
338 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
339 "[Init] Initializing ACPI Devices\n"));
341 Status = AcpiNsInitializeDevices ();
342 if (ACPI_FAILURE (Status))
344 return_ACPI_STATUS (Status);
349 * Empty the caches (delete the cached objects) on the assumption that
350 * the table load filled them up more than they will be at runtime --
351 * thus wasting non-paged memory.
353 Status = AcpiPurgeCachedObjects ();
355 AcpiGbl_StartupFlags |= ACPI_INITIALIZED_OK;
356 return_ACPI_STATUS (Status);
359 ACPI_EXPORT_SYMBOL (AcpiInitializeObjects)
364 /*******************************************************************************
366 * FUNCTION: AcpiTerminate
372 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
374 ******************************************************************************/
383 ACPI_FUNCTION_TRACE (AcpiTerminate);
386 /* Just exit if subsystem is already shutdown */
388 if (AcpiGbl_Shutdown)
390 ACPI_ERROR ((AE_INFO, "ACPI Subsystem is already terminated"));
391 return_ACPI_STATUS (AE_OK);
394 /* Subsystem appears active, go ahead and shut it down */
396 AcpiGbl_Shutdown = TRUE;
397 AcpiGbl_StartupFlags = 0;
398 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
400 /* Terminate the AML Debugger if present */
402 ACPI_DEBUGGER_EXEC (AcpiGbl_DbTerminateThreads = TRUE);
404 /* Shutdown and free all resources */
406 AcpiUtSubsystemShutdown ();
408 /* Free the mutex objects */
410 AcpiUtMutexTerminate ();
415 /* Shut down the debugger */
420 /* Now we can shutdown the OS-dependent layer */
422 Status = AcpiOsTerminate ();
423 return_ACPI_STATUS (Status);
426 ACPI_EXPORT_SYMBOL (AcpiTerminate)
429 #ifndef ACPI_ASL_COMPILER
430 /*******************************************************************************
432 * FUNCTION: AcpiSubsystemStatus
436 * RETURN: Status of the ACPI subsystem
438 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
439 * before making any other calls, to ensure the subsystem
440 * initialized successfully.
442 ******************************************************************************/
445 AcpiSubsystemStatus (
449 if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
459 ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)
462 /*******************************************************************************
464 * FUNCTION: AcpiGetSystemInfo
466 * PARAMETERS: OutBuffer - A buffer to receive the resources for the
469 * RETURN: Status - the status of the call
471 * DESCRIPTION: This function is called to get information about the current
472 * state of the ACPI subsystem. It will return system information
475 * If the function fails an appropriate status will be returned
476 * and the value of OutBuffer is undefined.
478 ******************************************************************************/
482 ACPI_BUFFER *OutBuffer)
484 ACPI_SYSTEM_INFO *InfoPtr;
488 ACPI_FUNCTION_TRACE (AcpiGetSystemInfo);
491 /* Parameter validation */
493 Status = AcpiUtValidateBuffer (OutBuffer);
494 if (ACPI_FAILURE (Status))
496 return_ACPI_STATUS (Status);
499 /* Validate/Allocate/Clear caller buffer */
501 Status = AcpiUtInitializeBuffer (OutBuffer, sizeof (ACPI_SYSTEM_INFO));
502 if (ACPI_FAILURE (Status))
504 return_ACPI_STATUS (Status);
508 * Populate the return buffer
510 InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer;
512 InfoPtr->AcpiCaVersion = ACPI_CA_VERSION;
514 /* System flags (ACPI capabilities) */
516 InfoPtr->Flags = ACPI_SYS_MODE_ACPI;
518 /* Timer resolution - 24 or 32 bits */
520 if (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER)
522 InfoPtr->TimerResolution = 24;
526 InfoPtr->TimerResolution = 32;
529 /* Clear the reserved fields */
531 InfoPtr->Reserved1 = 0;
532 InfoPtr->Reserved2 = 0;
534 /* Current debug levels */
536 InfoPtr->DebugLayer = AcpiDbgLayer;
537 InfoPtr->DebugLevel = AcpiDbgLevel;
539 return_ACPI_STATUS (AE_OK);
542 ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo)
545 /*******************************************************************************
547 * FUNCTION: AcpiGetStatistics
549 * PARAMETERS: Stats - Where the statistics are returned
551 * RETURN: Status - the status of the call
553 * DESCRIPTION: Get the contents of the various system counters
555 ******************************************************************************/
559 ACPI_STATISTICS *Stats)
561 ACPI_FUNCTION_TRACE (AcpiGetStatistics);
564 /* Parameter validation */
568 return_ACPI_STATUS (AE_BAD_PARAMETER);
571 /* Various interrupt-based event counters */
573 Stats->SciCount = AcpiSciCount;
574 Stats->GpeCount = AcpiGpeCount;
576 ACPI_MEMCPY (Stats->FixedEventCount, AcpiFixedEventCount,
577 sizeof (AcpiFixedEventCount));
582 Stats->MethodCount = AcpiMethodCount;
584 return_ACPI_STATUS (AE_OK);
587 ACPI_EXPORT_SYMBOL (AcpiGetStatistics)
590 /*****************************************************************************
592 * FUNCTION: AcpiInstallInitializationHandler
594 * PARAMETERS: Handler - Callback procedure
595 * Function - Not (currently) used, see below
599 * DESCRIPTION: Install an initialization handler
601 * TBD: When a second function is added, must save the Function also.
603 ****************************************************************************/
606 AcpiInstallInitializationHandler (
607 ACPI_INIT_HANDLER Handler,
613 return (AE_BAD_PARAMETER);
616 if (AcpiGbl_InitHandler)
618 return (AE_ALREADY_EXISTS);
621 AcpiGbl_InitHandler = Handler;
625 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
628 /*****************************************************************************
630 * FUNCTION: AcpiPurgeCachedObjects
636 * DESCRIPTION: Empty all caches (delete the cached objects)
638 ****************************************************************************/
641 AcpiPurgeCachedObjects (
644 ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects);
646 (void) AcpiOsPurgeCache (AcpiGbl_StateCache);
647 (void) AcpiOsPurgeCache (AcpiGbl_OperandCache);
648 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);
649 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);
650 return_ACPI_STATUS (AE_OK);
653 ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)
656 /*****************************************************************************
658 * FUNCTION: AcpiInstallInterface
660 * PARAMETERS: InterfaceName - The interface to install
664 * DESCRIPTION: Install an _OSI interface to the global list
666 ****************************************************************************/
669 AcpiInstallInterface (
670 ACPI_STRING InterfaceName)
673 ACPI_INTERFACE_INFO *InterfaceInfo;
676 /* Parameter validation */
678 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
680 return (AE_BAD_PARAMETER);
683 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
685 /* Check if the interface name is already in the global list */
687 InterfaceInfo = AcpiUtGetInterface (InterfaceName);
691 * The interface already exists in the list. This is OK if the
692 * interface has been marked invalid -- just clear the bit.
694 if (InterfaceInfo->Flags & ACPI_OSI_INVALID)
696 InterfaceInfo->Flags &= ~ACPI_OSI_INVALID;
701 Status = AE_ALREADY_EXISTS;
706 /* New interface name, install into the global list */
708 Status = AcpiUtInstallInterface (InterfaceName);
711 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
715 ACPI_EXPORT_SYMBOL (AcpiInstallInterface)
718 /*****************************************************************************
720 * FUNCTION: AcpiRemoveInterface
722 * PARAMETERS: InterfaceName - The interface to remove
726 * DESCRIPTION: Remove an _OSI interface from the global list
728 ****************************************************************************/
731 AcpiRemoveInterface (
732 ACPI_STRING InterfaceName)
737 /* Parameter validation */
739 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
741 return (AE_BAD_PARAMETER);
744 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
746 Status = AcpiUtRemoveInterface (InterfaceName);
748 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
752 ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)
755 /*****************************************************************************
757 * FUNCTION: AcpiInstallInterfaceHandler
759 * PARAMETERS: Handler - The _OSI interface handler to install
760 * NULL means "remove existing handler"
764 * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
765 * invoked during execution of the internal implementation of
766 * _OSI. A NULL handler simply removes any existing handler.
768 ****************************************************************************/
771 AcpiInstallInterfaceHandler (
772 ACPI_INTERFACE_HANDLER Handler)
774 ACPI_STATUS Status = AE_OK;
777 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
779 if (Handler && AcpiGbl_InterfaceHandler)
781 Status = AE_ALREADY_EXISTS;
785 AcpiGbl_InterfaceHandler = Handler;
788 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
792 ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)
795 /*****************************************************************************
797 * FUNCTION: AcpiCheckAddressRange
799 * PARAMETERS: SpaceId - Address space ID
800 * Address - Start address
802 * Warn - TRUE if warning on overlap desired
804 * RETURN: Count of the number of conflicts detected.
806 * DESCRIPTION: Check if the input address range overlaps any of the
807 * ASL operation region address ranges.
809 ****************************************************************************/
812 AcpiCheckAddressRange (
813 ACPI_ADR_SPACE_TYPE SpaceId,
814 ACPI_PHYSICAL_ADDRESS Address,
822 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
823 if (ACPI_FAILURE (Status))
828 Overlaps = AcpiUtCheckAddressRange (SpaceId, Address,
829 (UINT32) Length, Warn);
831 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
835 ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange)
837 #endif /* !ACPI_ASL_COMPILER */