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 (
87 struct acpi_resource_irq);
90 ACPI_FUNCTION_TRACE ("rs_irq_resource");
94 * The number of bytes consumed are contained in the descriptor
98 *bytes_consumed = (temp8 & 0x03) + 1;
99 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;
121 /* Calculate the structure size based upon the number of interrupts */
123 struct_size += ((acpi_size) i - 1) * 4;
126 /* Point to Byte 3 if it is used */
128 if (4 == *bytes_consumed) {
132 /* Check for HE, LL interrupts */
134 switch (temp8 & 0x09) {
136 output_struct->data.irq.edge_level = ACPI_EDGE_SENSITIVE;
137 output_struct->data.irq.active_high_low = ACPI_ACTIVE_HIGH;
141 output_struct->data.irq.edge_level = ACPI_LEVEL_SENSITIVE;
142 output_struct->data.irq.active_high_low = ACPI_ACTIVE_LOW;
147 * Only _LL and _HE polarity/trigger interrupts
148 * are allowed (ACPI spec, section "IRQ Format")
149 * so 0x00 and 0x09 are illegal.
151 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
152 "Invalid interrupt polarity/trigger in resource list, %X\n",
154 return_ACPI_STATUS (AE_BAD_DATA);
157 /* Check for sharable */
159 output_struct->data.irq.shared_exclusive = (temp8 >> 3) & 0x01;
163 * Assume Edge Sensitive, Active High, Non-Sharable
164 * per ACPI Specification
166 output_struct->data.irq.edge_level = ACPI_EDGE_SENSITIVE;
167 output_struct->data.irq.active_high_low = ACPI_ACTIVE_HIGH;
168 output_struct->data.irq.shared_exclusive = ACPI_EXCLUSIVE;
171 /* Set the Length parameter */
173 output_struct->length = (u32) struct_size;
175 /* Return the final size of the structure */
177 *structure_size = struct_size;
178 return_ACPI_STATUS (AE_OK);
182 /*******************************************************************************
184 * FUNCTION: acpi_rs_irq_stream
186 * PARAMETERS: linked_list - Pointer to the resource linked list
187 * output_buffer - Pointer to the user's return buffer
188 * bytes_consumed - Pointer to where the number of bytes
189 * used in the output_buffer is returned
193 * DESCRIPTION: Take the linked list resource structure and fills in the
194 * the appropriate bytes in a byte stream
196 ******************************************************************************/
200 struct acpi_resource *linked_list,
202 acpi_size *bytes_consumed)
204 u8 *buffer = *output_buffer;
208 u8 IRqinfo_byte_needed;
211 ACPI_FUNCTION_TRACE ("rs_irq_stream");
215 * The descriptor field is set based upon whether a third byte is
216 * needed to contain the IRQ Information.
218 if (ACPI_EDGE_SENSITIVE == linked_list->data.irq.edge_level &&
219 ACPI_ACTIVE_HIGH == linked_list->data.irq.active_high_low &&
220 ACPI_EXCLUSIVE == linked_list->data.irq.shared_exclusive) {
222 IRqinfo_byte_needed = FALSE;
226 IRqinfo_byte_needed = TRUE;
232 /* Loop through all of the interrupts and set the mask bits */
235 index < linked_list->data.irq.number_of_interrupts;
237 temp8 = (u8) linked_list->data.irq.interrupts[index];
238 temp16 |= 0x1 << temp8;
241 ACPI_MOVE_16_TO_16 (buffer, &temp16);
244 /* Set the IRQ Info byte if needed. */
246 if (IRqinfo_byte_needed) {
248 temp8 = (u8) ((linked_list->data.irq.shared_exclusive &
251 if (ACPI_LEVEL_SENSITIVE == linked_list->data.irq.edge_level &&
252 ACPI_ACTIVE_LOW == linked_list->data.irq.active_high_low) {
263 /* Return the number of bytes consumed in this operation */
265 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
266 return_ACPI_STATUS (AE_OK);
270 /*******************************************************************************
272 * FUNCTION: acpi_rs_extended_irq_resource
274 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
276 * bytes_consumed - Pointer to where the number of bytes
277 * consumed the byte_stream_buffer is
279 * output_buffer - Pointer to the return data buffer
280 * structure_size - Pointer to where the number of bytes
281 * in the return data struct is returned
285 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
286 * structure pointed to by the output_buffer. Return the
287 * number of bytes consumed from the byte stream.
289 ******************************************************************************/
292 acpi_rs_extended_irq_resource (
293 u8 *byte_stream_buffer,
294 acpi_size *bytes_consumed,
296 acpi_size *structure_size)
298 u8 *buffer = byte_stream_buffer;
299 struct acpi_resource *output_struct = (void *) *output_buffer;
304 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
305 struct acpi_resource_ext_irq);
308 ACPI_FUNCTION_TRACE ("rs_extended_irq_resource");
311 /* Point past the Descriptor to get the number of bytes consumed */
314 ACPI_MOVE_16_TO_16 (&temp16, buffer);
316 /* Validate minimum descriptor length */
319 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
322 *bytes_consumed = temp16 + 3;
323 output_struct->id = ACPI_RSTYPE_EXT_IRQ;
325 /* Point to the Byte3 */
330 output_struct->data.extended_irq.producer_consumer = temp8 & 0x01;
333 * Check for Interrupt Mode
335 * The definition of an Extended IRQ changed between ACPI spec v1.0b
336 * and ACPI spec 2.0 (section 6.4.3.6 in both).
338 * - Edge/Level are defined opposite in the table vs the headers
340 output_struct->data.extended_irq.edge_level =
341 (temp8 & 0x2) ? ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE;
343 /* Check Interrupt Polarity */
345 output_struct->data.extended_irq.active_high_low = (temp8 >> 2) & 0x1;
347 /* Check for sharable */
349 output_struct->data.extended_irq.shared_exclusive = (temp8 >> 3) & 0x01;
351 /* Point to Byte4 (IRQ Table length) */
356 /* Must have at least one IRQ */
359 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
362 output_struct->data.extended_irq.number_of_interrupts = temp8;
365 * Add any additional structure size to properly calculate
366 * the next pointer at the end of this function
368 struct_size += (temp8 - 1) * 4;
370 /* Point to Byte5 (First IRQ Number) */
374 /* Cycle through every IRQ in the table */
376 for (index = 0; index < temp8; index++) {
378 &output_struct->data.extended_irq.interrupts[index], buffer);
380 /* Point to the next IRQ */
386 * This will leave us pointing to the Resource Source Index
387 * If it is present, then save it off and calculate the
388 * pointer to where the null terminated string goes:
389 * Each Interrupt takes 32-bits + the 5 bytes of the
390 * stream that are default.
392 * Note: Some resource descriptors will have an additional null, so
393 * we add 1 to the length.
395 if (*bytes_consumed >
396 ((acpi_size) output_struct->data.extended_irq.number_of_interrupts * 4) +
398 /* Dereference the Index */
401 output_struct->data.extended_irq.resource_source.index = (u32) temp8;
403 /* Point to the String */
407 /* Point the String pointer to the end of this structure. */
409 output_struct->data.extended_irq.resource_source.string_ptr =
410 (char *)((char *) output_struct + struct_size);
413 output_struct->data.extended_irq.resource_source.string_ptr;
415 /* Copy the string into the buffer */
418 while (0x00 != *buffer) {
426 /* Add the terminating null */
429 output_struct->data.extended_irq.resource_source.string_length = index + 1;
432 * In order for the struct_size to fall on a 32-bit boundary,
433 * calculate the length of the string and expand the
434 * struct_size to the next 32-bit boundary.
436 temp8 = (u8) (index + 1);
437 struct_size += ACPI_ROUND_UP_to_32_bITS (temp8);
440 output_struct->data.extended_irq.resource_source.index = 0x00;
441 output_struct->data.extended_irq.resource_source.string_length = 0;
442 output_struct->data.extended_irq.resource_source.string_ptr = NULL;
445 /* Set the Length parameter */
447 output_struct->length = (u32) struct_size;
449 /* Return the final size of the structure */
451 *structure_size = struct_size;
452 return_ACPI_STATUS (AE_OK);
456 /*******************************************************************************
458 * FUNCTION: acpi_rs_extended_irq_stream
460 * PARAMETERS: linked_list - Pointer to the resource linked list
461 * output_buffer - Pointer to the user's return buffer
462 * bytes_consumed - Pointer to where the number of bytes
463 * used in the output_buffer is returned
467 * DESCRIPTION: Take the linked list resource structure and fills in the
468 * the appropriate bytes in a byte stream
470 ******************************************************************************/
473 acpi_rs_extended_irq_stream (
474 struct acpi_resource *linked_list,
476 acpi_size *bytes_consumed)
478 u8 *buffer = *output_buffer;
482 char *temp_pointer = NULL;
485 ACPI_FUNCTION_TRACE ("rs_extended_irq_stream");
488 /* The descriptor field is static */
493 /* Set a pointer to the Length field - to be filled in later */
495 length_field = ACPI_CAST_PTR (u16, buffer);
498 /* Set the Interrupt vector flags */
500 temp8 = (u8)(linked_list->data.extended_irq.producer_consumer & 0x01);
501 temp8 |= ((linked_list->data.extended_irq.shared_exclusive & 0x01) << 3);
504 * Set the Interrupt Mode
506 * The definition of an Extended IRQ changed between ACPI spec v1.0b
507 * and ACPI spec 2.0 (section 6.4.3.6 in both). This code does not
508 * implement the more restrictive definition of 1.0b
510 * - Edge/Level are defined opposite in the table vs the headers
512 if (ACPI_EDGE_SENSITIVE == linked_list->data.extended_irq.edge_level) {
516 /* Set the Interrupt Polarity */
518 temp8 |= ((linked_list->data.extended_irq.active_high_low & 0x1) << 2);
523 /* Set the Interrupt table length */
525 temp8 = (u8) linked_list->data.extended_irq.number_of_interrupts;
530 for (index = 0; index < linked_list->data.extended_irq.number_of_interrupts;
532 ACPI_MOVE_32_TO_32 (buffer,
533 &linked_list->data.extended_irq.interrupts[index]);
537 /* Resource Source Index and Resource Source are optional */
539 if (0 != linked_list->data.extended_irq.resource_source.string_length) {
540 *buffer = (u8) linked_list->data.extended_irq.resource_source.index;
543 temp_pointer = (char *) buffer;
545 /* Copy the string */
547 ACPI_STRCPY (temp_pointer,
548 linked_list->data.extended_irq.resource_source.string_ptr);
551 * Buffer needs to be set to the length of the sting + one for the
554 buffer += (acpi_size) (ACPI_STRLEN (
555 linked_list->data.extended_irq.resource_source.string_ptr) + 1);
558 /* Return the number of bytes consumed in this operation */
560 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
563 * Set the length field to the number of bytes consumed
564 * minus the header size (3 bytes)
566 *length_field = (u16) (*bytes_consumed - 3);
567 return_ACPI_STATUS (AE_OK);