1151937Sjkim/******************************************************************************* 2151937Sjkim * 3151937Sjkim * Module Name: utstate - state object support procedures 4151937Sjkim * 5151937Sjkim ******************************************************************************/ 6151937Sjkim 7316303Sjkim/****************************************************************************** 8316303Sjkim * 9316303Sjkim * 1. Copyright Notice 10316303Sjkim * 11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12151937Sjkim * All rights reserved. 13151937Sjkim * 14316303Sjkim * 2. License 15316303Sjkim * 16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property 17316303Sjkim * rights. You may have additional license terms from the party that provided 18316303Sjkim * you this software, covering your right to use that party's intellectual 19316303Sjkim * property rights. 20316303Sjkim * 21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an 23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy, 25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered 26316303Sjkim * Code in any form, with the right to sublicense such rights; and 27316303Sjkim * 28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29316303Sjkim * license (with the right to sublicense), under only those claims of Intel 30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell, 31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof 32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright 33316303Sjkim * license, and in no event shall the patent license extend to any additions 34316303Sjkim * to or modifications of the Original Intel Code. No other license or right 35316303Sjkim * is granted directly or by implication, estoppel or otherwise; 36316303Sjkim * 37316303Sjkim * The above copyright and patent license is granted only if the following 38316303Sjkim * conditions are met: 39316303Sjkim * 40316303Sjkim * 3. Conditions 41316303Sjkim * 42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43316303Sjkim * Redistribution of source code of any substantial portion of the Covered 44316303Sjkim * Code or modification with rights to further distribute source must include 45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions, 46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition, 47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to 48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered 49316303Sjkim * Code and the date of any change. Licensee must include in that file the 50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee 51316303Sjkim * must include a prominent statement that the modification is derived, 52316303Sjkim * directly or indirectly, from Original Intel Code. 53316303Sjkim * 54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55316303Sjkim * Redistribution of source code of any substantial portion of the Covered 56316303Sjkim * Code or modification without rights to further distribute source must 57316303Sjkim * include the following Disclaimer and Export Compliance provision in the 58316303Sjkim * documentation and/or other materials provided with distribution. In 59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any 60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the 61316303Sjkim * license from Licensee to its licensee is limited to the intellectual 62316303Sjkim * property embodied in the software Licensee provides to its licensee, and 63316303Sjkim * not to intellectual property embodied in modifications its licensee may 64316303Sjkim * make. 65316303Sjkim * 66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any 67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the 68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance 69316303Sjkim * provision in the documentation and/or other materials provided with the 70316303Sjkim * distribution. 71316303Sjkim * 72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original 73316303Sjkim * Intel Code. 74316303Sjkim * 75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or 77316303Sjkim * other dealings in products derived from or relating to the Covered Code 78316303Sjkim * without prior written authorization from Intel. 79316303Sjkim * 80316303Sjkim * 4. Disclaimer and Export Compliance 81316303Sjkim * 82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88316303Sjkim * PARTICULAR PURPOSE. 89316303Sjkim * 90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97316303Sjkim * LIMITED REMEDY. 98316303Sjkim * 99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this 100316303Sjkim * software or system incorporating such software without first obtaining any 101316303Sjkim * required license or other approval from the U. S. Department of Commerce or 102316303Sjkim * any other agency or department of the United States Government. In the 103316303Sjkim * event Licensee exports any such software from the United States or 104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall 105316303Sjkim * ensure that the distribution and export/re-export of the software is in 106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the 107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process, 109316303Sjkim * software, or service, directly or indirectly, to any country for which the 110316303Sjkim * United States government or any agency thereof requires an export license, 111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining 112316303Sjkim * such license, approval or letter. 113316303Sjkim * 114316303Sjkim ***************************************************************************** 115316303Sjkim * 116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 117316303Sjkim * following license: 118316303Sjkim * 119217365Sjkim * Redistribution and use in source and binary forms, with or without 120217365Sjkim * modification, are permitted provided that the following conditions 121217365Sjkim * are met: 122217365Sjkim * 1. Redistributions of source code must retain the above copyright 123217365Sjkim * notice, this list of conditions, and the following disclaimer, 124217365Sjkim * without modification. 125217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 127217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 128217365Sjkim * including a substantially similar Disclaimer requirement for further 129217365Sjkim * binary redistribution. 130217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 131217365Sjkim * of any contributors may be used to endorse or promote products derived 132217365Sjkim * from this software without specific prior written permission. 133151937Sjkim * 134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145316303Sjkim * 146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 147217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 148217365Sjkim * Software Foundation. 149151937Sjkim * 150316303Sjkim *****************************************************************************/ 151151937Sjkim 152193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 153193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 154151937Sjkim 155151937Sjkim#define _COMPONENT ACPI_UTILITIES 156151937Sjkim ACPI_MODULE_NAME ("utstate") 157151937Sjkim 158151937Sjkim 159151937Sjkim/******************************************************************************* 160151937Sjkim * 161151937Sjkim * FUNCTION: AcpiUtPushGenericState 162151937Sjkim * 163151937Sjkim * PARAMETERS: ListHead - Head of the state stack 164151937Sjkim * State - State object to push 165151937Sjkim * 166151937Sjkim * RETURN: None 167151937Sjkim * 168151937Sjkim * DESCRIPTION: Push a state object onto a state stack 169151937Sjkim * 170151937Sjkim ******************************************************************************/ 171151937Sjkim 172151937Sjkimvoid 173151937SjkimAcpiUtPushGenericState ( 174151937Sjkim ACPI_GENERIC_STATE **ListHead, 175151937Sjkim ACPI_GENERIC_STATE *State) 176151937Sjkim{ 177243347Sjkim ACPI_FUNCTION_ENTRY (); 178151937Sjkim 179151937Sjkim 180151937Sjkim /* Push the state object onto the front of the list (stack) */ 181151937Sjkim 182151937Sjkim State->Common.Next = *ListHead; 183151937Sjkim *ListHead = State; 184243347Sjkim return; 185151937Sjkim} 186151937Sjkim 187151937Sjkim 188151937Sjkim/******************************************************************************* 189151937Sjkim * 190151937Sjkim * FUNCTION: AcpiUtPopGenericState 191151937Sjkim * 192151937Sjkim * PARAMETERS: ListHead - Head of the state stack 193151937Sjkim * 194151937Sjkim * RETURN: The popped state object 195151937Sjkim * 196151937Sjkim * DESCRIPTION: Pop a state object from a state stack 197151937Sjkim * 198151937Sjkim ******************************************************************************/ 199151937Sjkim 200151937SjkimACPI_GENERIC_STATE * 201151937SjkimAcpiUtPopGenericState ( 202151937Sjkim ACPI_GENERIC_STATE **ListHead) 203151937Sjkim{ 204151937Sjkim ACPI_GENERIC_STATE *State; 205151937Sjkim 206151937Sjkim 207243347Sjkim ACPI_FUNCTION_ENTRY (); 208151937Sjkim 209151937Sjkim 210151937Sjkim /* Remove the state object at the head of the list (stack) */ 211151937Sjkim 212151937Sjkim State = *ListHead; 213151937Sjkim if (State) 214151937Sjkim { 215151937Sjkim /* Update the list head */ 216151937Sjkim 217151937Sjkim *ListHead = State->Common.Next; 218151937Sjkim } 219151937Sjkim 220243347Sjkim return (State); 221151937Sjkim} 222151937Sjkim 223151937Sjkim 224151937Sjkim/******************************************************************************* 225151937Sjkim * 226151937Sjkim * FUNCTION: AcpiUtCreateGenericState 227151937Sjkim * 228151937Sjkim * PARAMETERS: None 229151937Sjkim * 230151937Sjkim * RETURN: The new state object. NULL on failure. 231151937Sjkim * 232241973Sjkim * DESCRIPTION: Create a generic state object. Attempt to obtain one from 233151937Sjkim * the global state cache; If none available, create a new one. 234151937Sjkim * 235151937Sjkim ******************************************************************************/ 236151937Sjkim 237151937SjkimACPI_GENERIC_STATE * 238151937SjkimAcpiUtCreateGenericState ( 239151937Sjkim void) 240151937Sjkim{ 241151937Sjkim ACPI_GENERIC_STATE *State; 242151937Sjkim 243151937Sjkim 244151937Sjkim ACPI_FUNCTION_ENTRY (); 245151937Sjkim 246151937Sjkim 247151937Sjkim State = AcpiOsAcquireObject (AcpiGbl_StateCache); 248151937Sjkim if (State) 249151937Sjkim { 250151937Sjkim /* Initialize */ 251167802Sjkim State->Common.DescriptorType = ACPI_DESC_TYPE_STATE; 252151937Sjkim } 253151937Sjkim 254151937Sjkim return (State); 255151937Sjkim} 256151937Sjkim 257151937Sjkim 258151937Sjkim/******************************************************************************* 259151937Sjkim * 260151937Sjkim * FUNCTION: AcpiUtCreateThreadState 261151937Sjkim * 262151937Sjkim * PARAMETERS: None 263151937Sjkim * 264151937Sjkim * RETURN: New Thread State. NULL on failure 265151937Sjkim * 266151937Sjkim * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used 267151937Sjkim * to track per-thread info during method execution 268151937Sjkim * 269151937Sjkim ******************************************************************************/ 270151937Sjkim 271151937SjkimACPI_THREAD_STATE * 272151937SjkimAcpiUtCreateThreadState ( 273151937Sjkim void) 274151937Sjkim{ 275151937Sjkim ACPI_GENERIC_STATE *State; 276151937Sjkim 277151937Sjkim 278243347Sjkim ACPI_FUNCTION_ENTRY (); 279151937Sjkim 280151937Sjkim 281151937Sjkim /* Create the generic state object */ 282151937Sjkim 283151937Sjkim State = AcpiUtCreateGenericState (); 284151937Sjkim if (!State) 285151937Sjkim { 286243347Sjkim return (NULL); 287151937Sjkim } 288151937Sjkim 289151937Sjkim /* Init fields specific to the update struct */ 290151937Sjkim 291167802Sjkim State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_THREAD; 292151937Sjkim State->Thread.ThreadId = AcpiOsGetThreadId (); 293151937Sjkim 294167802Sjkim /* Check for invalid thread ID - zero is very bad, it will break things */ 295167802Sjkim 296167802Sjkim if (!State->Thread.ThreadId) 297167802Sjkim { 298167802Sjkim ACPI_ERROR ((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId")); 299193267Sjkim State->Thread.ThreadId = (ACPI_THREAD_ID) 1; 300167802Sjkim } 301167802Sjkim 302243347Sjkim return ((ACPI_THREAD_STATE *) State); 303151937Sjkim} 304151937Sjkim 305151937Sjkim 306151937Sjkim/******************************************************************************* 307151937Sjkim * 308151937Sjkim * FUNCTION: AcpiUtCreateUpdateState 309151937Sjkim * 310151937Sjkim * PARAMETERS: Object - Initial Object to be installed in the state 311151937Sjkim * Action - Update action to be performed 312151937Sjkim * 313151937Sjkim * RETURN: New state object, null on failure 314151937Sjkim * 315151937Sjkim * DESCRIPTION: Create an "Update State" - a flavor of the generic state used 316151937Sjkim * to update reference counts and delete complex objects such 317151937Sjkim * as packages. 318151937Sjkim * 319151937Sjkim ******************************************************************************/ 320151937Sjkim 321151937SjkimACPI_GENERIC_STATE * 322151937SjkimAcpiUtCreateUpdateState ( 323151937Sjkim ACPI_OPERAND_OBJECT *Object, 324151937Sjkim UINT16 Action) 325151937Sjkim{ 326151937Sjkim ACPI_GENERIC_STATE *State; 327151937Sjkim 328151937Sjkim 329243347Sjkim ACPI_FUNCTION_ENTRY (); 330151937Sjkim 331151937Sjkim 332151937Sjkim /* Create the generic state object */ 333151937Sjkim 334151937Sjkim State = AcpiUtCreateGenericState (); 335151937Sjkim if (!State) 336151937Sjkim { 337243347Sjkim return (NULL); 338151937Sjkim } 339151937Sjkim 340151937Sjkim /* Init fields specific to the update struct */ 341151937Sjkim 342167802Sjkim State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_UPDATE; 343151937Sjkim State->Update.Object = Object; 344167802Sjkim State->Update.Value = Action; 345243347Sjkim return (State); 346151937Sjkim} 347151937Sjkim 348151937Sjkim 349151937Sjkim/******************************************************************************* 350151937Sjkim * 351151937Sjkim * FUNCTION: AcpiUtCreatePkgState 352151937Sjkim * 353151937Sjkim * PARAMETERS: Object - Initial Object to be installed in the state 354151937Sjkim * Action - Update action to be performed 355151937Sjkim * 356151937Sjkim * RETURN: New state object, null on failure 357151937Sjkim * 358151937Sjkim * DESCRIPTION: Create a "Package State" 359151937Sjkim * 360151937Sjkim ******************************************************************************/ 361151937Sjkim 362151937SjkimACPI_GENERIC_STATE * 363151937SjkimAcpiUtCreatePkgState ( 364151937Sjkim void *InternalObject, 365151937Sjkim void *ExternalObject, 366322877Sjkim UINT32 Index) 367151937Sjkim{ 368151937Sjkim ACPI_GENERIC_STATE *State; 369151937Sjkim 370151937Sjkim 371243347Sjkim ACPI_FUNCTION_ENTRY (); 372151937Sjkim 373151937Sjkim 374151937Sjkim /* Create the generic state object */ 375151937Sjkim 376151937Sjkim State = AcpiUtCreateGenericState (); 377151937Sjkim if (!State) 378151937Sjkim { 379243347Sjkim return (NULL); 380151937Sjkim } 381151937Sjkim 382151937Sjkim /* Init fields specific to the update struct */ 383151937Sjkim 384167802Sjkim State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PACKAGE; 385151937Sjkim State->Pkg.SourceObject = (ACPI_OPERAND_OBJECT *) InternalObject; 386167802Sjkim State->Pkg.DestObject = ExternalObject; 387167802Sjkim State->Pkg.Index= Index; 388167802Sjkim State->Pkg.NumPackages = 1; 389298714Sjkim 390243347Sjkim return (State); 391151937Sjkim} 392151937Sjkim 393151937Sjkim 394151937Sjkim/******************************************************************************* 395151937Sjkim * 396151937Sjkim * FUNCTION: AcpiUtCreateControlState 397151937Sjkim * 398151937Sjkim * PARAMETERS: None 399151937Sjkim * 400151937Sjkim * RETURN: New state object, null on failure 401151937Sjkim * 402151937Sjkim * DESCRIPTION: Create a "Control State" - a flavor of the generic state used 403151937Sjkim * to support nested IF/WHILE constructs in the AML. 404151937Sjkim * 405151937Sjkim ******************************************************************************/ 406151937Sjkim 407151937SjkimACPI_GENERIC_STATE * 408151937SjkimAcpiUtCreateControlState ( 409151937Sjkim void) 410151937Sjkim{ 411151937Sjkim ACPI_GENERIC_STATE *State; 412151937Sjkim 413151937Sjkim 414243347Sjkim ACPI_FUNCTION_ENTRY (); 415151937Sjkim 416151937Sjkim 417151937Sjkim /* Create the generic state object */ 418151937Sjkim 419151937Sjkim State = AcpiUtCreateGenericState (); 420151937Sjkim if (!State) 421151937Sjkim { 422243347Sjkim return (NULL); 423151937Sjkim } 424151937Sjkim 425151937Sjkim /* Init fields specific to the control struct */ 426151937Sjkim 427167802Sjkim State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_CONTROL; 428167802Sjkim State->Common.State = ACPI_CONTROL_CONDITIONAL_EXECUTING; 429298714Sjkim 430243347Sjkim return (State); 431151937Sjkim} 432151937Sjkim 433151937Sjkim 434151937Sjkim/******************************************************************************* 435151937Sjkim * 436151937Sjkim * FUNCTION: AcpiUtDeleteGenericState 437151937Sjkim * 438151937Sjkim * PARAMETERS: State - The state object to be deleted 439151937Sjkim * 440151937Sjkim * RETURN: None 441151937Sjkim * 442167802Sjkim * DESCRIPTION: Release a state object to the state cache. NULL state objects 443167802Sjkim * are ignored. 444151937Sjkim * 445151937Sjkim ******************************************************************************/ 446151937Sjkim 447151937Sjkimvoid 448151937SjkimAcpiUtDeleteGenericState ( 449151937Sjkim ACPI_GENERIC_STATE *State) 450151937Sjkim{ 451243347Sjkim ACPI_FUNCTION_ENTRY (); 452151937Sjkim 453151937Sjkim 454167802Sjkim /* Ignore null state */ 455167802Sjkim 456167802Sjkim if (State) 457167802Sjkim { 458167802Sjkim (void) AcpiOsReleaseObject (AcpiGbl_StateCache, State); 459167802Sjkim } 460298714Sjkim 461243347Sjkim return; 462151937Sjkim} 463