utxfinit.c revision 239340
1239332Sjkim/****************************************************************************** 2239332Sjkim * 3239332Sjkim * Module Name: utxfinit - External interfaces for ACPICA initialization 4239332Sjkim * 5239332Sjkim *****************************************************************************/ 6239332Sjkim 7239332Sjkim/* 8239332Sjkim * Copyright (C) 2000 - 2012, Intel Corp. 9239332Sjkim * All rights reserved. 10239332Sjkim * 11239332Sjkim * Redistribution and use in source and binary forms, with or without 12239332Sjkim * modification, are permitted provided that the following conditions 13239332Sjkim * are met: 14239332Sjkim * 1. Redistributions of source code must retain the above copyright 15239332Sjkim * notice, this list of conditions, and the following disclaimer, 16239332Sjkim * without modification. 17239332Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18239332Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19239332Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20239332Sjkim * including a substantially similar Disclaimer requirement for further 21239332Sjkim * binary redistribution. 22239332Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23239332Sjkim * of any contributors may be used to endorse or promote products derived 24239332Sjkim * from this software without specific prior written permission. 25239332Sjkim * 26239332Sjkim * Alternatively, this software may be distributed under the terms of the 27239332Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28239332Sjkim * Software Foundation. 29239332Sjkim * 30239332Sjkim * NO WARRANTY 31239332Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32239332Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33239332Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34239332Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35239332Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36239332Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37239332Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38239332Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39239332Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40239332Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41239332Sjkim * POSSIBILITY OF SUCH DAMAGES. 42239332Sjkim */ 43239332Sjkim 44239332Sjkim 45239332Sjkim#define __UTXFINIT_C__ 46239332Sjkim 47239340Sjkim#include <contrib/dev/acpica/include/acpi.h> 48239340Sjkim#include <contrib/dev/acpica/include/accommon.h> 49239340Sjkim#include <contrib/dev/acpica/include/acevents.h> 50239340Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 51239340Sjkim#include <contrib/dev/acpica/include/acdebug.h> 52239340Sjkim#include <contrib/dev/acpica/include/actables.h> 53239332Sjkim 54239332Sjkim#define _COMPONENT ACPI_UTILITIES 55239332Sjkim ACPI_MODULE_NAME ("utxfinit") 56239332Sjkim 57239332Sjkim 58239332Sjkim/******************************************************************************* 59239332Sjkim * 60239332Sjkim * FUNCTION: AcpiInitializeSubsystem 61239332Sjkim * 62239332Sjkim * PARAMETERS: None 63239332Sjkim * 64239332Sjkim * RETURN: Status 65239332Sjkim * 66239332Sjkim * DESCRIPTION: Initializes all global variables. This is the first function 67239332Sjkim * called, so any early initialization belongs here. 68239332Sjkim * 69239332Sjkim ******************************************************************************/ 70239332Sjkim 71239332SjkimACPI_STATUS 72239332SjkimAcpiInitializeSubsystem ( 73239332Sjkim void) 74239332Sjkim{ 75239332Sjkim ACPI_STATUS Status; 76239332Sjkim 77239332Sjkim 78239332Sjkim ACPI_FUNCTION_TRACE (AcpiInitializeSubsystem); 79239332Sjkim 80239332Sjkim 81239332Sjkim AcpiGbl_StartupFlags = ACPI_SUBSYSTEM_INITIALIZE; 82239332Sjkim ACPI_DEBUG_EXEC (AcpiUtInitStackPtrTrace ()); 83239332Sjkim 84239332Sjkim /* Initialize the OS-Dependent layer */ 85239332Sjkim 86239332Sjkim Status = AcpiOsInitialize (); 87239332Sjkim if (ACPI_FAILURE (Status)) 88239332Sjkim { 89239332Sjkim ACPI_EXCEPTION ((AE_INFO, Status, "During OSL initialization")); 90239332Sjkim return_ACPI_STATUS (Status); 91239332Sjkim } 92239332Sjkim 93239332Sjkim /* Initialize all globals used by the subsystem */ 94239332Sjkim 95239332Sjkim Status = AcpiUtInitGlobals (); 96239332Sjkim if (ACPI_FAILURE (Status)) 97239332Sjkim { 98239332Sjkim ACPI_EXCEPTION ((AE_INFO, Status, "During initialization of globals")); 99239332Sjkim return_ACPI_STATUS (Status); 100239332Sjkim } 101239332Sjkim 102239332Sjkim /* Create the default mutex objects */ 103239332Sjkim 104239332Sjkim Status = AcpiUtMutexInitialize (); 105239332Sjkim if (ACPI_FAILURE (Status)) 106239332Sjkim { 107239332Sjkim ACPI_EXCEPTION ((AE_INFO, Status, "During Global Mutex creation")); 108239332Sjkim return_ACPI_STATUS (Status); 109239332Sjkim } 110239332Sjkim 111239332Sjkim /* 112239332Sjkim * Initialize the namespace manager and 113239332Sjkim * the root of the namespace tree 114239332Sjkim */ 115239332Sjkim Status = AcpiNsRootInitialize (); 116239332Sjkim if (ACPI_FAILURE (Status)) 117239332Sjkim { 118239332Sjkim ACPI_EXCEPTION ((AE_INFO, Status, "During Namespace initialization")); 119239332Sjkim return_ACPI_STATUS (Status); 120239332Sjkim } 121239332Sjkim 122239332Sjkim /* Initialize the global OSI interfaces list with the static names */ 123239332Sjkim 124239332Sjkim Status = AcpiUtInitializeInterfaces (); 125239332Sjkim if (ACPI_FAILURE (Status)) 126239332Sjkim { 127239332Sjkim ACPI_EXCEPTION ((AE_INFO, Status, "During OSI interfaces initialization")); 128239332Sjkim return_ACPI_STATUS (Status); 129239332Sjkim } 130239332Sjkim 131239332Sjkim /* If configured, initialize the AML debugger */ 132239332Sjkim 133239332Sjkim ACPI_DEBUGGER_EXEC (Status = AcpiDbInitialize ()); 134239332Sjkim return_ACPI_STATUS (Status); 135239332Sjkim} 136239332Sjkim 137239332SjkimACPI_EXPORT_SYMBOL (AcpiInitializeSubsystem) 138239332Sjkim 139239332Sjkim 140239332Sjkim/******************************************************************************* 141239332Sjkim * 142239332Sjkim * FUNCTION: AcpiEnableSubsystem 143239332Sjkim * 144239332Sjkim * PARAMETERS: Flags - Init/enable Options 145239332Sjkim * 146239332Sjkim * RETURN: Status 147239332Sjkim * 148239332Sjkim * DESCRIPTION: Completes the subsystem initialization including hardware. 149239332Sjkim * Puts system into ACPI mode if it isn't already. 150239332Sjkim * 151239332Sjkim ******************************************************************************/ 152239332Sjkim 153239332SjkimACPI_STATUS 154239332SjkimAcpiEnableSubsystem ( 155239332Sjkim UINT32 Flags) 156239332Sjkim{ 157239332Sjkim ACPI_STATUS Status = AE_OK; 158239332Sjkim 159239332Sjkim 160239332Sjkim ACPI_FUNCTION_TRACE (AcpiEnableSubsystem); 161239332Sjkim 162239332Sjkim 163239332Sjkim#if (!ACPI_REDUCED_HARDWARE) 164239332Sjkim 165239332Sjkim /* Enable ACPI mode */ 166239332Sjkim 167239332Sjkim if (!(Flags & ACPI_NO_ACPI_ENABLE)) 168239332Sjkim { 169239332Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Going into ACPI mode\n")); 170239332Sjkim 171239332Sjkim AcpiGbl_OriginalMode = AcpiHwGetMode(); 172239332Sjkim 173239332Sjkim Status = AcpiEnable (); 174239332Sjkim if (ACPI_FAILURE (Status)) 175239332Sjkim { 176239332Sjkim ACPI_WARNING ((AE_INFO, "AcpiEnable failed")); 177239332Sjkim return_ACPI_STATUS (Status); 178239332Sjkim } 179239332Sjkim } 180239332Sjkim 181239332Sjkim /* 182239332Sjkim * Obtain a permanent mapping for the FACS. This is required for the 183239332Sjkim * Global Lock and the Firmware Waking Vector 184239332Sjkim */ 185239332Sjkim Status = AcpiTbInitializeFacs (); 186239332Sjkim if (ACPI_FAILURE (Status)) 187239332Sjkim { 188239332Sjkim ACPI_WARNING ((AE_INFO, "Could not map the FACS table")); 189239332Sjkim return_ACPI_STATUS (Status); 190239332Sjkim } 191239332Sjkim 192239332Sjkim#endif /* !ACPI_REDUCED_HARDWARE */ 193239332Sjkim 194239332Sjkim /* 195239332Sjkim * Install the default OpRegion handlers. These are installed unless 196239332Sjkim * other handlers have already been installed via the 197239332Sjkim * InstallAddressSpaceHandler interface. 198239332Sjkim */ 199239332Sjkim if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT)) 200239332Sjkim { 201239332Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 202239332Sjkim "[Init] Installing default address space handlers\n")); 203239332Sjkim 204239332Sjkim Status = AcpiEvInstallRegionHandlers (); 205239332Sjkim if (ACPI_FAILURE (Status)) 206239332Sjkim { 207239332Sjkim return_ACPI_STATUS (Status); 208239332Sjkim } 209239332Sjkim } 210239332Sjkim 211239332Sjkim#if (!ACPI_REDUCED_HARDWARE) 212239332Sjkim /* 213239332Sjkim * Initialize ACPI Event handling (Fixed and General Purpose) 214239332Sjkim * 215239332Sjkim * Note1: We must have the hardware and events initialized before we can 216239332Sjkim * execute any control methods safely. Any control method can require 217239332Sjkim * ACPI hardware support, so the hardware must be fully initialized before 218239332Sjkim * any method execution! 219239332Sjkim * 220239332Sjkim * Note2: Fixed events are initialized and enabled here. GPEs are 221239332Sjkim * initialized, but cannot be enabled until after the hardware is 222239332Sjkim * completely initialized (SCI and GlobalLock activated) and the various 223239332Sjkim * initialization control methods are run (_REG, _STA, _INI) on the 224239332Sjkim * entire namespace. 225239332Sjkim */ 226239332Sjkim if (!(Flags & ACPI_NO_EVENT_INIT)) 227239332Sjkim { 228239332Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 229239332Sjkim "[Init] Initializing ACPI events\n")); 230239332Sjkim 231239332Sjkim Status = AcpiEvInitializeEvents (); 232239332Sjkim if (ACPI_FAILURE (Status)) 233239332Sjkim { 234239332Sjkim return_ACPI_STATUS (Status); 235239332Sjkim } 236239332Sjkim } 237239332Sjkim 238239332Sjkim /* 239239332Sjkim * Install the SCI handler and Global Lock handler. This completes the 240239332Sjkim * hardware initialization. 241239332Sjkim */ 242239332Sjkim if (!(Flags & ACPI_NO_HANDLER_INIT)) 243239332Sjkim { 244239332Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 245239332Sjkim "[Init] Installing SCI/GL handlers\n")); 246239332Sjkim 247239332Sjkim Status = AcpiEvInstallXruptHandlers (); 248239332Sjkim if (ACPI_FAILURE (Status)) 249239332Sjkim { 250239332Sjkim return_ACPI_STATUS (Status); 251239332Sjkim } 252239332Sjkim } 253239332Sjkim 254239332Sjkim#endif /* !ACPI_REDUCED_HARDWARE */ 255239332Sjkim 256239332Sjkim return_ACPI_STATUS (Status); 257239332Sjkim} 258239332Sjkim 259239332SjkimACPI_EXPORT_SYMBOL (AcpiEnableSubsystem) 260239332Sjkim 261239332Sjkim 262239332Sjkim/******************************************************************************* 263239332Sjkim * 264239332Sjkim * FUNCTION: AcpiInitializeObjects 265239332Sjkim * 266239332Sjkim * PARAMETERS: Flags - Init/enable Options 267239332Sjkim * 268239332Sjkim * RETURN: Status 269239332Sjkim * 270239332Sjkim * DESCRIPTION: Completes namespace initialization by initializing device 271239332Sjkim * objects and executing AML code for Regions, buffers, etc. 272239332Sjkim * 273239332Sjkim ******************************************************************************/ 274239332Sjkim 275239332SjkimACPI_STATUS 276239332SjkimAcpiInitializeObjects ( 277239332Sjkim UINT32 Flags) 278239332Sjkim{ 279239332Sjkim ACPI_STATUS Status = AE_OK; 280239332Sjkim 281239332Sjkim 282239332Sjkim ACPI_FUNCTION_TRACE (AcpiInitializeObjects); 283239332Sjkim 284239332Sjkim 285239332Sjkim /* 286239332Sjkim * Run all _REG methods 287239332Sjkim * 288239332Sjkim * Note: Any objects accessed by the _REG methods will be automatically 289239332Sjkim * initialized, even if they contain executable AML (see the call to 290239332Sjkim * AcpiNsInitializeObjects below). 291239332Sjkim */ 292239332Sjkim if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT)) 293239332Sjkim { 294239332Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 295239332Sjkim "[Init] Executing _REG OpRegion methods\n")); 296239332Sjkim 297239332Sjkim Status = AcpiEvInitializeOpRegions (); 298239332Sjkim if (ACPI_FAILURE (Status)) 299239332Sjkim { 300239332Sjkim return_ACPI_STATUS (Status); 301239332Sjkim } 302239332Sjkim } 303239332Sjkim 304239332Sjkim /* 305239332Sjkim * Execute any module-level code that was detected during the table load 306239332Sjkim * phase. Although illegal since ACPI 2.0, there are many machines that 307239332Sjkim * contain this type of code. Each block of detected executable AML code 308239332Sjkim * outside of any control method is wrapped with a temporary control 309239332Sjkim * method object and placed on a global list. The methods on this list 310239332Sjkim * are executed below. 311239332Sjkim */ 312239332Sjkim AcpiNsExecModuleCodeList (); 313239332Sjkim 314239332Sjkim /* 315239332Sjkim * Initialize the objects that remain uninitialized. This runs the 316239332Sjkim * executable AML that may be part of the declaration of these objects: 317239332Sjkim * OperationRegions, BufferFields, Buffers, and Packages. 318239332Sjkim */ 319239332Sjkim if (!(Flags & ACPI_NO_OBJECT_INIT)) 320239332Sjkim { 321239332Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 322239332Sjkim "[Init] Completing Initialization of ACPI Objects\n")); 323239332Sjkim 324239332Sjkim Status = AcpiNsInitializeObjects (); 325239332Sjkim if (ACPI_FAILURE (Status)) 326239332Sjkim { 327239332Sjkim return_ACPI_STATUS (Status); 328239332Sjkim } 329239332Sjkim } 330239332Sjkim 331239332Sjkim /* 332239332Sjkim * Initialize all device objects in the namespace. This runs the device 333239332Sjkim * _STA and _INI methods. 334239332Sjkim */ 335239332Sjkim if (!(Flags & ACPI_NO_DEVICE_INIT)) 336239332Sjkim { 337239332Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 338239332Sjkim "[Init] Initializing ACPI Devices\n")); 339239332Sjkim 340239332Sjkim Status = AcpiNsInitializeDevices (); 341239332Sjkim if (ACPI_FAILURE (Status)) 342239332Sjkim { 343239332Sjkim return_ACPI_STATUS (Status); 344239332Sjkim } 345239332Sjkim } 346239332Sjkim 347239332Sjkim /* 348239332Sjkim * Empty the caches (delete the cached objects) on the assumption that 349239332Sjkim * the table load filled them up more than they will be at runtime -- 350239332Sjkim * thus wasting non-paged memory. 351239332Sjkim */ 352239332Sjkim Status = AcpiPurgeCachedObjects (); 353239332Sjkim 354239332Sjkim AcpiGbl_StartupFlags |= ACPI_INITIALIZED_OK; 355239332Sjkim return_ACPI_STATUS (Status); 356239332Sjkim} 357239332Sjkim 358239332SjkimACPI_EXPORT_SYMBOL (AcpiInitializeObjects) 359