xref: /openbmc/linux/drivers/acpi/acpica/amlresrc.h (revision f80be457)
1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /******************************************************************************
3  *
4  * Module Name: amlresrc.h - AML resource descriptors
5  *
6  * Copyright (C) 2000 - 2022, Intel Corp.
7  *
8  *****************************************************************************/
9 
10 /* acpisrc:struct_defs -- for acpisrc conversion */
11 
12 #ifndef __AMLRESRC_H
13 #define __AMLRESRC_H
14 
15 /*
16  * Resource descriptor tags, as defined in the ACPI specification.
17  * Used to symbolically reference fields within a descriptor.
18  */
19 #define ACPI_RESTAG_ADDRESS                     "_ADR"
20 #define ACPI_RESTAG_ALIGNMENT                   "_ALN"
21 #define ACPI_RESTAG_ADDRESSSPACE                "_ASI"
22 #define ACPI_RESTAG_ACCESSSIZE                  "_ASZ"
23 #define ACPI_RESTAG_TYPESPECIFICATTRIBUTES      "_ATT"
24 #define ACPI_RESTAG_BASEADDRESS                 "_BAS"
25 #define ACPI_RESTAG_BUSMASTER                   "_BM_"	/* Master(1), Slave(0) */
26 #define ACPI_RESTAG_DEBOUNCETIME                "_DBT"
27 #define ACPI_RESTAG_DECODE                      "_DEC"
28 #define ACPI_RESTAG_DEVICEPOLARITY              "_DPL"
29 #define ACPI_RESTAG_DMA                         "_DMA"
30 #define ACPI_RESTAG_DMATYPE                     "_TYP"	/* Compatible(0), A(1), B(2), F(3) */
31 #define ACPI_RESTAG_DRIVESTRENGTH               "_DRS"
32 #define ACPI_RESTAG_ENDIANNESS                  "_END"
33 #define ACPI_RESTAG_FLOWCONTROL                 "_FLC"
34 #define ACPI_RESTAG_FUNCTION                    "_FUN"
35 #define ACPI_RESTAG_GRANULARITY                 "_GRA"
36 #define ACPI_RESTAG_INTERRUPT                   "_INT"
37 #define ACPI_RESTAG_INTERRUPTLEVEL              "_LL_"	/* active_lo(1), active_hi(0) */
38 #define ACPI_RESTAG_INTERRUPTSHARE              "_SHR"	/* Shareable(1), no_share(0) */
39 #define ACPI_RESTAG_INTERRUPTTYPE               "_HE_"	/* Edge(1), Level(0) */
40 #define ACPI_RESTAG_IORESTRICTION               "_IOR"
41 #define ACPI_RESTAG_LENGTH                      "_LEN"
42 #define ACPI_RESTAG_LINE                        "_LIN"
43 #define ACPI_RESTAG_LOCALPORT                   "_PRT"
44 #define ACPI_RESTAG_MEMATTRIBUTES               "_MTP"	/* Memory(0), Reserved(1), ACPI(2), NVS(3) */
45 #define ACPI_RESTAG_MEMTYPE                     "_MEM"	/* non_cache(0), Cacheable(1) Cache+combine(2), Cache+prefetch(3) */
46 #define ACPI_RESTAG_MAXADDR                     "_MAX"
47 #define ACPI_RESTAG_MINADDR                     "_MIN"
48 #define ACPI_RESTAG_MAXTYPE                     "_MAF"
49 #define ACPI_RESTAG_MINTYPE                     "_MIF"
50 #define ACPI_RESTAG_MODE                        "_MOD"
51 #define ACPI_RESTAG_PARITY                      "_PAR"
52 #define ACPI_RESTAG_PHASE                       "_PHA"
53 #define ACPI_RESTAG_PHYTYPE                     "_PHY"
54 #define ACPI_RESTAG_PIN                         "_PIN"
55 #define ACPI_RESTAG_PINCONFIG                   "_PPI"
56 #define ACPI_RESTAG_PINCONFIG_TYPE              "_TYP"
57 #define ACPI_RESTAG_PINCONFIG_VALUE             "_VAL"
58 #define ACPI_RESTAG_POLARITY                    "_POL"
59 #define ACPI_RESTAG_REGISTERBITOFFSET           "_RBO"
60 #define ACPI_RESTAG_REGISTERBITWIDTH            "_RBW"
61 #define ACPI_RESTAG_RANGETYPE                   "_RNG"
62 #define ACPI_RESTAG_READWRITETYPE               "_RW_"	/* read_only(0), Writeable (1) */
63 #define ACPI_RESTAG_LENGTH_RX                   "_RXL"
64 #define ACPI_RESTAG_LENGTH_TX                   "_TXL"
65 #define ACPI_RESTAG_SLAVEMODE                   "_SLV"
66 #define ACPI_RESTAG_SPEED                       "_SPE"
67 #define ACPI_RESTAG_STOPBITS                    "_STB"
68 #define ACPI_RESTAG_TRANSLATION                 "_TRA"
69 #define ACPI_RESTAG_TRANSTYPE                   "_TRS"	/* Sparse(1), Dense(0) */
70 #define ACPI_RESTAG_TYPE                        "_TTP"	/* Translation(1), Static (0) */
71 #define ACPI_RESTAG_XFERTYPE                    "_SIZ"	/* 8(0), 8And16(1), 16(2) */
72 #define ACPI_RESTAG_VENDORDATA                  "_VEN"
73 
74 /* Default sizes for "small" resource descriptors */
75 
76 #define ASL_RDESC_IRQ_SIZE                      0x02
77 #define ASL_RDESC_DMA_SIZE                      0x02
78 #define ASL_RDESC_ST_DEPEND_SIZE                0x00
79 #define ASL_RDESC_END_DEPEND_SIZE               0x00
80 #define ASL_RDESC_IO_SIZE                       0x07
81 #define ASL_RDESC_FIXED_IO_SIZE                 0x03
82 #define ASL_RDESC_FIXED_DMA_SIZE                0x05
83 #define ASL_RDESC_END_TAG_SIZE                  0x01
84 
85 struct asl_resource_node {
86 	u32 buffer_length;
87 	void *buffer;
88 	struct asl_resource_node *next;
89 };
90 
91 struct asl_resource_info {
92 	union acpi_parse_object *descriptor_type_op;	/* Resource descriptor parse node */
93 	union acpi_parse_object *mapping_op;	/* Used for mapfile support */
94 	u32 current_byte_offset;	/* Offset in resource template */
95 };
96 
97 /* Macros used to generate AML resource length fields */
98 
99 #define ACPI_AML_SIZE_LARGE(r)      (sizeof (r) - sizeof (struct aml_resource_large_header))
100 #define ACPI_AML_SIZE_SMALL(r)      (sizeof (r) - sizeof (struct aml_resource_small_header))
101 
102 /*
103  * Resource descriptors defined in the ACPI specification.
104  *
105  * Packing/alignment must be BYTE because these descriptors
106  * are used to overlay the raw AML byte stream.
107  */
108 #pragma pack(1)
109 
110 /*
111  * SMALL descriptors
112  */
113 #define AML_RESOURCE_SMALL_HEADER_COMMON \
114 	u8                              descriptor_type;
115 
116 struct aml_resource_small_header {
117 AML_RESOURCE_SMALL_HEADER_COMMON};
118 
119 struct aml_resource_irq {
120 	AML_RESOURCE_SMALL_HEADER_COMMON u16 irq_mask;
121 	u8 flags;
122 };
123 
124 struct aml_resource_irq_noflags {
125 	AML_RESOURCE_SMALL_HEADER_COMMON u16 irq_mask;
126 };
127 
128 struct aml_resource_dma {
129 	AML_RESOURCE_SMALL_HEADER_COMMON u8 dma_channel_mask;
130 	u8 flags;
131 };
132 
133 struct aml_resource_start_dependent {
134 	AML_RESOURCE_SMALL_HEADER_COMMON u8 flags;
135 };
136 
137 struct aml_resource_start_dependent_noprio {
138 AML_RESOURCE_SMALL_HEADER_COMMON};
139 
140 struct aml_resource_end_dependent {
141 AML_RESOURCE_SMALL_HEADER_COMMON};
142 
143 struct aml_resource_io {
144 	AML_RESOURCE_SMALL_HEADER_COMMON u8 flags;
145 	u16 minimum;
146 	u16 maximum;
147 	u8 alignment;
148 	u8 address_length;
149 };
150 
151 struct aml_resource_fixed_io {
152 	AML_RESOURCE_SMALL_HEADER_COMMON u16 address;
153 	u8 address_length;
154 };
155 
156 struct aml_resource_vendor_small {
157 AML_RESOURCE_SMALL_HEADER_COMMON};
158 
159 struct aml_resource_end_tag {
160 	AML_RESOURCE_SMALL_HEADER_COMMON u8 checksum;
161 };
162 
163 struct aml_resource_fixed_dma {
164 	AML_RESOURCE_SMALL_HEADER_COMMON u16 request_lines;
165 	u16 channels;
166 	u8 width;
167 };
168 
169 /*
170  * LARGE descriptors
171  */
172 #define AML_RESOURCE_LARGE_HEADER_COMMON \
173 	u8                              descriptor_type;\
174 	u16                             resource_length;
175 
176 struct aml_resource_large_header {
177 AML_RESOURCE_LARGE_HEADER_COMMON};
178 
179 /* General Flags for address space resource descriptors */
180 
181 #define ACPI_RESOURCE_FLAG_DEC      2
182 #define ACPI_RESOURCE_FLAG_MIF      4
183 #define ACPI_RESOURCE_FLAG_MAF      8
184 
185 struct aml_resource_memory24 {
186 	AML_RESOURCE_LARGE_HEADER_COMMON u8 flags;
187 	u16 minimum;
188 	u16 maximum;
189 	u16 alignment;
190 	u16 address_length;
191 };
192 
193 struct aml_resource_vendor_large {
194 AML_RESOURCE_LARGE_HEADER_COMMON};
195 
196 struct aml_resource_memory32 {
197 	AML_RESOURCE_LARGE_HEADER_COMMON u8 flags;
198 	u32 minimum;
199 	u32 maximum;
200 	u32 alignment;
201 	u32 address_length;
202 };
203 
204 struct aml_resource_fixed_memory32 {
205 	AML_RESOURCE_LARGE_HEADER_COMMON u8 flags;
206 	u32 address;
207 	u32 address_length;
208 };
209 
210 #define AML_RESOURCE_ADDRESS_COMMON \
211 	u8                              resource_type; \
212 	u8                              flags; \
213 	u8                              specific_flags;
214 
215 struct aml_resource_address {
216 AML_RESOURCE_LARGE_HEADER_COMMON AML_RESOURCE_ADDRESS_COMMON};
217 
218 struct aml_resource_extended_address64 {
219 	AML_RESOURCE_LARGE_HEADER_COMMON
220 	    AML_RESOURCE_ADDRESS_COMMON u8 revision_ID;
221 	u8 reserved;
222 	u64 granularity;
223 	u64 minimum;
224 	u64 maximum;
225 	u64 translation_offset;
226 	u64 address_length;
227 	u64 type_specific;
228 };
229 
230 #define AML_RESOURCE_EXTENDED_ADDRESS_REVISION          1	/* ACPI 3.0 */
231 
232 struct aml_resource_address64 {
233 	AML_RESOURCE_LARGE_HEADER_COMMON
234 	    AML_RESOURCE_ADDRESS_COMMON u64 granularity;
235 	u64 minimum;
236 	u64 maximum;
237 	u64 translation_offset;
238 	u64 address_length;
239 };
240 
241 struct aml_resource_address32 {
242 	AML_RESOURCE_LARGE_HEADER_COMMON
243 	    AML_RESOURCE_ADDRESS_COMMON u32 granularity;
244 	u32 minimum;
245 	u32 maximum;
246 	u32 translation_offset;
247 	u32 address_length;
248 };
249 
250 struct aml_resource_address16 {
251 	AML_RESOURCE_LARGE_HEADER_COMMON
252 	    AML_RESOURCE_ADDRESS_COMMON u16 granularity;
253 	u16 minimum;
254 	u16 maximum;
255 	u16 translation_offset;
256 	u16 address_length;
257 };
258 
259 struct aml_resource_extended_irq {
260 	AML_RESOURCE_LARGE_HEADER_COMMON u8 flags;
261 	u8 interrupt_count;
262 	u32 interrupts[1];
263 	/* res_source_index, res_source optional fields follow */
264 };
265 
266 struct aml_resource_generic_register {
267 	AML_RESOURCE_LARGE_HEADER_COMMON u8 address_space_id;
268 	u8 bit_width;
269 	u8 bit_offset;
270 	u8 access_size;		/* ACPI 3.0, was previously Reserved */
271 	u64 address;
272 };
273 
274 /* Common descriptor for gpio_int and gpio_io (ACPI 5.0) */
275 
276 struct aml_resource_gpio {
277 	AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id;
278 	u8 connection_type;
279 	u16 flags;
280 	u16 int_flags;
281 	u8 pin_config;
282 	u16 drive_strength;
283 	u16 debounce_timeout;
284 	u16 pin_table_offset;
285 	u8 res_source_index;
286 	u16 res_source_offset;
287 	u16 vendor_offset;
288 	u16 vendor_length;
289 	/*
290 	 * Optional fields follow immediately:
291 	 * 1) PIN list (Words)
292 	 * 2) Resource Source String
293 	 * 3) Vendor Data bytes
294 	 */
295 };
296 
297 #define AML_RESOURCE_GPIO_REVISION              1	/* ACPI 5.0 */
298 
299 /* Values for connection_type above */
300 
301 #define AML_RESOURCE_GPIO_TYPE_INT              0
302 #define AML_RESOURCE_GPIO_TYPE_IO               1
303 #define AML_RESOURCE_MAX_GPIOTYPE               1
304 
305 /* Common preamble for all serial descriptors (ACPI 5.0) */
306 
307 #define AML_RESOURCE_SERIAL_COMMON \
308 	u8                              revision_id; \
309 	u8                              res_source_index; \
310 	u8                              type; \
311 	u8                              flags; \
312 	u16                             type_specific_flags; \
313 	u8                              type_revision_id; \
314 	u16                             type_data_length; \
315 
316 /* Values for the type field above */
317 
318 #define AML_RESOURCE_I2C_SERIALBUSTYPE          1
319 #define AML_RESOURCE_SPI_SERIALBUSTYPE          2
320 #define AML_RESOURCE_UART_SERIALBUSTYPE         3
321 #define AML_RESOURCE_CSI2_SERIALBUSTYPE         4
322 #define AML_RESOURCE_MAX_SERIALBUSTYPE          4
323 #define AML_RESOURCE_VENDOR_SERIALBUSTYPE       192	/* Vendor defined is 0xC0-0xFF (NOT SUPPORTED) */
324 
325 struct aml_resource_common_serialbus {
326 AML_RESOURCE_LARGE_HEADER_COMMON AML_RESOURCE_SERIAL_COMMON};
327 
328 struct aml_resource_csi2_serialbus {
329 	AML_RESOURCE_LARGE_HEADER_COMMON AML_RESOURCE_SERIAL_COMMON
330 	    /*
331 	     * Optional fields follow immediately:
332 	     * 1) Vendor Data bytes
333 	     * 2) Resource Source String
334 	     */
335 };
336 
337 #define AML_RESOURCE_CSI2_REVISION              1	/* ACPI 6.4 */
338 #define AML_RESOURCE_CSI2_TYPE_REVISION         1	/* ACPI 6.4 */
339 #define AML_RESOURCE_CSI2_MIN_DATA_LEN          0	/* ACPI 6.4 */
340 
341 struct aml_resource_i2c_serialbus {
342 	AML_RESOURCE_LARGE_HEADER_COMMON
343 	    AML_RESOURCE_SERIAL_COMMON u32 connection_speed;
344 	u16 slave_address;
345 	/*
346 	 * Optional fields follow immediately:
347 	 * 1) Vendor Data bytes
348 	 * 2) Resource Source String
349 	 */
350 };
351 
352 #define AML_RESOURCE_I2C_REVISION               1	/* ACPI 5.0 */
353 #define AML_RESOURCE_I2C_TYPE_REVISION          1	/* ACPI 5.0 */
354 #define AML_RESOURCE_I2C_MIN_DATA_LEN           6
355 
356 struct aml_resource_spi_serialbus {
357 	AML_RESOURCE_LARGE_HEADER_COMMON
358 	    AML_RESOURCE_SERIAL_COMMON u32 connection_speed;
359 	u8 data_bit_length;
360 	u8 clock_phase;
361 	u8 clock_polarity;
362 	u16 device_selection;
363 	/*
364 	 * Optional fields follow immediately:
365 	 * 1) Vendor Data bytes
366 	 * 2) Resource Source String
367 	 */
368 };
369 
370 #define AML_RESOURCE_SPI_REVISION               1	/* ACPI 5.0 */
371 #define AML_RESOURCE_SPI_TYPE_REVISION          1	/* ACPI 5.0 */
372 #define AML_RESOURCE_SPI_MIN_DATA_LEN           9
373 
374 struct aml_resource_uart_serialbus {
375 	AML_RESOURCE_LARGE_HEADER_COMMON
376 	    AML_RESOURCE_SERIAL_COMMON u32 default_baud_rate;
377 	u16 rx_fifo_size;
378 	u16 tx_fifo_size;
379 	u8 parity;
380 	u8 lines_enabled;
381 	/*
382 	 * Optional fields follow immediately:
383 	 * 1) Vendor Data bytes
384 	 * 2) Resource Source String
385 	 */
386 };
387 
388 #define AML_RESOURCE_UART_REVISION              1	/* ACPI 5.0 */
389 #define AML_RESOURCE_UART_TYPE_REVISION         1	/* ACPI 5.0 */
390 #define AML_RESOURCE_UART_MIN_DATA_LEN          10
391 
392 struct aml_resource_pin_function {
393 	AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id;
394 	u16 flags;
395 	u8 pin_config;
396 	u16 function_number;
397 	u16 pin_table_offset;
398 	u8 res_source_index;
399 	u16 res_source_offset;
400 	u16 vendor_offset;
401 	u16 vendor_length;
402 	/*
403 	 * Optional fields follow immediately:
404 	 * 1) PIN list (Words)
405 	 * 2) Resource Source String
406 	 * 3) Vendor Data bytes
407 	 */
408 };
409 
410 #define AML_RESOURCE_PIN_FUNCTION_REVISION      1	/* ACPI 6.2 */
411 
412 struct aml_resource_pin_config {
413 	AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id;
414 	u16 flags;
415 	u8 pin_config_type;
416 	u32 pin_config_value;
417 	u16 pin_table_offset;
418 	u8 res_source_index;
419 	u16 res_source_offset;
420 	u16 vendor_offset;
421 	u16 vendor_length;
422 	/*
423 	 * Optional fields follow immediately:
424 	 * 1) PIN list (Words)
425 	 * 2) Resource Source String
426 	 * 3) Vendor Data bytes
427 	 */
428 };
429 
430 #define AML_RESOURCE_PIN_CONFIG_REVISION      1	/* ACPI 6.2 */
431 
432 struct aml_resource_pin_group {
433 	AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id;
434 	u16 flags;
435 	u16 pin_table_offset;
436 	u16 label_offset;
437 	u16 vendor_offset;
438 	u16 vendor_length;
439 	/*
440 	 * Optional fields follow immediately:
441 	 * 1) PIN list (Words)
442 	 * 2) Resource Label String
443 	 * 3) Vendor Data bytes
444 	 */
445 };
446 
447 #define AML_RESOURCE_PIN_GROUP_REVISION      1	/* ACPI 6.2 */
448 
449 struct aml_resource_pin_group_function {
450 	AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id;
451 	u16 flags;
452 	u16 function_number;
453 	u8 res_source_index;
454 	u16 res_source_offset;
455 	u16 res_source_label_offset;
456 	u16 vendor_offset;
457 	u16 vendor_length;
458 	/*
459 	 * Optional fields follow immediately:
460 	 * 1) Resource Source String
461 	 * 2) Resource Source Label String
462 	 * 3) Vendor Data bytes
463 	 */
464 };
465 
466 #define AML_RESOURCE_PIN_GROUP_FUNCTION_REVISION    1	/* ACPI 6.2 */
467 
468 struct aml_resource_pin_group_config {
469 	AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id;
470 	u16 flags;
471 	u8 pin_config_type;
472 	u32 pin_config_value;
473 	u8 res_source_index;
474 	u16 res_source_offset;
475 	u16 res_source_label_offset;
476 	u16 vendor_offset;
477 	u16 vendor_length;
478 	/*
479 	 * Optional fields follow immediately:
480 	 * 1) Resource Source String
481 	 * 2) Resource Source Label String
482 	 * 3) Vendor Data bytes
483 	 */
484 };
485 
486 #define AML_RESOURCE_PIN_GROUP_CONFIG_REVISION    1	/* ACPI 6.2 */
487 
488 /* restore default alignment */
489 
490 #pragma pack()
491 
492 /* Union of all resource descriptors, so we can allocate the worst case */
493 
494 union aml_resource {
495 	/* Descriptor headers */
496 
497 	u8 descriptor_type;
498 	struct aml_resource_small_header small_header;
499 	struct aml_resource_large_header large_header;
500 
501 	/* Small resource descriptors */
502 
503 	struct aml_resource_irq irq;
504 	struct aml_resource_dma dma;
505 	struct aml_resource_start_dependent start_dpf;
506 	struct aml_resource_end_dependent end_dpf;
507 	struct aml_resource_io io;
508 	struct aml_resource_fixed_io fixed_io;
509 	struct aml_resource_fixed_dma fixed_dma;
510 	struct aml_resource_vendor_small vendor_small;
511 	struct aml_resource_end_tag end_tag;
512 
513 	/* Large resource descriptors */
514 
515 	struct aml_resource_memory24 memory24;
516 	struct aml_resource_generic_register generic_reg;
517 	struct aml_resource_vendor_large vendor_large;
518 	struct aml_resource_memory32 memory32;
519 	struct aml_resource_fixed_memory32 fixed_memory32;
520 	struct aml_resource_address16 address16;
521 	struct aml_resource_address32 address32;
522 	struct aml_resource_address64 address64;
523 	struct aml_resource_extended_address64 ext_address64;
524 	struct aml_resource_extended_irq extended_irq;
525 	struct aml_resource_gpio gpio;
526 	struct aml_resource_i2c_serialbus i2c_serial_bus;
527 	struct aml_resource_spi_serialbus spi_serial_bus;
528 	struct aml_resource_uart_serialbus uart_serial_bus;
529 	struct aml_resource_csi2_serialbus csi2_serial_bus;
530 	struct aml_resource_common_serialbus common_serial_bus;
531 	struct aml_resource_pin_function pin_function;
532 	struct aml_resource_pin_config pin_config;
533 	struct aml_resource_pin_group pin_group;
534 	struct aml_resource_pin_group_function pin_group_function;
535 	struct aml_resource_pin_group_config pin_group_config;
536 
537 	/* Utility overlays */
538 
539 	struct aml_resource_address address;
540 	u32 dword_item;
541 	u16 word_item;
542 	u8 byte_item;
543 };
544 
545 /* Interfaces used by both the disassembler and compiler */
546 
547 void
548 mp_save_gpio_info(union acpi_parse_object *op,
549 		  union aml_resource *resource,
550 		  u32 pin_count, u16 *pin_list, char *device_name);
551 
552 void
553 mp_save_serial_info(union acpi_parse_object *op,
554 		    union aml_resource *resource, char *device_name);
555 
556 char *mp_get_hid_from_parse_tree(struct acpi_namespace_node *hid_node);
557 
558 char *mp_get_hid_via_namestring(char *device_name);
559 
560 char *mp_get_connection_info(union acpi_parse_object *op,
561 			     u32 pin_index,
562 			     struct acpi_namespace_node **target_node,
563 			     char **target_name);
564 
565 char *mp_get_parent_device_hid(union acpi_parse_object *op,
566 			       struct acpi_namespace_node **target_node,
567 			       char **parent_device_name);
568 
569 char *mp_get_ddn_value(char *device_name);
570 
571 char *mp_get_hid_value(struct acpi_namespace_node *device_node);
572 
573 #endif
574