1 /*******************************************************************************
3 * Module Name: rsirq - IRQ resource descriptors
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include <acpi/acpi.h>
46 #include <acpi/acresrc.h>
48 #define _COMPONENT ACPI_RESOURCES
49 ACPI_MODULE_NAME ("rsirq")
52 /*******************************************************************************
54 * FUNCTION: acpi_rs_irq_resource
56 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
58 * bytes_consumed - Pointer to where the number of bytes
59 * consumed the byte_stream_buffer is
61 * output_buffer - Pointer to the return data buffer
62 * structure_size - Pointer to where the number of bytes
63 * in the return data struct is returned
67 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
68 * structure pointed to by the output_buffer. Return the
69 * number of bytes consumed from the byte stream.
71 ******************************************************************************/
74 acpi_rs_irq_resource (
75 u8
*byte_stream_buffer
,
76 acpi_size
*bytes_consumed
,
78 acpi_size
*structure_size
)
80 u8
*buffer
= byte_stream_buffer
;
81 struct acpi_resource
*output_struct
= (void *) *output_buffer
;
86 acpi_size struct_size
= ACPI_SIZEOF_RESOURCE (struct acpi_resource_irq
);
89 ACPI_FUNCTION_TRACE ("rs_irq_resource");
93 * The number of bytes consumed are contained in the descriptor
97 *bytes_consumed
= (temp8
& 0x03) + 1;
98 output_struct
->id
= ACPI_RSTYPE_IRQ
;
101 * Point to the 16-bits of Bytes 1 and 2
104 ACPI_MOVE_16_TO_16 (&temp16
, buffer
);
106 output_struct
->data
.irq
.number_of_interrupts
= 0;
108 /* Decode the IRQ bits */
110 for (i
= 0, index
= 0; index
< 16; index
++) {
111 if ((temp16
>> index
) & 0x01) {
112 output_struct
->data
.irq
.interrupts
[i
] = index
;
117 /* Zero interrupts is valid */
119 output_struct
->data
.irq
.number_of_interrupts
= i
;
122 * Calculate the structure size based upon the number of interrupts
124 struct_size
+= ((acpi_size
) i
- 1) * 4;
128 * Point to Byte 3 if it is used
130 if (4 == *bytes_consumed
) {
135 * Check for HE, LL interrupts
137 switch (temp8
& 0x09) {
139 output_struct
->data
.irq
.edge_level
= ACPI_EDGE_SENSITIVE
;
140 output_struct
->data
.irq
.active_high_low
= ACPI_ACTIVE_HIGH
;
144 output_struct
->data
.irq
.edge_level
= ACPI_LEVEL_SENSITIVE
;
145 output_struct
->data
.irq
.active_high_low
= ACPI_ACTIVE_LOW
;
150 * Only _LL and _HE polarity/trigger interrupts
151 * are allowed (ACPI spec, section "IRQ Format")
152 * so 0x00 and 0x09 are illegal.
154 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
155 "Invalid interrupt polarity/trigger in resource list, %X\n", temp8
));
156 return_ACPI_STATUS (AE_BAD_DATA
);
162 output_struct
->data
.irq
.shared_exclusive
= (temp8
>> 3) & 0x01;
166 * Assume Edge Sensitive, Active High, Non-Sharable
167 * per ACPI Specification
169 output_struct
->data
.irq
.edge_level
= ACPI_EDGE_SENSITIVE
;
170 output_struct
->data
.irq
.active_high_low
= ACPI_ACTIVE_HIGH
;
171 output_struct
->data
.irq
.shared_exclusive
= ACPI_EXCLUSIVE
;
175 * Set the Length parameter
177 output_struct
->length
= (u32
) struct_size
;
180 * Return the final size of the structure
182 *structure_size
= struct_size
;
183 return_ACPI_STATUS (AE_OK
);
187 /*******************************************************************************
189 * FUNCTION: acpi_rs_irq_stream
191 * PARAMETERS: linked_list - Pointer to the resource linked list
192 * output_buffer - Pointer to the user's return buffer
193 * bytes_consumed - Pointer to where the number of bytes
194 * used in the output_buffer is returned
198 * DESCRIPTION: Take the linked list resource structure and fills in the
199 * the appropriate bytes in a byte stream
201 ******************************************************************************/
205 struct acpi_resource
*linked_list
,
207 acpi_size
*bytes_consumed
)
209 u8
*buffer
= *output_buffer
;
213 u8 IRqinfo_byte_needed
;
216 ACPI_FUNCTION_TRACE ("rs_irq_stream");
220 * The descriptor field is set based upon whether a third byte is
221 * needed to contain the IRQ Information.
223 if (ACPI_EDGE_SENSITIVE
== linked_list
->data
.irq
.edge_level
&&
224 ACPI_ACTIVE_HIGH
== linked_list
->data
.irq
.active_high_low
&&
225 ACPI_EXCLUSIVE
== linked_list
->data
.irq
.shared_exclusive
) {
227 IRqinfo_byte_needed
= FALSE
;
231 IRqinfo_byte_needed
= TRUE
;
238 * Loop through all of the interrupts and set the mask bits
241 index
< linked_list
->data
.irq
.number_of_interrupts
;
243 temp8
= (u8
) linked_list
->data
.irq
.interrupts
[index
];
244 temp16
|= 0x1 << temp8
;
247 ACPI_MOVE_16_TO_16 (buffer
, &temp16
);
251 * Set the IRQ Info byte if needed.
253 if (IRqinfo_byte_needed
) {
255 temp8
= (u8
) ((linked_list
->data
.irq
.shared_exclusive
&
258 if (ACPI_LEVEL_SENSITIVE
== linked_list
->data
.irq
.edge_level
&&
259 ACPI_ACTIVE_LOW
== linked_list
->data
.irq
.active_high_low
) {
271 * Return the number of bytes consumed in this operation
273 *bytes_consumed
= ACPI_PTR_DIFF (buffer
, *output_buffer
);
274 return_ACPI_STATUS (AE_OK
);
278 /*******************************************************************************
280 * FUNCTION: acpi_rs_extended_irq_resource
282 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
284 * bytes_consumed - Pointer to where the number of bytes
285 * consumed the byte_stream_buffer is
287 * output_buffer - Pointer to the return data buffer
288 * structure_size - Pointer to where the number of bytes
289 * in the return data struct is returned
293 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
294 * structure pointed to by the output_buffer. Return the
295 * number of bytes consumed from the byte stream.
297 ******************************************************************************/
300 acpi_rs_extended_irq_resource (
301 u8
*byte_stream_buffer
,
302 acpi_size
*bytes_consumed
,
304 acpi_size
*structure_size
)
306 u8
*buffer
= byte_stream_buffer
;
307 struct acpi_resource
*output_struct
= (void *) *output_buffer
;
312 acpi_size struct_size
= ACPI_SIZEOF_RESOURCE (struct acpi_resource_ext_irq
);
315 ACPI_FUNCTION_TRACE ("rs_extended_irq_resource");
319 * Point past the Descriptor to get the number of bytes consumed
322 ACPI_MOVE_16_TO_16 (&temp16
, buffer
);
324 /* Validate minimum descriptor length */
327 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH
);
330 *bytes_consumed
= temp16
+ 3;
331 output_struct
->id
= ACPI_RSTYPE_EXT_IRQ
;
339 output_struct
->data
.extended_irq
.producer_consumer
= temp8
& 0x01;
342 * Check for Interrupt Mode
344 * The definition of an Extended IRQ changed between ACPI spec v1.0b
345 * and ACPI spec 2.0 (section 6.4.3.6 in both).
347 * - Edge/Level are defined opposite in the table vs the headers
349 output_struct
->data
.extended_irq
.edge_level
=
350 (temp8
& 0x2) ? ACPI_EDGE_SENSITIVE
: ACPI_LEVEL_SENSITIVE
;
353 * Check Interrupt Polarity
355 output_struct
->data
.extended_irq
.active_high_low
= (temp8
>> 2) & 0x1;
360 output_struct
->data
.extended_irq
.shared_exclusive
= (temp8
>> 3) & 0x01;
363 * Point to Byte4 (IRQ Table length)
368 /* Must have at least one IRQ */
371 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH
);
374 output_struct
->data
.extended_irq
.number_of_interrupts
= temp8
;
377 * Add any additional structure size to properly calculate
378 * the next pointer at the end of this function
380 struct_size
+= (temp8
- 1) * 4;
383 * Point to Byte5 (First IRQ Number)
388 * Cycle through every IRQ in the table
390 for (index
= 0; index
< temp8
; index
++) {
392 &output_struct
->data
.extended_irq
.interrupts
[index
], buffer
);
394 /* Point to the next IRQ */
400 * This will leave us pointing to the Resource Source Index
401 * If it is present, then save it off and calculate the
402 * pointer to where the null terminated string goes:
403 * Each Interrupt takes 32-bits + the 5 bytes of the
404 * stream that are default.
406 * Note: Some resource descriptors will have an additional null, so
407 * we add 1 to the length.
409 if (*bytes_consumed
>
410 ((acpi_size
) output_struct
->data
.extended_irq
.number_of_interrupts
* 4) + (5 + 1)) {
411 /* Dereference the Index */
414 output_struct
->data
.extended_irq
.resource_source
.index
= (u32
) temp8
;
416 /* Point to the String */
421 * Point the String pointer to the end of this structure.
423 output_struct
->data
.extended_irq
.resource_source
.string_ptr
=
424 (char *)((char *) output_struct
+ struct_size
);
426 temp_ptr
= (u8
*) output_struct
->data
.extended_irq
.resource_source
.string_ptr
;
428 /* Copy the string into the buffer */
431 while (0x00 != *buffer
) {
440 * Add the terminating null
443 output_struct
->data
.extended_irq
.resource_source
.string_length
= index
+ 1;
446 * In order for the struct_size to fall on a 32-bit boundary,
447 * calculate the length of the string and expand the
448 * struct_size to the next 32-bit boundary.
450 temp8
= (u8
) (index
+ 1);
451 struct_size
+= ACPI_ROUND_UP_to_32_bITS (temp8
);
454 output_struct
->data
.extended_irq
.resource_source
.index
= 0x00;
455 output_struct
->data
.extended_irq
.resource_source
.string_length
= 0;
456 output_struct
->data
.extended_irq
.resource_source
.string_ptr
= NULL
;
460 * Set the Length parameter
462 output_struct
->length
= (u32
) struct_size
;
465 * Return the final size of the structure
467 *structure_size
= struct_size
;
468 return_ACPI_STATUS (AE_OK
);
472 /*******************************************************************************
474 * FUNCTION: acpi_rs_extended_irq_stream
476 * PARAMETERS: linked_list - Pointer to the resource linked list
477 * output_buffer - Pointer to the user's return buffer
478 * bytes_consumed - Pointer to where the number of bytes
479 * used in the output_buffer is returned
483 * DESCRIPTION: Take the linked list resource structure and fills in the
484 * the appropriate bytes in a byte stream
486 ******************************************************************************/
489 acpi_rs_extended_irq_stream (
490 struct acpi_resource
*linked_list
,
492 acpi_size
*bytes_consumed
)
494 u8
*buffer
= *output_buffer
;
498 char *temp_pointer
= NULL
;
501 ACPI_FUNCTION_TRACE ("rs_extended_irq_stream");
505 * The descriptor field is static
511 * Set a pointer to the Length field - to be filled in later
513 length_field
= ACPI_CAST_PTR (u16
, buffer
);
517 * Set the Interrupt vector flags
519 temp8
= (u8
)(linked_list
->data
.extended_irq
.producer_consumer
& 0x01);
520 temp8
|= ((linked_list
->data
.extended_irq
.shared_exclusive
& 0x01) << 3);
523 * Set the Interrupt Mode
525 * The definition of an Extended IRQ changed between ACPI spec v1.0b
526 * and ACPI spec 2.0 (section 6.4.3.6 in both). This code does not
527 * implement the more restrictive definition of 1.0b
529 * - Edge/Level are defined opposite in the table vs the headers
531 if (ACPI_EDGE_SENSITIVE
== linked_list
->data
.extended_irq
.edge_level
) {
536 * Set the Interrupt Polarity
538 temp8
|= ((linked_list
->data
.extended_irq
.active_high_low
& 0x1) << 2);
544 * Set the Interrupt table length
546 temp8
= (u8
) linked_list
->data
.extended_irq
.number_of_interrupts
;
551 for (index
= 0; index
< linked_list
->data
.extended_irq
.number_of_interrupts
;
553 ACPI_MOVE_32_TO_32 (buffer
,
554 &linked_list
->data
.extended_irq
.interrupts
[index
]);
559 * Resource Source Index and Resource Source are optional
561 if (0 != linked_list
->data
.extended_irq
.resource_source
.string_length
) {
562 *buffer
= (u8
) linked_list
->data
.extended_irq
.resource_source
.index
;
565 temp_pointer
= (char *) buffer
;
570 ACPI_STRCPY (temp_pointer
,
571 linked_list
->data
.extended_irq
.resource_source
.string_ptr
);
574 * Buffer needs to be set to the length of the sting + one for the
577 buffer
+= (acpi_size
)(ACPI_STRLEN (linked_list
->data
.extended_irq
.resource_source
.string_ptr
) + 1);
581 * Return the number of bytes consumed in this operation
583 *bytes_consumed
= ACPI_PTR_DIFF (buffer
, *output_buffer
);
586 * Set the length field to the number of bytes consumed
587 * minus the header size (3 bytes)
589 *length_field
= (u16
) (*bytes_consumed
- 3);
590 return_ACPI_STATUS (AE_OK
);