xref: /titanic_50/usr/src/uts/intel/io/acpica/resources/rsirq.c (revision 385cc6b4ad1792caef3f84eb61eed3f27085801f)
1 /*******************************************************************************
2  *
3  * Module Name: rsirq - IRQ resource descriptors
4  *
5  ******************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2016, Intel Corp.
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.h"
45 #include "accommon.h"
46 #include "acresrc.h"
47 
48 #define _COMPONENT          ACPI_RESOURCES
49         ACPI_MODULE_NAME    ("rsirq")
50 
51 
52 /*******************************************************************************
53  *
54  * AcpiRsGetIrq
55  *
56  ******************************************************************************/
57 
58 ACPI_RSCONVERT_INFO     AcpiRsGetIrq[9] =
59 {
60     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_IRQ,
61                         ACPI_RS_SIZE (ACPI_RESOURCE_IRQ),
62                         ACPI_RSC_TABLE_SIZE (AcpiRsGetIrq)},
63 
64     /* Get the IRQ mask (bytes 1:2) */
65 
66     {ACPI_RSC_BITMASK16,ACPI_RS_OFFSET (Data.Irq.Interrupts[0]),
67                         AML_OFFSET (Irq.IrqMask),
68                         ACPI_RS_OFFSET (Data.Irq.InterruptCount)},
69 
70     /* Set default flags (others are zero) */
71 
72     {ACPI_RSC_SET8,     ACPI_RS_OFFSET (Data.Irq.Triggering),
73                         ACPI_EDGE_SENSITIVE,
74                         1},
75 
76     /* Get the descriptor length (2 or 3 for IRQ descriptor) */
77 
78     {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Irq.DescriptorLength),
79                         AML_OFFSET (Irq.DescriptorType),
80                         0},
81 
82     /* All done if no flag byte present in descriptor */
83 
84     {ACPI_RSC_EXIT_NE,  ACPI_RSC_COMPARE_AML_LENGTH, 0, 3},
85 
86     /* Get flags: Triggering[0], Polarity[3], Sharing[4], Wake[5] */
87 
88     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Triggering),
89                         AML_OFFSET (Irq.Flags),
90                         0},
91 
92     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Polarity),
93                         AML_OFFSET (Irq.Flags),
94                         3},
95 
96     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Sharable),
97                         AML_OFFSET (Irq.Flags),
98                         4},
99 
100     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.WakeCapable),
101                         AML_OFFSET (Irq.Flags),
102                         5}
103 };
104 
105 
106 /*******************************************************************************
107  *
108  * AcpiRsSetIrq
109  *
110  ******************************************************************************/
111 
112 ACPI_RSCONVERT_INFO     AcpiRsSetIrq[14] =
113 {
114     /* Start with a default descriptor of length 3 */
115 
116     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_IRQ,
117                         sizeof (AML_RESOURCE_IRQ),
118                         ACPI_RSC_TABLE_SIZE (AcpiRsSetIrq)},
119 
120     /* Convert interrupt list to 16-bit IRQ bitmask */
121 
122     {ACPI_RSC_BITMASK16,ACPI_RS_OFFSET (Data.Irq.Interrupts[0]),
123                         AML_OFFSET (Irq.IrqMask),
124                         ACPI_RS_OFFSET (Data.Irq.InterruptCount)},
125 
126     /* Set flags: Triggering[0], Polarity[3], Sharing[4], Wake[5] */
127 
128     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Triggering),
129                         AML_OFFSET (Irq.Flags),
130                         0},
131 
132     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Polarity),
133                         AML_OFFSET (Irq.Flags),
134                         3},
135 
136     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Sharable),
137                         AML_OFFSET (Irq.Flags),
138                         4},
139 
140     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.WakeCapable),
141                         AML_OFFSET (Irq.Flags),
142                         5},
143 
144     /*
145      * All done if the output descriptor length is required to be 3
146      * (i.e., optimization to 2 bytes cannot be attempted)
147      */
148     {ACPI_RSC_EXIT_EQ,  ACPI_RSC_COMPARE_VALUE,
149                         ACPI_RS_OFFSET(Data.Irq.DescriptorLength),
150                         3},
151 
152     /* Set length to 2 bytes (no flags byte) */
153 
154     {ACPI_RSC_LENGTH,   0, 0, sizeof (AML_RESOURCE_IRQ_NOFLAGS)},
155 
156     /*
157      * All done if the output descriptor length is required to be 2.
158      *
159      * TBD: Perhaps we should check for error if input flags are not
160      * compatible with a 2-byte descriptor.
161      */
162     {ACPI_RSC_EXIT_EQ,  ACPI_RSC_COMPARE_VALUE,
163                         ACPI_RS_OFFSET(Data.Irq.DescriptorLength),
164                         2},
165 
166     /* Reset length to 3 bytes (descriptor with flags byte) */
167 
168     {ACPI_RSC_LENGTH,   0, 0, sizeof (AML_RESOURCE_IRQ)},
169 
170     /*
171      * Check if the flags byte is necessary. Not needed if the flags are:
172      * ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_HIGH, ACPI_EXCLUSIVE
173      */
174     {ACPI_RSC_EXIT_NE,  ACPI_RSC_COMPARE_VALUE,
175                         ACPI_RS_OFFSET (Data.Irq.Triggering),
176                         ACPI_EDGE_SENSITIVE},
177 
178     {ACPI_RSC_EXIT_NE,  ACPI_RSC_COMPARE_VALUE,
179                         ACPI_RS_OFFSET (Data.Irq.Polarity),
180                         ACPI_ACTIVE_HIGH},
181 
182     {ACPI_RSC_EXIT_NE,  ACPI_RSC_COMPARE_VALUE,
183                         ACPI_RS_OFFSET (Data.Irq.Sharable),
184                         ACPI_EXCLUSIVE},
185 
186     /* We can optimize to a 2-byte IrqNoFlags() descriptor */
187 
188     {ACPI_RSC_LENGTH,   0, 0, sizeof (AML_RESOURCE_IRQ_NOFLAGS)}
189 };
190 
191 
192 /*******************************************************************************
193  *
194  * AcpiRsConvertExtIrq
195  *
196  ******************************************************************************/
197 
198 ACPI_RSCONVERT_INFO     AcpiRsConvertExtIrq[10] =
199 {
200     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_EXTENDED_IRQ,
201                         ACPI_RS_SIZE (ACPI_RESOURCE_EXTENDED_IRQ),
202                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertExtIrq)},
203 
204     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_EXTENDED_IRQ,
205                         sizeof (AML_RESOURCE_EXTENDED_IRQ),
206                         0},
207 
208     /*
209      * Flags: Producer/Consumer[0], Triggering[1], Polarity[2],
210      *        Sharing[3], Wake[4]
211      */
212     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.ProducerConsumer),
213                         AML_OFFSET (ExtendedIrq.Flags),
214                         0},
215 
216     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.Triggering),
217                         AML_OFFSET (ExtendedIrq.Flags),
218                         1},
219 
220     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.Polarity),
221                         AML_OFFSET (ExtendedIrq.Flags),
222                         2},
223 
224     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.Sharable),
225                         AML_OFFSET (ExtendedIrq.Flags),
226                         3},
227 
228     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.WakeCapable),
229                         AML_OFFSET (ExtendedIrq.Flags),
230                         4},
231 
232     /* IRQ Table length (Byte4) */
233 
234     {ACPI_RSC_COUNT,    ACPI_RS_OFFSET (Data.ExtendedIrq.InterruptCount),
235                         AML_OFFSET (ExtendedIrq.InterruptCount),
236                         sizeof (UINT32)},
237 
238     /* Copy every IRQ in the table, each is 32 bits */
239 
240     {ACPI_RSC_MOVE32,   ACPI_RS_OFFSET (Data.ExtendedIrq.Interrupts[0]),
241                         AML_OFFSET (ExtendedIrq.Interrupts[0]),
242                         0},
243 
244     /* Optional ResourceSource (Index and String) */
245 
246     {ACPI_RSC_SOURCEX,  ACPI_RS_OFFSET (Data.ExtendedIrq.ResourceSource),
247                         ACPI_RS_OFFSET (Data.ExtendedIrq.Interrupts[0]),
248                         sizeof (AML_RESOURCE_EXTENDED_IRQ)}
249 };
250 
251 
252 /*******************************************************************************
253  *
254  * AcpiRsConvertDma
255  *
256  ******************************************************************************/
257 
258 ACPI_RSCONVERT_INFO     AcpiRsConvertDma[6] =
259 {
260     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_DMA,
261                         ACPI_RS_SIZE (ACPI_RESOURCE_DMA),
262                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertDma)},
263 
264     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_DMA,
265                         sizeof (AML_RESOURCE_DMA),
266                         0},
267 
268     /* Flags: transfer preference, bus mastering, channel speed */
269 
270     {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Dma.Transfer),
271                         AML_OFFSET (Dma.Flags),
272                         0},
273 
274     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Dma.BusMaster),
275                         AML_OFFSET (Dma.Flags),
276                         2},
277 
278     {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Dma.Type),
279                         AML_OFFSET (Dma.Flags),
280                         5},
281 
282     /* DMA channel mask bits */
283 
284     {ACPI_RSC_BITMASK,  ACPI_RS_OFFSET (Data.Dma.Channels[0]),
285                         AML_OFFSET (Dma.DmaChannelMask),
286                         ACPI_RS_OFFSET (Data.Dma.ChannelCount)}
287 };
288 
289 
290 /*******************************************************************************
291  *
292  * AcpiRsConvertFixedDma
293  *
294  ******************************************************************************/
295 
296 ACPI_RSCONVERT_INFO     AcpiRsConvertFixedDma[4] =
297 {
298     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_FIXED_DMA,
299                         ACPI_RS_SIZE (ACPI_RESOURCE_FIXED_DMA),
300                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertFixedDma)},
301 
302     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_FIXED_DMA,
303                         sizeof (AML_RESOURCE_FIXED_DMA),
304                         0},
305 
306     /*
307      * These fields are contiguous in both the source and destination:
308      * RequestLines
309      * Channels
310      */
311     {ACPI_RSC_MOVE16,   ACPI_RS_OFFSET (Data.FixedDma.RequestLines),
312                         AML_OFFSET (FixedDma.RequestLines),
313                         2},
314 
315     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.FixedDma.Width),
316                         AML_OFFSET (FixedDma.Width),
317                         1},
318 };
319