exprep.c revision 71867
1
2/******************************************************************************
3 *
4 * Module Name: amprep - ACPI AML (p-code) execution - field prep utilities
5 *              $Revision: 73 $
6 *
7 *****************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
13 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
14 * All rights reserved.
15 *
16 * 2. License
17 *
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights.  You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
21 * property rights.
22 *
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
29 *
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code.  No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
38 *
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
41 *
42 * 3. Conditions
43 *
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision.  In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change.  Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee.  Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
55 *
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution.  In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
66 * make.
67 *
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
72 * distribution.
73 *
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
76 *
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
81 *
82 * 4. Disclaimer and Export Compliance
83 *
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
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 __AMPREP_C__
119
120#include "acpi.h"
121#include "acinterp.h"
122#include "amlcode.h"
123#include "acnamesp.h"
124#include "acparser.h"
125
126
127#define _COMPONENT          INTERPRETER
128        MODULE_NAME         ("amprep")
129
130
131/*******************************************************************************
132 *
133 * FUNCTION:    AcpiAmlDecodeFieldAccessType
134 *
135 * PARAMETERS:  Access          - Encoded field access bits
136 *
137 * RETURN:      Field granularity (8, 16, or 32)
138 *
139 * DESCRIPTION: Decode the AccessType bits of a field definition.
140 *
141 ******************************************************************************/
142
143static UINT32
144AcpiAmlDecodeFieldAccessType (
145    UINT32                  Access,
146    UINT16                  Length)
147{
148
149    switch (Access)
150    {
151    case ACCESS_ANY_ACC:
152        if (Length <= 8)
153        {
154            return (8);
155        }
156        else if (Length <= 16)
157        {
158            return (16);
159        }
160        else if (Length <= 32)
161        {
162            return (32);
163        }
164        else
165        {
166            return (8);
167        }
168        break;
169
170    case ACCESS_BYTE_ACC:
171        return (8);
172        break;
173
174    case ACCESS_WORD_ACC:
175        return (16);
176        break;
177
178    case ACCESS_DWORD_ACC:
179        return (32);
180        break;
181
182    default:
183        /* Invalid field access type */
184
185        DEBUG_PRINT (ACPI_ERROR,
186            ("AmlDecodeFieldAccessType: Unknown field access type %x\n",
187            Access));
188        return (0);
189    }
190}
191
192
193/*******************************************************************************
194 *
195 * FUNCTION:    AcpiAmlPrepCommonFieldObjec
196 *
197 * PARAMETERS:  ObjDesc             - The field object
198 *              FieldFlags          - Access, LockRule, or UpdateRule.
199 *                                    The format of a FieldFlag is described
200 *                                    in the ACPI specification
201 *              FieldPosition       - Field position
202 *              FieldLength         - Field length
203 *
204 * RETURN:      Status
205 *
206 * DESCRIPTION: Initialize the areas of the field object that are common
207 *              to the various types of fields.
208 *
209 ******************************************************************************/
210
211static ACPI_STATUS
212AcpiAmlPrepCommonFieldObject (
213    ACPI_OPERAND_OBJECT     *ObjDesc,
214    UINT8                   FieldFlags,
215    UINT8                   FieldAttribute,
216    UINT32                  FieldPosition,
217    UINT32                  FieldLength)
218{
219    UINT32                  Granularity;
220
221
222    FUNCTION_TRACE ("AmlPrepCommonFieldObject");
223
224
225    /*
226     * Note: the structure being initialized is the
227     * ACPI_COMMON_FIELD_INFO;  Therefore, we can just use the Field union to
228     * access this common area.  No structure fields outside of the common area
229     * are initialized by this procedure.
230     */
231
232    /* Decode the FieldFlags */
233
234    ObjDesc->Field.Access           = (UINT8) ((FieldFlags & ACCESS_TYPE_MASK)
235                                                    >> ACCESS_TYPE_SHIFT);
236    ObjDesc->Field.LockRule         = (UINT8) ((FieldFlags & LOCK_RULE_MASK)
237                                                    >> LOCK_RULE_SHIFT);
238    ObjDesc->Field.UpdateRule       = (UINT8) ((FieldFlags & UPDATE_RULE_MASK)
239                                                    >> UPDATE_RULE_SHIFT);
240
241    /* Other misc fields */
242
243    ObjDesc->Field.Length           = (UINT16) FieldLength;
244    ObjDesc->Field.AccessAttribute  = FieldAttribute;
245
246    /* Decode the access type so we can compute offsets */
247
248    Granularity = AcpiAmlDecodeFieldAccessType (ObjDesc->Field.Access, ObjDesc->Field.Length);
249    if (!Granularity)
250    {
251        return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
252    }
253
254    /* Access granularity based fields */
255
256    ObjDesc->Field.Granularity      = (UINT8) Granularity;
257    ObjDesc->Field.BitOffset        = (UINT8) (FieldPosition % Granularity);
258    ObjDesc->Field.Offset           = (UINT32) FieldPosition / Granularity;
259
260
261    return_ACPI_STATUS (AE_OK);
262}
263
264
265/*******************************************************************************
266 *
267 * FUNCTION:    AcpiAmlPrepDefFieldValue
268 *
269 * PARAMETERS:  Node            - Owning Node
270 *              Region              - Region in which field is being defined
271 *              FieldFlags          - Access, LockRule, or UpdateRule.
272 *                                    The format of a FieldFlag is described
273 *                                    in the ACPI specification
274 *              FieldPosition       - Field position
275 *              FieldLength         - Field length
276 *
277 * RETURN:      Status
278 *
279 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT  of type DefField and
280 *              connect it to the parent Node.
281 *
282 ******************************************************************************/
283
284ACPI_STATUS
285AcpiAmlPrepDefFieldValue (
286    ACPI_NAMESPACE_NODE     *Node,
287    ACPI_HANDLE             Region,
288    UINT8                   FieldFlags,
289    UINT8                   FieldAttribute,
290    UINT32                  FieldPosition,
291    UINT32                  FieldLength)
292{
293    ACPI_OPERAND_OBJECT     *ObjDesc;
294    UINT32                  Type;
295    ACPI_STATUS             Status;
296
297
298    FUNCTION_TRACE ("AmlPrepDefFieldValue");
299
300
301    /* Parameter validation */
302
303    if (!Region)
304    {
305        DEBUG_PRINT (ACPI_ERROR, ("AmlPrepDefFieldValue: null Region\n"));
306        return_ACPI_STATUS (AE_AML_NO_OPERAND);
307    }
308
309    Type = AcpiNsGetType (Region);
310    if (Type != ACPI_TYPE_REGION)
311    {
312        DEBUG_PRINT (ACPI_ERROR,
313            ("AmlPrepDefFieldValue: Needed Region, found type %X %s\n",
314            Type, AcpiCmGetTypeName (Type)));
315        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
316    }
317
318    /* Allocate a new object */
319
320    ObjDesc = AcpiCmCreateInternalObject (INTERNAL_TYPE_DEF_FIELD);
321    if (!ObjDesc)
322    {
323        return_ACPI_STATUS (AE_NO_MEMORY);
324    }
325
326
327    /* ObjDesc and Region valid */
328
329    DUMP_OPERANDS ((ACPI_OPERAND_OBJECT  **) &Node, IMODE_EXECUTE,
330                    "AmlPrepDefFieldValue", 1, "case DefField");
331    DUMP_OPERANDS ((ACPI_OPERAND_OBJECT  **) &Region, IMODE_EXECUTE,
332                    "AmlPrepDefFieldValue", 1, "case DefField");
333
334    /* Initialize areas of the object that are common to all fields */
335
336    Status = AcpiAmlPrepCommonFieldObject (ObjDesc, FieldFlags, FieldAttribute,
337                                            FieldPosition, FieldLength);
338    if (ACPI_FAILURE (Status))
339    {
340        return_ACPI_STATUS (Status);
341    }
342
343    /* Initialize areas of the object that are specific to this field type */
344
345    ObjDesc->Field.Container = AcpiNsGetAttachedObject (Region);
346
347    /* An additional reference for the container */
348
349    AcpiCmAddReference (ObjDesc->Field.Container);
350
351
352    /* Debug info */
353
354    DEBUG_PRINT (ACPI_INFO,
355        ("AmlPrepDefFieldValue: bitoff=%X off=%X gran=%X\n",
356        ObjDesc->Field.BitOffset, ObjDesc->Field.Offset,
357        ObjDesc->Field.Granularity));
358
359    DEBUG_PRINT (ACPI_INFO,
360        ("AmlPrepDefFieldValue: set NamedObj %p (%4.4s) val = %p\n",
361        Node, &(Node->Name), ObjDesc));
362
363    DUMP_STACK_ENTRY (ObjDesc);
364    DUMP_ENTRY (Region, ACPI_INFO);
365    DEBUG_PRINT (ACPI_INFO, ("\t%p \n", ObjDesc->Field.Container));
366    if (ObjDesc->Field.Container)
367    {
368        DUMP_STACK_ENTRY (ObjDesc->Field.Container);
369    }
370    DEBUG_PRINT (ACPI_INFO,
371        ("============================================================\n"));
372
373    /*
374     * Store the constructed descriptor (ObjDesc) into the NamedObj whose
375     * handle is on TOS, preserving the current type of that NamedObj.
376     */
377    Status = AcpiNsAttachObject ((ACPI_HANDLE) Node, ObjDesc,
378                    (UINT8) AcpiNsGetType ((ACPI_HANDLE) Node));
379
380    return_ACPI_STATUS (Status);
381}
382
383
384/*******************************************************************************
385 *
386 * FUNCTION:    AcpiAmlPrepBankFieldValue
387 *
388 * PARAMETERS:  Node            - Owning Node
389 *              Region              - Region in which field is being defined
390 *              BankReg             - Bank selection register
391 *              BankVal             - Value to store in selection register
392 *              FieldFlags          - Access, LockRule, or UpdateRule
393 *              FieldPosition       - Field position
394 *              FieldLength         - Field length
395 *
396 * RETURN:      Status
397 *
398 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT  of type BankField and
399 *              connect it to the parent Node.
400 *
401 ******************************************************************************/
402
403ACPI_STATUS
404AcpiAmlPrepBankFieldValue (
405    ACPI_NAMESPACE_NODE     *Node,
406    ACPI_HANDLE             Region,
407    ACPI_HANDLE             BankReg,
408    UINT32                  BankVal,
409    UINT8                   FieldFlags,
410    UINT8                   FieldAttribute,
411    UINT32                  FieldPosition,
412    UINT32                  FieldLength)
413{
414    ACPI_OPERAND_OBJECT     *ObjDesc;
415    UINT32                  Type;
416    ACPI_STATUS             Status;
417
418
419    FUNCTION_TRACE ("AmlPrepBankFieldValue");
420
421
422    /* Parameter validation */
423
424    if (!Region)
425    {
426        DEBUG_PRINT (ACPI_ERROR, ("AmlPrepBankFieldValue: null Region\n"));
427        return_ACPI_STATUS (AE_AML_NO_OPERAND);
428    }
429
430    Type = AcpiNsGetType (Region);
431    if (Type != ACPI_TYPE_REGION)
432    {
433        DEBUG_PRINT (ACPI_ERROR,
434            ("AmlPrepBankFieldValue: Needed Region, found type %X %s\n",
435            Type, AcpiCmGetTypeName (Type)));
436        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
437    }
438
439    /* Allocate a new object */
440
441    ObjDesc = AcpiCmCreateInternalObject (INTERNAL_TYPE_BANK_FIELD);
442    if (!ObjDesc)
443    {
444        return_ACPI_STATUS (AE_NO_MEMORY);
445    }
446
447    /*  ObjDesc and Region valid    */
448
449    DUMP_OPERANDS ((ACPI_OPERAND_OBJECT  **) &Node, IMODE_EXECUTE,
450                    "AmlPrepBankFieldValue", 1, "case BankField");
451    DUMP_OPERANDS ((ACPI_OPERAND_OBJECT  **) &Region, IMODE_EXECUTE,
452                    "AmlPrepBankFieldValue", 1, "case BankField");
453
454    /* Initialize areas of the object that are common to all fields */
455
456    Status = AcpiAmlPrepCommonFieldObject (ObjDesc, FieldFlags, FieldAttribute,
457                                            FieldPosition, FieldLength);
458    if (ACPI_FAILURE (Status))
459    {
460        return_ACPI_STATUS (Status);
461    }
462
463    /* Initialize areas of the object that are specific to this field type */
464
465    ObjDesc->BankField.Value        = BankVal;
466    ObjDesc->BankField.Container    = AcpiNsGetAttachedObject (Region);
467    ObjDesc->BankField.BankSelect   = AcpiNsGetAttachedObject (BankReg);
468
469    /* An additional reference for the container and bank select */
470    /* TBD: [Restructure] is "BankSelect" ever a real internal object?? */
471
472    AcpiCmAddReference (ObjDesc->BankField.Container);
473    AcpiCmAddReference (ObjDesc->BankField.BankSelect);
474
475    /* Debug info */
476
477    DEBUG_PRINT (ACPI_INFO,
478        ("AmlPrepBankFieldValue: bitoff=%X off=%X gran=%X\n",
479        ObjDesc->BankField.BitOffset, ObjDesc->BankField.Offset,
480        ObjDesc->Field.Granularity));
481
482    DEBUG_PRINT (ACPI_INFO,
483        ("AmlPrepBankFieldValue: set NamedObj %p (%4.4s) val = %p\n",
484        Node, &(Node->Name), ObjDesc));
485
486    DUMP_STACK_ENTRY (ObjDesc);
487    DUMP_ENTRY (Region, ACPI_INFO);
488    DUMP_ENTRY (BankReg, ACPI_INFO);
489    DEBUG_PRINT (ACPI_INFO,
490        ("============================================================\n"));
491
492    /*
493     * Store the constructed descriptor (ObjDesc) into the NamedObj whose
494     * handle is on TOS, preserving the current type of that NamedObj.
495     */
496    Status = AcpiNsAttachObject ((ACPI_HANDLE) Node, ObjDesc,
497                (UINT8) AcpiNsGetType ((ACPI_HANDLE) Node));
498
499    return_ACPI_STATUS (Status);
500}
501
502
503/*******************************************************************************
504 *
505 * FUNCTION:    AcpiAmlPrepIndexFieldValue
506 *
507 * PARAMETERS:  Node            - Owning Node
508 *              IndexReg            - Index register
509 *              DataReg             - Data register
510 *              FieldFlags          - Access, LockRule, or UpdateRule
511 *              FieldPosition       - Field position
512 *              FieldLength         - Field length
513 *
514 * RETURN:      Status
515 *
516 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT  of type IndexField and
517 *              connect it to the parent Node.
518 *
519 ******************************************************************************/
520
521ACPI_STATUS
522AcpiAmlPrepIndexFieldValue (
523    ACPI_NAMESPACE_NODE     *Node,
524    ACPI_HANDLE             IndexReg,
525    ACPI_HANDLE             DataReg,
526    UINT8                   FieldFlags,
527    UINT8                   FieldAttribute,
528    UINT32                  FieldPosition,
529    UINT32                  FieldLength)
530{
531    ACPI_OPERAND_OBJECT     *ObjDesc;
532    ACPI_STATUS             Status;
533
534
535    FUNCTION_TRACE ("AmlPrepIndexFieldValue");
536
537
538    /* Parameter validation */
539
540    if (!IndexReg || !DataReg)
541    {
542        DEBUG_PRINT (ACPI_ERROR, ("AmlPrepIndexFieldValue: null handle\n"));
543        return_ACPI_STATUS (AE_AML_NO_OPERAND);
544    }
545
546    /* Allocate a new object descriptor */
547
548    ObjDesc = AcpiCmCreateInternalObject (INTERNAL_TYPE_INDEX_FIELD);
549    if (!ObjDesc)
550    {
551        return_ACPI_STATUS (AE_NO_MEMORY);
552    }
553
554    /* Initialize areas of the object that are common to all fields */
555
556    Status = AcpiAmlPrepCommonFieldObject (ObjDesc, FieldFlags, FieldAttribute,
557                                            FieldPosition, FieldLength);
558    if (ACPI_FAILURE (Status))
559    {
560        return_ACPI_STATUS (Status);
561    }
562
563    /* Initialize areas of the object that are specific to this field type */
564
565    ObjDesc->IndexField.Value       = (UINT32) (FieldPosition /
566                                                ObjDesc->Field.Granularity);
567    ObjDesc->IndexField.Index       = IndexReg;
568    ObjDesc->IndexField.Data        = DataReg;
569
570    /* Debug info */
571
572    DEBUG_PRINT (ACPI_INFO,
573        ("AmlPrepIndexFieldValue: bitoff=%X off=%X gran=%X\n",
574        ObjDesc->IndexField.BitOffset, ObjDesc->IndexField.Offset,
575        ObjDesc->Field.Granularity));
576
577    DEBUG_PRINT (ACPI_INFO,
578        ("AmlPrepIndexFieldValue: set NamedObj %p (%4.4s) val = %p\n",
579        Node, &(Node->Name), ObjDesc));
580
581    DUMP_STACK_ENTRY (ObjDesc);
582    DUMP_ENTRY (IndexReg, ACPI_INFO);
583    DUMP_ENTRY (DataReg, ACPI_INFO);
584    DEBUG_PRINT (ACPI_INFO,
585        ("============================================================\n"));
586
587    /*
588     * Store the constructed descriptor (ObjDesc) into the NamedObj whose
589     * handle is on TOS, preserving the current type of that NamedObj.
590     */
591    Status = AcpiNsAttachObject ((ACPI_HANDLE) Node, ObjDesc,
592                (UINT8) AcpiNsGetType ((ACPI_HANDLE) Node));
593
594    return_ACPI_STATUS (Status);
595}
596
597