1114239Snjl/****************************************************************************** 2114239Snjl * 3114239Snjl * Module Name: dsinit - Object initialization namespace walk 4114239Snjl * 5114239Snjl *****************************************************************************/ 6114239Snjl 7217365Sjkim/* 8306536Sjkim * Copyright (C) 2000 - 2016, Intel Corp. 9114239Snjl * All rights reserved. 10114239Snjl * 11217365Sjkim * Redistribution and use in source and binary forms, with or without 12217365Sjkim * modification, are permitted provided that the following conditions 13217365Sjkim * are met: 14217365Sjkim * 1. Redistributions of source code must retain the above copyright 15217365Sjkim * notice, this list of conditions, and the following disclaimer, 16217365Sjkim * without modification. 17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20217365Sjkim * including a substantially similar Disclaimer requirement for further 21217365Sjkim * binary redistribution. 22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23217365Sjkim * of any contributors may be used to endorse or promote products derived 24217365Sjkim * from this software without specific prior written permission. 25114239Snjl * 26217365Sjkim * Alternatively, this software may be distributed under the terms of the 27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28217365Sjkim * Software Foundation. 29114239Snjl * 30217365Sjkim * NO WARRANTY 31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41217365Sjkim * POSSIBILITY OF SUCH DAMAGES. 42217365Sjkim */ 43114239Snjl 44193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 45193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 46193341Sjkim#include <contrib/dev/acpica/include/acdispat.h> 47193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 48193341Sjkim#include <contrib/dev/acpica/include/actables.h> 49114239Snjl 50114239Snjl#define _COMPONENT ACPI_DISPATCHER 51114239Snjl ACPI_MODULE_NAME ("dsinit") 52114239Snjl 53281075Sdim 54151937Sjkim/* Local prototypes */ 55114239Snjl 56151937Sjkimstatic ACPI_STATUS 57151937SjkimAcpiDsInitOneObject ( 58151937Sjkim ACPI_HANDLE ObjHandle, 59151937Sjkim UINT32 Level, 60151937Sjkim void *Context, 61151937Sjkim void **ReturnValue); 62151937Sjkim 63151937Sjkim 64114239Snjl/******************************************************************************* 65114239Snjl * 66114239Snjl * FUNCTION: AcpiDsInitOneObject 67114239Snjl * 68151937Sjkim * PARAMETERS: ObjHandle - Node for the object 69114239Snjl * Level - Current nesting level 70114239Snjl * Context - Points to a init info struct 71114239Snjl * ReturnValue - Not used 72114239Snjl * 73114239Snjl * RETURN: Status 74114239Snjl * 75241973Sjkim * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object 76114239Snjl * within the namespace. 77114239Snjl * 78114239Snjl * Currently, the only objects that require initialization are: 79114239Snjl * 1) Methods 80114239Snjl * 2) Operation Regions 81114239Snjl * 82114239Snjl ******************************************************************************/ 83114239Snjl 84151937Sjkimstatic ACPI_STATUS 85114239SnjlAcpiDsInitOneObject ( 86114239Snjl ACPI_HANDLE ObjHandle, 87114239Snjl UINT32 Level, 88114239Snjl void *Context, 89114239Snjl void **ReturnValue) 90114239Snjl{ 91151937Sjkim ACPI_INIT_WALK_INFO *Info = (ACPI_INIT_WALK_INFO *) Context; 92151937Sjkim ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle; 93114239Snjl ACPI_STATUS Status; 94281075Sdim ACPI_OPERAND_OBJECT *ObjDesc; 95114239Snjl 96114239Snjl 97167802Sjkim ACPI_FUNCTION_ENTRY (); 98114239Snjl 99114239Snjl 100114239Snjl /* 101151937Sjkim * We are only interested in NS nodes owned by the table that 102114239Snjl * was just loaded 103114239Snjl */ 104167802Sjkim if (Node->OwnerId != Info->OwnerId) 105114239Snjl { 106114239Snjl return (AE_OK); 107114239Snjl } 108114239Snjl 109114239Snjl Info->ObjectCount++; 110114239Snjl 111114239Snjl /* And even then, we are only interested in a few object types */ 112114239Snjl 113281075Sdim switch (AcpiNsGetType (ObjHandle)) 114114239Snjl { 115114239Snjl case ACPI_TYPE_REGION: 116114239Snjl 117114239Snjl Status = AcpiDsInitializeRegion (ObjHandle); 118114239Snjl if (ACPI_FAILURE (Status)) 119114239Snjl { 120167802Sjkim ACPI_EXCEPTION ((AE_INFO, Status, 121167802Sjkim "During Region initialization %p [%4.4s]", 122167802Sjkim ObjHandle, AcpiUtGetNodeName (ObjHandle))); 123114239Snjl } 124114239Snjl 125114239Snjl Info->OpRegionCount++; 126114239Snjl break; 127114239Snjl 128114239Snjl case ACPI_TYPE_METHOD: 129281075Sdim /* 130281075Sdim * Auto-serialization support. We will examine each method that is 131281075Sdim * NotSerialized to determine if it creates any Named objects. If 132281075Sdim * it does, it will be marked serialized to prevent problems if 133281075Sdim * the method is entered by two or more threads and an attempt is 134281075Sdim * made to create the same named object twice -- which results in 135281075Sdim * an AE_ALREADY_EXISTS exception and method abort. 136281075Sdim */ 137281075Sdim Info->MethodCount++; 138281075Sdim ObjDesc = AcpiNsGetAttachedObject (Node); 139281075Sdim if (!ObjDesc) 140281075Sdim { 141281075Sdim break; 142281075Sdim } 143114239Snjl 144281075Sdim /* Ignore if already serialized */ 145281075Sdim 146281075Sdim if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED) 147281075Sdim { 148281075Sdim Info->SerialMethodCount++; 149281075Sdim break; 150281075Sdim } 151281075Sdim 152281075Sdim if (AcpiGbl_AutoSerializeMethods) 153281075Sdim { 154281075Sdim /* Parse/scan method and serialize it if necessary */ 155281075Sdim 156281075Sdim AcpiDsAutoSerializeMethod (Node, ObjDesc); 157281075Sdim if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED) 158281075Sdim { 159281075Sdim /* Method was just converted to Serialized */ 160281075Sdim 161281075Sdim Info->SerialMethodCount++; 162281075Sdim Info->SerializedMethodCount++; 163281075Sdim break; 164281075Sdim } 165281075Sdim } 166281075Sdim 167281075Sdim Info->NonSerialMethodCount++; 168114239Snjl break; 169114239Snjl 170114239Snjl case ACPI_TYPE_DEVICE: 171114239Snjl 172114239Snjl Info->DeviceCount++; 173114239Snjl break; 174114239Snjl 175250838Sjkim default: 176114239Snjl 177114239Snjl break; 178114239Snjl } 179114239Snjl 180114239Snjl /* 181114239Snjl * We ignore errors from above, and always return OK, since 182114239Snjl * we don't want to abort the walk on a single error. 183114239Snjl */ 184114239Snjl return (AE_OK); 185114239Snjl} 186114239Snjl 187114239Snjl 188114239Snjl/******************************************************************************* 189114239Snjl * 190114239Snjl * FUNCTION: AcpiDsInitializeObjects 191114239Snjl * 192114239Snjl * PARAMETERS: TableDesc - Descriptor for parent ACPI table 193114239Snjl * StartNode - Root of subtree to be initialized. 194114239Snjl * 195114239Snjl * RETURN: Status 196114239Snjl * 197114239Snjl * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any 198114239Snjl * necessary initialization on the objects found therein 199114239Snjl * 200114239Snjl ******************************************************************************/ 201114239Snjl 202114239SnjlACPI_STATUS 203114239SnjlAcpiDsInitializeObjects ( 204193267Sjkim UINT32 TableIndex, 205114239Snjl ACPI_NAMESPACE_NODE *StartNode) 206114239Snjl{ 207114239Snjl ACPI_STATUS Status; 208114239Snjl ACPI_INIT_WALK_INFO Info; 209167802Sjkim ACPI_TABLE_HEADER *Table; 210167802Sjkim ACPI_OWNER_ID OwnerId; 211114239Snjl 212114239Snjl 213167802Sjkim ACPI_FUNCTION_TRACE (DsInitializeObjects); 214114239Snjl 215114239Snjl 216167802Sjkim Status = AcpiTbGetOwnerId (TableIndex, &OwnerId); 217167802Sjkim if (ACPI_FAILURE (Status)) 218167802Sjkim { 219167802Sjkim return_ACPI_STATUS (Status); 220167802Sjkim } 221167802Sjkim 222114239Snjl ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 223114239Snjl "**** Starting initialization of namespace objects ****\n")); 224114239Snjl 225209746Sjkim /* Set all init info to zero */ 226114239Snjl 227306536Sjkim memset (&Info, 0, sizeof (ACPI_INIT_WALK_INFO)); 228209746Sjkim 229209746Sjkim Info.OwnerId = OwnerId; 230209746Sjkim Info.TableIndex = TableIndex; 231209746Sjkim 232114239Snjl /* Walk entire namespace from the supplied root */ 233114239Snjl 234193267Sjkim Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 235114239Snjl if (ACPI_FAILURE (Status)) 236114239Snjl { 237193267Sjkim return_ACPI_STATUS (Status); 238193267Sjkim } 239193267Sjkim 240193267Sjkim /* 241193267Sjkim * We don't use AcpiWalkNamespace since we do not want to acquire 242193267Sjkim * the namespace reader lock. 243193267Sjkim */ 244193267Sjkim Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, StartNode, ACPI_UINT32_MAX, 245306536Sjkim ACPI_NS_WALK_UNLOCK, AcpiDsInitOneObject, NULL, &Info, NULL); 246193267Sjkim if (ACPI_FAILURE (Status)) 247193267Sjkim { 248167802Sjkim ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace")); 249114239Snjl } 250193267Sjkim (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 251114239Snjl 252167802Sjkim Status = AcpiGetTableByIndex (TableIndex, &Table); 253167802Sjkim if (ACPI_FAILURE (Status)) 254167802Sjkim { 255167802Sjkim return_ACPI_STATUS (Status); 256167802Sjkim } 257167802Sjkim 258306536Sjkim /* DSDT is always the first AML table */ 259306536Sjkim 260306536Sjkim if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT)) 261306536Sjkim { 262306536Sjkim ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, 263306536Sjkim "\nInitializing Namespace objects:\n")); 264306536Sjkim } 265306536Sjkim 266306536Sjkim /* Summary of objects initialized */ 267306536Sjkim 268114239Snjl ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, 269306536Sjkim "Table [%4.4s: %-8.8s] (id %.2X) - %4u Objects with %3u Devices, " 270306536Sjkim "%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n", 271306536Sjkim Table->Signature, Table->OemTableId, OwnerId, Info.ObjectCount, 272306536Sjkim Info.DeviceCount,Info.OpRegionCount, Info.MethodCount, 273306536Sjkim Info.SerialMethodCount, Info.NonSerialMethodCount, 274306536Sjkim Info.SerializedMethodCount)); 275114239Snjl 276281075Sdim ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n", 277281075Sdim Info.MethodCount, Info.OpRegionCount)); 278114239Snjl 279114239Snjl return_ACPI_STATUS (AE_OK); 280114239Snjl} 281