xref: /openbmc/linux/drivers/acpi/acpica/amlresrc.h (revision 2b72693066a867ac073a657e871bb64391b4ffdb)
1 /******************************************************************************
2  *
3  * Module Name: amlresrc.h - AML resource descriptors
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2017, 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_FUNCTION                    "_FUN"
69 #define ACPI_RESTAG_GRANULARITY                 "_GRA"
70 #define ACPI_RESTAG_INTERRUPT                   "_INT"
71 #define ACPI_RESTAG_INTERRUPTLEVEL              "_LL_"	/* active_lo(1), active_hi(0) */
72 #define ACPI_RESTAG_INTERRUPTSHARE              "_SHR"	/* Shareable(1), no_share(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"	/* non_cache(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_"	/* read_only(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 /* Default sizes for "small" resource descriptors */
105 
106 #define ASL_RDESC_IRQ_SIZE                      0x02
107 #define ASL_RDESC_DMA_SIZE                      0x02
108 #define ASL_RDESC_ST_DEPEND_SIZE                0x00
109 #define ASL_RDESC_END_DEPEND_SIZE               0x00
110 #define ASL_RDESC_IO_SIZE                       0x07
111 #define ASL_RDESC_FIXED_IO_SIZE                 0x03
112 #define ASL_RDESC_FIXED_DMA_SIZE                0x05
113 #define ASL_RDESC_END_TAG_SIZE                  0x01
114 
115 struct asl_resource_node {
116 	u32 buffer_length;
117 	void *buffer;
118 	struct asl_resource_node *next;
119 };
120 
121 struct asl_resource_info {
122 	union acpi_parse_object *descriptor_type_op;	/* Resource descriptor parse node */
123 	union acpi_parse_object *mapping_op;	/* Used for mapfile support */
124 	u32 current_byte_offset;	/* Offset in resource template */
125 };
126 
127 /* Macros used to generate AML resource length fields */
128 
129 #define ACPI_AML_SIZE_LARGE(r)      (sizeof (r) - sizeof (struct aml_resource_large_header))
130 #define ACPI_AML_SIZE_SMALL(r)      (sizeof (r) - sizeof (struct aml_resource_small_header))
131 
132 /*
133  * Resource descriptors defined in the ACPI specification.
134  *
135  * Packing/alignment must be BYTE because these descriptors
136  * are used to overlay the raw AML byte stream.
137  */
138 #pragma pack(1)
139 
140 /*
141  * SMALL descriptors
142  */
143 #define AML_RESOURCE_SMALL_HEADER_COMMON \
144 	u8                              descriptor_type;
145 
146 struct aml_resource_small_header {
147 AML_RESOURCE_SMALL_HEADER_COMMON};
148 
149 struct aml_resource_irq {
150 	AML_RESOURCE_SMALL_HEADER_COMMON u16 irq_mask;
151 	u8 flags;
152 };
153 
154 struct aml_resource_irq_noflags {
155 	AML_RESOURCE_SMALL_HEADER_COMMON u16 irq_mask;
156 };
157 
158 struct aml_resource_dma {
159 	AML_RESOURCE_SMALL_HEADER_COMMON u8 dma_channel_mask;
160 	u8 flags;
161 };
162 
163 struct aml_resource_start_dependent {
164 	AML_RESOURCE_SMALL_HEADER_COMMON u8 flags;
165 };
166 
167 struct aml_resource_start_dependent_noprio {
168 AML_RESOURCE_SMALL_HEADER_COMMON};
169 
170 struct aml_resource_end_dependent {
171 AML_RESOURCE_SMALL_HEADER_COMMON};
172 
173 struct aml_resource_io {
174 	AML_RESOURCE_SMALL_HEADER_COMMON u8 flags;
175 	u16 minimum;
176 	u16 maximum;
177 	u8 alignment;
178 	u8 address_length;
179 };
180 
181 struct aml_resource_fixed_io {
182 	AML_RESOURCE_SMALL_HEADER_COMMON u16 address;
183 	u8 address_length;
184 };
185 
186 struct aml_resource_vendor_small {
187 AML_RESOURCE_SMALL_HEADER_COMMON};
188 
189 struct aml_resource_end_tag {
190 	AML_RESOURCE_SMALL_HEADER_COMMON u8 checksum;
191 };
192 
193 struct aml_resource_fixed_dma {
194 	AML_RESOURCE_SMALL_HEADER_COMMON u16 request_lines;
195 	u16 channels;
196 	u8 width;
197 };
198 
199 /*
200  * LARGE descriptors
201  */
202 #define AML_RESOURCE_LARGE_HEADER_COMMON \
203 	u8                              descriptor_type;\
204 	u16                             resource_length;
205 
206 struct aml_resource_large_header {
207 AML_RESOURCE_LARGE_HEADER_COMMON};
208 
209 /* General Flags for address space resource descriptors */
210 
211 #define ACPI_RESOURCE_FLAG_DEC      2
212 #define ACPI_RESOURCE_FLAG_MIF      4
213 #define ACPI_RESOURCE_FLAG_MAF      8
214 
215 struct aml_resource_memory24 {
216 	AML_RESOURCE_LARGE_HEADER_COMMON u8 flags;
217 	u16 minimum;
218 	u16 maximum;
219 	u16 alignment;
220 	u16 address_length;
221 };
222 
223 struct aml_resource_vendor_large {
224 AML_RESOURCE_LARGE_HEADER_COMMON};
225 
226 struct aml_resource_memory32 {
227 	AML_RESOURCE_LARGE_HEADER_COMMON u8 flags;
228 	u32 minimum;
229 	u32 maximum;
230 	u32 alignment;
231 	u32 address_length;
232 };
233 
234 struct aml_resource_fixed_memory32 {
235 	AML_RESOURCE_LARGE_HEADER_COMMON u8 flags;
236 	u32 address;
237 	u32 address_length;
238 };
239 
240 #define AML_RESOURCE_ADDRESS_COMMON \
241 	u8                              resource_type; \
242 	u8                              flags; \
243 	u8                              specific_flags;
244 
245 struct aml_resource_address {
246 AML_RESOURCE_LARGE_HEADER_COMMON AML_RESOURCE_ADDRESS_COMMON};
247 
248 struct aml_resource_extended_address64 {
249 	AML_RESOURCE_LARGE_HEADER_COMMON
250 	    AML_RESOURCE_ADDRESS_COMMON u8 revision_ID;
251 	u8 reserved;
252 	u64 granularity;
253 	u64 minimum;
254 	u64 maximum;
255 	u64 translation_offset;
256 	u64 address_length;
257 	u64 type_specific;
258 };
259 
260 #define AML_RESOURCE_EXTENDED_ADDRESS_REVISION          1	/* ACPI 3.0 */
261 
262 struct aml_resource_address64 {
263 	AML_RESOURCE_LARGE_HEADER_COMMON
264 	    AML_RESOURCE_ADDRESS_COMMON u64 granularity;
265 	u64 minimum;
266 	u64 maximum;
267 	u64 translation_offset;
268 	u64 address_length;
269 };
270 
271 struct aml_resource_address32 {
272 	AML_RESOURCE_LARGE_HEADER_COMMON
273 	    AML_RESOURCE_ADDRESS_COMMON u32 granularity;
274 	u32 minimum;
275 	u32 maximum;
276 	u32 translation_offset;
277 	u32 address_length;
278 };
279 
280 struct aml_resource_address16 {
281 	AML_RESOURCE_LARGE_HEADER_COMMON
282 	    AML_RESOURCE_ADDRESS_COMMON u16 granularity;
283 	u16 minimum;
284 	u16 maximum;
285 	u16 translation_offset;
286 	u16 address_length;
287 };
288 
289 struct aml_resource_extended_irq {
290 	AML_RESOURCE_LARGE_HEADER_COMMON u8 flags;
291 	u8 interrupt_count;
292 	u32 interrupts[1];
293 	/* res_source_index, res_source optional fields follow */
294 };
295 
296 struct aml_resource_generic_register {
297 	AML_RESOURCE_LARGE_HEADER_COMMON u8 address_space_id;
298 	u8 bit_width;
299 	u8 bit_offset;
300 	u8 access_size;		/* ACPI 3.0, was previously Reserved */
301 	u64 address;
302 };
303 
304 /* Common descriptor for gpio_int and gpio_io (ACPI 5.0) */
305 
306 struct aml_resource_gpio {
307 	AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id;
308 	u8 connection_type;
309 	u16 flags;
310 	u16 int_flags;
311 	u8 pin_config;
312 	u16 drive_strength;
313 	u16 debounce_timeout;
314 	u16 pin_table_offset;
315 	u8 res_source_index;
316 	u16 res_source_offset;
317 	u16 vendor_offset;
318 	u16 vendor_length;
319 	/*
320 	 * Optional fields follow immediately:
321 	 * 1) PIN list (Words)
322 	 * 2) Resource Source String
323 	 * 3) Vendor Data bytes
324 	 */
325 };
326 
327 #define AML_RESOURCE_GPIO_REVISION              1	/* ACPI 5.0 */
328 
329 /* Values for connection_type above */
330 
331 #define AML_RESOURCE_GPIO_TYPE_INT              0
332 #define AML_RESOURCE_GPIO_TYPE_IO               1
333 #define AML_RESOURCE_MAX_GPIOTYPE               1
334 
335 /* Common preamble for all serial descriptors (ACPI 5.0) */
336 
337 #define AML_RESOURCE_SERIAL_COMMON \
338 	u8                              revision_id; \
339 	u8                              res_source_index; \
340 	u8                              type; \
341 	u8                              flags; \
342 	u16                             type_specific_flags; \
343 	u8                              type_revision_id; \
344 	u16                             type_data_length; \
345 
346 /* Values for the type field above */
347 
348 #define AML_RESOURCE_I2C_SERIALBUSTYPE          1
349 #define AML_RESOURCE_SPI_SERIALBUSTYPE          2
350 #define AML_RESOURCE_UART_SERIALBUSTYPE         3
351 #define AML_RESOURCE_MAX_SERIALBUSTYPE          3
352 #define AML_RESOURCE_VENDOR_SERIALBUSTYPE       192	/* Vendor defined is 0xC0-0xFF (NOT SUPPORTED) */
353 
354 struct aml_resource_common_serialbus {
355 AML_RESOURCE_LARGE_HEADER_COMMON AML_RESOURCE_SERIAL_COMMON};
356 
357 struct aml_resource_i2c_serialbus {
358 	AML_RESOURCE_LARGE_HEADER_COMMON
359 	    AML_RESOURCE_SERIAL_COMMON u32 connection_speed;
360 	u16 slave_address;
361 	/*
362 	 * Optional fields follow immediately:
363 	 * 1) Vendor Data bytes
364 	 * 2) Resource Source String
365 	 */
366 };
367 
368 #define AML_RESOURCE_I2C_REVISION               1	/* ACPI 5.0 */
369 #define AML_RESOURCE_I2C_TYPE_REVISION          1	/* ACPI 5.0 */
370 #define AML_RESOURCE_I2C_MIN_DATA_LEN           6
371 
372 struct aml_resource_spi_serialbus {
373 	AML_RESOURCE_LARGE_HEADER_COMMON
374 	    AML_RESOURCE_SERIAL_COMMON u32 connection_speed;
375 	u8 data_bit_length;
376 	u8 clock_phase;
377 	u8 clock_polarity;
378 	u16 device_selection;
379 	/*
380 	 * Optional fields follow immediately:
381 	 * 1) Vendor Data bytes
382 	 * 2) Resource Source String
383 	 */
384 };
385 
386 #define AML_RESOURCE_SPI_REVISION               1	/* ACPI 5.0 */
387 #define AML_RESOURCE_SPI_TYPE_REVISION          1	/* ACPI 5.0 */
388 #define AML_RESOURCE_SPI_MIN_DATA_LEN           9
389 
390 struct aml_resource_uart_serialbus {
391 	AML_RESOURCE_LARGE_HEADER_COMMON
392 	    AML_RESOURCE_SERIAL_COMMON u32 default_baud_rate;
393 	u16 rx_fifo_size;
394 	u16 tx_fifo_size;
395 	u8 parity;
396 	u8 lines_enabled;
397 	/*
398 	 * Optional fields follow immediately:
399 	 * 1) Vendor Data bytes
400 	 * 2) Resource Source String
401 	 */
402 };
403 
404 #define AML_RESOURCE_UART_REVISION              1	/* ACPI 5.0 */
405 #define AML_RESOURCE_UART_TYPE_REVISION         1	/* ACPI 5.0 */
406 #define AML_RESOURCE_UART_MIN_DATA_LEN          10
407 
408 struct aml_resource_pin_function {
409 	AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id;
410 	u16 flags;
411 	u8 pin_config;
412 	u16 function_number;
413 	u16 pin_table_offset;
414 	u8 res_source_index;
415 	u16 res_source_offset;
416 	u16 vendor_offset;
417 	u16 vendor_length;
418 	/*
419 	 * Optional fields follow immediately:
420 	 * 1) PIN list (Words)
421 	 * 2) Resource Source String
422 	 * 3) Vendor Data bytes
423 	 */
424 };
425 
426 #define AML_RESOURCE_PIN_FUNCTION_REVISION      1	/* ACPI 6.2 */
427 
428 /* restore default alignment */
429 
430 #pragma pack()
431 
432 /* Union of all resource descriptors, so we can allocate the worst case */
433 
434 union aml_resource {
435 	/* Descriptor headers */
436 
437 	u8 descriptor_type;
438 	struct aml_resource_small_header small_header;
439 	struct aml_resource_large_header large_header;
440 
441 	/* Small resource descriptors */
442 
443 	struct aml_resource_irq irq;
444 	struct aml_resource_dma dma;
445 	struct aml_resource_start_dependent start_dpf;
446 	struct aml_resource_end_dependent end_dpf;
447 	struct aml_resource_io io;
448 	struct aml_resource_fixed_io fixed_io;
449 	struct aml_resource_fixed_dma fixed_dma;
450 	struct aml_resource_vendor_small vendor_small;
451 	struct aml_resource_end_tag end_tag;
452 
453 	/* Large resource descriptors */
454 
455 	struct aml_resource_memory24 memory24;
456 	struct aml_resource_generic_register generic_reg;
457 	struct aml_resource_vendor_large vendor_large;
458 	struct aml_resource_memory32 memory32;
459 	struct aml_resource_fixed_memory32 fixed_memory32;
460 	struct aml_resource_address16 address16;
461 	struct aml_resource_address32 address32;
462 	struct aml_resource_address64 address64;
463 	struct aml_resource_extended_address64 ext_address64;
464 	struct aml_resource_extended_irq extended_irq;
465 	struct aml_resource_gpio gpio;
466 	struct aml_resource_i2c_serialbus i2c_serial_bus;
467 	struct aml_resource_spi_serialbus spi_serial_bus;
468 	struct aml_resource_uart_serialbus uart_serial_bus;
469 	struct aml_resource_common_serialbus common_serial_bus;
470 	struct aml_resource_pin_function pin_function;
471 
472 	/* Utility overlays */
473 
474 	struct aml_resource_address address;
475 	u32 dword_item;
476 	u16 word_item;
477 	u8 byte_item;
478 };
479 
480 /* Interfaces used by both the disassembler and compiler */
481 
482 void
483 mp_save_gpio_info(union acpi_parse_object *op,
484 		  union aml_resource *resource,
485 		  u32 pin_count, u16 *pin_list, char *device_name);
486 
487 void
488 mp_save_serial_info(union acpi_parse_object *op,
489 		    union aml_resource *resource, char *device_name);
490 
491 char *mp_get_hid_from_parse_tree(struct acpi_namespace_node *hid_node);
492 
493 char *mp_get_hid_via_namestring(char *device_name);
494 
495 char *mp_get_connection_info(union acpi_parse_object *op,
496 			     u32 pin_index,
497 			     struct acpi_namespace_node **target_node,
498 			     char **target_name);
499 
500 char *mp_get_parent_device_hid(union acpi_parse_object *op,
501 			       struct acpi_namespace_node **target_node,
502 			       char **parent_device_name);
503 
504 char *mp_get_ddn_value(char *device_name);
505 
506 char *mp_get_hid_value(struct acpi_namespace_node *device_node);
507 
508 #endif
509