Home | History | Annotate | Line # | Download | only in utilities
utinit.c revision 1.1.1.18
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: utinit - Common ACPI subsystem initialization
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7   1.1.1.2    jruoho /*
      8  1.1.1.17  christos  * Copyright (C) 2000 - 2023, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13   1.1.1.2    jruoho  * are met:
     14   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16   1.1.1.2    jruoho  *    without modification.
     17   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21   1.1.1.2    jruoho  *    binary redistribution.
     22   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24   1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25   1.1.1.2    jruoho  *
     26   1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27   1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.1.1.2    jruoho  * Software Foundation.
     29   1.1.1.2    jruoho  *
     30   1.1.1.2    jruoho  * NO WARRANTY
     31   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.15  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42   1.1.1.2    jruoho  */
     43       1.1    jruoho 
     44       1.1    jruoho #include "acpi.h"
     45       1.1    jruoho #include "accommon.h"
     46       1.1    jruoho #include "acnamesp.h"
     47       1.1    jruoho #include "acevents.h"
     48       1.1    jruoho #include "actables.h"
     49       1.1    jruoho 
     50       1.1    jruoho #define _COMPONENT          ACPI_UTILITIES
     51       1.1    jruoho         ACPI_MODULE_NAME    ("utinit")
     52       1.1    jruoho 
     53       1.1    jruoho /* Local prototypes */
     54       1.1    jruoho 
     55       1.1    jruoho static void AcpiUtTerminate (
     56       1.1    jruoho     void);
     57       1.1    jruoho 
     58   1.1.1.3  christos #if (!ACPI_REDUCED_HARDWARE)
     59       1.1    jruoho 
     60   1.1.1.3  christos static void
     61   1.1.1.3  christos AcpiUtFreeGpeLists (
     62   1.1.1.3  christos     void);
     63   1.1.1.3  christos 
     64   1.1.1.3  christos #else
     65   1.1.1.3  christos 
     66   1.1.1.3  christos #define AcpiUtFreeGpeLists()
     67   1.1.1.3  christos #endif /* !ACPI_REDUCED_HARDWARE */
     68   1.1.1.3  christos 
     69   1.1.1.3  christos 
     70   1.1.1.3  christos #if (!ACPI_REDUCED_HARDWARE)
     71       1.1    jruoho /******************************************************************************
     72       1.1    jruoho  *
     73   1.1.1.3  christos  * FUNCTION:    AcpiUtFreeGpeLists
     74       1.1    jruoho  *
     75       1.1    jruoho  * PARAMETERS:  none
     76       1.1    jruoho  *
     77       1.1    jruoho  * RETURN:      none
     78       1.1    jruoho  *
     79   1.1.1.3  christos  * DESCRIPTION: Free global GPE lists
     80       1.1    jruoho  *
     81       1.1    jruoho  ******************************************************************************/
     82       1.1    jruoho 
     83       1.1    jruoho static void
     84   1.1.1.3  christos AcpiUtFreeGpeLists (
     85       1.1    jruoho     void)
     86       1.1    jruoho {
     87       1.1    jruoho     ACPI_GPE_BLOCK_INFO     *GpeBlock;
     88       1.1    jruoho     ACPI_GPE_BLOCK_INFO     *NextGpeBlock;
     89       1.1    jruoho     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo;
     90       1.1    jruoho     ACPI_GPE_XRUPT_INFO     *NextGpeXruptInfo;
     91       1.1    jruoho 
     92       1.1    jruoho 
     93       1.1    jruoho     /* Free global GPE blocks and related info structures */
     94       1.1    jruoho 
     95       1.1    jruoho     GpeXruptInfo = AcpiGbl_GpeXruptListHead;
     96       1.1    jruoho     while (GpeXruptInfo)
     97       1.1    jruoho     {
     98       1.1    jruoho         GpeBlock = GpeXruptInfo->GpeBlockListHead;
     99       1.1    jruoho         while (GpeBlock)
    100       1.1    jruoho         {
    101       1.1    jruoho             NextGpeBlock = GpeBlock->Next;
    102       1.1    jruoho             ACPI_FREE (GpeBlock->EventInfo);
    103       1.1    jruoho             ACPI_FREE (GpeBlock->RegisterInfo);
    104       1.1    jruoho             ACPI_FREE (GpeBlock);
    105       1.1    jruoho 
    106       1.1    jruoho             GpeBlock = NextGpeBlock;
    107       1.1    jruoho         }
    108       1.1    jruoho         NextGpeXruptInfo = GpeXruptInfo->Next;
    109       1.1    jruoho         ACPI_FREE (GpeXruptInfo);
    110       1.1    jruoho         GpeXruptInfo = NextGpeXruptInfo;
    111       1.1    jruoho     }
    112   1.1.1.3  christos }
    113   1.1.1.3  christos #endif /* !ACPI_REDUCED_HARDWARE */
    114   1.1.1.3  christos 
    115   1.1.1.3  christos 
    116   1.1.1.4  christos /*******************************************************************************
    117   1.1.1.4  christos  *
    118   1.1.1.4  christos  * FUNCTION:    AcpiUtInitGlobals
    119   1.1.1.4  christos  *
    120   1.1.1.4  christos  * PARAMETERS:  None
    121   1.1.1.4  christos  *
    122   1.1.1.4  christos  * RETURN:      Status
    123   1.1.1.4  christos  *
    124   1.1.1.4  christos  * DESCRIPTION: Initialize ACPICA globals. All globals that require specific
    125   1.1.1.4  christos  *              initialization should be initialized here. This allows for
    126   1.1.1.4  christos  *              a warm restart.
    127   1.1.1.4  christos  *
    128   1.1.1.4  christos  ******************************************************************************/
    129   1.1.1.4  christos 
    130   1.1.1.4  christos ACPI_STATUS
    131   1.1.1.4  christos AcpiUtInitGlobals (
    132   1.1.1.4  christos     void)
    133   1.1.1.4  christos {
    134   1.1.1.4  christos     ACPI_STATUS             Status;
    135   1.1.1.4  christos     UINT32                  i;
    136   1.1.1.4  christos 
    137   1.1.1.4  christos 
    138   1.1.1.4  christos     ACPI_FUNCTION_TRACE (UtInitGlobals);
    139   1.1.1.4  christos 
    140   1.1.1.4  christos 
    141   1.1.1.4  christos     /* Create all memory caches */
    142   1.1.1.4  christos 
    143   1.1.1.4  christos     Status = AcpiUtCreateCaches ();
    144   1.1.1.4  christos     if (ACPI_FAILURE (Status))
    145   1.1.1.4  christos     {
    146   1.1.1.4  christos         return_ACPI_STATUS (Status);
    147   1.1.1.4  christos     }
    148   1.1.1.4  christos 
    149   1.1.1.4  christos     /* Address Range lists */
    150   1.1.1.4  christos 
    151   1.1.1.4  christos     for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++)
    152   1.1.1.4  christos     {
    153   1.1.1.4  christos         AcpiGbl_AddressRangeList[i] = NULL;
    154   1.1.1.4  christos     }
    155   1.1.1.4  christos 
    156   1.1.1.4  christos     /* Mutex locked flags */
    157   1.1.1.4  christos 
    158   1.1.1.4  christos     for (i = 0; i < ACPI_NUM_MUTEX; i++)
    159   1.1.1.4  christos     {
    160   1.1.1.4  christos         AcpiGbl_MutexInfo[i].Mutex          = NULL;
    161   1.1.1.4  christos         AcpiGbl_MutexInfo[i].ThreadId       = ACPI_MUTEX_NOT_ACQUIRED;
    162   1.1.1.4  christos         AcpiGbl_MutexInfo[i].UseCount       = 0;
    163   1.1.1.4  christos     }
    164   1.1.1.4  christos 
    165   1.1.1.4  christos     for (i = 0; i < ACPI_NUM_OWNERID_MASKS; i++)
    166   1.1.1.4  christos     {
    167   1.1.1.4  christos         AcpiGbl_OwnerIdMask[i]              = 0;
    168   1.1.1.4  christos     }
    169   1.1.1.4  christos 
    170   1.1.1.4  christos     /* Last OwnerID is never valid */
    171   1.1.1.4  christos 
    172   1.1.1.4  christos     AcpiGbl_OwnerIdMask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000;
    173   1.1.1.4  christos 
    174   1.1.1.4  christos     /* Event counters */
    175   1.1.1.4  christos 
    176   1.1.1.4  christos     AcpiMethodCount                     = 0;
    177   1.1.1.4  christos     AcpiSciCount                        = 0;
    178   1.1.1.4  christos     AcpiGpeCount                        = 0;
    179   1.1.1.4  christos 
    180   1.1.1.4  christos     for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
    181   1.1.1.4  christos     {
    182   1.1.1.4  christos         AcpiFixedEventCount[i]              = 0;
    183   1.1.1.4  christos     }
    184   1.1.1.4  christos 
    185   1.1.1.4  christos #if (!ACPI_REDUCED_HARDWARE)
    186   1.1.1.4  christos 
    187   1.1.1.4  christos     /* GPE/SCI support */
    188   1.1.1.4  christos 
    189   1.1.1.4  christos     AcpiGbl_AllGpesInitialized          = FALSE;
    190   1.1.1.4  christos     AcpiGbl_GpeXruptListHead            = NULL;
    191   1.1.1.4  christos     AcpiGbl_GpeFadtBlocks[0]            = NULL;
    192   1.1.1.4  christos     AcpiGbl_GpeFadtBlocks[1]            = NULL;
    193   1.1.1.4  christos     AcpiCurrentGpeCount                 = 0;
    194   1.1.1.4  christos 
    195   1.1.1.4  christos     AcpiGbl_GlobalEventHandler          = NULL;
    196   1.1.1.4  christos     AcpiGbl_SciHandlerList              = NULL;
    197   1.1.1.4  christos 
    198   1.1.1.4  christos #endif /* !ACPI_REDUCED_HARDWARE */
    199   1.1.1.4  christos 
    200   1.1.1.4  christos     /* Global handlers */
    201   1.1.1.4  christos 
    202   1.1.1.4  christos     AcpiGbl_GlobalNotify[0].Handler     = NULL;
    203   1.1.1.4  christos     AcpiGbl_GlobalNotify[1].Handler     = NULL;
    204   1.1.1.4  christos     AcpiGbl_ExceptionHandler            = NULL;
    205   1.1.1.4  christos     AcpiGbl_InitHandler                 = NULL;
    206   1.1.1.4  christos     AcpiGbl_TableHandler                = NULL;
    207   1.1.1.4  christos     AcpiGbl_InterfaceHandler            = NULL;
    208   1.1.1.4  christos 
    209   1.1.1.4  christos     /* Global Lock support */
    210   1.1.1.4  christos 
    211  1.1.1.18  christos     AcpiGbl_GlobalLockSemaphore         = ACPI_SEMAPHORE_NULL;
    212   1.1.1.4  christos     AcpiGbl_GlobalLockMutex             = NULL;
    213   1.1.1.4  christos     AcpiGbl_GlobalLockAcquired          = FALSE;
    214   1.1.1.4  christos     AcpiGbl_GlobalLockHandle            = 0;
    215   1.1.1.4  christos     AcpiGbl_GlobalLockPresent           = FALSE;
    216   1.1.1.4  christos 
    217   1.1.1.4  christos     /* Miscellaneous variables */
    218   1.1.1.4  christos 
    219   1.1.1.4  christos     AcpiGbl_DSDT                        = NULL;
    220   1.1.1.4  christos     AcpiGbl_CmSingleStep                = FALSE;
    221   1.1.1.4  christos     AcpiGbl_Shutdown                    = FALSE;
    222   1.1.1.4  christos     AcpiGbl_NsLookupCount               = 0;
    223   1.1.1.4  christos     AcpiGbl_PsFindCount                 = 0;
    224   1.1.1.4  christos     AcpiGbl_AcpiHardwarePresent         = TRUE;
    225   1.1.1.4  christos     AcpiGbl_LastOwnerIdIndex            = 0;
    226   1.1.1.4  christos     AcpiGbl_NextOwnerIdOffset           = 0;
    227   1.1.1.4  christos     AcpiGbl_DebuggerConfiguration       = DEBUGGER_THREADING;
    228   1.1.1.4  christos     AcpiGbl_OsiMutex                    = NULL;
    229   1.1.1.4  christos 
    230   1.1.1.4  christos     /* Hardware oriented */
    231   1.1.1.4  christos 
    232   1.1.1.4  christos     AcpiGbl_EventsInitialized           = FALSE;
    233   1.1.1.4  christos     AcpiGbl_SystemAwakeAndRunning       = TRUE;
    234   1.1.1.4  christos 
    235   1.1.1.4  christos     /* Namespace */
    236   1.1.1.4  christos 
    237   1.1.1.4  christos     AcpiGbl_RootNode                    = NULL;
    238   1.1.1.4  christos     AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
    239   1.1.1.4  christos     AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
    240   1.1.1.4  christos     AcpiGbl_RootNodeStruct.Type         = ACPI_TYPE_DEVICE;
    241   1.1.1.4  christos     AcpiGbl_RootNodeStruct.Parent       = NULL;
    242   1.1.1.4  christos     AcpiGbl_RootNodeStruct.Child        = NULL;
    243   1.1.1.4  christos     AcpiGbl_RootNodeStruct.Peer         = NULL;
    244   1.1.1.4  christos     AcpiGbl_RootNodeStruct.Object       = NULL;
    245   1.1.1.4  christos 
    246   1.1.1.4  christos 
    247   1.1.1.4  christos #ifdef ACPI_DISASSEMBLER
    248   1.1.1.4  christos     AcpiGbl_ExternalList                = NULL;
    249   1.1.1.4  christos     AcpiGbl_NumExternalMethods          = 0;
    250   1.1.1.4  christos     AcpiGbl_ResolvedExternalMethods     = 0;
    251   1.1.1.4  christos #endif
    252   1.1.1.4  christos 
    253   1.1.1.4  christos #ifdef ACPI_DEBUG_OUTPUT
    254   1.1.1.4  christos     AcpiGbl_LowestStackPointer          = ACPI_CAST_PTR (ACPI_SIZE, ACPI_SIZE_MAX);
    255   1.1.1.4  christos #endif
    256   1.1.1.4  christos 
    257   1.1.1.4  christos #ifdef ACPI_DBG_TRACK_ALLOCATIONS
    258   1.1.1.4  christos     AcpiGbl_DisplayFinalMemStats        = FALSE;
    259   1.1.1.4  christos     AcpiGbl_DisableMemTracking          = FALSE;
    260   1.1.1.4  christos #endif
    261   1.1.1.4  christos 
    262   1.1.1.4  christos     return_ACPI_STATUS (AE_OK);
    263   1.1.1.4  christos }
    264   1.1.1.4  christos 
    265   1.1.1.4  christos 
    266   1.1.1.3  christos /******************************************************************************
    267   1.1.1.3  christos  *
    268   1.1.1.3  christos  * FUNCTION:    AcpiUtTerminate
    269   1.1.1.3  christos  *
    270   1.1.1.3  christos  * PARAMETERS:  none
    271   1.1.1.3  christos  *
    272   1.1.1.3  christos  * RETURN:      none
    273   1.1.1.3  christos  *
    274   1.1.1.3  christos  * DESCRIPTION: Free global memory
    275   1.1.1.3  christos  *
    276   1.1.1.3  christos  ******************************************************************************/
    277       1.1    jruoho 
    278   1.1.1.3  christos static void
    279   1.1.1.3  christos AcpiUtTerminate (
    280   1.1.1.3  christos     void)
    281   1.1.1.3  christos {
    282   1.1.1.3  christos     ACPI_FUNCTION_TRACE (UtTerminate);
    283   1.1.1.3  christos 
    284   1.1.1.3  christos     AcpiUtFreeGpeLists ();
    285   1.1.1.3  christos     AcpiUtDeleteAddressLists ();
    286       1.1    jruoho     return_VOID;
    287       1.1    jruoho }
    288       1.1    jruoho 
    289       1.1    jruoho 
    290       1.1    jruoho /*******************************************************************************
    291       1.1    jruoho  *
    292       1.1    jruoho  * FUNCTION:    AcpiUtSubsystemShutdown
    293       1.1    jruoho  *
    294       1.1    jruoho  * PARAMETERS:  None
    295       1.1    jruoho  *
    296       1.1    jruoho  * RETURN:      None
    297       1.1    jruoho  *
    298       1.1    jruoho  * DESCRIPTION: Shutdown the various components. Do not delete the mutex
    299       1.1    jruoho  *              objects here, because the AML debugger may be still running.
    300       1.1    jruoho  *
    301       1.1    jruoho  ******************************************************************************/
    302       1.1    jruoho 
    303       1.1    jruoho void
    304       1.1    jruoho AcpiUtSubsystemShutdown (
    305       1.1    jruoho     void)
    306       1.1    jruoho {
    307       1.1    jruoho     ACPI_FUNCTION_TRACE (UtSubsystemShutdown);
    308       1.1    jruoho 
    309       1.1    jruoho 
    310   1.1.1.7  christos     /* Just exit if subsystem is already shutdown */
    311   1.1.1.7  christos 
    312   1.1.1.7  christos     if (AcpiGbl_Shutdown)
    313   1.1.1.7  christos     {
    314   1.1.1.7  christos         ACPI_ERROR ((AE_INFO, "ACPI Subsystem is already terminated"));
    315   1.1.1.7  christos         return_VOID;
    316   1.1.1.7  christos     }
    317   1.1.1.7  christos 
    318   1.1.1.7  christos     /* Subsystem appears active, go ahead and shut it down */
    319   1.1.1.7  christos 
    320   1.1.1.7  christos     AcpiGbl_Shutdown = TRUE;
    321   1.1.1.7  christos     AcpiGbl_StartupFlags = 0;
    322   1.1.1.7  christos     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
    323   1.1.1.7  christos 
    324       1.1    jruoho #ifndef ACPI_ASL_COMPILER
    325       1.1    jruoho 
    326       1.1    jruoho     /* Close the AcpiEvent Handling */
    327       1.1    jruoho 
    328       1.1    jruoho     AcpiEvTerminate ();
    329   1.1.1.2    jruoho 
    330   1.1.1.2    jruoho     /* Delete any dynamic _OSI interfaces */
    331   1.1.1.2    jruoho 
    332   1.1.1.2    jruoho     AcpiUtInterfaceTerminate ();
    333       1.1    jruoho #endif
    334       1.1    jruoho 
    335       1.1    jruoho     /* Close the Namespace */
    336       1.1    jruoho 
    337       1.1    jruoho     AcpiNsTerminate ();
    338       1.1    jruoho 
    339       1.1    jruoho     /* Delete the ACPI tables */
    340       1.1    jruoho 
    341       1.1    jruoho     AcpiTbTerminate ();
    342       1.1    jruoho 
    343       1.1    jruoho     /* Close the globals */
    344       1.1    jruoho 
    345       1.1    jruoho     AcpiUtTerminate ();
    346       1.1    jruoho 
    347       1.1    jruoho     /* Purge the local caches */
    348       1.1    jruoho 
    349       1.1    jruoho     (void) AcpiUtDeleteCaches ();
    350       1.1    jruoho     return_VOID;
    351       1.1    jruoho }
    352