1 /******************************************************************************* 2 * 3 * Module Name: rsmisc - Miscellaneous resource descriptors 4 * 5 ******************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2021, 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 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include <contrib/dev/acpica/include/acpi.h> 153 #include <contrib/dev/acpica/include/accommon.h> 154 #include <contrib/dev/acpica/include/acresrc.h> 155 156 #define _COMPONENT ACPI_RESOURCES 157 ACPI_MODULE_NAME ("rsmisc") 158 159 160 #define INIT_RESOURCE_TYPE(i) i->ResourceOffset 161 #define INIT_RESOURCE_LENGTH(i) i->AmlOffset 162 #define INIT_TABLE_LENGTH(i) i->Value 163 164 #define COMPARE_OPCODE(i) i->ResourceOffset 165 #define COMPARE_TARGET(i) i->AmlOffset 166 #define COMPARE_VALUE(i) i->Value 167 168 169 /******************************************************************************* 170 * 171 * FUNCTION: AcpiRsConvertAmlToResource 172 * 173 * PARAMETERS: Resource - Pointer to the resource descriptor 174 * Aml - Where the AML descriptor is returned 175 * Info - Pointer to appropriate conversion table 176 * 177 * RETURN: Status 178 * 179 * DESCRIPTION: Convert an external AML resource descriptor to the corresponding 180 * internal resource descriptor 181 * 182 ******************************************************************************/ 183 184 ACPI_STATUS 185 AcpiRsConvertAmlToResource ( 186 ACPI_RESOURCE *Resource, 187 AML_RESOURCE *Aml, 188 ACPI_RSCONVERT_INFO *Info) 189 { 190 ACPI_RS_LENGTH AmlResourceLength; 191 void *Source; 192 void *Destination; 193 char *Target; 194 UINT8 Count; 195 UINT8 FlagsMode = FALSE; 196 UINT16 ItemCount = 0; 197 UINT16 Temp16 = 0; 198 199 200 ACPI_FUNCTION_TRACE (RsConvertAmlToResource); 201 202 203 if (!Info) 204 { 205 return_ACPI_STATUS (AE_BAD_PARAMETER); 206 } 207 208 if (((ACPI_SIZE) Resource) & 0x3) 209 { 210 /* Each internal resource struct is expected to be 32-bit aligned */ 211 212 ACPI_WARNING ((AE_INFO, 213 "Misaligned resource pointer (get): %p Type 0x%2.2X Length %u", 214 Resource, Resource->Type, Resource->Length)); 215 } 216 217 /* Extract the resource Length field (does not include header length) */ 218 219 AmlResourceLength = AcpiUtGetResourceLength (Aml); 220 221 /* 222 * First table entry must be ACPI_RSC_INITxxx and must contain the 223 * table length (# of table entries) 224 */ 225 Count = INIT_TABLE_LENGTH (Info); 226 while (Count) 227 { 228 Target = NULL; 229 230 /* 231 * Source is the external AML byte stream buffer, 232 * destination is the internal resource descriptor 233 */ 234 Source = ACPI_ADD_PTR (void, Aml, Info->AmlOffset); 235 Destination = ACPI_ADD_PTR (void, Resource, Info->ResourceOffset); 236 237 switch (Info->Opcode) 238 { 239 case ACPI_RSC_INITGET: 240 /* 241 * Get the resource type and the initial (minimum) length 242 */ 243 memset (Resource, 0, INIT_RESOURCE_LENGTH (Info)); 244 Resource->Type = INIT_RESOURCE_TYPE (Info); 245 Resource->Length = INIT_RESOURCE_LENGTH (Info); 246 break; 247 248 case ACPI_RSC_INITSET: 249 break; 250 251 case ACPI_RSC_FLAGINIT: 252 253 FlagsMode = TRUE; 254 break; 255 256 case ACPI_RSC_1BITFLAG: 257 /* 258 * Mask and shift the flag bit 259 */ 260 ACPI_SET8 (Destination, 261 ((ACPI_GET8 (Source) >> Info->Value) & 0x01)); 262 break; 263 264 case ACPI_RSC_2BITFLAG: 265 /* 266 * Mask and shift the flag bits 267 */ 268 ACPI_SET8 (Destination, 269 ((ACPI_GET8 (Source) >> Info->Value) & 0x03)); 270 break; 271 272 case ACPI_RSC_3BITFLAG: 273 /* 274 * Mask and shift the flag bits 275 */ 276 ACPI_SET8 (Destination, 277 ((ACPI_GET8 (Source) >> Info->Value) & 0x07)); 278 break; 279 280 case ACPI_RSC_6BITFLAG: 281 /* 282 * Mask and shift the flag bits 283 */ 284 ACPI_SET8 (Destination, 285 ((ACPI_GET8 (Source) >> Info->Value) & 0x3F)); 286 break; 287 288 case ACPI_RSC_COUNT: 289 290 ItemCount = ACPI_GET8 (Source); 291 ACPI_SET8 (Destination, ItemCount); 292 293 Resource->Length = Resource->Length + 294 (Info->Value * (ItemCount - 1)); 295 break; 296 297 case ACPI_RSC_COUNT16: 298 299 ItemCount = AmlResourceLength; 300 ACPI_SET16 (Destination, ItemCount); 301 302 Resource->Length = Resource->Length + 303 (Info->Value * (ItemCount - 1)); 304 break; 305 306 case ACPI_RSC_COUNT_GPIO_PIN: 307 308 Target = ACPI_ADD_PTR (void, Aml, Info->Value); 309 ItemCount = ACPI_GET16 (Target) - ACPI_GET16 (Source); 310 311 Resource->Length = Resource->Length + ItemCount; 312 ItemCount = ItemCount / 2; 313 ACPI_SET16 (Destination, ItemCount); 314 break; 315 316 case ACPI_RSC_COUNT_GPIO_VEN: 317 318 ItemCount = ACPI_GET8 (Source); 319 ACPI_SET8 (Destination, ItemCount); 320 321 Resource->Length = Resource->Length + (Info->Value * ItemCount); 322 break; 323 324 case ACPI_RSC_COUNT_GPIO_RES: 325 /* 326 * Vendor data is optional (length/offset may both be zero) 327 * Examine vendor data length field first 328 */ 329 Target = ACPI_ADD_PTR (void, Aml, (Info->Value + 2)); 330 if (ACPI_GET16 (Target)) 331 { 332 /* Use vendor offset to get resource source length */ 333 334 Target = ACPI_ADD_PTR (void, Aml, Info->Value); 335 ItemCount = ACPI_GET16 (Target) - ACPI_GET16 (Source); 336 } 337 else 338 { 339 /* No vendor data to worry about */ 340 341 ItemCount = Aml->LargeHeader.ResourceLength + 342 sizeof (AML_RESOURCE_LARGE_HEADER) - 343 ACPI_GET16 (Source); 344 } 345 346 Resource->Length = Resource->Length + ItemCount; 347 ACPI_SET16 (Destination, ItemCount); 348 break; 349 350 case ACPI_RSC_COUNT_SERIAL_VEN: 351 352 ItemCount = ACPI_GET16 (Source) - Info->Value; 353 354 Resource->Length = Resource->Length + ItemCount; 355 ACPI_SET16 (Destination, ItemCount); 356 break; 357 358 case ACPI_RSC_COUNT_SERIAL_RES: 359 360 ItemCount = (AmlResourceLength + 361 sizeof (AML_RESOURCE_LARGE_HEADER)) - 362 ACPI_GET16 (Source) - Info->Value; 363 364 Resource->Length = Resource->Length + ItemCount; 365 ACPI_SET16 (Destination, ItemCount); 366 break; 367 368 case ACPI_RSC_LENGTH: 369 370 Resource->Length = Resource->Length + Info->Value; 371 break; 372 373 case ACPI_RSC_MOVE8: 374 case ACPI_RSC_MOVE16: 375 case ACPI_RSC_MOVE32: 376 case ACPI_RSC_MOVE64: 377 /* 378 * Raw data move. Use the Info value field unless ItemCount has 379 * been previously initialized via a COUNT opcode 380 */ 381 if (Info->Value) 382 { 383 ItemCount = Info->Value; 384 } 385 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode); 386 break; 387 388 case ACPI_RSC_MOVE_GPIO_PIN: 389 390 /* Generate and set the PIN data pointer */ 391 392 Target = (char *) ACPI_ADD_PTR (void, Resource, 393 (Resource->Length - ItemCount * 2)); 394 *(UINT16 **) Destination = ACPI_CAST_PTR (UINT16, Target); 395 396 /* Copy the PIN data */ 397 398 Source = ACPI_ADD_PTR (void, Aml, ACPI_GET16 (Source)); 399 AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode); 400 break; 401 402 case ACPI_RSC_MOVE_GPIO_RES: 403 404 /* Generate and set the ResourceSource string pointer */ 405 406 Target = (char *) ACPI_ADD_PTR (void, Resource, 407 (Resource->Length - ItemCount)); 408 *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target); 409 410 /* Copy the ResourceSource string */ 411 412 Source = ACPI_ADD_PTR (void, Aml, ACPI_GET16 (Source)); 413 AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode); 414 break; 415 416 case ACPI_RSC_MOVE_SERIAL_VEN: 417 418 /* Generate and set the Vendor Data pointer */ 419 420 Target = (char *) ACPI_ADD_PTR (void, Resource, 421 (Resource->Length - ItemCount)); 422 *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target); 423 424 /* Copy the Vendor Data */ 425 426 Source = ACPI_ADD_PTR (void, Aml, Info->Value); 427 AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode); 428 break; 429 430 case ACPI_RSC_MOVE_SERIAL_RES: 431 432 /* Generate and set the ResourceSource string pointer */ 433 434 Target = (char *) ACPI_ADD_PTR (void, Resource, 435 (Resource->Length - ItemCount)); 436 *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target); 437 438 /* Copy the ResourceSource string */ 439 440 Source = ACPI_ADD_PTR ( 441 void, Aml, (ACPI_GET16 (Source) + Info->Value)); 442 AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode); 443 break; 444 445 case ACPI_RSC_SET8: 446 447 memset (Destination, Info->AmlOffset, Info->Value); 448 break; 449 450 case ACPI_RSC_DATA8: 451 452 Target = ACPI_ADD_PTR (char, Resource, Info->Value); 453 memcpy (Destination, Source, ACPI_GET16 (Target)); 454 break; 455 456 case ACPI_RSC_ADDRESS: 457 /* 458 * Common handler for address descriptor flags 459 */ 460 if (!AcpiRsGetAddressCommon (Resource, Aml)) 461 { 462 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE); 463 } 464 break; 465 466 case ACPI_RSC_SOURCE: 467 /* 468 * Optional ResourceSource (Index and String) 469 */ 470 Resource->Length += 471 AcpiRsGetResourceSource (AmlResourceLength, Info->Value, 472 Destination, Aml, NULL); 473 break; 474 475 case ACPI_RSC_SOURCEX: 476 /* 477 * Optional ResourceSource (Index and String). This is the more 478 * complicated case used by the Interrupt() macro 479 */ 480 Target = ACPI_ADD_PTR (char, Resource, 481 Info->AmlOffset + (ItemCount * 4)); 482 483 Resource->Length += 484 AcpiRsGetResourceSource (AmlResourceLength, (ACPI_RS_LENGTH) 485 (((ItemCount - 1) * sizeof (UINT32)) + Info->Value), 486 Destination, Aml, Target); 487 break; 488 489 case ACPI_RSC_BITMASK: 490 /* 491 * 8-bit encoded bitmask (DMA macro) 492 */ 493 ItemCount = AcpiRsDecodeBitmask (ACPI_GET8 (Source), Destination); 494 if (ItemCount) 495 { 496 Resource->Length += (ItemCount - 1); 497 } 498 499 Target = ACPI_ADD_PTR (char, Resource, Info->Value); 500 ACPI_SET8 (Target, ItemCount); 501 break; 502 503 case ACPI_RSC_BITMASK16: 504 /* 505 * 16-bit encoded bitmask (IRQ macro) 506 */ 507 ACPI_MOVE_16_TO_16 (&Temp16, Source); 508 509 ItemCount = AcpiRsDecodeBitmask (Temp16, Destination); 510 if (ItemCount) 511 { 512 Resource->Length += (ItemCount - 1); 513 } 514 515 Target = ACPI_ADD_PTR (char, Resource, Info->Value); 516 ACPI_SET8 (Target, ItemCount); 517 break; 518 519 case ACPI_RSC_EXIT_NE: 520 /* 521 * Control - Exit conversion if not equal 522 */ 523 switch (Info->ResourceOffset) 524 { 525 case ACPI_RSC_COMPARE_AML_LENGTH: 526 527 if (AmlResourceLength != Info->Value) 528 { 529 goto Exit; 530 } 531 break; 532 533 case ACPI_RSC_COMPARE_VALUE: 534 535 if (ACPI_GET8 (Source) != Info->Value) 536 { 537 goto Exit; 538 } 539 break; 540 541 default: 542 543 ACPI_ERROR ((AE_INFO, "Invalid conversion sub-opcode")); 544 return_ACPI_STATUS (AE_BAD_PARAMETER); 545 } 546 break; 547 548 default: 549 550 ACPI_ERROR ((AE_INFO, "Invalid conversion opcode")); 551 return_ACPI_STATUS (AE_BAD_PARAMETER); 552 } 553 554 Count--; 555 Info++; 556 } 557 558 Exit: 559 if (!FlagsMode) 560 { 561 /* Round the resource struct length up to the next boundary (32 or 64) */ 562 563 Resource->Length = (UINT32) 564 ACPI_ROUND_UP_TO_NATIVE_WORD (Resource->Length); 565 } 566 return_ACPI_STATUS (AE_OK); 567 } 568 569 570 /******************************************************************************* 571 * 572 * FUNCTION: AcpiRsConvertResourceToAml 573 * 574 * PARAMETERS: Resource - Pointer to the resource descriptor 575 * Aml - Where the AML descriptor is returned 576 * Info - Pointer to appropriate conversion table 577 * 578 * RETURN: Status 579 * 580 * DESCRIPTION: Convert an internal resource descriptor to the corresponding 581 * external AML resource descriptor. 582 * 583 ******************************************************************************/ 584 585 ACPI_STATUS 586 AcpiRsConvertResourceToAml ( 587 ACPI_RESOURCE *Resource, 588 AML_RESOURCE *Aml, 589 ACPI_RSCONVERT_INFO *Info) 590 { 591 void *Source = NULL; 592 void *Destination; 593 char *Target; 594 ACPI_RSDESC_SIZE AmlLength = 0; 595 UINT8 Count; 596 UINT16 Temp16 = 0; 597 UINT16 ItemCount = 0; 598 599 600 ACPI_FUNCTION_TRACE (RsConvertResourceToAml); 601 602 603 if (!Info) 604 { 605 return_ACPI_STATUS (AE_BAD_PARAMETER); 606 } 607 608 /* 609 * First table entry must be ACPI_RSC_INITxxx and must contain the 610 * table length (# of table entries) 611 */ 612 Count = INIT_TABLE_LENGTH (Info); 613 614 while (Count) 615 { 616 /* 617 * Source is the internal resource descriptor, 618 * destination is the external AML byte stream buffer 619 */ 620 Source = ACPI_ADD_PTR (void, Resource, Info->ResourceOffset); 621 Destination = ACPI_ADD_PTR (void, Aml, Info->AmlOffset); 622 623 switch (Info->Opcode) 624 { 625 case ACPI_RSC_INITSET: 626 627 memset (Aml, 0, INIT_RESOURCE_LENGTH (Info)); 628 AmlLength = INIT_RESOURCE_LENGTH (Info); 629 AcpiRsSetResourceHeader ( 630 INIT_RESOURCE_TYPE (Info), AmlLength, Aml); 631 break; 632 633 case ACPI_RSC_INITGET: 634 break; 635 636 case ACPI_RSC_FLAGINIT: 637 /* 638 * Clear the flag byte 639 */ 640 ACPI_SET8 (Destination, 0); 641 break; 642 643 case ACPI_RSC_1BITFLAG: 644 /* 645 * Mask and shift the flag bit 646 */ 647 ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8) 648 ((ACPI_GET8 (Source) & 0x01) << Info->Value)); 649 break; 650 651 case ACPI_RSC_2BITFLAG: 652 /* 653 * Mask and shift the flag bits 654 */ 655 ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8) 656 ((ACPI_GET8 (Source) & 0x03) << Info->Value)); 657 break; 658 659 case ACPI_RSC_3BITFLAG: 660 /* 661 * Mask and shift the flag bits 662 */ 663 ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8) 664 ((ACPI_GET8 (Source) & 0x07) << Info->Value)); 665 break; 666 667 case ACPI_RSC_6BITFLAG: 668 /* 669 * Mask and shift the flag bits 670 */ 671 ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8) 672 ((ACPI_GET8 (Source) & 0x3F) << Info->Value)); 673 break; 674 675 case ACPI_RSC_COUNT: 676 677 ItemCount = ACPI_GET8 (Source); 678 ACPI_SET8 (Destination, ItemCount); 679 680 AmlLength = (UINT16) 681 (AmlLength + (Info->Value * (ItemCount - 1))); 682 break; 683 684 case ACPI_RSC_COUNT16: 685 686 ItemCount = ACPI_GET16 (Source); 687 AmlLength = (UINT16) (AmlLength + ItemCount); 688 AcpiRsSetResourceLength (AmlLength, Aml); 689 break; 690 691 case ACPI_RSC_COUNT_GPIO_PIN: 692 693 ItemCount = ACPI_GET16 (Source); 694 ACPI_SET16 (Destination, AmlLength); 695 696 AmlLength = (UINT16) (AmlLength + ItemCount * 2); 697 Target = ACPI_ADD_PTR (void, Aml, Info->Value); 698 ACPI_SET16 (Target, AmlLength); 699 AcpiRsSetResourceLength (AmlLength, Aml); 700 break; 701 702 case ACPI_RSC_COUNT_GPIO_VEN: 703 704 ItemCount = ACPI_GET16 (Source); 705 ACPI_SET16 (Destination, ItemCount); 706 707 AmlLength = (UINT16) ( 708 AmlLength + (Info->Value * ItemCount)); 709 AcpiRsSetResourceLength (AmlLength, Aml); 710 break; 711 712 case ACPI_RSC_COUNT_GPIO_RES: 713 714 /* Set resource source string length */ 715 716 ItemCount = ACPI_GET16 (Source); 717 ACPI_SET16 (Destination, AmlLength); 718 719 /* Compute offset for the Vendor Data */ 720 721 AmlLength = (UINT16) (AmlLength + ItemCount); 722 Target = ACPI_ADD_PTR (void, Aml, Info->Value); 723 724 /* Set vendor offset only if there is vendor data */ 725 726 ACPI_SET16 (Target, AmlLength); 727 728 AcpiRsSetResourceLength (AmlLength, Aml); 729 break; 730 731 case ACPI_RSC_COUNT_SERIAL_VEN: 732 733 ItemCount = ACPI_GET16 (Source); 734 ACPI_SET16 (Destination, ItemCount + Info->Value); 735 AmlLength = (UINT16) (AmlLength + ItemCount); 736 AcpiRsSetResourceLength (AmlLength, Aml); 737 break; 738 739 case ACPI_RSC_COUNT_SERIAL_RES: 740 741 ItemCount = ACPI_GET16 (Source); 742 AmlLength = (UINT16) (AmlLength + ItemCount); 743 AcpiRsSetResourceLength (AmlLength, Aml); 744 break; 745 746 case ACPI_RSC_LENGTH: 747 748 AcpiRsSetResourceLength (Info->Value, Aml); 749 break; 750 751 case ACPI_RSC_MOVE8: 752 case ACPI_RSC_MOVE16: 753 case ACPI_RSC_MOVE32: 754 case ACPI_RSC_MOVE64: 755 756 if (Info->Value) 757 { 758 ItemCount = Info->Value; 759 } 760 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode); 761 break; 762 763 case ACPI_RSC_MOVE_GPIO_PIN: 764 765 Destination = (char *) ACPI_ADD_PTR (void, Aml, 766 ACPI_GET16 (Destination)); 767 Source = * (UINT16 **) Source; 768 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode); 769 break; 770 771 case ACPI_RSC_MOVE_GPIO_RES: 772 773 /* Used for both ResourceSource string and VendorData */ 774 775 Destination = (char *) ACPI_ADD_PTR (void, Aml, 776 ACPI_GET16 (Destination)); 777 Source = * (UINT8 **) Source; 778 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode); 779 break; 780 781 case ACPI_RSC_MOVE_SERIAL_VEN: 782 783 Destination = (char *) ACPI_ADD_PTR (void, Aml, 784 (AmlLength - ItemCount)); 785 Source = * (UINT8 **) Source; 786 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode); 787 break; 788 789 case ACPI_RSC_MOVE_SERIAL_RES: 790 791 Destination = (char *) ACPI_ADD_PTR (void, Aml, 792 (AmlLength - ItemCount)); 793 Source = * (UINT8 **) Source; 794 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode); 795 break; 796 797 case ACPI_RSC_ADDRESS: 798 799 /* Set the Resource Type, General Flags, and Type-Specific Flags */ 800 801 AcpiRsSetAddressCommon (Aml, Resource); 802 break; 803 804 case ACPI_RSC_SOURCEX: 805 /* 806 * Optional ResourceSource (Index and String) 807 */ 808 AmlLength = AcpiRsSetResourceSource ( 809 Aml, (ACPI_RS_LENGTH) AmlLength, Source); 810 AcpiRsSetResourceLength (AmlLength, Aml); 811 break; 812 813 case ACPI_RSC_SOURCE: 814 /* 815 * Optional ResourceSource (Index and String). This is the more 816 * complicated case used by the Interrupt() macro 817 */ 818 AmlLength = AcpiRsSetResourceSource (Aml, Info->Value, Source); 819 AcpiRsSetResourceLength (AmlLength, Aml); 820 break; 821 822 case ACPI_RSC_BITMASK: 823 /* 824 * 8-bit encoded bitmask (DMA macro) 825 */ 826 ACPI_SET8 (Destination, 827 AcpiRsEncodeBitmask (Source, 828 *ACPI_ADD_PTR (UINT8, Resource, Info->Value))); 829 break; 830 831 case ACPI_RSC_BITMASK16: 832 /* 833 * 16-bit encoded bitmask (IRQ macro) 834 */ 835 Temp16 = AcpiRsEncodeBitmask ( 836 Source, *ACPI_ADD_PTR (UINT8, Resource, Info->Value)); 837 ACPI_MOVE_16_TO_16 (Destination, &Temp16); 838 break; 839 840 case ACPI_RSC_EXIT_LE: 841 /* 842 * Control - Exit conversion if less than or equal 843 */ 844 if (ItemCount <= Info->Value) 845 { 846 goto Exit; 847 } 848 break; 849 850 case ACPI_RSC_EXIT_NE: 851 /* 852 * Control - Exit conversion if not equal 853 */ 854 switch (COMPARE_OPCODE (Info)) 855 { 856 case ACPI_RSC_COMPARE_VALUE: 857 858 if (*ACPI_ADD_PTR (UINT8, Resource, 859 COMPARE_TARGET (Info)) != COMPARE_VALUE (Info)) 860 { 861 goto Exit; 862 } 863 break; 864 865 default: 866 867 ACPI_ERROR ((AE_INFO, "Invalid conversion sub-opcode")); 868 return_ACPI_STATUS (AE_BAD_PARAMETER); 869 } 870 break; 871 872 case ACPI_RSC_EXIT_EQ: 873 /* 874 * Control - Exit conversion if equal 875 */ 876 if (*ACPI_ADD_PTR (UINT8, Resource, 877 COMPARE_TARGET (Info)) == COMPARE_VALUE (Info)) 878 { 879 goto Exit; 880 } 881 break; 882 883 default: 884 885 ACPI_ERROR ((AE_INFO, "Invalid conversion opcode")); 886 return_ACPI_STATUS (AE_BAD_PARAMETER); 887 } 888 889 Count--; 890 Info++; 891 } 892 893 Exit: 894 return_ACPI_STATUS (AE_OK); 895 } 896 897 898 #if 0 899 /* Previous resource validations */ 900 901 if (Aml->ExtAddress64.RevisionID != 902 AML_RESOURCE_EXTENDED_ADDRESS_REVISION) 903 { 904 return_ACPI_STATUS (AE_SUPPORT); 905 } 906 907 if (Resource->Data.StartDpf.PerformanceRobustness >= 3) 908 { 909 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE); 910 } 911 912 if (((Aml->Irq.Flags & 0x09) == 0x00) || 913 ((Aml->Irq.Flags & 0x09) == 0x09)) 914 { 915 /* 916 * Only [ActiveHigh, EdgeSensitive] or [ActiveLow, LevelSensitive] 917 * polarity/trigger interrupts are allowed (ACPI spec, section 918 * "IRQ Format"), so 0x00 and 0x09 are illegal. 919 */ 920 ACPI_ERROR ((AE_INFO, 921 "Invalid interrupt polarity/trigger in resource list, 0x%X", 922 Aml->Irq.Flags)); 923 return_ACPI_STATUS (AE_BAD_DATA); 924 } 925 926 Resource->Data.ExtendedIrq.InterruptCount = Temp8; 927 if (Temp8 < 1) 928 { 929 /* Must have at least one IRQ */ 930 931 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH); 932 } 933 934 if (Resource->Data.Dma.Transfer == 0x03) 935 { 936 ACPI_ERROR ((AE_INFO, 937 "Invalid DMA.Transfer preference (3)")); 938 return_ACPI_STATUS (AE_BAD_DATA); 939 } 940 #endif 941