Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /******************************************************************************* |
2 | * | |
3 | * Module Name: rsirq - IRQ resource descriptors | |
4 | * | |
5 | ******************************************************************************/ | |
6 | ||
7 | /* | |
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | |
9 | * All rights reserved. | |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
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. | |
25 | * | |
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. | |
29 | * | |
30 | * NO WARRANTY | |
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. | |
42 | */ | |
43 | ||
1da177e4 LT |
44 | #include <acpi/acpi.h> |
45 | #include <acpi/acresrc.h> | |
46 | ||
47 | #define _COMPONENT ACPI_RESOURCES | |
4be44fcd | 48 | ACPI_MODULE_NAME("rsirq") |
1da177e4 LT |
49 | |
50 | /******************************************************************************* | |
51 | * | |
50eca3eb | 52 | * FUNCTION: acpi_rs_get_irq |
1da177e4 | 53 | * |
50eca3eb BM |
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 | |
1da177e4 LT |
57 | * |
58 | * RETURN: Status | |
59 | * | |
50eca3eb BM |
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. | |
1da177e4 LT |
63 | * |
64 | ******************************************************************************/ | |
1da177e4 | 65 | acpi_status |
50eca3eb BM |
66 | acpi_rs_get_irq(union aml_resource *aml, |
67 | u16 aml_resource_length, struct acpi_resource *resource) | |
1da177e4 | 68 | { |
4be44fcd | 69 | u16 temp16 = 0; |
50eca3eb BM |
70 | u32 interrupt_count = 0; |
71 | u32 i; | |
72 | u32 resource_length; | |
1da177e4 | 73 | |
50eca3eb | 74 | ACPI_FUNCTION_TRACE("rs_get_irq"); |
44f6c012 | 75 | |
50eca3eb | 76 | /* Get the IRQ mask (bytes 1:2) */ |
1da177e4 | 77 | |
50eca3eb | 78 | ACPI_MOVE_16_TO_16(&temp16, &aml->irq.irq_mask); |
1da177e4 | 79 | |
50eca3eb | 80 | /* Decode the IRQ bits (up to 16 possible) */ |
1da177e4 | 81 | |
50eca3eb BM |
82 | for (i = 0; i < 16; i++) { |
83 | if ((temp16 >> i) & 0x01) { | |
84 | resource->data.irq.interrupts[interrupt_count] = i; | |
85 | interrupt_count++; | |
1da177e4 LT |
86 | } |
87 | } | |
88 | ||
89 | /* Zero interrupts is valid */ | |
90 | ||
50eca3eb BM |
91 | resource_length = 0; |
92 | resource->data.irq.interrupt_count = interrupt_count; | |
93 | if (interrupt_count > 0) { | |
44f6c012 RM |
94 | /* Calculate the structure size based upon the number of interrupts */ |
95 | ||
50eca3eb | 96 | resource_length = (u32) (interrupt_count - 1) * 4; |
1da177e4 LT |
97 | } |
98 | ||
50eca3eb | 99 | /* Get Flags (Byte 3) if it is used */ |
1da177e4 | 100 | |
50eca3eb | 101 | if (aml_resource_length == 3) { |
44f6c012 RM |
102 | /* Check for HE, LL interrupts */ |
103 | ||
50eca3eb | 104 | switch (aml->irq.flags & 0x09) { |
4be44fcd | 105 | case 0x01: /* HE */ |
50eca3eb BM |
106 | resource->data.irq.triggering = ACPI_EDGE_SENSITIVE; |
107 | resource->data.irq.polarity = ACPI_ACTIVE_HIGH; | |
1da177e4 LT |
108 | break; |
109 | ||
4be44fcd | 110 | case 0x08: /* LL */ |
50eca3eb BM |
111 | resource->data.irq.triggering = ACPI_LEVEL_SENSITIVE; |
112 | resource->data.irq.polarity = ACPI_ACTIVE_LOW; | |
1da177e4 LT |
113 | break; |
114 | ||
115 | default: | |
116 | /* | |
117 | * Only _LL and _HE polarity/trigger interrupts | |
118 | * are allowed (ACPI spec, section "IRQ Format") | |
119 | * so 0x00 and 0x09 are illegal. | |
120 | */ | |
4be44fcd LB |
121 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
122 | "Invalid interrupt polarity/trigger in resource list, %X\n", | |
50eca3eb | 123 | aml->irq.flags)); |
4be44fcd | 124 | return_ACPI_STATUS(AE_BAD_DATA); |
1da177e4 LT |
125 | } |
126 | ||
50eca3eb | 127 | /* Get Sharing flag */ |
44f6c012 | 128 | |
50eca3eb | 129 | resource->data.irq.sharable = (aml->irq.flags >> 3) & 0x01; |
4be44fcd | 130 | } else { |
1da177e4 | 131 | /* |
50eca3eb BM |
132 | * Default configuration: assume Edge Sensitive, Active High, |
133 | * Non-Sharable as per the ACPI Specification | |
1da177e4 | 134 | */ |
50eca3eb BM |
135 | resource->data.irq.triggering = ACPI_EDGE_SENSITIVE; |
136 | resource->data.irq.polarity = ACPI_ACTIVE_HIGH; | |
137 | resource->data.irq.sharable = ACPI_EXCLUSIVE; | |
1da177e4 LT |
138 | } |
139 | ||
50eca3eb | 140 | /* Complete the resource header */ |
44f6c012 | 141 | |
50eca3eb BM |
142 | resource->type = ACPI_RESOURCE_TYPE_IRQ; |
143 | resource->length = | |
144 | resource_length + ACPI_SIZEOF_RESOURCE(struct acpi_resource_irq); | |
4be44fcd | 145 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
146 | } |
147 | ||
1da177e4 LT |
148 | /******************************************************************************* |
149 | * | |
50eca3eb | 150 | * FUNCTION: acpi_rs_set_irq |
1da177e4 | 151 | * |
50eca3eb BM |
152 | * PARAMETERS: Resource - Pointer to the resource descriptor |
153 | * Aml - Where the AML descriptor is returned | |
1da177e4 LT |
154 | * |
155 | * RETURN: Status | |
156 | * | |
50eca3eb BM |
157 | * DESCRIPTION: Convert an internal resource descriptor to the corresponding |
158 | * external AML resource descriptor. | |
1da177e4 LT |
159 | * |
160 | ******************************************************************************/ | |
161 | ||
162 | acpi_status | |
50eca3eb | 163 | acpi_rs_set_irq(struct acpi_resource *resource, union aml_resource *aml) |
1da177e4 | 164 | { |
50eca3eb BM |
165 | acpi_size descriptor_length; |
166 | u16 irq_mask; | |
167 | u8 i; | |
168 | ||
169 | ACPI_FUNCTION_TRACE("rs_set_irq"); | |
1da177e4 | 170 | |
50eca3eb BM |
171 | /* Convert interrupt list to 16-bit IRQ bitmask */ |
172 | ||
173 | irq_mask = 0; | |
174 | for (i = 0; i < resource->data.irq.interrupt_count; i++) { | |
175 | irq_mask |= (1 << resource->data.irq.interrupts[i]); | |
176 | } | |
177 | ||
178 | /* Set the interrupt mask */ | |
179 | ||
180 | ACPI_MOVE_16_TO_16(&aml->irq.irq_mask, &irq_mask); | |
1da177e4 LT |
181 | |
182 | /* | |
183 | * The descriptor field is set based upon whether a third byte is | |
184 | * needed to contain the IRQ Information. | |
185 | */ | |
50eca3eb BM |
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 */ | |
44f6c012 | 190 | |
50eca3eb BM |
191 | descriptor_length = sizeof(struct aml_resource_irq_noflags); |
192 | } else { | |
193 | /* Irq() descriptor must be used */ | |
1da177e4 | 194 | |
50eca3eb | 195 | descriptor_length = sizeof(struct aml_resource_irq); |
1da177e4 | 196 | |
50eca3eb | 197 | /* Set the IRQ Info byte */ |
44f6c012 | 198 | |
50eca3eb BM |
199 | aml->irq.flags = (u8) |
200 | ((resource->data.irq.sharable & 0x01) << 4); | |
1da177e4 | 201 | |
50eca3eb BM |
202 | if (ACPI_LEVEL_SENSITIVE == resource->data.irq.triggering && |
203 | ACPI_ACTIVE_LOW == resource->data.irq.polarity) { | |
204 | aml->irq.flags |= 0x08; | |
4be44fcd | 205 | } else { |
50eca3eb | 206 | aml->irq.flags |= 0x01; |
1da177e4 | 207 | } |
1da177e4 LT |
208 | } |
209 | ||
50eca3eb | 210 | /* Complete the AML descriptor header */ |
44f6c012 | 211 | |
50eca3eb BM |
212 | acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_IRQ, descriptor_length, |
213 | aml); | |
4be44fcd | 214 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
215 | } |
216 | ||
1da177e4 LT |
217 | /******************************************************************************* |
218 | * | |
50eca3eb | 219 | * FUNCTION: acpi_rs_get_ext_irq |
1da177e4 | 220 | * |
50eca3eb BM |
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 | |
1da177e4 LT |
224 | * |
225 | * RETURN: Status | |
226 | * | |
50eca3eb BM |
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. | |
1da177e4 LT |
230 | * |
231 | ******************************************************************************/ | |
232 | ||
233 | acpi_status | |
50eca3eb BM |
234 | acpi_rs_get_ext_irq(union aml_resource *aml, |
235 | u16 aml_resource_length, struct acpi_resource *resource) | |
1da177e4 | 236 | { |
50eca3eb BM |
237 | char *out_resource_string; |
238 | u8 temp8; | |
1da177e4 | 239 | |
50eca3eb | 240 | ACPI_FUNCTION_TRACE("rs_get_ext_irq"); |
44f6c012 | 241 | |
50eca3eb | 242 | /* Get the flag bits */ |
1da177e4 | 243 | |
50eca3eb BM |
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; | |
1da177e4 LT |
248 | |
249 | /* | |
250 | * Check for Interrupt Mode | |
251 | * | |
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). | |
254 | * | |
255 | * - Edge/Level are defined opposite in the table vs the headers | |
256 | */ | |
50eca3eb | 257 | resource->data.extended_irq.triggering = |
4be44fcd | 258 | (temp8 & 0x2) ? ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE; |
44f6c012 | 259 | |
50eca3eb | 260 | /* Get the IRQ Table length (Byte4) */ |
1da177e4 | 261 | |
50eca3eb BM |
262 | temp8 = aml->extended_irq.table_length; |
263 | resource->data.extended_irq.interrupt_count = temp8; | |
1da177e4 | 264 | if (temp8 < 1) { |
50eca3eb BM |
265 | /* Must have at least one IRQ */ |
266 | ||
4be44fcd | 267 | return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH); |
1da177e4 LT |
268 | } |
269 | ||
1da177e4 LT |
270 | /* |
271 | * Add any additional structure size to properly calculate | |
272 | * the next pointer at the end of this function | |
273 | */ | |
50eca3eb BM |
274 | resource->length = (temp8 - 1) * 4; |
275 | out_resource_string = ACPI_CAST_PTR(char, | |
276 | (&resource->data.extended_irq. | |
277 | interrupts[0] + temp8)); | |
1da177e4 | 278 | |
50eca3eb | 279 | /* Get every IRQ in the table, each is 32 bits */ |
44f6c012 | 280 | |
50eca3eb BM |
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); | |
1da177e4 | 284 | |
50eca3eb | 285 | /* Get the optional resource_source (index and string) */ |
44f6c012 | 286 | |
50eca3eb BM |
287 | resource->length += |
288 | acpi_rs_get_resource_source(aml_resource_length, | |
289 | (acpi_size) resource->length + | |
290 | sizeof(struct | |
291 | aml_resource_extended_irq), | |
292 | &resource->data.extended_irq. | |
293 | resource_source, aml, | |
294 | out_resource_string); | |
1da177e4 | 295 | |
50eca3eb | 296 | /* Complete the resource header */ |
1da177e4 | 297 | |
50eca3eb BM |
298 | resource->type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; |
299 | resource->length += | |
300 | ACPI_SIZEOF_RESOURCE(struct acpi_resource_extended_irq); | |
4be44fcd | 301 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
302 | } |
303 | ||
1da177e4 LT |
304 | /******************************************************************************* |
305 | * | |
50eca3eb | 306 | * FUNCTION: acpi_rs_set_ext_irq |
1da177e4 | 307 | * |
50eca3eb BM |
308 | * PARAMETERS: Resource - Pointer to the resource descriptor |
309 | * Aml - Where the AML descriptor is returned | |
1da177e4 LT |
310 | * |
311 | * RETURN: Status | |
312 | * | |
50eca3eb BM |
313 | * DESCRIPTION: Convert an internal resource descriptor to the corresponding |
314 | * external AML resource descriptor. | |
1da177e4 LT |
315 | * |
316 | ******************************************************************************/ | |
317 | ||
318 | acpi_status | |
50eca3eb | 319 | acpi_rs_set_ext_irq(struct acpi_resource *resource, union aml_resource *aml) |
1da177e4 | 320 | { |
50eca3eb | 321 | acpi_size descriptor_length; |
1da177e4 | 322 | |
50eca3eb | 323 | ACPI_FUNCTION_TRACE("rs_set_ext_irq"); |
1da177e4 | 324 | |
44f6c012 RM |
325 | /* Set the Interrupt vector flags */ |
326 | ||
50eca3eb BM |
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)); | |
1da177e4 LT |
331 | |
332 | /* | |
333 | * Set the Interrupt Mode | |
334 | * | |
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 | |
338 | * | |
339 | * - Edge/Level are defined opposite in the table vs the headers | |
340 | */ | |
50eca3eb BM |
341 | if (resource->data.extended_irq.triggering == ACPI_EDGE_SENSITIVE) { |
342 | aml->extended_irq.flags |= 0x02; | |
1da177e4 LT |
343 | } |
344 | ||
44f6c012 RM |
345 | /* Set the Interrupt table length */ |
346 | ||
50eca3eb BM |
347 | aml->extended_irq.table_length = (u8) |
348 | resource->data.extended_irq.interrupt_count; | |
1da177e4 | 349 | |
50eca3eb BM |
350 | descriptor_length = (sizeof(struct aml_resource_extended_irq) - 4) + |
351 | ((acpi_size) resource->data.extended_irq.interrupt_count * | |
352 | sizeof(u32)); | |
44f6c012 | 353 | |
50eca3eb | 354 | /* Set each interrupt value */ |
1da177e4 | 355 | |
50eca3eb BM |
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); | |
44f6c012 | 360 | |
50eca3eb | 361 | /* Resource Source Index and Resource Source are optional */ |
1da177e4 | 362 | |
50eca3eb BM |
363 | descriptor_length = acpi_rs_set_resource_source(aml, descriptor_length, |
364 | &resource->data. | |
365 | extended_irq. | |
366 | resource_source); | |
44f6c012 | 367 | |
50eca3eb | 368 | /* Complete the AML descriptor header */ |
1da177e4 | 369 | |
50eca3eb BM |
370 | acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_EXTENDED_IRQ, |
371 | descriptor_length, aml); | |
4be44fcd | 372 | return_ACPI_STATUS(AE_OK); |
1da177e4 | 373 | } |