excreate.c revision 87031
1/******************************************************************************
2 *
3 * Module Name: excreate - Named object creation
4 *              $Revision: 79 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights.  You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code.  No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision.  In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change.  Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee.  Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution.  In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * PARTICULAR PURPOSE.
91 *
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * LIMITED REMEDY.
100 *
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government.  In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
115 *
116 *****************************************************************************/
117
118#define __EXCREATE_C__
119
120#include "acpi.h"
121#include "acparser.h"
122#include "acinterp.h"
123#include "amlcode.h"
124#include "acnamesp.h"
125#include "acevents.h"
126#include "acdispat.h"
127
128
129#define _COMPONENT          ACPI_EXECUTER
130        MODULE_NAME         ("excreate")
131
132
133/*****************************************************************************
134 *
135 * FUNCTION:    AcpiExCreateAlias
136 *
137 * PARAMETERS:  WalkState            - Current state, contains List of
138 *                                      operands for the opcode
139 *
140 * RETURN:      Status
141 *
142 * DESCRIPTION: Create a new named alias
143 *
144 ****************************************************************************/
145
146ACPI_STATUS
147AcpiExCreateAlias (
148    ACPI_WALK_STATE         *WalkState)
149{
150    ACPI_NAMESPACE_NODE     *SourceNode;
151    ACPI_STATUS             Status;
152
153
154    FUNCTION_TRACE ("ExCreateAlias");
155
156
157    /* Get the source/alias operands (both namespace nodes) */
158
159    SourceNode = (ACPI_NAMESPACE_NODE *) WalkState->Operands[1];
160
161
162    /* Attach the original source object to the new Alias Node */
163
164    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) WalkState->Operands[0],
165                                    AcpiNsGetAttachedObject (SourceNode),
166                                    SourceNode->Type);
167
168    /*
169     * The new alias assumes the type of the source, but it points
170     * to the same object.  The reference count of the object has an
171     * additional reference to prevent deletion out from under either the
172     * source or the alias Node
173     */
174
175    /* Since both operands are Nodes, we don't need to delete them */
176
177    return_ACPI_STATUS (Status);
178}
179
180
181/*****************************************************************************
182 *
183 * FUNCTION:    AcpiExCreateEvent
184 *
185 * PARAMETERS:  WalkState           - Current state
186 *
187 * RETURN:      Status
188 *
189 * DESCRIPTION: Create a new event object
190 *
191 ****************************************************************************/
192
193ACPI_STATUS
194AcpiExCreateEvent (
195    ACPI_WALK_STATE         *WalkState)
196{
197    ACPI_STATUS             Status;
198    ACPI_OPERAND_OBJECT     *ObjDesc;
199
200
201    FUNCTION_TRACE ("ExCreateEvent");
202
203
204    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_EVENT);
205    if (!ObjDesc)
206    {
207        Status = AE_NO_MEMORY;
208        goto Cleanup;
209    }
210
211    /*
212     * Create the actual OS semaphore, with zero initial units -- meaning
213     * that the event is created in an unsignalled state
214     */
215    Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0,
216                                    &ObjDesc->Event.Semaphore);
217    if (ACPI_FAILURE (Status))
218    {
219        goto Cleanup;
220    }
221
222    /* Attach object to the Node */
223
224    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) WalkState->Operands[0],
225                                    ObjDesc, (UINT8) ACPI_TYPE_EVENT);
226
227Cleanup:
228    /*
229     * Remove local reference to the object (on error, will cause deletion
230     * of both object and semaphore if present.)
231     */
232    AcpiUtRemoveReference (ObjDesc);
233    return_ACPI_STATUS (Status);
234}
235
236
237/*****************************************************************************
238 *
239 * FUNCTION:    AcpiExCreateMutex
240 *
241 * PARAMETERS:  WalkState           - Current state
242 *
243 * RETURN:      Status
244 *
245 * DESCRIPTION: Create a new mutex object
246 *
247 *              Mutex (Name[0], SyncLevel[1])
248 *
249 ****************************************************************************/
250
251ACPI_STATUS
252AcpiExCreateMutex (
253    ACPI_WALK_STATE         *WalkState)
254{
255    ACPI_STATUS             Status = AE_OK;
256    ACPI_OPERAND_OBJECT     *ObjDesc;
257
258
259    FUNCTION_TRACE_PTR ("ExCreateMutex", WALK_OPERANDS);
260
261
262    /* Create the new mutex object */
263
264    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX);
265    if (!ObjDesc)
266    {
267        Status = AE_NO_MEMORY;
268        goto Cleanup;
269    }
270
271    /*
272     * Create the actual OS semaphore.
273     * One unit max to make it a mutex, with one initial unit to allow
274     * the mutex to be acquired.
275     */
276    Status = AcpiOsCreateSemaphore (1, 1, &ObjDesc->Mutex.Semaphore);
277    if (ACPI_FAILURE (Status))
278    {
279        goto Cleanup;
280    }
281
282    /* Init object and attach to NS node */
283
284    ObjDesc->Mutex.SyncLevel = (UINT8) WalkState->Operands[1]->Integer.Value;
285
286    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) WalkState->Operands[0],
287                                ObjDesc, (UINT8) ACPI_TYPE_MUTEX);
288
289
290Cleanup:
291    /*
292     * Remove local reference to the object (on error, will cause deletion
293     * of both object and semaphore if present.)
294     */
295    AcpiUtRemoveReference (ObjDesc);
296    return_ACPI_STATUS (Status);
297}
298
299
300/*****************************************************************************
301 *
302 * FUNCTION:    AcpiExCreateRegion
303 *
304 * PARAMETERS:  AmlStart            - Pointer to the region declaration AML
305 *              AmlLength           - Max length of the declaration AML
306 *              Operands            - List of operands for the opcode
307 *              WalkState           - Current state
308 *
309 * RETURN:      Status
310 *
311 * DESCRIPTION: Create a new operation region object
312 *
313 ****************************************************************************/
314
315ACPI_STATUS
316AcpiExCreateRegion (
317    UINT8                   *AmlStart,
318    UINT32                  AmlLength,
319    UINT8                   RegionSpace,
320    ACPI_WALK_STATE         *WalkState)
321{
322    ACPI_STATUS             Status;
323    ACPI_OPERAND_OBJECT     *ObjDesc;
324    ACPI_NAMESPACE_NODE     *Node;
325    ACPI_OPERAND_OBJECT     *RegionObj2 = NULL;
326
327
328    FUNCTION_TRACE ("ExCreateRegion");
329
330
331    /* Get the Node from the object stack  */
332
333    Node = WalkState->Op->Node;
334
335    /*
336     * If the region object is already attached to this node,
337     * just return
338     */
339    if (AcpiNsGetAttachedObject (Node))
340    {
341        return_ACPI_STATUS (AE_OK);
342    }
343
344    /*
345     * Space ID must be one of the predefined IDs, or in the user-defined
346     * range
347     */
348    if ((RegionSpace >= ACPI_NUM_PREDEFINED_REGIONS) &&
349        (RegionSpace < ACPI_USER_REGION_BEGIN))
350    {
351        REPORT_ERROR (("Invalid AddressSpace type %X\n", RegionSpace));
352        return_ACPI_STATUS (AE_AML_INVALID_SPACE_ID);
353    }
354
355    ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (%X)\n",
356                    AcpiUtGetRegionName (RegionSpace), RegionSpace));
357
358
359    /* Create the region descriptor */
360
361    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
362    if (!ObjDesc)
363    {
364        Status = AE_NO_MEMORY;
365        goto Cleanup;
366    }
367
368    /*
369     * Remember location in AML stream of address & length
370     * operands since they need to be evaluated at run time.
371     */
372    RegionObj2                  = ObjDesc->Common.NextObject;
373    RegionObj2->Extra.AmlStart  = AmlStart;
374    RegionObj2->Extra.AmlLength = AmlLength;
375
376    /* Init the region from the operands */
377
378    ObjDesc->Region.SpaceId = RegionSpace;
379    ObjDesc->Region.Address = 0;
380    ObjDesc->Region.Length  = 0;
381    ObjDesc->Region.Node    = Node;
382
383    /* Install the new region object in the parent Node */
384
385    Status = AcpiNsAttachObject (Node, ObjDesc, (UINT8) ACPI_TYPE_REGION);
386
387
388Cleanup:
389
390    /* Remove local reference to the object */
391
392    AcpiUtRemoveReference (ObjDesc);
393    return_ACPI_STATUS (Status);
394}
395
396
397/*****************************************************************************
398 *
399 * FUNCTION:    AcpiExCreateTableRegion
400 *
401 * PARAMETERS:  WalkState           - Current state
402 *
403 * RETURN:      Status
404 *
405 * DESCRIPTION: Create a new DataTableRegion object
406 *
407 ****************************************************************************/
408
409ACPI_STATUS
410AcpiExCreateTableRegion (
411    ACPI_WALK_STATE         *WalkState)
412{
413    ACPI_STATUS             Status = AE_OK;
414
415
416    FUNCTION_TRACE ("ExCreateTableRegion");
417
418/*
419    ACPI_OPERAND_OBJECT     *ObjDesc;
420    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
421    if (!ObjDesc)
422    {
423        Status = AE_NO_MEMORY;
424        goto Cleanup;
425    }
426
427
428Cleanup:
429*/
430
431    return_ACPI_STATUS (Status);
432}
433
434
435/*****************************************************************************
436 *
437 * FUNCTION:    AcpiExCreateProcessor
438 *
439 * PARAMETERS:  Op              - Op containing the Processor definition and
440 *                                args
441 *              ProcessorNode   - Parent Node for the processor object
442 *
443 * RETURN:      Status
444 *
445 * DESCRIPTION: Create a new processor object and populate the fields
446 *
447 *              Processor (Name[0], CpuID[1], PblockAddr[2], PblockLength[3])
448 *
449 ****************************************************************************/
450
451ACPI_STATUS
452AcpiExCreateProcessor (
453    ACPI_WALK_STATE         *WalkState)
454{
455    ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
456    ACPI_OPERAND_OBJECT     *ObjDesc;
457    ACPI_STATUS             Status;
458
459
460    FUNCTION_TRACE_PTR ("ExCreateProcessor", WalkState);
461
462
463    /* Create the processor object */
464
465    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PROCESSOR);
466    if (!ObjDesc)
467    {
468        return_ACPI_STATUS (AE_NO_MEMORY);
469    }
470
471    /*
472     * Initialize the processor object from the operands
473     */
474    ObjDesc->Processor.ProcId  = (UINT8)           Operand[1]->Integer.Value;
475    ObjDesc->Processor.Address = (ACPI_IO_ADDRESS) Operand[2]->Integer.Value;
476    ObjDesc->Processor.Length  = (UINT8)           Operand[3]->Integer.Value;
477
478    /* Install the processor object in the parent Node */
479
480    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
481                    ObjDesc, (UINT8) ACPI_TYPE_PROCESSOR);
482
483
484    /* Remove local reference to the object */
485
486    AcpiUtRemoveReference (ObjDesc);
487    return_ACPI_STATUS (Status);
488}
489
490
491/*****************************************************************************
492 *
493 * FUNCTION:    AcpiExCreatePowerResource
494 *
495 * PARAMETERS:  Op              - Op containing the PowerResource definition
496 *                                and args
497 *              PowerNode       - Parent Node for the power object
498 *
499 * RETURN:      Status
500 *
501 * DESCRIPTION: Create a new PowerResource object and populate the fields
502 *
503 *              PowerResource (Name[0], SystemLevel[1], ResourceOrder[2])
504 *
505 ****************************************************************************/
506
507ACPI_STATUS
508AcpiExCreatePowerResource (
509    ACPI_WALK_STATE         *WalkState)
510{
511    ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
512    ACPI_STATUS             Status;
513    ACPI_OPERAND_OBJECT     *ObjDesc;
514
515
516    FUNCTION_TRACE_PTR ("ExCreatePowerResource", WalkState);
517
518
519    /* Create the power resource object */
520
521    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_POWER);
522    if (!ObjDesc)
523    {
524        return_ACPI_STATUS (AE_NO_MEMORY);
525    }
526
527    /* Initialize the power object from the operands */
528
529    ObjDesc->PowerResource.SystemLevel   = (UINT8)  Operand[1]->Integer.Value;
530    ObjDesc->PowerResource.ResourceOrder = (UINT16) Operand[2]->Integer.Value;
531
532    /* Install the  power resource object in the parent Node */
533
534    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
535                    ObjDesc, (UINT8) ACPI_TYPE_POWER);
536
537
538    /* Remove local reference to the object */
539
540    AcpiUtRemoveReference (ObjDesc);
541    return_ACPI_STATUS (Status);
542}
543
544
545/*****************************************************************************
546 *
547 * FUNCTION:    AcpiExCreateMethod
548 *
549 * PARAMETERS:  AmlStart        - First byte of the method's AML
550 *              AmlLength       - AML byte count for this method
551 *              MethodFlags     - AML method flag byte
552 *              Method          - Method Node
553 *
554 * RETURN:      Status
555 *
556 * DESCRIPTION: Create a new method object
557 *
558 ****************************************************************************/
559
560ACPI_STATUS
561AcpiExCreateMethod (
562    UINT8                   *AmlStart,
563    UINT32                  AmlLength,
564    ACPI_WALK_STATE         *WalkState)
565{
566    ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
567    ACPI_OPERAND_OBJECT     *ObjDesc;
568    ACPI_STATUS             Status;
569    UINT8                   MethodFlags;
570
571
572    FUNCTION_TRACE_PTR ("ExCreateMethod", WalkState);
573
574
575    /* Create a new method object */
576
577    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
578    if (!ObjDesc)
579    {
580       return_ACPI_STATUS (AE_NO_MEMORY);
581    }
582
583    /* Save the method's AML pointer and length  */
584
585    ObjDesc->Method.AmlStart  = AmlStart;
586    ObjDesc->Method.AmlLength = AmlLength;
587
588    /* disassemble the method flags */
589
590    MethodFlags = (UINT8) Operand[1]->Integer.Value;
591
592    ObjDesc->Method.MethodFlags = MethodFlags;
593    ObjDesc->Method.ParamCount  = (UINT8) (MethodFlags & METHOD_FLAGS_ARG_COUNT);
594
595    /*
596     * Get the concurrency count.  If required, a semaphore will be
597     * created for this method when it is parsed.
598     */
599    if (MethodFlags & METHOD_FLAGS_SERIALIZED)
600    {
601        /*
602         * ACPI 1.0: Concurrency = 1
603         * ACPI 2.0: Concurrency = (SyncLevel (in method declaration) + 1)
604         */
605        ObjDesc->Method.Concurrency = (UINT8)
606                        (((MethodFlags & METHOD_FLAGS_SYNCH_LEVEL) >> 4) + 1);
607    }
608
609    else
610    {
611        ObjDesc->Method.Concurrency = INFINITE_CONCURRENCY;
612    }
613
614    /* Attach the new object to the method Node */
615
616    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
617                    ObjDesc, (UINT8) ACPI_TYPE_METHOD);
618
619    /* Remove local reference to the object */
620
621    AcpiUtRemoveReference (ObjDesc);
622
623    /* Remove a reference to the operand */
624
625    AcpiUtRemoveReference (Operand[1]);
626    return_ACPI_STATUS (Status);
627}
628
629
630