1 /******************************************************************************* 2 * 3 * Module Name: utresrc - Resource management utilities 4 * 5 ******************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2014, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 *****************************************************************************/ 115 116 117 #define __UTRESRC_C__ 118 119 #include "acpi.h" 120 #include "accommon.h" 121 #include "acresrc.h" 122 123 124 #define _COMPONENT ACPI_UTILITIES 125 ACPI_MODULE_NAME ("utresrc") 126 127 128 #if defined(ACPI_DEBUG_OUTPUT) || defined (ACPI_DISASSEMBLER) || defined (ACPI_DEBUGGER) 129 130 /* 131 * Strings used to decode resource descriptors. 132 * Used by both the disassembler and the debugger resource dump routines 133 */ 134 const char *AcpiGbl_BmDecode[] = 135 { 136 "NotBusMaster", 137 "BusMaster" 138 }; 139 140 const char *AcpiGbl_ConfigDecode[] = 141 { 142 "0 - Good Configuration", 143 "1 - Acceptable Configuration", 144 "2 - Suboptimal Configuration", 145 "3 - ***Invalid Configuration***", 146 }; 147 148 const char *AcpiGbl_ConsumeDecode[] = 149 { 150 "ResourceProducer", 151 "ResourceConsumer" 152 }; 153 154 const char *AcpiGbl_DecDecode[] = 155 { 156 "PosDecode", 157 "SubDecode" 158 }; 159 160 const char *AcpiGbl_HeDecode[] = 161 { 162 "Level", 163 "Edge" 164 }; 165 166 const char *AcpiGbl_IoDecode[] = 167 { 168 "Decode10", 169 "Decode16" 170 }; 171 172 const char *AcpiGbl_LlDecode[] = 173 { 174 "ActiveHigh", 175 "ActiveLow" 176 }; 177 178 const char *AcpiGbl_MaxDecode[] = 179 { 180 "MaxNotFixed", 181 "MaxFixed" 182 }; 183 184 const char *AcpiGbl_MemDecode[] = 185 { 186 "NonCacheable", 187 "Cacheable", 188 "WriteCombining", 189 "Prefetchable" 190 }; 191 192 const char *AcpiGbl_MinDecode[] = 193 { 194 "MinNotFixed", 195 "MinFixed" 196 }; 197 198 const char *AcpiGbl_MtpDecode[] = 199 { 200 "AddressRangeMemory", 201 "AddressRangeReserved", 202 "AddressRangeACPI", 203 "AddressRangeNVS" 204 }; 205 206 const char *AcpiGbl_RngDecode[] = 207 { 208 "InvalidRanges", 209 "NonISAOnlyRanges", 210 "ISAOnlyRanges", 211 "EntireRange" 212 }; 213 214 const char *AcpiGbl_RwDecode[] = 215 { 216 "ReadOnly", 217 "ReadWrite" 218 }; 219 220 const char *AcpiGbl_ShrDecode[] = 221 { 222 "Exclusive", 223 "Shared", 224 "ExclusiveAndWake", /* ACPI 5.0 */ 225 "SharedAndWake" /* ACPI 5.0 */ 226 }; 227 228 const char *AcpiGbl_SizDecode[] = 229 { 230 "Transfer8", 231 "Transfer8_16", 232 "Transfer16", 233 "InvalidSize" 234 }; 235 236 const char *AcpiGbl_TrsDecode[] = 237 { 238 "DenseTranslation", 239 "SparseTranslation" 240 }; 241 242 const char *AcpiGbl_TtpDecode[] = 243 { 244 "TypeStatic", 245 "TypeTranslation" 246 }; 247 248 const char *AcpiGbl_TypDecode[] = 249 { 250 "Compatibility", 251 "TypeA", 252 "TypeB", 253 "TypeF" 254 }; 255 256 const char *AcpiGbl_PpcDecode[] = 257 { 258 "PullDefault", 259 "PullUp", 260 "PullDown", 261 "PullNone" 262 }; 263 264 const char *AcpiGbl_IorDecode[] = 265 { 266 "IoRestrictionNone", 267 "IoRestrictionInputOnly", 268 "IoRestrictionOutputOnly", 269 "IoRestrictionNoneAndPreserve" 270 }; 271 272 const char *AcpiGbl_DtsDecode[] = 273 { 274 "Width8bit", 275 "Width16bit", 276 "Width32bit", 277 "Width64bit", 278 "Width128bit", 279 "Width256bit", 280 }; 281 282 /* GPIO connection type */ 283 284 const char *AcpiGbl_CtDecode[] = 285 { 286 "Interrupt", 287 "I/O" 288 }; 289 290 /* Serial bus type */ 291 292 const char *AcpiGbl_SbtDecode[] = 293 { 294 "/* UNKNOWN serial bus type */", 295 "I2C", 296 "SPI", 297 "UART" 298 }; 299 300 /* I2C serial bus access mode */ 301 302 const char *AcpiGbl_AmDecode[] = 303 { 304 "AddressingMode7Bit", 305 "AddressingMode10Bit" 306 }; 307 308 /* I2C serial bus slave mode */ 309 310 const char *AcpiGbl_SmDecode[] = 311 { 312 "ControllerInitiated", 313 "DeviceInitiated" 314 }; 315 316 /* SPI serial bus wire mode */ 317 318 const char *AcpiGbl_WmDecode[] = 319 { 320 "FourWireMode", 321 "ThreeWireMode" 322 }; 323 324 /* SPI serial clock phase */ 325 326 const char *AcpiGbl_CphDecode[] = 327 { 328 "ClockPhaseFirst", 329 "ClockPhaseSecond" 330 }; 331 332 /* SPI serial bus clock polarity */ 333 334 const char *AcpiGbl_CpoDecode[] = 335 { 336 "ClockPolarityLow", 337 "ClockPolarityHigh" 338 }; 339 340 /* SPI serial bus device polarity */ 341 342 const char *AcpiGbl_DpDecode[] = 343 { 344 "PolarityLow", 345 "PolarityHigh" 346 }; 347 348 /* UART serial bus endian */ 349 350 const char *AcpiGbl_EdDecode[] = 351 { 352 "LittleEndian", 353 "BigEndian" 354 }; 355 356 /* UART serial bus bits per byte */ 357 358 const char *AcpiGbl_BpbDecode[] = 359 { 360 "DataBitsFive", 361 "DataBitsSix", 362 "DataBitsSeven", 363 "DataBitsEight", 364 "DataBitsNine", 365 "/* UNKNOWN Bits per byte */", 366 "/* UNKNOWN Bits per byte */", 367 "/* UNKNOWN Bits per byte */" 368 }; 369 370 /* UART serial bus stop bits */ 371 372 const char *AcpiGbl_SbDecode[] = 373 { 374 "StopBitsNone", 375 "StopBitsOne", 376 "StopBitsOnePlusHalf", 377 "StopBitsTwo" 378 }; 379 380 /* UART serial bus flow control */ 381 382 const char *AcpiGbl_FcDecode[] = 383 { 384 "FlowControlNone", 385 "FlowControlHardware", 386 "FlowControlXON", 387 "/* UNKNOWN flow control keyword */" 388 }; 389 390 /* UART serial bus parity type */ 391 392 const char *AcpiGbl_PtDecode[] = 393 { 394 "ParityTypeNone", 395 "ParityTypeEven", 396 "ParityTypeOdd", 397 "ParityTypeMark", 398 "ParityTypeSpace", 399 "/* UNKNOWN parity keyword */", 400 "/* UNKNOWN parity keyword */", 401 "/* UNKNOWN parity keyword */" 402 }; 403 404 #endif 405 406 407 /* 408 * Base sizes of the raw AML resource descriptors, indexed by resource type. 409 * Zero indicates a reserved (and therefore invalid) resource type. 410 */ 411 const UINT8 AcpiGbl_ResourceAmlSizes[] = 412 { 413 /* Small descriptors */ 414 415 0, 416 0, 417 0, 418 0, 419 ACPI_AML_SIZE_SMALL (AML_RESOURCE_IRQ), 420 ACPI_AML_SIZE_SMALL (AML_RESOURCE_DMA), 421 ACPI_AML_SIZE_SMALL (AML_RESOURCE_START_DEPENDENT), 422 ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_DEPENDENT), 423 ACPI_AML_SIZE_SMALL (AML_RESOURCE_IO), 424 ACPI_AML_SIZE_SMALL (AML_RESOURCE_FIXED_IO), 425 ACPI_AML_SIZE_SMALL (AML_RESOURCE_FIXED_DMA), 426 0, 427 0, 428 0, 429 ACPI_AML_SIZE_SMALL (AML_RESOURCE_VENDOR_SMALL), 430 ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_TAG), 431 432 /* Large descriptors */ 433 434 0, 435 ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY24), 436 ACPI_AML_SIZE_LARGE (AML_RESOURCE_GENERIC_REGISTER), 437 0, 438 ACPI_AML_SIZE_LARGE (AML_RESOURCE_VENDOR_LARGE), 439 ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY32), 440 ACPI_AML_SIZE_LARGE (AML_RESOURCE_FIXED_MEMORY32), 441 ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS32), 442 ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS16), 443 ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_IRQ), 444 ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS64), 445 ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_ADDRESS64), 446 ACPI_AML_SIZE_LARGE (AML_RESOURCE_GPIO), 447 0, 448 ACPI_AML_SIZE_LARGE (AML_RESOURCE_COMMON_SERIALBUS), 449 }; 450 451 const UINT8 AcpiGbl_ResourceAmlSerialBusSizes[] = 452 { 453 0, 454 ACPI_AML_SIZE_LARGE (AML_RESOURCE_I2C_SERIALBUS), 455 ACPI_AML_SIZE_LARGE (AML_RESOURCE_SPI_SERIALBUS), 456 ACPI_AML_SIZE_LARGE (AML_RESOURCE_UART_SERIALBUS), 457 }; 458 459 460 /* 461 * Resource types, used to validate the resource length field. 462 * The length of fixed-length types must match exactly, variable 463 * lengths must meet the minimum required length, etc. 464 * Zero indicates a reserved (and therefore invalid) resource type. 465 */ 466 static const UINT8 AcpiGbl_ResourceTypes[] = 467 { 468 /* Small descriptors */ 469 470 0, 471 0, 472 0, 473 0, 474 ACPI_SMALL_VARIABLE_LENGTH, /* 04 IRQ */ 475 ACPI_FIXED_LENGTH, /* 05 DMA */ 476 ACPI_SMALL_VARIABLE_LENGTH, /* 06 StartDependentFunctions */ 477 ACPI_FIXED_LENGTH, /* 07 EndDependentFunctions */ 478 ACPI_FIXED_LENGTH, /* 08 IO */ 479 ACPI_FIXED_LENGTH, /* 09 FixedIO */ 480 ACPI_FIXED_LENGTH, /* 0A FixedDMA */ 481 0, 482 0, 483 0, 484 ACPI_VARIABLE_LENGTH, /* 0E VendorShort */ 485 ACPI_FIXED_LENGTH, /* 0F EndTag */ 486 487 /* Large descriptors */ 488 489 0, 490 ACPI_FIXED_LENGTH, /* 01 Memory24 */ 491 ACPI_FIXED_LENGTH, /* 02 GenericRegister */ 492 0, 493 ACPI_VARIABLE_LENGTH, /* 04 VendorLong */ 494 ACPI_FIXED_LENGTH, /* 05 Memory32 */ 495 ACPI_FIXED_LENGTH, /* 06 Memory32Fixed */ 496 ACPI_VARIABLE_LENGTH, /* 07 Dword* address */ 497 ACPI_VARIABLE_LENGTH, /* 08 Word* address */ 498 ACPI_VARIABLE_LENGTH, /* 09 ExtendedIRQ */ 499 ACPI_VARIABLE_LENGTH, /* 0A Qword* address */ 500 ACPI_FIXED_LENGTH, /* 0B Extended* address */ 501 ACPI_VARIABLE_LENGTH, /* 0C Gpio* */ 502 0, 503 ACPI_VARIABLE_LENGTH /* 0E *SerialBus */ 504 }; 505 506 507 /******************************************************************************* 508 * 509 * FUNCTION: AcpiUtWalkAmlResources 510 * 511 * PARAMETERS: WalkState - Current walk info 512 * PARAMETERS: Aml - Pointer to the raw AML resource template 513 * AmlLength - Length of the entire template 514 * UserFunction - Called once for each descriptor found. If 515 * NULL, a pointer to the EndTag is returned 516 * Context - Passed to UserFunction 517 * 518 * RETURN: Status 519 * 520 * DESCRIPTION: Walk a raw AML resource list(buffer). User function called 521 * once for each resource found. 522 * 523 ******************************************************************************/ 524 525 ACPI_STATUS 526 AcpiUtWalkAmlResources ( 527 ACPI_WALK_STATE *WalkState, 528 UINT8 *Aml, 529 ACPI_SIZE AmlLength, 530 ACPI_WALK_AML_CALLBACK UserFunction, 531 void **Context) 532 { 533 ACPI_STATUS Status; 534 UINT8 *EndAml; 535 UINT8 ResourceIndex; 536 UINT32 Length; 537 UINT32 Offset = 0; 538 UINT8 EndTag[2] = {0x79, 0x00}; 539 540 541 ACPI_FUNCTION_TRACE (UtWalkAmlResources); 542 543 544 /* The absolute minimum resource template is one EndTag descriptor */ 545 546 if (AmlLength < sizeof (AML_RESOURCE_END_TAG)) 547 { 548 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 549 } 550 551 /* Point to the end of the resource template buffer */ 552 553 EndAml = Aml + AmlLength; 554 555 /* Walk the byte list, abort on any invalid descriptor type or length */ 556 557 while (Aml < EndAml) 558 { 559 /* Validate the Resource Type and Resource Length */ 560 561 Status = AcpiUtValidateResource (WalkState, Aml, &ResourceIndex); 562 if (ACPI_FAILURE (Status)) 563 { 564 /* 565 * Exit on failure. Cannot continue because the descriptor length 566 * may be bogus also. 567 */ 568 return_ACPI_STATUS (Status); 569 } 570 571 /* Get the length of this descriptor */ 572 573 Length = AcpiUtGetDescriptorLength (Aml); 574 575 /* Invoke the user function */ 576 577 if (UserFunction) 578 { 579 Status = UserFunction (Aml, Length, Offset, ResourceIndex, Context); 580 if (ACPI_FAILURE (Status)) 581 { 582 return_ACPI_STATUS (Status); 583 } 584 } 585 586 /* An EndTag descriptor terminates this resource template */ 587 588 if (AcpiUtGetResourceType (Aml) == ACPI_RESOURCE_NAME_END_TAG) 589 { 590 /* 591 * There must be at least one more byte in the buffer for 592 * the 2nd byte of the EndTag 593 */ 594 if ((Aml + 1) >= EndAml) 595 { 596 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 597 } 598 599 /* Return the pointer to the EndTag if requested */ 600 601 if (!UserFunction) 602 { 603 *Context = Aml; 604 } 605 606 /* Normal exit */ 607 608 return_ACPI_STATUS (AE_OK); 609 } 610 611 Aml += Length; 612 Offset += Length; 613 } 614 615 /* Did not find an EndTag descriptor */ 616 617 if (UserFunction) 618 { 619 /* Insert an EndTag anyway. AcpiRsGetListLength always leaves room */ 620 621 (void) AcpiUtValidateResource (WalkState, EndTag, &ResourceIndex); 622 Status = UserFunction (EndTag, 2, Offset, ResourceIndex, Context); 623 if (ACPI_FAILURE (Status)) 624 { 625 return_ACPI_STATUS (Status); 626 } 627 } 628 629 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 630 } 631 632 633 /******************************************************************************* 634 * 635 * FUNCTION: AcpiUtValidateResource 636 * 637 * PARAMETERS: WalkState - Current walk info 638 * Aml - Pointer to the raw AML resource descriptor 639 * ReturnIndex - Where the resource index is returned. NULL 640 * if the index is not required. 641 * 642 * RETURN: Status, and optionally the Index into the global resource tables 643 * 644 * DESCRIPTION: Validate an AML resource descriptor by checking the Resource 645 * Type and Resource Length. Returns an index into the global 646 * resource information/dispatch tables for later use. 647 * 648 ******************************************************************************/ 649 650 ACPI_STATUS 651 AcpiUtValidateResource ( 652 ACPI_WALK_STATE *WalkState, 653 void *Aml, 654 UINT8 *ReturnIndex) 655 { 656 AML_RESOURCE *AmlResource; 657 UINT8 ResourceType; 658 UINT8 ResourceIndex; 659 ACPI_RS_LENGTH ResourceLength; 660 ACPI_RS_LENGTH MinimumResourceLength; 661 662 663 ACPI_FUNCTION_ENTRY (); 664 665 666 /* 667 * 1) Validate the ResourceType field (Byte 0) 668 */ 669 ResourceType = ACPI_GET8 (Aml); 670 671 /* 672 * Byte 0 contains the descriptor name (Resource Type) 673 * Examine the large/small bit in the resource header 674 */ 675 if (ResourceType & ACPI_RESOURCE_NAME_LARGE) 676 { 677 /* Verify the large resource type (name) against the max */ 678 679 if (ResourceType > ACPI_RESOURCE_NAME_LARGE_MAX) 680 { 681 goto InvalidResource; 682 } 683 684 /* 685 * Large Resource Type -- bits 6:0 contain the name 686 * Translate range 0x80-0x8B to index range 0x10-0x1B 687 */ 688 ResourceIndex = (UINT8) (ResourceType - 0x70); 689 } 690 else 691 { 692 /* 693 * Small Resource Type -- bits 6:3 contain the name 694 * Shift range to index range 0x00-0x0F 695 */ 696 ResourceIndex = (UINT8) 697 ((ResourceType & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3); 698 } 699 700 /* 701 * Check validity of the resource type, via AcpiGbl_ResourceTypes. Zero 702 * indicates an invalid resource. 703 */ 704 if (!AcpiGbl_ResourceTypes[ResourceIndex]) 705 { 706 goto InvalidResource; 707 } 708 709 /* 710 * Validate the ResourceLength field. This ensures that the length 711 * is at least reasonable, and guarantees that it is non-zero. 712 */ 713 ResourceLength = AcpiUtGetResourceLength (Aml); 714 MinimumResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex]; 715 716 /* Validate based upon the type of resource - fixed length or variable */ 717 718 switch (AcpiGbl_ResourceTypes[ResourceIndex]) 719 { 720 case ACPI_FIXED_LENGTH: 721 722 /* Fixed length resource, length must match exactly */ 723 724 if (ResourceLength != MinimumResourceLength) 725 { 726 goto BadResourceLength; 727 } 728 break; 729 730 case ACPI_VARIABLE_LENGTH: 731 732 /* Variable length resource, length must be at least the minimum */ 733 734 if (ResourceLength < MinimumResourceLength) 735 { 736 goto BadResourceLength; 737 } 738 break; 739 740 case ACPI_SMALL_VARIABLE_LENGTH: 741 742 /* Small variable length resource, length can be (Min) or (Min-1) */ 743 744 if ((ResourceLength > MinimumResourceLength) || 745 (ResourceLength < (MinimumResourceLength - 1))) 746 { 747 goto BadResourceLength; 748 } 749 break; 750 751 default: 752 753 /* Shouldn't happen (because of validation earlier), but be sure */ 754 755 goto InvalidResource; 756 } 757 758 AmlResource = ACPI_CAST_PTR (AML_RESOURCE, Aml); 759 if (ResourceType == ACPI_RESOURCE_NAME_SERIAL_BUS) 760 { 761 /* Validate the BusType field */ 762 763 if ((AmlResource->CommonSerialBus.Type == 0) || 764 (AmlResource->CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE)) 765 { 766 if (WalkState) 767 { 768 ACPI_ERROR ((AE_INFO, 769 "Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X", 770 AmlResource->CommonSerialBus.Type)); 771 } 772 return (AE_AML_INVALID_RESOURCE_TYPE); 773 } 774 } 775 776 /* Optionally return the resource table index */ 777 778 if (ReturnIndex) 779 { 780 *ReturnIndex = ResourceIndex; 781 } 782 783 return (AE_OK); 784 785 786 InvalidResource: 787 788 if (WalkState) 789 { 790 ACPI_ERROR ((AE_INFO, 791 "Invalid/unsupported resource descriptor: Type 0x%2.2X", 792 ResourceType)); 793 } 794 return (AE_AML_INVALID_RESOURCE_TYPE); 795 796 BadResourceLength: 797 798 if (WalkState) 799 { 800 ACPI_ERROR ((AE_INFO, 801 "Invalid resource descriptor length: Type " 802 "0x%2.2X, Length 0x%4.4X, MinLength 0x%4.4X", 803 ResourceType, ResourceLength, MinimumResourceLength)); 804 } 805 return (AE_AML_BAD_RESOURCE_LENGTH); 806 } 807 808 809 /******************************************************************************* 810 * 811 * FUNCTION: AcpiUtGetResourceType 812 * 813 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor 814 * 815 * RETURN: The Resource Type with no extraneous bits (except the 816 * Large/Small descriptor bit -- this is left alone) 817 * 818 * DESCRIPTION: Extract the Resource Type/Name from the first byte of 819 * a resource descriptor. 820 * 821 ******************************************************************************/ 822 823 UINT8 824 AcpiUtGetResourceType ( 825 void *Aml) 826 { 827 ACPI_FUNCTION_ENTRY (); 828 829 830 /* 831 * Byte 0 contains the descriptor name (Resource Type) 832 * Examine the large/small bit in the resource header 833 */ 834 if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE) 835 { 836 /* Large Resource Type -- bits 6:0 contain the name */ 837 838 return (ACPI_GET8 (Aml)); 839 } 840 else 841 { 842 /* Small Resource Type -- bits 6:3 contain the name */ 843 844 return ((UINT8) (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_SMALL_MASK)); 845 } 846 } 847 848 849 /******************************************************************************* 850 * 851 * FUNCTION: AcpiUtGetResourceLength 852 * 853 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor 854 * 855 * RETURN: Byte Length 856 * 857 * DESCRIPTION: Get the "Resource Length" of a raw AML descriptor. By 858 * definition, this does not include the size of the descriptor 859 * header or the length field itself. 860 * 861 ******************************************************************************/ 862 863 UINT16 864 AcpiUtGetResourceLength ( 865 void *Aml) 866 { 867 ACPI_RS_LENGTH ResourceLength; 868 869 870 ACPI_FUNCTION_ENTRY (); 871 872 873 /* 874 * Byte 0 contains the descriptor name (Resource Type) 875 * Examine the large/small bit in the resource header 876 */ 877 if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE) 878 { 879 /* Large Resource type -- bytes 1-2 contain the 16-bit length */ 880 881 ACPI_MOVE_16_TO_16 (&ResourceLength, ACPI_ADD_PTR (UINT8, Aml, 1)); 882 883 } 884 else 885 { 886 /* Small Resource type -- bits 2:0 of byte 0 contain the length */ 887 888 ResourceLength = (UINT16) (ACPI_GET8 (Aml) & 889 ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK); 890 } 891 892 return (ResourceLength); 893 } 894 895 896 /******************************************************************************* 897 * 898 * FUNCTION: AcpiUtGetResourceHeaderLength 899 * 900 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor 901 * 902 * RETURN: Length of the AML header (depends on large/small descriptor) 903 * 904 * DESCRIPTION: Get the length of the header for this resource. 905 * 906 ******************************************************************************/ 907 908 UINT8 909 AcpiUtGetResourceHeaderLength ( 910 void *Aml) 911 { 912 ACPI_FUNCTION_ENTRY (); 913 914 915 /* Examine the large/small bit in the resource header */ 916 917 if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE) 918 { 919 return (sizeof (AML_RESOURCE_LARGE_HEADER)); 920 } 921 else 922 { 923 return (sizeof (AML_RESOURCE_SMALL_HEADER)); 924 } 925 } 926 927 928 /******************************************************************************* 929 * 930 * FUNCTION: AcpiUtGetDescriptorLength 931 * 932 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor 933 * 934 * RETURN: Byte length 935 * 936 * DESCRIPTION: Get the total byte length of a raw AML descriptor, including the 937 * length of the descriptor header and the length field itself. 938 * Used to walk descriptor lists. 939 * 940 ******************************************************************************/ 941 942 UINT32 943 AcpiUtGetDescriptorLength ( 944 void *Aml) 945 { 946 ACPI_FUNCTION_ENTRY (); 947 948 949 /* 950 * Get the Resource Length (does not include header length) and add 951 * the header length (depends on if this is a small or large resource) 952 */ 953 return (AcpiUtGetResourceLength (Aml) + 954 AcpiUtGetResourceHeaderLength (Aml)); 955 } 956 957 958 /******************************************************************************* 959 * 960 * FUNCTION: AcpiUtGetResourceEndTag 961 * 962 * PARAMETERS: ObjDesc - The resource template buffer object 963 * EndTag - Where the pointer to the EndTag is returned 964 * 965 * RETURN: Status, pointer to the end tag 966 * 967 * DESCRIPTION: Find the EndTag resource descriptor in an AML resource template 968 * Note: allows a buffer length of zero. 969 * 970 ******************************************************************************/ 971 972 ACPI_STATUS 973 AcpiUtGetResourceEndTag ( 974 ACPI_OPERAND_OBJECT *ObjDesc, 975 UINT8 **EndTag) 976 { 977 ACPI_STATUS Status; 978 979 980 ACPI_FUNCTION_TRACE (UtGetResourceEndTag); 981 982 983 /* Allow a buffer length of zero */ 984 985 if (!ObjDesc->Buffer.Length) 986 { 987 *EndTag = ObjDesc->Buffer.Pointer; 988 return_ACPI_STATUS (AE_OK); 989 } 990 991 /* Validate the template and get a pointer to the EndTag */ 992 993 Status = AcpiUtWalkAmlResources (NULL, ObjDesc->Buffer.Pointer, 994 ObjDesc->Buffer.Length, NULL, (void **) EndTag); 995 996 return_ACPI_STATUS (Status); 997 } 998