1 /*******************************************************************************
3 * Module Name: rsirq - IRQ resource descriptors
6 ******************************************************************************/
9 * Copyright (C) 2000, 2001 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #define _COMPONENT ACPI_RESOURCES
34 /*******************************************************************************
36 * FUNCTION: Acpi_rs_irq_resource
38 * PARAMETERS: Byte_stream_buffer - Pointer to the resource input byte
40 * Bytes_consumed - u32 pointer that is filled with
41 * the number of bytes consumed from
42 * the Byte_stream_buffer
43 * Output_buffer - Pointer to the user's return buffer
44 * Structure_size - u32 pointer that is filled with
45 * the number of bytes in the filled
50 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
51 * structure pointed to by the Output_buffer. Return the
52 * number of bytes consumed from the byte stream.
54 ******************************************************************************/
57 acpi_rs_irq_resource (
58 u8 *byte_stream_buffer,
63 u8 *buffer = byte_stream_buffer;
64 acpi_resource *output_struct = (acpi_resource *) *output_buffer;
69 u32 struct_size = SIZEOF_RESOURCE (acpi_resource_irq);
72 FUNCTION_TRACE ("Rs_irq_resource");
76 * The number of bytes consumed are contained in the descriptor
80 *bytes_consumed = (temp8 & 0x03) + 1;
81 output_struct->id = ACPI_RSTYPE_IRQ;
84 * Point to the 16-bits of Bytes 1 and 2
87 MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
89 output_struct->data.irq.number_of_interrupts = 0;
91 /* Decode the IRQ bits */
93 for (i = 0, index = 0; index < 16; index++) {
94 if((temp16 >> index) & 0x01) {
95 output_struct->data.irq.interrupts[i] = index;
99 output_struct->data.irq.number_of_interrupts = i;
102 * Calculate the structure size based upon the number of interrupts
104 struct_size += (output_struct->data.irq.number_of_interrupts - 1) * 4;
107 * Point to Byte 3 if it is used
109 if (4 == *bytes_consumed) {
114 * Check for HE, LL or HL
117 output_struct->data.irq.edge_level = EDGE_SENSITIVE;
118 output_struct->data.irq.active_high_low = ACTIVE_HIGH;
123 output_struct->data.irq.edge_level = LEVEL_SENSITIVE;
124 output_struct->data.irq.active_high_low = ACTIVE_LOW;
129 * Only _LL and _HE polarity/trigger interrupts
130 * are allowed (ACPI spec v1.0b ection 6.4.2.1),
131 * so an error will occur if we reach this point
133 return_ACPI_STATUS (AE_BAD_DATA);
140 output_struct->data.irq.shared_exclusive = (temp8 >> 3) & 0x01;
145 * Assume Edge Sensitive, Active High, Non-Sharable
146 * per ACPI Specification
148 output_struct->data.irq.edge_level = EDGE_SENSITIVE;
149 output_struct->data.irq.active_high_low = ACTIVE_HIGH;
150 output_struct->data.irq.shared_exclusive = EXCLUSIVE;
154 * Set the Length parameter
156 output_struct->length = struct_size;
159 * Return the final size of the structure
161 *structure_size = struct_size;
162 return_ACPI_STATUS (AE_OK);
166 /*******************************************************************************
168 * FUNCTION: Acpi_rs_irq_stream
170 * PARAMETERS: Linked_list - Pointer to the resource linked list
171 * Output_buffer - Pointer to the user's return buffer
172 * Bytes_consumed - u32 pointer that is filled with
173 * the number of bytes of the
178 * DESCRIPTION: Take the linked list resource structure and fills in the
179 * the appropriate bytes in a byte stream
181 ******************************************************************************/
185 acpi_resource *linked_list,
189 u8 *buffer = *output_buffer;
193 u8 IRQinfo_byte_needed;
196 FUNCTION_TRACE ("Rs_irq_stream");
200 * The descriptor field is set based upon whether a third byte is
201 * needed to contain the IRQ Information.
203 if (EDGE_SENSITIVE == linked_list->data.irq.edge_level &&
204 ACTIVE_HIGH == linked_list->data.irq.active_high_low &&
205 EXCLUSIVE == linked_list->data.irq.shared_exclusive) {
207 IRQinfo_byte_needed = FALSE;
212 IRQinfo_byte_needed = TRUE;
219 * Loop through all of the interrupts and set the mask bits
222 index < linked_list->data.irq.number_of_interrupts;
224 temp8 = (u8) linked_list->data.irq.interrupts[index];
225 temp16 |= 0x1 << temp8;
228 MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
232 * Set the IRQ Info byte if needed.
234 if (IRQinfo_byte_needed) {
236 temp8 = (u8) ((linked_list->data.irq.shared_exclusive &
239 if (LEVEL_SENSITIVE == linked_list->data.irq.edge_level &&
240 ACTIVE_LOW == linked_list->data.irq.active_high_low) {
253 * Return the number of bytes consumed in this operation
255 *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
256 return_ACPI_STATUS (AE_OK);
260 /*******************************************************************************
262 * FUNCTION: Acpi_rs_extended_irq_resource
264 * PARAMETERS: Byte_stream_buffer - Pointer to the resource input byte
266 * Bytes_consumed - u32 pointer that is filled with
267 * the number of bytes consumed from
268 * the Byte_stream_buffer
269 * Output_buffer - Pointer to the user's return buffer
270 * Structure_size - u32 pointer that is filled with
271 * the number of bytes in the filled
276 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
277 * structure pointed to by the Output_buffer. Return the
278 * number of bytes consumed from the byte stream.
280 ******************************************************************************/
283 acpi_rs_extended_irq_resource (
284 u8 *byte_stream_buffer,
289 u8 *buffer = byte_stream_buffer;
290 acpi_resource *output_struct = (acpi_resource *) *output_buffer;
293 NATIVE_CHAR *temp_ptr;
295 u32 struct_size = SIZEOF_RESOURCE (acpi_resource_ext_irq);
298 FUNCTION_TRACE ("Rs_extended_irq_resource");
302 * Point past the Descriptor to get the number of bytes consumed
305 MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
307 *bytes_consumed = temp16 + 3;
308 output_struct->id = ACPI_RSTYPE_EXT_IRQ;
316 output_struct->data.extended_irq.producer_consumer = temp8 & 0x01;
319 * Check for HE, LL or HL
322 output_struct->data.extended_irq.edge_level = EDGE_SENSITIVE;
323 output_struct->data.extended_irq.active_high_low = ACTIVE_HIGH;
328 output_struct->data.extended_irq.edge_level = LEVEL_SENSITIVE;
329 output_struct->data.extended_irq.active_high_low = ACTIVE_LOW;
334 * Only _LL and _HE polarity/trigger interrupts
335 * are allowed (ACPI spec v1.0b ection 6.4.2.1),
336 * so an error will occur if we reach this point
338 return_ACPI_STATUS (AE_BAD_DATA);
345 output_struct->data.extended_irq.shared_exclusive = (temp8 >> 3) & 0x01;
348 * Point to Byte4 (IRQ Table length)
353 output_struct->data.extended_irq.number_of_interrupts = temp8;
356 * Add any additional structure size to properly calculate
357 * the next pointer at the end of this function
359 struct_size += (temp8 - 1) * 4;
362 * Point to Byte5 (First IRQ Number)
367 * Cycle through every IRQ in the table
369 for (index = 0; index < temp8; index++) {
370 output_struct->data.extended_irq.interrupts[index] =
373 /* Point to the next IRQ */
379 * This will leave us pointing to the Resource Source Index
380 * If it is present, then save it off and calculate the
381 * pointer to where the null terminated string goes:
382 * Each Interrupt takes 32-bits + the 5 bytes of the
383 * stream that are default.
385 if (*bytes_consumed >
386 (u32)(output_struct->data.extended_irq.number_of_interrupts * 4) + 5) {
387 /* Dereference the Index */
390 output_struct->data.extended_irq.resource_source.index = (u32) temp8;
392 /* Point to the String */
397 * Point the String pointer to the end of this structure.
399 output_struct->data.extended_irq.resource_source.string_ptr =
400 (NATIVE_CHAR *)(output_struct + struct_size);
402 temp_ptr = output_struct->data.extended_irq.resource_source.string_ptr;
404 /* Copy the string into the buffer */
408 while (0x00 != *buffer) {
417 * Add the terminating null
420 output_struct->data.extended_irq.resource_source.string_length = index + 1;
423 * In order for the Struct_size to fall on a 32-bit boundary,
424 * calculate the length of the string and expand the
425 * Struct_size to the next 32-bit boundary.
427 temp8 = (u8) (index + 1);
428 struct_size += ROUND_UP_TO_32_bITS (temp8);
432 output_struct->data.extended_irq.resource_source.index = 0x00;
433 output_struct->data.extended_irq.resource_source.string_length = 0;
434 output_struct->data.extended_irq.resource_source.string_ptr = NULL;
438 * Set the Length parameter
440 output_struct->length = struct_size;
443 * Return the final size of the structure
445 *structure_size = struct_size;
446 return_ACPI_STATUS (AE_OK);
450 /*******************************************************************************
452 * FUNCTION: Acpi_rs_extended_irq_stream
454 * PARAMETERS: Linked_list - Pointer to the resource linked list
455 * Output_buffer - Pointer to the user's return buffer
456 * Bytes_consumed - u32 pointer that is filled with
457 * the number of bytes of the
462 * DESCRIPTION: Take the linked list resource structure and fills in the
463 * the appropriate bytes in a byte stream
465 ******************************************************************************/
468 acpi_rs_extended_irq_stream (
469 acpi_resource *linked_list,
473 u8 *buffer = *output_buffer;
477 NATIVE_CHAR *temp_pointer = NULL;
480 FUNCTION_TRACE ("Rs_extended_irq_stream");
484 * The descriptor field is static
490 * Set a pointer to the Length field - to be filled in later
492 length_field = (u16 *)buffer;
496 * Set the Interrupt vector flags
498 temp8 = (u8)(linked_list->data.extended_irq.producer_consumer & 0x01);
499 temp8 |= ((linked_list->data.extended_irq.shared_exclusive & 0x01) << 3);
501 if (LEVEL_SENSITIVE == linked_list->data.extended_irq.edge_level &&
502 ACTIVE_LOW == linked_list->data.extended_irq.active_high_low) {
513 * Set the Interrupt table length
515 temp8 = (u8) linked_list->data.extended_irq.number_of_interrupts;
520 for (index = 0; index < linked_list->data.extended_irq.number_of_interrupts;
522 MOVE_UNALIGNED32_TO_32 (buffer,
523 &linked_list->data.extended_irq.interrupts[index]);
528 * Resource Source Index and Resource Source are optional
530 if (0 != linked_list->data.extended_irq.resource_source.string_length) {
531 *buffer = (u8) linked_list->data.extended_irq.resource_source.index;
534 temp_pointer = (NATIVE_CHAR *) buffer;
539 STRCPY (temp_pointer,
540 linked_list->data.extended_irq.resource_source.string_ptr);
543 * Buffer needs to be set to the length of the sting + one for the
546 buffer += (STRLEN (linked_list->data.extended_irq.resource_source.string_ptr) + 1);
550 * Return the number of bytes consumed in this operation
552 *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
555 * Set the length field to the number of bytes consumed
556 * minus the header size (3 bytes)
558 *length_field = (u16) (*bytes_consumed - 3);
559 return_ACPI_STATUS (AE_OK);