1 /*******************************************************************************
3 * Module Name: rsirq - IRQ resource descriptors
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2003, 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 *****************************************************************************/
116 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/rsirq.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $ */
123 #define _COMPONENT ACPI_RESOURCES
124 ACPI_MODULE_NAME ("rsirq")
127 /*******************************************************************************
129 * FUNCTION: AcpiRsIrqResource
131 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte
133 * BytesConsumed - Pointer to where the number of bytes
134 * consumed the ByteStreamBuffer is
136 * OutputBuffer - Pointer to the return data buffer
137 * StructureSize - Pointer to where the number of bytes
138 * in the return data struct is returned
142 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
143 * structure pointed to by the OutputBuffer. Return the
144 * number of bytes consumed from the byte stream.
146 ******************************************************************************/
150 UINT8 *ByteStreamBuffer,
151 ACPI_SIZE *BytesConsumed,
152 UINT8 **OutputBuffer,
153 ACPI_SIZE *StructureSize)
155 UINT8 *Buffer = ByteStreamBuffer;
156 ACPI_RESOURCE *OutputStruct = (void *) *OutputBuffer;
161 ACPI_SIZE StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_IRQ);
164 ACPI_FUNCTION_TRACE ("RsIrqResource");
168 * The number of bytes consumed are contained in the descriptor
172 *BytesConsumed = (Temp8 & 0x03) + 1;
173 OutputStruct->Id = ACPI_RSTYPE_IRQ;
176 * Point to the 16-bits of Bytes 1 and 2
179 ACPI_MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
181 OutputStruct->Data.Irq.NumberOfInterrupts = 0;
183 /* Decode the IRQ bits */
185 for (i = 0, Index = 0; Index < 16; Index++)
187 if ((Temp16 >> Index) & 0x01)
189 OutputStruct->Data.Irq.Interrupts[i] = Index;
194 /* Zero interrupts is valid */
196 OutputStruct->Data.Irq.NumberOfInterrupts = i;
200 * Calculate the structure size based upon the number of interrupts
202 StructSize += ((ACPI_SIZE) i - 1) * 4;
206 * Point to Byte 3 if it is used
208 if (4 == *BytesConsumed)
214 * Check for HE, LL or HL
218 OutputStruct->Data.Irq.EdgeLevel = ACPI_EDGE_SENSITIVE;
219 OutputStruct->Data.Irq.ActiveHighLow = ACPI_ACTIVE_HIGH;
225 OutputStruct->Data.Irq.EdgeLevel = ACPI_LEVEL_SENSITIVE;
226 OutputStruct->Data.Irq.ActiveHighLow = ACPI_ACTIVE_LOW;
231 * Only _LL and _HE polarity/trigger interrupts
232 * are allowed (ACPI spec v1.0b ection 6.4.2.1),
233 * so an error will occur if we reach this point
235 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid interrupt polarity/trigger in resource list\n"));
236 return_ACPI_STATUS (AE_BAD_DATA);
243 OutputStruct->Data.Irq.SharedExclusive = (Temp8 >> 3) & 0x01;
248 * Assume Edge Sensitive, Active High, Non-Sharable
249 * per ACPI Specification
251 OutputStruct->Data.Irq.EdgeLevel = ACPI_EDGE_SENSITIVE;
252 OutputStruct->Data.Irq.ActiveHighLow = ACPI_ACTIVE_HIGH;
253 OutputStruct->Data.Irq.SharedExclusive = ACPI_EXCLUSIVE;
257 * Set the Length parameter
259 OutputStruct->Length = (UINT32) StructSize;
262 * Return the final size of the structure
264 *StructureSize = StructSize;
265 return_ACPI_STATUS (AE_OK);
269 /*******************************************************************************
271 * FUNCTION: AcpiRsIrqStream
273 * PARAMETERS: LinkedList - Pointer to the resource linked list
274 * OutputBuffer - Pointer to the user's return buffer
275 * BytesConsumed - Pointer to where the number of bytes
276 * used in the OutputBuffer is returned
280 * DESCRIPTION: Take the linked list resource structure and fills in the
281 * the appropriate bytes in a byte stream
283 ******************************************************************************/
287 ACPI_RESOURCE *LinkedList,
288 UINT8 **OutputBuffer,
289 ACPI_SIZE *BytesConsumed)
291 UINT8 *Buffer = *OutputBuffer;
295 BOOLEAN IRQInfoByteNeeded;
298 ACPI_FUNCTION_TRACE ("RsIrqStream");
302 * The descriptor field is set based upon whether a third byte is
303 * needed to contain the IRQ Information.
305 if (ACPI_EDGE_SENSITIVE == LinkedList->Data.Irq.EdgeLevel &&
306 ACPI_ACTIVE_HIGH == LinkedList->Data.Irq.ActiveHighLow &&
307 ACPI_EXCLUSIVE == LinkedList->Data.Irq.SharedExclusive)
310 IRQInfoByteNeeded = FALSE;
315 IRQInfoByteNeeded = TRUE;
322 * Loop through all of the interrupts and set the mask bits
325 Index < LinkedList->Data.Irq.NumberOfInterrupts;
328 Temp8 = (UINT8) LinkedList->Data.Irq.Interrupts[Index];
329 Temp16 |= 0x1 << Temp8;
332 ACPI_MOVE_UNALIGNED16_TO_16 (Buffer, &Temp16);
336 * Set the IRQ Info byte if needed.
338 if (IRQInfoByteNeeded)
341 Temp8 = (UINT8) ((LinkedList->Data.Irq.SharedExclusive &
344 if (ACPI_LEVEL_SENSITIVE == LinkedList->Data.Irq.EdgeLevel &&
345 ACPI_ACTIVE_LOW == LinkedList->Data.Irq.ActiveHighLow)
359 * Return the number of bytes consumed in this operation
361 *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
362 return_ACPI_STATUS (AE_OK);
366 /*******************************************************************************
368 * FUNCTION: AcpiRsExtendedIrqResource
370 * PARAMETERS: ByteStreamBuffer - Pointer to the resource input byte
372 * BytesConsumed - Pointer to where the number of bytes
373 * consumed the ByteStreamBuffer is
375 * OutputBuffer - Pointer to the return data buffer
376 * StructureSize - Pointer to where the number of bytes
377 * in the return data struct is returned
381 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
382 * structure pointed to by the OutputBuffer. Return the
383 * number of bytes consumed from the byte stream.
385 ******************************************************************************/
388 AcpiRsExtendedIrqResource (
389 UINT8 *ByteStreamBuffer,
390 ACPI_SIZE *BytesConsumed,
391 UINT8 **OutputBuffer,
392 ACPI_SIZE *StructureSize)
394 UINT8 *Buffer = ByteStreamBuffer;
395 ACPI_RESOURCE *OutputStruct = (void *) *OutputBuffer;
400 ACPI_SIZE StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_EXT_IRQ);
403 ACPI_FUNCTION_TRACE ("RsExtendedIrqResource");
407 * Point past the Descriptor to get the number of bytes consumed
410 ACPI_MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
412 *BytesConsumed = Temp16 + 3;
413 OutputStruct->Id = ACPI_RSTYPE_EXT_IRQ;
421 OutputStruct->Data.ExtendedIrq.ProducerConsumer = Temp8 & 0x01;
424 * Check for Interrupt Mode
426 * The definition of an Extended IRQ changed between ACPI spec v1.0b
427 * and ACPI spec 2.0 (section 6.4.3.6 in both).
429 * - Edge/Level are defined opposite in the table vs the headers
431 OutputStruct->Data.ExtendedIrq.EdgeLevel =
432 (Temp8 & 0x2) ? ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE;
435 * Check Interrupt Polarity
437 OutputStruct->Data.ExtendedIrq.ActiveHighLow = (Temp8 >> 2) & 0x1;
442 OutputStruct->Data.ExtendedIrq.SharedExclusive = (Temp8 >> 3) & 0x01;
445 * Point to Byte4 (IRQ Table length)
450 OutputStruct->Data.ExtendedIrq.NumberOfInterrupts = Temp8;
453 * Add any additional structure size to properly calculate
454 * the next pointer at the end of this function
456 StructSize += (Temp8 - 1) * 4;
459 * Point to Byte5 (First IRQ Number)
464 * Cycle through every IRQ in the table
466 for (Index = 0; Index < Temp8; Index++)
468 ACPI_MOVE_UNALIGNED32_TO_32 (
469 &OutputStruct->Data.ExtendedIrq.Interrupts[Index], Buffer);
471 /* Point to the next IRQ */
477 * This will leave us pointing to the Resource Source Index
478 * If it is present, then save it off and calculate the
479 * pointer to where the null terminated string goes:
480 * Each Interrupt takes 32-bits + the 5 bytes of the
481 * stream that are default.
484 ((ACPI_SIZE) OutputStruct->Data.ExtendedIrq.NumberOfInterrupts * 4) + 5)
486 /* Dereference the Index */
489 OutputStruct->Data.ExtendedIrq.ResourceSource.Index = (UINT32) Temp8;
491 /* Point to the String */
496 * Point the String pointer to the end of this structure.
498 OutputStruct->Data.ExtendedIrq.ResourceSource.StringPtr =
499 (char *)(OutputStruct + StructSize);
501 TempPtr = (UINT8 *) OutputStruct->Data.ExtendedIrq.ResourceSource.StringPtr;
503 /* Copy the string into the buffer */
506 while (0x00 != *Buffer)
516 * Add the terminating null
519 OutputStruct->Data.ExtendedIrq.ResourceSource.StringLength = Index + 1;
522 * In order for the StructSize to fall on a 32-bit boundary,
523 * calculate the length of the string and expand the
524 * StructSize to the next 32-bit boundary.
526 Temp8 = (UINT8) (Index + 1);
527 StructSize += ACPI_ROUND_UP_TO_32BITS (Temp8);
531 OutputStruct->Data.ExtendedIrq.ResourceSource.Index = 0x00;
532 OutputStruct->Data.ExtendedIrq.ResourceSource.StringLength = 0;
533 OutputStruct->Data.ExtendedIrq.ResourceSource.StringPtr = NULL;
537 * Set the Length parameter
539 OutputStruct->Length = (UINT32) StructSize;
542 * Return the final size of the structure
544 *StructureSize = StructSize;
545 return_ACPI_STATUS (AE_OK);
549 /*******************************************************************************
551 * FUNCTION: AcpiRsExtendedIrqStream
553 * PARAMETERS: LinkedList - Pointer to the resource linked list
554 * OutputBuffer - Pointer to the user's return buffer
555 * BytesConsumed - Pointer to where the number of bytes
556 * used in the OutputBuffer is returned
560 * DESCRIPTION: Take the linked list resource structure and fills in the
561 * the appropriate bytes in a byte stream
563 ******************************************************************************/
566 AcpiRsExtendedIrqStream (
567 ACPI_RESOURCE *LinkedList,
568 UINT8 **OutputBuffer,
569 ACPI_SIZE *BytesConsumed)
571 UINT8 *Buffer = *OutputBuffer;
575 char *TempPointer = NULL;
578 ACPI_FUNCTION_TRACE ("RsExtendedIrqStream");
582 * The descriptor field is static
588 * Set a pointer to the Length field - to be filled in later
590 LengthField = ACPI_CAST_PTR (UINT16, Buffer);
594 * Set the Interrupt vector flags
596 Temp8 = (UINT8)(LinkedList->Data.ExtendedIrq.ProducerConsumer & 0x01);
597 Temp8 |= ((LinkedList->Data.ExtendedIrq.SharedExclusive & 0x01) << 3);
600 * Set the Interrupt Mode
602 * The definition of an Extended IRQ changed between ACPI spec v1.0b
603 * and ACPI spec 2.0 (section 6.4.3.6 in both). This code does not
604 * implement the more restrictive definition of 1.0b
606 * - Edge/Level are defined opposite in the table vs the headers
608 if (ACPI_EDGE_SENSITIVE == LinkedList->Data.ExtendedIrq.EdgeLevel)
614 * Set the Interrupt Polarity
616 Temp8 |= ((LinkedList->Data.ExtendedIrq.ActiveHighLow & 0x1) << 2);
622 * Set the Interrupt table length
624 Temp8 = (UINT8) LinkedList->Data.ExtendedIrq.NumberOfInterrupts;
629 for (Index = 0; Index < LinkedList->Data.ExtendedIrq.NumberOfInterrupts;
632 ACPI_MOVE_UNALIGNED32_TO_32 (Buffer,
633 &LinkedList->Data.ExtendedIrq.Interrupts[Index]);
638 * Resource Source Index and Resource Source are optional
640 if (0 != LinkedList->Data.ExtendedIrq.ResourceSource.StringLength)
642 *Buffer = (UINT8) LinkedList->Data.ExtendedIrq.ResourceSource.Index;
645 TempPointer = (char *) Buffer;
650 ACPI_STRCPY (TempPointer,
651 LinkedList->Data.ExtendedIrq.ResourceSource.StringPtr);
654 * Buffer needs to be set to the length of the sting + one for the
657 Buffer += (ACPI_STRLEN (LinkedList->Data.ExtendedIrq.ResourceSource.StringPtr) + 1);
661 * Return the number of bytes consumed in this operation
663 *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
666 * Set the length field to the number of bytes consumed
667 * minus the header size (3 bytes)
669 *LengthField = (UINT16) (*BytesConsumed - 3);
670 return_ACPI_STATUS (AE_OK);