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 - 2015, 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 #include "acpi.h" 117 #include "accommon.h" 118 #include "acresrc.h" 119 120 121 #define _COMPONENT ACPI_UTILITIES 122 ACPI_MODULE_NAME ("utresrc") 123 124 125 #if defined(ACPI_DEBUG_OUTPUT) || defined (ACPI_DISASSEMBLER) || defined (ACPI_DEBUGGER) 126 127 /* 128 * Strings used to decode resource descriptors. 129 * Used by both the disassembler and the debugger resource dump routines 130 */ 131 const char *AcpiGbl_BmDecode[] = 132 { 133 "NotBusMaster", 134 "BusMaster" 135 }; 136 137 const char *AcpiGbl_ConfigDecode[] = 138 { 139 "0 - Good Configuration", 140 "1 - Acceptable Configuration", 141 "2 - Suboptimal Configuration", 142 "3 - ***Invalid Configuration***", 143 }; 144 145 const char *AcpiGbl_ConsumeDecode[] = 146 { 147 "ResourceProducer", 148 "ResourceConsumer" 149 }; 150 151 const char *AcpiGbl_DecDecode[] = 152 { 153 "PosDecode", 154 "SubDecode" 155 }; 156 157 const char *AcpiGbl_HeDecode[] = 158 { 159 "Level", 160 "Edge" 161 }; 162 163 const char *AcpiGbl_IoDecode[] = 164 { 165 "Decode10", 166 "Decode16" 167 }; 168 169 const char *AcpiGbl_LlDecode[] = 170 { 171 "ActiveHigh", 172 "ActiveLow", 173 "ActiveBoth", 174 "Reserved" 175 }; 176 177 const char *AcpiGbl_MaxDecode[] = 178 { 179 "MaxNotFixed", 180 "MaxFixed" 181 }; 182 183 const char *AcpiGbl_MemDecode[] = 184 { 185 "NonCacheable", 186 "Cacheable", 187 "WriteCombining", 188 "Prefetchable" 189 }; 190 191 const char *AcpiGbl_MinDecode[] = 192 { 193 "MinNotFixed", 194 "MinFixed" 195 }; 196 197 const char *AcpiGbl_MtpDecode[] = 198 { 199 "AddressRangeMemory", 200 "AddressRangeReserved", 201 "AddressRangeACPI", 202 "AddressRangeNVS" 203 }; 204 205 const char *AcpiGbl_RngDecode[] = 206 { 207 "InvalidRanges", 208 "NonISAOnlyRanges", 209 "ISAOnlyRanges", 210 "EntireRange" 211 }; 212 213 const char *AcpiGbl_RwDecode[] = 214 { 215 "ReadOnly", 216 "ReadWrite" 217 }; 218 219 const char *AcpiGbl_ShrDecode[] = 220 { 221 "Exclusive", 222 "Shared", 223 "ExclusiveAndWake", /* ACPI 5.0 */ 224 "SharedAndWake" /* ACPI 5.0 */ 225 }; 226 227 const char *AcpiGbl_SizDecode[] = 228 { 229 "Transfer8", 230 "Transfer8_16", 231 "Transfer16", 232 "InvalidSize" 233 }; 234 235 const char *AcpiGbl_TrsDecode[] = 236 { 237 "DenseTranslation", 238 "SparseTranslation" 239 }; 240 241 const char *AcpiGbl_TtpDecode[] = 242 { 243 "TypeStatic", 244 "TypeTranslation" 245 }; 246 247 const char *AcpiGbl_TypDecode[] = 248 { 249 "Compatibility", 250 "TypeA", 251 "TypeB", 252 "TypeF" 253 }; 254 255 const char *AcpiGbl_PpcDecode[] = 256 { 257 "PullDefault", 258 "PullUp", 259 "PullDown", 260 "PullNone" 261 }; 262 263 const char *AcpiGbl_IorDecode[] = 264 { 265 "IoRestrictionNone", 266 "IoRestrictionInputOnly", 267 "IoRestrictionOutputOnly", 268 "IoRestrictionNoneAndPreserve" 269 }; 270 271 const char *AcpiGbl_DtsDecode[] = 272 { 273 "Width8bit", 274 "Width16bit", 275 "Width32bit", 276 "Width64bit", 277 "Width128bit", 278 "Width256bit", 279 }; 280 281 /* GPIO connection type */ 282 283 const char *AcpiGbl_CtDecode[] = 284 { 285 "Interrupt", 286 "I/O" 287 }; 288 289 /* Serial bus type */ 290 291 const char *AcpiGbl_SbtDecode[] = 292 { 293 "/* UNKNOWN serial bus type */", 294 "I2C", 295 "SPI", 296 "UART" 297 }; 298 299 /* I2C serial bus access mode */ 300 301 const char *AcpiGbl_AmDecode[] = 302 { 303 "AddressingMode7Bit", 304 "AddressingMode10Bit" 305 }; 306 307 /* I2C serial bus slave mode */ 308 309 const char *AcpiGbl_SmDecode[] = 310 { 311 "ControllerInitiated", 312 "DeviceInitiated" 313 }; 314 315 /* SPI serial bus wire mode */ 316 317 const char *AcpiGbl_WmDecode[] = 318 { 319 "FourWireMode", 320 "ThreeWireMode" 321 }; 322 323 /* SPI serial clock phase */ 324 325 const char *AcpiGbl_CphDecode[] = 326 { 327 "ClockPhaseFirst", 328 "ClockPhaseSecond" 329 }; 330 331 /* SPI serial bus clock polarity */ 332 333 const char *AcpiGbl_CpoDecode[] = 334 { 335 "ClockPolarityLow", 336 "ClockPolarityHigh" 337 }; 338 339 /* SPI serial bus device polarity */ 340 341 const char *AcpiGbl_DpDecode[] = 342 { 343 "PolarityLow", 344 "PolarityHigh" 345 }; 346 347 /* UART serial bus endian */ 348 349 const char *AcpiGbl_EdDecode[] = 350 { 351 "LittleEndian", 352 "BigEndian" 353 }; 354 355 /* UART serial bus bits per byte */ 356 357 const char *AcpiGbl_BpbDecode[] = 358 { 359 "DataBitsFive", 360 "DataBitsSix", 361 "DataBitsSeven", 362 "DataBitsEight", 363 "DataBitsNine", 364 "/* UNKNOWN Bits per byte */", 365 "/* UNKNOWN Bits per byte */", 366 "/* UNKNOWN Bits per byte */" 367 }; 368 369 /* UART serial bus stop bits */ 370 371 const char *AcpiGbl_SbDecode[] = 372 { 373 "StopBitsZero", 374 "StopBitsOne", 375 "StopBitsOnePlusHalf", 376 "StopBitsTwo" 377 }; 378 379 /* UART serial bus flow control */ 380 381 const char *AcpiGbl_FcDecode[] = 382 { 383 "FlowControlNone", 384 "FlowControlHardware", 385 "FlowControlXON", 386 "/* UNKNOWN flow control keyword */" 387 }; 388 389 /* UART serial bus parity type */ 390 391 const char *AcpiGbl_PtDecode[] = 392 { 393 "ParityTypeNone", 394 "ParityTypeEven", 395 "ParityTypeOdd", 396 "ParityTypeMark", 397 "ParityTypeSpace", 398 "/* UNKNOWN parity keyword */", 399 "/* UNKNOWN parity keyword */", 400 "/* UNKNOWN parity keyword */" 401 }; 402 403 #endif 404 405 406 /* 407 * Base sizes of the raw AML resource descriptors, indexed by resource type. 408 * Zero indicates a reserved (and therefore invalid) resource type. 409 */ 410 const UINT8 AcpiGbl_ResourceAmlSizes[] = 411 { 412 /* Small descriptors */ 413 414 0, 415 0, 416 0, 417 0, 418 ACPI_AML_SIZE_SMALL (AML_RESOURCE_IRQ), 419 ACPI_AML_SIZE_SMALL (AML_RESOURCE_DMA), 420 ACPI_AML_SIZE_SMALL (AML_RESOURCE_START_DEPENDENT), 421 ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_DEPENDENT), 422 ACPI_AML_SIZE_SMALL (AML_RESOURCE_IO), 423 ACPI_AML_SIZE_SMALL (AML_RESOURCE_FIXED_IO), 424 ACPI_AML_SIZE_SMALL (AML_RESOURCE_FIXED_DMA), 425 0, 426 0, 427 0, 428 ACPI_AML_SIZE_SMALL (AML_RESOURCE_VENDOR_SMALL), 429 ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_TAG), 430 431 /* Large descriptors */ 432 433 0, 434 ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY24), 435 ACPI_AML_SIZE_LARGE (AML_RESOURCE_GENERIC_REGISTER), 436 0, 437 ACPI_AML_SIZE_LARGE (AML_RESOURCE_VENDOR_LARGE), 438 ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY32), 439 ACPI_AML_SIZE_LARGE (AML_RESOURCE_FIXED_MEMORY32), 440 ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS32), 441 ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS16), 442 ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_IRQ), 443 ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS64), 444 ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_ADDRESS64), 445 ACPI_AML_SIZE_LARGE (AML_RESOURCE_GPIO), 446 0, 447 ACPI_AML_SIZE_LARGE (AML_RESOURCE_COMMON_SERIALBUS), 448 }; 449 450 const UINT8 AcpiGbl_ResourceAmlSerialBusSizes[] = 451 { 452 0, 453 ACPI_AML_SIZE_LARGE (AML_RESOURCE_I2C_SERIALBUS), 454 ACPI_AML_SIZE_LARGE (AML_RESOURCE_SPI_SERIALBUS), 455 ACPI_AML_SIZE_LARGE (AML_RESOURCE_UART_SERIALBUS), 456 }; 457 458 459 /* 460 * Resource types, used to validate the resource length field. 461 * The length of fixed-length types must match exactly, variable 462 * lengths must meet the minimum required length, etc. 463 * Zero indicates a reserved (and therefore invalid) resource type. 464 */ 465 static const UINT8 AcpiGbl_ResourceTypes[] = 466 { 467 /* Small descriptors */ 468 469 0, 470 0, 471 0, 472 0, 473 ACPI_SMALL_VARIABLE_LENGTH, /* 04 IRQ */ 474 ACPI_FIXED_LENGTH, /* 05 DMA */ 475 ACPI_SMALL_VARIABLE_LENGTH, /* 06 StartDependentFunctions */ 476 ACPI_FIXED_LENGTH, /* 07 EndDependentFunctions */ 477 ACPI_FIXED_LENGTH, /* 08 IO */ 478 ACPI_FIXED_LENGTH, /* 09 FixedIO */ 479 ACPI_FIXED_LENGTH, /* 0A FixedDMA */ 480 0, 481 0, 482 0, 483 ACPI_VARIABLE_LENGTH, /* 0E VendorShort */ 484 ACPI_FIXED_LENGTH, /* 0F EndTag */ 485 486 /* Large descriptors */ 487 488 0, 489 ACPI_FIXED_LENGTH, /* 01 Memory24 */ 490 ACPI_FIXED_LENGTH, /* 02 GenericRegister */ 491 0, 492 ACPI_VARIABLE_LENGTH, /* 04 VendorLong */ 493 ACPI_FIXED_LENGTH, /* 05 Memory32 */ 494 ACPI_FIXED_LENGTH, /* 06 Memory32Fixed */ 495 ACPI_VARIABLE_LENGTH, /* 07 Dword* address */ 496 ACPI_VARIABLE_LENGTH, /* 08 Word* address */ 497 ACPI_VARIABLE_LENGTH, /* 09 ExtendedIRQ */ 498 ACPI_VARIABLE_LENGTH, /* 0A Qword* address */ 499 ACPI_FIXED_LENGTH, /* 0B Extended* address */ 500 ACPI_VARIABLE_LENGTH, /* 0C Gpio* */ 501 0, 502 ACPI_VARIABLE_LENGTH /* 0E *SerialBus */ 503 }; 504 505 506 /******************************************************************************* 507 * 508 * FUNCTION: AcpiUtWalkAmlResources 509 * 510 * PARAMETERS: WalkState - Current walk info 511 * PARAMETERS: Aml - Pointer to the raw AML resource template 512 * AmlLength - Length of the entire template 513 * UserFunction - Called once for each descriptor found. If 514 * NULL, a pointer to the EndTag is returned 515 * Context - Passed to UserFunction 516 * 517 * RETURN: Status 518 * 519 * DESCRIPTION: Walk a raw AML resource list(buffer). User function called 520 * once for each resource found. 521 * 522 ******************************************************************************/ 523 524 ACPI_STATUS 525 AcpiUtWalkAmlResources ( 526 ACPI_WALK_STATE *WalkState, 527 UINT8 *Aml, 528 ACPI_SIZE AmlLength, 529 ACPI_WALK_AML_CALLBACK UserFunction, 530 void **Context) 531 { 532 ACPI_STATUS Status; 533 UINT8 *EndAml; 534 UINT8 ResourceIndex; 535 UINT32 Length; 536 UINT32 Offset = 0; 537 UINT8 EndTag[2] = {0x79, 0x00}; 538 539 540 ACPI_FUNCTION_TRACE (UtWalkAmlResources); 541 542 543 /* The absolute minimum resource template is one EndTag descriptor */ 544 545 if (AmlLength < sizeof (AML_RESOURCE_END_TAG)) 546 { 547 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 548 } 549 550 /* Point to the end of the resource template buffer */ 551 552 EndAml = Aml + AmlLength; 553 554 /* Walk the byte list, abort on any invalid descriptor type or length */ 555 556 while (Aml < EndAml) 557 { 558 /* Validate the Resource Type and Resource Length */ 559 560 Status = AcpiUtValidateResource (WalkState, Aml, &ResourceIndex); 561 if (ACPI_FAILURE (Status)) 562 { 563 /* 564 * Exit on failure. Cannot continue because the descriptor length 565 * may be bogus also. 566 */ 567 return_ACPI_STATUS (Status); 568 } 569 570 /* Get the length of this descriptor */ 571 572 Length = AcpiUtGetDescriptorLength (Aml); 573 574 /* Invoke the user function */ 575 576 if (UserFunction) 577 { 578 Status = UserFunction (Aml, Length, Offset, ResourceIndex, Context); 579 if (ACPI_FAILURE (Status)) 580 { 581 return_ACPI_STATUS (Status); 582 } 583 } 584 585 /* An EndTag descriptor terminates this resource template */ 586 587 if (AcpiUtGetResourceType (Aml) == ACPI_RESOURCE_NAME_END_TAG) 588 { 589 /* 590 * There must be at least one more byte in the buffer for 591 * the 2nd byte of the EndTag 592 */ 593 if ((Aml + 1) >= EndAml) 594 { 595 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 596 } 597 598 /* Return the pointer to the EndTag if requested */ 599 600 if (!UserFunction) 601 { 602 *Context = Aml; 603 } 604 605 /* Normal exit */ 606 607 return_ACPI_STATUS (AE_OK); 608 } 609 610 Aml += Length; 611 Offset += Length; 612 } 613 614 /* Did not find an EndTag descriptor */ 615 616 if (UserFunction) 617 { 618 /* Insert an EndTag anyway. AcpiRsGetListLength always leaves room */ 619 620 (void) AcpiUtValidateResource (WalkState, EndTag, &ResourceIndex); 621 Status = UserFunction (EndTag, 2, Offset, ResourceIndex, Context); 622 if (ACPI_FAILURE (Status)) 623 { 624 return_ACPI_STATUS (Status); 625 } 626 } 627 628 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 629 } 630 631 632 /******************************************************************************* 633 * 634 * FUNCTION: AcpiUtValidateResource 635 * 636 * PARAMETERS: WalkState - Current walk info 637 * Aml - Pointer to the raw AML resource descriptor 638 * ReturnIndex - Where the resource index is returned. NULL 639 * if the index is not required. 640 * 641 * RETURN: Status, and optionally the Index into the global resource tables 642 * 643 * DESCRIPTION: Validate an AML resource descriptor by checking the Resource 644 * Type and Resource Length. Returns an index into the global 645 * resource information/dispatch tables for later use. 646 * 647 ******************************************************************************/ 648 649 ACPI_STATUS 650 AcpiUtValidateResource ( 651 ACPI_WALK_STATE *WalkState, 652 void *Aml, 653 UINT8 *ReturnIndex) 654 { 655 AML_RESOURCE *AmlResource; 656 UINT8 ResourceType; 657 UINT8 ResourceIndex; 658 ACPI_RS_LENGTH ResourceLength; 659 ACPI_RS_LENGTH MinimumResourceLength; 660 661 662 ACPI_FUNCTION_ENTRY (); 663 664 665 /* 666 * 1) Validate the ResourceType field (Byte 0) 667 */ 668 ResourceType = ACPI_GET8 (Aml); 669 670 /* 671 * Byte 0 contains the descriptor name (Resource Type) 672 * Examine the large/small bit in the resource header 673 */ 674 if (ResourceType & ACPI_RESOURCE_NAME_LARGE) 675 { 676 /* Verify the large resource type (name) against the max */ 677 678 if (ResourceType > ACPI_RESOURCE_NAME_LARGE_MAX) 679 { 680 goto InvalidResource; 681 } 682 683 /* 684 * Large Resource Type -- bits 6:0 contain the name 685 * Translate range 0x80-0x8B to index range 0x10-0x1B 686 */ 687 ResourceIndex = (UINT8) (ResourceType - 0x70); 688 } 689 else 690 { 691 /* 692 * Small Resource Type -- bits 6:3 contain the name 693 * Shift range to index range 0x00-0x0F 694 */ 695 ResourceIndex = (UINT8) 696 ((ResourceType & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3); 697 } 698 699 /* 700 * Check validity of the resource type, via AcpiGbl_ResourceTypes. Zero 701 * indicates an invalid resource. 702 */ 703 if (!AcpiGbl_ResourceTypes[ResourceIndex]) 704 { 705 goto InvalidResource; 706 } 707 708 /* 709 * Validate the ResourceLength field. This ensures that the length 710 * is at least reasonable, and guarantees that it is non-zero. 711 */ 712 ResourceLength = AcpiUtGetResourceLength (Aml); 713 MinimumResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex]; 714 715 /* Validate based upon the type of resource - fixed length or variable */ 716 717 switch (AcpiGbl_ResourceTypes[ResourceIndex]) 718 { 719 case ACPI_FIXED_LENGTH: 720 721 /* Fixed length resource, length must match exactly */ 722 723 if (ResourceLength != MinimumResourceLength) 724 { 725 goto BadResourceLength; 726 } 727 break; 728 729 case ACPI_VARIABLE_LENGTH: 730 731 /* Variable length resource, length must be at least the minimum */ 732 733 if (ResourceLength < MinimumResourceLength) 734 { 735 goto BadResourceLength; 736 } 737 break; 738 739 case ACPI_SMALL_VARIABLE_LENGTH: 740 741 /* Small variable length resource, length can be (Min) or (Min-1) */ 742 743 if ((ResourceLength > MinimumResourceLength) || 744 (ResourceLength < (MinimumResourceLength - 1))) 745 { 746 goto BadResourceLength; 747 } 748 break; 749 750 default: 751 752 /* Shouldn't happen (because of validation earlier), but be sure */ 753 754 goto InvalidResource; 755 } 756 757 AmlResource = ACPI_CAST_PTR (AML_RESOURCE, Aml); 758 if (ResourceType == ACPI_RESOURCE_NAME_SERIAL_BUS) 759 { 760 /* Validate the BusType field */ 761 762 if ((AmlResource->CommonSerialBus.Type == 0) || 763 (AmlResource->CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE)) 764 { 765 if (WalkState) 766 { 767 ACPI_ERROR ((AE_INFO, 768 "Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X", 769 AmlResource->CommonSerialBus.Type)); 770 } 771 return (AE_AML_INVALID_RESOURCE_TYPE); 772 } 773 } 774 775 /* Optionally return the resource table index */ 776 777 if (ReturnIndex) 778 { 779 *ReturnIndex = ResourceIndex; 780 } 781 782 return (AE_OK); 783 784 785 InvalidResource: 786 787 if (WalkState) 788 { 789 ACPI_ERROR ((AE_INFO, 790 "Invalid/unsupported resource descriptor: Type 0x%2.2X", 791 ResourceType)); 792 } 793 return (AE_AML_INVALID_RESOURCE_TYPE); 794 795 BadResourceLength: 796 797 if (WalkState) 798 { 799 ACPI_ERROR ((AE_INFO, 800 "Invalid resource descriptor length: Type " 801 "0x%2.2X, Length 0x%4.4X, MinLength 0x%4.4X", 802 ResourceType, ResourceLength, MinimumResourceLength)); 803 } 804 return (AE_AML_BAD_RESOURCE_LENGTH); 805 } 806 807 808 /******************************************************************************* 809 * 810 * FUNCTION: AcpiUtGetResourceType 811 * 812 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor 813 * 814 * RETURN: The Resource Type with no extraneous bits (except the 815 * Large/Small descriptor bit -- this is left alone) 816 * 817 * DESCRIPTION: Extract the Resource Type/Name from the first byte of 818 * a resource descriptor. 819 * 820 ******************************************************************************/ 821 822 UINT8 823 AcpiUtGetResourceType ( 824 void *Aml) 825 { 826 ACPI_FUNCTION_ENTRY (); 827 828 829 /* 830 * Byte 0 contains the descriptor name (Resource Type) 831 * Examine the large/small bit in the resource header 832 */ 833 if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE) 834 { 835 /* Large Resource Type -- bits 6:0 contain the name */ 836 837 return (ACPI_GET8 (Aml)); 838 } 839 else 840 { 841 /* Small Resource Type -- bits 6:3 contain the name */ 842 843 return ((UINT8) (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_SMALL_MASK)); 844 } 845 } 846 847 848 /******************************************************************************* 849 * 850 * FUNCTION: AcpiUtGetResourceLength 851 * 852 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor 853 * 854 * RETURN: Byte Length 855 * 856 * DESCRIPTION: Get the "Resource Length" of a raw AML descriptor. By 857 * definition, this does not include the size of the descriptor 858 * header or the length field itself. 859 * 860 ******************************************************************************/ 861 862 UINT16 863 AcpiUtGetResourceLength ( 864 void *Aml) 865 { 866 ACPI_RS_LENGTH ResourceLength; 867 868 869 ACPI_FUNCTION_ENTRY (); 870 871 872 /* 873 * Byte 0 contains the descriptor name (Resource Type) 874 * Examine the large/small bit in the resource header 875 */ 876 if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE) 877 { 878 /* Large Resource type -- bytes 1-2 contain the 16-bit length */ 879 880 ACPI_MOVE_16_TO_16 (&ResourceLength, ACPI_ADD_PTR (UINT8, Aml, 1)); 881 882 } 883 else 884 { 885 /* Small Resource type -- bits 2:0 of byte 0 contain the length */ 886 887 ResourceLength = (UINT16) (ACPI_GET8 (Aml) & 888 ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK); 889 } 890 891 return (ResourceLength); 892 } 893 894 895 /******************************************************************************* 896 * 897 * FUNCTION: AcpiUtGetResourceHeaderLength 898 * 899 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor 900 * 901 * RETURN: Length of the AML header (depends on large/small descriptor) 902 * 903 * DESCRIPTION: Get the length of the header for this resource. 904 * 905 ******************************************************************************/ 906 907 UINT8 908 AcpiUtGetResourceHeaderLength ( 909 void *Aml) 910 { 911 ACPI_FUNCTION_ENTRY (); 912 913 914 /* Examine the large/small bit in the resource header */ 915 916 if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE) 917 { 918 return (sizeof (AML_RESOURCE_LARGE_HEADER)); 919 } 920 else 921 { 922 return (sizeof (AML_RESOURCE_SMALL_HEADER)); 923 } 924 } 925 926 927 /******************************************************************************* 928 * 929 * FUNCTION: AcpiUtGetDescriptorLength 930 * 931 * PARAMETERS: Aml - Pointer to the raw AML resource descriptor 932 * 933 * RETURN: Byte length 934 * 935 * DESCRIPTION: Get the total byte length of a raw AML descriptor, including the 936 * length of the descriptor header and the length field itself. 937 * Used to walk descriptor lists. 938 * 939 ******************************************************************************/ 940 941 UINT32 942 AcpiUtGetDescriptorLength ( 943 void *Aml) 944 { 945 ACPI_FUNCTION_ENTRY (); 946 947 948 /* 949 * Get the Resource Length (does not include header length) and add 950 * the header length (depends on if this is a small or large resource) 951 */ 952 return (AcpiUtGetResourceLength (Aml) + 953 AcpiUtGetResourceHeaderLength (Aml)); 954 } 955 956 957 /******************************************************************************* 958 * 959 * FUNCTION: AcpiUtGetResourceEndTag 960 * 961 * PARAMETERS: ObjDesc - The resource template buffer object 962 * EndTag - Where the pointer to the EndTag is returned 963 * 964 * RETURN: Status, pointer to the end tag 965 * 966 * DESCRIPTION: Find the EndTag resource descriptor in an AML resource template 967 * Note: allows a buffer length of zero. 968 * 969 ******************************************************************************/ 970 971 ACPI_STATUS 972 AcpiUtGetResourceEndTag ( 973 ACPI_OPERAND_OBJECT *ObjDesc, 974 UINT8 **EndTag) 975 { 976 ACPI_STATUS Status; 977 978 979 ACPI_FUNCTION_TRACE (UtGetResourceEndTag); 980 981 982 /* Allow a buffer length of zero */ 983 984 if (!ObjDesc->Buffer.Length) 985 { 986 *EndTag = ObjDesc->Buffer.Pointer; 987 return_ACPI_STATUS (AE_OK); 988 } 989 990 /* Validate the template and get a pointer to the EndTag */ 991 992 Status = AcpiUtWalkAmlResources (NULL, ObjDesc->Buffer.Pointer, 993 ObjDesc->Buffer.Length, NULL, (void **) EndTag); 994 995 return_ACPI_STATUS (Status); 996 } 997