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.
55 #define _COMPONENT ACPI_UTILITIES
56 ACPI_MODULE_NAME ("utxface")
59 #ifndef ACPI_ASL_COMPILER
61 /*******************************************************************************
63 * FUNCTION: AcpiInitializeSubsystem
69 * DESCRIPTION: Initializes all global variables. This is the first function
70 * called, so any early initialization belongs here.
72 ******************************************************************************/
75 AcpiInitializeSubsystem (
81 ACPI_FUNCTION_TRACE (AcpiInitializeSubsystem);
84 AcpiGbl_StartupFlags = ACPI_SUBSYSTEM_INITIALIZE;
85 ACPI_DEBUG_EXEC (AcpiUtInitStackPtrTrace ());
87 /* Initialize the OS-Dependent layer */
89 Status = AcpiOsInitialize ();
90 if (ACPI_FAILURE (Status))
92 ACPI_EXCEPTION ((AE_INFO, Status, "During OSL initialization"));
93 return_ACPI_STATUS (Status);
96 /* Initialize all globals used by the subsystem */
98 Status = AcpiUtInitGlobals ();
99 if (ACPI_FAILURE (Status))
101 ACPI_EXCEPTION ((AE_INFO, Status, "During initialization of globals"));
102 return_ACPI_STATUS (Status);
105 /* Create the default mutex objects */
107 Status = AcpiUtMutexInitialize ();
108 if (ACPI_FAILURE (Status))
110 ACPI_EXCEPTION ((AE_INFO, Status, "During Global Mutex creation"));
111 return_ACPI_STATUS (Status);
115 * Initialize the namespace manager and
116 * the root of the namespace tree
118 Status = AcpiNsRootInitialize ();
119 if (ACPI_FAILURE (Status))
121 ACPI_EXCEPTION ((AE_INFO, Status, "During Namespace initialization"));
122 return_ACPI_STATUS (Status);
125 /* Initialize the global OSI interfaces list with the static names */
127 Status = AcpiUtInitializeInterfaces ();
128 if (ACPI_FAILURE (Status))
130 ACPI_EXCEPTION ((AE_INFO, Status, "During OSI interfaces initialization"));
131 return_ACPI_STATUS (Status);
134 /* If configured, initialize the AML debugger */
136 ACPI_DEBUGGER_EXEC (Status = AcpiDbInitialize ());
137 return_ACPI_STATUS (Status);
140 ACPI_EXPORT_SYMBOL (AcpiInitializeSubsystem)
143 /*******************************************************************************
145 * FUNCTION: AcpiEnableSubsystem
147 * PARAMETERS: Flags - Init/enable Options
151 * DESCRIPTION: Completes the subsystem initialization including hardware.
152 * Puts system into ACPI mode if it isn't already.
154 ******************************************************************************/
157 AcpiEnableSubsystem (
160 ACPI_STATUS Status = AE_OK;
163 ACPI_FUNCTION_TRACE (AcpiEnableSubsystem);
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);
194 * Install the default OpRegion handlers. These are installed unless
195 * other handlers have already been installed via the
196 * InstallAddressSpaceHandler interface.
198 if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
200 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
201 "[Init] Installing default address space handlers\n"));
203 Status = AcpiEvInstallRegionHandlers ();
204 if (ACPI_FAILURE (Status))
206 return_ACPI_STATUS (Status);
211 * Initialize ACPI Event handling (Fixed and General Purpose)
213 * Note1: We must have the hardware and events initialized before we can
214 * execute any control methods safely. Any control method can require
215 * ACPI hardware support, so the hardware must be fully initialized before
216 * any method execution!
218 * Note2: Fixed events are initialized and enabled here. GPEs are
219 * initialized, but cannot be enabled until after the hardware is
220 * completely initialized (SCI and GlobalLock activated) and the various
221 * initialization control methods are run (_REG, _STA, _INI) on the
224 if (!(Flags & ACPI_NO_EVENT_INIT))
226 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
227 "[Init] Initializing ACPI events\n"));
229 Status = AcpiEvInitializeEvents ();
230 if (ACPI_FAILURE (Status))
232 return_ACPI_STATUS (Status);
237 * Install the SCI handler and Global Lock handler. This completes the
238 * hardware initialization.
240 if (!(Flags & ACPI_NO_HANDLER_INIT))
242 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
243 "[Init] Installing SCI/GL handlers\n"));
245 Status = AcpiEvInstallXruptHandlers ();
246 if (ACPI_FAILURE (Status))
248 return_ACPI_STATUS (Status);
252 return_ACPI_STATUS (Status);
255 ACPI_EXPORT_SYMBOL (AcpiEnableSubsystem)
258 /*******************************************************************************
260 * FUNCTION: AcpiInitializeObjects
262 * PARAMETERS: Flags - Init/enable Options
266 * DESCRIPTION: Completes namespace initialization by initializing device
267 * objects and executing AML code for Regions, buffers, etc.
269 ******************************************************************************/
272 AcpiInitializeObjects (
275 ACPI_STATUS Status = AE_OK;
278 ACPI_FUNCTION_TRACE (AcpiInitializeObjects);
282 * Run all _REG methods
284 * Note: Any objects accessed by the _REG methods will be automatically
285 * initialized, even if they contain executable AML (see the call to
286 * AcpiNsInitializeObjects below).
288 if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
290 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
291 "[Init] Executing _REG OpRegion methods\n"));
293 Status = AcpiEvInitializeOpRegions ();
294 if (ACPI_FAILURE (Status))
296 return_ACPI_STATUS (Status);
301 * Execute any module-level code that was detected during the table load
302 * phase. Although illegal since ACPI 2.0, there are many machines that
303 * contain this type of code. Each block of detected executable AML code
304 * outside of any control method is wrapped with a temporary control
305 * method object and placed on a global list. The methods on this list
306 * are executed below.
308 AcpiNsExecModuleCodeList ();
311 * Initialize the objects that remain uninitialized. This runs the
312 * executable AML that may be part of the declaration of these objects:
313 * OperationRegions, BufferFields, Buffers, and Packages.
315 if (!(Flags & ACPI_NO_OBJECT_INIT))
317 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
318 "[Init] Completing Initialization of ACPI Objects\n"));
320 Status = AcpiNsInitializeObjects ();
321 if (ACPI_FAILURE (Status))
323 return_ACPI_STATUS (Status);
328 * Initialize all device objects in the namespace. This runs the device
329 * _STA and _INI methods.
331 if (!(Flags & ACPI_NO_DEVICE_INIT))
333 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
334 "[Init] Initializing ACPI Devices\n"));
336 Status = AcpiNsInitializeDevices ();
337 if (ACPI_FAILURE (Status))
339 return_ACPI_STATUS (Status);
344 * Empty the caches (delete the cached objects) on the assumption that
345 * the table load filled them up more than they will be at runtime --
346 * thus wasting non-paged memory.
348 Status = AcpiPurgeCachedObjects ();
350 AcpiGbl_StartupFlags |= ACPI_INITIALIZED_OK;
351 return_ACPI_STATUS (Status);
354 ACPI_EXPORT_SYMBOL (AcpiInitializeObjects)
359 /*******************************************************************************
361 * FUNCTION: AcpiTerminate
367 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
369 ******************************************************************************/
378 ACPI_FUNCTION_TRACE (AcpiTerminate);
381 /* Just exit if subsystem is already shutdown */
383 if (AcpiGbl_Shutdown)
385 ACPI_ERROR ((AE_INFO, "ACPI Subsystem is already terminated"));
386 return_ACPI_STATUS (AE_OK);
389 /* Subsystem appears active, go ahead and shut it down */
391 AcpiGbl_Shutdown = TRUE;
392 AcpiGbl_StartupFlags = 0;
393 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
395 /* Terminate the AML Debugger if present */
397 ACPI_DEBUGGER_EXEC (AcpiGbl_DbTerminateThreads = TRUE);
399 /* Shutdown and free all resources */
401 AcpiUtSubsystemShutdown ();
403 /* Free the mutex objects */
405 AcpiUtMutexTerminate ();
410 /* Shut down the debugger */
415 /* Now we can shutdown the OS-dependent layer */
417 Status = AcpiOsTerminate ();
418 return_ACPI_STATUS (Status);
421 ACPI_EXPORT_SYMBOL (AcpiTerminate)
424 #ifndef ACPI_ASL_COMPILER
425 /*******************************************************************************
427 * FUNCTION: AcpiSubsystemStatus
431 * RETURN: Status of the ACPI subsystem
433 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
434 * before making any other calls, to ensure the subsystem
435 * initialized successfully.
437 ******************************************************************************/
440 AcpiSubsystemStatus (
444 if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
454 ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)
457 /*******************************************************************************
459 * FUNCTION: AcpiGetSystemInfo
461 * PARAMETERS: OutBuffer - A buffer to receive the resources for the
464 * RETURN: Status - the status of the call
466 * DESCRIPTION: This function is called to get information about the current
467 * state of the ACPI subsystem. It will return system information
470 * If the function fails an appropriate status will be returned
471 * and the value of OutBuffer is undefined.
473 ******************************************************************************/
477 ACPI_BUFFER *OutBuffer)
479 ACPI_SYSTEM_INFO *InfoPtr;
483 ACPI_FUNCTION_TRACE (AcpiGetSystemInfo);
486 /* Parameter validation */
488 Status = AcpiUtValidateBuffer (OutBuffer);
489 if (ACPI_FAILURE (Status))
491 return_ACPI_STATUS (Status);
494 /* Validate/Allocate/Clear caller buffer */
496 Status = AcpiUtInitializeBuffer (OutBuffer, sizeof (ACPI_SYSTEM_INFO));
497 if (ACPI_FAILURE (Status))
499 return_ACPI_STATUS (Status);
503 * Populate the return buffer
505 InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer;
507 InfoPtr->AcpiCaVersion = ACPI_CA_VERSION;
509 /* System flags (ACPI capabilities) */
511 InfoPtr->Flags = ACPI_SYS_MODE_ACPI;
513 /* Timer resolution - 24 or 32 bits */
515 if (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER)
517 InfoPtr->TimerResolution = 24;
521 InfoPtr->TimerResolution = 32;
524 /* Clear the reserved fields */
526 InfoPtr->Reserved1 = 0;
527 InfoPtr->Reserved2 = 0;
529 /* Current debug levels */
531 InfoPtr->DebugLayer = AcpiDbgLayer;
532 InfoPtr->DebugLevel = AcpiDbgLevel;
534 return_ACPI_STATUS (AE_OK);
537 ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo)
540 /*******************************************************************************
542 * FUNCTION: AcpiGetStatistics
544 * PARAMETERS: Stats - Where the statistics are returned
546 * RETURN: Status - the status of the call
548 * DESCRIPTION: Get the contents of the various system counters
550 ******************************************************************************/
554 ACPI_STATISTICS *Stats)
556 ACPI_FUNCTION_TRACE (AcpiGetStatistics);
559 /* Parameter validation */
563 return_ACPI_STATUS (AE_BAD_PARAMETER);
566 /* Various interrupt-based event counters */
568 Stats->SciCount = AcpiSciCount;
569 Stats->GpeCount = AcpiGpeCount;
571 ACPI_MEMCPY (Stats->FixedEventCount, AcpiFixedEventCount,
572 sizeof (AcpiFixedEventCount));
577 Stats->MethodCount = AcpiMethodCount;
579 return_ACPI_STATUS (AE_OK);
582 ACPI_EXPORT_SYMBOL (AcpiGetStatistics)
585 /*****************************************************************************
587 * FUNCTION: AcpiInstallInitializationHandler
589 * PARAMETERS: Handler - Callback procedure
590 * Function - Not (currently) used, see below
594 * DESCRIPTION: Install an initialization handler
596 * TBD: When a second function is added, must save the Function also.
598 ****************************************************************************/
601 AcpiInstallInitializationHandler (
602 ACPI_INIT_HANDLER Handler,
608 return (AE_BAD_PARAMETER);
611 if (AcpiGbl_InitHandler)
613 return (AE_ALREADY_EXISTS);
616 AcpiGbl_InitHandler = Handler;
620 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
623 /*****************************************************************************
625 * FUNCTION: AcpiPurgeCachedObjects
631 * DESCRIPTION: Empty all caches (delete the cached objects)
633 ****************************************************************************/
636 AcpiPurgeCachedObjects (
639 ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects);
641 (void) AcpiOsPurgeCache (AcpiGbl_StateCache);
642 (void) AcpiOsPurgeCache (AcpiGbl_OperandCache);
643 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);
644 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);
645 return_ACPI_STATUS (AE_OK);
648 ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)
651 /*****************************************************************************
653 * FUNCTION: AcpiInstallInterface
655 * PARAMETERS: InterfaceName - The interface to install
659 * DESCRIPTION: Install an _OSI interface to the global list
661 ****************************************************************************/
664 AcpiInstallInterface (
665 ACPI_STRING InterfaceName)
668 ACPI_INTERFACE_INFO *InterfaceInfo;
671 /* Parameter validation */
673 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
675 return (AE_BAD_PARAMETER);
678 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
680 /* Check if the interface name is already in the global list */
682 InterfaceInfo = AcpiUtGetInterface (InterfaceName);
686 * The interface already exists in the list. This is OK if the
687 * interface has been marked invalid -- just clear the bit.
689 if (InterfaceInfo->Flags & ACPI_OSI_INVALID)
691 InterfaceInfo->Flags &= ~ACPI_OSI_INVALID;
696 Status = AE_ALREADY_EXISTS;
701 /* New interface name, install into the global list */
703 Status = AcpiUtInstallInterface (InterfaceName);
706 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
710 ACPI_EXPORT_SYMBOL (AcpiInstallInterface)
713 /*****************************************************************************
715 * FUNCTION: AcpiRemoveInterface
717 * PARAMETERS: InterfaceName - The interface to remove
721 * DESCRIPTION: Remove an _OSI interface from the global list
723 ****************************************************************************/
726 AcpiRemoveInterface (
727 ACPI_STRING InterfaceName)
732 /* Parameter validation */
734 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
736 return (AE_BAD_PARAMETER);
739 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
741 Status = AcpiUtRemoveInterface (InterfaceName);
743 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
747 ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)
750 /*****************************************************************************
752 * FUNCTION: AcpiInstallInterfaceHandler
754 * PARAMETERS: Handler - The _OSI interface handler to install
755 * NULL means "remove existing handler"
759 * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
760 * invoked during execution of the internal implementation of
761 * _OSI. A NULL handler simply removes any existing handler.
763 ****************************************************************************/
766 AcpiInstallInterfaceHandler (
767 ACPI_INTERFACE_HANDLER Handler)
769 ACPI_STATUS Status = AE_OK;
772 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
774 if (Handler && AcpiGbl_InterfaceHandler)
776 Status = AE_ALREADY_EXISTS;
780 AcpiGbl_InterfaceHandler = Handler;
783 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
787 ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)
790 /*****************************************************************************
792 * FUNCTION: AcpiCheckAddressRange
794 * PARAMETERS: SpaceId - Address space ID
795 * Address - Start address
797 * Warn - TRUE if warning on overlap desired
799 * RETURN: Count of the number of conflicts detected.
801 * DESCRIPTION: Check if the input address range overlaps any of the
802 * ASL operation region address ranges.
804 ****************************************************************************/
807 AcpiCheckAddressRange (
808 ACPI_ADR_SPACE_TYPE SpaceId,
809 ACPI_PHYSICAL_ADDRESS Address,
817 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
818 if (ACPI_FAILURE (Status))
823 Overlaps = AcpiUtCheckAddressRange (SpaceId, Address,
824 (UINT32) Length, Warn);
826 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
830 ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange)
832 #endif /* !ACPI_ASL_COMPILER */