1 /*******************************************************************************
3 * Module Name: rsirq - IRQ resource descriptors
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
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
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
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;
38 * The above copyright and patent license is granted only if the following
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.
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
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
73 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
81 * 4. Disclaimer and Export Compliance
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
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
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.
115 *****************************************************************************/
122 #define _COMPONENT ACPI_RESOURCES
123 ACPI_MODULE_NAME ("rsirq")
126 /*******************************************************************************
128 * FUNCTION: AcpiRsIrqResource
130 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte
132 * BytesConsumed - Pointer to where the number of bytes
133 * consumed the ByteStreamBuffer is
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
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.
145 ******************************************************************************/
149 UINT8
*ByteStreamBuffer
,
150 ACPI_SIZE
*BytesConsumed
,
151 UINT8
**OutputBuffer
,
152 ACPI_SIZE
*StructureSize
)
154 UINT8
*Buffer
= ByteStreamBuffer
;
155 ACPI_RESOURCE
*OutputStruct
= (void *) *OutputBuffer
;
160 ACPI_SIZE StructSize
= ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_IRQ
);
163 ACPI_FUNCTION_TRACE ("RsIrqResource");
167 * The number of bytes consumed are contained in the descriptor
171 *BytesConsumed
= (Temp8
& 0x03) + 1;
172 OutputStruct
->Id
= ACPI_RSTYPE_IRQ
;
175 * Point to the 16-bits of Bytes 1 and 2
178 ACPI_MOVE_16_TO_16 (&Temp16
, Buffer
);
180 OutputStruct
->Data
.Irq
.NumberOfInterrupts
= 0;
182 /* Decode the IRQ bits */
184 for (i
= 0, Index
= 0; Index
< 16; Index
++)
186 if ((Temp16
>> Index
) & 0x01)
188 OutputStruct
->Data
.Irq
.Interrupts
[i
] = Index
;
193 /* Zero interrupts is valid */
195 OutputStruct
->Data
.Irq
.NumberOfInterrupts
= i
;
199 * Calculate the structure size based upon the number of interrupts
201 StructSize
+= ((ACPI_SIZE
) i
- 1) * 4;
205 * Point to Byte 3 if it is used
207 if (4 == *BytesConsumed
)
213 * Check for HE, LL interrupts
215 switch (Temp8
& 0x09)
218 OutputStruct
->Data
.Irq
.EdgeLevel
= ACPI_EDGE_SENSITIVE
;
219 OutputStruct
->Data
.Irq
.ActiveHighLow
= ACPI_ACTIVE_HIGH
;
223 OutputStruct
->Data
.Irq
.EdgeLevel
= ACPI_LEVEL_SENSITIVE
;
224 OutputStruct
->Data
.Irq
.ActiveHighLow
= ACPI_ACTIVE_LOW
;
229 * Only _LL and _HE polarity/trigger interrupts
230 * are allowed (ACPI spec, section "IRQ Format")
231 * so 0x00 and 0x09 are illegal.
233 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
234 "Invalid interrupt polarity/trigger in resource list, %X\n", Temp8
));
235 return_ACPI_STATUS (AE_BAD_DATA
);
241 OutputStruct
->Data
.Irq
.SharedExclusive
= (Temp8
>> 3) & 0x01;
246 * Assume Edge Sensitive, Active High, Non-Sharable
247 * per ACPI Specification
249 OutputStruct
->Data
.Irq
.EdgeLevel
= ACPI_EDGE_SENSITIVE
;
250 OutputStruct
->Data
.Irq
.ActiveHighLow
= ACPI_ACTIVE_HIGH
;
251 OutputStruct
->Data
.Irq
.SharedExclusive
= ACPI_EXCLUSIVE
;
255 * Set the Length parameter
257 OutputStruct
->Length
= (UINT32
) StructSize
;
260 * Return the final size of the structure
262 *StructureSize
= StructSize
;
263 return_ACPI_STATUS (AE_OK
);
267 /*******************************************************************************
269 * FUNCTION: AcpiRsIrqStream
271 * PARAMETERS: LinkedList - Pointer to the resource linked list
272 * OutputBuffer - Pointer to the user's return buffer
273 * BytesConsumed - Pointer to where the number of bytes
274 * used in the OutputBuffer is returned
278 * DESCRIPTION: Take the linked list resource structure and fills in the
279 * the appropriate bytes in a byte stream
281 ******************************************************************************/
285 ACPI_RESOURCE
*LinkedList
,
286 UINT8
**OutputBuffer
,
287 ACPI_SIZE
*BytesConsumed
)
289 UINT8
*Buffer
= *OutputBuffer
;
293 BOOLEAN IRQInfoByteNeeded
;
296 ACPI_FUNCTION_TRACE ("RsIrqStream");
300 * The descriptor field is set based upon whether a third byte is
301 * needed to contain the IRQ Information.
303 if (ACPI_EDGE_SENSITIVE
== LinkedList
->Data
.Irq
.EdgeLevel
&&
304 ACPI_ACTIVE_HIGH
== LinkedList
->Data
.Irq
.ActiveHighLow
&&
305 ACPI_EXCLUSIVE
== LinkedList
->Data
.Irq
.SharedExclusive
)
308 IRQInfoByteNeeded
= FALSE
;
313 IRQInfoByteNeeded
= TRUE
;
320 * Loop through all of the interrupts and set the mask bits
323 Index
< LinkedList
->Data
.Irq
.NumberOfInterrupts
;
326 Temp8
= (UINT8
) LinkedList
->Data
.Irq
.Interrupts
[Index
];
327 Temp16
|= 0x1 << Temp8
;
330 ACPI_MOVE_16_TO_16 (Buffer
, &Temp16
);
334 * Set the IRQ Info byte if needed.
336 if (IRQInfoByteNeeded
)
339 Temp8
= (UINT8
) ((LinkedList
->Data
.Irq
.SharedExclusive
&
342 if (ACPI_LEVEL_SENSITIVE
== LinkedList
->Data
.Irq
.EdgeLevel
&&
343 ACPI_ACTIVE_LOW
== LinkedList
->Data
.Irq
.ActiveHighLow
)
357 * Return the number of bytes consumed in this operation
359 *BytesConsumed
= ACPI_PTR_DIFF (Buffer
, *OutputBuffer
);
360 return_ACPI_STATUS (AE_OK
);
364 /*******************************************************************************
366 * FUNCTION: AcpiRsExtendedIrqResource
368 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte
370 * BytesConsumed - Pointer to where the number of bytes
371 * consumed the ByteStreamBuffer is
373 * OutputBuffer - Pointer to the return data buffer
374 * StructureSize - Pointer to where the number of bytes
375 * in the return data struct is returned
379 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
380 * structure pointed to by the OutputBuffer. Return the
381 * number of bytes consumed from the byte stream.
383 ******************************************************************************/
386 AcpiRsExtendedIrqResource (
387 UINT8
*ByteStreamBuffer
,
388 ACPI_SIZE
*BytesConsumed
,
389 UINT8
**OutputBuffer
,
390 ACPI_SIZE
*StructureSize
)
392 UINT8
*Buffer
= ByteStreamBuffer
;
393 ACPI_RESOURCE
*OutputStruct
= (void *) *OutputBuffer
;
398 ACPI_SIZE StructSize
= ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_EXT_IRQ
);
401 ACPI_FUNCTION_TRACE ("RsExtendedIrqResource");
405 * Point past the Descriptor to get the number of bytes consumed
408 ACPI_MOVE_16_TO_16 (&Temp16
, Buffer
);
410 /* Validate minimum descriptor length */
414 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH
);
417 *BytesConsumed
= Temp16
+ 3;
418 OutputStruct
->Id
= ACPI_RSTYPE_EXT_IRQ
;
426 OutputStruct
->Data
.ExtendedIrq
.ProducerConsumer
= Temp8
& 0x01;
429 * Check for Interrupt Mode
431 * The definition of an Extended IRQ changed between ACPI spec v1.0b
432 * and ACPI spec 2.0 (section 6.4.3.6 in both).
434 * - Edge/Level are defined opposite in the table vs the headers
436 OutputStruct
->Data
.ExtendedIrq
.EdgeLevel
=
437 (Temp8
& 0x2) ? ACPI_EDGE_SENSITIVE
: ACPI_LEVEL_SENSITIVE
;
440 * Check Interrupt Polarity
442 OutputStruct
->Data
.ExtendedIrq
.ActiveHighLow
= (Temp8
>> 2) & 0x1;
447 OutputStruct
->Data
.ExtendedIrq
.SharedExclusive
= (Temp8
>> 3) & 0x01;
450 * Point to Byte4 (IRQ Table length)
455 /* Must have at least one IRQ */
459 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH
);
462 OutputStruct
->Data
.ExtendedIrq
.NumberOfInterrupts
= Temp8
;
465 * Add any additional structure size to properly calculate
466 * the next pointer at the end of this function
468 StructSize
+= (Temp8
- 1) * 4;
471 * Point to Byte5 (First IRQ Number)
476 * Cycle through every IRQ in the table
478 for (Index
= 0; Index
< Temp8
; Index
++)
481 &OutputStruct
->Data
.ExtendedIrq
.Interrupts
[Index
], Buffer
);
483 /* Point to the next IRQ */
489 * This will leave us pointing to the Resource Source Index
490 * If it is present, then save it off and calculate the
491 * pointer to where the null terminated string goes:
492 * Each Interrupt takes 32-bits + the 5 bytes of the
493 * stream that are default.
495 * Note: Some resource descriptors will have an additional null, so
496 * we add 1 to the length.
499 ((ACPI_SIZE
) OutputStruct
->Data
.ExtendedIrq
.NumberOfInterrupts
* 4) + (5 + 1))
501 /* Dereference the Index */
504 OutputStruct
->Data
.ExtendedIrq
.ResourceSource
.Index
= (UINT32
) Temp8
;
506 /* Point to the String */
511 * Point the String pointer to the end of this structure.
513 OutputStruct
->Data
.ExtendedIrq
.ResourceSource
.StringPtr
=
514 (char *)((char *) OutputStruct
+ StructSize
);
516 TempPtr
= (UINT8
*) OutputStruct
->Data
.ExtendedIrq
.ResourceSource
.StringPtr
;
518 /* Copy the string into the buffer */
521 while (0x00 != *Buffer
)
531 * Add the terminating null
534 OutputStruct
->Data
.ExtendedIrq
.ResourceSource
.StringLength
= Index
+ 1;
537 * In order for the StructSize to fall on a 32-bit boundary,
538 * calculate the length of the string and expand the
539 * StructSize to the next 32-bit boundary.
541 Temp8
= (UINT8
) (Index
+ 1);
542 StructSize
+= ACPI_ROUND_UP_TO_32BITS (Temp8
);
546 OutputStruct
->Data
.ExtendedIrq
.ResourceSource
.Index
= 0x00;
547 OutputStruct
->Data
.ExtendedIrq
.ResourceSource
.StringLength
= 0;
548 OutputStruct
->Data
.ExtendedIrq
.ResourceSource
.StringPtr
= NULL
;
552 * Set the Length parameter
554 OutputStruct
->Length
= (UINT32
) StructSize
;
557 * Return the final size of the structure
559 *StructureSize
= StructSize
;
560 return_ACPI_STATUS (AE_OK
);
564 /*******************************************************************************
566 * FUNCTION: AcpiRsExtendedIrqStream
568 * PARAMETERS: LinkedList - Pointer to the resource linked list
569 * OutputBuffer - Pointer to the user's return buffer
570 * BytesConsumed - Pointer to where the number of bytes
571 * used in the OutputBuffer is returned
575 * DESCRIPTION: Take the linked list resource structure and fills in the
576 * the appropriate bytes in a byte stream
578 ******************************************************************************/
581 AcpiRsExtendedIrqStream (
582 ACPI_RESOURCE
*LinkedList
,
583 UINT8
**OutputBuffer
,
584 ACPI_SIZE
*BytesConsumed
)
586 UINT8
*Buffer
= *OutputBuffer
;
590 char *TempPointer
= NULL
;
593 ACPI_FUNCTION_TRACE ("RsExtendedIrqStream");
597 * The descriptor field is static
603 * Set a pointer to the Length field - to be filled in later
605 LengthField
= ACPI_CAST_PTR (UINT16
, Buffer
);
609 * Set the Interrupt vector flags
611 Temp8
= (UINT8
)(LinkedList
->Data
.ExtendedIrq
.ProducerConsumer
& 0x01);
612 Temp8
|= ((LinkedList
->Data
.ExtendedIrq
.SharedExclusive
& 0x01) << 3);
615 * Set the Interrupt Mode
617 * The definition of an Extended IRQ changed between ACPI spec v1.0b
618 * and ACPI spec 2.0 (section 6.4.3.6 in both). This code does not
619 * implement the more restrictive definition of 1.0b
621 * - Edge/Level are defined opposite in the table vs the headers
623 if (ACPI_EDGE_SENSITIVE
== LinkedList
->Data
.ExtendedIrq
.EdgeLevel
)
629 * Set the Interrupt Polarity
631 Temp8
|= ((LinkedList
->Data
.ExtendedIrq
.ActiveHighLow
& 0x1) << 2);
637 * Set the Interrupt table length
639 Temp8
= (UINT8
) LinkedList
->Data
.ExtendedIrq
.NumberOfInterrupts
;
644 for (Index
= 0; Index
< LinkedList
->Data
.ExtendedIrq
.NumberOfInterrupts
;
647 ACPI_MOVE_32_TO_32 (Buffer
,
648 &LinkedList
->Data
.ExtendedIrq
.Interrupts
[Index
]);
653 * Resource Source Index and Resource Source are optional
655 if (0 != LinkedList
->Data
.ExtendedIrq
.ResourceSource
.StringLength
)
657 *Buffer
= (UINT8
) LinkedList
->Data
.ExtendedIrq
.ResourceSource
.Index
;
660 TempPointer
= (char *) Buffer
;
665 ACPI_STRCPY (TempPointer
,
666 LinkedList
->Data
.ExtendedIrq
.ResourceSource
.StringPtr
);
669 * Buffer needs to be set to the length of the sting + one for the
672 Buffer
+= (ACPI_SIZE
)(ACPI_STRLEN (LinkedList
->Data
.ExtendedIrq
.ResourceSource
.StringPtr
) + 1);
676 * Return the number of bytes consumed in this operation
678 *BytesConsumed
= ACPI_PTR_DIFF (Buffer
, *OutputBuffer
);
681 * Set the length field to the number of bytes consumed
682 * minus the header size (3 bytes)
684 *LengthField
= (UINT16
) (*BytesConsumed
- 3);
685 return_ACPI_STATUS (AE_OK
);