1ae115bc7Smrj /******************************************************************************* 2ae115bc7Smrj * 3ae115bc7Smrj * Module Name: utstate - state object support procedures 4ae115bc7Smrj * 5ae115bc7Smrj ******************************************************************************/ 6ae115bc7Smrj 726f3cdf0SGordon Ross /* 8*385cc6b4SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp. 9ae115bc7Smrj * All rights reserved. 10ae115bc7Smrj * 1126f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without 1226f3cdf0SGordon Ross * modification, are permitted provided that the following conditions 1326f3cdf0SGordon Ross * are met: 1426f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright 1526f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer, 1626f3cdf0SGordon Ross * without modification. 1726f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1826f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below 1926f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon 2026f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further 2126f3cdf0SGordon Ross * binary redistribution. 2226f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names 2326f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived 2426f3cdf0SGordon Ross * from this software without specific prior written permission. 25ae115bc7Smrj * 2626f3cdf0SGordon Ross * Alternatively, this software may be distributed under the terms of the 2726f3cdf0SGordon Ross * GNU General Public License ("GPL") version 2 as published by the Free 2826f3cdf0SGordon Ross * Software Foundation. 29ae115bc7Smrj * 3026f3cdf0SGordon Ross * NO WARRANTY 3126f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3226f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3326f3cdf0SGordon Ross * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 3426f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3526f3cdf0SGordon Ross * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3626f3cdf0SGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3726f3cdf0SGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3826f3cdf0SGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 3926f3cdf0SGordon Ross * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4026f3cdf0SGordon Ross * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4126f3cdf0SGordon Ross * POSSIBILITY OF SUCH DAMAGES. 4226f3cdf0SGordon Ross */ 43ae115bc7Smrj 44ae115bc7Smrj #include "acpi.h" 45aa2aa9a6SDana Myers #include "accommon.h" 46ae115bc7Smrj 47ae115bc7Smrj #define _COMPONENT ACPI_UTILITIES 48ae115bc7Smrj ACPI_MODULE_NAME ("utstate") 49ae115bc7Smrj 50ae115bc7Smrj 51ae115bc7Smrj /******************************************************************************* 52ae115bc7Smrj * 53ae115bc7Smrj * FUNCTION: AcpiUtPushGenericState 54ae115bc7Smrj * 55ae115bc7Smrj * PARAMETERS: ListHead - Head of the state stack 56ae115bc7Smrj * State - State object to push 57ae115bc7Smrj * 58ae115bc7Smrj * RETURN: None 59ae115bc7Smrj * 60ae115bc7Smrj * DESCRIPTION: Push a state object onto a state stack 61ae115bc7Smrj * 62ae115bc7Smrj ******************************************************************************/ 63ae115bc7Smrj 64ae115bc7Smrj void 65ae115bc7Smrj AcpiUtPushGenericState ( 66ae115bc7Smrj ACPI_GENERIC_STATE **ListHead, 67ae115bc7Smrj ACPI_GENERIC_STATE *State) 68ae115bc7Smrj { 69*385cc6b4SJerry Jelinek ACPI_FUNCTION_ENTRY (); 70ae115bc7Smrj 71ae115bc7Smrj 72ae115bc7Smrj /* Push the state object onto the front of the list (stack) */ 73ae115bc7Smrj 74ae115bc7Smrj State->Common.Next = *ListHead; 75ae115bc7Smrj *ListHead = State; 76*385cc6b4SJerry Jelinek return; 77ae115bc7Smrj } 78ae115bc7Smrj 79ae115bc7Smrj 80ae115bc7Smrj /******************************************************************************* 81ae115bc7Smrj * 82ae115bc7Smrj * FUNCTION: AcpiUtPopGenericState 83ae115bc7Smrj * 84ae115bc7Smrj * PARAMETERS: ListHead - Head of the state stack 85ae115bc7Smrj * 86ae115bc7Smrj * RETURN: The popped state object 87ae115bc7Smrj * 88ae115bc7Smrj * DESCRIPTION: Pop a state object from a state stack 89ae115bc7Smrj * 90ae115bc7Smrj ******************************************************************************/ 91ae115bc7Smrj 92ae115bc7Smrj ACPI_GENERIC_STATE * 93ae115bc7Smrj AcpiUtPopGenericState ( 94ae115bc7Smrj ACPI_GENERIC_STATE **ListHead) 95ae115bc7Smrj { 96ae115bc7Smrj ACPI_GENERIC_STATE *State; 97ae115bc7Smrj 98ae115bc7Smrj 99*385cc6b4SJerry Jelinek ACPI_FUNCTION_ENTRY (); 100ae115bc7Smrj 101ae115bc7Smrj 102ae115bc7Smrj /* Remove the state object at the head of the list (stack) */ 103ae115bc7Smrj 104ae115bc7Smrj State = *ListHead; 105ae115bc7Smrj if (State) 106ae115bc7Smrj { 107ae115bc7Smrj /* Update the list head */ 108ae115bc7Smrj 109ae115bc7Smrj *ListHead = State->Common.Next; 110ae115bc7Smrj } 111ae115bc7Smrj 112*385cc6b4SJerry Jelinek return (State); 113ae115bc7Smrj } 114ae115bc7Smrj 115ae115bc7Smrj 116ae115bc7Smrj /******************************************************************************* 117ae115bc7Smrj * 118ae115bc7Smrj * FUNCTION: AcpiUtCreateGenericState 119ae115bc7Smrj * 120ae115bc7Smrj * PARAMETERS: None 121ae115bc7Smrj * 122ae115bc7Smrj * RETURN: The new state object. NULL on failure. 123ae115bc7Smrj * 124ae115bc7Smrj * DESCRIPTION: Create a generic state object. Attempt to obtain one from 125ae115bc7Smrj * the global state cache; If none available, create a new one. 126ae115bc7Smrj * 127ae115bc7Smrj ******************************************************************************/ 128ae115bc7Smrj 129ae115bc7Smrj ACPI_GENERIC_STATE * 130ae115bc7Smrj AcpiUtCreateGenericState ( 131ae115bc7Smrj void) 132ae115bc7Smrj { 133ae115bc7Smrj ACPI_GENERIC_STATE *State; 134ae115bc7Smrj 135ae115bc7Smrj 136ae115bc7Smrj ACPI_FUNCTION_ENTRY (); 137ae115bc7Smrj 138ae115bc7Smrj 139ae115bc7Smrj State = AcpiOsAcquireObject (AcpiGbl_StateCache); 140ae115bc7Smrj if (State) 141ae115bc7Smrj { 142ae115bc7Smrj /* Initialize */ 143ae115bc7Smrj State->Common.DescriptorType = ACPI_DESC_TYPE_STATE; 144ae115bc7Smrj } 145ae115bc7Smrj 146ae115bc7Smrj return (State); 147ae115bc7Smrj } 148ae115bc7Smrj 149ae115bc7Smrj 150ae115bc7Smrj /******************************************************************************* 151ae115bc7Smrj * 152ae115bc7Smrj * FUNCTION: AcpiUtCreateThreadState 153ae115bc7Smrj * 154ae115bc7Smrj * PARAMETERS: None 155ae115bc7Smrj * 156ae115bc7Smrj * RETURN: New Thread State. NULL on failure 157ae115bc7Smrj * 158ae115bc7Smrj * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used 159ae115bc7Smrj * to track per-thread info during method execution 160ae115bc7Smrj * 161ae115bc7Smrj ******************************************************************************/ 162ae115bc7Smrj 163ae115bc7Smrj ACPI_THREAD_STATE * 164ae115bc7Smrj AcpiUtCreateThreadState ( 165ae115bc7Smrj void) 166ae115bc7Smrj { 167ae115bc7Smrj ACPI_GENERIC_STATE *State; 168ae115bc7Smrj 169ae115bc7Smrj 170*385cc6b4SJerry Jelinek ACPI_FUNCTION_ENTRY (); 171ae115bc7Smrj 172ae115bc7Smrj 173ae115bc7Smrj /* Create the generic state object */ 174ae115bc7Smrj 175ae115bc7Smrj State = AcpiUtCreateGenericState (); 176ae115bc7Smrj if (!State) 177ae115bc7Smrj { 178*385cc6b4SJerry Jelinek return (NULL); 179ae115bc7Smrj } 180ae115bc7Smrj 181ae115bc7Smrj /* Init fields specific to the update struct */ 182ae115bc7Smrj 183ae115bc7Smrj State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_THREAD; 184ae115bc7Smrj State->Thread.ThreadId = AcpiOsGetThreadId (); 185ae115bc7Smrj 186ae115bc7Smrj /* Check for invalid thread ID - zero is very bad, it will break things */ 187ae115bc7Smrj 188ae115bc7Smrj if (!State->Thread.ThreadId) 189ae115bc7Smrj { 190ae115bc7Smrj ACPI_ERROR ((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId")); 191aa2aa9a6SDana Myers State->Thread.ThreadId = (ACPI_THREAD_ID) 1; 192ae115bc7Smrj } 193ae115bc7Smrj 194*385cc6b4SJerry Jelinek return ((ACPI_THREAD_STATE *) State); 195ae115bc7Smrj } 196ae115bc7Smrj 197ae115bc7Smrj 198ae115bc7Smrj /******************************************************************************* 199ae115bc7Smrj * 200ae115bc7Smrj * FUNCTION: AcpiUtCreateUpdateState 201ae115bc7Smrj * 202ae115bc7Smrj * PARAMETERS: Object - Initial Object to be installed in the state 203ae115bc7Smrj * Action - Update action to be performed 204ae115bc7Smrj * 205ae115bc7Smrj * RETURN: New state object, null on failure 206ae115bc7Smrj * 207ae115bc7Smrj * DESCRIPTION: Create an "Update State" - a flavor of the generic state used 208ae115bc7Smrj * to update reference counts and delete complex objects such 209ae115bc7Smrj * as packages. 210ae115bc7Smrj * 211ae115bc7Smrj ******************************************************************************/ 212ae115bc7Smrj 213ae115bc7Smrj ACPI_GENERIC_STATE * 214ae115bc7Smrj AcpiUtCreateUpdateState ( 215ae115bc7Smrj ACPI_OPERAND_OBJECT *Object, 216ae115bc7Smrj UINT16 Action) 217ae115bc7Smrj { 218ae115bc7Smrj ACPI_GENERIC_STATE *State; 219ae115bc7Smrj 220ae115bc7Smrj 221*385cc6b4SJerry Jelinek ACPI_FUNCTION_ENTRY (); 222ae115bc7Smrj 223ae115bc7Smrj 224ae115bc7Smrj /* Create the generic state object */ 225ae115bc7Smrj 226ae115bc7Smrj State = AcpiUtCreateGenericState (); 227ae115bc7Smrj if (!State) 228ae115bc7Smrj { 229*385cc6b4SJerry Jelinek return (NULL); 230ae115bc7Smrj } 231ae115bc7Smrj 232ae115bc7Smrj /* Init fields specific to the update struct */ 233ae115bc7Smrj 234ae115bc7Smrj State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_UPDATE; 235ae115bc7Smrj State->Update.Object = Object; 236ae115bc7Smrj State->Update.Value = Action; 237*385cc6b4SJerry Jelinek return (State); 238ae115bc7Smrj } 239ae115bc7Smrj 240ae115bc7Smrj 241ae115bc7Smrj /******************************************************************************* 242ae115bc7Smrj * 243ae115bc7Smrj * FUNCTION: AcpiUtCreatePkgState 244ae115bc7Smrj * 245ae115bc7Smrj * PARAMETERS: Object - Initial Object to be installed in the state 246ae115bc7Smrj * Action - Update action to be performed 247ae115bc7Smrj * 248ae115bc7Smrj * RETURN: New state object, null on failure 249ae115bc7Smrj * 250ae115bc7Smrj * DESCRIPTION: Create a "Package State" 251ae115bc7Smrj * 252ae115bc7Smrj ******************************************************************************/ 253ae115bc7Smrj 254ae115bc7Smrj ACPI_GENERIC_STATE * 255ae115bc7Smrj AcpiUtCreatePkgState ( 256ae115bc7Smrj void *InternalObject, 257ae115bc7Smrj void *ExternalObject, 258ae115bc7Smrj UINT16 Index) 259ae115bc7Smrj { 260ae115bc7Smrj ACPI_GENERIC_STATE *State; 261ae115bc7Smrj 262ae115bc7Smrj 263*385cc6b4SJerry Jelinek ACPI_FUNCTION_ENTRY (); 264ae115bc7Smrj 265ae115bc7Smrj 266ae115bc7Smrj /* Create the generic state object */ 267ae115bc7Smrj 268ae115bc7Smrj State = AcpiUtCreateGenericState (); 269ae115bc7Smrj if (!State) 270ae115bc7Smrj { 271*385cc6b4SJerry Jelinek return (NULL); 272ae115bc7Smrj } 273ae115bc7Smrj 274ae115bc7Smrj /* Init fields specific to the update struct */ 275ae115bc7Smrj 276ae115bc7Smrj State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PACKAGE; 277ae115bc7Smrj State->Pkg.SourceObject = (ACPI_OPERAND_OBJECT *) InternalObject; 278ae115bc7Smrj State->Pkg.DestObject = ExternalObject; 279ae115bc7Smrj State->Pkg.Index= Index; 280ae115bc7Smrj State->Pkg.NumPackages = 1; 281ae115bc7Smrj 282*385cc6b4SJerry Jelinek return (State); 283ae115bc7Smrj } 284ae115bc7Smrj 285ae115bc7Smrj 286ae115bc7Smrj /******************************************************************************* 287ae115bc7Smrj * 288ae115bc7Smrj * FUNCTION: AcpiUtCreateControlState 289ae115bc7Smrj * 290ae115bc7Smrj * PARAMETERS: None 291ae115bc7Smrj * 292ae115bc7Smrj * RETURN: New state object, null on failure 293ae115bc7Smrj * 294ae115bc7Smrj * DESCRIPTION: Create a "Control State" - a flavor of the generic state used 295ae115bc7Smrj * to support nested IF/WHILE constructs in the AML. 296ae115bc7Smrj * 297ae115bc7Smrj ******************************************************************************/ 298ae115bc7Smrj 299ae115bc7Smrj ACPI_GENERIC_STATE * 300ae115bc7Smrj AcpiUtCreateControlState ( 301ae115bc7Smrj void) 302ae115bc7Smrj { 303ae115bc7Smrj ACPI_GENERIC_STATE *State; 304ae115bc7Smrj 305ae115bc7Smrj 306*385cc6b4SJerry Jelinek ACPI_FUNCTION_ENTRY (); 307ae115bc7Smrj 308ae115bc7Smrj 309ae115bc7Smrj /* Create the generic state object */ 310ae115bc7Smrj 311ae115bc7Smrj State = AcpiUtCreateGenericState (); 312ae115bc7Smrj if (!State) 313ae115bc7Smrj { 314*385cc6b4SJerry Jelinek return (NULL); 315ae115bc7Smrj } 316ae115bc7Smrj 317ae115bc7Smrj /* Init fields specific to the control struct */ 318ae115bc7Smrj 319ae115bc7Smrj State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_CONTROL; 320ae115bc7Smrj State->Common.State = ACPI_CONTROL_CONDITIONAL_EXECUTING; 321ae115bc7Smrj 322*385cc6b4SJerry Jelinek return (State); 323ae115bc7Smrj } 324ae115bc7Smrj 325ae115bc7Smrj 326ae115bc7Smrj /******************************************************************************* 327ae115bc7Smrj * 328ae115bc7Smrj * FUNCTION: AcpiUtDeleteGenericState 329ae115bc7Smrj * 330ae115bc7Smrj * PARAMETERS: State - The state object to be deleted 331ae115bc7Smrj * 332ae115bc7Smrj * RETURN: None 333ae115bc7Smrj * 334ae115bc7Smrj * DESCRIPTION: Release a state object to the state cache. NULL state objects 335ae115bc7Smrj * are ignored. 336ae115bc7Smrj * 337ae115bc7Smrj ******************************************************************************/ 338ae115bc7Smrj 339ae115bc7Smrj void 340ae115bc7Smrj AcpiUtDeleteGenericState ( 341ae115bc7Smrj ACPI_GENERIC_STATE *State) 342ae115bc7Smrj { 343*385cc6b4SJerry Jelinek ACPI_FUNCTION_ENTRY (); 344ae115bc7Smrj 345ae115bc7Smrj 346ae115bc7Smrj /* Ignore null state */ 347ae115bc7Smrj 348ae115bc7Smrj if (State) 349ae115bc7Smrj { 350ae115bc7Smrj (void) AcpiOsReleaseObject (AcpiGbl_StateCache, State); 351ae115bc7Smrj } 352*385cc6b4SJerry Jelinek 353*385cc6b4SJerry Jelinek return; 354ae115bc7Smrj } 355