xref: /freebsd/sys/contrib/dev/acpica/components/resources/rsserial.c (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
1 /*******************************************************************************
2  *
3  * Module Name: rsserial - GPIO/SerialBus resource descriptors
4  *
5  ******************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2015, 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 <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acresrc.h>
47 
48 #define _COMPONENT          ACPI_RESOURCES
49         ACPI_MODULE_NAME    ("rsserial")
50 
51 
52 /*******************************************************************************
53  *
54  * AcpiRsConvertGpio
55  *
56  ******************************************************************************/
57 
58 ACPI_RSCONVERT_INFO     AcpiRsConvertGpio[18] =
59 {
60     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_GPIO,
61                         ACPI_RS_SIZE (ACPI_RESOURCE_GPIO),
62                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertGpio)},
63 
64     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_GPIO,
65                         sizeof (AML_RESOURCE_GPIO),
66                         0},
67 
68     /*
69      * These fields are contiguous in both the source and destination:
70      * RevisionId
71      * ConnectionType
72      */
73     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.Gpio.RevisionId),
74                         AML_OFFSET (Gpio.RevisionId),
75                         2},
76 
77     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Gpio.ProducerConsumer),
78                         AML_OFFSET (Gpio.Flags),
79                         0},
80 
81     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Gpio.Sharable),
82                         AML_OFFSET (Gpio.IntFlags),
83                         3},
84 
85     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Gpio.WakeCapable),
86                         AML_OFFSET (Gpio.IntFlags),
87                         4},
88 
89     {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Gpio.IoRestriction),
90                         AML_OFFSET (Gpio.IntFlags),
91                         0},
92 
93     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Gpio.Triggering),
94                         AML_OFFSET (Gpio.IntFlags),
95                         0},
96 
97     {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Gpio.Polarity),
98                         AML_OFFSET (Gpio.IntFlags),
99                         1},
100 
101     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.Gpio.PinConfig),
102                         AML_OFFSET (Gpio.PinConfig),
103                         1},
104 
105     /*
106      * These fields are contiguous in both the source and destination:
107      * DriveStrength
108      * DebounceTimeout
109      */
110     {ACPI_RSC_MOVE16,   ACPI_RS_OFFSET (Data.Gpio.DriveStrength),
111                         AML_OFFSET (Gpio.DriveStrength),
112                         2},
113 
114     /* Pin Table */
115 
116     {ACPI_RSC_COUNT_GPIO_PIN, ACPI_RS_OFFSET (Data.Gpio.PinTableLength),
117                         AML_OFFSET (Gpio.PinTableOffset),
118                         AML_OFFSET (Gpio.ResSourceOffset)},
119 
120     {ACPI_RSC_MOVE_GPIO_PIN, ACPI_RS_OFFSET (Data.Gpio.PinTable),
121                         AML_OFFSET (Gpio.PinTableOffset),
122                         0},
123 
124     /* Resource Source */
125 
126     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.Gpio.ResourceSource.Index),
127                         AML_OFFSET (Gpio.ResSourceIndex),
128                         1},
129 
130     {ACPI_RSC_COUNT_GPIO_RES,  ACPI_RS_OFFSET (Data.Gpio.ResourceSource.StringLength),
131                         AML_OFFSET (Gpio.ResSourceOffset),
132                         AML_OFFSET (Gpio.VendorOffset)},
133 
134     {ACPI_RSC_MOVE_GPIO_RES,   ACPI_RS_OFFSET (Data.Gpio.ResourceSource.StringPtr),
135                         AML_OFFSET (Gpio.ResSourceOffset),
136                         0},
137 
138     /* Vendor Data */
139 
140     {ACPI_RSC_COUNT_GPIO_VEN,   ACPI_RS_OFFSET (Data.Gpio.VendorLength),
141                         AML_OFFSET (Gpio.VendorLength),
142                         1},
143 
144     {ACPI_RSC_MOVE_GPIO_RES,   ACPI_RS_OFFSET (Data.Gpio.VendorData),
145                         AML_OFFSET (Gpio.VendorOffset),
146                         0},
147 };
148 
149 
150 /*******************************************************************************
151  *
152  * AcpiRsConvertI2cSerialBus
153  *
154  ******************************************************************************/
155 
156 ACPI_RSCONVERT_INFO     AcpiRsConvertI2cSerialBus[16] =
157 {
158     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_SERIAL_BUS,
159                         ACPI_RS_SIZE (ACPI_RESOURCE_I2C_SERIALBUS),
160                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertI2cSerialBus)},
161 
162     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_SERIAL_BUS,
163                         sizeof (AML_RESOURCE_I2C_SERIALBUS),
164                         0},
165 
166     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.CommonSerialBus.RevisionId),
167                         AML_OFFSET (CommonSerialBus.RevisionId),
168                         1},
169 
170     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.CommonSerialBus.Type),
171                         AML_OFFSET (CommonSerialBus.Type),
172                         1},
173 
174     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.CommonSerialBus.SlaveMode),
175                         AML_OFFSET (CommonSerialBus.Flags),
176                         0},
177 
178     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.CommonSerialBus.ProducerConsumer),
179                         AML_OFFSET (CommonSerialBus.Flags),
180                         1},
181 
182     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.CommonSerialBus.TypeRevisionId),
183                         AML_OFFSET (CommonSerialBus.TypeRevisionId),
184                         1},
185 
186     {ACPI_RSC_MOVE16,   ACPI_RS_OFFSET (Data.CommonSerialBus.TypeDataLength),
187                         AML_OFFSET (CommonSerialBus.TypeDataLength),
188                         1},
189 
190     /* Vendor data */
191 
192     {ACPI_RSC_COUNT_SERIAL_VEN, ACPI_RS_OFFSET (Data.CommonSerialBus.VendorLength),
193                         AML_OFFSET (CommonSerialBus.TypeDataLength),
194                         AML_RESOURCE_I2C_MIN_DATA_LEN},
195 
196     {ACPI_RSC_MOVE_SERIAL_VEN,  ACPI_RS_OFFSET (Data.CommonSerialBus.VendorData),
197                         0,
198                         sizeof (AML_RESOURCE_I2C_SERIALBUS)},
199 
200     /* Resource Source */
201 
202     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.CommonSerialBus.ResourceSource.Index),
203                         AML_OFFSET (CommonSerialBus.ResSourceIndex),
204                         1},
205 
206     {ACPI_RSC_COUNT_SERIAL_RES, ACPI_RS_OFFSET (Data.CommonSerialBus.ResourceSource.StringLength),
207                         AML_OFFSET (CommonSerialBus.TypeDataLength),
208                         sizeof (AML_RESOURCE_COMMON_SERIALBUS)},
209 
210     {ACPI_RSC_MOVE_SERIAL_RES,  ACPI_RS_OFFSET (Data.CommonSerialBus.ResourceSource.StringPtr),
211                         AML_OFFSET (CommonSerialBus.TypeDataLength),
212                         sizeof (AML_RESOURCE_COMMON_SERIALBUS)},
213 
214     /* I2C bus type specific */
215 
216     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.I2cSerialBus.AccessMode),
217                         AML_OFFSET (I2cSerialBus.TypeSpecificFlags),
218                         0},
219 
220     {ACPI_RSC_MOVE32,   ACPI_RS_OFFSET (Data.I2cSerialBus.ConnectionSpeed),
221                         AML_OFFSET (I2cSerialBus.ConnectionSpeed),
222                         1},
223 
224     {ACPI_RSC_MOVE16,   ACPI_RS_OFFSET (Data.I2cSerialBus.SlaveAddress),
225                         AML_OFFSET (I2cSerialBus.SlaveAddress),
226                         1},
227 };
228 
229 
230 /*******************************************************************************
231  *
232  * AcpiRsConvertSpiSerialBus
233  *
234  ******************************************************************************/
235 
236 ACPI_RSCONVERT_INFO     AcpiRsConvertSpiSerialBus[20] =
237 {
238     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_SERIAL_BUS,
239                         ACPI_RS_SIZE (ACPI_RESOURCE_SPI_SERIALBUS),
240                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertSpiSerialBus)},
241 
242     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_SERIAL_BUS,
243                         sizeof (AML_RESOURCE_SPI_SERIALBUS),
244                         0},
245 
246     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.CommonSerialBus.RevisionId),
247                         AML_OFFSET (CommonSerialBus.RevisionId),
248                         1},
249 
250     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.CommonSerialBus.Type),
251                         AML_OFFSET (CommonSerialBus.Type),
252                         1},
253 
254     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.CommonSerialBus.SlaveMode),
255                         AML_OFFSET (CommonSerialBus.Flags),
256                         0},
257 
258     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.CommonSerialBus.ProducerConsumer),
259                         AML_OFFSET (CommonSerialBus.Flags),
260                         1},
261 
262     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.CommonSerialBus.TypeRevisionId),
263                         AML_OFFSET (CommonSerialBus.TypeRevisionId),
264                         1},
265 
266     {ACPI_RSC_MOVE16,   ACPI_RS_OFFSET (Data.CommonSerialBus.TypeDataLength),
267                         AML_OFFSET (CommonSerialBus.TypeDataLength),
268                         1},
269 
270     /* Vendor data */
271 
272     {ACPI_RSC_COUNT_SERIAL_VEN, ACPI_RS_OFFSET (Data.CommonSerialBus.VendorLength),
273                         AML_OFFSET (CommonSerialBus.TypeDataLength),
274                         AML_RESOURCE_SPI_MIN_DATA_LEN},
275 
276     {ACPI_RSC_MOVE_SERIAL_VEN,  ACPI_RS_OFFSET (Data.CommonSerialBus.VendorData),
277                         0,
278                         sizeof (AML_RESOURCE_SPI_SERIALBUS)},
279 
280     /* Resource Source */
281 
282     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.CommonSerialBus.ResourceSource.Index),
283                         AML_OFFSET (CommonSerialBus.ResSourceIndex),
284                         1},
285 
286     {ACPI_RSC_COUNT_SERIAL_RES, ACPI_RS_OFFSET (Data.CommonSerialBus.ResourceSource.StringLength),
287                         AML_OFFSET (CommonSerialBus.TypeDataLength),
288                         sizeof (AML_RESOURCE_COMMON_SERIALBUS)},
289 
290     {ACPI_RSC_MOVE_SERIAL_RES,  ACPI_RS_OFFSET (Data.CommonSerialBus.ResourceSource.StringPtr),
291                         AML_OFFSET (CommonSerialBus.TypeDataLength),
292                         sizeof (AML_RESOURCE_COMMON_SERIALBUS)},
293 
294     /* Spi bus type specific  */
295 
296     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.SpiSerialBus.WireMode),
297                         AML_OFFSET (SpiSerialBus.TypeSpecificFlags),
298                         0},
299 
300     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.SpiSerialBus.DevicePolarity),
301                         AML_OFFSET (SpiSerialBus.TypeSpecificFlags),
302                         1},
303 
304     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.SpiSerialBus.DataBitLength),
305                         AML_OFFSET (SpiSerialBus.DataBitLength),
306                         1},
307 
308     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.SpiSerialBus.ClockPhase),
309                         AML_OFFSET (SpiSerialBus.ClockPhase),
310                         1},
311 
312     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.SpiSerialBus.ClockPolarity),
313                         AML_OFFSET (SpiSerialBus.ClockPolarity),
314                         1},
315 
316     {ACPI_RSC_MOVE16,   ACPI_RS_OFFSET (Data.SpiSerialBus.DeviceSelection),
317                         AML_OFFSET (SpiSerialBus.DeviceSelection),
318                         1},
319 
320     {ACPI_RSC_MOVE32,   ACPI_RS_OFFSET (Data.SpiSerialBus.ConnectionSpeed),
321                         AML_OFFSET (SpiSerialBus.ConnectionSpeed),
322                         1},
323 };
324 
325 
326 /*******************************************************************************
327  *
328  * AcpiRsConvertUartSerialBus
329  *
330  ******************************************************************************/
331 
332 ACPI_RSCONVERT_INFO     AcpiRsConvertUartSerialBus[22] =
333 {
334     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_SERIAL_BUS,
335                         ACPI_RS_SIZE (ACPI_RESOURCE_UART_SERIALBUS),
336                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertUartSerialBus)},
337 
338     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_SERIAL_BUS,
339                         sizeof (AML_RESOURCE_UART_SERIALBUS),
340                         0},
341 
342     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.CommonSerialBus.RevisionId),
343                         AML_OFFSET (CommonSerialBus.RevisionId),
344                         1},
345 
346     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.CommonSerialBus.Type),
347                         AML_OFFSET (CommonSerialBus.Type),
348                         1},
349 
350     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.CommonSerialBus.SlaveMode),
351                         AML_OFFSET (CommonSerialBus.Flags),
352                         0},
353 
354     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.CommonSerialBus.ProducerConsumer),
355                         AML_OFFSET (CommonSerialBus.Flags),
356                         1},
357 
358     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.CommonSerialBus.TypeRevisionId),
359                         AML_OFFSET (CommonSerialBus.TypeRevisionId),
360                         1},
361 
362     {ACPI_RSC_MOVE16,   ACPI_RS_OFFSET (Data.CommonSerialBus.TypeDataLength),
363                         AML_OFFSET (CommonSerialBus.TypeDataLength),
364                         1},
365 
366     /* Vendor data */
367 
368     {ACPI_RSC_COUNT_SERIAL_VEN, ACPI_RS_OFFSET (Data.CommonSerialBus.VendorLength),
369                         AML_OFFSET (CommonSerialBus.TypeDataLength),
370                         AML_RESOURCE_UART_MIN_DATA_LEN},
371 
372     {ACPI_RSC_MOVE_SERIAL_VEN,  ACPI_RS_OFFSET (Data.CommonSerialBus.VendorData),
373                         0,
374                         sizeof (AML_RESOURCE_UART_SERIALBUS)},
375 
376     /* Resource Source */
377 
378     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.CommonSerialBus.ResourceSource.Index),
379                         AML_OFFSET (CommonSerialBus.ResSourceIndex),
380                         1},
381 
382     {ACPI_RSC_COUNT_SERIAL_RES, ACPI_RS_OFFSET (Data.CommonSerialBus.ResourceSource.StringLength),
383                         AML_OFFSET (CommonSerialBus.TypeDataLength),
384                         sizeof (AML_RESOURCE_COMMON_SERIALBUS)},
385 
386     {ACPI_RSC_MOVE_SERIAL_RES,  ACPI_RS_OFFSET (Data.CommonSerialBus.ResourceSource.StringPtr),
387                         AML_OFFSET (CommonSerialBus.TypeDataLength),
388                         sizeof (AML_RESOURCE_COMMON_SERIALBUS)},
389 
390     /* Uart bus type specific  */
391 
392     {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.UartSerialBus.FlowControl),
393                         AML_OFFSET (UartSerialBus.TypeSpecificFlags),
394                         0},
395 
396     {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.UartSerialBus.StopBits),
397                         AML_OFFSET (UartSerialBus.TypeSpecificFlags),
398                         2},
399 
400     {ACPI_RSC_3BITFLAG, ACPI_RS_OFFSET (Data.UartSerialBus.DataBits),
401                         AML_OFFSET (UartSerialBus.TypeSpecificFlags),
402                         4},
403 
404     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.UartSerialBus.Endian),
405                         AML_OFFSET (UartSerialBus.TypeSpecificFlags),
406                         7},
407 
408     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.UartSerialBus.Parity),
409                         AML_OFFSET (UartSerialBus.Parity),
410                         1},
411 
412     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.UartSerialBus.LinesEnabled),
413                         AML_OFFSET (UartSerialBus.LinesEnabled),
414                         1},
415 
416     {ACPI_RSC_MOVE16,   ACPI_RS_OFFSET (Data.UartSerialBus.RxFifoSize),
417                         AML_OFFSET (UartSerialBus.RxFifoSize),
418                         1},
419 
420     {ACPI_RSC_MOVE16,   ACPI_RS_OFFSET (Data.UartSerialBus.TxFifoSize),
421                         AML_OFFSET (UartSerialBus.TxFifoSize),
422                         1},
423 
424     {ACPI_RSC_MOVE32,   ACPI_RS_OFFSET (Data.UartSerialBus.DefaultBaudRate),
425                         AML_OFFSET (UartSerialBus.DefaultBaudRate),
426                         1},
427 };
428