excreate.c revision 85756
1/******************************************************************************
2 *
3 * Module Name: excreate - Named object creation
4 *              $Revision: 71 $
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 *
136 * FUNCTION:    AcpiExCreateAlias
137 *
138 * PARAMETERS:  WalkState            - Current state, contains List of
139 *                                      operands for the opcode
140 *
141 * RETURN:      Status
142 *
143 * DESCRIPTION: Create a new named alias
144 *
145 ****************************************************************************/
146
147ACPI_STATUS
148AcpiExCreateAlias (
149    ACPI_WALK_STATE         *WalkState)
150{
151    ACPI_NAMESPACE_NODE     *SourceNode;
152    ACPI_STATUS             Status;
153
154
155    FUNCTION_TRACE ("ExCreateAlias");
156
157
158    /* Get the source/alias operands (both namespace nodes) */
159
160    SourceNode = (ACPI_NAMESPACE_NODE *) WalkState->Operands[1];
161
162
163    /* Attach the original source object to the new Alias Node */
164
165    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) WalkState->Operands[0],
166                                    SourceNode->Object,
167                                    SourceNode->Type);
168
169    /*
170     * The new alias assumes the type of the source, but it points
171     * to the same object.  The reference count of the object has an
172     * additional reference to prevent deletion out from under either the
173     * source or the alias Node
174     */
175
176    /* Since both operands are Nodes, we don't need to delete them */
177
178    return_ACPI_STATUS (Status);
179}
180
181
182/*****************************************************************************
183 *
184 * FUNCTION:    AcpiExCreateEvent
185 *
186 * PARAMETERS:  WalkState           - Current state
187 *
188 * RETURN:      Status
189 *
190 * DESCRIPTION: Create a new event object
191 *
192 ****************************************************************************/
193
194ACPI_STATUS
195AcpiExCreateEvent (
196    ACPI_WALK_STATE         *WalkState)
197{
198    ACPI_STATUS             Status;
199    ACPI_OPERAND_OBJECT     *ObjDesc;
200
201
202    FUNCTION_TRACE ("ExCreateEvent");
203
204
205    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_EVENT);
206    if (!ObjDesc)
207    {
208        Status = AE_NO_MEMORY;
209        goto Cleanup;
210    }
211
212    /* Create the actual OS semaphore */
213
214    /* TBD: [Investigate] should be created with 0 or 1 units? */
215
216    Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 1,
217                                    &ObjDesc->Event.Semaphore);
218    if (ACPI_FAILURE (Status))
219    {
220        goto Cleanup;
221    }
222
223    /* Attach object to the Node */
224
225    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) WalkState->Operands[0],
226                                    ObjDesc, (UINT8) ACPI_TYPE_EVENT);
227
228Cleanup:
229    /*
230     * Remove local reference to the object (on error, will cause deletion
231     * of both object and semaphore if present.)
232     */
233    AcpiUtRemoveReference (ObjDesc);
234    return_ACPI_STATUS (Status);
235}
236
237
238/*****************************************************************************
239 *
240 * FUNCTION:    AcpiExCreateMutex
241 *
242 * PARAMETERS:  WalkState           - Current state
243 *
244 * RETURN:      Status
245 *
246 * DESCRIPTION: Create a new mutex object
247 *
248 *              Mutex (Name[0], SyncLevel[1])
249 *
250 ****************************************************************************/
251
252ACPI_STATUS
253AcpiExCreateMutex (
254    ACPI_WALK_STATE         *WalkState)
255{
256    ACPI_STATUS             Status = AE_OK;
257    ACPI_OPERAND_OBJECT     *ObjDesc;
258
259
260    FUNCTION_TRACE_PTR ("ExCreateMutex", WALK_OPERANDS);
261
262
263    /* Create the new mutex object */
264
265    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX);
266    if (!ObjDesc)
267    {
268        Status = AE_NO_MEMORY;
269        goto Cleanup;
270    }
271
272    /* Create the actual OS semaphore */
273
274    Status = AcpiOsCreateSemaphore (1, 1, &ObjDesc->Mutex.Semaphore);
275    if (ACPI_FAILURE (Status))
276    {
277        goto Cleanup;
278    }
279
280    /* Init object and attach to NS node */
281
282    ObjDesc->Mutex.SyncLevel = (UINT8) WalkState->Operands[1]->Integer.Value;
283
284    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) WalkState->Operands[0],
285                                ObjDesc, (UINT8) ACPI_TYPE_MUTEX);
286
287
288Cleanup:
289    /*
290     * Remove local reference to the object (on error, will cause deletion
291     * of both object and semaphore if present.)
292     */
293    AcpiUtRemoveReference (ObjDesc);
294    return_ACPI_STATUS (Status);
295}
296
297
298/*****************************************************************************
299 *
300 * FUNCTION:    AcpiExCreateRegion
301 *
302 * PARAMETERS:  AmlStart            - Pointer to the region declaration AML
303 *              AmlLength           - Max length of the declaration AML
304 *              Operands            - List of operands for the opcode
305 *              WalkState           - Current state
306 *
307 * RETURN:      Status
308 *
309 * DESCRIPTION: Create a new operation region object
310 *
311 ****************************************************************************/
312
313ACPI_STATUS
314AcpiExCreateRegion (
315    UINT8                   *AmlStart,
316    UINT32                  AmlLength,
317    UINT8                   RegionSpace,
318    ACPI_WALK_STATE         *WalkState)
319{
320    ACPI_STATUS             Status;
321    ACPI_OPERAND_OBJECT     *ObjDesc;
322    ACPI_NAMESPACE_NODE     *Node;
323
324
325    FUNCTION_TRACE ("ExCreateRegion");
326
327
328    /* Get the Node from the object stack  */
329
330    Node = (ACPI_NAMESPACE_NODE *) WalkState->Operands[0];
331
332    /*
333     * If the region object is already attached to this node,
334     * just return
335     */
336    if (Node->Object)
337    {
338        return_ACPI_STATUS (AE_OK);
339    }
340
341    /*
342     * Space ID must be one of the predefined IDs, or in the user-defined
343     * range
344     */
345    if ((RegionSpace >= NUM_REGION_TYPES) &&
346        (RegionSpace < USER_REGION_BEGIN))
347    {
348        REPORT_ERROR (("Invalid AddressSpace type %X\n", RegionSpace));
349        return_ACPI_STATUS (AE_AML_INVALID_SPACE_ID);
350    }
351
352    ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (%X)\n",
353                    AcpiUtGetRegionName (RegionSpace), RegionSpace));
354
355
356    /* Create the region descriptor */
357
358    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
359    if (!ObjDesc)
360    {
361        Status = AE_NO_MEMORY;
362        goto Cleanup;
363    }
364
365    /* Allocate a method object for this region */
366
367    ObjDesc->Region.Extra =  AcpiUtCreateInternalObject (
368                                        INTERNAL_TYPE_EXTRA);
369    if (!ObjDesc->Region.Extra)
370    {
371        Status = AE_NO_MEMORY;
372        goto Cleanup;
373    }
374
375    /*
376     * Remember location in AML stream of address & length
377     * operands since they need to be evaluated at run time.
378     */
379    ObjDesc->Region.Extra->Extra.AmlStart  = AmlStart;
380    ObjDesc->Region.Extra->Extra.AmlLength = AmlLength;
381
382    /* Init the region from the operands */
383
384    ObjDesc->Region.SpaceId = RegionSpace;
385    ObjDesc->Region.Address = 0;
386    ObjDesc->Region.Length  = 0;
387    ObjDesc->Region.Node    = Node;
388
389    /* Install the new region object in the parent Node */
390
391    Status = AcpiNsAttachObject (Node, ObjDesc,
392                                (UINT8) ACPI_TYPE_REGION);
393    if (ACPI_FAILURE (Status))
394    {
395        goto Cleanup;
396    }
397
398    /*
399     * If we have a valid region, initialize it
400     * Namespace is NOT locked at this point.
401     */
402    Status = AcpiEvInitializeRegion (ObjDesc, FALSE);
403    if (ACPI_FAILURE (Status))
404    {
405        /*
406         *  If AE_NOT_EXIST is returned, it is not fatal
407         *  because many regions get created before a handler
408         *  is installed for said region.
409         */
410        if (AE_NOT_EXIST == Status)
411        {
412            Status = AE_OK;
413        }
414    }
415
416Cleanup:
417
418    /* Remove local reference to the object */
419
420    AcpiUtRemoveReference (ObjDesc);
421
422    return_ACPI_STATUS (Status);
423}
424
425
426/*****************************************************************************
427 *
428 * FUNCTION:    AcpiExCreateTableRegion
429 *
430 * PARAMETERS:  WalkState           - Current state
431 *
432 * RETURN:      Status
433 *
434 * DESCRIPTION: Create a new DataTableRegion object
435 *
436 ****************************************************************************/
437
438ACPI_STATUS
439AcpiExCreateTableRegion (
440    ACPI_WALK_STATE         *WalkState)
441{
442    ACPI_STATUS             Status = AE_OK;
443
444
445    FUNCTION_TRACE ("ExCreateTableRegion");
446
447/*
448    ACPI_OPERAND_OBJECT     *ObjDesc;
449    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
450    if (!ObjDesc)
451    {
452        Status = AE_NO_MEMORY;
453        goto Cleanup;
454    }
455
456
457Cleanup:
458*/
459
460    return_ACPI_STATUS (Status);
461}
462
463
464/*****************************************************************************
465 *
466 * FUNCTION:    AcpiExCreateProcessor
467 *
468 * PARAMETERS:  Op              - Op containing the Processor definition and
469 *                                args
470 *              ProcessorNode   - Parent Node for the processor object
471 *
472 * RETURN:      Status
473 *
474 * DESCRIPTION: Create a new processor object and populate the fields
475 *
476 *              Processor (Name[0], CpuID[1], PblockAddr[2], PblockLength[3])
477 *
478 ****************************************************************************/
479
480ACPI_STATUS
481AcpiExCreateProcessor (
482    ACPI_WALK_STATE         *WalkState)
483{
484    ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
485    ACPI_OPERAND_OBJECT     *ObjDesc;
486    ACPI_STATUS             Status;
487
488
489    FUNCTION_TRACE_PTR ("ExCreateProcessor", WalkState);
490
491
492    /* Create the processor object */
493
494    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PROCESSOR);
495    if (!ObjDesc)
496    {
497        return_ACPI_STATUS (AE_NO_MEMORY);
498    }
499
500    /*
501     * Initialize the processor object from the operands
502     */
503    ObjDesc->Processor.ProcId  = (UINT8)           Operand[1]->Integer.Value;
504    ObjDesc->Processor.Address = (ACPI_IO_ADDRESS) Operand[2]->Integer.Value;
505    ObjDesc->Processor.Length  = (UINT8)           Operand[3]->Integer.Value;
506
507    /* Install the processor object in the parent Node */
508
509    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
510                    ObjDesc, (UINT8) ACPI_TYPE_PROCESSOR);
511
512
513    /* Remove local reference to the object */
514
515    AcpiUtRemoveReference (ObjDesc);
516    return_ACPI_STATUS (Status);
517}
518
519
520/*****************************************************************************
521 *
522 * FUNCTION:    AcpiExCreatePowerResource
523 *
524 * PARAMETERS:  Op              - Op containing the PowerResource definition
525 *                                and args
526 *              PowerNode       - Parent Node for the power object
527 *
528 * RETURN:      Status
529 *
530 * DESCRIPTION: Create a new PowerResource object and populate the fields
531 *
532 *              PowerResource (Name[0], SystemLevel[1], ResourceOrder[2])
533 *
534 ****************************************************************************/
535
536ACPI_STATUS
537AcpiExCreatePowerResource (
538    ACPI_WALK_STATE         *WalkState)
539{
540    ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
541    ACPI_STATUS             Status;
542    ACPI_OPERAND_OBJECT     *ObjDesc;
543
544
545    FUNCTION_TRACE_PTR ("ExCreatePowerResource", WalkState);
546
547
548    /* Create the power resource object */
549
550    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_POWER);
551    if (!ObjDesc)
552    {
553        return_ACPI_STATUS (AE_NO_MEMORY);
554    }
555
556    /* Initialize the power object from the operands */
557
558    ObjDesc->PowerResource.SystemLevel   = (UINT8)  Operand[1]->Integer.Value;
559    ObjDesc->PowerResource.ResourceOrder = (UINT16) Operand[2]->Integer.Value;
560
561    /* Install the  power resource object in the parent Node */
562
563    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
564                    ObjDesc, (UINT8) ACPI_TYPE_POWER);
565
566
567    /* Remove local reference to the object */
568
569    AcpiUtRemoveReference (ObjDesc);
570    return_ACPI_STATUS (Status);
571}
572
573
574/*****************************************************************************
575 *
576 * FUNCTION:    AcpiExCreateMethod
577 *
578 * PARAMETERS:  AmlStart        - First byte of the method's AML
579 *              AmlLength       - AML byte count for this method
580 *              MethodFlags     - AML method flag byte
581 *              Method          - Method Node
582 *
583 * RETURN:      Status
584 *
585 * DESCRIPTION: Create a new method object
586 *
587 ****************************************************************************/
588
589ACPI_STATUS
590AcpiExCreateMethod (
591    UINT8                   *AmlStart,
592    UINT32                  AmlLength,
593    ACPI_WALK_STATE         *WalkState)
594{
595    ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
596    ACPI_OPERAND_OBJECT     *ObjDesc;
597    ACPI_STATUS             Status;
598    UINT8                   MethodFlags;
599
600
601    FUNCTION_TRACE_PTR ("ExCreateMethod", WalkState);
602
603
604    /* Create a new method object */
605
606    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
607    if (!ObjDesc)
608    {
609       return_ACPI_STATUS (AE_NO_MEMORY);
610    }
611
612    /* Save the method's AML pointer and length  */
613
614    ObjDesc->Method.AmlStart  = AmlStart;
615    ObjDesc->Method.AmlLength = AmlLength;
616
617    /* disassemble the method flags */
618
619    MethodFlags = (UINT8) Operand[1]->Integer.Value;
620
621    ObjDesc->Method.MethodFlags = MethodFlags;
622    ObjDesc->Method.ParamCount  = (UINT8) (MethodFlags & METHOD_FLAGS_ARG_COUNT);
623
624    /*
625     * Get the concurrency count.  If required, a semaphore will be
626     * created for this method when it is parsed.
627     */
628    if (MethodFlags & METHOD_FLAGS_SERIALIZED)
629    {
630        /*
631         * ACPI 1.0: Concurrency = 1
632         * ACPI 2.0: Concurrency = (SyncLevel (in method declaration) + 1)
633         */
634        ObjDesc->Method.Concurrency = (UINT8)
635                        (((MethodFlags & METHOD_FLAGS_SYNCH_LEVEL) >> 4) + 1);
636    }
637
638    else
639    {
640        ObjDesc->Method.Concurrency = INFINITE_CONCURRENCY;
641    }
642
643    /* Attach the new object to the method Node */
644
645    Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],
646                    ObjDesc, (UINT8) ACPI_TYPE_METHOD);
647
648    /* Remove local reference to the object */
649
650    AcpiUtRemoveReference (ObjDesc);
651
652    /* Remove a reference to the operand */
653
654    AcpiUtRemoveReference (Operand[1]);
655    return_ACPI_STATUS (Status);
656}
657
658
659