rsirq.c revision 117521
1/******************************************************************************* 2 * 3 * Module Name: rsirq - IRQ resource descriptors 4 * $Revision: 34 $ 5 * 6 ******************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp. 13 * All rights reserved. 14 * 15 * 2. License 16 * 17 * 2.1. This is your license from Intel Corp. under its intellectual property 18 * rights. You may have additional license terms from the party that provided 19 * you this software, covering your right to use that party's intellectual 20 * property rights. 21 * 22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23 * copy of the source code appearing in this file ("Covered Code") an 24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25 * base code distributed originally by Intel ("Original Intel Code") to copy, 26 * make derivatives, distribute, use and display any portion of the Covered 27 * Code in any form, with the right to sublicense such rights; and 28 * 29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30 * license (with the right to sublicense), under only those claims of Intel 31 * patents that are infringed by the Original Intel Code, to make, use, sell, 32 * offer to sell, and import the Covered Code and derivative works thereof 33 * solely to the minimum extent necessary to exercise the above copyright 34 * license, and in no event shall the patent license extend to any additions 35 * to or modifications of the Original Intel Code. No other license or right 36 * is granted directly or by implication, estoppel or otherwise; 37 * 38 * The above copyright and patent license is granted only if the following 39 * conditions are met: 40 * 41 * 3. Conditions 42 * 43 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44 * Redistribution of source code of any substantial portion of the Covered 45 * Code or modification with rights to further distribute source must include 46 * the above Copyright Notice, the above License, this list of Conditions, 47 * and the following Disclaimer and Export Compliance provision. In addition, 48 * Licensee must cause all Covered Code to which Licensee contributes to 49 * contain a file documenting the changes Licensee made to create that Covered 50 * Code and the date of any change. Licensee must include in that file the 51 * documentation of any changes made by any predecessor Licensee. Licensee 52 * must include a prominent statement that the modification is derived, 53 * directly or indirectly, from Original Intel Code. 54 * 55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56 * Redistribution of source code of any substantial portion of the Covered 57 * Code or modification without rights to further distribute source must 58 * include the following Disclaimer and Export Compliance provision in the 59 * documentation and/or other materials provided with distribution. In 60 * addition, Licensee may not authorize further sublicense of source of any 61 * portion of the Covered Code, and must include terms to the effect that the 62 * license from Licensee to its licensee is limited to the intellectual 63 * property embodied in the software Licensee provides to its licensee, and 64 * not to intellectual property embodied in modifications its licensee may 65 * make. 66 * 67 * 3.3. Redistribution of Executable. Redistribution in executable form of any 68 * substantial portion of the Covered Code or modification must reproduce the 69 * above Copyright Notice, and the following Disclaimer and Export Compliance 70 * provision in the documentation and/or other materials provided with the 71 * distribution. 72 * 73 * 3.4. Intel retains all right, title, and interest in and to the Original 74 * Intel Code. 75 * 76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77 * Intel shall be used in advertising or otherwise to promote the sale, use or 78 * other dealings in products derived from or relating to the Covered Code 79 * without prior written authorization from Intel. 80 * 81 * 4. Disclaimer and Export Compliance 82 * 83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89 * PARTICULAR PURPOSE. 90 * 91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98 * LIMITED REMEDY. 99 * 100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 101 * software or system incorporating such software without first obtaining any 102 * required license or other approval from the U. S. Department of Commerce or 103 * any other agency or department of the United States Government. In the 104 * event Licensee exports any such software from the United States or 105 * re-exports any such software from a foreign destination, Licensee shall 106 * ensure that the distribution and export/re-export of the software is in 107 * compliance with all laws, regulations, orders, or other restrictions of the 108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109 * any of its subsidiaries will export/re-export any technical data, process, 110 * software, or service, directly or indirectly, to any country for which the 111 * United States government or any agency thereof requires an export license, 112 * other governmental approval, or letter of assurance, without first obtaining 113 * such license, approval or letter. 114 * 115 *****************************************************************************/ 116 117#define __RSIRQ_C__ 118 119#include "acpi.h" 120#include "acresrc.h" 121 122#define _COMPONENT ACPI_RESOURCES 123 ACPI_MODULE_NAME ("rsirq") 124 125 126/******************************************************************************* 127 * 128 * FUNCTION: AcpiRsIrqResource 129 * 130 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte 131 * stream 132 * BytesConsumed - Pointer to where the number of bytes 133 * consumed the ByteStreamBuffer is 134 * returned 135 * OutputBuffer - Pointer to the return data buffer 136 * StructureSize - Pointer to where the number of bytes 137 * in the return data struct is returned 138 * 139 * RETURN: Status 140 * 141 * DESCRIPTION: Take the resource byte stream and fill out the appropriate 142 * structure pointed to by the OutputBuffer. Return the 143 * number of bytes consumed from the byte stream. 144 * 145 ******************************************************************************/ 146 147ACPI_STATUS 148AcpiRsIrqResource ( 149 UINT8 *ByteStreamBuffer, 150 ACPI_SIZE *BytesConsumed, 151 UINT8 **OutputBuffer, 152 ACPI_SIZE *StructureSize) 153{ 154 UINT8 *Buffer = ByteStreamBuffer; 155 ACPI_RESOURCE *OutputStruct = (void *) *OutputBuffer; 156 UINT16 Temp16 = 0; 157 UINT8 Temp8 = 0; 158 UINT8 Index; 159 UINT8 i; 160 ACPI_SIZE StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_IRQ); 161 162 163 ACPI_FUNCTION_TRACE ("RsIrqResource"); 164 165 166 /* 167 * The number of bytes consumed are contained in the descriptor 168 * (Bits:0-1) 169 */ 170 Temp8 = *Buffer; 171 *BytesConsumed = (Temp8 & 0x03) + 1; 172 OutputStruct->Id = ACPI_RSTYPE_IRQ; 173 174 /* 175 * Point to the 16-bits of Bytes 1 and 2 176 */ 177 Buffer += 1; 178 ACPI_MOVE_16_TO_16 (&Temp16, Buffer); 179 180 OutputStruct->Data.Irq.NumberOfInterrupts = 0; 181 182 /* Decode the IRQ bits */ 183 184 for (i = 0, Index = 0; Index < 16; Index++) 185 { 186 if ((Temp16 >> Index) & 0x01) 187 { 188 OutputStruct->Data.Irq.Interrupts[i] = Index; 189 i++; 190 } 191 } 192 193 /* Zero interrupts is valid */ 194 195 OutputStruct->Data.Irq.NumberOfInterrupts = i; 196 if (i > 0) 197 { 198 /* 199 * Calculate the structure size based upon the number of interrupts 200 */ 201 StructSize += ((ACPI_SIZE) i - 1) * 4; 202 } 203 204 /* 205 * Point to Byte 3 if it is used 206 */ 207 if (4 == *BytesConsumed) 208 { 209 Buffer += 2; 210 Temp8 = *Buffer; 211 212 /* 213 * Check for HE, LL or HL 214 */ 215 if (Temp8 & 0x01) 216 { 217 OutputStruct->Data.Irq.EdgeLevel = ACPI_EDGE_SENSITIVE; 218 OutputStruct->Data.Irq.ActiveHighLow = ACPI_ACTIVE_HIGH; 219 } 220 else 221 { 222 if (Temp8 & 0x8) 223 { 224 OutputStruct->Data.Irq.EdgeLevel = ACPI_LEVEL_SENSITIVE; 225 OutputStruct->Data.Irq.ActiveHighLow = ACPI_ACTIVE_LOW; 226 } 227 else 228 { 229 /* 230 * Only _LL and _HE polarity/trigger interrupts 231 * are allowed (ACPI spec v1.0b ection 6.4.2.1), 232 * so an error will occur if we reach this point 233 */ 234 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid interrupt polarity/trigger in resource list\n")); 235 return_ACPI_STATUS (AE_BAD_DATA); 236 } 237 } 238 239 /* 240 * Check for sharable 241 */ 242 OutputStruct->Data.Irq.SharedExclusive = (Temp8 >> 3) & 0x01; 243 } 244 else 245 { 246 /* 247 * Assume Edge Sensitive, Active High, Non-Sharable 248 * per ACPI Specification 249 */ 250 OutputStruct->Data.Irq.EdgeLevel = ACPI_EDGE_SENSITIVE; 251 OutputStruct->Data.Irq.ActiveHighLow = ACPI_ACTIVE_HIGH; 252 OutputStruct->Data.Irq.SharedExclusive = ACPI_EXCLUSIVE; 253 } 254 255 /* 256 * Set the Length parameter 257 */ 258 OutputStruct->Length = (UINT32) StructSize; 259 260 /* 261 * Return the final size of the structure 262 */ 263 *StructureSize = StructSize; 264 return_ACPI_STATUS (AE_OK); 265} 266 267 268/******************************************************************************* 269 * 270 * FUNCTION: AcpiRsIrqStream 271 * 272 * PARAMETERS: LinkedList - Pointer to the resource linked list 273 * OutputBuffer - Pointer to the user's return buffer 274 * BytesConsumed - Pointer to where the number of bytes 275 * used in the OutputBuffer is returned 276 * 277 * RETURN: Status 278 * 279 * DESCRIPTION: Take the linked list resource structure and fills in the 280 * the appropriate bytes in a byte stream 281 * 282 ******************************************************************************/ 283 284ACPI_STATUS 285AcpiRsIrqStream ( 286 ACPI_RESOURCE *LinkedList, 287 UINT8 **OutputBuffer, 288 ACPI_SIZE *BytesConsumed) 289{ 290 UINT8 *Buffer = *OutputBuffer; 291 UINT16 Temp16 = 0; 292 UINT8 Temp8 = 0; 293 UINT8 Index; 294 BOOLEAN IRQInfoByteNeeded; 295 296 297 ACPI_FUNCTION_TRACE ("RsIrqStream"); 298 299 300 /* 301 * The descriptor field is set based upon whether a third byte is 302 * needed to contain the IRQ Information. 303 */ 304 if (ACPI_EDGE_SENSITIVE == LinkedList->Data.Irq.EdgeLevel && 305 ACPI_ACTIVE_HIGH == LinkedList->Data.Irq.ActiveHighLow && 306 ACPI_EXCLUSIVE == LinkedList->Data.Irq.SharedExclusive) 307 { 308 *Buffer = 0x22; 309 IRQInfoByteNeeded = FALSE; 310 } 311 else 312 { 313 *Buffer = 0x23; 314 IRQInfoByteNeeded = TRUE; 315 } 316 317 Buffer += 1; 318 Temp16 = 0; 319 320 /* 321 * Loop through all of the interrupts and set the mask bits 322 */ 323 for(Index = 0; 324 Index < LinkedList->Data.Irq.NumberOfInterrupts; 325 Index++) 326 { 327 Temp8 = (UINT8) LinkedList->Data.Irq.Interrupts[Index]; 328 Temp16 |= 0x1 << Temp8; 329 } 330 331 ACPI_MOVE_16_TO_16 (Buffer, &Temp16); 332 Buffer += 2; 333 334 /* 335 * Set the IRQ Info byte if needed. 336 */ 337 if (IRQInfoByteNeeded) 338 { 339 Temp8 = 0; 340 Temp8 = (UINT8) ((LinkedList->Data.Irq.SharedExclusive & 341 0x01) << 4); 342 343 if (ACPI_LEVEL_SENSITIVE == LinkedList->Data.Irq.EdgeLevel && 344 ACPI_ACTIVE_LOW == LinkedList->Data.Irq.ActiveHighLow) 345 { 346 Temp8 |= 0x08; 347 } 348 else 349 { 350 Temp8 |= 0x01; 351 } 352 353 *Buffer = Temp8; 354 Buffer += 1; 355 } 356 357 /* 358 * Return the number of bytes consumed in this operation 359 */ 360 *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer); 361 return_ACPI_STATUS (AE_OK); 362} 363 364 365/******************************************************************************* 366 * 367 * FUNCTION: AcpiRsExtendedIrqResource 368 * 369 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte 370 * stream 371 * BytesConsumed - Pointer to where the number of bytes 372 * consumed the ByteStreamBuffer is 373 * returned 374 * OutputBuffer - Pointer to the return data buffer 375 * StructureSize - Pointer to where the number of bytes 376 * in the return data struct is returned 377 * 378 * RETURN: Status 379 * 380 * DESCRIPTION: Take the resource byte stream and fill out the appropriate 381 * structure pointed to by the OutputBuffer. Return the 382 * number of bytes consumed from the byte stream. 383 * 384 ******************************************************************************/ 385 386ACPI_STATUS 387AcpiRsExtendedIrqResource ( 388 UINT8 *ByteStreamBuffer, 389 ACPI_SIZE *BytesConsumed, 390 UINT8 **OutputBuffer, 391 ACPI_SIZE *StructureSize) 392{ 393 UINT8 *Buffer = ByteStreamBuffer; 394 ACPI_RESOURCE *OutputStruct = (void *) *OutputBuffer; 395 UINT16 Temp16 = 0; 396 UINT8 Temp8 = 0; 397 UINT8 *TempPtr; 398 UINT8 Index; 399 ACPI_SIZE StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_EXT_IRQ); 400 401 402 ACPI_FUNCTION_TRACE ("RsExtendedIrqResource"); 403 404 405 /* 406 * Point past the Descriptor to get the number of bytes consumed 407 */ 408 Buffer += 1; 409 ACPI_MOVE_16_TO_16 (&Temp16, Buffer); 410 411 *BytesConsumed = Temp16 + 3; 412 OutputStruct->Id = ACPI_RSTYPE_EXT_IRQ; 413 414 /* 415 * Point to the Byte3 416 */ 417 Buffer += 2; 418 Temp8 = *Buffer; 419 420 OutputStruct->Data.ExtendedIrq.ProducerConsumer = Temp8 & 0x01; 421 422 /* 423 * Check for Interrupt Mode 424 * 425 * The definition of an Extended IRQ changed between ACPI spec v1.0b 426 * and ACPI spec 2.0 (section 6.4.3.6 in both). 427 * 428 * - Edge/Level are defined opposite in the table vs the headers 429 */ 430 OutputStruct->Data.ExtendedIrq.EdgeLevel = 431 (Temp8 & 0x2) ? ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE; 432 433 /* 434 * Check Interrupt Polarity 435 */ 436 OutputStruct->Data.ExtendedIrq.ActiveHighLow = (Temp8 >> 2) & 0x1; 437 438 /* 439 * Check for sharable 440 */ 441 OutputStruct->Data.ExtendedIrq.SharedExclusive = (Temp8 >> 3) & 0x01; 442 443 /* 444 * Point to Byte4 (IRQ Table length) 445 */ 446 Buffer += 1; 447 Temp8 = *Buffer; 448 449 OutputStruct->Data.ExtendedIrq.NumberOfInterrupts = Temp8; 450 451 /* 452 * Add any additional structure size to properly calculate 453 * the next pointer at the end of this function 454 */ 455 StructSize += (Temp8 - 1) * 4; 456 457 /* 458 * Point to Byte5 (First IRQ Number) 459 */ 460 Buffer += 1; 461 462 /* 463 * Cycle through every IRQ in the table 464 */ 465 for (Index = 0; Index < Temp8; Index++) 466 { 467 ACPI_MOVE_32_TO_32 ( 468 &OutputStruct->Data.ExtendedIrq.Interrupts[Index], Buffer); 469 470 /* Point to the next IRQ */ 471 472 Buffer += 4; 473 } 474 475 /* 476 * This will leave us pointing to the Resource Source Index 477 * If it is present, then save it off and calculate the 478 * pointer to where the null terminated string goes: 479 * Each Interrupt takes 32-bits + the 5 bytes of the 480 * stream that are default. 481 */ 482 if (*BytesConsumed > 483 ((ACPI_SIZE) OutputStruct->Data.ExtendedIrq.NumberOfInterrupts * 4) + 5) 484 { 485 /* Dereference the Index */ 486 487 Temp8 = *Buffer; 488 OutputStruct->Data.ExtendedIrq.ResourceSource.Index = (UINT32) Temp8; 489 490 /* Point to the String */ 491 492 Buffer += 1; 493 494 /* 495 * Point the String pointer to the end of this structure. 496 */ 497 OutputStruct->Data.ExtendedIrq.ResourceSource.StringPtr = 498 (char *)(OutputStruct + StructSize); 499 500 TempPtr = (UINT8 *) OutputStruct->Data.ExtendedIrq.ResourceSource.StringPtr; 501 502 /* Copy the string into the buffer */ 503 504 Index = 0; 505 while (0x00 != *Buffer) 506 { 507 *TempPtr = *Buffer; 508 509 TempPtr += 1; 510 Buffer += 1; 511 Index += 1; 512 } 513 514 /* 515 * Add the terminating null 516 */ 517 *TempPtr = 0x00; 518 OutputStruct->Data.ExtendedIrq.ResourceSource.StringLength = Index + 1; 519 520 /* 521 * In order for the StructSize to fall on a 32-bit boundary, 522 * calculate the length of the string and expand the 523 * StructSize to the next 32-bit boundary. 524 */ 525 Temp8 = (UINT8) (Index + 1); 526 StructSize += ACPI_ROUND_UP_TO_32BITS (Temp8); 527 } 528 else 529 { 530 OutputStruct->Data.ExtendedIrq.ResourceSource.Index = 0x00; 531 OutputStruct->Data.ExtendedIrq.ResourceSource.StringLength = 0; 532 OutputStruct->Data.ExtendedIrq.ResourceSource.StringPtr = NULL; 533 } 534 535 /* 536 * Set the Length parameter 537 */ 538 OutputStruct->Length = (UINT32) StructSize; 539 540 /* 541 * Return the final size of the structure 542 */ 543 *StructureSize = StructSize; 544 return_ACPI_STATUS (AE_OK); 545} 546 547 548/******************************************************************************* 549 * 550 * FUNCTION: AcpiRsExtendedIrqStream 551 * 552 * PARAMETERS: LinkedList - Pointer to the resource linked list 553 * OutputBuffer - Pointer to the user's return buffer 554 * BytesConsumed - Pointer to where the number of bytes 555 * used in the OutputBuffer is returned 556 * 557 * RETURN: Status 558 * 559 * DESCRIPTION: Take the linked list resource structure and fills in the 560 * the appropriate bytes in a byte stream 561 * 562 ******************************************************************************/ 563 564ACPI_STATUS 565AcpiRsExtendedIrqStream ( 566 ACPI_RESOURCE *LinkedList, 567 UINT8 **OutputBuffer, 568 ACPI_SIZE *BytesConsumed) 569{ 570 UINT8 *Buffer = *OutputBuffer; 571 UINT16 *LengthField; 572 UINT8 Temp8 = 0; 573 UINT8 Index; 574 char *TempPointer = NULL; 575 576 577 ACPI_FUNCTION_TRACE ("RsExtendedIrqStream"); 578 579 580 /* 581 * The descriptor field is static 582 */ 583 *Buffer = 0x89; 584 Buffer += 1; 585 586 /* 587 * Set a pointer to the Length field - to be filled in later 588 */ 589 LengthField = ACPI_CAST_PTR (UINT16, Buffer); 590 Buffer += 2; 591 592 /* 593 * Set the Interrupt vector flags 594 */ 595 Temp8 = (UINT8)(LinkedList->Data.ExtendedIrq.ProducerConsumer & 0x01); 596 Temp8 |= ((LinkedList->Data.ExtendedIrq.SharedExclusive & 0x01) << 3); 597 598 /* 599 * Set the Interrupt Mode 600 * 601 * The definition of an Extended IRQ changed between ACPI spec v1.0b 602 * and ACPI spec 2.0 (section 6.4.3.6 in both). This code does not 603 * implement the more restrictive definition of 1.0b 604 * 605 * - Edge/Level are defined opposite in the table vs the headers 606 */ 607 if (ACPI_EDGE_SENSITIVE == LinkedList->Data.ExtendedIrq.EdgeLevel) 608 { 609 Temp8 |= 0x2; 610 } 611 612 /* 613 * Set the Interrupt Polarity 614 */ 615 Temp8 |= ((LinkedList->Data.ExtendedIrq.ActiveHighLow & 0x1) << 2); 616 617 *Buffer = Temp8; 618 Buffer += 1; 619 620 /* 621 * Set the Interrupt table length 622 */ 623 Temp8 = (UINT8) LinkedList->Data.ExtendedIrq.NumberOfInterrupts; 624 625 *Buffer = Temp8; 626 Buffer += 1; 627 628 for (Index = 0; Index < LinkedList->Data.ExtendedIrq.NumberOfInterrupts; 629 Index++) 630 { 631 ACPI_MOVE_32_TO_32 (Buffer, 632 &LinkedList->Data.ExtendedIrq.Interrupts[Index]); 633 Buffer += 4; 634 } 635 636 /* 637 * Resource Source Index and Resource Source are optional 638 */ 639 if (0 != LinkedList->Data.ExtendedIrq.ResourceSource.StringLength) 640 { 641 *Buffer = (UINT8) LinkedList->Data.ExtendedIrq.ResourceSource.Index; 642 Buffer += 1; 643 644 TempPointer = (char *) Buffer; 645 646 /* 647 * Copy the string 648 */ 649 ACPI_STRCPY (TempPointer, 650 LinkedList->Data.ExtendedIrq.ResourceSource.StringPtr); 651 652 /* 653 * Buffer needs to be set to the length of the sting + one for the 654 * terminating null 655 */ 656 Buffer += (ACPI_SIZE)(ACPI_STRLEN (LinkedList->Data.ExtendedIrq.ResourceSource.StringPtr) + 1); 657 } 658 659 /* 660 * Return the number of bytes consumed in this operation 661 */ 662 *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer); 663 664 /* 665 * Set the length field to the number of bytes consumed 666 * minus the header size (3 bytes) 667 */ 668 *LengthField = (UINT16) (*BytesConsumed - 3); 669 return_ACPI_STATUS (AE_OK); 670} 671 672