excreate.c revision 69746
167754Smsmith/******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: amcreate - Named object creation
469746Smsmith *              $Revision: 51 $
567754Smsmith *
667754Smsmith *****************************************************************************/
767754Smsmith
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
1267754Smsmith * Some or all of this work - Copyright (c) 1999, Intel Corp.  All rights
1367754Smsmith * reserved.
1467754Smsmith *
1567754Smsmith * 2. License
1667754Smsmith *
1767754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
1867754Smsmith * rights.  You may have additional license terms from the party that provided
1967754Smsmith * you this software, covering your right to use that party's intellectual
2067754Smsmith * property rights.
2167754Smsmith *
2267754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2367754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2467754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2567754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2667754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2767754Smsmith * Code in any form, with the right to sublicense such rights; and
2867754Smsmith *
2967754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3067754Smsmith * license (with the right to sublicense), under only those claims of Intel
3167754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3267754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3367754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3467754Smsmith * license, and in no event shall the patent license extend to any additions
3567754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3667754Smsmith * is granted directly or by implication, estoppel or otherwise;
3767754Smsmith *
3867754Smsmith * The above copyright and patent license is granted only if the following
3967754Smsmith * conditions are met:
4067754Smsmith *
4167754Smsmith * 3. Conditions
4267754Smsmith *
4367754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4467754Smsmith * Redistribution of source code of any substantial portion of the Covered
4567754Smsmith * Code or modification with rights to further distribute source must include
4667754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4767754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
4867754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
4967754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5067754Smsmith * Code and the date of any change.  Licensee must include in that file the
5167754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5267754Smsmith * must include a prominent statement that the modification is derived,
5367754Smsmith * directly or indirectly, from Original Intel Code.
5467754Smsmith *
5567754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5667754Smsmith * Redistribution of source code of any substantial portion of the Covered
5767754Smsmith * Code or modification without rights to further distribute source must
5867754Smsmith * include the following Disclaimer and Export Compliance provision in the
5967754Smsmith * documentation and/or other materials provided with distribution.  In
6067754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6167754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6267754Smsmith * license from Licensee to its licensee is limited to the intellectual
6367754Smsmith * property embodied in the software Licensee provides to its licensee, and
6467754Smsmith * not to intellectual property embodied in modifications its licensee may
6567754Smsmith * make.
6667754Smsmith *
6767754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
6867754Smsmith * substantial portion of the Covered Code or modification must reproduce the
6967754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7067754Smsmith * provision in the documentation and/or other materials provided with the
7167754Smsmith * distribution.
7267754Smsmith *
7367754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7467754Smsmith * Intel Code.
7567754Smsmith *
7667754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7767754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
7867754Smsmith * other dealings in products derived from or relating to the Covered Code
7967754Smsmith * without prior written authorization from Intel.
8067754Smsmith *
8167754Smsmith * 4. Disclaimer and Export Compliance
8267754Smsmith *
8367754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8467754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8567754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8667754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8767754Smsmith
8867754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8967754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
9067754Smsmith * PARTICULAR PURPOSE.
9167754Smsmith *
9267754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9367754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9467754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9567754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9667754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9767754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9867754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9967754Smsmith * LIMITED REMEDY.
10067754Smsmith *
10167754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10267754Smsmith * software or system incorporating such software without first obtaining any
10367754Smsmith * required license or other approval from the U. S. Department of Commerce or
10467754Smsmith * any other agency or department of the United States Government.  In the
10567754Smsmith * event Licensee exports any such software from the United States or
10667754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10767754Smsmith * ensure that the distribution and export/re-export of the software is in
10867754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10967754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
11067754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11167754Smsmith * software, or service, directly or indirectly, to any country for which the
11267754Smsmith * United States government or any agency thereof requires an export license,
11367754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11467754Smsmith * such license, approval or letter.
11567754Smsmith *
11667754Smsmith *****************************************************************************/
11767754Smsmith
11867754Smsmith#define __AMCREATE_C__
11967754Smsmith
12067754Smsmith#include "acpi.h"
12167754Smsmith#include "acparser.h"
12267754Smsmith#include "acinterp.h"
12367754Smsmith#include "amlcode.h"
12467754Smsmith#include "acnamesp.h"
12567754Smsmith#include "acevents.h"
12667754Smsmith#include "acdispat.h"
12767754Smsmith
12867754Smsmith
12967754Smsmith#define _COMPONENT          INTERPRETER
13067754Smsmith        MODULE_NAME         ("amcreate")
13167754Smsmith
13267754Smsmith
13367754Smsmith/*******************************************************************************
13467754Smsmith *
13567754Smsmith * FUNCTION:    AcpiAmlExecCreateField
13667754Smsmith *
13767754Smsmith * PARAMETERS:  Opcode              - The opcode to be executed
13867754Smsmith *              Operands            - List of operands for the opcode
13967754Smsmith *
14067754Smsmith * RETURN:      Status
14167754Smsmith *
14267754Smsmith * DESCRIPTION: Execute CreateField operators: CreateBitFieldOp,
14367754Smsmith *              CreateByteFieldOp, CreateWordFieldOp, CreateDWordFieldOp,
14467754Smsmith *              CreateFieldOp (which define fields in buffers)
14567754Smsmith *
14667754Smsmith * ALLOCATION:  Deletes CreateFieldOp's count operand descriptor
14767754Smsmith *
14867754Smsmith *
14967754Smsmith *  ACPI SPECIFICATION REFERENCES:
15067754Smsmith *  DefCreateBitField   :=  CreateBitFieldOp    SrcBuf  BitIdx    NameString
15167754Smsmith *  DefCreateByteField  :=  CreateByteFieldOp   SrcBuf  ByteIdx   NameString
15267754Smsmith *  DefCreateDWordField :=  CreateDWordFieldOp  SrcBuf  ByteIdx   NameString
15367754Smsmith *  DefCreateField      :=  CreateFieldOp       SrcBuf  BitIdx    NumBits     NameString
15467754Smsmith *  DefCreateWordField  :=  CreateWordFieldOp   SrcBuf  ByteIdx   NameString
15567754Smsmith *  BitIndex            :=  TermArg=>Integer
15667754Smsmith *  ByteIndex           :=  TermArg=>Integer
15767754Smsmith *  NumBits             :=  TermArg=>Integer
15867754Smsmith *  SourceBuff          :=  TermArg=>Buffer
15967754Smsmith *
16067754Smsmith ******************************************************************************/
16167754Smsmith
16267754Smsmith
16367754SmsmithACPI_STATUS
16467754SmsmithAcpiAmlExecCreateField (
16567754Smsmith    UINT8                   *AmlPtr,
16667754Smsmith    UINT32                  AmlLength,
16767754Smsmith    ACPI_NAMESPACE_NODE     *Node,
16867754Smsmith    ACPI_WALK_STATE         *WalkState)
16967754Smsmith{
17067754Smsmith    ACPI_STATUS             Status;
17167754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
17267754Smsmith    ACPI_OPERAND_OBJECT     *TmpDesc;
17367754Smsmith
17467754Smsmith
17567754Smsmith    FUNCTION_TRACE ("AmlExecCreateField");
17667754Smsmith
17767754Smsmith
17867754Smsmith    /* Create the region descriptor */
17967754Smsmith
18067754Smsmith    ObjDesc = AcpiCmCreateInternalObject (ACPI_TYPE_FIELD_UNIT);
18167754Smsmith    if (!ObjDesc)
18267754Smsmith    {
18367754Smsmith        Status = AE_NO_MEMORY;
18467754Smsmith        goto Cleanup;
18567754Smsmith    }
18667754Smsmith
18767754Smsmith    /* Construct the field object */
18867754Smsmith
18967754Smsmith    ObjDesc->FieldUnit.Access       = (UINT8) ACCESS_ANY_ACC;
19067754Smsmith    ObjDesc->FieldUnit.LockRule     = (UINT8) GLOCK_NEVER_LOCK;
19167754Smsmith    ObjDesc->FieldUnit.UpdateRule   = (UINT8) UPDATE_PRESERVE;
19267754Smsmith
19367754Smsmith    /*
19467754Smsmith     * Allocate a method object for this field unit
19567754Smsmith     */
19667754Smsmith
19767754Smsmith    ObjDesc->FieldUnit.Extra = AcpiCmCreateInternalObject (
19867754Smsmith                                        INTERNAL_TYPE_EXTRA);
19967754Smsmith    if (!ObjDesc->FieldUnit.Extra)
20067754Smsmith    {
20167754Smsmith        Status = AE_NO_MEMORY;
20267754Smsmith        goto Cleanup;
20367754Smsmith    }
20467754Smsmith
20567754Smsmith    /*
20667754Smsmith     * Remember location in AML stream of the field unit
20767754Smsmith     * opcode and operands -- since the buffer and index
20867754Smsmith     * operands must be evaluated.
20967754Smsmith     */
21067754Smsmith
21167754Smsmith    ObjDesc->FieldUnit.Extra->Extra.Pcode       = AmlPtr;
21267754Smsmith    ObjDesc->FieldUnit.Extra->Extra.PcodeLength = AmlLength;
21367754Smsmith    ObjDesc->FieldUnit.Node = Node;
21467754Smsmith
21567754Smsmith
21667754Smsmith    /*
21767754Smsmith     * This operation is supposed to cause the destination Name to refer
21867754Smsmith     * to the defined FieldUnit -- it must not store the constructed
21967754Smsmith     * FieldUnit object (or its current value) in some location that the
22067754Smsmith     * Name may already be pointing to.  So, if the Name currently contains
22167754Smsmith     * a reference which would cause AcpiAmlExecStore() to perform an indirect
22267754Smsmith     * store rather than setting the value of the Name itself, clobber that
22367754Smsmith     * reference before calling AcpiAmlExecStore().
22467754Smsmith     */
22567754Smsmith
22667754Smsmith    /* Type of Name's existing value */
22767754Smsmith
22867754Smsmith    switch (AcpiNsGetType (Node))
22967754Smsmith    {
23067754Smsmith
23167754Smsmith    case ACPI_TYPE_FIELD_UNIT:
23267754Smsmith
23367754Smsmith    case INTERNAL_TYPE_ALIAS:
23467754Smsmith    case INTERNAL_TYPE_BANK_FIELD:
23567754Smsmith    case INTERNAL_TYPE_DEF_FIELD:
23667754Smsmith    case INTERNAL_TYPE_INDEX_FIELD:
23767754Smsmith
23867754Smsmith        TmpDesc = AcpiNsGetAttachedObject (Node);
23967754Smsmith        if (TmpDesc)
24067754Smsmith        {
24167754Smsmith            /*
24267754Smsmith             * There is an existing object here;  delete it and zero out the
24367754Smsmith             * object field within the Node
24467754Smsmith             */
24567754Smsmith
24667754Smsmith            DUMP_PATHNAME (Node,
24767754Smsmith                "AmlExecCreateField: Removing Current Reference",
24867754Smsmith                TRACE_BFIELD, _COMPONENT);
24967754Smsmith
25067754Smsmith            DUMP_ENTRY (Node, TRACE_BFIELD);
25167754Smsmith            DUMP_STACK_ENTRY (TmpDesc);
25267754Smsmith
25367754Smsmith            AcpiCmRemoveReference (TmpDesc);
25467754Smsmith            AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Node, NULL,
25567754Smsmith                                    ACPI_TYPE_ANY);
25667754Smsmith        }
25767754Smsmith
25867754Smsmith        /* Set the type to ANY (or the store below will fail) */
25967754Smsmith
26067754Smsmith        ((ACPI_NAMESPACE_NODE *) Node)->Type = ACPI_TYPE_ANY;
26167754Smsmith
26267754Smsmith        break;
26367754Smsmith
26467754Smsmith
26567754Smsmith    default:
26667754Smsmith
26767754Smsmith        break;
26867754Smsmith    }
26967754Smsmith
27067754Smsmith
27167754Smsmith    /* Store constructed field descriptor in result location */
27267754Smsmith
27367754Smsmith    Status = AcpiAmlExecStore (ObjDesc, (ACPI_OPERAND_OBJECT *) Node, WalkState);
27467754Smsmith
27567754Smsmith    /*
27667754Smsmith     * If the field descriptor was not physically stored (or if a failure
27767754Smsmith     * above), we must delete it
27867754Smsmith     */
27967754Smsmith    if (ObjDesc->Common.ReferenceCount <= 1)
28067754Smsmith    {
28167754Smsmith        AcpiCmRemoveReference (ObjDesc);
28267754Smsmith    }
28367754Smsmith
28467754Smsmith
28567754Smsmith    return_ACPI_STATUS (AE_OK);
28667754Smsmith
28767754Smsmith
28867754SmsmithCleanup:
28967754Smsmith
29067754Smsmith    /* Delete region object and method subobject */
29167754Smsmith
29267754Smsmith    if (ObjDesc)
29367754Smsmith    {
29467754Smsmith        /* Remove deletes both objects! */
29567754Smsmith
29667754Smsmith        AcpiCmRemoveReference (ObjDesc);
29767754Smsmith        ObjDesc = NULL;
29867754Smsmith    }
29967754Smsmith
30067754Smsmith    return_ACPI_STATUS (Status);
30167754Smsmith}
30267754Smsmith
30367754Smsmith
30467754Smsmith/*****************************************************************************
30567754Smsmith *
30667754Smsmith * FUNCTION:    AcpiAmlExecCreateAlias
30767754Smsmith *
30867754Smsmith * PARAMETERS:  Operands            - List of operands for the opcode
30967754Smsmith *
31067754Smsmith * RETURN:      Status
31167754Smsmith *
31267754Smsmith * DESCRIPTION: Create a new named alias
31367754Smsmith *
31467754Smsmith ****************************************************************************/
31567754Smsmith
31667754SmsmithACPI_STATUS
31767754SmsmithAcpiAmlExecCreateAlias (
31867754Smsmith    ACPI_WALK_STATE         *WalkState)
31967754Smsmith{
32067754Smsmith    ACPI_NAMESPACE_NODE     *SourceNode;
32167754Smsmith    ACPI_NAMESPACE_NODE     *AliasNode;
32267754Smsmith    ACPI_STATUS             Status;
32367754Smsmith
32467754Smsmith
32567754Smsmith    FUNCTION_TRACE ("AmlExecCreateAlias");
32667754Smsmith
32767754Smsmith
32867754Smsmith    /* Get the source/alias operands (both NTEs) */
32967754Smsmith
33067754Smsmith    Status = AcpiDsObjStackPopObject ((ACPI_OPERAND_OBJECT  **) &SourceNode,
33167754Smsmith                                        WalkState);
33267754Smsmith    if (ACPI_FAILURE (Status))
33367754Smsmith    {
33467754Smsmith        return_ACPI_STATUS (Status);
33567754Smsmith    }
33667754Smsmith
33767754Smsmith    /*
33867754Smsmith     * Don't pop it, it gets removed in the calling routine
33967754Smsmith     */
34067754Smsmith
34167754Smsmith    AliasNode = AcpiDsObjStackGetValue (0, WalkState);
34267754Smsmith
34367754Smsmith    /* Add an additional reference to the object */
34467754Smsmith
34567754Smsmith    AcpiCmAddReference (SourceNode->Object);
34667754Smsmith
34767754Smsmith    /*
34867754Smsmith     * Attach the original source Node to the new Alias Node.
34967754Smsmith     */
35067754Smsmith    Status = AcpiNsAttachObject (AliasNode, SourceNode->Object,
35167754Smsmith                                    SourceNode->Type);
35267754Smsmith
35367754Smsmith
35467754Smsmith    /*
35567754Smsmith     * The new alias assumes the type of the source, but it points
35667754Smsmith     * to the same object.  The reference count of the object has two
35767754Smsmith     * additional references to prevent deletion out from under either the
35867754Smsmith     * source or the alias Node
35967754Smsmith     */
36067754Smsmith
36167754Smsmith    /* Since both operands are NTEs, we don't need to delete them */
36267754Smsmith
36367754Smsmith    return_ACPI_STATUS (Status);
36467754Smsmith}
36567754Smsmith
36667754Smsmith
36767754Smsmith/*****************************************************************************
36867754Smsmith *
36967754Smsmith * FUNCTION:    AcpiAmlExecCreateEvent
37067754Smsmith *
37167754Smsmith * PARAMETERS:  None
37267754Smsmith *
37367754Smsmith * RETURN:      Status
37467754Smsmith *
37567754Smsmith * DESCRIPTION: Create a new event object
37667754Smsmith *
37767754Smsmith ****************************************************************************/
37867754Smsmith
37967754SmsmithACPI_STATUS
38067754SmsmithAcpiAmlExecCreateEvent (
38167754Smsmith    ACPI_WALK_STATE         *WalkState)
38267754Smsmith{
38367754Smsmith    ACPI_STATUS             Status;
38467754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
38567754Smsmith
38667754Smsmith
38767754Smsmith    FUNCTION_TRACE ("AmlExecCreateEvent");
38867754Smsmith
38967754Smsmith
39067754Smsmith BREAKPOINT3;
39167754Smsmith
39267754Smsmith    ObjDesc = AcpiCmCreateInternalObject (ACPI_TYPE_EVENT);
39367754Smsmith    if (!ObjDesc)
39467754Smsmith    {
39567754Smsmith        Status = AE_NO_MEMORY;
39667754Smsmith        goto Cleanup;
39767754Smsmith    }
39867754Smsmith
39967754Smsmith    /* Create the actual OS semaphore */
40067754Smsmith
40167754Smsmith    /* TBD: [Investigate] should be created with 0 or 1 units? */
40267754Smsmith
40367754Smsmith    Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 1,
40467754Smsmith                                    &ObjDesc->Event.Semaphore);
40567754Smsmith    if (ACPI_FAILURE (Status))
40667754Smsmith    {
40767754Smsmith        AcpiCmRemoveReference (ObjDesc);
40867754Smsmith        goto Cleanup;
40967754Smsmith    }
41067754Smsmith
41167754Smsmith    /* Attach object to the Node */
41267754Smsmith
41367754Smsmith    Status = AcpiNsAttachObject (AcpiDsObjStackGetValue (0, WalkState),
41467754Smsmith                                    ObjDesc, (UINT8) ACPI_TYPE_EVENT);
41567754Smsmith    if (ACPI_FAILURE (Status))
41667754Smsmith    {
41767754Smsmith        AcpiOsDeleteSemaphore (ObjDesc->Event.Semaphore);
41867754Smsmith        AcpiCmRemoveReference (ObjDesc);
41967754Smsmith        goto Cleanup;
42067754Smsmith    }
42167754Smsmith
42267754Smsmith
42367754SmsmithCleanup:
42467754Smsmith
42567754Smsmith    return_ACPI_STATUS (Status);
42667754Smsmith}
42767754Smsmith
42867754Smsmith
42967754Smsmith/*****************************************************************************
43067754Smsmith *
43167754Smsmith * FUNCTION:    AcpiAmlExecCreateMutex
43267754Smsmith *
43367754Smsmith * PARAMETERS:  InterpreterMode     - Current running mode (load1/Load2/Exec)
43467754Smsmith *              Operands            - List of operands for the opcode
43567754Smsmith *
43667754Smsmith * RETURN:      Status
43767754Smsmith *
43867754Smsmith * DESCRIPTION: Create a new mutex object
43967754Smsmith *
44067754Smsmith ****************************************************************************/
44167754Smsmith
44267754SmsmithACPI_STATUS
44367754SmsmithAcpiAmlExecCreateMutex (
44467754Smsmith    ACPI_WALK_STATE         *WalkState)
44567754Smsmith{
44667754Smsmith    ACPI_STATUS             Status = AE_OK;
44767754Smsmith    ACPI_OPERAND_OBJECT     *SyncDesc;
44867754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
44967754Smsmith
45067754Smsmith
45167754Smsmith    FUNCTION_TRACE_PTR ("AmlExecCreateMutex", WALK_OPERANDS);
45267754Smsmith
45367754Smsmith
45467754Smsmith    /* Get the operand */
45567754Smsmith
45667754Smsmith    Status = AcpiDsObjStackPopObject (&SyncDesc, WalkState);
45767754Smsmith    if (ACPI_FAILURE (Status))
45867754Smsmith    {
45967754Smsmith        return_ACPI_STATUS (Status);
46067754Smsmith    }
46167754Smsmith
46267754Smsmith    /* Attempt to allocate a new object */
46367754Smsmith
46467754Smsmith    ObjDesc = AcpiCmCreateInternalObject (ACPI_TYPE_MUTEX);
46567754Smsmith    if (!ObjDesc)
46667754Smsmith    {
46767754Smsmith        Status = AE_NO_MEMORY;
46867754Smsmith        goto Cleanup;
46967754Smsmith    }
47067754Smsmith
47167754Smsmith    /* Create the actual OS semaphore */
47267754Smsmith
47367754Smsmith    Status = AcpiOsCreateSemaphore (1, 1, &ObjDesc->Mutex.Semaphore);
47467754Smsmith    if (ACPI_FAILURE (Status))
47567754Smsmith    {
47667754Smsmith        AcpiCmRemoveReference (ObjDesc);
47767754Smsmith        goto Cleanup;
47867754Smsmith    }
47967754Smsmith
48067754Smsmith    ObjDesc->Mutex.SyncLevel = (UINT8) SyncDesc->Number.Value;
48167754Smsmith
48267754Smsmith    /* ObjDesc was on the stack top, and the name is below it */
48367754Smsmith
48467754Smsmith    Status = AcpiNsAttachObject (AcpiDsObjStackGetValue (0, WalkState),
48567754Smsmith                                ObjDesc, (UINT8) ACPI_TYPE_MUTEX);
48667754Smsmith    if (ACPI_FAILURE (Status))
48767754Smsmith    {
48867754Smsmith        AcpiOsDeleteSemaphore (ObjDesc->Mutex.Semaphore);
48967754Smsmith        AcpiCmRemoveReference (ObjDesc);
49067754Smsmith        goto Cleanup;
49167754Smsmith    }
49267754Smsmith
49367754Smsmith
49467754SmsmithCleanup:
49567754Smsmith
49667754Smsmith    /* Always delete the operand */
49767754Smsmith
49867754Smsmith    AcpiCmRemoveReference (SyncDesc);
49967754Smsmith
50067754Smsmith    return_ACPI_STATUS (Status);
50167754Smsmith}
50267754Smsmith
50367754Smsmith
50467754Smsmith/*****************************************************************************
50567754Smsmith *
50667754Smsmith * FUNCTION:    AcpiAmlExecCreateRegion
50767754Smsmith *
50867754Smsmith * PARAMETERS:  AmlPtr              - Pointer to the region declaration AML
50967754Smsmith *              AmlLength           - Max length of the declaration AML
51067754Smsmith *              Operands            - List of operands for the opcode
51167754Smsmith *              InterpreterMode     - Load1/Load2/Execute
51267754Smsmith *
51367754Smsmith * RETURN:      Status
51467754Smsmith *
51567754Smsmith * DESCRIPTION: Create a new operation region object
51667754Smsmith *
51767754Smsmith ****************************************************************************/
51867754Smsmith
51967754SmsmithACPI_STATUS
52067754SmsmithAcpiAmlExecCreateRegion (
52167754Smsmith    UINT8                   *AmlPtr,
52267754Smsmith    UINT32                  AmlLength,
52369746Smsmith    UINT8                   RegionSpace,
52467754Smsmith    ACPI_WALK_STATE         *WalkState)
52567754Smsmith{
52667754Smsmith    ACPI_STATUS             Status;
52767754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
52867754Smsmith    ACPI_NAMESPACE_NODE     *Node;
52967754Smsmith
53067754Smsmith
53167754Smsmith    FUNCTION_TRACE ("AmlExecCreateRegion");
53267754Smsmith
53367754Smsmith
53469746Smsmith    /*
53569746Smsmith     * Space ID must be one of the predefined IDs, or in the user-defined
53669746Smsmith     * range
53769746Smsmith     */
53869746Smsmith    if ((RegionSpace >= NUM_REGION_TYPES) &&
53969746Smsmith        (RegionSpace < USER_REGION_BEGIN))
54067754Smsmith    {
54169746Smsmith        REPORT_ERROR (("Invalid AddressSpace type %X\n", RegionSpace));
54269746Smsmith        return_ACPI_STATUS (AE_AML_INVALID_SPACE_ID);
54367754Smsmith    }
54467754Smsmith
54569746Smsmith    DEBUG_PRINT (TRACE_LOAD, ("AmlExecCreateRegion: Region Type - %s (%X)\n",
54669746Smsmith                    AcpiCmGetRegionName (RegionSpace), RegionSpace));
54767754Smsmith
54867754Smsmith
54967754Smsmith    /* Get the Node from the object stack  */
55067754Smsmith
55167754Smsmith    Node = (ACPI_NAMESPACE_NODE *) AcpiDsObjStackGetValue (0, WalkState);
55267754Smsmith
55367754Smsmith    /* Create the region descriptor */
55467754Smsmith
55567754Smsmith    ObjDesc = AcpiCmCreateInternalObject (ACPI_TYPE_REGION);
55667754Smsmith    if (!ObjDesc)
55767754Smsmith    {
55867754Smsmith        Status = AE_NO_MEMORY;
55967754Smsmith        goto Cleanup;
56067754Smsmith    }
56167754Smsmith
56267754Smsmith    /*
56367754Smsmith     * Allocate a method object for this region.
56467754Smsmith     */
56567754Smsmith
56667754Smsmith    ObjDesc->Region.Extra =  AcpiCmCreateInternalObject (
56767754Smsmith                                        INTERNAL_TYPE_EXTRA);
56867754Smsmith    if (!ObjDesc->Region.Extra)
56967754Smsmith    {
57067754Smsmith        Status = AE_NO_MEMORY;
57167754Smsmith        goto Cleanup;
57267754Smsmith    }
57367754Smsmith
57467754Smsmith    /*
57567754Smsmith     * Remember location in AML stream of address & length
57667754Smsmith     * operands since they need to be evaluated at run time.
57767754Smsmith     */
57867754Smsmith
57967754Smsmith    ObjDesc->Region.Extra->Extra.Pcode       = AmlPtr;
58067754Smsmith    ObjDesc->Region.Extra->Extra.PcodeLength = AmlLength;
58167754Smsmith
58267754Smsmith    /* Init the region from the operands */
58367754Smsmith
58469746Smsmith    ObjDesc->Region.SpaceId       = RegionSpace;
58567754Smsmith    ObjDesc->Region.Address       = 0;
58667754Smsmith    ObjDesc->Region.Length        = 0;
58767754Smsmith
58867754Smsmith
58967754Smsmith    /* Install the new region object in the parent Node */
59067754Smsmith
59167754Smsmith    ObjDesc->Region.Node = Node;
59267754Smsmith
59367754Smsmith    Status = AcpiNsAttachObject (Node, ObjDesc,
59467754Smsmith                                (UINT8) ACPI_TYPE_REGION);
59567754Smsmith
59667754Smsmith    if (ACPI_FAILURE (Status))
59767754Smsmith    {
59867754Smsmith        goto Cleanup;
59967754Smsmith    }
60067754Smsmith
60167754Smsmith    /*
60267754Smsmith     * If we have a valid region, initialize it
60367754Smsmith     * Namespace is NOT locked at this point.
60467754Smsmith     */
60567754Smsmith
60667754Smsmith    Status = AcpiEvInitializeRegion (ObjDesc, FALSE);
60767754Smsmith
60867754Smsmith    if (ACPI_FAILURE (Status))
60967754Smsmith    {
61067754Smsmith        /*
61167754Smsmith         *  If AE_NOT_EXIST is returned, it is not fatal
61267754Smsmith         *  because many regions get created before a handler
61367754Smsmith         *  is installed for said region.
61467754Smsmith         */
61567754Smsmith        if (AE_NOT_EXIST == Status)
61667754Smsmith        {
61767754Smsmith            Status = AE_OK;
61867754Smsmith        }
61967754Smsmith    }
62067754Smsmith
62167754SmsmithCleanup:
62267754Smsmith
62367754Smsmith    if (ACPI_FAILURE (Status))
62467754Smsmith    {
62567754Smsmith        /* Delete region object and method subobject */
62667754Smsmith
62767754Smsmith        if (ObjDesc)
62867754Smsmith        {
62967754Smsmith            /* Remove deletes both objects! */
63067754Smsmith
63167754Smsmith            AcpiCmRemoveReference (ObjDesc);
63267754Smsmith            ObjDesc = NULL;
63367754Smsmith        }
63467754Smsmith    }
63567754Smsmith
63667754Smsmith    return_ACPI_STATUS (Status);
63767754Smsmith}
63867754Smsmith
63967754Smsmith
64067754Smsmith/*****************************************************************************
64167754Smsmith *
64267754Smsmith * FUNCTION:    AcpiAmlExecCreateProcessor
64367754Smsmith *
64467754Smsmith * PARAMETERS:  Op              - Op containing the Processor definition and
64567754Smsmith *                                args
64667754Smsmith *              ProcessorNTE    - Node for the containing Node
64767754Smsmith *
64867754Smsmith * RETURN:      Status
64967754Smsmith *
65067754Smsmith * DESCRIPTION: Create a new processor object and populate the fields
65167754Smsmith *
65267754Smsmith ****************************************************************************/
65367754Smsmith
65467754SmsmithACPI_STATUS
65567754SmsmithAcpiAmlExecCreateProcessor (
65667754Smsmith    ACPI_PARSE_OBJECT       *Op,
65767754Smsmith    ACPI_HANDLE             ProcessorNTE)
65867754Smsmith{
65967754Smsmith    ACPI_STATUS             Status;
66067754Smsmith    ACPI_PARSE_OBJECT       *Arg;
66167754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
66267754Smsmith
66367754Smsmith
66467754Smsmith    FUNCTION_TRACE_PTR ("AmlExecCreateProcessor", Op);
66567754Smsmith
66667754Smsmith
66767754Smsmith    ObjDesc = AcpiCmCreateInternalObject (ACPI_TYPE_PROCESSOR);
66867754Smsmith    if (!ObjDesc)
66967754Smsmith    {
67067754Smsmith        Status = AE_NO_MEMORY;
67167754Smsmith        return_ACPI_STATUS (Status);
67267754Smsmith    }
67367754Smsmith
67467754Smsmith    /* Install the new processor object in the parent Node */
67567754Smsmith
67667754Smsmith    Status = AcpiNsAttachObject (ProcessorNTE, ObjDesc,
67767754Smsmith                                    (UINT8) ACPI_TYPE_PROCESSOR);
67867754Smsmith    if (ACPI_FAILURE (Status))
67967754Smsmith    {
68067754Smsmith        return_ACPI_STATUS(Status);
68167754Smsmith    }
68267754Smsmith
68367754Smsmith    Arg = Op->Value.Arg;
68467754Smsmith
68567754Smsmith    /* check existence */
68667754Smsmith
68767754Smsmith    if (!Arg)
68867754Smsmith    {
68967754Smsmith        Status = AE_AML_NO_OPERAND;
69067754Smsmith        return_ACPI_STATUS (Status);
69167754Smsmith    }
69267754Smsmith
69367754Smsmith    /* First arg is the Processor ID */
69467754Smsmith
69567754Smsmith    ObjDesc->Processor.ProcId = (UINT8) Arg->Value.Integer;
69667754Smsmith
69767754Smsmith    /* Move to next arg and check existence */
69867754Smsmith
69967754Smsmith    Arg = Arg->Next;
70067754Smsmith    if (!Arg)
70167754Smsmith    {
70267754Smsmith        Status = AE_AML_NO_OPERAND;
70367754Smsmith        return_ACPI_STATUS (Status);
70467754Smsmith    }
70567754Smsmith
70667754Smsmith    /* Second arg is the PBlock Address */
70767754Smsmith
70867754Smsmith    ObjDesc->Processor.Address = (ACPI_IO_ADDRESS) Arg->Value.Integer;
70967754Smsmith
71067754Smsmith    /* Move to next arg and check existence */
71167754Smsmith
71267754Smsmith    Arg = Arg->Next;
71367754Smsmith    if (!Arg)
71467754Smsmith    {
71567754Smsmith        Status = AE_AML_NO_OPERAND;
71667754Smsmith        return_ACPI_STATUS (Status);
71767754Smsmith    }
71867754Smsmith
71967754Smsmith    /* Third arg is the PBlock Length */
72067754Smsmith
72167754Smsmith    ObjDesc->Processor.Length = (UINT8) Arg->Value.Integer;
72267754Smsmith
72367754Smsmith    return_ACPI_STATUS (AE_OK);
72467754Smsmith}
72567754Smsmith
72667754Smsmith
72767754Smsmith/*****************************************************************************
72867754Smsmith *
72967754Smsmith * FUNCTION:    AcpiAmlExecCreatePowerResource
73067754Smsmith *
73167754Smsmith * PARAMETERS:  Op              - Op containing the PowerResource definition
73267754Smsmith *                                and args
73367754Smsmith *              PowerResNTE     - Node for the containing Node
73467754Smsmith *
73567754Smsmith * RETURN:      Status
73667754Smsmith *
73767754Smsmith * DESCRIPTION: Create a new PowerResource object and populate the fields
73867754Smsmith *
73967754Smsmith ****************************************************************************/
74067754Smsmith
74167754SmsmithACPI_STATUS
74267754SmsmithAcpiAmlExecCreatePowerResource (
74367754Smsmith    ACPI_PARSE_OBJECT       *Op,
74467754Smsmith    ACPI_HANDLE             PowerResNTE)
74567754Smsmith{
74667754Smsmith    ACPI_STATUS             Status;
74767754Smsmith    ACPI_PARSE_OBJECT       *Arg;
74867754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
74967754Smsmith
75067754Smsmith
75167754Smsmith    FUNCTION_TRACE_PTR ("AmlExecCreatePowerResource", Op);
75267754Smsmith
75367754Smsmith
75467754Smsmith    ObjDesc = AcpiCmCreateInternalObject (ACPI_TYPE_POWER);
75567754Smsmith    if (!ObjDesc)
75667754Smsmith    {
75767754Smsmith        Status = AE_NO_MEMORY;
75867754Smsmith        return_ACPI_STATUS (Status);
75967754Smsmith    }
76067754Smsmith
76167754Smsmith    /* Install the new power resource object in the parent Node */
76267754Smsmith
76367754Smsmith    Status = AcpiNsAttachObject (PowerResNTE, ObjDesc,
76467754Smsmith                                (UINT8) ACPI_TYPE_POWER);
76567754Smsmith    if (ACPI_FAILURE (Status))
76667754Smsmith    {
76767754Smsmith        return_ACPI_STATUS(Status);
76867754Smsmith    }
76967754Smsmith
77067754Smsmith    Arg = Op->Value.Arg;
77167754Smsmith
77267754Smsmith    /* check existence */
77367754Smsmith
77467754Smsmith    if (!Arg)
77567754Smsmith    {
77667754Smsmith        Status = AE_AML_NO_OPERAND;
77767754Smsmith        return_ACPI_STATUS (Status);
77867754Smsmith    }
77967754Smsmith
78067754Smsmith    /* First arg is the SystemLevel */
78167754Smsmith
78267754Smsmith    ObjDesc->PowerResource.SystemLevel = (UINT8) Arg->Value.Integer;
78367754Smsmith
78467754Smsmith    /* Move to next arg and check existence */
78567754Smsmith
78667754Smsmith    Arg = Arg->Next;
78767754Smsmith    if (!Arg)
78867754Smsmith    {
78967754Smsmith        Status = AE_AML_NO_OPERAND;
79067754Smsmith        return_ACPI_STATUS (Status);
79167754Smsmith    }
79267754Smsmith
79367754Smsmith    /* Second arg is the PBlock Address */
79467754Smsmith
79567754Smsmith    ObjDesc->PowerResource.ResourceOrder = (UINT16) Arg->Value.Integer;
79667754Smsmith
79767754Smsmith    return_ACPI_STATUS (AE_OK);
79867754Smsmith}
79967754Smsmith
80067754Smsmith
80167754Smsmith/*****************************************************************************
80267754Smsmith *
80367754Smsmith * FUNCTION:    AcpiAmlExecCreateMethod
80467754Smsmith *
80567754Smsmith * PARAMETERS:  AmlPtr          - First byte of the method's AML
80667754Smsmith *              AmlLength       - AML byte count for this method
80767754Smsmith *              MethodFlags     - AML method flag byte
80867754Smsmith *              Method          - Method Node
80967754Smsmith *
81067754Smsmith * RETURN:      Status
81167754Smsmith *
81267754Smsmith * DESCRIPTION: Create a new method object
81367754Smsmith *
81467754Smsmith ****************************************************************************/
81567754Smsmith
81667754SmsmithACPI_STATUS
81767754SmsmithAcpiAmlExecCreateMethod (
81867754Smsmith    UINT8                   *AmlPtr,
81967754Smsmith    UINT32                  AmlLength,
82067754Smsmith    UINT32                  MethodFlags,
82167754Smsmith    ACPI_HANDLE             Method)
82267754Smsmith{
82367754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
82467754Smsmith    ACPI_STATUS             Status;
82567754Smsmith
82667754Smsmith
82767754Smsmith    FUNCTION_TRACE_PTR ("AmlExecCreateMethod", Method);
82867754Smsmith
82967754Smsmith
83067754Smsmith    /* Create a new method object */
83167754Smsmith
83267754Smsmith    ObjDesc = AcpiCmCreateInternalObject (ACPI_TYPE_METHOD);
83367754Smsmith    if (!ObjDesc)
83467754Smsmith    {
83567754Smsmith       return_ACPI_STATUS (AE_NO_MEMORY);
83667754Smsmith    }
83767754Smsmith
83867754Smsmith    /* Get the method's AML pointer/length from the Op */
83967754Smsmith
84067754Smsmith    ObjDesc->Method.Pcode       = AmlPtr;
84167754Smsmith    ObjDesc->Method.PcodeLength = AmlLength;
84267754Smsmith
84367754Smsmith    /*
84467754Smsmith     * First argument is the Method Flags (contains parameter count for the
84567754Smsmith     * method)
84667754Smsmith     */
84767754Smsmith
84867754Smsmith    ObjDesc->Method.MethodFlags = (UINT8) MethodFlags;
84967754Smsmith    ObjDesc->Method.ParamCount  = (UINT8) (MethodFlags &
85067754Smsmith                                            METHOD_FLAGS_ARG_COUNT);
85167754Smsmith
85267754Smsmith    /*
85367754Smsmith     * Get the concurrency count.  If required, a semaphore will be
85467754Smsmith     * created for this method when it is parsed.
85567754Smsmith     *
85667754Smsmith     * TBD: [Future]  for APCI 2.0, there will be a SyncLevel value, not
85767754Smsmith     * just a flag
85867754Smsmith     * Concurrency = SyncLevel + 1;.
85967754Smsmith     */
86067754Smsmith
86167754Smsmith    if (MethodFlags & METHOD_FLAGS_SERIALIZED)
86267754Smsmith    {
86367754Smsmith        ObjDesc->Method.Concurrency = 1;
86467754Smsmith    }
86567754Smsmith
86667754Smsmith    else
86767754Smsmith    {
86867754Smsmith        ObjDesc->Method.Concurrency = INFINITE_CONCURRENCY;
86967754Smsmith    }
87067754Smsmith
87167754Smsmith    /* Attach the new object to the method Node */
87267754Smsmith
87367754Smsmith    Status = AcpiNsAttachObject (Method, ObjDesc, (UINT8) ACPI_TYPE_METHOD);
87467754Smsmith    if (ACPI_FAILURE (Status))
87567754Smsmith    {
87667754Smsmith        AcpiCmDeleteObjectDesc (ObjDesc);
87767754Smsmith    }
87867754Smsmith
87967754Smsmith    return_ACPI_STATUS (Status);
88067754Smsmith}
88167754Smsmith
88267754Smsmith
883