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.
44 #include <acpi/acpi.h>
45 #include <acpi/acresrc.h>
47 #define _COMPONENT ACPI_RESOURCES
48 ACPI_MODULE_NAME("rsirq")
50 /*******************************************************************************
52 * FUNCTION: acpi_rs_get_irq
54 * PARAMETERS: Aml - Pointer to the AML resource descriptor
55 * aml_resource_length - Length of the resource from the AML header
56 * Resource - Where the internal resource is returned
60 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
61 * internal resource descriptor, simplifying bitflags and handling
62 * alignment and endian issues if necessary.
64 ******************************************************************************/
66 acpi_rs_get_irq(union aml_resource
*aml
,
67 u16 aml_resource_length
, struct acpi_resource
*resource
)
70 u32 interrupt_count
= 0;
74 ACPI_FUNCTION_TRACE("rs_get_irq");
76 /* Get the IRQ mask (bytes 1:2) */
78 ACPI_MOVE_16_TO_16(&temp16
, &aml
->irq
.irq_mask
);
80 /* Decode the IRQ bits (up to 16 possible) */
82 for (i
= 0; i
< 16; i
++) {
83 if ((temp16
>> i
) & 0x01) {
84 resource
->data
.irq
.interrupts
[interrupt_count
] = i
;
89 /* Zero interrupts is valid */
92 resource
->data
.irq
.interrupt_count
= interrupt_count
;
93 if (interrupt_count
> 0) {
94 /* Calculate the structure size based upon the number of interrupts */
96 resource_length
= (u32
) (interrupt_count
- 1) * 4;
99 /* Get Flags (Byte 3) if it is used */
101 if (aml_resource_length
== 3) {
102 /* Check for HE, LL interrupts */
104 switch (aml
->irq
.flags
& 0x09) {
106 resource
->data
.irq
.triggering
= ACPI_EDGE_SENSITIVE
;
107 resource
->data
.irq
.polarity
= ACPI_ACTIVE_HIGH
;
111 resource
->data
.irq
.triggering
= ACPI_LEVEL_SENSITIVE
;
112 resource
->data
.irq
.polarity
= ACPI_ACTIVE_LOW
;
117 * Only _LL and _HE polarity/trigger interrupts
118 * are allowed (ACPI spec, section "IRQ Format")
119 * so 0x00 and 0x09 are illegal.
121 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
122 "Invalid interrupt polarity/trigger in resource list, %X\n",
124 return_ACPI_STATUS(AE_BAD_DATA
);
127 /* Get Sharing flag */
129 resource
->data
.irq
.sharable
= (aml
->irq
.flags
>> 3) & 0x01;
132 * Default configuration: assume Edge Sensitive, Active High,
133 * Non-Sharable as per the ACPI Specification
135 resource
->data
.irq
.triggering
= ACPI_EDGE_SENSITIVE
;
136 resource
->data
.irq
.polarity
= ACPI_ACTIVE_HIGH
;
137 resource
->data
.irq
.sharable
= ACPI_EXCLUSIVE
;
140 /* Complete the resource header */
142 resource
->type
= ACPI_RESOURCE_TYPE_IRQ
;
144 resource_length
+ ACPI_SIZEOF_RESOURCE(struct acpi_resource_irq
);
145 return_ACPI_STATUS(AE_OK
);
148 /*******************************************************************************
150 * FUNCTION: acpi_rs_set_irq
152 * PARAMETERS: Resource - Pointer to the resource descriptor
153 * Aml - Where the AML descriptor is returned
157 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
158 * external AML resource descriptor.
160 ******************************************************************************/
163 acpi_rs_set_irq(struct acpi_resource
*resource
, union aml_resource
*aml
)
165 acpi_size descriptor_length
;
169 ACPI_FUNCTION_TRACE("rs_set_irq");
171 /* Convert interrupt list to 16-bit IRQ bitmask */
174 for (i
= 0; i
< resource
->data
.irq
.interrupt_count
; i
++) {
175 irq_mask
|= (1 << resource
->data
.irq
.interrupts
[i
]);
178 /* Set the interrupt mask */
180 ACPI_MOVE_16_TO_16(&aml
->irq
.irq_mask
, &irq_mask
);
183 * The descriptor field is set based upon whether a third byte is
184 * needed to contain the IRQ Information.
186 if ((resource
->data
.irq
.triggering
== ACPI_EDGE_SENSITIVE
) &&
187 (resource
->data
.irq
.polarity
== ACPI_ACTIVE_HIGH
) &&
188 (resource
->data
.irq
.sharable
== ACPI_EXCLUSIVE
)) {
189 /* irq_no_flags() descriptor can be used */
191 descriptor_length
= sizeof(struct aml_resource_irq_noflags
);
193 /* Irq() descriptor must be used */
195 descriptor_length
= sizeof(struct aml_resource_irq
);
197 /* Set the IRQ Info byte */
199 aml
->irq
.flags
= (u8
)
200 ((resource
->data
.irq
.sharable
& 0x01) << 4);
202 if (ACPI_LEVEL_SENSITIVE
== resource
->data
.irq
.triggering
&&
203 ACPI_ACTIVE_LOW
== resource
->data
.irq
.polarity
) {
204 aml
->irq
.flags
|= 0x08;
206 aml
->irq
.flags
|= 0x01;
210 /* Complete the AML descriptor header */
212 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_IRQ
, descriptor_length
,
214 return_ACPI_STATUS(AE_OK
);
217 /*******************************************************************************
219 * FUNCTION: acpi_rs_get_ext_irq
221 * PARAMETERS: Aml - Pointer to the AML resource descriptor
222 * aml_resource_length - Length of the resource from the AML header
223 * Resource - Where the internal resource is returned
227 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
228 * internal resource descriptor, simplifying bitflags and handling
229 * alignment and endian issues if necessary.
231 ******************************************************************************/
234 acpi_rs_get_ext_irq(union aml_resource
*aml
,
235 u16 aml_resource_length
, struct acpi_resource
*resource
)
237 char *out_resource_string
;
240 ACPI_FUNCTION_TRACE("rs_get_ext_irq");
242 /* Get the flag bits */
244 temp8
= aml
->extended_irq
.flags
;
245 resource
->data
.extended_irq
.producer_consumer
= temp8
& 0x01;
246 resource
->data
.extended_irq
.polarity
= (temp8
>> 2) & 0x01;
247 resource
->data
.extended_irq
.sharable
= (temp8
>> 3) & 0x01;
250 * Check for Interrupt Mode
252 * The definition of an Extended IRQ changed between ACPI spec v1.0b
253 * and ACPI spec 2.0 (section 6.4.3.6 in both).
255 * - Edge/Level are defined opposite in the table vs the headers
257 resource
->data
.extended_irq
.triggering
=
258 (temp8
& 0x2) ? ACPI_EDGE_SENSITIVE
: ACPI_LEVEL_SENSITIVE
;
260 /* Get the IRQ Table length (Byte4) */
262 temp8
= aml
->extended_irq
.table_length
;
263 resource
->data
.extended_irq
.interrupt_count
= temp8
;
265 /* Must have at least one IRQ */
267 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH
);
271 * Add any additional structure size to properly calculate
272 * the next pointer at the end of this function
274 resource
->length
= (temp8
- 1) * 4;
275 out_resource_string
= ACPI_CAST_PTR(char,
276 (&resource
->data
.extended_irq
.
277 interrupts
[0] + temp8
));
279 /* Get every IRQ in the table, each is 32 bits */
281 acpi_rs_move_data(resource
->data
.extended_irq
.interrupts
,
282 aml
->extended_irq
.interrupt_number
,
283 (u16
) temp8
, ACPI_MOVE_TYPE_32_TO_32
);
285 /* Get the optional resource_source (index and string) */
288 acpi_rs_get_resource_source(aml_resource_length
,
289 (acpi_size
) resource
->length
+
291 aml_resource_extended_irq
),
292 &resource
->data
.extended_irq
.
293 resource_source
, aml
,
294 out_resource_string
);
296 /* Complete the resource header */
298 resource
->type
= ACPI_RESOURCE_TYPE_EXTENDED_IRQ
;
300 ACPI_SIZEOF_RESOURCE(struct acpi_resource_extended_irq
);
301 return_ACPI_STATUS(AE_OK
);
304 /*******************************************************************************
306 * FUNCTION: acpi_rs_set_ext_irq
308 * PARAMETERS: Resource - Pointer to the resource descriptor
309 * Aml - Where the AML descriptor is returned
313 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
314 * external AML resource descriptor.
316 ******************************************************************************/
319 acpi_rs_set_ext_irq(struct acpi_resource
*resource
, union aml_resource
*aml
)
321 acpi_size descriptor_length
;
323 ACPI_FUNCTION_TRACE("rs_set_ext_irq");
325 /* Set the Interrupt vector flags */
327 aml
->extended_irq
.flags
= (u8
)
328 ((resource
->data
.extended_irq
.producer_consumer
& 0x01) |
329 ((resource
->data
.extended_irq
.sharable
& 0x01) << 3) |
330 ((resource
->data
.extended_irq
.polarity
& 0x1) << 2));
333 * Set the 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). This code does not
337 * implement the more restrictive definition of 1.0b
339 * - Edge/Level are defined opposite in the table vs the headers
341 if (resource
->data
.extended_irq
.triggering
== ACPI_EDGE_SENSITIVE
) {
342 aml
->extended_irq
.flags
|= 0x02;
345 /* Set the Interrupt table length */
347 aml
->extended_irq
.table_length
= (u8
)
348 resource
->data
.extended_irq
.interrupt_count
;
350 descriptor_length
= (sizeof(struct aml_resource_extended_irq
) - 4) +
351 ((acpi_size
) resource
->data
.extended_irq
.interrupt_count
*
354 /* Set each interrupt value */
356 acpi_rs_move_data(aml
->extended_irq
.interrupt_number
,
357 resource
->data
.extended_irq
.interrupts
,
358 (u16
) resource
->data
.extended_irq
.interrupt_count
,
359 ACPI_MOVE_TYPE_32_TO_32
);
361 /* Resource Source Index and Resource Source are optional */
363 descriptor_length
= acpi_rs_set_resource_source(aml
, descriptor_length
,
368 /* Complete the AML descriptor header */
370 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_EXTENDED_IRQ
,
371 descriptor_length
, aml
);
372 return_ACPI_STATUS(AE_OK
);