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