rsmisc.c revision 67754
1/******************************************************************************* 2 * 3 * Module Name: rsmisc - AcpiRsEndTagResource 4 * AcpiRsEndTagStream 5 * AcpiRsVendorResource 6 * AcpiRsVendorStream 7 * AcpiRsStartDependentFunctionsResource 8 * AcpiRsEndDependentFunctionsResource 9 * AcpiRsStartDependentFunctionsStream 10 * AcpiRsEndDependentFunctionsStream 11 * $Revision: 9 $ 12 * 13 ******************************************************************************/ 14 15/****************************************************************************** 16 * 17 * 1. Copyright Notice 18 * 19 * Some or all of this work - Copyright (c) 1999, Intel Corp. All rights 20 * reserved. 21 * 22 * 2. License 23 * 24 * 2.1. This is your license from Intel Corp. under its intellectual property 25 * rights. You may have additional license terms from the party that provided 26 * you this software, covering your right to use that party's intellectual 27 * property rights. 28 * 29 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 30 * copy of the source code appearing in this file ("Covered Code") an 31 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 32 * base code distributed originally by Intel ("Original Intel Code") to copy, 33 * make derivatives, distribute, use and display any portion of the Covered 34 * Code in any form, with the right to sublicense such rights; and 35 * 36 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 37 * license (with the right to sublicense), under only those claims of Intel 38 * patents that are infringed by the Original Intel Code, to make, use, sell, 39 * offer to sell, and import the Covered Code and derivative works thereof 40 * solely to the minimum extent necessary to exercise the above copyright 41 * license, and in no event shall the patent license extend to any additions 42 * to or modifications of the Original Intel Code. No other license or right 43 * is granted directly or by implication, estoppel or otherwise; 44 * 45 * The above copyright and patent license is granted only if the following 46 * conditions are met: 47 * 48 * 3. Conditions 49 * 50 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 51 * Redistribution of source code of any substantial portion of the Covered 52 * Code or modification with rights to further distribute source must include 53 * the above Copyright Notice, the above License, this list of Conditions, 54 * and the following Disclaimer and Export Compliance provision. In addition, 55 * Licensee must cause all Covered Code to which Licensee contributes to 56 * contain a file documenting the changes Licensee made to create that Covered 57 * Code and the date of any change. Licensee must include in that file the 58 * documentation of any changes made by any predecessor Licensee. Licensee 59 * must include a prominent statement that the modification is derived, 60 * directly or indirectly, from Original Intel Code. 61 * 62 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 63 * Redistribution of source code of any substantial portion of the Covered 64 * Code or modification without rights to further distribute source must 65 * include the following Disclaimer and Export Compliance provision in the 66 * documentation and/or other materials provided with distribution. In 67 * addition, Licensee may not authorize further sublicense of source of any 68 * portion of the Covered Code, and must include terms to the effect that the 69 * license from Licensee to its licensee is limited to the intellectual 70 * property embodied in the software Licensee provides to its licensee, and 71 * not to intellectual property embodied in modifications its licensee may 72 * make. 73 * 74 * 3.3. Redistribution of Executable. Redistribution in executable form of any 75 * substantial portion of the Covered Code or modification must reproduce the 76 * above Copyright Notice, and the following Disclaimer and Export Compliance 77 * provision in the documentation and/or other materials provided with the 78 * distribution. 79 * 80 * 3.4. Intel retains all right, title, and interest in and to the Original 81 * Intel Code. 82 * 83 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 84 * Intel shall be used in advertising or otherwise to promote the sale, use or 85 * other dealings in products derived from or relating to the Covered Code 86 * without prior written authorization from Intel. 87 * 88 * 4. Disclaimer and Export Compliance 89 * 90 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 91 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 92 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 93 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 94 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 95 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 96 * PARTICULAR PURPOSE. 97 * 98 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 99 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 100 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 101 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 102 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 103 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 104 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 105 * LIMITED REMEDY. 106 * 107 * 4.3. Licensee shall not export, either directly or indirectly, any of this 108 * software or system incorporating such software without first obtaining any 109 * required license or other approval from the U. S. Department of Commerce or 110 * any other agency or department of the United States Government. In the 111 * event Licensee exports any such software from the United States or 112 * re-exports any such software from a foreign destination, Licensee shall 113 * ensure that the distribution and export/re-export of the software is in 114 * compliance with all laws, regulations, orders, or other restrictions of the 115 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 116 * any of its subsidiaries will export/re-export any technical data, process, 117 * software, or service, directly or indirectly, to any country for which the 118 * United States government or any agency thereof requires an export license, 119 * other governmental approval, or letter of assurance, without first obtaining 120 * such license, approval or letter. 121 * 122 *****************************************************************************/ 123 124#define __RSMISC_C__ 125 126#include "acpi.h" 127 128#define _COMPONENT RESOURCE_MANAGER 129 MODULE_NAME ("rsmisc") 130 131 132/******************************************************************************* 133 * 134 * FUNCTION: AcpiRsEndTagResource 135 * 136 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte 137 * stream 138 * BytesConsumed - UINT32 pointer that is filled with 139 * the number of bytes consumed from 140 * the ByteStreamBuffer 141 * OutputBuffer - Pointer to the user's return buffer 142 * StructureSize - UINT32 pointer that is filled with 143 * the number of bytes in the filled 144 * in structure 145 * 146 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code 147 * 148 * DESCRIPTION: Take the resource byte stream and fill out the appropriate 149 * structure pointed to by the OutputBuffer. Return the 150 * number of bytes consumed from the byte stream. 151 * 152 ******************************************************************************/ 153 154ACPI_STATUS 155AcpiRsEndTagResource ( 156 UINT8 *ByteStreamBuffer, 157 UINT32 *BytesConsumed, 158 UINT8 **OutputBuffer, 159 UINT32 *StructureSize) 160{ 161 RESOURCE *OutputStruct = (RESOURCE *) * OutputBuffer; 162 UINT32 StructSize = RESOURCE_LENGTH; 163 164 165 FUNCTION_TRACE ("RsEndTagResource"); 166 167 /* 168 * The number of bytes consumed is static 169 */ 170 *BytesConsumed = 2; 171 172 /* 173 * Fill out the structure 174 */ 175 OutputStruct->Id = EndTag; 176 177 /* 178 * Set the Length parameter 179 */ 180 OutputStruct->Length = 0; 181 182 /* 183 * Return the final size of the structure 184 */ 185 *StructureSize = StructSize; 186 187 return_ACPI_STATUS (AE_OK); 188} 189 190 191/******************************************************************************* 192 * 193 * FUNCTION: AcpiRsEndTagStream 194 * 195 * PARAMETERS: LinkedList - Pointer to the resource linked list 196 * OutputBuffer - Pointer to the user's return buffer 197 * BytesConsumed - UINT32 pointer that is filled with 198 * the number of bytes of the 199 * OutputBuffer used 200 * 201 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code 202 * 203 * DESCRIPTION: Take the linked list resource structure and fills in the 204 * the appropriate bytes in a byte stream 205 * 206 ******************************************************************************/ 207 208ACPI_STATUS 209AcpiRsEndTagStream ( 210 RESOURCE *LinkedList, 211 UINT8 **OutputBuffer, 212 UINT32 *BytesConsumed) 213{ 214 UINT8 *Buffer = *OutputBuffer; 215 UINT8 Temp8 = 0; 216 217 218 FUNCTION_TRACE ("RsEndTagStream"); 219 220 /* 221 * The descriptor field is static 222 */ 223 *Buffer = 0x79; 224 Buffer += 1; 225 226 /* 227 * Set the Checksum - zero means that the resource data is treated as if 228 * the checksum operation succeeded (ACPI Spec 1.0b Section 6.4.2.8) 229 */ 230 Temp8 = 0; 231 232 *Buffer = Temp8; 233 Buffer += 1; 234 235 /* 236 * Return the number of bytes consumed in this operation 237 */ 238 *BytesConsumed = (UINT32) ((NATIVE_UINT) Buffer - 239 (NATIVE_UINT) *OutputBuffer); 240 241 return_ACPI_STATUS (AE_OK); 242} 243 244 245/******************************************************************************* 246 * 247 * FUNCTION: AcpiRsVendorResource 248 * 249 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte 250 * stream 251 * BytesConsumed - UINT32 pointer that is filled with 252 * the number of bytes consumed from 253 * the ByteStreamBuffer 254 * OutputBuffer - Pointer to the user's return buffer 255 * StructureSize - UINT32 pointer that is filled with 256 * the number of bytes in the filled 257 * in structure 258 * 259 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code 260 * 261 * DESCRIPTION: Take the resource byte stream and fill out the appropriate 262 * structure pointed to by the OutputBuffer. Return the 263 * number of bytes consumed from the byte stream. 264 * 265 ******************************************************************************/ 266 267ACPI_STATUS 268AcpiRsVendorResource ( 269 UINT8 *ByteStreamBuffer, 270 UINT32 *BytesConsumed, 271 UINT8 **OutputBuffer, 272 UINT32 *StructureSize) 273{ 274 UINT8 *Buffer = ByteStreamBuffer; 275 RESOURCE *OutputStruct = (RESOURCE *) * OutputBuffer; 276 UINT16 Temp16 = 0; 277 UINT8 Temp8 = 0; 278 UINT8 Index; 279 UINT32 StructSize = sizeof (VENDOR_RESOURCE) + 280 RESOURCE_LENGTH_NO_DATA; 281 282 283 FUNCTION_TRACE ("RsVendorResource"); 284 285 /* 286 * Dereference the Descriptor to find if this is a large or small item. 287 */ 288 Temp8 = *Buffer; 289 290 if (Temp8 & 0x80) 291 { 292 /* 293 * Large Item 294 */ 295 /* Point to the length field */ 296 297 Buffer += 1; 298 299 /* Dereference */ 300 301 MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer); 302 303 /* Calculate bytes consumed */ 304 305 *BytesConsumed = Temp16 + 3; 306 307 /* Point to the first vendor byte */ 308 309 Buffer += 2; 310 } 311 312 else 313 { 314 /* 315 * Small Item 316 */ 317 318 /* Dereference the size */ 319 320 Temp16 = (UINT8)(*Buffer & 0x07); 321 322 /* Calculate bytes consumed */ 323 324 *BytesConsumed = Temp16 + 1; 325 326 /* Point to the first vendor byte */ 327 328 Buffer += 1; 329 } 330 331 OutputStruct->Id = VendorSpecific; 332 OutputStruct->Data.VendorSpecific.Length = Temp16; 333 334 for (Index = 0; Index < Temp16; Index++) 335 { 336 OutputStruct->Data.VendorSpecific.Reserved[Index] = *Buffer; 337 Buffer += 1; 338 } 339 340 /* 341 * In order for the StructSize to fall on a 32-bit boundry, 342 * calculate the length of the vendor string and expand the 343 * StructSize to the next 32-bit boundry. 344 */ 345 StructSize += ROUND_UP_TO_32BITS (Temp16); 346 347 /* 348 * Set the Length parameter 349 */ 350 OutputStruct->Length = StructSize; 351 352 /* 353 * Return the final size of the structure 354 */ 355 *StructureSize = StructSize; 356 357 return_ACPI_STATUS (AE_OK); 358} 359 360 361/******************************************************************************* 362 * 363 * FUNCTION: AcpiRsVendorStream 364 * 365 * PARAMETERS: LinkedList - Pointer to the resource linked list 366 * OutputBuffer - Pointer to the user's return buffer 367 * BytesConsumed - UINT32 pointer that is filled with 368 * the number of bytes of the 369 * OutputBuffer used 370 * 371 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code 372 * 373 * DESCRIPTION: Take the linked list resource structure and fills in the 374 * the appropriate bytes in a byte stream 375 * 376 ******************************************************************************/ 377 378ACPI_STATUS 379AcpiRsVendorStream ( 380 RESOURCE *LinkedList, 381 UINT8 **OutputBuffer, 382 UINT32 *BytesConsumed) 383{ 384 UINT8 *Buffer = *OutputBuffer; 385 UINT16 Temp16 = 0; 386 UINT8 Temp8 = 0; 387 UINT8 Index; 388 389 390 FUNCTION_TRACE ("RsVendorStream"); 391 392 /* 393 * Dereference the length to find if this is a large or small item. 394 */ 395 396 if(LinkedList->Data.VendorSpecific.Length > 7) 397 { 398 /* 399 * Large Item 400 */ 401 /* 402 * Set the descriptor field and length bytes 403 */ 404 *Buffer = 0x84; 405 Buffer += 1; 406 407 Temp16 = (UINT16) LinkedList->Data.VendorSpecific.Length; 408 409 MOVE_UNALIGNED16_TO_16 (Buffer, &Temp16); 410 Buffer += 2; 411 } 412 413 else 414 { 415 /* 416 * Small Item 417 */ 418 419 /* 420 * Set the descriptor field 421 */ 422 Temp8 = 0x70; 423 Temp8 |= LinkedList->Data.VendorSpecific.Length; 424 425 *Buffer = Temp8; 426 Buffer += 1; 427 } 428 429 /* 430 * Loop through all of the Vendor Specific fields 431 */ 432 for (Index = 0; Index < LinkedList->Data.VendorSpecific.Length; Index++) 433 { 434 Temp8 = LinkedList->Data.VendorSpecific.Reserved[Index]; 435 436 *Buffer = Temp8; 437 Buffer += 1; 438 } 439 440 /* 441 * Return the number of bytes consumed in this operation 442 */ 443 *BytesConsumed = (UINT32) ((NATIVE_UINT) Buffer - 444 (NATIVE_UINT) *OutputBuffer); 445 446 return_ACPI_STATUS (AE_OK); 447} 448 449 450/******************************************************************************* 451 * 452 * FUNCTION: AcpiRsStartDependentFunctionsResource 453 * 454 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte 455 * stream 456 * BytesConsumed - UINT32 pointer that is filled with 457 * the number of bytes consumed from 458 * the ByteStreamBuffer 459 * OutputBuffer - Pointer to the user's return buffer 460 * StructureSize - UINT32 pointer that is filled with 461 * the number of bytes in the filled 462 * in structure 463 * 464 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code 465 * 466 * DESCRIPTION: Take the resource byte stream and fill out the appropriate 467 * structure pointed to by the OutputBuffer. Return the 468 * number of bytes consumed from the byte stream. 469 * 470 ******************************************************************************/ 471 472ACPI_STATUS 473AcpiRsStartDependentFunctionsResource ( 474 UINT8 *ByteStreamBuffer, 475 UINT32 *BytesConsumed, 476 UINT8 **OutputBuffer, 477 UINT32 *StructureSize) 478{ 479 UINT8 *Buffer = ByteStreamBuffer; 480 RESOURCE *OutputStruct = (RESOURCE *) * OutputBuffer; 481 UINT8 Temp8 = 0; 482 UINT32 StructSize = 483 sizeof(START_DEPENDENT_FUNCTIONS_RESOURCE) + 484 RESOURCE_LENGTH_NO_DATA; 485 486 487 FUNCTION_TRACE ("RsStartDependentFunctionsResource"); 488 489 /* 490 * The number of bytes consumed are contained in the descriptor (Bits:0-1) 491 */ 492 Temp8 = *Buffer; 493 494 *BytesConsumed = (Temp8 & 0x01) + 1; 495 496 OutputStruct->Id = StartDependentFunctions; 497 498 /* 499 * Point to Byte 1 if it is used 500 */ 501 if (2 == *BytesConsumed) 502 { 503 Buffer += 1; 504 Temp8 = *Buffer; 505 506 /* 507 * Check Compatibility priority 508 */ 509 OutputStruct->Data.StartDependentFunctions.CompatibilityPriority = 510 Temp8 & 0x03; 511 512 if (3 == OutputStruct->Data.StartDependentFunctions.CompatibilityPriority) 513 { 514 return_ACPI_STATUS (AE_AML_ERROR); 515 } 516 517 /* 518 * Check Performance/Robustness preference 519 */ 520 OutputStruct->Data.StartDependentFunctions.PerformanceRobustness = 521 (Temp8 >> 2) & 0x03; 522 523 if (3 == OutputStruct->Data.StartDependentFunctions.PerformanceRobustness) 524 { 525 return_ACPI_STATUS (AE_AML_ERROR); 526 } 527 } 528 529 else 530 { 531 OutputStruct->Data.StartDependentFunctions.CompatibilityPriority = 532 ACCEPTABLE_CONFIGURATION; 533 534 OutputStruct->Data.StartDependentFunctions.PerformanceRobustness = 535 ACCEPTABLE_CONFIGURATION; 536 } 537 538 /* 539 * Set the Length parameter 540 */ 541 OutputStruct->Length = StructSize; 542 543 /* 544 * Return the final size of the structure 545 */ 546 *StructureSize = StructSize; 547 548 return_ACPI_STATUS (AE_OK); 549} 550 551 552/******************************************************************************* 553 * 554 * FUNCTION: AcpiRsEndDependentFunctionsResource 555 * 556 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte 557 * stream 558 * BytesConsumed - UINT32 pointer that is filled with 559 * the number of bytes consumed from 560 * the ByteStreamBuffer 561 * OutputBuffer - Pointer to the user's return buffer 562 * StructureSize - UINT32 pointer that is filled with 563 * the number of bytes in the filled 564 * in structure 565 * 566 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code 567 * 568 * DESCRIPTION: Take the resource byte stream and fill out the appropriate 569 * structure pointed to by the OutputBuffer. Return the 570 * number of bytes consumed from the byte stream. 571 * 572 ******************************************************************************/ 573 574ACPI_STATUS 575AcpiRsEndDependentFunctionsResource ( 576 UINT8 *ByteStreamBuffer, 577 UINT32 *BytesConsumed, 578 UINT8 **OutputBuffer, 579 UINT32 *StructureSize) 580{ 581 RESOURCE *OutputStruct = (RESOURCE *) * OutputBuffer; 582 UINT32 StructSize = RESOURCE_LENGTH; 583 584 585 FUNCTION_TRACE ("RsEndDependentFunctionsResource"); 586 587 /* 588 * The number of bytes consumed is static 589 */ 590 *BytesConsumed = 1; 591 592 /* 593 * Fill out the structure 594 */ 595 OutputStruct->Id = EndDependentFunctions; 596 597 /* 598 * Set the Length parameter 599 */ 600 OutputStruct->Length = StructSize; 601 602 /* 603 * Return the final size of the structure 604 */ 605 *StructureSize = StructSize; 606 607 return_ACPI_STATUS (AE_OK); 608} 609 610 611/******************************************************************************* 612 * 613 * FUNCTION: AcpiRsStartDependentFunctionsStream 614 * 615 * PARAMETERS: LinkedList - Pointer to the resource linked list 616 * OutputBuffer - Pointer to the user's return buffer 617 * BytesConsumed - UINT32 pointer that is filled with 618 * the number of bytes of the 619 * OutputBuffer used 620 * 621 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code 622 * 623 * DESCRIPTION: Take the linked list resource structure and fills in the 624 * the appropriate bytes in a byte stream 625 * 626 ******************************************************************************/ 627 628ACPI_STATUS 629AcpiRsStartDependentFunctionsStream ( 630 RESOURCE *LinkedList, 631 UINT8 **OutputBuffer, 632 UINT32 *BytesConsumed) 633{ 634 UINT8 *Buffer = *OutputBuffer; 635 UINT8 Temp8 = 0; 636 637 638 FUNCTION_TRACE ("RsStartDependentFunctionsStream"); 639 640 /* 641 * The descriptor field is set based upon whether a byte is needed 642 * to contain Priority data. 643 */ 644 if (ACCEPTABLE_CONFIGURATION == 645 LinkedList->Data.StartDependentFunctions.CompatibilityPriority && 646 ACCEPTABLE_CONFIGURATION == 647 LinkedList->Data.StartDependentFunctions.PerformanceRobustness) 648 { 649 *Buffer = 0x30; 650 } 651 else 652 { 653 *Buffer = 0x31; 654 Buffer += 1; 655 656 /* 657 * Set the Priority Byte Definition 658 */ 659 Temp8 = 0; 660 Temp8 = (UINT8) 661 ((LinkedList->Data.StartDependentFunctions.PerformanceRobustness & 662 0x03) << 2); 663 Temp8 |= 664 (LinkedList->Data.StartDependentFunctions.CompatibilityPriority & 665 0x03); 666 667 *Buffer = Temp8; 668 } 669 670 Buffer += 1; 671 672 /* 673 * Return the number of bytes consumed in this operation 674 */ 675 *BytesConsumed = (UINT32) ((NATIVE_UINT) Buffer - 676 (NATIVE_UINT) *OutputBuffer); 677 678 return_ACPI_STATUS (AE_OK); 679} 680 681 682/******************************************************************************* 683 * 684 * FUNCTION: AcpiRsEndDependentFunctionsStream 685 * 686 * PARAMETERS: LinkedList - Pointer to the resource linked list 687 * OutputBuffer - Pointer to the user's return buffer 688 * BytesConsumed - UINT32 pointer that is filled with 689 * the number of bytes of the 690 * OutputBuffer used 691 * 692 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code 693 * 694 * DESCRIPTION: Take the linked list resource structure and fills in the 695 * the appropriate bytes in a byte stream 696 * 697 ******************************************************************************/ 698 699ACPI_STATUS 700AcpiRsEndDependentFunctionsStream ( 701 RESOURCE *LinkedList, 702 UINT8 **OutputBuffer, 703 UINT32 *BytesConsumed 704 ) 705{ 706 UINT8 *Buffer = *OutputBuffer; 707 708 709 FUNCTION_TRACE ("RsEndDependentFunctionsStream"); 710 711 /* 712 * The descriptor field is static 713 */ 714 *Buffer = 0x38; 715 Buffer += 1; 716 717 /* 718 * Return the number of bytes consumed in this operation 719 */ 720 *BytesConsumed = (UINT32) ((NATIVE_UINT) Buffer - 721 (NATIVE_UINT) *OutputBuffer); 722 723 return_ACPI_STATUS (AE_OK); 724} 725 726