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 - 2023, 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 #define ACPI_RESTAG_FQN "_FQN" 74 #define ACPI_RESTAG_FQD "_FQD" 75 76 /* Default sizes for "small" resource descriptors */ 77 78 #define ASL_RDESC_IRQ_SIZE 0x02 79 #define ASL_RDESC_DMA_SIZE 0x02 80 #define ASL_RDESC_ST_DEPEND_SIZE 0x00 81 #define ASL_RDESC_END_DEPEND_SIZE 0x00 82 #define ASL_RDESC_IO_SIZE 0x07 83 #define ASL_RDESC_FIXED_IO_SIZE 0x03 84 #define ASL_RDESC_FIXED_DMA_SIZE 0x05 85 #define ASL_RDESC_END_TAG_SIZE 0x01 86 87 struct asl_resource_node { 88 u32 buffer_length; 89 void *buffer; 90 struct asl_resource_node *next; 91 }; 92 93 struct asl_resource_info { 94 union acpi_parse_object *descriptor_type_op; /* Resource descriptor parse node */ 95 union acpi_parse_object *mapping_op; /* Used for mapfile support */ 96 u32 current_byte_offset; /* Offset in resource template */ 97 }; 98 99 /* Macros used to generate AML resource length fields */ 100 101 #define ACPI_AML_SIZE_LARGE(r) (sizeof (r) - sizeof (struct aml_resource_large_header)) 102 #define ACPI_AML_SIZE_SMALL(r) (sizeof (r) - sizeof (struct aml_resource_small_header)) 103 104 /* 105 * Resource descriptors defined in the ACPI specification. 106 * 107 * Packing/alignment must be BYTE because these descriptors 108 * are used to overlay the raw AML byte stream. 109 */ 110 #pragma pack(1) 111 112 /* 113 * SMALL descriptors 114 */ 115 #define AML_RESOURCE_SMALL_HEADER_COMMON \ 116 u8 descriptor_type; 117 118 struct aml_resource_small_header { 119 AML_RESOURCE_SMALL_HEADER_COMMON}; 120 121 struct aml_resource_irq { 122 AML_RESOURCE_SMALL_HEADER_COMMON u16 irq_mask; 123 u8 flags; 124 }; 125 126 struct aml_resource_irq_noflags { 127 AML_RESOURCE_SMALL_HEADER_COMMON u16 irq_mask; 128 }; 129 130 struct aml_resource_dma { 131 AML_RESOURCE_SMALL_HEADER_COMMON u8 dma_channel_mask; 132 u8 flags; 133 }; 134 135 struct aml_resource_start_dependent { 136 AML_RESOURCE_SMALL_HEADER_COMMON u8 flags; 137 }; 138 139 struct aml_resource_start_dependent_noprio { 140 AML_RESOURCE_SMALL_HEADER_COMMON}; 141 142 struct aml_resource_end_dependent { 143 AML_RESOURCE_SMALL_HEADER_COMMON}; 144 145 struct aml_resource_io { 146 AML_RESOURCE_SMALL_HEADER_COMMON u8 flags; 147 u16 minimum; 148 u16 maximum; 149 u8 alignment; 150 u8 address_length; 151 }; 152 153 struct aml_resource_fixed_io { 154 AML_RESOURCE_SMALL_HEADER_COMMON u16 address; 155 u8 address_length; 156 }; 157 158 struct aml_resource_vendor_small { 159 AML_RESOURCE_SMALL_HEADER_COMMON}; 160 161 struct aml_resource_end_tag { 162 AML_RESOURCE_SMALL_HEADER_COMMON u8 checksum; 163 }; 164 165 struct aml_resource_fixed_dma { 166 AML_RESOURCE_SMALL_HEADER_COMMON u16 request_lines; 167 u16 channels; 168 u8 width; 169 }; 170 171 /* 172 * LARGE descriptors 173 */ 174 #define AML_RESOURCE_LARGE_HEADER_COMMON \ 175 u8 descriptor_type;\ 176 u16 resource_length; 177 178 struct aml_resource_large_header { 179 AML_RESOURCE_LARGE_HEADER_COMMON}; 180 181 /* General Flags for address space resource descriptors */ 182 183 #define ACPI_RESOURCE_FLAG_DEC 2 184 #define ACPI_RESOURCE_FLAG_MIF 4 185 #define ACPI_RESOURCE_FLAG_MAF 8 186 187 struct aml_resource_memory24 { 188 AML_RESOURCE_LARGE_HEADER_COMMON u8 flags; 189 u16 minimum; 190 u16 maximum; 191 u16 alignment; 192 u16 address_length; 193 }; 194 195 struct aml_resource_vendor_large { 196 AML_RESOURCE_LARGE_HEADER_COMMON}; 197 198 struct aml_resource_memory32 { 199 AML_RESOURCE_LARGE_HEADER_COMMON u8 flags; 200 u32 minimum; 201 u32 maximum; 202 u32 alignment; 203 u32 address_length; 204 }; 205 206 struct aml_resource_fixed_memory32 { 207 AML_RESOURCE_LARGE_HEADER_COMMON u8 flags; 208 u32 address; 209 u32 address_length; 210 }; 211 212 #define AML_RESOURCE_ADDRESS_COMMON \ 213 u8 resource_type; \ 214 u8 flags; \ 215 u8 specific_flags; 216 217 struct aml_resource_address { 218 AML_RESOURCE_LARGE_HEADER_COMMON AML_RESOURCE_ADDRESS_COMMON}; 219 220 struct aml_resource_extended_address64 { 221 AML_RESOURCE_LARGE_HEADER_COMMON 222 AML_RESOURCE_ADDRESS_COMMON u8 revision_ID; 223 u8 reserved; 224 u64 granularity; 225 u64 minimum; 226 u64 maximum; 227 u64 translation_offset; 228 u64 address_length; 229 u64 type_specific; 230 }; 231 232 #define AML_RESOURCE_EXTENDED_ADDRESS_REVISION 1 /* ACPI 3.0 */ 233 234 struct aml_resource_address64 { 235 AML_RESOURCE_LARGE_HEADER_COMMON 236 AML_RESOURCE_ADDRESS_COMMON u64 granularity; 237 u64 minimum; 238 u64 maximum; 239 u64 translation_offset; 240 u64 address_length; 241 }; 242 243 struct aml_resource_address32 { 244 AML_RESOURCE_LARGE_HEADER_COMMON 245 AML_RESOURCE_ADDRESS_COMMON u32 granularity; 246 u32 minimum; 247 u32 maximum; 248 u32 translation_offset; 249 u32 address_length; 250 }; 251 252 struct aml_resource_address16 { 253 AML_RESOURCE_LARGE_HEADER_COMMON 254 AML_RESOURCE_ADDRESS_COMMON u16 granularity; 255 u16 minimum; 256 u16 maximum; 257 u16 translation_offset; 258 u16 address_length; 259 }; 260 261 struct aml_resource_extended_irq { 262 AML_RESOURCE_LARGE_HEADER_COMMON u8 flags; 263 u8 interrupt_count; 264 union { 265 u32 interrupt; 266 ACPI_FLEX_ARRAY(u32, interrupts); 267 }; 268 /* res_source_index, res_source optional fields follow */ 269 }; 270 271 struct aml_resource_generic_register { 272 AML_RESOURCE_LARGE_HEADER_COMMON u8 address_space_id; 273 u8 bit_width; 274 u8 bit_offset; 275 u8 access_size; /* ACPI 3.0, was previously Reserved */ 276 u64 address; 277 }; 278 279 /* Common descriptor for gpio_int and gpio_io (ACPI 5.0) */ 280 281 struct aml_resource_gpio { 282 AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id; 283 u8 connection_type; 284 u16 flags; 285 u16 int_flags; 286 u8 pin_config; 287 u16 drive_strength; 288 u16 debounce_timeout; 289 u16 pin_table_offset; 290 u8 res_source_index; 291 u16 res_source_offset; 292 u16 vendor_offset; 293 u16 vendor_length; 294 /* 295 * Optional fields follow immediately: 296 * 1) PIN list (Words) 297 * 2) Resource Source String 298 * 3) Vendor Data bytes 299 */ 300 }; 301 302 #define AML_RESOURCE_GPIO_REVISION 1 /* ACPI 5.0 */ 303 304 /* Values for connection_type above */ 305 306 #define AML_RESOURCE_GPIO_TYPE_INT 0 307 #define AML_RESOURCE_GPIO_TYPE_IO 1 308 #define AML_RESOURCE_MAX_GPIOTYPE 1 309 310 /* Common preamble for all serial descriptors (ACPI 5.0) */ 311 312 #define AML_RESOURCE_SERIAL_COMMON \ 313 u8 revision_id; \ 314 u8 res_source_index; \ 315 u8 type; \ 316 u8 flags; \ 317 u16 type_specific_flags; \ 318 u8 type_revision_id; \ 319 u16 type_data_length; \ 320 321 /* Values for the type field above */ 322 323 #define AML_RESOURCE_I2C_SERIALBUSTYPE 1 324 #define AML_RESOURCE_SPI_SERIALBUSTYPE 2 325 #define AML_RESOURCE_UART_SERIALBUSTYPE 3 326 #define AML_RESOURCE_CSI2_SERIALBUSTYPE 4 327 #define AML_RESOURCE_MAX_SERIALBUSTYPE 4 328 #define AML_RESOURCE_VENDOR_SERIALBUSTYPE 192 /* Vendor defined is 0xC0-0xFF (NOT SUPPORTED) */ 329 330 struct aml_resource_common_serialbus { 331 AML_RESOURCE_LARGE_HEADER_COMMON AML_RESOURCE_SERIAL_COMMON}; 332 333 struct aml_resource_csi2_serialbus { 334 AML_RESOURCE_LARGE_HEADER_COMMON AML_RESOURCE_SERIAL_COMMON 335 /* 336 * Optional fields follow immediately: 337 * 1) Vendor Data bytes 338 * 2) Resource Source String 339 */ 340 }; 341 342 #define AML_RESOURCE_CSI2_REVISION 1 /* ACPI 6.4 */ 343 #define AML_RESOURCE_CSI2_TYPE_REVISION 1 /* ACPI 6.4 */ 344 #define AML_RESOURCE_CSI2_MIN_DATA_LEN 0 /* ACPI 6.4 */ 345 346 struct aml_resource_i2c_serialbus { 347 AML_RESOURCE_LARGE_HEADER_COMMON 348 AML_RESOURCE_SERIAL_COMMON u32 connection_speed; 349 u16 slave_address; 350 /* 351 * Optional fields follow immediately: 352 * 1) Vendor Data bytes 353 * 2) Resource Source String 354 */ 355 }; 356 357 #define AML_RESOURCE_I2C_REVISION 1 /* ACPI 5.0 */ 358 #define AML_RESOURCE_I2C_TYPE_REVISION 1 /* ACPI 5.0 */ 359 #define AML_RESOURCE_I2C_MIN_DATA_LEN 6 360 361 struct aml_resource_spi_serialbus { 362 AML_RESOURCE_LARGE_HEADER_COMMON 363 AML_RESOURCE_SERIAL_COMMON u32 connection_speed; 364 u8 data_bit_length; 365 u8 clock_phase; 366 u8 clock_polarity; 367 u16 device_selection; 368 /* 369 * Optional fields follow immediately: 370 * 1) Vendor Data bytes 371 * 2) Resource Source String 372 */ 373 }; 374 375 #define AML_RESOURCE_SPI_REVISION 1 /* ACPI 5.0 */ 376 #define AML_RESOURCE_SPI_TYPE_REVISION 1 /* ACPI 5.0 */ 377 #define AML_RESOURCE_SPI_MIN_DATA_LEN 9 378 379 struct aml_resource_uart_serialbus { 380 AML_RESOURCE_LARGE_HEADER_COMMON 381 AML_RESOURCE_SERIAL_COMMON u32 default_baud_rate; 382 u16 rx_fifo_size; 383 u16 tx_fifo_size; 384 u8 parity; 385 u8 lines_enabled; 386 /* 387 * Optional fields follow immediately: 388 * 1) Vendor Data bytes 389 * 2) Resource Source String 390 */ 391 }; 392 393 #define AML_RESOURCE_UART_REVISION 1 /* ACPI 5.0 */ 394 #define AML_RESOURCE_UART_TYPE_REVISION 1 /* ACPI 5.0 */ 395 #define AML_RESOURCE_UART_MIN_DATA_LEN 10 396 397 struct aml_resource_pin_function { 398 AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id; 399 u16 flags; 400 u8 pin_config; 401 u16 function_number; 402 u16 pin_table_offset; 403 u8 res_source_index; 404 u16 res_source_offset; 405 u16 vendor_offset; 406 u16 vendor_length; 407 /* 408 * Optional fields follow immediately: 409 * 1) PIN list (Words) 410 * 2) Resource Source String 411 * 3) Vendor Data bytes 412 */ 413 }; 414 415 #define AML_RESOURCE_PIN_FUNCTION_REVISION 1 /* ACPI 6.2 */ 416 417 struct aml_resource_pin_config { 418 AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id; 419 u16 flags; 420 u8 pin_config_type; 421 u32 pin_config_value; 422 u16 pin_table_offset; 423 u8 res_source_index; 424 u16 res_source_offset; 425 u16 vendor_offset; 426 u16 vendor_length; 427 /* 428 * Optional fields follow immediately: 429 * 1) PIN list (Words) 430 * 2) Resource Source String 431 * 3) Vendor Data bytes 432 */ 433 }; 434 435 #define AML_RESOURCE_CLOCK_INPUT_REVISION 1 /* ACPI 6.5 */ 436 437 struct aml_resource_clock_input { 438 AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id; 439 u16 flags; 440 u16 frequency_divisor; 441 u32 frequency_numerator; 442 /* 443 * Optional fields follow immediately: 444 * 1) Resource Source index 445 * 2) Resource Source String 446 */ 447 }; 448 449 #define AML_RESOURCE_PIN_CONFIG_REVISION 1 /* ACPI 6.2 */ 450 451 struct aml_resource_pin_group { 452 AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id; 453 u16 flags; 454 u16 pin_table_offset; 455 u16 label_offset; 456 u16 vendor_offset; 457 u16 vendor_length; 458 /* 459 * Optional fields follow immediately: 460 * 1) PIN list (Words) 461 * 2) Resource Label String 462 * 3) Vendor Data bytes 463 */ 464 }; 465 466 #define AML_RESOURCE_PIN_GROUP_REVISION 1 /* ACPI 6.2 */ 467 468 struct aml_resource_pin_group_function { 469 AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id; 470 u16 flags; 471 u16 function_number; 472 u8 res_source_index; 473 u16 res_source_offset; 474 u16 res_source_label_offset; 475 u16 vendor_offset; 476 u16 vendor_length; 477 /* 478 * Optional fields follow immediately: 479 * 1) Resource Source String 480 * 2) Resource Source Label String 481 * 3) Vendor Data bytes 482 */ 483 }; 484 485 #define AML_RESOURCE_PIN_GROUP_FUNCTION_REVISION 1 /* ACPI 6.2 */ 486 487 struct aml_resource_pin_group_config { 488 AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id; 489 u16 flags; 490 u8 pin_config_type; 491 u32 pin_config_value; 492 u8 res_source_index; 493 u16 res_source_offset; 494 u16 res_source_label_offset; 495 u16 vendor_offset; 496 u16 vendor_length; 497 /* 498 * Optional fields follow immediately: 499 * 1) Resource Source String 500 * 2) Resource Source Label String 501 * 3) Vendor Data bytes 502 */ 503 }; 504 505 #define AML_RESOURCE_PIN_GROUP_CONFIG_REVISION 1 /* ACPI 6.2 */ 506 507 /* restore default alignment */ 508 509 #pragma pack() 510 511 /* Union of all resource descriptors, so we can allocate the worst case */ 512 513 union aml_resource { 514 /* Descriptor headers */ 515 516 u8 descriptor_type; 517 struct aml_resource_small_header small_header; 518 struct aml_resource_large_header large_header; 519 520 /* Small resource descriptors */ 521 522 struct aml_resource_irq irq; 523 struct aml_resource_dma dma; 524 struct aml_resource_start_dependent start_dpf; 525 struct aml_resource_end_dependent end_dpf; 526 struct aml_resource_io io; 527 struct aml_resource_fixed_io fixed_io; 528 struct aml_resource_fixed_dma fixed_dma; 529 struct aml_resource_vendor_small vendor_small; 530 struct aml_resource_end_tag end_tag; 531 532 /* Large resource descriptors */ 533 534 struct aml_resource_memory24 memory24; 535 struct aml_resource_generic_register generic_reg; 536 struct aml_resource_vendor_large vendor_large; 537 struct aml_resource_memory32 memory32; 538 struct aml_resource_fixed_memory32 fixed_memory32; 539 struct aml_resource_address16 address16; 540 struct aml_resource_address32 address32; 541 struct aml_resource_address64 address64; 542 struct aml_resource_extended_address64 ext_address64; 543 struct aml_resource_extended_irq extended_irq; 544 struct aml_resource_gpio gpio; 545 struct aml_resource_i2c_serialbus i2c_serial_bus; 546 struct aml_resource_spi_serialbus spi_serial_bus; 547 struct aml_resource_uart_serialbus uart_serial_bus; 548 struct aml_resource_csi2_serialbus csi2_serial_bus; 549 struct aml_resource_common_serialbus common_serial_bus; 550 struct aml_resource_pin_function pin_function; 551 struct aml_resource_pin_config pin_config; 552 struct aml_resource_pin_group pin_group; 553 struct aml_resource_pin_group_function pin_group_function; 554 struct aml_resource_pin_group_config pin_group_config; 555 struct aml_resource_clock_input clock_input; 556 557 /* Utility overlays */ 558 559 struct aml_resource_address address; 560 u32 dword_item; 561 u16 word_item; 562 u8 byte_item; 563 }; 564 565 /* Interfaces used by both the disassembler and compiler */ 566 567 void 568 mp_save_gpio_info(union acpi_parse_object *op, 569 union aml_resource *resource, 570 u32 pin_count, u16 *pin_list, char *device_name); 571 572 void 573 mp_save_serial_info(union acpi_parse_object *op, 574 union aml_resource *resource, char *device_name); 575 576 char *mp_get_hid_from_parse_tree(struct acpi_namespace_node *hid_node); 577 578 char *mp_get_hid_via_namestring(char *device_name); 579 580 char *mp_get_connection_info(union acpi_parse_object *op, 581 u32 pin_index, 582 struct acpi_namespace_node **target_node, 583 char **target_name); 584 585 char *mp_get_parent_device_hid(union acpi_parse_object *op, 586 struct acpi_namespace_node **target_node, 587 char **parent_device_name); 588 589 char *mp_get_ddn_value(char *device_name); 590 591 char *mp_get_hid_value(struct acpi_namespace_node *device_node); 592 593 #endif 594