Path: blob/main/sys/contrib/dev/acpica/components/utilities/utinit.c
48406 views
/******************************************************************************1*2* Module Name: utinit - Common ACPI subsystem initialization3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acnamesp.h>154#include <contrib/dev/acpica/include/acevents.h>155#include <contrib/dev/acpica/include/actables.h>156157#define _COMPONENT ACPI_UTILITIES158ACPI_MODULE_NAME ("utinit")159160/* Local prototypes */161162static void AcpiUtTerminate (163void);164165#if (!ACPI_REDUCED_HARDWARE)166167static void168AcpiUtFreeGpeLists (169void);170171#else172173#define AcpiUtFreeGpeLists()174#endif /* !ACPI_REDUCED_HARDWARE */175176177#if (!ACPI_REDUCED_HARDWARE)178/******************************************************************************179*180* FUNCTION: AcpiUtFreeGpeLists181*182* PARAMETERS: none183*184* RETURN: none185*186* DESCRIPTION: Free global GPE lists187*188******************************************************************************/189190static void191AcpiUtFreeGpeLists (192void)193{194ACPI_GPE_BLOCK_INFO *GpeBlock;195ACPI_GPE_BLOCK_INFO *NextGpeBlock;196ACPI_GPE_XRUPT_INFO *GpeXruptInfo;197ACPI_GPE_XRUPT_INFO *NextGpeXruptInfo;198199200/* Free global GPE blocks and related info structures */201202GpeXruptInfo = AcpiGbl_GpeXruptListHead;203while (GpeXruptInfo)204{205GpeBlock = GpeXruptInfo->GpeBlockListHead;206while (GpeBlock)207{208NextGpeBlock = GpeBlock->Next;209ACPI_FREE (GpeBlock->EventInfo);210ACPI_FREE (GpeBlock->RegisterInfo);211ACPI_FREE (GpeBlock);212213GpeBlock = NextGpeBlock;214}215NextGpeXruptInfo = GpeXruptInfo->Next;216ACPI_FREE (GpeXruptInfo);217GpeXruptInfo = NextGpeXruptInfo;218}219}220#endif /* !ACPI_REDUCED_HARDWARE */221222223/*******************************************************************************224*225* FUNCTION: AcpiUtInitGlobals226*227* PARAMETERS: None228*229* RETURN: Status230*231* DESCRIPTION: Initialize ACPICA globals. All globals that require specific232* initialization should be initialized here. This allows for233* a warm restart.234*235******************************************************************************/236237ACPI_STATUS238AcpiUtInitGlobals (239void)240{241ACPI_STATUS Status;242UINT32 i;243244245ACPI_FUNCTION_TRACE (UtInitGlobals);246247248/* Create all memory caches */249250Status = AcpiUtCreateCaches ();251if (ACPI_FAILURE (Status))252{253return_ACPI_STATUS (Status);254}255256/* Address Range lists */257258for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++)259{260AcpiGbl_AddressRangeList[i] = NULL;261}262263/* Mutex locked flags */264265for (i = 0; i < ACPI_NUM_MUTEX; i++)266{267AcpiGbl_MutexInfo[i].Mutex = NULL;268AcpiGbl_MutexInfo[i].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;269AcpiGbl_MutexInfo[i].UseCount = 0;270}271272for (i = 0; i < ACPI_NUM_OWNERID_MASKS; i++)273{274AcpiGbl_OwnerIdMask[i] = 0;275}276277/* Last OwnerID is never valid */278279AcpiGbl_OwnerIdMask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000;280281/* Event counters */282283AcpiMethodCount = 0;284AcpiSciCount = 0;285AcpiGpeCount = 0;286287for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)288{289AcpiFixedEventCount[i] = 0;290}291292#if (!ACPI_REDUCED_HARDWARE)293294/* GPE/SCI support */295296AcpiGbl_AllGpesInitialized = FALSE;297AcpiGbl_GpeXruptListHead = NULL;298AcpiGbl_GpeFadtBlocks[0] = NULL;299AcpiGbl_GpeFadtBlocks[1] = NULL;300AcpiCurrentGpeCount = 0;301302AcpiGbl_GlobalEventHandler = NULL;303AcpiGbl_SciHandlerList = NULL;304305#endif /* !ACPI_REDUCED_HARDWARE */306307/* Global handlers */308309AcpiGbl_GlobalNotify[0].Handler = NULL;310AcpiGbl_GlobalNotify[1].Handler = NULL;311AcpiGbl_ExceptionHandler = NULL;312AcpiGbl_InitHandler = NULL;313AcpiGbl_TableHandler = NULL;314AcpiGbl_InterfaceHandler = NULL;315316/* Global Lock support */317318AcpiGbl_GlobalLockSemaphore = ACPI_SEMAPHORE_NULL;319AcpiGbl_GlobalLockMutex = NULL;320AcpiGbl_GlobalLockAcquired = FALSE;321AcpiGbl_GlobalLockHandle = 0;322AcpiGbl_GlobalLockPresent = FALSE;323324/* Miscellaneous variables */325326AcpiGbl_DSDT = NULL;327AcpiGbl_CmSingleStep = FALSE;328AcpiGbl_Shutdown = FALSE;329AcpiGbl_NsLookupCount = 0;330AcpiGbl_PsFindCount = 0;331AcpiGbl_AcpiHardwarePresent = TRUE;332AcpiGbl_LastOwnerIdIndex = 0;333AcpiGbl_NextOwnerIdOffset = 0;334AcpiGbl_DebuggerConfiguration = DEBUGGER_THREADING;335AcpiGbl_OsiMutex = NULL;336337/* Hardware oriented */338339AcpiGbl_EventsInitialized = FALSE;340AcpiGbl_SystemAwakeAndRunning = TRUE;341342/* Namespace */343344AcpiGbl_RootNode = NULL;345AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;346AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;347AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE;348AcpiGbl_RootNodeStruct.Parent = NULL;349AcpiGbl_RootNodeStruct.Child = NULL;350AcpiGbl_RootNodeStruct.Peer = NULL;351AcpiGbl_RootNodeStruct.Object = NULL;352353354#ifdef ACPI_DISASSEMBLER355AcpiGbl_ExternalList = NULL;356AcpiGbl_NumExternalMethods = 0;357AcpiGbl_ResolvedExternalMethods = 0;358#endif359360#ifdef ACPI_DEBUG_OUTPUT361AcpiGbl_LowestStackPointer = ACPI_CAST_PTR (ACPI_SIZE, ACPI_SIZE_MAX);362#endif363364#ifdef ACPI_DBG_TRACK_ALLOCATIONS365AcpiGbl_DisplayFinalMemStats = FALSE;366AcpiGbl_DisableMemTracking = FALSE;367#endif368369return_ACPI_STATUS (AE_OK);370}371372373/******************************************************************************374*375* FUNCTION: AcpiUtTerminate376*377* PARAMETERS: none378*379* RETURN: none380*381* DESCRIPTION: Free global memory382*383******************************************************************************/384385static void386AcpiUtTerminate (387void)388{389ACPI_FUNCTION_TRACE (UtTerminate);390391AcpiUtFreeGpeLists ();392AcpiUtDeleteAddressLists ();393return_VOID;394}395396397/*******************************************************************************398*399* FUNCTION: AcpiUtSubsystemShutdown400*401* PARAMETERS: None402*403* RETURN: None404*405* DESCRIPTION: Shutdown the various components. Do not delete the mutex406* objects here, because the AML debugger may be still running.407*408******************************************************************************/409410void411AcpiUtSubsystemShutdown (412void)413{414ACPI_FUNCTION_TRACE (UtSubsystemShutdown);415416417/* Just exit if subsystem is already shutdown */418419if (AcpiGbl_Shutdown)420{421ACPI_ERROR ((AE_INFO, "ACPI Subsystem is already terminated"));422return_VOID;423}424425/* Subsystem appears active, go ahead and shut it down */426427AcpiGbl_Shutdown = TRUE;428AcpiGbl_StartupFlags = 0;429ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));430431#ifndef ACPI_ASL_COMPILER432433/* Close the AcpiEvent Handling */434435AcpiEvTerminate ();436437/* Delete any dynamic _OSI interfaces */438439AcpiUtInterfaceTerminate ();440#endif441442/* Close the Namespace */443444AcpiNsTerminate ();445446/* Delete the ACPI tables */447448AcpiTbTerminate ();449450/* Close the globals */451452AcpiUtTerminate ();453454/* Purge the local caches */455456(void) AcpiUtDeleteCaches ();457return_VOID;458}459460461