exprep.c revision 69450
1
2/******************************************************************************
3 *
4 * Module Name: amprep - ACPI AML (p-code) execution - field prep utilities
5 *              $Revision: 68 $
6 *
7 *****************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
13 * Some or all of this work - Copyright (c) 1999, Intel Corp.  All rights
14 * 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{
147
148    switch (Access)
149    {
150    case ACCESS_ANY_ACC:
151        return (8);
152        break;
153
154    case ACCESS_BYTE_ACC:
155        return (8);
156        break;
157
158    case ACCESS_WORD_ACC:
159        return (16);
160        break;
161
162    case ACCESS_DWORD_ACC:
163        return (32);
164        break;
165
166    default:
167        /* Invalid field access type */
168
169        DEBUG_PRINT (ACPI_ERROR,
170            ("AmlDecodeFieldAccessType: Unknown field access type %x\n",
171            Access));
172        return (0);
173    }
174}
175
176
177/*******************************************************************************
178 *
179 * FUNCTION:    AcpiAmlPrepCommonFieldObjec
180 *
181 * PARAMETERS:  ObjDesc             - The field object
182 *              FieldFlags          - Access, LockRule, or UpdateRule.
183 *                                    The format of a FieldFlag is described
184 *                                    in the ACPI specification
185 *              FieldPosition       - Field position
186 *              FieldLength         - Field length
187 *
188 * RETURN:      Status
189 *
190 * DESCRIPTION: Initialize the areas of the field object that are common
191 *              to the various types of fields.
192 *
193 ******************************************************************************/
194
195static ACPI_STATUS
196AcpiAmlPrepCommonFieldObject (
197    ACPI_OPERAND_OBJECT     *ObjDesc,
198    UINT8                   FieldFlags,
199    UINT8                   FieldAttribute,
200    UINT32                  FieldPosition,
201    UINT32                  FieldLength)
202{
203    UINT32                  Granularity;
204
205
206    FUNCTION_TRACE ("AmlPrepCommonFieldObject");
207
208
209    /*
210     * Note: the structure being initialized is the
211     * ACPI_COMMON_FIELD_INFO;  Therefore, we can just use the Field union to
212     * access this common area.  No structure fields outside of the common area
213     * are initialized by this procedure.
214     */
215
216    /* Decode the FieldFlags */
217
218    ObjDesc->Field.Access           = (UINT8) ((FieldFlags & ACCESS_TYPE_MASK)
219                                                    >> ACCESS_TYPE_SHIFT);
220    ObjDesc->Field.LockRule         = (UINT8) ((FieldFlags & LOCK_RULE_MASK)
221                                                    >> LOCK_RULE_SHIFT);
222    ObjDesc->Field.UpdateRule       = (UINT8) ((FieldFlags & UPDATE_RULE_MASK)
223                                                    >> UPDATE_RULE_SHIFT);
224
225    /* Other misc fields */
226
227    ObjDesc->Field.Length           = (UINT16) FieldLength;
228    ObjDesc->Field.AccessAttribute  = FieldAttribute;
229
230    /* Decode the access type so we can compute offsets */
231
232    Granularity = AcpiAmlDecodeFieldAccessType (ObjDesc->Field.Access);
233    if (!Granularity)
234    {
235        return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
236    }
237
238    /* Access granularity based fields */
239
240    ObjDesc->Field.Granularity      = (UINT8) Granularity;
241    ObjDesc->Field.BitOffset        = (UINT8) (FieldPosition % Granularity);
242    ObjDesc->Field.Offset           = (UINT32) FieldPosition / Granularity;
243
244
245    return_ACPI_STATUS (AE_OK);
246}
247
248
249/*******************************************************************************
250 *
251 * FUNCTION:    AcpiAmlPrepDefFieldValue
252 *
253 * PARAMETERS:  Node            - Owning Node
254 *              Region              - Region in which field is being defined
255 *              FieldFlags          - Access, LockRule, or UpdateRule.
256 *                                    The format of a FieldFlag is described
257 *                                    in the ACPI specification
258 *              FieldPosition       - Field position
259 *              FieldLength         - Field length
260 *
261 * RETURN:      Status
262 *
263 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT  of type DefField and
264 *              connect it to the parent Node.
265 *
266 ******************************************************************************/
267
268ACPI_STATUS
269AcpiAmlPrepDefFieldValue (
270    ACPI_NAMESPACE_NODE     *Node,
271    ACPI_HANDLE             Region,
272    UINT8                   FieldFlags,
273    UINT8                   FieldAttribute,
274    UINT32                  FieldPosition,
275    UINT32                  FieldLength)
276{
277    ACPI_OPERAND_OBJECT     *ObjDesc;
278    UINT32                  Type;
279    ACPI_STATUS             Status;
280
281
282    FUNCTION_TRACE ("AmlPrepDefFieldValue");
283
284
285    /* Parameter validation */
286
287    if (!Region)
288    {
289        DEBUG_PRINT (ACPI_ERROR, ("AmlPrepDefFieldValue: null Region\n"));
290        return_ACPI_STATUS (AE_AML_NO_OPERAND);
291    }
292
293    Type = AcpiNsGetType (Region);
294    if (Type != ACPI_TYPE_REGION)
295    {
296        DEBUG_PRINT (ACPI_ERROR,
297            ("AmlPrepDefFieldValue: Needed Region, found %d %s\n",
298            Type, AcpiCmGetTypeName (Type)));
299        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
300    }
301
302    /* Allocate a new object */
303
304    ObjDesc = AcpiCmCreateInternalObject (INTERNAL_TYPE_DEF_FIELD);
305    if (!ObjDesc)
306    {
307        return_ACPI_STATUS (AE_NO_MEMORY);
308    }
309
310
311    /* ObjDesc and Region valid */
312
313    DUMP_OPERANDS ((ACPI_OPERAND_OBJECT  **) &Node, IMODE_EXECUTE,
314                    "AmlPrepDefFieldValue", 1, "case DefField");
315    DUMP_OPERANDS ((ACPI_OPERAND_OBJECT  **) &Region, IMODE_EXECUTE,
316                    "AmlPrepDefFieldValue", 1, "case DefField");
317
318    /* Initialize areas of the object that are common to all fields */
319
320    Status = AcpiAmlPrepCommonFieldObject (ObjDesc, FieldFlags, FieldAttribute,
321                                            FieldPosition, FieldLength);
322    if (ACPI_FAILURE (Status))
323    {
324        return_ACPI_STATUS (Status);
325    }
326
327    /* Initialize areas of the object that are specific to this field type */
328
329    ObjDesc->Field.Container = AcpiNsGetAttachedObject (Region);
330
331    /* An additional reference for the container */
332
333    AcpiCmAddReference (ObjDesc->Field.Container);
334
335
336    /* Debug info */
337
338    DEBUG_PRINT (ACPI_INFO,
339        ("AmlPrepDefFieldValue: bitoff=%X off=%X gran=%X\n",
340        ObjDesc->Field.BitOffset, ObjDesc->Field.Offset,
341        ObjDesc->Field.Granularity));
342
343    DEBUG_PRINT (ACPI_INFO,
344        ("AmlPrepDefFieldValue: set NamedObj %p (%4.4s) val = %p\n",
345        Node, &(Node->Name), ObjDesc));
346
347    DUMP_STACK_ENTRY (ObjDesc);
348    DUMP_ENTRY (Region, ACPI_INFO);
349    DEBUG_PRINT (ACPI_INFO, ("\t%p \n", ObjDesc->Field.Container));
350    if (ObjDesc->Field.Container)
351    {
352        DUMP_STACK_ENTRY (ObjDesc->Field.Container);
353    }
354    DEBUG_PRINT (ACPI_INFO,
355        ("============================================================\n"));
356
357    /*
358     * Store the constructed descriptor (ObjDesc) into the NamedObj whose
359     * handle is on TOS, preserving the current type of that NamedObj.
360     */
361    Status = AcpiNsAttachObject ((ACPI_HANDLE) Node, ObjDesc,
362                    (UINT8) AcpiNsGetType ((ACPI_HANDLE) Node));
363
364    return_ACPI_STATUS (Status);
365}
366
367
368/*******************************************************************************
369 *
370 * FUNCTION:    AcpiAmlPrepBankFieldValue
371 *
372 * PARAMETERS:  Node            - Owning Node
373 *              Region              - Region in which field is being defined
374 *              BankReg             - Bank selection register
375 *              BankVal             - Value to store in selection register
376 *              FieldFlags          - Access, LockRule, or UpdateRule
377 *              FieldPosition       - Field position
378 *              FieldLength         - Field length
379 *
380 * RETURN:      Status
381 *
382 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT  of type BankField and
383 *              connect it to the parent Node.
384 *
385 ******************************************************************************/
386
387ACPI_STATUS
388AcpiAmlPrepBankFieldValue (
389    ACPI_NAMESPACE_NODE     *Node,
390    ACPI_HANDLE             Region,
391    ACPI_HANDLE             BankReg,
392    UINT32                  BankVal,
393    UINT8                   FieldFlags,
394    UINT8                   FieldAttribute,
395    UINT32                  FieldPosition,
396    UINT32                  FieldLength)
397{
398    ACPI_OPERAND_OBJECT     *ObjDesc;
399    UINT32                  Type;
400    ACPI_STATUS             Status;
401
402
403    FUNCTION_TRACE ("AmlPrepBankFieldValue");
404
405
406    /* Parameter validation */
407
408    if (!Region)
409    {
410        DEBUG_PRINT (ACPI_ERROR, ("AmlPrepBankFieldValue: null Region\n"));
411        return_ACPI_STATUS (AE_AML_NO_OPERAND);
412    }
413
414    Type = AcpiNsGetType (Region);
415    if (Type != ACPI_TYPE_REGION)
416    {
417        DEBUG_PRINT (ACPI_ERROR,
418            ("AmlPrepBankFieldValue: Needed Region, found %d %s\n",
419            Type, AcpiCmGetTypeName (Type)));
420        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
421    }
422
423    /* Allocate a new object */
424
425    ObjDesc = AcpiCmCreateInternalObject (INTERNAL_TYPE_BANK_FIELD);
426    if (!ObjDesc)
427    {
428        return_ACPI_STATUS (AE_NO_MEMORY);
429    }
430
431    /*  ObjDesc and Region valid    */
432
433    DUMP_OPERANDS ((ACPI_OPERAND_OBJECT  **) &Node, IMODE_EXECUTE,
434                    "AmlPrepBankFieldValue", 1, "case BankField");
435    DUMP_OPERANDS ((ACPI_OPERAND_OBJECT  **) &Region, IMODE_EXECUTE,
436                    "AmlPrepBankFieldValue", 1, "case BankField");
437
438    /* Initialize areas of the object that are common to all fields */
439
440    Status = AcpiAmlPrepCommonFieldObject (ObjDesc, FieldFlags, FieldAttribute,
441                                            FieldPosition, FieldLength);
442    if (ACPI_FAILURE (Status))
443    {
444        return_ACPI_STATUS (Status);
445    }
446
447    /* Initialize areas of the object that are specific to this field type */
448
449    ObjDesc->BankField.Value        = BankVal;
450    ObjDesc->BankField.Container    = AcpiNsGetAttachedObject (Region);
451    ObjDesc->BankField.BankSelect   = AcpiNsGetAttachedObject (BankReg);
452
453    /* An additional reference for the container and bank select */
454    /* TBD: [Restructure] is "BankSelect" ever a real internal object?? */
455
456    AcpiCmAddReference (ObjDesc->BankField.Container);
457    AcpiCmAddReference (ObjDesc->BankField.BankSelect);
458
459    /* Debug info */
460
461    DEBUG_PRINT (ACPI_INFO,
462        ("AmlPrepBankFieldValue: bitoff=%X off=%X gran=%X\n",
463        ObjDesc->BankField.BitOffset, ObjDesc->BankField.Offset,
464        ObjDesc->Field.Granularity));
465
466    DEBUG_PRINT (ACPI_INFO,
467        ("AmlPrepBankFieldValue: set NamedObj %p (%4.4s) val = %p\n",
468        Node, &(Node->Name), ObjDesc));
469
470    DUMP_STACK_ENTRY (ObjDesc);
471    DUMP_ENTRY (Region, ACPI_INFO);
472    DUMP_ENTRY (BankReg, ACPI_INFO);
473    DEBUG_PRINT (ACPI_INFO,
474        ("============================================================\n"));
475
476    /*
477     * Store the constructed descriptor (ObjDesc) into the NamedObj whose
478     * handle is on TOS, preserving the current type of that NamedObj.
479     */
480    Status = AcpiNsAttachObject ((ACPI_HANDLE) Node, ObjDesc,
481                (UINT8) AcpiNsGetType ((ACPI_HANDLE) Node));
482
483    return_ACPI_STATUS (Status);
484}
485
486
487/*******************************************************************************
488 *
489 * FUNCTION:    AcpiAmlPrepIndexFieldValue
490 *
491 * PARAMETERS:  Node            - Owning Node
492 *              IndexReg            - Index register
493 *              DataReg             - Data register
494 *              FieldFlags          - Access, LockRule, or UpdateRule
495 *              FieldPosition       - Field position
496 *              FieldLength         - Field length
497 *
498 * RETURN:      Status
499 *
500 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT  of type IndexField and
501 *              connect it to the parent Node.
502 *
503 ******************************************************************************/
504
505ACPI_STATUS
506AcpiAmlPrepIndexFieldValue (
507    ACPI_NAMESPACE_NODE     *Node,
508    ACPI_HANDLE             IndexReg,
509    ACPI_HANDLE             DataReg,
510    UINT8                   FieldFlags,
511    UINT8                   FieldAttribute,
512    UINT32                  FieldPosition,
513    UINT32                  FieldLength)
514{
515    ACPI_OPERAND_OBJECT     *ObjDesc;
516    ACPI_STATUS             Status;
517
518
519    FUNCTION_TRACE ("AmlPrepIndexFieldValue");
520
521
522    /* Parameter validation */
523
524    if (!IndexReg || !DataReg)
525    {
526        DEBUG_PRINT (ACPI_ERROR, ("AmlPrepIndexFieldValue: null handle\n"));
527        return_ACPI_STATUS (AE_AML_NO_OPERAND);
528    }
529
530    /* Allocate a new object descriptor */
531
532    ObjDesc = AcpiCmCreateInternalObject (INTERNAL_TYPE_INDEX_FIELD);
533    if (!ObjDesc)
534    {
535        return_ACPI_STATUS (AE_NO_MEMORY);
536    }
537
538    /* Initialize areas of the object that are common to all fields */
539
540    Status = AcpiAmlPrepCommonFieldObject (ObjDesc, FieldFlags, FieldAttribute,
541                                            FieldPosition, FieldLength);
542    if (ACPI_FAILURE (Status))
543    {
544        return_ACPI_STATUS (Status);
545    }
546
547    /* Initialize areas of the object that are specific to this field type */
548
549    ObjDesc->IndexField.Value       = (UINT32) (FieldPosition /
550                                                ObjDesc->Field.Granularity);
551    ObjDesc->IndexField.Index       = IndexReg;
552    ObjDesc->IndexField.Data        = DataReg;
553
554    /* Debug info */
555
556    DEBUG_PRINT (ACPI_INFO,
557        ("AmlPrepIndexFieldValue: bitoff=%X off=%X gran=%X\n",
558        ObjDesc->IndexField.BitOffset, ObjDesc->IndexField.Offset,
559        ObjDesc->Field.Granularity));
560
561    DEBUG_PRINT (ACPI_INFO,
562        ("AmlPrepIndexFieldValue: set NamedObj %p (%4.4s) val = %p\n",
563        Node, &(Node->Name), ObjDesc));
564
565    DUMP_STACK_ENTRY (ObjDesc);
566    DUMP_ENTRY (IndexReg, ACPI_INFO);
567    DUMP_ENTRY (DataReg, ACPI_INFO);
568    DEBUG_PRINT (ACPI_INFO,
569        ("============================================================\n"));
570
571    /*
572     * Store the constructed descriptor (ObjDesc) into the NamedObj whose
573     * handle is on TOS, preserving the current type of that NamedObj.
574     */
575    Status = AcpiNsAttachObject ((ACPI_HANDLE) Node, ObjDesc,
576                (UINT8) AcpiNsGetType ((ACPI_HANDLE) Node));
577
578    return_ACPI_STATUS (Status);
579}
580
581