1 /******************************************************************************
   2  *
   3  * Module Name: aslrestype2d - Large DWord address resource descriptors
   4  *
   5  *****************************************************************************/
   6 
   7 /*
   8  * Copyright (C) 2000 - 2013, Intel Corp.
   9  * All rights reserved.
  10  *
  11  * Redistribution and use in source and binary forms, with or without
  12  * modification, are permitted provided that the following conditions
  13  * are met:
  14  * 1. Redistributions of source code must retain the above copyright
  15  *    notice, this list of conditions, and the following disclaimer,
  16  *    without modification.
  17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18  *    substantially similar to the "NO WARRANTY" disclaimer below
  19  *    ("Disclaimer") and any redistribution must be conditioned upon
  20  *    including a substantially similar Disclaimer requirement for further
  21  *    binary redistribution.
  22  * 3. Neither the names of the above-listed copyright holders nor the names
  23  *    of any contributors may be used to endorse or promote products derived
  24  *    from this software without specific prior written permission.
  25  *
  26  * Alternatively, this software may be distributed under the terms of the
  27  * GNU General Public License ("GPL") version 2 as published by the Free
  28  * Software Foundation.
  29  *
  30  * NO WARRANTY
  31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41  * POSSIBILITY OF SUCH DAMAGES.
  42  */
  43 
  44 
  45 #include "aslcompiler.h"
  46 #include "aslcompiler.y.h"
  47 
  48 #define _COMPONENT          ACPI_COMPILER
  49         ACPI_MODULE_NAME    ("aslrestype2d")
  50 
  51 /*
  52  * This module contains the Dword (32-bit) address space descriptors:
  53  *
  54  * DwordIO
  55  * DwordMemory
  56  * DwordSpace
  57  */
  58 
  59 /*******************************************************************************
  60  *
  61  * FUNCTION:    RsDoDwordIoDescriptor
  62  *
  63  * PARAMETERS:  Op                  - Parent resource descriptor parse node
  64  *              CurrentByteOffset   - Offset into the resource template AML
  65  *                                    buffer (to track references to the desc)
  66  *
  67  * RETURN:      Completed resource node
  68  *
  69  * DESCRIPTION: Construct a long "DwordIO" descriptor
  70  *
  71  ******************************************************************************/
  72 
  73 ASL_RESOURCE_NODE *
  74 RsDoDwordIoDescriptor (
  75     ACPI_PARSE_OBJECT       *Op,
  76     UINT32                  CurrentByteOffset)
  77 {
  78     AML_RESOURCE            *Descriptor;
  79     ACPI_PARSE_OBJECT       *InitializerOp;
  80     ACPI_PARSE_OBJECT       *MinOp = NULL;
  81     ACPI_PARSE_OBJECT       *MaxOp = NULL;
  82     ACPI_PARSE_OBJECT       *LengthOp = NULL;
  83     ACPI_PARSE_OBJECT       *GranOp = NULL;
  84     ASL_RESOURCE_NODE       *Rnode;
  85     UINT16                  StringLength = 0;
  86     UINT32                  OptionIndex = 0;
  87     UINT8                   *OptionalFields;
  88     UINT32                  i;
  89     BOOLEAN                 ResSourceIndex = FALSE;
  90 
  91 
  92     InitializerOp = Op->Asl.Child;
  93     StringLength = RsGetStringDataLength (InitializerOp);
  94 
  95     Rnode = RsAllocateResourceNode (
  96                 sizeof (AML_RESOURCE_ADDRESS32) + 1 + StringLength);
  97 
  98     Descriptor = Rnode->Buffer;
  99     Descriptor->Address32.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS32;
 100     Descriptor->Address32.ResourceType   = ACPI_ADDRESS_TYPE_IO_RANGE;
 101 
 102     /*
 103      * Initial descriptor length -- may be enlarged if there are
 104      * optional fields present
 105      */
 106     OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS32);
 107     Descriptor->Address32.ResourceLength = (UINT16)
 108         (sizeof (AML_RESOURCE_ADDRESS32) -
 109          sizeof (AML_RESOURCE_LARGE_HEADER));
 110 
 111     /* Process all child initialization nodes */
 112 
 113     for (i = 0; InitializerOp; i++)
 114     {
 115         switch (i)
 116         {
 117         case 0: /* Resource Usage */
 118 
 119             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 0, 1);
 120             break;
 121 
 122         case 1: /* MinType */
 123 
 124             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 2, 0);
 125             RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE,
 126                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 2);
 127             break;
 128 
 129         case 2: /* MaxType */
 130 
 131             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 3, 0);
 132             RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE,
 133                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 3);
 134             break;
 135 
 136         case 3: /* DecodeType */
 137 
 138             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 1, 0);
 139             RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE,
 140                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 1);
 141             break;
 142 
 143         case 4: /* Range Type */
 144 
 145             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 0, 3);
 146             RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_RANGETYPE,
 147                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 0, 2);
 148             break;
 149 
 150         case 5: /* Address Granularity */
 151 
 152             Descriptor->Address32.Granularity =
 153                 (UINT32) InitializerOp->Asl.Value.Integer;
 154             RsCreateDwordField (InitializerOp, ACPI_RESTAG_GRANULARITY,
 155                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Granularity));
 156             GranOp = InitializerOp;
 157             break;
 158 
 159         case 6: /* Address Min */
 160 
 161             Descriptor->Address32.Minimum =
 162                 (UINT32) InitializerOp->Asl.Value.Integer;
 163             RsCreateDwordField (InitializerOp, ACPI_RESTAG_MINADDR,
 164                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Minimum));
 165             MinOp = InitializerOp;
 166             break;
 167 
 168         case 7: /* Address Max */
 169 
 170             Descriptor->Address32.Maximum =
 171                 (UINT32) InitializerOp->Asl.Value.Integer;
 172             RsCreateDwordField (InitializerOp, ACPI_RESTAG_MAXADDR,
 173                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Maximum));
 174             MaxOp = InitializerOp;
 175             break;
 176 
 177         case 8: /* Translation Offset */
 178 
 179             Descriptor->Address32.TranslationOffset =
 180                 (UINT32) InitializerOp->Asl.Value.Integer;
 181             RsCreateDwordField (InitializerOp, ACPI_RESTAG_TRANSLATION,
 182                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.TranslationOffset));
 183             break;
 184 
 185         case 9: /* Address Length */
 186 
 187             Descriptor->Address32.AddressLength =
 188                 (UINT32) InitializerOp->Asl.Value.Integer;
 189             RsCreateDwordField (InitializerOp, ACPI_RESTAG_LENGTH,
 190                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.AddressLength));
 191             LengthOp = InitializerOp;
 192             break;
 193 
 194         case 10: /* ResSourceIndex [Optional Field - BYTE] */
 195 
 196             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
 197             {
 198                 /* Found a valid ResourceSourceIndex */
 199 
 200                 OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer;
 201                 OptionIndex++;
 202                 Descriptor->Address32.ResourceLength++;
 203                 ResSourceIndex = TRUE;
 204             }
 205             break;
 206 
 207         case 11: /* ResSource [Optional Field - STRING] */
 208 
 209             if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
 210                 (InitializerOp->Asl.Value.String))
 211             {
 212                 if (StringLength)
 213                 {
 214                     /* Found a valid ResourceSource */
 215 
 216                     Descriptor->Address32.ResourceLength = (UINT16)
 217                         (Descriptor->Address32.ResourceLength + StringLength);
 218 
 219                     strcpy ((char *)
 220                         &OptionalFields[OptionIndex],
 221                         InitializerOp->Asl.Value.String);
 222 
 223                     /* ResourceSourceIndex must also be valid */
 224 
 225                     if (!ResSourceIndex)
 226                     {
 227                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
 228                             InitializerOp, NULL);
 229                     }
 230                 }
 231             }
 232 
 233 #if 0
 234             /*
 235              * Not a valid ResourceSource, ResourceSourceIndex must also
 236              * be invalid
 237              */
 238             else if (ResSourceIndex)
 239             {
 240                 AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
 241                     InitializerOp, NULL);
 242             }
 243 #endif
 244             break;
 245 
 246         case 12: /* ResourceTag */
 247 
 248             UtAttachNamepathToOwner (Op, InitializerOp);
 249             break;
 250 
 251         case 13: /* Type */
 252 
 253             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 4, 0);
 254             RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE,
 255                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 4);
 256             break;
 257 
 258         case 14: /* Translation Type */
 259 
 260             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 5, 0);
 261             RsCreateBitField (InitializerOp, ACPI_RESTAG_TRANSTYPE,
 262                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 5);
 263             break;
 264 
 265         default:
 266 
 267             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
 268             break;
 269         }
 270 
 271         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
 272     }
 273 
 274     /* Validate the Min/Max/Len/Gran values */
 275 
 276     RsLargeAddressCheck (
 277         (UINT64) Descriptor->Address32.Minimum,
 278         (UINT64) Descriptor->Address32.Maximum,
 279         (UINT64) Descriptor->Address32.AddressLength,
 280         (UINT64) Descriptor->Address32.Granularity,
 281         Descriptor->Address32.Flags,
 282         MinOp, MaxOp, LengthOp, GranOp, Op);
 283 
 284     Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS32) +
 285                             OptionIndex + StringLength;
 286     return (Rnode);
 287 }
 288 
 289 
 290 /*******************************************************************************
 291  *
 292  * FUNCTION:    RsDoDwordMemoryDescriptor
 293  *
 294  * PARAMETERS:  Op                  - Parent resource descriptor parse node
 295  *              CurrentByteOffset   - Offset into the resource template AML
 296  *                                    buffer (to track references to the desc)
 297  *
 298  * RETURN:      Completed resource node
 299  *
 300  * DESCRIPTION: Construct a long "DwordMemory" descriptor
 301  *
 302  ******************************************************************************/
 303 
 304 ASL_RESOURCE_NODE *
 305 RsDoDwordMemoryDescriptor (
 306     ACPI_PARSE_OBJECT       *Op,
 307     UINT32                  CurrentByteOffset)
 308 {
 309     AML_RESOURCE            *Descriptor;
 310     ACPI_PARSE_OBJECT       *InitializerOp;
 311     ACPI_PARSE_OBJECT       *MinOp = NULL;
 312     ACPI_PARSE_OBJECT       *MaxOp = NULL;
 313     ACPI_PARSE_OBJECT       *LengthOp = NULL;
 314     ACPI_PARSE_OBJECT       *GranOp = NULL;
 315     ASL_RESOURCE_NODE       *Rnode;
 316     UINT8                   *OptionalFields;
 317     UINT16                  StringLength = 0;
 318     UINT32                  OptionIndex = 0;
 319     UINT32                  i;
 320     BOOLEAN                 ResSourceIndex = FALSE;
 321 
 322 
 323     InitializerOp = Op->Asl.Child;
 324     StringLength = RsGetStringDataLength (InitializerOp);
 325 
 326     Rnode = RsAllocateResourceNode (
 327                 sizeof (AML_RESOURCE_ADDRESS32) + 1 + StringLength);
 328 
 329     Descriptor = Rnode->Buffer;
 330     Descriptor->Address32.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS32;
 331     Descriptor->Address32.ResourceType   = ACPI_ADDRESS_TYPE_MEMORY_RANGE;
 332 
 333     /*
 334      * Initial descriptor length -- may be enlarged if there are
 335      * optional fields present
 336      */
 337     OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS32);
 338     Descriptor->Address32.ResourceLength = (UINT16)
 339         (sizeof (AML_RESOURCE_ADDRESS32) -
 340          sizeof (AML_RESOURCE_LARGE_HEADER));
 341 
 342 
 343     /* Process all child initialization nodes */
 344 
 345     for (i = 0; InitializerOp; i++)
 346     {
 347         switch (i)
 348         {
 349         case 0: /* Resource Usage */
 350 
 351             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 0, 1);
 352             break;
 353 
 354         case 1: /* DecodeType */
 355 
 356             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 1, 0);
 357             RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE,
 358                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 1);
 359             break;
 360 
 361         case 2: /* MinType */
 362 
 363             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 2, 0);
 364             RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE,
 365                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 2);
 366             break;
 367 
 368         case 3: /* MaxType */
 369 
 370             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 3, 0);
 371             RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE,
 372                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 3);
 373             break;
 374 
 375         case 4: /* Memory Type */
 376 
 377             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 1, 0);
 378             RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMTYPE,
 379                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 1, 2);
 380             break;
 381 
 382         case 5: /* Read/Write Type */
 383 
 384             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 0, 1);
 385             RsCreateBitField (InitializerOp, ACPI_RESTAG_READWRITETYPE,
 386                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 0);
 387             break;
 388 
 389         case 6: /* Address Granularity */
 390 
 391             Descriptor->Address32.Granularity =
 392                 (UINT32) InitializerOp->Asl.Value.Integer;
 393             RsCreateDwordField (InitializerOp, ACPI_RESTAG_GRANULARITY,
 394                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Granularity));
 395             GranOp = InitializerOp;
 396             break;
 397 
 398         case 7: /* Min Address */
 399 
 400             Descriptor->Address32.Minimum =
 401                 (UINT32) InitializerOp->Asl.Value.Integer;
 402             RsCreateDwordField (InitializerOp, ACPI_RESTAG_MINADDR,
 403                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Minimum));
 404             MinOp = InitializerOp;
 405             break;
 406 
 407         case 8: /* Max Address */
 408 
 409             Descriptor->Address32.Maximum =
 410                 (UINT32) InitializerOp->Asl.Value.Integer;
 411             RsCreateDwordField (InitializerOp, ACPI_RESTAG_MAXADDR,
 412                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Maximum));
 413             MaxOp = InitializerOp;
 414             break;
 415 
 416         case 9: /* Translation Offset */
 417 
 418             Descriptor->Address32.TranslationOffset =
 419                 (UINT32) InitializerOp->Asl.Value.Integer;
 420             RsCreateDwordField (InitializerOp, ACPI_RESTAG_TRANSLATION,
 421                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.TranslationOffset));
 422             break;
 423 
 424         case 10: /* Address Length */
 425 
 426             Descriptor->Address32.AddressLength =
 427                 (UINT32) InitializerOp->Asl.Value.Integer;
 428             RsCreateDwordField (InitializerOp, ACPI_RESTAG_LENGTH,
 429                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.AddressLength));
 430             LengthOp = InitializerOp;
 431             break;
 432 
 433         case 11: /* ResSourceIndex [Optional Field - BYTE] */
 434 
 435             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
 436             {
 437                 OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer;
 438                 OptionIndex++;
 439                 Descriptor->Address32.ResourceLength++;
 440                 ResSourceIndex = TRUE;
 441             }
 442             break;
 443 
 444         case 12: /* ResSource [Optional Field - STRING] */
 445 
 446             if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
 447                 (InitializerOp->Asl.Value.String))
 448             {
 449                 if (StringLength)
 450                 {
 451                     Descriptor->Address32.ResourceLength = (UINT16)
 452                         (Descriptor->Address32.ResourceLength + StringLength);
 453 
 454                     strcpy ((char *)
 455                         &OptionalFields[OptionIndex],
 456                         InitializerOp->Asl.Value.String);
 457 
 458                     /* ResourceSourceIndex must also be valid */
 459 
 460                     if (!ResSourceIndex)
 461                     {
 462                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
 463                             InitializerOp, NULL);
 464                     }
 465                 }
 466             }
 467 
 468 #if 0
 469             /*
 470              * Not a valid ResourceSource, ResourceSourceIndex must also
 471              * be invalid
 472              */
 473             else if (ResSourceIndex)
 474             {
 475                 AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
 476                     InitializerOp, NULL);
 477             }
 478 #endif
 479             break;
 480 
 481         case 13: /* ResourceTag */
 482 
 483             UtAttachNamepathToOwner (Op, InitializerOp);
 484             break;
 485 
 486 
 487         case 14: /* Address Range */
 488 
 489             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 3, 0);
 490             RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMATTRIBUTES,
 491                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 3, 2);
 492             break;
 493 
 494         case 15: /* Type */
 495 
 496             RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 5, 0);
 497             RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE,
 498                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 5);
 499             break;
 500 
 501         default:
 502 
 503             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
 504             break;
 505         }
 506 
 507         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
 508     }
 509 
 510     /* Validate the Min/Max/Len/Gran values */
 511 
 512     RsLargeAddressCheck (
 513         (UINT64) Descriptor->Address32.Minimum,
 514         (UINT64) Descriptor->Address32.Maximum,
 515         (UINT64) Descriptor->Address32.AddressLength,
 516         (UINT64) Descriptor->Address32.Granularity,
 517         Descriptor->Address32.Flags,
 518         MinOp, MaxOp, LengthOp, GranOp, Op);
 519 
 520     Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS32) +
 521                             OptionIndex + StringLength;
 522     return (Rnode);
 523 }
 524 
 525 
 526 /*******************************************************************************
 527  *
 528  * FUNCTION:    RsDoDwordSpaceDescriptor
 529  *
 530  * PARAMETERS:  Op                  - Parent resource descriptor parse node
 531  *              CurrentByteOffset   - Offset into the resource template AML
 532  *                                    buffer (to track references to the desc)
 533  *
 534  * RETURN:      Completed resource node
 535  *
 536  * DESCRIPTION: Construct a long "DwordSpace" descriptor
 537  *
 538  ******************************************************************************/
 539 
 540 ASL_RESOURCE_NODE *
 541 RsDoDwordSpaceDescriptor (
 542     ACPI_PARSE_OBJECT       *Op,
 543     UINT32                  CurrentByteOffset)
 544 {
 545     AML_RESOURCE            *Descriptor;
 546     ACPI_PARSE_OBJECT       *InitializerOp;
 547     ACPI_PARSE_OBJECT       *MinOp = NULL;
 548     ACPI_PARSE_OBJECT       *MaxOp = NULL;
 549     ACPI_PARSE_OBJECT       *LengthOp = NULL;
 550     ACPI_PARSE_OBJECT       *GranOp = NULL;
 551     ASL_RESOURCE_NODE       *Rnode;
 552     UINT8                   *OptionalFields;
 553     UINT16                  StringLength = 0;
 554     UINT32                  OptionIndex = 0;
 555     UINT32                  i;
 556     BOOLEAN                 ResSourceIndex = FALSE;
 557 
 558 
 559     InitializerOp = Op->Asl.Child;
 560     StringLength = RsGetStringDataLength (InitializerOp);
 561 
 562     Rnode = RsAllocateResourceNode (
 563                 sizeof (AML_RESOURCE_ADDRESS32) + 1 + StringLength);
 564 
 565     Descriptor = Rnode->Buffer;
 566     Descriptor->Address32.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS32;
 567 
 568     /*
 569      * Initial descriptor length -- may be enlarged if there are
 570      * optional fields present
 571      */
 572     OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS32);
 573     Descriptor->Address32.ResourceLength = (UINT16)
 574         (sizeof (AML_RESOURCE_ADDRESS32) -
 575          sizeof (AML_RESOURCE_LARGE_HEADER));
 576 
 577     /* Process all child initialization nodes */
 578 
 579     for (i = 0; InitializerOp; i++)
 580     {
 581         switch (i)
 582         {
 583         case 0: /* Resource Type */
 584 
 585             Descriptor->Address32.ResourceType =
 586                 (UINT8) InitializerOp->Asl.Value.Integer;
 587             break;
 588 
 589         case 1: /* Resource Usage */
 590 
 591             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 0, 1);
 592             break;
 593 
 594         case 2: /* DecodeType */
 595 
 596             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 1, 0);
 597             RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE,
 598                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 1);
 599             break;
 600 
 601         case 3: /* MinType */
 602 
 603             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 2, 0);
 604             RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE,
 605                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 2);
 606             break;
 607 
 608         case 4: /* MaxType */
 609 
 610             RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 3, 0);
 611             RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE,
 612                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 3);
 613             break;
 614 
 615         case 5: /* Type-Specific flags */
 616 
 617             Descriptor->Address32.SpecificFlags =
 618                 (UINT8) InitializerOp->Asl.Value.Integer;
 619             break;
 620 
 621         case 6: /* Address Granularity */
 622 
 623             Descriptor->Address32.Granularity =
 624                 (UINT32) InitializerOp->Asl.Value.Integer;
 625             RsCreateDwordField (InitializerOp, ACPI_RESTAG_GRANULARITY,
 626                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Granularity));
 627             GranOp = InitializerOp;
 628             break;
 629 
 630         case 7: /* Min Address */
 631 
 632             Descriptor->Address32.Minimum =
 633                 (UINT32) InitializerOp->Asl.Value.Integer;
 634             RsCreateDwordField (InitializerOp, ACPI_RESTAG_MINADDR,
 635                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Minimum));
 636             MinOp = InitializerOp;
 637             break;
 638 
 639         case 8: /* Max Address */
 640 
 641             Descriptor->Address32.Maximum =
 642                 (UINT32) InitializerOp->Asl.Value.Integer;
 643             RsCreateDwordField (InitializerOp, ACPI_RESTAG_MAXADDR,
 644                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Maximum));
 645             MaxOp = InitializerOp;
 646             break;
 647 
 648         case 9: /* Translation Offset */
 649 
 650             Descriptor->Address32.TranslationOffset =
 651                 (UINT32) InitializerOp->Asl.Value.Integer;
 652             RsCreateDwordField (InitializerOp, ACPI_RESTAG_TRANSLATION,
 653                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.TranslationOffset));
 654             break;
 655 
 656         case 10: /* Address Length */
 657 
 658             Descriptor->Address32.AddressLength =
 659                 (UINT32) InitializerOp->Asl.Value.Integer;
 660             RsCreateDwordField (InitializerOp, ACPI_RESTAG_LENGTH,
 661                 CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.AddressLength));
 662             LengthOp = InitializerOp;
 663             break;
 664 
 665         case 11: /* ResSourceIndex [Optional Field - BYTE] */
 666 
 667             if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
 668             {
 669                 OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer;
 670                 OptionIndex++;
 671                 Descriptor->Address32.ResourceLength++;
 672                 ResSourceIndex = TRUE;
 673             }
 674             break;
 675 
 676         case 12: /* ResSource [Optional Field - STRING] */
 677 
 678             if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
 679                 (InitializerOp->Asl.Value.String))
 680             {
 681                 if (StringLength)
 682                 {
 683                     Descriptor->Address32.ResourceLength = (UINT16)
 684                         (Descriptor->Address32.ResourceLength + StringLength);
 685 
 686                     strcpy ((char *)
 687                         &OptionalFields[OptionIndex],
 688                         InitializerOp->Asl.Value.String);
 689 
 690                     /* ResourceSourceIndex must also be valid */
 691 
 692                     if (!ResSourceIndex)
 693                     {
 694                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
 695                             InitializerOp, NULL);
 696                     }
 697                 }
 698             }
 699 
 700 #if 0
 701             /*
 702              * Not a valid ResourceSource, ResourceSourceIndex must also
 703              * be invalid
 704              */
 705             else if (ResSourceIndex)
 706             {
 707                 AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
 708                     InitializerOp, NULL);
 709             }
 710 #endif
 711             break;
 712 
 713         case 13: /* ResourceTag */
 714 
 715             UtAttachNamepathToOwner (Op, InitializerOp);
 716             break;
 717 
 718         default:
 719 
 720             AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST,
 721                 InitializerOp, NULL);
 722             break;
 723         }
 724 
 725         InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
 726     }
 727 
 728     /* Validate the Min/Max/Len/Gran values */
 729 
 730     RsLargeAddressCheck (
 731         (UINT64) Descriptor->Address32.Minimum,
 732         (UINT64) Descriptor->Address32.Maximum,
 733         (UINT64) Descriptor->Address32.AddressLength,
 734         (UINT64) Descriptor->Address32.Granularity,
 735         Descriptor->Address32.Flags,
 736         MinOp, MaxOp, LengthOp, GranOp, Op);
 737 
 738     Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS32) +
 739                             OptionIndex + StringLength;
 740     return (Rnode);
 741 }