utxfinit.c revision 306536
1239332Sjkim/****************************************************************************** 2239332Sjkim * 3239332Sjkim * Module Name: utxfinit - External interfaces for ACPICA initialization 4239332Sjkim * 5239332Sjkim *****************************************************************************/ 6239332Sjkim 7239332Sjkim/* 8306536Sjkim * Copyright (C) 2000 - 2016, 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 44281075Sdim#define EXPORT_ACPI_INTERFACES 45239332Sjkim 46239340Sjkim#include <contrib/dev/acpica/include/acpi.h> 47239340Sjkim#include <contrib/dev/acpica/include/accommon.h> 48239340Sjkim#include <contrib/dev/acpica/include/acevents.h> 49239340Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 50239340Sjkim#include <contrib/dev/acpica/include/acdebug.h> 51239340Sjkim#include <contrib/dev/acpica/include/actables.h> 52239332Sjkim 53239332Sjkim#define _COMPONENT ACPI_UTILITIES 54239332Sjkim ACPI_MODULE_NAME ("utxfinit") 55239332Sjkim 56281075Sdim/* For AcpiExec only */ 57281075Sdimvoid 58281075SdimAeDoObjectOverrides ( 59281075Sdim void); 60239332Sjkim 61281075Sdim 62239332Sjkim/******************************************************************************* 63239332Sjkim * 64239332Sjkim * FUNCTION: AcpiInitializeSubsystem 65239332Sjkim * 66239332Sjkim * PARAMETERS: None 67239332Sjkim * 68239332Sjkim * RETURN: Status 69239332Sjkim * 70239332Sjkim * DESCRIPTION: Initializes all global variables. This is the first function 71239332Sjkim * called, so any early initialization belongs here. 72239332Sjkim * 73239332Sjkim ******************************************************************************/ 74239332Sjkim 75239332SjkimACPI_STATUS 76239332SjkimAcpiInitializeSubsystem ( 77239332Sjkim void) 78239332Sjkim{ 79239332Sjkim ACPI_STATUS Status; 80239332Sjkim 81239332Sjkim 82239332Sjkim ACPI_FUNCTION_TRACE (AcpiInitializeSubsystem); 83239332Sjkim 84239332Sjkim 85239332Sjkim AcpiGbl_StartupFlags = ACPI_SUBSYSTEM_INITIALIZE; 86239332Sjkim ACPI_DEBUG_EXEC (AcpiUtInitStackPtrTrace ()); 87239332Sjkim 88239332Sjkim /* Initialize the OS-Dependent layer */ 89239332Sjkim 90239332Sjkim Status = AcpiOsInitialize (); 91239332Sjkim if (ACPI_FAILURE (Status)) 92239332Sjkim { 93239332Sjkim ACPI_EXCEPTION ((AE_INFO, Status, "During OSL initialization")); 94239332Sjkim return_ACPI_STATUS (Status); 95239332Sjkim } 96239332Sjkim 97239332Sjkim /* Initialize all globals used by the subsystem */ 98239332Sjkim 99239332Sjkim Status = AcpiUtInitGlobals (); 100239332Sjkim if (ACPI_FAILURE (Status)) 101239332Sjkim { 102239332Sjkim ACPI_EXCEPTION ((AE_INFO, Status, "During initialization of globals")); 103239332Sjkim return_ACPI_STATUS (Status); 104239332Sjkim } 105239332Sjkim 106239332Sjkim /* Create the default mutex objects */ 107239332Sjkim 108239332Sjkim Status = AcpiUtMutexInitialize (); 109239332Sjkim if (ACPI_FAILURE (Status)) 110239332Sjkim { 111239332Sjkim ACPI_EXCEPTION ((AE_INFO, Status, "During Global Mutex creation")); 112239332Sjkim return_ACPI_STATUS (Status); 113239332Sjkim } 114239332Sjkim 115239332Sjkim /* 116239332Sjkim * Initialize the namespace manager and 117239332Sjkim * the root of the namespace tree 118239332Sjkim */ 119239332Sjkim Status = AcpiNsRootInitialize (); 120239332Sjkim if (ACPI_FAILURE (Status)) 121239332Sjkim { 122239332Sjkim ACPI_EXCEPTION ((AE_INFO, Status, "During Namespace initialization")); 123239332Sjkim return_ACPI_STATUS (Status); 124239332Sjkim } 125239332Sjkim 126239332Sjkim /* Initialize the global OSI interfaces list with the static names */ 127239332Sjkim 128239332Sjkim Status = AcpiUtInitializeInterfaces (); 129239332Sjkim if (ACPI_FAILURE (Status)) 130239332Sjkim { 131239332Sjkim ACPI_EXCEPTION ((AE_INFO, Status, "During OSI interfaces initialization")); 132239332Sjkim return_ACPI_STATUS (Status); 133239332Sjkim } 134239332Sjkim 135281075Sdim return_ACPI_STATUS (AE_OK); 136239332Sjkim} 137239332Sjkim 138281075SdimACPI_EXPORT_SYMBOL_INIT (AcpiInitializeSubsystem) 139239332Sjkim 140239332Sjkim 141239332Sjkim/******************************************************************************* 142239332Sjkim * 143239332Sjkim * FUNCTION: AcpiEnableSubsystem 144239332Sjkim * 145239332Sjkim * PARAMETERS: Flags - Init/enable Options 146239332Sjkim * 147239332Sjkim * RETURN: Status 148239332Sjkim * 149239332Sjkim * DESCRIPTION: Completes the subsystem initialization including hardware. 150239332Sjkim * Puts system into ACPI mode if it isn't already. 151239332Sjkim * 152239332Sjkim ******************************************************************************/ 153239332Sjkim 154239332SjkimACPI_STATUS 155239332SjkimAcpiEnableSubsystem ( 156239332Sjkim UINT32 Flags) 157239332Sjkim{ 158239332Sjkim ACPI_STATUS Status = AE_OK; 159239332Sjkim 160239332Sjkim 161239332Sjkim ACPI_FUNCTION_TRACE (AcpiEnableSubsystem); 162239332Sjkim 163239332Sjkim 164306536Sjkim /* 165306536Sjkim * The early initialization phase is complete. The namespace is loaded, 166306536Sjkim * and we can now support address spaces other than Memory, I/O, and 167306536Sjkim * PCI_Config. 168306536Sjkim */ 169306536Sjkim AcpiGbl_EarlyInitialization = FALSE; 170306536Sjkim 171239332Sjkim#if (!ACPI_REDUCED_HARDWARE) 172239332Sjkim 173239332Sjkim /* Enable ACPI mode */ 174239332Sjkim 175239332Sjkim if (!(Flags & ACPI_NO_ACPI_ENABLE)) 176239332Sjkim { 177239332Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Going into ACPI mode\n")); 178239332Sjkim 179239332Sjkim AcpiGbl_OriginalMode = AcpiHwGetMode(); 180239332Sjkim 181239332Sjkim Status = AcpiEnable (); 182239332Sjkim if (ACPI_FAILURE (Status)) 183239332Sjkim { 184239332Sjkim ACPI_WARNING ((AE_INFO, "AcpiEnable failed")); 185239332Sjkim return_ACPI_STATUS (Status); 186239332Sjkim } 187239332Sjkim } 188239332Sjkim 189239332Sjkim /* 190239332Sjkim * Obtain a permanent mapping for the FACS. This is required for the 191239332Sjkim * Global Lock and the Firmware Waking Vector 192239332Sjkim */ 193306536Sjkim if (!(Flags & ACPI_NO_FACS_INIT)) 194239332Sjkim { 195306536Sjkim Status = AcpiTbInitializeFacs (); 196239332Sjkim if (ACPI_FAILURE (Status)) 197239332Sjkim { 198306536Sjkim ACPI_WARNING ((AE_INFO, "Could not map the FACS table")); 199239332Sjkim return_ACPI_STATUS (Status); 200239332Sjkim } 201239332Sjkim } 202239332Sjkim 203239332Sjkim /* 204239332Sjkim * Initialize ACPI Event handling (Fixed and General Purpose) 205239332Sjkim * 206239332Sjkim * Note1: We must have the hardware and events initialized before we can 207239332Sjkim * execute any control methods safely. Any control method can require 208239332Sjkim * ACPI hardware support, so the hardware must be fully initialized before 209239332Sjkim * any method execution! 210239332Sjkim * 211239332Sjkim * Note2: Fixed events are initialized and enabled here. GPEs are 212239332Sjkim * initialized, but cannot be enabled until after the hardware is 213239332Sjkim * completely initialized (SCI and GlobalLock activated) and the various 214239332Sjkim * initialization control methods are run (_REG, _STA, _INI) on the 215239332Sjkim * entire namespace. 216239332Sjkim */ 217239332Sjkim if (!(Flags & ACPI_NO_EVENT_INIT)) 218239332Sjkim { 219239332Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 220239332Sjkim "[Init] Initializing ACPI events\n")); 221239332Sjkim 222239332Sjkim Status = AcpiEvInitializeEvents (); 223239332Sjkim if (ACPI_FAILURE (Status)) 224239332Sjkim { 225239332Sjkim return_ACPI_STATUS (Status); 226239332Sjkim } 227239332Sjkim } 228239332Sjkim 229239332Sjkim /* 230239332Sjkim * Install the SCI handler and Global Lock handler. This completes the 231239332Sjkim * hardware initialization. 232239332Sjkim */ 233239332Sjkim if (!(Flags & ACPI_NO_HANDLER_INIT)) 234239332Sjkim { 235239332Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 236239332Sjkim "[Init] Installing SCI/GL handlers\n")); 237239332Sjkim 238239332Sjkim Status = AcpiEvInstallXruptHandlers (); 239239332Sjkim if (ACPI_FAILURE (Status)) 240239332Sjkim { 241239332Sjkim return_ACPI_STATUS (Status); 242239332Sjkim } 243239332Sjkim } 244239332Sjkim 245239332Sjkim#endif /* !ACPI_REDUCED_HARDWARE */ 246239332Sjkim 247239332Sjkim return_ACPI_STATUS (Status); 248239332Sjkim} 249239332Sjkim 250281075SdimACPI_EXPORT_SYMBOL_INIT (AcpiEnableSubsystem) 251239332Sjkim 252239332Sjkim 253239332Sjkim/******************************************************************************* 254239332Sjkim * 255239332Sjkim * FUNCTION: AcpiInitializeObjects 256239332Sjkim * 257239332Sjkim * PARAMETERS: Flags - Init/enable Options 258239332Sjkim * 259239332Sjkim * RETURN: Status 260239332Sjkim * 261239332Sjkim * DESCRIPTION: Completes namespace initialization by initializing device 262239332Sjkim * objects and executing AML code for Regions, buffers, etc. 263239332Sjkim * 264239332Sjkim ******************************************************************************/ 265239332Sjkim 266239332SjkimACPI_STATUS 267239332SjkimAcpiInitializeObjects ( 268239332Sjkim UINT32 Flags) 269239332Sjkim{ 270239332Sjkim ACPI_STATUS Status = AE_OK; 271239332Sjkim 272239332Sjkim 273239332Sjkim ACPI_FUNCTION_TRACE (AcpiInitializeObjects); 274239332Sjkim 275239332Sjkim 276281075Sdim#ifdef ACPI_EXEC_APP 277239332Sjkim /* 278281075Sdim * This call implements the "initialization file" option for AcpiExec. 279281075Sdim * This is the precise point that we want to perform the overrides. 280281075Sdim */ 281281075Sdim AeDoObjectOverrides (); 282281075Sdim#endif 283281075Sdim 284281075Sdim /* 285239332Sjkim * Execute any module-level code that was detected during the table load 286239332Sjkim * phase. Although illegal since ACPI 2.0, there are many machines that 287239332Sjkim * contain this type of code. Each block of detected executable AML code 288239332Sjkim * outside of any control method is wrapped with a temporary control 289239332Sjkim * method object and placed on a global list. The methods on this list 290239332Sjkim * are executed below. 291306536Sjkim * 292306536Sjkim * This case executes the module-level code for all tables only after 293306536Sjkim * all of the tables have been loaded. It is a legacy option and is 294306536Sjkim * not compatible with other ACPI implementations. See AcpiNsLoadTable. 295239332Sjkim */ 296306536Sjkim if (AcpiGbl_GroupModuleLevelCode) 297239332Sjkim { 298306536Sjkim AcpiNsExecModuleCodeList (); 299239332Sjkim 300306536Sjkim /* 301306536Sjkim * Initialize the objects that remain uninitialized. This 302306536Sjkim * runs the executable AML that may be part of the 303306536Sjkim * declaration of these objects: 304306536Sjkim * OperationRegions, BufferFields, Buffers, and Packages. 305306536Sjkim */ 306306536Sjkim if (!(Flags & ACPI_NO_OBJECT_INIT)) 307239332Sjkim { 308306536Sjkim Status = AcpiNsInitializeObjects (); 309306536Sjkim if (ACPI_FAILURE (Status)) 310306536Sjkim { 311306536Sjkim return_ACPI_STATUS (Status); 312306536Sjkim } 313239332Sjkim } 314239332Sjkim } 315239332Sjkim 316239332Sjkim /* 317306536Sjkim * Initialize all device/region objects in the namespace. This runs 318306536Sjkim * the device _STA and _INI methods and region _REG methods. 319239332Sjkim */ 320306536Sjkim if (!(Flags & (ACPI_NO_DEVICE_INIT | ACPI_NO_ADDRESS_SPACE_INIT))) 321239332Sjkim { 322306536Sjkim Status = AcpiNsInitializeDevices (Flags); 323239332Sjkim if (ACPI_FAILURE (Status)) 324239332Sjkim { 325239332Sjkim return_ACPI_STATUS (Status); 326239332Sjkim } 327239332Sjkim } 328239332Sjkim 329239332Sjkim /* 330239332Sjkim * Empty the caches (delete the cached objects) on the assumption that 331239332Sjkim * the table load filled them up more than they will be at runtime -- 332239332Sjkim * thus wasting non-paged memory. 333239332Sjkim */ 334239332Sjkim Status = AcpiPurgeCachedObjects (); 335239332Sjkim 336239332Sjkim AcpiGbl_StartupFlags |= ACPI_INITIALIZED_OK; 337239332Sjkim return_ACPI_STATUS (Status); 338239332Sjkim} 339239332Sjkim 340281075SdimACPI_EXPORT_SYMBOL_INIT (AcpiInitializeObjects) 341