Home | History | Annotate | Line # | Download | only in utilities
utxfinit.c revision 1.1.1.2.2.1
      1 /******************************************************************************
      2  *
      3  * Module Name: utxfinit - External interfaces for ACPICA initialization
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2015, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     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.
     25  *
     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.
     29  *
     30  * NO WARRANTY
     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.
     42  */
     43 
     44 #define EXPORT_ACPI_INTERFACES
     45 
     46 #include "acpi.h"
     47 #include "accommon.h"
     48 #include "acevents.h"
     49 #include "acnamesp.h"
     50 #include "acdebug.h"
     51 #include "actables.h"
     52 
     53 #define _COMPONENT          ACPI_UTILITIES
     54         ACPI_MODULE_NAME    ("utxfinit")
     55 
     56 /* For AcpiExec only */
     57 void
     58 AeDoObjectOverrides (
     59     void);
     60 
     61 
     62 /*******************************************************************************
     63  *
     64  * FUNCTION:    AcpiInitializeSubsystem
     65  *
     66  * PARAMETERS:  None
     67  *
     68  * RETURN:      Status
     69  *
     70  * DESCRIPTION: Initializes all global variables. This is the first function
     71  *              called, so any early initialization belongs here.
     72  *
     73  ******************************************************************************/
     74 
     75 ACPI_STATUS
     76 AcpiInitializeSubsystem (
     77     void)
     78 {
     79     ACPI_STATUS             Status;
     80 
     81 
     82     ACPI_FUNCTION_TRACE (AcpiInitializeSubsystem);
     83 
     84 
     85     AcpiGbl_StartupFlags = ACPI_SUBSYSTEM_INITIALIZE;
     86     ACPI_DEBUG_EXEC (AcpiUtInitStackPtrTrace ());
     87 
     88     /* Initialize the OS-Dependent layer */
     89 
     90     Status = AcpiOsInitialize ();
     91     if (ACPI_FAILURE (Status))
     92     {
     93         ACPI_EXCEPTION ((AE_INFO, Status, "During OSL initialization"));
     94         return_ACPI_STATUS (Status);
     95     }
     96 
     97     /* Initialize all globals used by the subsystem */
     98 
     99     Status = AcpiUtInitGlobals ();
    100     if (ACPI_FAILURE (Status))
    101     {
    102         ACPI_EXCEPTION ((AE_INFO, Status, "During initialization of globals"));
    103         return_ACPI_STATUS (Status);
    104     }
    105 
    106     /* Create the default mutex objects */
    107 
    108     Status = AcpiUtMutexInitialize ();
    109     if (ACPI_FAILURE (Status))
    110     {
    111         ACPI_EXCEPTION ((AE_INFO, Status, "During Global Mutex creation"));
    112         return_ACPI_STATUS (Status);
    113     }
    114 
    115     /*
    116      * Initialize the namespace manager and
    117      * the root of the namespace tree
    118      */
    119     Status = AcpiNsRootInitialize ();
    120     if (ACPI_FAILURE (Status))
    121     {
    122         ACPI_EXCEPTION ((AE_INFO, Status, "During Namespace initialization"));
    123         return_ACPI_STATUS (Status);
    124     }
    125 
    126     /* Initialize the global OSI interfaces list with the static names */
    127 
    128     Status = AcpiUtInitializeInterfaces ();
    129     if (ACPI_FAILURE (Status))
    130     {
    131         ACPI_EXCEPTION ((AE_INFO, Status, "During OSI interfaces initialization"));
    132         return_ACPI_STATUS (Status);
    133     }
    134 
    135     /* If configured, initialize the AML debugger */
    136 
    137 #ifdef ACPI_DEBUGGER
    138     Status = AcpiDbInitialize ();
    139     if (ACPI_FAILURE (Status))
    140     {
    141         ACPI_EXCEPTION ((AE_INFO, Status, "During Debugger initialization"));
    142         return_ACPI_STATUS (Status);
    143     }
    144 #endif
    145 
    146     return_ACPI_STATUS (AE_OK);
    147 }
    148 
    149 ACPI_EXPORT_SYMBOL_INIT (AcpiInitializeSubsystem)
    150 
    151 
    152 /*******************************************************************************
    153  *
    154  * FUNCTION:    AcpiEnableSubsystem
    155  *
    156  * PARAMETERS:  Flags               - Init/enable Options
    157  *
    158  * RETURN:      Status
    159  *
    160  * DESCRIPTION: Completes the subsystem initialization including hardware.
    161  *              Puts system into ACPI mode if it isn't already.
    162  *
    163  ******************************************************************************/
    164 
    165 ACPI_STATUS
    166 AcpiEnableSubsystem (
    167     UINT32                  Flags)
    168 {
    169     ACPI_STATUS             Status = AE_OK;
    170 
    171 
    172     ACPI_FUNCTION_TRACE (AcpiEnableSubsystem);
    173 
    174 
    175 #if (!ACPI_REDUCED_HARDWARE)
    176 
    177     /* Enable ACPI mode */
    178 
    179     if (!(Flags & ACPI_NO_ACPI_ENABLE))
    180     {
    181         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Going into ACPI mode\n"));
    182 
    183         AcpiGbl_OriginalMode = AcpiHwGetMode();
    184 
    185         Status = AcpiEnable ();
    186         if (ACPI_FAILURE (Status))
    187         {
    188             ACPI_WARNING ((AE_INFO, "AcpiEnable failed"));
    189             return_ACPI_STATUS (Status);
    190         }
    191     }
    192 
    193     /*
    194      * Obtain a permanent mapping for the FACS. This is required for the
    195      * Global Lock and the Firmware Waking Vector
    196      */
    197     Status = AcpiTbInitializeFacs ();
    198     if (ACPI_FAILURE (Status))
    199     {
    200         ACPI_WARNING ((AE_INFO, "Could not map the FACS table"));
    201         return_ACPI_STATUS (Status);
    202     }
    203 
    204 #endif /* !ACPI_REDUCED_HARDWARE */
    205 
    206     /*
    207      * Install the default OpRegion handlers. These are installed unless
    208      * other handlers have already been installed via the
    209      * InstallAddressSpaceHandler interface.
    210      */
    211     if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
    212     {
    213         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    214             "[Init] Installing default address space handlers\n"));
    215 
    216         Status = AcpiEvInstallRegionHandlers ();
    217         if (ACPI_FAILURE (Status))
    218         {
    219             return_ACPI_STATUS (Status);
    220         }
    221     }
    222 
    223 #if (!ACPI_REDUCED_HARDWARE)
    224     /*
    225      * Initialize ACPI Event handling (Fixed and General Purpose)
    226      *
    227      * Note1: We must have the hardware and events initialized before we can
    228      * execute any control methods safely. Any control method can require
    229      * ACPI hardware support, so the hardware must be fully initialized before
    230      * any method execution!
    231      *
    232      * Note2: Fixed events are initialized and enabled here. GPEs are
    233      * initialized, but cannot be enabled until after the hardware is
    234      * completely initialized (SCI and GlobalLock activated) and the various
    235      * initialization control methods are run (_REG, _STA, _INI) on the
    236      * entire namespace.
    237      */
    238     if (!(Flags & ACPI_NO_EVENT_INIT))
    239     {
    240         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    241             "[Init] Initializing ACPI events\n"));
    242 
    243         Status = AcpiEvInitializeEvents ();
    244         if (ACPI_FAILURE (Status))
    245         {
    246             return_ACPI_STATUS (Status);
    247         }
    248     }
    249 
    250     /*
    251      * Install the SCI handler and Global Lock handler. This completes the
    252      * hardware initialization.
    253      */
    254     if (!(Flags & ACPI_NO_HANDLER_INIT))
    255     {
    256         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    257             "[Init] Installing SCI/GL handlers\n"));
    258 
    259         Status = AcpiEvInstallXruptHandlers ();
    260         if (ACPI_FAILURE (Status))
    261         {
    262             return_ACPI_STATUS (Status);
    263         }
    264     }
    265 
    266 #endif /* !ACPI_REDUCED_HARDWARE */
    267 
    268     return_ACPI_STATUS (Status);
    269 }
    270 
    271 ACPI_EXPORT_SYMBOL_INIT (AcpiEnableSubsystem)
    272 
    273 
    274 /*******************************************************************************
    275  *
    276  * FUNCTION:    AcpiInitializeObjects
    277  *
    278  * PARAMETERS:  Flags               - Init/enable Options
    279  *
    280  * RETURN:      Status
    281  *
    282  * DESCRIPTION: Completes namespace initialization by initializing device
    283  *              objects and executing AML code for Regions, buffers, etc.
    284  *
    285  ******************************************************************************/
    286 
    287 ACPI_STATUS
    288 AcpiInitializeObjects (
    289     UINT32                  Flags)
    290 {
    291     ACPI_STATUS             Status = AE_OK;
    292 
    293 
    294     ACPI_FUNCTION_TRACE (AcpiInitializeObjects);
    295 
    296 
    297     /*
    298      * Run all _REG methods
    299      *
    300      * Note: Any objects accessed by the _REG methods will be automatically
    301      * initialized, even if they contain executable AML (see the call to
    302      * AcpiNsInitializeObjects below).
    303      */
    304     if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
    305     {
    306         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    307             "[Init] Executing _REG OpRegion methods\n"));
    308 
    309         Status = AcpiEvInitializeOpRegions ();
    310         if (ACPI_FAILURE (Status))
    311         {
    312             return_ACPI_STATUS (Status);
    313         }
    314     }
    315 
    316 #ifdef ACPI_EXEC_APP
    317     /*
    318      * This call implements the "initialization file" option for AcpiExec.
    319      * This is the precise point that we want to perform the overrides.
    320      */
    321     AeDoObjectOverrides ();
    322 #endif
    323 
    324     /*
    325      * Execute any module-level code that was detected during the table load
    326      * phase. Although illegal since ACPI 2.0, there are many machines that
    327      * contain this type of code. Each block of detected executable AML code
    328      * outside of any control method is wrapped with a temporary control
    329      * method object and placed on a global list. The methods on this list
    330      * are executed below.
    331      */
    332     AcpiNsExecModuleCodeList ();
    333 
    334     /*
    335      * Initialize the objects that remain uninitialized. This runs the
    336      * executable AML that may be part of the declaration of these objects:
    337      * OperationRegions, BufferFields, Buffers, and Packages.
    338      */
    339     if (!(Flags & ACPI_NO_OBJECT_INIT))
    340     {
    341         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    342             "[Init] Completing Initialization of ACPI Objects\n"));
    343 
    344         Status = AcpiNsInitializeObjects ();
    345         if (ACPI_FAILURE (Status))
    346         {
    347             return_ACPI_STATUS (Status);
    348         }
    349     }
    350 
    351     /*
    352      * Initialize all device objects in the namespace. This runs the device
    353      * _STA and _INI methods.
    354      */
    355     if (!(Flags & ACPI_NO_DEVICE_INIT))
    356     {
    357         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    358             "[Init] Initializing ACPI Devices\n"));
    359 
    360         Status = AcpiNsInitializeDevices ();
    361         if (ACPI_FAILURE (Status))
    362         {
    363             return_ACPI_STATUS (Status);
    364         }
    365     }
    366 
    367     /*
    368      * Empty the caches (delete the cached objects) on the assumption that
    369      * the table load filled them up more than they will be at runtime --
    370      * thus wasting non-paged memory.
    371      */
    372     Status = AcpiPurgeCachedObjects ();
    373 
    374     AcpiGbl_StartupFlags |= ACPI_INITIALIZED_OK;
    375     return_ACPI_STATUS (Status);
    376 }
    377 
    378 ACPI_EXPORT_SYMBOL_INIT (AcpiInitializeObjects)
    379