exprep.c revision 80062
122347Spst
222347Spst/******************************************************************************
329967Sache *
492914Smarkm * Module Name: exprep - ACPI AML (p-code) execution - field prep utilities
522347Spst *              $Revision: 91 $
622347Spst *
722347Spst *****************************************************************************/
822347Spst
922347Spst/******************************************************************************
1022347Spst *
1122347Spst * 1. Copyright Notice
1222347Spst *
1322347Spst * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
1422347Spst * All rights reserved.
1522347Spst *
1622347Spst * 2. License
1792914Smarkm *
1822347Spst * 2.1. This is your license from Intel Corp. under its intellectual property
1922347Spst * rights.  You may have additional license terms from the party that provided
2022347Spst * you this software, covering your right to use that party's intellectual
2122347Spst * property rights.
2222347Spst *
2322347Spst * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2422347Spst * copy of the source code appearing in this file ("Covered Code") an
2559121Skris * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2622347Spst * base code distributed originally by Intel ("Original Intel Code") to copy,
2722347Spst * make derivatives, distribute, use and display any portion of the Covered
2822347Spst * Code in any form, with the right to sublicense such rights; and
2922347Spst *
3022347Spst * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3122347Spst * license (with the right to sublicense), under only those claims of Intel
3222347Spst * patents that are infringed by the Original Intel Code, to make, use, sell,
3322347Spst * offer to sell, and import the Covered Code and derivative works thereof
3422347Spst * solely to the minimum extent necessary to exercise the above copyright
3522347Spst * license, and in no event shall the patent license extend to any additions
3622347Spst * to or modifications of the Original Intel Code.  No other license or right
3722347Spst * is granted directly or by implication, estoppel or otherwise;
3822347Spst *
3922347Spst * The above copyright and patent license is granted only if the following
4092914Smarkm * conditions are met:
4122347Spst *
4222347Spst * 3. Conditions
4322347Spst *
4422347Spst * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4522347Spst * Redistribution of source code of any substantial portion of the Covered
4622347Spst * Code or modification with rights to further distribute source must include
4722347Spst * the above Copyright Notice, the above License, this list of Conditions,
4822347Spst * and the following Disclaimer and Export Compliance provision.  In addition,
4922347Spst * Licensee must cause all Covered Code to which Licensee contributes to
5022347Spst * contain a file documenting the changes Licensee made to create that Covered
5122347Spst * Code and the date of any change.  Licensee must include in that file the
5222347Spst * documentation of any changes made by any predecessor Licensee.  Licensee
5322347Spst * must include a prominent statement that the modification is derived,
5422347Spst * directly or indirectly, from Original Intel Code.
5522347Spst *
5622347Spst * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5722347Spst * Redistribution of source code of any substantial portion of the Covered
5822347Spst * Code or modification without rights to further distribute source must
5922347Spst * include the following Disclaimer and Export Compliance provision in the
6022347Spst * documentation and/or other materials provided with distribution.  In
6122347Spst * addition, Licensee may not authorize further sublicense of source of any
6222347Spst * portion of the Covered Code, and must include terms to the effect that the
6322347Spst * license from Licensee to its licensee is limited to the intellectual
6422347Spst * property embodied in the software Licensee provides to its licensee, and
6522347Spst * not to intellectual property embodied in modifications its licensee may
6622347Spst * make.
6722347Spst *
6822347Spst * 3.3. Redistribution of Executable. Redistribution in executable form of any
6922347Spst * substantial portion of the Covered Code or modification must reproduce the
7022347Spst * above Copyright Notice, and the following Disclaimer and Export Compliance
7122347Spst * provision in the documentation and/or other materials provided with the
7222347Spst * distribution.
7322347Spst *
7422347Spst * 3.4. Intel retains all right, title, and interest in and to the Original
7522347Spst * Intel Code.
7622347Spst *
7722347Spst * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7822347Spst * Intel shall be used in advertising or otherwise to promote the sale, use or
7922347Spst * other dealings in products derived from or relating to the Covered Code
8022347Spst * without prior written authorization from Intel.
8122347Spst *
8222347Spst * 4. Disclaimer and Export Compliance
8322347Spst *
8422347Spst * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8522347Spst * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8622347Spst * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8722347Spst * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8822347Spst * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8922347Spst * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
9022347Spst * PARTICULAR PURPOSE.
9122347Spst *
9222347Spst * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9322347Spst * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9422347Spst * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9522347Spst * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9622347Spst * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9722347Spst * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9822347Spst * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9922347Spst * LIMITED REMEDY.
10022347Spst *
10122347Spst * 4.3. Licensee shall not export, either directly or indirectly, any of this
10222347Spst * software or system incorporating such software without first obtaining any
10322347Spst * required license or other approval from the U. S. Department of Commerce or
10422347Spst * any other agency or department of the United States Government.  In the
10522347Spst * event Licensee exports any such software from the United States or
10622347Spst * re-exports any such software from a foreign destination, Licensee shall
10722347Spst * ensure that the distribution and export/re-export of the software is in
10822347Spst * compliance with all laws, regulations, orders, or other restrictions of the
10922347Spst * U.S. Export Administration Regulations. Licensee agrees that neither it nor
11022347Spst * any of its subsidiaries will export/re-export any technical data, process,
11122347Spst * software, or service, directly or indirectly, to any country for which the
11222347Spst * United States government or any agency thereof requires an export license,
11322347Spst * other governmental approval, or letter of assurance, without first obtaining
11422347Spst * such license, approval or letter.
11522347Spst *
11622347Spst *****************************************************************************/
11722347Spst
11822347Spst#define __EXPREP_C__
11922347Spst
12022347Spst#include "acpi.h"
12122347Spst#include "acinterp.h"
12222347Spst#include "amlcode.h"
12322347Spst#include "acnamesp.h"
12422347Spst#include "acparser.h"
12522347Spst
12622347Spst
12722347Spst#define _COMPONENT          ACPI_EXECUTER
12822347Spst        MODULE_NAME         ("exprep")
12922347Spst
13022347Spst
13122347Spst/*******************************************************************************
13222347Spst *
13322347Spst * FUNCTION:    AcpiExDecodeFieldAccessType
13422347Spst *
13522347Spst * PARAMETERS:  Access          - Encoded field access bits
13622347Spst *              Length          - Field length.
13722347Spst *
13822347Spst * RETURN:      Field granularity (8, 16, or 32)
13922347Spst *
14022347Spst * DESCRIPTION: Decode the AccessType bits of a field definition.
14122347Spst *
14222347Spst ******************************************************************************/
14322347Spst
14422347Spststatic UINT32
14522347SpstAcpiExDecodeFieldAccessType (
14622347Spst    UINT32                  Access,
14722347Spst    UINT16                  Length,
14822347Spst    UINT32                  *Alignment)
14922347Spst{
15022347Spst
15122347Spst    switch (Access)
15222347Spst    {
15322347Spst    case ACCESS_ANY_ACC:
15422347Spst
15522347Spst        *Alignment = 8;
15622347Spst
15722372Spst        /* Use the length to set the access type */
15822372Spst
15922347Spst        if (Length <= 8)
16022347Spst        {
16122347Spst            return (8);
16222347Spst        }
16322372Spst        else if (Length <= 16)
16422347Spst        {
16522347Spst            return (16);
16622347Spst        }
16722347Spst        else if (Length <= 32)
16822347Spst        {
16922347Spst            return (32);
17022347Spst        }
17122347Spst        else if (Length <= 64)
17222347Spst        {
17322347Spst            return (64);
17422347Spst        }
17522347Spst
17622347Spst        /* Default is 8 (byte) */
17722347Spst
17822347Spst        return (8);
179        break;
180
181    case ACCESS_BYTE_ACC:
182        *Alignment = 8;
183        return (8);
184        break;
185
186    case ACCESS_WORD_ACC:
187        *Alignment = 16;
188        return (16);
189        break;
190
191    case ACCESS_DWORD_ACC:
192        *Alignment = 32;
193        return (32);
194        break;
195
196    case ACCESS_QWORD_ACC:  /* ACPI 2.0 */
197        *Alignment = 64;
198        return (64);
199        break;
200
201    default:
202        /* Invalid field access type */
203
204        DEBUG_PRINT (ACPI_ERROR,
205            ("ExDecodeFieldAccessType: Unknown field access type %x\n",
206            Access));
207        return (0);
208    }
209}
210
211
212/*******************************************************************************
213 *
214 * FUNCTION:    AcpiExPrepCommonFieldObject
215 *
216 * PARAMETERS:  ObjDesc             - The field object
217 *              FieldFlags          - Access, LockRule, and UpdateRule.
218 *                                    The format of a FieldFlag is described
219 *                                    in the ACPI specification
220 *              FieldBitPosition    - Field start position
221 *              FieldBitLength      - Field length in number of bits
222 *
223 * RETURN:      Status
224 *
225 * DESCRIPTION: Initialize the areas of the field object that are common
226 *              to the various types of fields.
227 *
228 ******************************************************************************/
229
230ACPI_STATUS
231AcpiExPrepCommonFieldObject (
232    ACPI_OPERAND_OBJECT     *ObjDesc,
233    UINT8                   FieldFlags,
234    UINT32                  FieldBitPosition,
235    UINT32                  FieldBitLength)
236{
237    UINT32                  AccessBitWidth;
238    UINT32                  Alignment;
239    UINT32                  NearestByteAddress;
240
241
242    FUNCTION_TRACE ("ExPrepCommonFieldObject");
243
244
245    /*
246     * Note: the structure being initialized is the
247     * ACPI_COMMON_FIELD_INFO;  No structure fields outside of the common area
248     * are initialized by this procedure.
249     */
250
251    /* Demultiplex the FieldFlags byte */
252
253    ObjDesc->CommonField.LockRule   = (UINT8) ((FieldFlags & LOCK_RULE_MASK)
254                                                    >> LOCK_RULE_SHIFT);
255    ObjDesc->CommonField.UpdateRule = (UINT8) ((FieldFlags & UPDATE_RULE_MASK)
256                                                    >> UPDATE_RULE_SHIFT);
257    /* Other misc fields */
258
259    ObjDesc->CommonField.BitLength  = (UINT16) FieldBitLength;
260
261    /*
262     * Decode the access type so we can compute offsets.  The access type gives
263     * two pieces of information - the width of each field access and the
264     * necessary alignment of the access.  For AnyAcc, the width used is the
265     * largest necessary/possible in an attempt to access the whole field in one
266     * I/O operation.  However, for AnyAcc, the alignment is 8.  For all other
267     * access types (Byte, Word, Dword, Qword), the width is the same as the
268     * alignment.
269     */
270    AccessBitWidth = AcpiExDecodeFieldAccessType (
271                        ((FieldFlags & ACCESS_TYPE_MASK) >> ACCESS_TYPE_SHIFT),
272                        ObjDesc->Field.BitLength, &Alignment);
273    if (!AccessBitWidth)
274    {
275        return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
276    }
277
278    /* Setup width (access granularity) fields */
279
280    ObjDesc->CommonField.AccessBitWidth    = (UINT8) AccessBitWidth;            /* 8, 16, 32, 64 */
281    ObjDesc->CommonField.AccessByteWidth   = (UINT8) DIV_8 (AccessBitWidth);    /* 1,  2,  4,  8 */
282
283    if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
284    {
285        /*
286         * BufferField access can be on any byte boundary, so the
287         * alignment is always 8 (regardless of any alignment implied by the
288         * field access type.)
289         */
290        Alignment = 8;
291    }
292
293
294    /*
295     * BaseByteOffset is the address of the start of the field within the region.  It is
296     * the byte address of the first *datum* (field-width data unit) of the field.
297     * (i.e., the first datum that contains at least the first *bit* of the field.)
298     */
299    NearestByteAddress                        = ROUND_BITS_DOWN_TO_BYTES (FieldBitPosition);
300    ObjDesc->CommonField.BaseByteOffset       = ROUND_DOWN (NearestByteAddress,
301                                                            DIV_8 (Alignment));
302
303    /*
304     * StartFieldBitOffset is the offset of the first bit of the field within a field datum.
305     * This is calculated as the number of bits from the BaseByteOffset.  In other words,
306     * the start of the field is relative to a byte address, regardless of the access type
307     * of the field.
308     */
309    ObjDesc->CommonField.StartFieldBitOffset  = (UINT8) (MOD_8 (FieldBitPosition));
310
311    /*
312     * DatumValidBits is the number of valid field bits in the first field datum.
313     */
314    ObjDesc->CommonField.DatumValidBits       = (UINT8) (AccessBitWidth -
315                                                         ObjDesc->CommonField.StartFieldBitOffset);
316
317    /*
318     * Valid bits -- the number of bits that compose a partial datum,
319     * 1) At the end of the field within the region (arbitrary starting bit offset)
320     * 2) At the end of a buffer used to contain the field (starting offset always zero)
321     */
322    ObjDesc->CommonField.EndFieldValidBits    = (UINT8) ((ObjDesc->CommonField.StartFieldBitOffset +
323                                                            FieldBitLength) % AccessBitWidth);
324    ObjDesc->CommonField.EndBufferValidBits   = (UINT8) (FieldBitLength % AccessBitWidth); /* StartBufferBitOffset always = 0 */
325
326
327    /*
328     * Does the entire field fit within a single field access element
329     * (datum)?  (without crossing a datum boundary)
330     */
331    if ((ObjDesc->CommonField.StartFieldBitOffset + ObjDesc->CommonField.BitLength) <=
332        (UINT16) ObjDesc->CommonField.AccessBitWidth)
333    {
334        ObjDesc->CommonField.AccessFlags |= AFIELD_SINGLE_DATUM;
335    }
336
337
338    return_ACPI_STATUS (AE_OK);
339}
340
341
342/*******************************************************************************
343 *
344 * FUNCTION:    AcpiExPrepRegionFieldValue
345 *
346 * PARAMETERS:  Node                - Owning Node
347 *              RegionNode          - Region in which field is being defined
348 *              FieldFlags          - Access, LockRule, and UpdateRule.
349 *              FieldBitPosition    - Field start position
350 *              FieldBitLength      - Field length in number of bits
351 *
352 * RETURN:      Status
353 *
354 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT  of type DefField and
355 *              connect it to the parent Node.
356 *
357 ******************************************************************************/
358
359ACPI_STATUS
360AcpiExPrepRegionFieldValue (
361    ACPI_NAMESPACE_NODE     *Node,
362    ACPI_HANDLE             RegionNode,
363    UINT8                   FieldFlags,
364    UINT32                  FieldBitPosition,
365    UINT32                  FieldBitLength)
366{
367    ACPI_OPERAND_OBJECT     *ObjDesc;
368    UINT32                  Type;
369    ACPI_STATUS             Status;
370
371
372    FUNCTION_TRACE ("ExPrepRegionFieldValue");
373
374
375    /* Parameter validation */
376
377    if (!RegionNode)
378    {
379        DEBUG_PRINTP (ACPI_ERROR, ("Null RegionNode\n"));
380        return_ACPI_STATUS (AE_AML_NO_OPERAND);
381    }
382
383    Type = AcpiNsGetType (RegionNode);
384    if (Type != ACPI_TYPE_REGION)
385    {
386        DEBUG_PRINTP (ACPI_ERROR, ("Needed Region, found type %X %s\n",
387            Type, AcpiUtGetTypeName (Type)));
388        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
389    }
390
391    /* Allocate a new object */
392
393    ObjDesc = AcpiUtCreateInternalObject (INTERNAL_TYPE_REGION_FIELD);
394    if (!ObjDesc)
395    {
396        return_ACPI_STATUS (AE_NO_MEMORY);
397    }
398
399
400    /* ObjDesc and Region valid */
401
402    DUMP_OPERANDS ((ACPI_OPERAND_OBJECT  **) &Node, IMODE_EXECUTE,
403                    "ExPrepRegionFieldValue", 1, "case RegionField");
404    DUMP_OPERANDS ((ACPI_OPERAND_OBJECT  **) &RegionNode, IMODE_EXECUTE,
405                    "ExPrepRegionFieldValue", 1, "case RegionField");
406
407    /* Initialize areas of the object that are common to all fields */
408
409    Status = AcpiExPrepCommonFieldObject (ObjDesc, FieldFlags,
410                                            FieldBitPosition, FieldBitLength);
411    if (ACPI_FAILURE (Status))
412    {
413        return_ACPI_STATUS (Status);
414    }
415
416    /* Initialize areas of the object that are specific to this field type */
417
418    ObjDesc->Field.RegionObj = AcpiNsGetAttachedObject (RegionNode);
419
420    /* An additional reference for the container */
421
422    AcpiUtAddReference (ObjDesc->Field.RegionObj);
423
424
425    /* Debug info */
426
427    DEBUG_PRINTP (ACPI_INFO, ("Bitoff=%X Off=%X Gran=%X Region %p\n",
428        ObjDesc->Field.StartFieldBitOffset, ObjDesc->Field.BaseByteOffset,
429        ObjDesc->Field.AccessBitWidth, ObjDesc->Field.RegionObj));
430
431    DEBUG_PRINTP (ACPI_INFO, ("set NamedObj %p (%4.4s) val = %p\n",
432        Node, &(Node->Name), ObjDesc));
433
434
435    /*
436     * Store the constructed descriptor (ObjDesc) into the parent Node,
437     * preserving the current type of that NamedObj.
438     */
439    Status = AcpiNsAttachObject (Node, ObjDesc, (UINT8) AcpiNsGetType (Node));
440    return_ACPI_STATUS (Status);
441}
442
443
444/*******************************************************************************
445 *
446 * FUNCTION:    AcpiExPrepBankFieldValue
447 *
448 * PARAMETERS:  Node                - Owning Node
449 *              RegionNode          - Region in which field is being defined
450 *              BankRegisterNode    - Bank selection register node
451 *              BankVal             - Value to store in selection register
452 *              FieldFlags          - Access, LockRule, and UpdateRule
453 *              FieldBitPosition    - Field start position
454 *              FieldBitLength      - Field length in number of bits
455 *
456 * RETURN:      Status
457 *
458 * DESCRIPTION: Construct an object of type BankField and attach it to the
459 *              parent Node.
460 *
461 ******************************************************************************/
462
463ACPI_STATUS
464AcpiExPrepBankFieldValue (
465    ACPI_NAMESPACE_NODE     *Node,
466    ACPI_NAMESPACE_NODE     *RegionNode,
467    ACPI_NAMESPACE_NODE     *BankRegisterNode,
468    UINT32                  BankVal,
469    UINT8                   FieldFlags,
470    UINT32                  FieldBitPosition,
471    UINT32                  FieldBitLength)
472{
473    ACPI_OPERAND_OBJECT     *ObjDesc;
474    UINT32                  Type;
475    ACPI_STATUS             Status;
476
477
478    FUNCTION_TRACE ("ExPrepBankFieldValue");
479
480
481    /* Parameter validation */
482
483    if (!RegionNode)
484    {
485        DEBUG_PRINTP (ACPI_ERROR, ("Null RegionNode\n"));
486        return_ACPI_STATUS (AE_AML_NO_OPERAND);
487    }
488
489    Type = AcpiNsGetType (RegionNode);
490    if (Type != ACPI_TYPE_REGION)
491    {
492        DEBUG_PRINTP (ACPI_ERROR, ("Needed Region, found type %X %s\n",
493            Type, AcpiUtGetTypeName (Type)));
494        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
495    }
496
497    /* Allocate a new object */
498
499    ObjDesc = AcpiUtCreateInternalObject (INTERNAL_TYPE_BANK_FIELD);
500    if (!ObjDesc)
501    {
502        return_ACPI_STATUS (AE_NO_MEMORY);
503    }
504
505    /*  ObjDesc and Region valid    */
506
507    DUMP_OPERANDS ((ACPI_OPERAND_OBJECT  **) &Node, IMODE_EXECUTE,
508                    "ExPrepBankFieldValue", 1, "case BankField");
509    DUMP_OPERANDS ((ACPI_OPERAND_OBJECT  **) &RegionNode, IMODE_EXECUTE,
510                    "ExPrepBankFieldValue", 1, "case BankField");
511
512    /* Initialize areas of the object that are common to all fields */
513
514    Status = AcpiExPrepCommonFieldObject (ObjDesc, FieldFlags,
515                                            FieldBitPosition, FieldBitLength);
516    if (ACPI_FAILURE (Status))
517    {
518        return_ACPI_STATUS (Status);
519    }
520
521    /* Initialize areas of the object that are specific to this field type */
522
523    ObjDesc->BankField.Value           = BankVal;
524    ObjDesc->BankField.RegionObj       = AcpiNsGetAttachedObject (RegionNode);
525    ObjDesc->BankField.BankRegisterObj = AcpiNsGetAttachedObject (BankRegisterNode);
526
527    /* An additional reference for the attached objects */
528
529    AcpiUtAddReference (ObjDesc->BankField.RegionObj);
530    AcpiUtAddReference (ObjDesc->BankField.BankRegisterObj);
531
532    /* Debug info */
533
534    DEBUG_PRINTP (ACPI_INFO, ("BitOff=%X Off=%X Gran=%X Region %p BankReg %p\n",
535        ObjDesc->BankField.StartFieldBitOffset, ObjDesc->BankField.BaseByteOffset,
536        ObjDesc->Field.AccessBitWidth, ObjDesc->BankField.RegionObj,
537        ObjDesc->BankField.BankRegisterObj));
538
539    DEBUG_PRINTP (ACPI_INFO, ("Set NamedObj %p (%4.4s) val=%p\n",
540        Node, &(Node->Name), ObjDesc));
541
542
543    /*
544     * Store the constructed descriptor (ObjDesc) into the parent Node,
545     * preserving the current type of that NamedObj.
546     */
547    Status = AcpiNsAttachObject (Node, ObjDesc, (UINT8) AcpiNsGetType (Node));
548    return_ACPI_STATUS (Status);
549}
550
551
552/*******************************************************************************
553 *
554 * FUNCTION:    AcpiExPrepIndexFieldValue
555 *
556 * PARAMETERS:  Node                - Owning Node
557 *              IndexReg            - Index register
558 *              DataReg             - Data register
559 *              FieldFlags          - Access, LockRule, and UpdateRule
560 *              FieldBitPosition    - Field start position
561 *              FieldBitLength      - Field length in number of bits
562 *
563 * RETURN:      Status
564 *
565 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT  of type IndexField and
566 *              connect it to the parent Node.
567 *
568 ******************************************************************************/
569
570ACPI_STATUS
571AcpiExPrepIndexFieldValue (
572    ACPI_NAMESPACE_NODE     *Node,
573    ACPI_NAMESPACE_NODE     *IndexReg,
574    ACPI_NAMESPACE_NODE     *DataReg,
575    UINT8                   FieldFlags,
576    UINT32                  FieldBitPosition,
577    UINT32                  FieldBitLength)
578{
579    ACPI_OPERAND_OBJECT     *ObjDesc;
580    ACPI_STATUS             Status;
581
582
583    FUNCTION_TRACE ("ExPrepIndexFieldValue");
584
585
586    /* Parameter validation */
587
588    if (!IndexReg || !DataReg)
589    {
590        DEBUG_PRINTP (ACPI_ERROR, ("Null handle\n"));
591        return_ACPI_STATUS (AE_AML_NO_OPERAND);
592    }
593
594    /* Allocate a new object descriptor */
595
596    ObjDesc = AcpiUtCreateInternalObject (INTERNAL_TYPE_INDEX_FIELD);
597    if (!ObjDesc)
598    {
599        return_ACPI_STATUS (AE_NO_MEMORY);
600    }
601
602    /* Initialize areas of the object that are common to all fields */
603
604    Status = AcpiExPrepCommonFieldObject (ObjDesc, FieldFlags,
605                                            FieldBitPosition, FieldBitLength);
606    if (ACPI_FAILURE (Status))
607    {
608        return_ACPI_STATUS (Status);
609    }
610
611    /* Initialize areas of the object that are specific to this field type */
612
613    ObjDesc->IndexField.DataObj  = AcpiNsGetAttachedObject (DataReg);
614    ObjDesc->IndexField.IndexObj = AcpiNsGetAttachedObject (IndexReg);
615    ObjDesc->IndexField.Value    = (UINT32) (FieldBitPosition /
616                                            ObjDesc->Field.AccessBitWidth);
617
618    /* An additional reference for the attached objects */
619
620    AcpiUtAddReference (ObjDesc->IndexField.DataObj);
621    AcpiUtAddReference (ObjDesc->IndexField.IndexObj);
622
623    /* Debug info */
624
625    DEBUG_PRINTP (ACPI_INFO, ("bitoff=%X off=%X gran=%X Index %p Data %p\n",
626        ObjDesc->IndexField.StartFieldBitOffset, ObjDesc->IndexField.BaseByteOffset,
627        ObjDesc->Field.AccessBitWidth, ObjDesc->IndexField.IndexObj,
628        ObjDesc->IndexField.DataObj));
629
630    DEBUG_PRINTP (ACPI_INFO, ("set NamedObj %p (%4.4s) val = %p\n",
631        Node, &(Node->Name), ObjDesc));
632
633
634    /*
635     * Store the constructed descriptor (ObjDesc) into the parent Node,
636     * preserving the current type of that NamedObj.
637     */
638    Status = AcpiNsAttachObject (Node, ObjDesc, (UINT8) AcpiNsGetType (Node));
639    return_ACPI_STATUS (Status);
640}
641
642