]> err.no Git - linux-2.6/blob - drivers/acpi/resources/rsirq.c
[ACPI] ACPICA 20050930
[linux-2.6] / drivers / acpi / resources / rsirq.c
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
44 #include <acpi/acpi.h>
45 #include <acpi/acresrc.h>
46
47 #define _COMPONENT          ACPI_RESOURCES
48 ACPI_MODULE_NAME("rsirq")
49
50 /*******************************************************************************
51  *
52  * FUNCTION:    acpi_rs_get_irq
53  *
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
57  *
58  * RETURN:      Status
59  *
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.
63  *
64  ******************************************************************************/
65 acpi_status
66 acpi_rs_get_irq(union aml_resource *aml,
67                 u16 aml_resource_length, struct acpi_resource *resource)
68 {
69         u16 temp16 = 0;
70         u32 interrupt_count = 0;
71         u32 i;
72         u32 resource_length;
73
74         ACPI_FUNCTION_TRACE("rs_get_irq");
75
76         /* Get the IRQ mask (bytes 1:2) */
77
78         ACPI_MOVE_16_TO_16(&temp16, &aml->irq.irq_mask);
79
80         /* Decode the IRQ bits (up to 16 possible) */
81
82         for (i = 0; i < 16; i++) {
83                 if ((temp16 >> i) & 0x01) {
84                         resource->data.irq.interrupts[interrupt_count] = i;
85                         interrupt_count++;
86                 }
87         }
88
89         /* Zero interrupts is valid */
90
91         resource_length = 0;
92         resource->data.irq.interrupt_count = interrupt_count;
93         if (interrupt_count > 0) {
94                 /* Calculate the structure size based upon the number of interrupts */
95
96                 resource_length = (u32) (interrupt_count - 1) * 4;
97         }
98
99         /* Get Flags (Byte 3) if it is used */
100
101         if (aml_resource_length == 3) {
102                 /* Check for HE, LL interrupts */
103
104                 switch (aml->irq.flags & 0x09) {
105                 case 0x01:      /* HE */
106                         resource->data.irq.triggering = ACPI_EDGE_SENSITIVE;
107                         resource->data.irq.polarity = ACPI_ACTIVE_HIGH;
108                         break;
109
110                 case 0x08:      /* LL */
111                         resource->data.irq.triggering = ACPI_LEVEL_SENSITIVE;
112                         resource->data.irq.polarity = ACPI_ACTIVE_LOW;
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                          */
121                         ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
122                                           "Invalid interrupt polarity/trigger in resource list, %X\n",
123                                           aml->irq.flags));
124                         return_ACPI_STATUS(AE_BAD_DATA);
125                 }
126
127                 /* Get Sharing flag */
128
129                 resource->data.irq.sharable = (aml->irq.flags >> 3) & 0x01;
130         } else {
131                 /*
132                  * Default configuration: assume Edge Sensitive, Active High,
133                  * Non-Sharable as per the ACPI Specification
134                  */
135                 resource->data.irq.triggering = ACPI_EDGE_SENSITIVE;
136                 resource->data.irq.polarity = ACPI_ACTIVE_HIGH;
137                 resource->data.irq.sharable = ACPI_EXCLUSIVE;
138         }
139
140         /* Complete the resource header */
141
142         resource->type = ACPI_RESOURCE_TYPE_IRQ;
143         resource->length =
144             resource_length + ACPI_SIZEOF_RESOURCE(struct acpi_resource_irq);
145         return_ACPI_STATUS(AE_OK);
146 }
147
148 /*******************************************************************************
149  *
150  * FUNCTION:    acpi_rs_set_irq
151  *
152  * PARAMETERS:  Resource            - Pointer to the resource descriptor
153  *              Aml                 - Where the AML descriptor is returned
154  *
155  * RETURN:      Status
156  *
157  * DESCRIPTION: Convert an internal resource descriptor to the corresponding
158  *              external AML resource descriptor.
159  *
160  ******************************************************************************/
161
162 acpi_status
163 acpi_rs_set_irq(struct acpi_resource *resource, union aml_resource *aml)
164 {
165         acpi_size descriptor_length;
166         u16 irq_mask;
167         u8 i;
168
169         ACPI_FUNCTION_TRACE("rs_set_irq");
170
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);
181
182         /*
183          * The descriptor field is set based upon whether a third byte is
184          * needed to contain the IRQ Information.
185          */
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 */
190
191                 descriptor_length = sizeof(struct aml_resource_irq_noflags);
192         } else {
193                 /* Irq() descriptor must be used */
194
195                 descriptor_length = sizeof(struct aml_resource_irq);
196
197                 /* Set the IRQ Info byte */
198
199                 aml->irq.flags = (u8)
200                     ((resource->data.irq.sharable & 0x01) << 4);
201
202                 if (ACPI_LEVEL_SENSITIVE == resource->data.irq.triggering &&
203                     ACPI_ACTIVE_LOW == resource->data.irq.polarity) {
204                         aml->irq.flags |= 0x08;
205                 } else {
206                         aml->irq.flags |= 0x01;
207                 }
208         }
209
210         /* Complete the AML descriptor header */
211
212         acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_IRQ, descriptor_length,
213                                     aml);
214         return_ACPI_STATUS(AE_OK);
215 }
216
217 /*******************************************************************************
218  *
219  * FUNCTION:    acpi_rs_get_ext_irq
220  *
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
224  *
225  * RETURN:      Status
226  *
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.
230  *
231  ******************************************************************************/
232
233 acpi_status
234 acpi_rs_get_ext_irq(union aml_resource *aml,
235                     u16 aml_resource_length, struct acpi_resource *resource)
236 {
237         char *out_resource_string;
238         u8 temp8;
239
240         ACPI_FUNCTION_TRACE("rs_get_ext_irq");
241
242         /* Get the flag bits */
243
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;
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          */
257         resource->data.extended_irq.triggering =
258             (temp8 & 0x2) ? ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE;
259
260         /* Get the IRQ Table length (Byte4) */
261
262         temp8 = aml->extended_irq.table_length;
263         resource->data.extended_irq.interrupt_count = temp8;
264         if (temp8 < 1) {
265                 /* Must have at least one IRQ */
266
267                 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
268         }
269
270         /*
271          * Add any additional structure size to properly calculate
272          * the next pointer at the end of this function
273          */
274         resource->length = (temp8 - 1) * 4;
275         out_resource_string = ACPI_CAST_PTR(char,
276                                             (&resource->data.extended_irq.
277                                              interrupts[0] + temp8));
278
279         /* Get every IRQ in the table, each is 32 bits */
280
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);
284
285         /* Get the optional resource_source (index and string) */
286
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);
295
296         /* Complete the resource header */
297
298         resource->type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
299         resource->length +=
300             ACPI_SIZEOF_RESOURCE(struct acpi_resource_extended_irq);
301         return_ACPI_STATUS(AE_OK);
302 }
303
304 /*******************************************************************************
305  *
306  * FUNCTION:    acpi_rs_set_ext_irq
307  *
308  * PARAMETERS:  Resource            - Pointer to the resource descriptor
309  *              Aml                 - Where the AML descriptor is returned
310  *
311  * RETURN:      Status
312  *
313  * DESCRIPTION: Convert an internal resource descriptor to the corresponding
314  *              external AML resource descriptor.
315  *
316  ******************************************************************************/
317
318 acpi_status
319 acpi_rs_set_ext_irq(struct acpi_resource *resource, union aml_resource *aml)
320 {
321         acpi_size descriptor_length;
322
323         ACPI_FUNCTION_TRACE("rs_set_ext_irq");
324
325         /* Set the Interrupt vector flags */
326
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));
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          */
341         if (resource->data.extended_irq.triggering == ACPI_EDGE_SENSITIVE) {
342                 aml->extended_irq.flags |= 0x02;
343         }
344
345         /* Set the Interrupt table length */
346
347         aml->extended_irq.table_length = (u8)
348             resource->data.extended_irq.interrupt_count;
349
350         descriptor_length = (sizeof(struct aml_resource_extended_irq) - 4) +
351             ((acpi_size) resource->data.extended_irq.interrupt_count *
352              sizeof(u32));
353
354         /* Set each interrupt value */
355
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);
360
361         /* Resource Source Index and Resource Source are optional */
362
363         descriptor_length = acpi_rs_set_resource_source(aml, descriptor_length,
364                                                         &resource->data.
365                                                         extended_irq.
366                                                         resource_source);
367
368         /* Complete the AML descriptor header */
369
370         acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_EXTENDED_IRQ,
371                                     descriptor_length, aml);
372         return_ACPI_STATUS(AE_OK);
373 }