xref: /freebsd/sys/contrib/dev/acpica/include/amlresrc.h (revision 8d20be1e22095c27faf8fe8b2f0d089739cc742e)
1 /******************************************************************************
2  *
3  * Module Name: amlresrc.h - AML resource descriptors
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2013, 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 /* acpisrc:StructDefs -- for acpisrc conversion */
45 
46 #ifndef __AMLRESRC_H
47 #define __AMLRESRC_H
48 
49 
50 /*
51  * Resource descriptor tags, as defined in the ACPI specification.
52  * Used to symbolically reference fields within a descriptor.
53  */
54 #define ACPI_RESTAG_ADDRESS                     "_ADR"
55 #define ACPI_RESTAG_ALIGNMENT                   "_ALN"
56 #define ACPI_RESTAG_ADDRESSSPACE                "_ASI"
57 #define ACPI_RESTAG_ACCESSSIZE                  "_ASZ"
58 #define ACPI_RESTAG_TYPESPECIFICATTRIBUTES      "_ATT"
59 #define ACPI_RESTAG_BASEADDRESS                 "_BAS"
60 #define ACPI_RESTAG_BUSMASTER                   "_BM_"  /* Master(1), Slave(0) */
61 #define ACPI_RESTAG_DEBOUNCETIME                "_DBT"
62 #define ACPI_RESTAG_DECODE                      "_DEC"
63 #define ACPI_RESTAG_DEVICEPOLARITY              "_DPL"
64 #define ACPI_RESTAG_DMA                         "_DMA"
65 #define ACPI_RESTAG_DMATYPE                     "_TYP"  /* Compatible(0), A(1), B(2), F(3) */
66 #define ACPI_RESTAG_DRIVESTRENGTH               "_DRS"
67 #define ACPI_RESTAG_ENDIANNESS                  "_END"
68 #define ACPI_RESTAG_FLOWCONTROL                 "_FLC"
69 #define ACPI_RESTAG_GRANULARITY                 "_GRA"
70 #define ACPI_RESTAG_INTERRUPT                   "_INT"
71 #define ACPI_RESTAG_INTERRUPTLEVEL              "_LL_"  /* ActiveLo(1), ActiveHi(0) */
72 #define ACPI_RESTAG_INTERRUPTSHARE              "_SHR"  /* Shareable(1), NoShare(0) */
73 #define ACPI_RESTAG_INTERRUPTTYPE               "_HE_"  /* Edge(1), Level(0) */
74 #define ACPI_RESTAG_IORESTRICTION               "_IOR"
75 #define ACPI_RESTAG_LENGTH                      "_LEN"
76 #define ACPI_RESTAG_LINE                        "_LIN"
77 #define ACPI_RESTAG_MEMATTRIBUTES               "_MTP"  /* Memory(0), Reserved(1), ACPI(2), NVS(3) */
78 #define ACPI_RESTAG_MEMTYPE                     "_MEM"  /* NonCache(0), Cacheable(1) Cache+combine(2), Cache+prefetch(3) */
79 #define ACPI_RESTAG_MAXADDR                     "_MAX"
80 #define ACPI_RESTAG_MINADDR                     "_MIN"
81 #define ACPI_RESTAG_MAXTYPE                     "_MAF"
82 #define ACPI_RESTAG_MINTYPE                     "_MIF"
83 #define ACPI_RESTAG_MODE                        "_MOD"
84 #define ACPI_RESTAG_PARITY                      "_PAR"
85 #define ACPI_RESTAG_PHASE                       "_PHA"
86 #define ACPI_RESTAG_PIN                         "_PIN"
87 #define ACPI_RESTAG_PINCONFIG                   "_PPI"
88 #define ACPI_RESTAG_POLARITY                    "_POL"
89 #define ACPI_RESTAG_REGISTERBITOFFSET           "_RBO"
90 #define ACPI_RESTAG_REGISTERBITWIDTH            "_RBW"
91 #define ACPI_RESTAG_RANGETYPE                   "_RNG"
92 #define ACPI_RESTAG_READWRITETYPE               "_RW_"  /* ReadOnly(0), Writeable (1) */
93 #define ACPI_RESTAG_LENGTH_RX                   "_RXL"
94 #define ACPI_RESTAG_LENGTH_TX                   "_TXL"
95 #define ACPI_RESTAG_SLAVEMODE                   "_SLV"
96 #define ACPI_RESTAG_SPEED                       "_SPE"
97 #define ACPI_RESTAG_STOPBITS                    "_STB"
98 #define ACPI_RESTAG_TRANSLATION                 "_TRA"
99 #define ACPI_RESTAG_TRANSTYPE                   "_TRS"  /* Sparse(1), Dense(0) */
100 #define ACPI_RESTAG_TYPE                        "_TTP"  /* Translation(1), Static (0) */
101 #define ACPI_RESTAG_XFERTYPE                    "_SIZ"  /* 8(0), 8And16(1), 16(2) */
102 #define ACPI_RESTAG_VENDORDATA                  "_VEN"
103 
104 
105 /* Default sizes for "small" resource descriptors */
106 
107 #define ASL_RDESC_IRQ_SIZE                      0x02
108 #define ASL_RDESC_DMA_SIZE                      0x02
109 #define ASL_RDESC_ST_DEPEND_SIZE                0x00
110 #define ASL_RDESC_END_DEPEND_SIZE               0x00
111 #define ASL_RDESC_IO_SIZE                       0x07
112 #define ASL_RDESC_FIXED_IO_SIZE                 0x03
113 #define ASL_RDESC_FIXED_DMA_SIZE                0x05
114 #define ASL_RDESC_END_TAG_SIZE                  0x01
115 
116 
117 typedef struct asl_resource_node
118 {
119     UINT32                          BufferLength;
120     void                            *Buffer;
121     struct asl_resource_node        *Next;
122 
123 } ASL_RESOURCE_NODE;
124 
125 
126 /* Macros used to generate AML resource length fields */
127 
128 #define ACPI_AML_SIZE_LARGE(r)      (sizeof (r) - sizeof (AML_RESOURCE_LARGE_HEADER))
129 #define ACPI_AML_SIZE_SMALL(r)      (sizeof (r) - sizeof (AML_RESOURCE_SMALL_HEADER))
130 
131 /*
132  * Resource descriptors defined in the ACPI specification.
133  *
134  * Packing/alignment must be BYTE because these descriptors
135  * are used to overlay the raw AML byte stream.
136  */
137 #pragma pack(1)
138 
139 /*
140  * SMALL descriptors
141  */
142 #define AML_RESOURCE_SMALL_HEADER_COMMON \
143     UINT8                           DescriptorType;
144 
145 typedef struct aml_resource_small_header
146 {
147     AML_RESOURCE_SMALL_HEADER_COMMON
148 
149 } AML_RESOURCE_SMALL_HEADER;
150 
151 
152 typedef struct aml_resource_irq
153 {
154     AML_RESOURCE_SMALL_HEADER_COMMON
155     UINT16                          IrqMask;
156     UINT8                           Flags;
157 
158 } AML_RESOURCE_IRQ;
159 
160 
161 typedef struct aml_resource_irq_noflags
162 {
163     AML_RESOURCE_SMALL_HEADER_COMMON
164     UINT16                          IrqMask;
165 
166 } AML_RESOURCE_IRQ_NOFLAGS;
167 
168 
169 typedef struct aml_resource_dma
170 {
171     AML_RESOURCE_SMALL_HEADER_COMMON
172     UINT8                           DmaChannelMask;
173     UINT8                           Flags;
174 
175 } AML_RESOURCE_DMA;
176 
177 
178 typedef struct aml_resource_start_dependent
179 {
180     AML_RESOURCE_SMALL_HEADER_COMMON
181     UINT8                           Flags;
182 
183 } AML_RESOURCE_START_DEPENDENT;
184 
185 
186 typedef struct aml_resource_start_dependent_noprio
187 {
188     AML_RESOURCE_SMALL_HEADER_COMMON
189 
190 } AML_RESOURCE_START_DEPENDENT_NOPRIO;
191 
192 
193 typedef struct aml_resource_end_dependent
194 {
195     AML_RESOURCE_SMALL_HEADER_COMMON
196 
197 } AML_RESOURCE_END_DEPENDENT;
198 
199 
200 typedef struct aml_resource_io
201 {
202     AML_RESOURCE_SMALL_HEADER_COMMON
203     UINT8                           Flags;
204     UINT16                          Minimum;
205     UINT16                          Maximum;
206     UINT8                           Alignment;
207     UINT8                           AddressLength;
208 
209 } AML_RESOURCE_IO;
210 
211 
212 typedef struct aml_resource_fixed_io
213 {
214     AML_RESOURCE_SMALL_HEADER_COMMON
215     UINT16                          Address;
216     UINT8                           AddressLength;
217 
218 } AML_RESOURCE_FIXED_IO;
219 
220 
221 typedef struct aml_resource_vendor_small
222 {
223     AML_RESOURCE_SMALL_HEADER_COMMON
224 
225 } AML_RESOURCE_VENDOR_SMALL;
226 
227 
228 typedef struct aml_resource_end_tag
229 {
230     AML_RESOURCE_SMALL_HEADER_COMMON
231     UINT8                           Checksum;
232 
233 } AML_RESOURCE_END_TAG;
234 
235 
236 typedef struct aml_resource_fixed_dma
237 {
238     AML_RESOURCE_SMALL_HEADER_COMMON
239     UINT16                          RequestLines;
240     UINT16                          Channels;
241     UINT8                           Width;
242 
243 } AML_RESOURCE_FIXED_DMA;
244 
245 
246 /*
247  * LARGE descriptors
248  */
249 #define AML_RESOURCE_LARGE_HEADER_COMMON \
250     UINT8                           DescriptorType;\
251     UINT16                          ResourceLength;
252 
253 typedef struct aml_resource_large_header
254 {
255     AML_RESOURCE_LARGE_HEADER_COMMON
256 
257 } AML_RESOURCE_LARGE_HEADER;
258 
259 
260 /* General Flags for address space resource descriptors */
261 
262 #define ACPI_RESOURCE_FLAG_DEC      2
263 #define ACPI_RESOURCE_FLAG_MIF      4
264 #define ACPI_RESOURCE_FLAG_MAF      8
265 
266 typedef struct aml_resource_memory24
267 {
268     AML_RESOURCE_LARGE_HEADER_COMMON
269     UINT8                           Flags;
270     UINT16                          Minimum;
271     UINT16                          Maximum;
272     UINT16                          Alignment;
273     UINT16                          AddressLength;
274 
275 } AML_RESOURCE_MEMORY24;
276 
277 
278 typedef struct aml_resource_vendor_large
279 {
280     AML_RESOURCE_LARGE_HEADER_COMMON
281 
282 } AML_RESOURCE_VENDOR_LARGE;
283 
284 
285 typedef struct aml_resource_memory32
286 {
287     AML_RESOURCE_LARGE_HEADER_COMMON
288     UINT8                           Flags;
289     UINT32                          Minimum;
290     UINT32                          Maximum;
291     UINT32                          Alignment;
292     UINT32                          AddressLength;
293 
294 } AML_RESOURCE_MEMORY32;
295 
296 
297 typedef struct aml_resource_fixed_memory32
298 {
299     AML_RESOURCE_LARGE_HEADER_COMMON
300     UINT8                           Flags;
301     UINT32                          Address;
302     UINT32                          AddressLength;
303 
304 } AML_RESOURCE_FIXED_MEMORY32;
305 
306 
307 #define AML_RESOURCE_ADDRESS_COMMON \
308     UINT8                           ResourceType; \
309     UINT8                           Flags; \
310     UINT8                           SpecificFlags;
311 
312 
313 typedef struct aml_resource_address
314 {
315     AML_RESOURCE_LARGE_HEADER_COMMON
316     AML_RESOURCE_ADDRESS_COMMON
317 
318 } AML_RESOURCE_ADDRESS;
319 
320 
321 typedef struct aml_resource_extended_address64
322 {
323     AML_RESOURCE_LARGE_HEADER_COMMON
324     AML_RESOURCE_ADDRESS_COMMON
325     UINT8                           RevisionID;
326     UINT8                           Reserved;
327     UINT64                          Granularity;
328     UINT64                          Minimum;
329     UINT64                          Maximum;
330     UINT64                          TranslationOffset;
331     UINT64                          AddressLength;
332     UINT64                          TypeSpecific;
333 
334 } AML_RESOURCE_EXTENDED_ADDRESS64;
335 
336 #define AML_RESOURCE_EXTENDED_ADDRESS_REVISION          1       /* ACPI 3.0 */
337 
338 
339 typedef struct aml_resource_address64
340 {
341     AML_RESOURCE_LARGE_HEADER_COMMON
342     AML_RESOURCE_ADDRESS_COMMON
343     UINT64                          Granularity;
344     UINT64                          Minimum;
345     UINT64                          Maximum;
346     UINT64                          TranslationOffset;
347     UINT64                          AddressLength;
348 
349 } AML_RESOURCE_ADDRESS64;
350 
351 
352 typedef struct aml_resource_address32
353 {
354     AML_RESOURCE_LARGE_HEADER_COMMON
355     AML_RESOURCE_ADDRESS_COMMON
356     UINT32                          Granularity;
357     UINT32                          Minimum;
358     UINT32                          Maximum;
359     UINT32                          TranslationOffset;
360     UINT32                          AddressLength;
361 
362 } AML_RESOURCE_ADDRESS32;
363 
364 
365 typedef struct aml_resource_address16
366 {
367     AML_RESOURCE_LARGE_HEADER_COMMON
368     AML_RESOURCE_ADDRESS_COMMON
369     UINT16                          Granularity;
370     UINT16                          Minimum;
371     UINT16                          Maximum;
372     UINT16                          TranslationOffset;
373     UINT16                          AddressLength;
374 
375 } AML_RESOURCE_ADDRESS16;
376 
377 
378 typedef struct aml_resource_extended_irq
379 {
380     AML_RESOURCE_LARGE_HEADER_COMMON
381     UINT8                           Flags;
382     UINT8                           InterruptCount;
383     UINT32                          Interrupts[1];
384     /* ResSourceIndex, ResSource optional fields follow */
385 
386 } AML_RESOURCE_EXTENDED_IRQ;
387 
388 
389 typedef struct aml_resource_generic_register
390 {
391     AML_RESOURCE_LARGE_HEADER_COMMON
392     UINT8                           AddressSpaceId;
393     UINT8                           BitWidth;
394     UINT8                           BitOffset;
395     UINT8                           AccessSize; /* ACPI 3.0, was previously Reserved */
396     UINT64                          Address;
397 
398 } AML_RESOURCE_GENERIC_REGISTER;
399 
400 
401 /* Common descriptor for GpioInt and GpioIo (ACPI 5.0) */
402 
403 typedef struct aml_resource_gpio
404 {
405     AML_RESOURCE_LARGE_HEADER_COMMON
406     UINT8                           RevisionId;
407     UINT8                           ConnectionType;
408     UINT16                          Flags;
409     UINT16                          IntFlags;
410     UINT8                           PinConfig;
411     UINT16                          DriveStrength;
412     UINT16                          DebounceTimeout;
413     UINT16                          PinTableOffset;
414     UINT8                           ResSourceIndex;
415     UINT16                          ResSourceOffset;
416     UINT16                          VendorOffset;
417     UINT16                          VendorLength;
418     /*
419      * Optional fields follow immediately:
420      * 1) PIN list (Words)
421      * 2) Resource Source String
422      * 3) Vendor Data bytes
423      */
424 
425 } AML_RESOURCE_GPIO;
426 
427 #define AML_RESOURCE_GPIO_REVISION              1       /* ACPI 5.0 */
428 
429 /* Values for ConnectionType above */
430 
431 #define AML_RESOURCE_GPIO_TYPE_INT              0
432 #define AML_RESOURCE_GPIO_TYPE_IO               1
433 #define AML_RESOURCE_MAX_GPIOTYPE               1
434 
435 
436 /* Common preamble for all serial descriptors (ACPI 5.0) */
437 
438 #define AML_RESOURCE_SERIAL_COMMON \
439     UINT8                           RevisionId; \
440     UINT8                           ResSourceIndex; \
441     UINT8                           Type; \
442     UINT8                           Flags; \
443     UINT16                          TypeSpecificFlags; \
444     UINT8                           TypeRevisionId; \
445     UINT16                          TypeDataLength; \
446 
447 /* Values for the type field above */
448 
449 #define AML_RESOURCE_I2C_SERIALBUSTYPE          1
450 #define AML_RESOURCE_SPI_SERIALBUSTYPE          2
451 #define AML_RESOURCE_UART_SERIALBUSTYPE         3
452 #define AML_RESOURCE_MAX_SERIALBUSTYPE          3
453 #define AML_RESOURCE_VENDOR_SERIALBUSTYPE       192 /* Vendor defined is 0xC0-0xFF (NOT SUPPORTED) */
454 
455 typedef struct aml_resource_common_serialbus
456 {
457     AML_RESOURCE_LARGE_HEADER_COMMON
458     AML_RESOURCE_SERIAL_COMMON
459 
460 } AML_RESOURCE_COMMON_SERIALBUS;
461 
462 typedef struct aml_resource_i2c_serialbus
463 {
464     AML_RESOURCE_LARGE_HEADER_COMMON
465     AML_RESOURCE_SERIAL_COMMON
466     UINT32                          ConnectionSpeed;
467     UINT16                          SlaveAddress;
468     /*
469      * Optional fields follow immediately:
470      * 1) Vendor Data bytes
471      * 2) Resource Source String
472      */
473 
474 } AML_RESOURCE_I2C_SERIALBUS;
475 
476 #define AML_RESOURCE_I2C_REVISION               1       /* ACPI 5.0 */
477 #define AML_RESOURCE_I2C_TYPE_REVISION          1       /* ACPI 5.0 */
478 #define AML_RESOURCE_I2C_MIN_DATA_LEN           6
479 
480 typedef struct aml_resource_spi_serialbus
481 {
482     AML_RESOURCE_LARGE_HEADER_COMMON
483     AML_RESOURCE_SERIAL_COMMON
484     UINT32                          ConnectionSpeed;
485     UINT8                           DataBitLength;
486     UINT8                           ClockPhase;
487     UINT8                           ClockPolarity;
488     UINT16                          DeviceSelection;
489     /*
490      * Optional fields follow immediately:
491      * 1) Vendor Data bytes
492      * 2) Resource Source String
493      */
494 
495 } AML_RESOURCE_SPI_SERIALBUS;
496 
497 #define AML_RESOURCE_SPI_REVISION               1       /* ACPI 5.0 */
498 #define AML_RESOURCE_SPI_TYPE_REVISION          1       /* ACPI 5.0 */
499 #define AML_RESOURCE_SPI_MIN_DATA_LEN           9
500 
501 
502 typedef struct aml_resource_uart_serialbus
503 {
504     AML_RESOURCE_LARGE_HEADER_COMMON
505     AML_RESOURCE_SERIAL_COMMON
506     UINT32                          DefaultBaudRate;
507     UINT16                          RxFifoSize;
508     UINT16                          TxFifoSize;
509     UINT8                           Parity;
510     UINT8                           LinesEnabled;
511     /*
512      * Optional fields follow immediately:
513      * 1) Vendor Data bytes
514      * 2) Resource Source String
515      */
516 
517 } AML_RESOURCE_UART_SERIALBUS;
518 
519 #define AML_RESOURCE_UART_REVISION              1       /* ACPI 5.0 */
520 #define AML_RESOURCE_UART_TYPE_REVISION         1       /* ACPI 5.0 */
521 #define AML_RESOURCE_UART_MIN_DATA_LEN          10
522 
523 
524 /* restore default alignment */
525 
526 #pragma pack()
527 
528 /* Union of all resource descriptors, so we can allocate the worst case */
529 
530 typedef union aml_resource
531 {
532     /* Descriptor headers */
533 
534     UINT8                                   DescriptorType;
535     AML_RESOURCE_SMALL_HEADER               SmallHeader;
536     AML_RESOURCE_LARGE_HEADER               LargeHeader;
537 
538     /* Small resource descriptors */
539 
540     AML_RESOURCE_IRQ                        Irq;
541     AML_RESOURCE_DMA                        Dma;
542     AML_RESOURCE_START_DEPENDENT            StartDpf;
543     AML_RESOURCE_END_DEPENDENT              EndDpf;
544     AML_RESOURCE_IO                         Io;
545     AML_RESOURCE_FIXED_IO                   FixedIo;
546     AML_RESOURCE_FIXED_DMA                  FixedDma;
547     AML_RESOURCE_VENDOR_SMALL               VendorSmall;
548     AML_RESOURCE_END_TAG                    EndTag;
549 
550     /* Large resource descriptors */
551 
552     AML_RESOURCE_MEMORY24                   Memory24;
553     AML_RESOURCE_GENERIC_REGISTER           GenericReg;
554     AML_RESOURCE_VENDOR_LARGE               VendorLarge;
555     AML_RESOURCE_MEMORY32                   Memory32;
556     AML_RESOURCE_FIXED_MEMORY32             FixedMemory32;
557     AML_RESOURCE_ADDRESS16                  Address16;
558     AML_RESOURCE_ADDRESS32                  Address32;
559     AML_RESOURCE_ADDRESS64                  Address64;
560     AML_RESOURCE_EXTENDED_ADDRESS64         ExtAddress64;
561     AML_RESOURCE_EXTENDED_IRQ               ExtendedIrq;
562     AML_RESOURCE_GPIO                       Gpio;
563     AML_RESOURCE_I2C_SERIALBUS              I2cSerialBus;
564     AML_RESOURCE_SPI_SERIALBUS              SpiSerialBus;
565     AML_RESOURCE_UART_SERIALBUS             UartSerialBus;
566     AML_RESOURCE_COMMON_SERIALBUS           CommonSerialBus;
567 
568     /* Utility overlays */
569 
570     AML_RESOURCE_ADDRESS                    Address;
571     UINT32                                  DwordItem;
572     UINT16                                  WordItem;
573     UINT8                                   ByteItem;
574 
575 } AML_RESOURCE;
576 
577 #endif
578