linux/drivers/acpi/acpica/utxfinit.c
<<
>>
Prefs
   1/******************************************************************************
   2 *
   3 * Module Name: utxfinit - External interfaces for ACPICA initialization
   4 *
   5 *****************************************************************************/
   6
   7/*
   8 * Copyright (C) 2000 - 2013, 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#include <linux/export.h>
  45#include <acpi/acpi.h>
  46#include "accommon.h"
  47#include "acevents.h"
  48#include "acnamesp.h"
  49#include "acdebug.h"
  50#include "actables.h"
  51
  52#define _COMPONENT          ACPI_UTILITIES
  53ACPI_MODULE_NAME("utxfinit")
  54
  55/*******************************************************************************
  56 *
  57 * FUNCTION:    acpi_initialize_subsystem
  58 *
  59 * PARAMETERS:  None
  60 *
  61 * RETURN:      Status
  62 *
  63 * DESCRIPTION: Initializes all global variables. This is the first function
  64 *              called, so any early initialization belongs here.
  65 *
  66 ******************************************************************************/
  67acpi_status acpi_initialize_subsystem(void)
  68{
  69        acpi_status status;
  70
  71        ACPI_FUNCTION_TRACE(acpi_initialize_subsystem);
  72
  73        acpi_gbl_startup_flags = ACPI_SUBSYSTEM_INITIALIZE;
  74        ACPI_DEBUG_EXEC(acpi_ut_init_stack_ptr_trace());
  75
  76        /* Initialize the OS-Dependent layer */
  77
  78        status = acpi_os_initialize();
  79        if (ACPI_FAILURE(status)) {
  80                ACPI_EXCEPTION((AE_INFO, status, "During OSL initialization"));
  81                return_ACPI_STATUS(status);
  82        }
  83
  84        /* Initialize all globals used by the subsystem */
  85
  86        status = acpi_ut_init_globals();
  87        if (ACPI_FAILURE(status)) {
  88                ACPI_EXCEPTION((AE_INFO, status,
  89                                "During initialization of globals"));
  90                return_ACPI_STATUS(status);
  91        }
  92
  93        /* Create the default mutex objects */
  94
  95        status = acpi_ut_mutex_initialize();
  96        if (ACPI_FAILURE(status)) {
  97                ACPI_EXCEPTION((AE_INFO, status,
  98                                "During Global Mutex creation"));
  99                return_ACPI_STATUS(status);
 100        }
 101
 102        /*
 103         * Initialize the namespace manager and
 104         * the root of the namespace tree
 105         */
 106        status = acpi_ns_root_initialize();
 107        if (ACPI_FAILURE(status)) {
 108                ACPI_EXCEPTION((AE_INFO, status,
 109                                "During Namespace initialization"));
 110                return_ACPI_STATUS(status);
 111        }
 112
 113        /* Initialize the global OSI interfaces list with the static names */
 114
 115        status = acpi_ut_initialize_interfaces();
 116        if (ACPI_FAILURE(status)) {
 117                ACPI_EXCEPTION((AE_INFO, status,
 118                                "During OSI interfaces initialization"));
 119                return_ACPI_STATUS(status);
 120        }
 121
 122        /* If configured, initialize the AML debugger */
 123
 124        ACPI_DEBUGGER_EXEC(status = acpi_db_initialize());
 125        return_ACPI_STATUS(status);
 126}
 127ACPI_EXPORT_SYMBOL(acpi_initialize_subsystem)
 128
 129/*******************************************************************************
 130 *
 131 * FUNCTION:    acpi_enable_subsystem
 132 *
 133 * PARAMETERS:  flags               - Init/enable Options
 134 *
 135 * RETURN:      Status
 136 *
 137 * DESCRIPTION: Completes the subsystem initialization including hardware.
 138 *              Puts system into ACPI mode if it isn't already.
 139 *
 140 ******************************************************************************/
 141acpi_status acpi_enable_subsystem(u32 flags)
 142{
 143        acpi_status status = AE_OK;
 144
 145        ACPI_FUNCTION_TRACE(acpi_enable_subsystem);
 146
 147#if (!ACPI_REDUCED_HARDWARE)
 148
 149        /* Enable ACPI mode */
 150
 151        if (!(flags & ACPI_NO_ACPI_ENABLE)) {
 152                ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
 153                                  "[Init] Going into ACPI mode\n"));
 154
 155                acpi_gbl_original_mode = acpi_hw_get_mode();
 156
 157                status = acpi_enable();
 158                if (ACPI_FAILURE(status)) {
 159                        ACPI_WARNING((AE_INFO, "AcpiEnable failed"));
 160                        return_ACPI_STATUS(status);
 161                }
 162        }
 163
 164        /*
 165         * Obtain a permanent mapping for the FACS. This is required for the
 166         * Global Lock and the Firmware Waking Vector
 167         */
 168        status = acpi_tb_initialize_facs();
 169        if (ACPI_FAILURE(status)) {
 170                ACPI_WARNING((AE_INFO, "Could not map the FACS table"));
 171                return_ACPI_STATUS(status);
 172        }
 173#endif                          /* !ACPI_REDUCED_HARDWARE */
 174
 175        /*
 176         * Install the default op_region handlers. These are installed unless
 177         * other handlers have already been installed via the
 178         * install_address_space_handler interface.
 179         */
 180        if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
 181                ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
 182                                  "[Init] Installing default address space handlers\n"));
 183
 184                status = acpi_ev_install_region_handlers();
 185                if (ACPI_FAILURE(status)) {
 186                        return_ACPI_STATUS(status);
 187                }
 188        }
 189#if (!ACPI_REDUCED_HARDWARE)
 190        /*
 191         * Initialize ACPI Event handling (Fixed and General Purpose)
 192         *
 193         * Note1: We must have the hardware and events initialized before we can
 194         * execute any control methods safely. Any control method can require
 195         * ACPI hardware support, so the hardware must be fully initialized before
 196         * any method execution!
 197         *
 198         * Note2: Fixed events are initialized and enabled here. GPEs are
 199         * initialized, but cannot be enabled until after the hardware is
 200         * completely initialized (SCI and global_lock activated) and the various
 201         * initialization control methods are run (_REG, _STA, _INI) on the
 202         * entire namespace.
 203         */
 204        if (!(flags & ACPI_NO_EVENT_INIT)) {
 205                ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
 206                                  "[Init] Initializing ACPI events\n"));
 207
 208                status = acpi_ev_initialize_events();
 209                if (ACPI_FAILURE(status)) {
 210                        return_ACPI_STATUS(status);
 211                }
 212        }
 213
 214        /*
 215         * Install the SCI handler and Global Lock handler. This completes the
 216         * hardware initialization.
 217         */
 218        if (!(flags & ACPI_NO_HANDLER_INIT)) {
 219                ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
 220                                  "[Init] Installing SCI/GL handlers\n"));
 221
 222                status = acpi_ev_install_xrupt_handlers();
 223                if (ACPI_FAILURE(status)) {
 224                        return_ACPI_STATUS(status);
 225                }
 226        }
 227#endif                          /* !ACPI_REDUCED_HARDWARE */
 228
 229        return_ACPI_STATUS(status);
 230}
 231ACPI_EXPORT_SYMBOL(acpi_enable_subsystem)
 232
 233/*******************************************************************************
 234 *
 235 * FUNCTION:    acpi_initialize_objects
 236 *
 237 * PARAMETERS:  flags               - Init/enable Options
 238 *
 239 * RETURN:      Status
 240 *
 241 * DESCRIPTION: Completes namespace initialization by initializing device
 242 *              objects and executing AML code for Regions, buffers, etc.
 243 *
 244 ******************************************************************************/
 245acpi_status acpi_initialize_objects(u32 flags)
 246{
 247        acpi_status status = AE_OK;
 248
 249        ACPI_FUNCTION_TRACE(acpi_initialize_objects);
 250
 251        /*
 252         * Run all _REG methods
 253         *
 254         * Note: Any objects accessed by the _REG methods will be automatically
 255         * initialized, even if they contain executable AML (see the call to
 256         * acpi_ns_initialize_objects below).
 257         */
 258        if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
 259                ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
 260                                  "[Init] Executing _REG OpRegion methods\n"));
 261
 262                status = acpi_ev_initialize_op_regions();
 263                if (ACPI_FAILURE(status)) {
 264                        return_ACPI_STATUS(status);
 265                }
 266        }
 267
 268        /*
 269         * Execute any module-level code that was detected during the table load
 270         * phase. Although illegal since ACPI 2.0, there are many machines that
 271         * contain this type of code. Each block of detected executable AML code
 272         * outside of any control method is wrapped with a temporary control
 273         * method object and placed on a global list. The methods on this list
 274         * are executed below.
 275         */
 276        acpi_ns_exec_module_code_list();
 277
 278        /*
 279         * Initialize the objects that remain uninitialized. This runs the
 280         * executable AML that may be part of the declaration of these objects:
 281         * operation_regions, buffer_fields, Buffers, and Packages.
 282         */
 283        if (!(flags & ACPI_NO_OBJECT_INIT)) {
 284                ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
 285                                  "[Init] Completing Initialization of ACPI Objects\n"));
 286
 287                status = acpi_ns_initialize_objects();
 288                if (ACPI_FAILURE(status)) {
 289                        return_ACPI_STATUS(status);
 290                }
 291        }
 292
 293        /*
 294         * Initialize all device objects in the namespace. This runs the device
 295         * _STA and _INI methods.
 296         */
 297        if (!(flags & ACPI_NO_DEVICE_INIT)) {
 298                ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
 299                                  "[Init] Initializing ACPI Devices\n"));
 300
 301                status = acpi_ns_initialize_devices();
 302                if (ACPI_FAILURE(status)) {
 303                        return_ACPI_STATUS(status);
 304                }
 305        }
 306
 307        /*
 308         * Empty the caches (delete the cached objects) on the assumption that
 309         * the table load filled them up more than they will be at runtime --
 310         * thus wasting non-paged memory.
 311         */
 312        status = acpi_purge_cached_objects();
 313
 314        acpi_gbl_startup_flags |= ACPI_INITIALIZED_OK;
 315        return_ACPI_STATUS(status);
 316}
 317ACPI_EXPORT_SYMBOL(acpi_initialize_objects)
 318