excreate.c revision 84491
167754Smsmith/******************************************************************************
267754Smsmith *
377424Smsmith * Module Name: excreate - Named object creation
484491Smsmith *              $Revision: 68 $
567754Smsmith *
667754Smsmith *****************************************************************************/
767754Smsmith
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
1271867Smsmith * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
1370243Smsmith * All rights 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
11877424Smsmith#define __EXCREATE_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
12977424Smsmith#define _COMPONENT          ACPI_EXECUTER
13077424Smsmith        MODULE_NAME         ("excreate")
13167754Smsmith
13267754Smsmith
13367754Smsmith/*******************************************************************************
13467754Smsmith *
13577424Smsmith * FUNCTION:    AcpiExCreateBufferField
13667754Smsmith *
13767754Smsmith * PARAMETERS:  Opcode              - The opcode to be executed
13867754Smsmith *              Operands            - List of operands for the opcode
13984491Smsmith *              WalkState           - Current state
14067754Smsmith *
14167754Smsmith * RETURN:      Status
14267754Smsmith *
14367754Smsmith * DESCRIPTION: Execute CreateField operators: CreateBitFieldOp,
14467754Smsmith *              CreateByteFieldOp, CreateWordFieldOp, CreateDWordFieldOp,
14567754Smsmith *              CreateFieldOp (which define fields in buffers)
14667754Smsmith *
14767754Smsmith * ALLOCATION:  Deletes CreateFieldOp's count operand descriptor
14867754Smsmith *
14967754Smsmith *
15067754Smsmith *  ACPI SPECIFICATION REFERENCES:
15167754Smsmith *  DefCreateBitField   :=  CreateBitFieldOp    SrcBuf  BitIdx    NameString
15267754Smsmith *  DefCreateByteField  :=  CreateByteFieldOp   SrcBuf  ByteIdx   NameString
15367754Smsmith *  DefCreateDWordField :=  CreateDWordFieldOp  SrcBuf  ByteIdx   NameString
15467754Smsmith *  DefCreateField      :=  CreateFieldOp       SrcBuf  BitIdx    NumBits     NameString
15567754Smsmith *  DefCreateWordField  :=  CreateWordFieldOp   SrcBuf  ByteIdx   NameString
15667754Smsmith *  BitIndex            :=  TermArg=>Integer
15767754Smsmith *  ByteIndex           :=  TermArg=>Integer
15867754Smsmith *  NumBits             :=  TermArg=>Integer
15967754Smsmith *  SourceBuff          :=  TermArg=>Buffer
16067754Smsmith *
16167754Smsmith ******************************************************************************/
16267754Smsmith
16367754SmsmithACPI_STATUS
16477424SmsmithAcpiExCreateBufferField (
16584491Smsmith    UINT8                   *AmlStart,
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
17577424Smsmith    FUNCTION_TRACE ("ExCreateBufferField");
17667754Smsmith
17767754Smsmith
17877424Smsmith    /* Create the descriptor */
17967754Smsmith
18077424Smsmith    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD);
18167754Smsmith    if (!ObjDesc)
18267754Smsmith    {
18367754Smsmith        Status = AE_NO_MEMORY;
18467754Smsmith        goto Cleanup;
18567754Smsmith    }
18667754Smsmith
18767754Smsmith
18867754Smsmith    /*
18967754Smsmith     * Allocate a method object for this field unit
19067754Smsmith     */
19177424Smsmith    ObjDesc->BufferField.Extra = AcpiUtCreateInternalObject (
19277424Smsmith                                    INTERNAL_TYPE_EXTRA);
19377424Smsmith    if (!ObjDesc->BufferField.Extra)
19467754Smsmith    {
19567754Smsmith        Status = AE_NO_MEMORY;
19667754Smsmith        goto Cleanup;
19767754Smsmith    }
19867754Smsmith
19967754Smsmith    /*
20067754Smsmith     * Remember location in AML stream of the field unit
20167754Smsmith     * opcode and operands -- since the buffer and index
20267754Smsmith     * operands must be evaluated.
20367754Smsmith     */
20484491Smsmith    ObjDesc->BufferField.Extra->Extra.AmlStart  = AmlStart;
20584491Smsmith    ObjDesc->BufferField.Extra->Extra.AmlLength = AmlLength;
20677424Smsmith    ObjDesc->BufferField.Node = Node;
20767754Smsmith
20867754Smsmith
20967754Smsmith    /*
21067754Smsmith     * This operation is supposed to cause the destination Name to refer
21177424Smsmith     * to the defined BufferField -- it must not store the constructed
21277424Smsmith     * BufferField object (or its current value) in some location that the
21367754Smsmith     * Name may already be pointing to.  So, if the Name currently contains
21477424Smsmith     * a reference which would cause AcpiExStore() to perform an indirect
21567754Smsmith     * store rather than setting the value of the Name itself, clobber that
21677424Smsmith     * reference before calling AcpiExStore().
21767754Smsmith     */
21867754Smsmith
21967754Smsmith    /* Type of Name's existing value */
22067754Smsmith
22167754Smsmith    switch (AcpiNsGetType (Node))
22267754Smsmith    {
22367754Smsmith
22477424Smsmith    case ACPI_TYPE_BUFFER_FIELD:
22567754Smsmith    case INTERNAL_TYPE_ALIAS:
22677424Smsmith    case INTERNAL_TYPE_REGION_FIELD:
22767754Smsmith    case INTERNAL_TYPE_BANK_FIELD:
22867754Smsmith    case INTERNAL_TYPE_INDEX_FIELD:
22967754Smsmith
23067754Smsmith        TmpDesc = AcpiNsGetAttachedObject (Node);
23167754Smsmith        if (TmpDesc)
23267754Smsmith        {
23367754Smsmith            /*
23467754Smsmith             * There is an existing object here;  delete it and zero out the
23567754Smsmith             * object field within the Node
23667754Smsmith             */
23767754Smsmith            DUMP_PATHNAME (Node,
23877424Smsmith                "ExCreateBufferField: Removing Current Reference",
23982367Smsmith                ACPI_LV_BFIELD, _COMPONENT);
24067754Smsmith
24182367Smsmith            DUMP_ENTRY (Node, ACPI_LV_BFIELD);
24267754Smsmith            DUMP_STACK_ENTRY (TmpDesc);
24367754Smsmith
24477424Smsmith            AcpiUtRemoveReference (TmpDesc);
24567754Smsmith            AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Node, NULL,
24667754Smsmith                                    ACPI_TYPE_ANY);
24767754Smsmith        }
24867754Smsmith
24967754Smsmith        /* Set the type to ANY (or the store below will fail) */
25067754Smsmith
25167754Smsmith        ((ACPI_NAMESPACE_NODE *) Node)->Type = ACPI_TYPE_ANY;
25267754Smsmith
25367754Smsmith        break;
25467754Smsmith
25567754Smsmith
25667754Smsmith    default:
25767754Smsmith
25867754Smsmith        break;
25967754Smsmith    }
26067754Smsmith
26167754Smsmith    /* Store constructed field descriptor in result location */
26267754Smsmith
26377424Smsmith    Status = AcpiExStore (ObjDesc, (ACPI_OPERAND_OBJECT *) Node,
26477424Smsmith                    WalkState);
26567754Smsmith
26667754Smsmith    /*
26767754Smsmith     * If the field descriptor was not physically stored (or if a failure
26867754Smsmith     * above), we must delete it
26967754Smsmith     */
27067754Smsmith    if (ObjDesc->Common.ReferenceCount <= 1)
27167754Smsmith    {
27277424Smsmith        AcpiUtRemoveReference (ObjDesc);
27367754Smsmith    }
27467754Smsmith
27567754Smsmith    return_ACPI_STATUS (AE_OK);
27667754Smsmith
27767754Smsmith
27867754SmsmithCleanup:
27967754Smsmith
28067754Smsmith    /* Delete region object and method subobject */
28167754Smsmith
28267754Smsmith    if (ObjDesc)
28367754Smsmith    {
28467754Smsmith        /* Remove deletes both objects! */
28567754Smsmith
28677424Smsmith        AcpiUtRemoveReference (ObjDesc);
28767754Smsmith        ObjDesc = NULL;
28867754Smsmith    }
28967754Smsmith
29067754Smsmith    return_ACPI_STATUS (Status);
29167754Smsmith}
29267754Smsmith
29367754Smsmith
29467754Smsmith/*****************************************************************************
29567754Smsmith *
29677424Smsmith * FUNCTION:    AcpiExCreateAlias
29767754Smsmith *
29877424Smsmith * PARAMETERS:  WalkState            - Current state, contains List of
29977424Smsmith *                                      operands for the opcode
30067754Smsmith *
30167754Smsmith * RETURN:      Status
30267754Smsmith *
30367754Smsmith * DESCRIPTION: Create a new named alias
30467754Smsmith *
30567754Smsmith ****************************************************************************/
30667754Smsmith
30767754SmsmithACPI_STATUS
30877424SmsmithAcpiExCreateAlias (
30967754Smsmith    ACPI_WALK_STATE         *WalkState)
31067754Smsmith{
31167754Smsmith    ACPI_NAMESPACE_NODE     *SourceNode;
31267754Smsmith    ACPI_NAMESPACE_NODE     *AliasNode;
31367754Smsmith    ACPI_STATUS             Status;
31467754Smsmith
31567754Smsmith
31677424Smsmith    FUNCTION_TRACE ("ExCreateAlias");
31767754Smsmith
31867754Smsmith
31977424Smsmith    /* Get the source/alias operands (both namespace nodes) */
32067754Smsmith
32184491Smsmith    SourceNode = (ACPI_NAMESPACE_NODE *) WalkState->Operands[WalkState->NumOperands -1];
32284491Smsmith    WalkState->NumOperands--;
32367754Smsmith
32467754Smsmith    /*
32567754Smsmith     * Don't pop it, it gets removed in the calling routine
32667754Smsmith     */
32767754Smsmith    AliasNode = AcpiDsObjStackGetValue (0, WalkState);
32867754Smsmith
32967754Smsmith    /* Add an additional reference to the object */
33067754Smsmith
33177424Smsmith    AcpiUtAddReference (SourceNode->Object);
33267754Smsmith
33367754Smsmith    /*
33467754Smsmith     * Attach the original source Node to the new Alias Node.
33567754Smsmith     */
33667754Smsmith    Status = AcpiNsAttachObject (AliasNode, SourceNode->Object,
33767754Smsmith                                    SourceNode->Type);
33867754Smsmith
33967754Smsmith
34067754Smsmith    /*
34167754Smsmith     * The new alias assumes the type of the source, but it points
34267754Smsmith     * to the same object.  The reference count of the object has two
34367754Smsmith     * additional references to prevent deletion out from under either the
34467754Smsmith     * source or the alias Node
34567754Smsmith     */
34667754Smsmith
34777424Smsmith    /* Since both operands are Nodes, we don't need to delete them */
34867754Smsmith
34967754Smsmith    return_ACPI_STATUS (Status);
35067754Smsmith}
35167754Smsmith
35267754Smsmith
35367754Smsmith/*****************************************************************************
35467754Smsmith *
35577424Smsmith * FUNCTION:    AcpiExCreateEvent
35667754Smsmith *
35784491Smsmith * PARAMETERS:  WalkState           - Current state
35867754Smsmith *
35967754Smsmith * RETURN:      Status
36067754Smsmith *
36167754Smsmith * DESCRIPTION: Create a new event object
36267754Smsmith *
36367754Smsmith ****************************************************************************/
36467754Smsmith
36567754SmsmithACPI_STATUS
36677424SmsmithAcpiExCreateEvent (
36767754Smsmith    ACPI_WALK_STATE         *WalkState)
36867754Smsmith{
36967754Smsmith    ACPI_STATUS             Status;
37067754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
37167754Smsmith
37267754Smsmith
37377424Smsmith    FUNCTION_TRACE ("ExCreateEvent");
37467754Smsmith
37567754Smsmith
37677424Smsmith    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_EVENT);
37767754Smsmith    if (!ObjDesc)
37867754Smsmith    {
37967754Smsmith        Status = AE_NO_MEMORY;
38067754Smsmith        goto Cleanup;
38167754Smsmith    }
38267754Smsmith
38367754Smsmith    /* Create the actual OS semaphore */
38467754Smsmith
38567754Smsmith    /* TBD: [Investigate] should be created with 0 or 1 units? */
38667754Smsmith
38767754Smsmith    Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 1,
38867754Smsmith                                    &ObjDesc->Event.Semaphore);
38967754Smsmith    if (ACPI_FAILURE (Status))
39067754Smsmith    {
39177424Smsmith        AcpiUtRemoveReference (ObjDesc);
39267754Smsmith        goto Cleanup;
39367754Smsmith    }
39467754Smsmith
39567754Smsmith    /* Attach object to the Node */
39667754Smsmith
39767754Smsmith    Status = AcpiNsAttachObject (AcpiDsObjStackGetValue (0, WalkState),
39867754Smsmith                                    ObjDesc, (UINT8) ACPI_TYPE_EVENT);
39967754Smsmith    if (ACPI_FAILURE (Status))
40067754Smsmith    {
40167754Smsmith        AcpiOsDeleteSemaphore (ObjDesc->Event.Semaphore);
40277424Smsmith        AcpiUtRemoveReference (ObjDesc);
40367754Smsmith        goto Cleanup;
40467754Smsmith    }
40567754Smsmith
40667754Smsmith
40767754SmsmithCleanup:
40867754Smsmith
40967754Smsmith    return_ACPI_STATUS (Status);
41067754Smsmith}
41167754Smsmith
41267754Smsmith
41367754Smsmith/*****************************************************************************
41467754Smsmith *
41577424Smsmith * FUNCTION:    AcpiExCreateMutex
41667754Smsmith *
41784491Smsmith * PARAMETERS:  WalkState           - Current state
41867754Smsmith *
41967754Smsmith * RETURN:      Status
42067754Smsmith *
42167754Smsmith * DESCRIPTION: Create a new mutex object
42267754Smsmith *
42367754Smsmith ****************************************************************************/
42467754Smsmith
42567754SmsmithACPI_STATUS
42677424SmsmithAcpiExCreateMutex (
42767754Smsmith    ACPI_WALK_STATE         *WalkState)
42867754Smsmith{
42967754Smsmith    ACPI_STATUS             Status = AE_OK;
43067754Smsmith    ACPI_OPERAND_OBJECT     *SyncDesc;
43167754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
43267754Smsmith
43367754Smsmith
43477424Smsmith    FUNCTION_TRACE_PTR ("ExCreateMutex", WALK_OPERANDS);
43567754Smsmith
43667754Smsmith
43767754Smsmith    /* Get the operand */
43867754Smsmith
43984491Smsmith    SyncDesc = WalkState->Operands[WalkState->NumOperands -1];
44084491Smsmith    WalkState->NumOperands--;
44167754Smsmith
44267754Smsmith    /* Attempt to allocate a new object */
44367754Smsmith
44477424Smsmith    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX);
44567754Smsmith    if (!ObjDesc)
44667754Smsmith    {
44767754Smsmith        Status = AE_NO_MEMORY;
44867754Smsmith        goto Cleanup;
44967754Smsmith    }
45067754Smsmith
45167754Smsmith    /* Create the actual OS semaphore */
45267754Smsmith
45367754Smsmith    Status = AcpiOsCreateSemaphore (1, 1, &ObjDesc->Mutex.Semaphore);
45467754Smsmith    if (ACPI_FAILURE (Status))
45567754Smsmith    {
45677424Smsmith        AcpiUtRemoveReference (ObjDesc);
45767754Smsmith        goto Cleanup;
45867754Smsmith    }
45967754Smsmith
46071867Smsmith    ObjDesc->Mutex.SyncLevel = (UINT8) SyncDesc->Integer.Value;
46167754Smsmith
46267754Smsmith    /* ObjDesc was on the stack top, and the name is below it */
46367754Smsmith
46467754Smsmith    Status = AcpiNsAttachObject (AcpiDsObjStackGetValue (0, WalkState),
46567754Smsmith                                ObjDesc, (UINT8) ACPI_TYPE_MUTEX);
46667754Smsmith    if (ACPI_FAILURE (Status))
46767754Smsmith    {
46867754Smsmith        AcpiOsDeleteSemaphore (ObjDesc->Mutex.Semaphore);
46977424Smsmith        AcpiUtRemoveReference (ObjDesc);
47067754Smsmith        goto Cleanup;
47167754Smsmith    }
47267754Smsmith
47367754Smsmith
47467754SmsmithCleanup:
47567754Smsmith
47667754Smsmith    /* Always delete the operand */
47767754Smsmith
47877424Smsmith    AcpiUtRemoveReference (SyncDesc);
47967754Smsmith
48067754Smsmith    return_ACPI_STATUS (Status);
48167754Smsmith}
48267754Smsmith
48367754Smsmith
48467754Smsmith/*****************************************************************************
48567754Smsmith *
48677424Smsmith * FUNCTION:    AcpiExCreateRegion
48767754Smsmith *
48884491Smsmith * PARAMETERS:  AmlStart            - Pointer to the region declaration AML
48967754Smsmith *              AmlLength           - Max length of the declaration AML
49067754Smsmith *              Operands            - List of operands for the opcode
49184491Smsmith *              WalkState           - Current state
49267754Smsmith *
49367754Smsmith * RETURN:      Status
49467754Smsmith *
49567754Smsmith * DESCRIPTION: Create a new operation region object
49667754Smsmith *
49767754Smsmith ****************************************************************************/
49867754Smsmith
49967754SmsmithACPI_STATUS
50077424SmsmithAcpiExCreateRegion (
50184491Smsmith    UINT8                   *AmlStart,
50267754Smsmith    UINT32                  AmlLength,
50369746Smsmith    UINT8                   RegionSpace,
50467754Smsmith    ACPI_WALK_STATE         *WalkState)
50567754Smsmith{
50667754Smsmith    ACPI_STATUS             Status;
50767754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
50867754Smsmith    ACPI_NAMESPACE_NODE     *Node;
50967754Smsmith
51067754Smsmith
51177424Smsmith    FUNCTION_TRACE ("ExCreateRegion");
51267754Smsmith
51367754Smsmith
51470243Smsmith    /*
51570243Smsmith     * Space ID must be one of the predefined IDs, or in the user-defined
51669746Smsmith     * range
51769746Smsmith     */
51869746Smsmith    if ((RegionSpace >= NUM_REGION_TYPES) &&
51969746Smsmith        (RegionSpace < USER_REGION_BEGIN))
52067754Smsmith    {
52169746Smsmith        REPORT_ERROR (("Invalid AddressSpace type %X\n", RegionSpace));
52269746Smsmith        return_ACPI_STATUS (AE_AML_INVALID_SPACE_ID);
52367754Smsmith    }
52467754Smsmith
52582367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (%X)\n",
52677424Smsmith                    AcpiUtGetRegionName (RegionSpace), RegionSpace));
52767754Smsmith
52867754Smsmith
52967754Smsmith    /* Get the Node from the object stack  */
53067754Smsmith
53167754Smsmith    Node = (ACPI_NAMESPACE_NODE *) AcpiDsObjStackGetValue (0, WalkState);
53267754Smsmith
53367754Smsmith    /* Create the region descriptor */
53467754Smsmith
53577424Smsmith    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
53667754Smsmith    if (!ObjDesc)
53767754Smsmith    {
53867754Smsmith        Status = AE_NO_MEMORY;
53967754Smsmith        goto Cleanup;
54067754Smsmith    }
54167754Smsmith
54267754Smsmith    /*
54367754Smsmith     * Allocate a method object for this region.
54467754Smsmith     */
54577424Smsmith    ObjDesc->Region.Extra =  AcpiUtCreateInternalObject (
54667754Smsmith                                        INTERNAL_TYPE_EXTRA);
54767754Smsmith    if (!ObjDesc->Region.Extra)
54867754Smsmith    {
54967754Smsmith        Status = AE_NO_MEMORY;
55067754Smsmith        goto Cleanup;
55167754Smsmith    }
55267754Smsmith
55367754Smsmith    /*
55467754Smsmith     * Remember location in AML stream of address & length
55567754Smsmith     * operands since they need to be evaluated at run time.
55667754Smsmith     */
55784491Smsmith    ObjDesc->Region.Extra->Extra.AmlStart  = AmlStart;
55884491Smsmith    ObjDesc->Region.Extra->Extra.AmlLength = AmlLength;
55967754Smsmith
56067754Smsmith    /* Init the region from the operands */
56167754Smsmith
56269746Smsmith    ObjDesc->Region.SpaceId       = RegionSpace;
56367754Smsmith    ObjDesc->Region.Address       = 0;
56467754Smsmith    ObjDesc->Region.Length        = 0;
56567754Smsmith
56667754Smsmith
56767754Smsmith    /* Install the new region object in the parent Node */
56867754Smsmith
56967754Smsmith    ObjDesc->Region.Node = Node;
57067754Smsmith
57167754Smsmith    Status = AcpiNsAttachObject (Node, ObjDesc,
57267754Smsmith                                (UINT8) ACPI_TYPE_REGION);
57367754Smsmith
57467754Smsmith    if (ACPI_FAILURE (Status))
57567754Smsmith    {
57667754Smsmith        goto Cleanup;
57767754Smsmith    }
57867754Smsmith
57967754Smsmith    /*
58067754Smsmith     * If we have a valid region, initialize it
58167754Smsmith     * Namespace is NOT locked at this point.
58267754Smsmith     */
58367754Smsmith    Status = AcpiEvInitializeRegion (ObjDesc, FALSE);
58467754Smsmith
58567754Smsmith    if (ACPI_FAILURE (Status))
58667754Smsmith    {
58767754Smsmith        /*
58867754Smsmith         *  If AE_NOT_EXIST is returned, it is not fatal
58967754Smsmith         *  because many regions get created before a handler
59067754Smsmith         *  is installed for said region.
59167754Smsmith         */
59267754Smsmith        if (AE_NOT_EXIST == Status)
59367754Smsmith        {
59467754Smsmith            Status = AE_OK;
59567754Smsmith        }
59667754Smsmith    }
59767754Smsmith
59867754SmsmithCleanup:
59967754Smsmith
60067754Smsmith    if (ACPI_FAILURE (Status))
60167754Smsmith    {
60267754Smsmith        /* Delete region object and method subobject */
60367754Smsmith
60467754Smsmith        if (ObjDesc)
60567754Smsmith        {
60667754Smsmith            /* Remove deletes both objects! */
60767754Smsmith
60877424Smsmith            AcpiUtRemoveReference (ObjDesc);
60967754Smsmith            ObjDesc = NULL;
61067754Smsmith        }
61167754Smsmith    }
61267754Smsmith
61367754Smsmith    return_ACPI_STATUS (Status);
61467754Smsmith}
61567754Smsmith
61667754Smsmith
61767754Smsmith/*****************************************************************************
61867754Smsmith *
61984491Smsmith * FUNCTION:    AcpiExCreateTableRegion
62084491Smsmith *
62184491Smsmith * PARAMETERS:  WalkState           - Current state
62284491Smsmith *
62384491Smsmith * RETURN:      Status
62484491Smsmith *
62584491Smsmith * DESCRIPTION: Create a new DataTableRegion object
62684491Smsmith *
62784491Smsmith ****************************************************************************/
62884491Smsmith
62984491SmsmithACPI_STATUS
63084491SmsmithAcpiExCreateTableRegion (
63184491Smsmith    ACPI_WALK_STATE         *WalkState)
63284491Smsmith{
63384491Smsmith    ACPI_STATUS             Status = AE_OK;
63484491Smsmith
63584491Smsmith
63684491Smsmith    FUNCTION_TRACE ("ExCreateTableRegion");
63784491Smsmith
63884491Smsmith/*
63984491Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
64084491Smsmith    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
64184491Smsmith    if (!ObjDesc)
64284491Smsmith    {
64384491Smsmith        Status = AE_NO_MEMORY;
64484491Smsmith        goto Cleanup;
64584491Smsmith    }
64684491Smsmith
64784491Smsmith
64884491SmsmithCleanup:
64984491Smsmith*/
65084491Smsmith
65184491Smsmith    return_ACPI_STATUS (Status);
65284491Smsmith}
65384491Smsmith
65484491Smsmith
65584491Smsmith/*****************************************************************************
65684491Smsmith *
65777424Smsmith * FUNCTION:    AcpiExCreateProcessor
65867754Smsmith *
65967754Smsmith * PARAMETERS:  Op              - Op containing the Processor definition and
66067754Smsmith *                                args
66177424Smsmith *              ProcessorNode   - Parent Node for the processor object
66267754Smsmith *
66367754Smsmith * RETURN:      Status
66467754Smsmith *
66567754Smsmith * DESCRIPTION: Create a new processor object and populate the fields
66667754Smsmith *
66767754Smsmith ****************************************************************************/
66867754Smsmith
66967754SmsmithACPI_STATUS
67077424SmsmithAcpiExCreateProcessor (
67167754Smsmith    ACPI_PARSE_OBJECT       *Op,
67277424Smsmith    ACPI_NAMESPACE_NODE     *ProcessorNode)
67367754Smsmith{
67467754Smsmith    ACPI_STATUS             Status;
67567754Smsmith    ACPI_PARSE_OBJECT       *Arg;
67667754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
67767754Smsmith
67867754Smsmith
67977424Smsmith    FUNCTION_TRACE_PTR ("ExCreateProcessor", Op);
68067754Smsmith
68167754Smsmith
68277424Smsmith    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PROCESSOR);
68367754Smsmith    if (!ObjDesc)
68467754Smsmith    {
68577424Smsmith        return_ACPI_STATUS (AE_NO_MEMORY);
68667754Smsmith    }
68767754Smsmith
68867754Smsmith    /* Install the new processor object in the parent Node */
68967754Smsmith
69077424Smsmith    Status = AcpiNsAttachObject (ProcessorNode, ObjDesc,
69167754Smsmith                                    (UINT8) ACPI_TYPE_PROCESSOR);
69267754Smsmith    if (ACPI_FAILURE (Status))
69367754Smsmith    {
69477424Smsmith        AcpiUtDeleteObjectDesc (ObjDesc);
69577424Smsmith        return_ACPI_STATUS (Status);
69667754Smsmith    }
69767754Smsmith
69877424Smsmith    /* Get first arg and verify existence */
69977424Smsmith
70067754Smsmith    Arg = Op->Value.Arg;
70167754Smsmith    if (!Arg)
70267754Smsmith    {
70377424Smsmith        return_ACPI_STATUS (AE_AML_NO_OPERAND);
70467754Smsmith    }
70567754Smsmith
70667754Smsmith    /* First arg is the Processor ID */
70767754Smsmith
70867754Smsmith    ObjDesc->Processor.ProcId = (UINT8) Arg->Value.Integer;
70967754Smsmith
71077424Smsmith    /* Get second arg and verify existence */
71167754Smsmith
71267754Smsmith    Arg = Arg->Next;
71367754Smsmith    if (!Arg)
71467754Smsmith    {
71577424Smsmith        return_ACPI_STATUS (AE_AML_NO_OPERAND);
71667754Smsmith    }
71767754Smsmith
71867754Smsmith    /* Second arg is the PBlock Address */
71967754Smsmith
72067754Smsmith    ObjDesc->Processor.Address = (ACPI_IO_ADDRESS) Arg->Value.Integer;
72167754Smsmith
72277424Smsmith    /* Get third arg and verify existence */
72367754Smsmith
72467754Smsmith    Arg = Arg->Next;
72567754Smsmith    if (!Arg)
72667754Smsmith    {
72777424Smsmith        return_ACPI_STATUS (AE_AML_NO_OPERAND);
72867754Smsmith    }
72967754Smsmith
73067754Smsmith    /* Third arg is the PBlock Length */
73167754Smsmith
73267754Smsmith    ObjDesc->Processor.Length = (UINT8) Arg->Value.Integer;
73367754Smsmith    return_ACPI_STATUS (AE_OK);
73467754Smsmith}
73567754Smsmith
73667754Smsmith
73767754Smsmith/*****************************************************************************
73867754Smsmith *
73977424Smsmith * FUNCTION:    AcpiExCreatePowerResource
74067754Smsmith *
74167754Smsmith * PARAMETERS:  Op              - Op containing the PowerResource definition
74267754Smsmith *                                and args
74377424Smsmith *              PowerNode       - Parent Node for the power object
74467754Smsmith *
74567754Smsmith * RETURN:      Status
74667754Smsmith *
74767754Smsmith * DESCRIPTION: Create a new PowerResource object and populate the fields
74867754Smsmith *
74967754Smsmith ****************************************************************************/
75067754Smsmith
75167754SmsmithACPI_STATUS
75277424SmsmithAcpiExCreatePowerResource (
75367754Smsmith    ACPI_PARSE_OBJECT       *Op,
75477424Smsmith    ACPI_NAMESPACE_NODE     *PowerNode)
75567754Smsmith{
75667754Smsmith    ACPI_STATUS             Status;
75767754Smsmith    ACPI_PARSE_OBJECT       *Arg;
75867754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
75967754Smsmith
76067754Smsmith
76177424Smsmith    FUNCTION_TRACE_PTR ("ExCreatePowerResource", Op);
76267754Smsmith
76367754Smsmith
76477424Smsmith    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_POWER);
76567754Smsmith    if (!ObjDesc)
76667754Smsmith    {
76777424Smsmith        return_ACPI_STATUS (AE_NO_MEMORY);
76867754Smsmith    }
76967754Smsmith
77067754Smsmith    /* Install the new power resource object in the parent Node */
77167754Smsmith
77277424Smsmith    Status = AcpiNsAttachObject (PowerNode, ObjDesc,
77367754Smsmith                                (UINT8) ACPI_TYPE_POWER);
77467754Smsmith    if (ACPI_FAILURE (Status))
77567754Smsmith    {
77667754Smsmith        return_ACPI_STATUS(Status);
77767754Smsmith    }
77867754Smsmith
77967754Smsmith
78077424Smsmith    /* Get first arg and verify existence */
78167754Smsmith
78277424Smsmith    Arg = Op->Value.Arg;
78367754Smsmith    if (!Arg)
78467754Smsmith    {
78577424Smsmith        return_ACPI_STATUS (AE_AML_NO_OPERAND);
78667754Smsmith    }
78767754Smsmith
78867754Smsmith    /* First arg is the SystemLevel */
78967754Smsmith
79067754Smsmith    ObjDesc->PowerResource.SystemLevel = (UINT8) Arg->Value.Integer;
79167754Smsmith
79277424Smsmith    /* Get second arg and check existence */
79367754Smsmith
79467754Smsmith    Arg = Arg->Next;
79567754Smsmith    if (!Arg)
79667754Smsmith    {
79777424Smsmith        return_ACPI_STATUS (AE_AML_NO_OPERAND);
79867754Smsmith    }
79967754Smsmith
80067754Smsmith    /* Second arg is the PBlock Address */
80167754Smsmith
80267754Smsmith    ObjDesc->PowerResource.ResourceOrder = (UINT16) Arg->Value.Integer;
80367754Smsmith
80467754Smsmith    return_ACPI_STATUS (AE_OK);
80567754Smsmith}
80667754Smsmith
80767754Smsmith
80867754Smsmith/*****************************************************************************
80967754Smsmith *
81077424Smsmith * FUNCTION:    AcpiExCreateMethod
81167754Smsmith *
81284491Smsmith * PARAMETERS:  AmlStart        - First byte of the method's AML
81367754Smsmith *              AmlLength       - AML byte count for this method
81467754Smsmith *              MethodFlags     - AML method flag byte
81567754Smsmith *              Method          - Method Node
81667754Smsmith *
81767754Smsmith * RETURN:      Status
81867754Smsmith *
81967754Smsmith * DESCRIPTION: Create a new method object
82067754Smsmith *
82167754Smsmith ****************************************************************************/
82267754Smsmith
82367754SmsmithACPI_STATUS
82477424SmsmithAcpiExCreateMethod (
82584491Smsmith    UINT8                   *AmlStart,
82667754Smsmith    UINT32                  AmlLength,
82767754Smsmith    UINT32                  MethodFlags,
82877424Smsmith    ACPI_NAMESPACE_NODE     *Method)
82967754Smsmith{
83067754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
83167754Smsmith    ACPI_STATUS             Status;
83267754Smsmith
83367754Smsmith
83477424Smsmith    FUNCTION_TRACE_PTR ("ExCreateMethod", Method);
83567754Smsmith
83667754Smsmith
83767754Smsmith    /* Create a new method object */
83867754Smsmith
83977424Smsmith    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
84067754Smsmith    if (!ObjDesc)
84167754Smsmith    {
84267754Smsmith       return_ACPI_STATUS (AE_NO_MEMORY);
84367754Smsmith    }
84467754Smsmith
84567754Smsmith    /* Get the method's AML pointer/length from the Op */
84667754Smsmith
84784491Smsmith    ObjDesc->Method.AmlStart  = AmlStart;
84884491Smsmith    ObjDesc->Method.AmlLength = AmlLength;
84967754Smsmith
85067754Smsmith    /*
85167754Smsmith     * First argument is the Method Flags (contains parameter count for the
85267754Smsmith     * method)
85367754Smsmith     */
85467754Smsmith    ObjDesc->Method.MethodFlags = (UINT8) MethodFlags;
85567754Smsmith    ObjDesc->Method.ParamCount  = (UINT8) (MethodFlags &
85667754Smsmith                                            METHOD_FLAGS_ARG_COUNT);
85767754Smsmith
85867754Smsmith    /*
85967754Smsmith     * Get the concurrency count.  If required, a semaphore will be
86067754Smsmith     * created for this method when it is parsed.
86167754Smsmith     */
86267754Smsmith    if (MethodFlags & METHOD_FLAGS_SERIALIZED)
86367754Smsmith    {
86477424Smsmith        /*
86577424Smsmith         * ACPI 1.0: Concurrency = 1
86677424Smsmith         * ACPI 2.0: Concurrency = (SyncLevel (in method declaration) + 1)
86777424Smsmith         */
86877424Smsmith        ObjDesc->Method.Concurrency = (UINT8)
86977424Smsmith                        (((MethodFlags & METHOD_FLAGS_SYNCH_LEVEL) >> 4) + 1);
87067754Smsmith    }
87167754Smsmith
87267754Smsmith    else
87367754Smsmith    {
87467754Smsmith        ObjDesc->Method.Concurrency = INFINITE_CONCURRENCY;
87567754Smsmith    }
87667754Smsmith
87767754Smsmith    /* Attach the new object to the method Node */
87867754Smsmith
87967754Smsmith    Status = AcpiNsAttachObject (Method, ObjDesc, (UINT8) ACPI_TYPE_METHOD);
88067754Smsmith    if (ACPI_FAILURE (Status))
88167754Smsmith    {
88277424Smsmith        AcpiUtDeleteObjectDesc (ObjDesc);
88367754Smsmith    }
88467754Smsmith
88567754Smsmith    return_ACPI_STATUS (Status);
88667754Smsmith}
88767754Smsmith
88867754Smsmith
889