xref: /openbmc/linux/drivers/acpi/acpica/amlresrc.h (revision afb46f79)
1 /******************************************************************************
2  *
3  * Module Name: amlresrc.h - AML resource descriptors
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2014, 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:struct_defs -- for acpisrc conversion */
45 
46 #ifndef __AMLRESRC_H
47 #define __AMLRESRC_H
48 
49 /*
50  * Resource descriptor tags, as defined in the ACPI specification.
51  * Used to symbolically reference fields within a descriptor.
52  */
53 #define ACPI_RESTAG_ADDRESS                     "_ADR"
54 #define ACPI_RESTAG_ALIGNMENT                   "_ALN"
55 #define ACPI_RESTAG_ADDRESSSPACE                "_ASI"
56 #define ACPI_RESTAG_ACCESSSIZE                  "_ASZ"
57 #define ACPI_RESTAG_TYPESPECIFICATTRIBUTES      "_ATT"
58 #define ACPI_RESTAG_BASEADDRESS                 "_BAS"
59 #define ACPI_RESTAG_BUSMASTER                   "_BM_"	/* Master(1), Slave(0) */
60 #define ACPI_RESTAG_DEBOUNCETIME                "_DBT"
61 #define ACPI_RESTAG_DECODE                      "_DEC"
62 #define ACPI_RESTAG_DEVICEPOLARITY              "_DPL"
63 #define ACPI_RESTAG_DMA                         "_DMA"
64 #define ACPI_RESTAG_DMATYPE                     "_TYP"	/* Compatible(0), A(1), B(2), F(3) */
65 #define ACPI_RESTAG_DRIVESTRENGTH               "_DRS"
66 #define ACPI_RESTAG_ENDIANNESS                  "_END"
67 #define ACPI_RESTAG_FLOWCONTROL                 "_FLC"
68 #define ACPI_RESTAG_GRANULARITY                 "_GRA"
69 #define ACPI_RESTAG_INTERRUPT                   "_INT"
70 #define ACPI_RESTAG_INTERRUPTLEVEL              "_LL_"	/* active_lo(1), active_hi(0) */
71 #define ACPI_RESTAG_INTERRUPTSHARE              "_SHR"	/* Shareable(1), no_share(0) */
72 #define ACPI_RESTAG_INTERRUPTTYPE               "_HE_"	/* Edge(1), Level(0) */
73 #define ACPI_RESTAG_IORESTRICTION               "_IOR"
74 #define ACPI_RESTAG_LENGTH                      "_LEN"
75 #define ACPI_RESTAG_LINE                        "_LIN"
76 #define ACPI_RESTAG_MEMATTRIBUTES               "_MTP"	/* Memory(0), Reserved(1), ACPI(2), NVS(3) */
77 #define ACPI_RESTAG_MEMTYPE                     "_MEM"	/* non_cache(0), Cacheable(1) Cache+combine(2), Cache+prefetch(3) */
78 #define ACPI_RESTAG_MAXADDR                     "_MAX"
79 #define ACPI_RESTAG_MINADDR                     "_MIN"
80 #define ACPI_RESTAG_MAXTYPE                     "_MAF"
81 #define ACPI_RESTAG_MINTYPE                     "_MIF"
82 #define ACPI_RESTAG_MODE                        "_MOD"
83 #define ACPI_RESTAG_PARITY                      "_PAR"
84 #define ACPI_RESTAG_PHASE                       "_PHA"
85 #define ACPI_RESTAG_PIN                         "_PIN"
86 #define ACPI_RESTAG_PINCONFIG                   "_PPI"
87 #define ACPI_RESTAG_POLARITY                    "_POL"
88 #define ACPI_RESTAG_REGISTERBITOFFSET           "_RBO"
89 #define ACPI_RESTAG_REGISTERBITWIDTH            "_RBW"
90 #define ACPI_RESTAG_RANGETYPE                   "_RNG"
91 #define ACPI_RESTAG_READWRITETYPE               "_RW_"	/* read_only(0), Writeable (1) */
92 #define ACPI_RESTAG_LENGTH_RX                   "_RXL"
93 #define ACPI_RESTAG_LENGTH_TX                   "_TXL"
94 #define ACPI_RESTAG_SLAVEMODE                   "_SLV"
95 #define ACPI_RESTAG_SPEED                       "_SPE"
96 #define ACPI_RESTAG_STOPBITS                    "_STB"
97 #define ACPI_RESTAG_TRANSLATION                 "_TRA"
98 #define ACPI_RESTAG_TRANSTYPE                   "_TRS"	/* Sparse(1), Dense(0) */
99 #define ACPI_RESTAG_TYPE                        "_TTP"	/* Translation(1), Static (0) */
100 #define ACPI_RESTAG_XFERTYPE                    "_SIZ"	/* 8(0), 8And16(1), 16(2) */
101 #define ACPI_RESTAG_VENDORDATA                  "_VEN"
102 
103 /* Default sizes for "small" resource descriptors */
104 
105 #define ASL_RDESC_IRQ_SIZE                      0x02
106 #define ASL_RDESC_DMA_SIZE                      0x02
107 #define ASL_RDESC_ST_DEPEND_SIZE                0x00
108 #define ASL_RDESC_END_DEPEND_SIZE               0x00
109 #define ASL_RDESC_IO_SIZE                       0x07
110 #define ASL_RDESC_FIXED_IO_SIZE                 0x03
111 #define ASL_RDESC_FIXED_DMA_SIZE                0x05
112 #define ASL_RDESC_END_TAG_SIZE                  0x01
113 
114 struct asl_resource_node {
115 	u32 buffer_length;
116 	void *buffer;
117 	struct asl_resource_node *next;
118 };
119 
120 /* Macros used to generate AML resource length fields */
121 
122 #define ACPI_AML_SIZE_LARGE(r)      (sizeof (r) - sizeof (struct aml_resource_large_header))
123 #define ACPI_AML_SIZE_SMALL(r)      (sizeof (r) - sizeof (struct aml_resource_small_header))
124 
125 /*
126  * Resource descriptors defined in the ACPI specification.
127  *
128  * Packing/alignment must be BYTE because these descriptors
129  * are used to overlay the raw AML byte stream.
130  */
131 #pragma pack(1)
132 
133 /*
134  * SMALL descriptors
135  */
136 #define AML_RESOURCE_SMALL_HEADER_COMMON \
137 	u8                              descriptor_type;
138 
139 struct aml_resource_small_header {
140 AML_RESOURCE_SMALL_HEADER_COMMON};
141 
142 struct aml_resource_irq {
143 	AML_RESOURCE_SMALL_HEADER_COMMON u16 irq_mask;
144 	u8 flags;
145 };
146 
147 struct aml_resource_irq_noflags {
148 	AML_RESOURCE_SMALL_HEADER_COMMON u16 irq_mask;
149 };
150 
151 struct aml_resource_dma {
152 	AML_RESOURCE_SMALL_HEADER_COMMON u8 dma_channel_mask;
153 	u8 flags;
154 };
155 
156 struct aml_resource_start_dependent {
157 	AML_RESOURCE_SMALL_HEADER_COMMON u8 flags;
158 };
159 
160 struct aml_resource_start_dependent_noprio {
161 AML_RESOURCE_SMALL_HEADER_COMMON};
162 
163 struct aml_resource_end_dependent {
164 AML_RESOURCE_SMALL_HEADER_COMMON};
165 
166 struct aml_resource_io {
167 	AML_RESOURCE_SMALL_HEADER_COMMON u8 flags;
168 	u16 minimum;
169 	u16 maximum;
170 	u8 alignment;
171 	u8 address_length;
172 };
173 
174 struct aml_resource_fixed_io {
175 	AML_RESOURCE_SMALL_HEADER_COMMON u16 address;
176 	u8 address_length;
177 };
178 
179 struct aml_resource_vendor_small {
180 AML_RESOURCE_SMALL_HEADER_COMMON};
181 
182 struct aml_resource_end_tag {
183 	AML_RESOURCE_SMALL_HEADER_COMMON u8 checksum;
184 };
185 
186 struct aml_resource_fixed_dma {
187 	AML_RESOURCE_SMALL_HEADER_COMMON u16 request_lines;
188 	u16 channels;
189 	u8 width;
190 };
191 
192 /*
193  * LARGE descriptors
194  */
195 #define AML_RESOURCE_LARGE_HEADER_COMMON \
196 	u8                              descriptor_type;\
197 	u16                             resource_length;
198 
199 struct aml_resource_large_header {
200 AML_RESOURCE_LARGE_HEADER_COMMON};
201 
202 /* General Flags for address space resource descriptors */
203 
204 #define ACPI_RESOURCE_FLAG_DEC      2
205 #define ACPI_RESOURCE_FLAG_MIF      4
206 #define ACPI_RESOURCE_FLAG_MAF      8
207 
208 struct aml_resource_memory24 {
209 	AML_RESOURCE_LARGE_HEADER_COMMON u8 flags;
210 	u16 minimum;
211 	u16 maximum;
212 	u16 alignment;
213 	u16 address_length;
214 };
215 
216 struct aml_resource_vendor_large {
217 AML_RESOURCE_LARGE_HEADER_COMMON};
218 
219 struct aml_resource_memory32 {
220 	AML_RESOURCE_LARGE_HEADER_COMMON u8 flags;
221 	u32 minimum;
222 	u32 maximum;
223 	u32 alignment;
224 	u32 address_length;
225 };
226 
227 struct aml_resource_fixed_memory32 {
228 	AML_RESOURCE_LARGE_HEADER_COMMON u8 flags;
229 	u32 address;
230 	u32 address_length;
231 };
232 
233 #define AML_RESOURCE_ADDRESS_COMMON \
234 	u8                              resource_type; \
235 	u8                              flags; \
236 	u8                              specific_flags;
237 
238 struct aml_resource_address {
239 AML_RESOURCE_LARGE_HEADER_COMMON AML_RESOURCE_ADDRESS_COMMON};
240 
241 struct aml_resource_extended_address64 {
242 	AML_RESOURCE_LARGE_HEADER_COMMON
243 	    AML_RESOURCE_ADDRESS_COMMON u8 revision_ID;
244 	u8 reserved;
245 	u64 granularity;
246 	u64 minimum;
247 	u64 maximum;
248 	u64 translation_offset;
249 	u64 address_length;
250 	u64 type_specific;
251 };
252 
253 #define AML_RESOURCE_EXTENDED_ADDRESS_REVISION          1	/* ACPI 3.0 */
254 
255 struct aml_resource_address64 {
256 	AML_RESOURCE_LARGE_HEADER_COMMON
257 	    AML_RESOURCE_ADDRESS_COMMON u64 granularity;
258 	u64 minimum;
259 	u64 maximum;
260 	u64 translation_offset;
261 	u64 address_length;
262 };
263 
264 struct aml_resource_address32 {
265 	AML_RESOURCE_LARGE_HEADER_COMMON
266 	    AML_RESOURCE_ADDRESS_COMMON u32 granularity;
267 	u32 minimum;
268 	u32 maximum;
269 	u32 translation_offset;
270 	u32 address_length;
271 };
272 
273 struct aml_resource_address16 {
274 	AML_RESOURCE_LARGE_HEADER_COMMON
275 	    AML_RESOURCE_ADDRESS_COMMON u16 granularity;
276 	u16 minimum;
277 	u16 maximum;
278 	u16 translation_offset;
279 	u16 address_length;
280 };
281 
282 struct aml_resource_extended_irq {
283 	AML_RESOURCE_LARGE_HEADER_COMMON u8 flags;
284 	u8 interrupt_count;
285 	u32 interrupts[1];
286 	/* res_source_index, res_source optional fields follow */
287 };
288 
289 struct aml_resource_generic_register {
290 	AML_RESOURCE_LARGE_HEADER_COMMON u8 address_space_id;
291 	u8 bit_width;
292 	u8 bit_offset;
293 	u8 access_size;		/* ACPI 3.0, was previously Reserved */
294 	u64 address;
295 };
296 
297 /* Common descriptor for gpio_int and gpio_io (ACPI 5.0) */
298 
299 struct aml_resource_gpio {
300 	AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id;
301 	u8 connection_type;
302 	u16 flags;
303 	u16 int_flags;
304 	u8 pin_config;
305 	u16 drive_strength;
306 	u16 debounce_timeout;
307 	u16 pin_table_offset;
308 	u8 res_source_index;
309 	u16 res_source_offset;
310 	u16 vendor_offset;
311 	u16 vendor_length;
312 	/*
313 	 * Optional fields follow immediately:
314 	 * 1) PIN list (Words)
315 	 * 2) Resource Source String
316 	 * 3) Vendor Data bytes
317 	 */
318 };
319 
320 #define AML_RESOURCE_GPIO_REVISION              1	/* ACPI 5.0 */
321 
322 /* Values for connection_type above */
323 
324 #define AML_RESOURCE_GPIO_TYPE_INT              0
325 #define AML_RESOURCE_GPIO_TYPE_IO               1
326 #define AML_RESOURCE_MAX_GPIOTYPE               1
327 
328 /* Common preamble for all serial descriptors (ACPI 5.0) */
329 
330 #define AML_RESOURCE_SERIAL_COMMON \
331 	u8                              revision_id; \
332 	u8                              res_source_index; \
333 	u8                              type; \
334 	u8                              flags; \
335 	u16                             type_specific_flags; \
336 	u8                              type_revision_id; \
337 	u16                             type_data_length; \
338 
339 /* Values for the type field above */
340 
341 #define AML_RESOURCE_I2C_SERIALBUSTYPE          1
342 #define AML_RESOURCE_SPI_SERIALBUSTYPE          2
343 #define AML_RESOURCE_UART_SERIALBUSTYPE         3
344 #define AML_RESOURCE_MAX_SERIALBUSTYPE          3
345 #define AML_RESOURCE_VENDOR_SERIALBUSTYPE       192	/* Vendor defined is 0xC0-0xFF (NOT SUPPORTED) */
346 
347 struct aml_resource_common_serialbus {
348 AML_RESOURCE_LARGE_HEADER_COMMON AML_RESOURCE_SERIAL_COMMON};
349 
350 struct aml_resource_i2c_serialbus {
351 	AML_RESOURCE_LARGE_HEADER_COMMON
352 	    AML_RESOURCE_SERIAL_COMMON u32 connection_speed;
353 	u16 slave_address;
354 	/*
355 	 * Optional fields follow immediately:
356 	 * 1) Vendor Data bytes
357 	 * 2) Resource Source String
358 	 */
359 };
360 
361 #define AML_RESOURCE_I2C_REVISION               1	/* ACPI 5.0 */
362 #define AML_RESOURCE_I2C_TYPE_REVISION          1	/* ACPI 5.0 */
363 #define AML_RESOURCE_I2C_MIN_DATA_LEN           6
364 
365 struct aml_resource_spi_serialbus {
366 	AML_RESOURCE_LARGE_HEADER_COMMON
367 	    AML_RESOURCE_SERIAL_COMMON u32 connection_speed;
368 	u8 data_bit_length;
369 	u8 clock_phase;
370 	u8 clock_polarity;
371 	u16 device_selection;
372 	/*
373 	 * Optional fields follow immediately:
374 	 * 1) Vendor Data bytes
375 	 * 2) Resource Source String
376 	 */
377 };
378 
379 #define AML_RESOURCE_SPI_REVISION               1	/* ACPI 5.0 */
380 #define AML_RESOURCE_SPI_TYPE_REVISION          1	/* ACPI 5.0 */
381 #define AML_RESOURCE_SPI_MIN_DATA_LEN           9
382 
383 struct aml_resource_uart_serialbus {
384 	AML_RESOURCE_LARGE_HEADER_COMMON
385 	    AML_RESOURCE_SERIAL_COMMON u32 default_baud_rate;
386 	u16 rx_fifo_size;
387 	u16 tx_fifo_size;
388 	u8 parity;
389 	u8 lines_enabled;
390 	/*
391 	 * Optional fields follow immediately:
392 	 * 1) Vendor Data bytes
393 	 * 2) Resource Source String
394 	 */
395 };
396 
397 #define AML_RESOURCE_UART_REVISION              1	/* ACPI 5.0 */
398 #define AML_RESOURCE_UART_TYPE_REVISION         1	/* ACPI 5.0 */
399 #define AML_RESOURCE_UART_MIN_DATA_LEN          10
400 
401 /* restore default alignment */
402 
403 #pragma pack()
404 
405 /* Union of all resource descriptors, so we can allocate the worst case */
406 
407 union aml_resource {
408 	/* Descriptor headers */
409 
410 	u8 descriptor_type;
411 	struct aml_resource_small_header small_header;
412 	struct aml_resource_large_header large_header;
413 
414 	/* Small resource descriptors */
415 
416 	struct aml_resource_irq irq;
417 	struct aml_resource_dma dma;
418 	struct aml_resource_start_dependent start_dpf;
419 	struct aml_resource_end_dependent end_dpf;
420 	struct aml_resource_io io;
421 	struct aml_resource_fixed_io fixed_io;
422 	struct aml_resource_fixed_dma fixed_dma;
423 	struct aml_resource_vendor_small vendor_small;
424 	struct aml_resource_end_tag end_tag;
425 
426 	/* Large resource descriptors */
427 
428 	struct aml_resource_memory24 memory24;
429 	struct aml_resource_generic_register generic_reg;
430 	struct aml_resource_vendor_large vendor_large;
431 	struct aml_resource_memory32 memory32;
432 	struct aml_resource_fixed_memory32 fixed_memory32;
433 	struct aml_resource_address16 address16;
434 	struct aml_resource_address32 address32;
435 	struct aml_resource_address64 address64;
436 	struct aml_resource_extended_address64 ext_address64;
437 	struct aml_resource_extended_irq extended_irq;
438 	struct aml_resource_gpio gpio;
439 	struct aml_resource_i2c_serialbus i2c_serial_bus;
440 	struct aml_resource_spi_serialbus spi_serial_bus;
441 	struct aml_resource_uart_serialbus uart_serial_bus;
442 	struct aml_resource_common_serialbus common_serial_bus;
443 
444 	/* Utility overlays */
445 
446 	struct aml_resource_address address;
447 	u32 dword_item;
448 	u16 word_item;
449 	u8 byte_item;
450 };
451 
452 #endif
453