| 1 | #pragma once |
| 2 | |
| 3 | #include <uacpi/types.h> |
| 4 | |
| 5 | #ifdef __cplusplus |
| 6 | extern "C" { |
| 7 | #endif |
| 8 | |
| 9 | #ifndef UACPI_BAREBONES_MODE |
| 10 | |
| 11 | typedef enum uacpi_resource_type { |
| 12 | UACPI_RESOURCE_TYPE_IRQ, |
| 13 | UACPI_RESOURCE_TYPE_EXTENDED_IRQ, |
| 14 | |
| 15 | UACPI_RESOURCE_TYPE_DMA, |
| 16 | UACPI_RESOURCE_TYPE_FIXED_DMA, |
| 17 | |
| 18 | UACPI_RESOURCE_TYPE_IO, |
| 19 | UACPI_RESOURCE_TYPE_FIXED_IO, |
| 20 | |
| 21 | UACPI_RESOURCE_TYPE_ADDRESS16, |
| 22 | UACPI_RESOURCE_TYPE_ADDRESS32, |
| 23 | UACPI_RESOURCE_TYPE_ADDRESS64, |
| 24 | UACPI_RESOURCE_TYPE_ADDRESS64_EXTENDED, |
| 25 | |
| 26 | UACPI_RESOURCE_TYPE_MEMORY24, |
| 27 | UACPI_RESOURCE_TYPE_MEMORY32, |
| 28 | UACPI_RESOURCE_TYPE_FIXED_MEMORY32, |
| 29 | |
| 30 | UACPI_RESOURCE_TYPE_START_DEPENDENT, |
| 31 | UACPI_RESOURCE_TYPE_END_DEPENDENT, |
| 32 | |
| 33 | // Up to 7 bytes |
| 34 | UACPI_RESOURCE_TYPE_VENDOR_SMALL, |
| 35 | |
| 36 | // Up to 2^16 - 1 bytes |
| 37 | UACPI_RESOURCE_TYPE_VENDOR_LARGE, |
| 38 | |
| 39 | UACPI_RESOURCE_TYPE_GENERIC_REGISTER, |
| 40 | UACPI_RESOURCE_TYPE_GPIO_CONNECTION, |
| 41 | |
| 42 | // These must always be contiguous in this order |
| 43 | UACPI_RESOURCE_TYPE_SERIAL_I2C_CONNECTION, |
| 44 | UACPI_RESOURCE_TYPE_SERIAL_SPI_CONNECTION, |
| 45 | UACPI_RESOURCE_TYPE_SERIAL_UART_CONNECTION, |
| 46 | UACPI_RESOURCE_TYPE_SERIAL_CSI2_CONNECTION, |
| 47 | |
| 48 | UACPI_RESOURCE_TYPE_PIN_FUNCTION, |
| 49 | UACPI_RESOURCE_TYPE_PIN_CONFIGURATION, |
| 50 | UACPI_RESOURCE_TYPE_PIN_GROUP, |
| 51 | UACPI_RESOURCE_TYPE_PIN_GROUP_FUNCTION, |
| 52 | UACPI_RESOURCE_TYPE_PIN_GROUP_CONFIGURATION, |
| 53 | |
| 54 | UACPI_RESOURCE_TYPE_CLOCK_INPUT, |
| 55 | |
| 56 | UACPI_RESOURCE_TYPE_END_TAG, |
| 57 | UACPI_RESOURCE_TYPE_MAX = UACPI_RESOURCE_TYPE_END_TAG, |
| 58 | } uacpi_resource_type; |
| 59 | |
| 60 | typedef struct uacpi_resource_source { |
| 61 | uacpi_u8 index; |
| 62 | uacpi_bool index_present; |
| 63 | uacpi_u16 length; |
| 64 | uacpi_char *string; |
| 65 | } uacpi_resource_source; |
| 66 | |
| 67 | /** |
| 68 | * This applies to IRQ & StartDependent resources only. The DONT_CARE value is |
| 69 | * used for deserialization into the AML format to signify that the serializer |
| 70 | * is allowed to optimize the length down if possible. Note that this is |
| 71 | * generally not allowed unless the resource is generated by the caller: |
| 72 | * |
| 73 | * -- ACPI 6.5 ------------------------------------------------------------ |
| 74 | * The resource descriptors in the byte stream argument must be specified |
| 75 | * exactly as listed in the _CRS byte stream - meaning that the identical |
| 76 | * resource descriptors must appear in the identical order, resulting in a |
| 77 | * buffer of exactly the same length. Optimizations such as changing an |
| 78 | * IRQ descriptor to an IRQNoFlags descriptor (or vice-versa) must not be |
| 79 | * performed. Similarly, changing StartDependentFn to StartDependentFnNoPri |
| 80 | * is not allowed. |
| 81 | * ------------------------------------------------------------------------ |
| 82 | */ |
| 83 | enum uacpi_resource_length_kind { |
| 84 | UACPI_RESOURCE_LENGTH_KIND_DONT_CARE = 0, |
| 85 | UACPI_RESOURCE_LENGTH_KIND_ONE_LESS, |
| 86 | UACPI_RESOURCE_LENGTH_KIND_FULL, |
| 87 | }; |
| 88 | |
| 89 | // triggering fields |
| 90 | #define UACPI_TRIGGERING_EDGE 1 |
| 91 | #define UACPI_TRIGGERING_LEVEL 0 |
| 92 | |
| 93 | // polarity |
| 94 | #define UACPI_POLARITY_ACTIVE_HIGH 0 |
| 95 | #define UACPI_POLARITY_ACTIVE_LOW 1 |
| 96 | #define UACPI_POLARITY_ACTIVE_BOTH 2 |
| 97 | |
| 98 | // sharing |
| 99 | #define UACPI_EXCLUSIVE 0 |
| 100 | #define UACPI_SHARED 1 |
| 101 | |
| 102 | // wake_capability |
| 103 | #define UACPI_WAKE_CAPABLE 1 |
| 104 | #define UACPI_NOT_WAKE_CAPABLE 0 |
| 105 | |
| 106 | typedef struct uacpi_resource_irq { |
| 107 | uacpi_u8 length_kind; |
| 108 | uacpi_u8 triggering; |
| 109 | uacpi_u8 polarity; |
| 110 | uacpi_u8 sharing; |
| 111 | uacpi_u8 wake_capability; |
| 112 | uacpi_u8 num_irqs; |
| 113 | uacpi_u8 irqs[]; |
| 114 | } uacpi_resource_irq; |
| 115 | |
| 116 | typedef struct uacpi_resource_extended_irq { |
| 117 | uacpi_u8 direction; |
| 118 | uacpi_u8 triggering; |
| 119 | uacpi_u8 polarity; |
| 120 | uacpi_u8 sharing; |
| 121 | uacpi_u8 wake_capability; |
| 122 | uacpi_u8 num_irqs; |
| 123 | uacpi_resource_source source; |
| 124 | uacpi_u32 irqs[]; |
| 125 | } uacpi_resource_extended_irq; |
| 126 | |
| 127 | // transfer_type |
| 128 | #define UACPI_TRANSFER_TYPE_8_BIT 0b00 |
| 129 | #define UACPI_TRANSFER_TYPE_8_AND_16_BIT 0b01 |
| 130 | #define UACPI_TRANSFER_TYPE_16_BIT 0b10 |
| 131 | |
| 132 | // bus_master_status |
| 133 | #define UACPI_BUS_MASTER 0b1 |
| 134 | |
| 135 | // channel_speed |
| 136 | #define UACPI_DMA_COMPATIBILITY 0b00 |
| 137 | #define UACPI_DMA_TYPE_A 0b01 |
| 138 | #define UACPI_DMA_TYPE_B 0b10 |
| 139 | #define UACPI_DMA_TYPE_F 0b11 |
| 140 | |
| 141 | // transfer_width |
| 142 | #define UACPI_TRANSFER_WIDTH_8 0x00 |
| 143 | #define UACPI_TRANSFER_WIDTH_16 0x01 |
| 144 | #define UACPI_TRANSFER_WIDTH_32 0x02 |
| 145 | #define UACPI_TRANSFER_WIDTH_64 0x03 |
| 146 | #define UACPI_TRANSFER_WIDTH_128 0x04 |
| 147 | #define UACPI_TRANSFER_WIDTH_256 0x05 |
| 148 | |
| 149 | typedef struct uacpi_resource_dma { |
| 150 | uacpi_u8 transfer_type; |
| 151 | uacpi_u8 bus_master_status; |
| 152 | uacpi_u8 channel_speed; |
| 153 | uacpi_u8 num_channels; |
| 154 | uacpi_u8 channels[]; |
| 155 | } uacpi_resource_dma; |
| 156 | |
| 157 | typedef struct uacpi_resource_fixed_dma { |
| 158 | uacpi_u16 request_line; |
| 159 | uacpi_u16 channel; |
| 160 | uacpi_u8 transfer_width; |
| 161 | } uacpi_resource_fixed_dma; |
| 162 | |
| 163 | // decode_type |
| 164 | #define UACPI_DECODE_16 0b1 |
| 165 | #define UACPI_DECODE_10 0b0 |
| 166 | |
| 167 | typedef struct uacpi_resource_io { |
| 168 | uacpi_u8 decode_type; |
| 169 | uacpi_u16 minimum; |
| 170 | uacpi_u16 maximum; |
| 171 | uacpi_u8 alignment; |
| 172 | uacpi_u8 length; |
| 173 | } uacpi_resource_io; |
| 174 | |
| 175 | typedef struct uacpi_resource_fixed_io { |
| 176 | uacpi_u16 address; |
| 177 | uacpi_u8 length; |
| 178 | } uacpi_resource_fixed_io; |
| 179 | |
| 180 | // write_status |
| 181 | #define UACPI_NON_WRITABLE 0 |
| 182 | #define UACPI_WRITABLE 1 |
| 183 | |
| 184 | // caching |
| 185 | #define UACPI_NON_CACHEABLE 0 |
| 186 | #define UACPI_CACHEABLE 1 |
| 187 | #define UACPI_CACHEABLE_WRITE_COMBINING 2 |
| 188 | #define UACPI_PREFETCHABLE 3 |
| 189 | |
| 190 | // range_type |
| 191 | #define UACPI_RANGE_TYPE_MEMORY 0 |
| 192 | #define UACPI_RANGE_TYPE_RESERVED 1 |
| 193 | #define UACPI_RANGE_TYPE_ACPI 2 |
| 194 | #define UACPI_RANGE_TYPE_NVS 3 |
| 195 | |
| 196 | // address_common->type |
| 197 | #define UACPI_RANGE_MEMORY 0 |
| 198 | #define UACPI_RANGE_IO 1 |
| 199 | #define UACPI_RANGE_BUS 2 |
| 200 | |
| 201 | // translation |
| 202 | #define UACPI_IO_MEM_TRANSLATION 1 |
| 203 | #define UACPI_IO_MEM_STATIC 0 |
| 204 | |
| 205 | // translation_type |
| 206 | #define UACPI_TRANSLATION_DENSE 0 |
| 207 | #define UACPI_TRANSLATION_SPARSE 1 |
| 208 | |
| 209 | // direction |
| 210 | #define UACPI_PRODUCER 0 |
| 211 | #define UACPI_CONSUMER 1 |
| 212 | |
| 213 | // decode_type |
| 214 | #define UACPI_POSITIVE_DECODE 0 |
| 215 | #define UACPI_SUBTRACTIVE_DECODE 1 |
| 216 | |
| 217 | // fixed_min_address & fixed_max_address |
| 218 | #define UACPI_ADDRESS_NOT_FIXED 0 |
| 219 | #define UACPI_ADDRESS_FIXED 1 |
| 220 | |
| 221 | typedef struct uacpi_memory_attribute { |
| 222 | uacpi_u8 write_status; |
| 223 | uacpi_u8 caching; |
| 224 | uacpi_u8 range_type; |
| 225 | uacpi_u8 translation; |
| 226 | } uacpi_memory_attribute; |
| 227 | |
| 228 | typedef struct uacpi_io_attribute { |
| 229 | uacpi_u8 range_type; |
| 230 | uacpi_u8 translation; |
| 231 | uacpi_u8 translation_type; |
| 232 | } uacpi_io_attribute; |
| 233 | |
| 234 | typedef union uacpi_address_attribute { |
| 235 | uacpi_memory_attribute memory; |
| 236 | uacpi_io_attribute io; |
| 237 | uacpi_u8 type_specific; |
| 238 | } uacpi_address_attribute; |
| 239 | |
| 240 | typedef struct uacpi_resource_address_common { |
| 241 | uacpi_address_attribute attribute; |
| 242 | uacpi_u8 type; |
| 243 | uacpi_u8 direction; |
| 244 | uacpi_u8 decode_type; |
| 245 | uacpi_u8 fixed_min_address; |
| 246 | uacpi_u8 fixed_max_address; |
| 247 | } uacpi_resource_address_common; |
| 248 | |
| 249 | typedef struct uacpi_resource_address16 { |
| 250 | uacpi_resource_address_common common; |
| 251 | uacpi_u16 granularity; |
| 252 | uacpi_u16 minimum; |
| 253 | uacpi_u16 maximum; |
| 254 | uacpi_u16 translation_offset; |
| 255 | uacpi_u16 address_length; |
| 256 | uacpi_resource_source source; |
| 257 | } uacpi_resource_address16; |
| 258 | |
| 259 | typedef struct uacpi_resource_address32 { |
| 260 | uacpi_resource_address_common common; |
| 261 | uacpi_u32 granularity; |
| 262 | uacpi_u32 minimum; |
| 263 | uacpi_u32 maximum; |
| 264 | uacpi_u32 translation_offset; |
| 265 | uacpi_u32 address_length; |
| 266 | uacpi_resource_source source; |
| 267 | } uacpi_resource_address32; |
| 268 | |
| 269 | typedef struct uacpi_resource_address64 { |
| 270 | uacpi_resource_address_common common; |
| 271 | uacpi_u64 granularity; |
| 272 | uacpi_u64 minimum; |
| 273 | uacpi_u64 maximum; |
| 274 | uacpi_u64 translation_offset; |
| 275 | uacpi_u64 address_length; |
| 276 | uacpi_resource_source source; |
| 277 | } uacpi_resource_address64; |
| 278 | |
| 279 | typedef struct uacpi_resource_address64_extended { |
| 280 | uacpi_resource_address_common common; |
| 281 | uacpi_u8 revision_id; |
| 282 | uacpi_u64 granularity; |
| 283 | uacpi_u64 minimum; |
| 284 | uacpi_u64 maximum; |
| 285 | uacpi_u64 translation_offset; |
| 286 | uacpi_u64 address_length; |
| 287 | uacpi_u64 attributes; |
| 288 | } uacpi_resource_address64_extended; |
| 289 | |
| 290 | typedef struct uacpi_resource_memory24 { |
| 291 | uacpi_u8 write_status; |
| 292 | uacpi_u16 minimum; |
| 293 | uacpi_u16 maximum; |
| 294 | uacpi_u16 alignment; |
| 295 | uacpi_u16 length; |
| 296 | } uacpi_resource_memory24; |
| 297 | |
| 298 | typedef struct uacpi_resource_memory32 { |
| 299 | uacpi_u8 write_status; |
| 300 | uacpi_u32 minimum; |
| 301 | uacpi_u32 maximum; |
| 302 | uacpi_u32 alignment; |
| 303 | uacpi_u32 length; |
| 304 | } uacpi_resource_memory32; |
| 305 | |
| 306 | typedef struct uacpi_resource_fixed_memory32 { |
| 307 | uacpi_u8 write_status; |
| 308 | uacpi_u32 address; |
| 309 | uacpi_u32 length; |
| 310 | } uacpi_resource_fixed_memory32; |
| 311 | |
| 312 | // compatibility & performance |
| 313 | #define UACPI_GOOD 0 |
| 314 | #define UACPI_ACCEPTABLE 1 |
| 315 | #define UACPI_SUB_OPTIMAL 2 |
| 316 | |
| 317 | typedef struct uacpi_resource_start_dependent { |
| 318 | uacpi_u8 length_kind; |
| 319 | uacpi_u8 compatibility; |
| 320 | uacpi_u8 performance; |
| 321 | } uacpi_resource_start_dependent; |
| 322 | |
| 323 | typedef struct uacpi_resource_vendor_defined { |
| 324 | uacpi_u8 length; |
| 325 | uacpi_u8 data[]; |
| 326 | } uacpi_resource_vendor; |
| 327 | |
| 328 | typedef struct uacpi_resource_vendor_typed { |
| 329 | uacpi_u16 length; |
| 330 | uacpi_u8 sub_type; |
| 331 | uacpi_u8 uuid[16]; |
| 332 | uacpi_u8 data[]; |
| 333 | } uacpi_resource_vendor_typed; |
| 334 | |
| 335 | typedef struct uacpi_resource_generic_register { |
| 336 | uacpi_u8 address_space_id; |
| 337 | uacpi_u8 bit_width; |
| 338 | uacpi_u8 bit_offset; |
| 339 | uacpi_u8 access_size; |
| 340 | uacpi_u64 address; |
| 341 | } uacpi_resource_generic_register; |
| 342 | |
| 343 | // type |
| 344 | #define UACPI_GPIO_CONNECTION_INTERRUPT 0x00 |
| 345 | #define UACPI_GPIO_CONNECTION_IO 0x01 |
| 346 | |
| 347 | typedef struct uacpi_interrupt_connection_flags { |
| 348 | uacpi_u8 triggering; |
| 349 | uacpi_u8 polarity; |
| 350 | uacpi_u8 sharing; |
| 351 | uacpi_u8 wake_capability; |
| 352 | } uacpi_interrupt_connection_flags; |
| 353 | |
| 354 | // restriction |
| 355 | #define UACPI_IO_RESTRICTION_NONE 0x0 |
| 356 | #define UACPI_IO_RESTRICTION_INPUT 0x1 |
| 357 | #define UACPI_IO_RESTRICTION_OUTPUT 0x2 |
| 358 | #define UACPI_IO_RESTRICTION_NONE_PRESERVE 0x3 |
| 359 | |
| 360 | typedef struct uacpi_io_connection_flags { |
| 361 | uacpi_u8 restriction; |
| 362 | uacpi_u8 sharing; |
| 363 | } uacpi_io_connection_flags; |
| 364 | |
| 365 | // pull_configuration |
| 366 | #define UACPI_PIN_CONFIG_DEFAULT 0x00 |
| 367 | #define UACPI_PIN_CONFIG_PULL_UP 0x01 |
| 368 | #define UACPI_PIN_CONFIG_PULL_DOWN 0x02 |
| 369 | #define UACPI_PIN_CONFIG_NO_PULL 0x03 |
| 370 | |
| 371 | typedef struct uacpi_resource_gpio_connection { |
| 372 | uacpi_u8 revision_id; |
| 373 | uacpi_u8 type; |
| 374 | uacpi_u8 direction; |
| 375 | |
| 376 | union { |
| 377 | uacpi_interrupt_connection_flags intr; |
| 378 | uacpi_io_connection_flags io; |
| 379 | uacpi_u16 type_specific; |
| 380 | }; |
| 381 | |
| 382 | uacpi_u8 pull_configuration; |
| 383 | uacpi_u16 drive_strength; |
| 384 | uacpi_u16 debounce_timeout; |
| 385 | uacpi_u16 vendor_data_length; |
| 386 | uacpi_u16 pin_table_length; |
| 387 | uacpi_resource_source source; |
| 388 | uacpi_u16 *pin_table; |
| 389 | uacpi_u8 *vendor_data; |
| 390 | } uacpi_resource_gpio_connection; |
| 391 | |
| 392 | // mode |
| 393 | #define UACPI_MODE_CONTROLLER_INITIATED 0x0 |
| 394 | #define UACPI_MODE_DEVICE_INITIATED 0x1 |
| 395 | |
| 396 | typedef struct uacpi_resource_serial_bus_common { |
| 397 | uacpi_u8 revision_id; |
| 398 | uacpi_u8 type; |
| 399 | uacpi_u8 mode; |
| 400 | uacpi_u8 direction; |
| 401 | uacpi_u8 sharing; |
| 402 | uacpi_u8 type_revision_id; |
| 403 | uacpi_u16 type_data_length; |
| 404 | uacpi_u16 vendor_data_length; |
| 405 | uacpi_resource_source source; |
| 406 | uacpi_u8 *vendor_data; |
| 407 | } uacpi_resource_serial_bus_common; |
| 408 | |
| 409 | // addressing_mode |
| 410 | #define UACPI_I2C_7BIT 0x0 |
| 411 | #define UACPI_I2C_10BIT 0x1 |
| 412 | |
| 413 | typedef struct uacpi_resource_i2c_connection { |
| 414 | uacpi_resource_serial_bus_common common; |
| 415 | uacpi_u8 addressing_mode; |
| 416 | uacpi_u16 slave_address; |
| 417 | uacpi_u32 connection_speed; |
| 418 | } uacpi_resource_i2c_connection; |
| 419 | |
| 420 | // wire_mode |
| 421 | #define UACPI_SPI_4_WIRES 0 |
| 422 | #define UACPI_SPI_3_WIRES 1 |
| 423 | |
| 424 | // device_polarity |
| 425 | #define UACPI_SPI_ACTIVE_LOW 0 |
| 426 | #define UACPI_SPI_ACTIVE_HIGH 1 |
| 427 | |
| 428 | // phase |
| 429 | #define UACPI_SPI_PHASE_FIRST 0 |
| 430 | #define UACPI_SPI_PHASE_SECOND 1 |
| 431 | |
| 432 | // polarity |
| 433 | #define UACPI_SPI_START_LOW 0 |
| 434 | #define UACPI_SPI_START_HIGH 1 |
| 435 | |
| 436 | typedef struct uacpi_resource_spi_connection { |
| 437 | uacpi_resource_serial_bus_common common; |
| 438 | uacpi_u8 wire_mode; |
| 439 | uacpi_u8 device_polarity; |
| 440 | uacpi_u8 data_bit_length; |
| 441 | uacpi_u8 phase; |
| 442 | uacpi_u8 polarity; |
| 443 | uacpi_u16 device_selection; |
| 444 | uacpi_u32 connection_speed; |
| 445 | } uacpi_resource_spi_connection; |
| 446 | |
| 447 | // stop_bits |
| 448 | #define UACPI_UART_STOP_BITS_NONE 0b00 |
| 449 | #define UACPI_UART_STOP_BITS_1 0b01 |
| 450 | #define UACPI_UART_STOP_BITS_1_5 0b10 |
| 451 | #define UACPI_UART_STOP_BITS_2 0b11 |
| 452 | |
| 453 | // data_bits |
| 454 | #define UACPI_UART_DATA_5BITS 0b000 |
| 455 | #define UACPI_UART_DATA_6BITS 0b001 |
| 456 | #define UACPI_UART_DATA_7BITS 0b010 |
| 457 | #define UACPI_UART_DATA_8BITS 0b011 |
| 458 | #define UACPI_UART_DATA_9BITS 0b100 |
| 459 | |
| 460 | // endianness |
| 461 | #define UACPI_UART_LITTLE_ENDIAN 0 |
| 462 | #define UACPI_UART_BIG_ENDIAN 1 |
| 463 | |
| 464 | // parity |
| 465 | #define UACPI_UART_PARITY_NONE 0x00 |
| 466 | #define UACPI_UART_PARITY_EVEN 0x01 |
| 467 | #define UACPI_UART_PARITY_ODD 0x02 |
| 468 | #define UACPI_UART_PARITY_MARK 0x03 |
| 469 | #define UACPI_UART_PARITY_SPACE 0x04 |
| 470 | |
| 471 | // lines_enabled |
| 472 | #define UACPI_UART_DATA_CARRIER_DETECT (1 << 2) |
| 473 | #define UACPI_UART_RING_INDICATOR (1 << 3) |
| 474 | #define UACPI_UART_DATA_SET_READY (1 << 4) |
| 475 | #define UACPI_UART_DATA_TERMINAL_READY (1 << 5) |
| 476 | #define UACPI_UART_CLEAR_TO_SEND (1 << 6) |
| 477 | #define UACPI_UART_REQUEST_TO_SEND (1 << 7) |
| 478 | |
| 479 | // flow_control |
| 480 | #define UACPI_UART_FLOW_CONTROL_NONE 0b00 |
| 481 | #define UACPI_UART_FLOW_CONTROL_HW 0b01 |
| 482 | #define UACPI_UART_FLOW_CONTROL_XON_XOFF 0b10 |
| 483 | |
| 484 | typedef struct uacpi_resource_uart_connection { |
| 485 | uacpi_resource_serial_bus_common common; |
| 486 | uacpi_u8 stop_bits; |
| 487 | uacpi_u8 data_bits; |
| 488 | uacpi_u8 endianness; |
| 489 | uacpi_u8 parity; |
| 490 | uacpi_u8 lines_enabled; |
| 491 | uacpi_u8 flow_control; |
| 492 | uacpi_u32 baud_rate; |
| 493 | uacpi_u16 rx_fifo; |
| 494 | uacpi_u16 tx_fifo; |
| 495 | } uacpi_resource_uart_connection; |
| 496 | |
| 497 | // phy_type |
| 498 | #define UACPI_CSI2_PHY_C 0b00 |
| 499 | #define UACPI_CSI2_PHY_D 0b01 |
| 500 | |
| 501 | typedef struct uacpi_resource_csi2_connection { |
| 502 | uacpi_resource_serial_bus_common common; |
| 503 | uacpi_u8 phy_type; |
| 504 | uacpi_u8 local_port; |
| 505 | } uacpi_resource_csi2_connection; |
| 506 | |
| 507 | typedef struct uacpi_resource_pin_function { |
| 508 | uacpi_u8 revision_id; |
| 509 | uacpi_u8 sharing; |
| 510 | uacpi_u8 pull_configuration; |
| 511 | uacpi_u16 function_number; |
| 512 | uacpi_u16 pin_table_length; |
| 513 | uacpi_u16 vendor_data_length; |
| 514 | uacpi_resource_source source; |
| 515 | uacpi_u16 *pin_table; |
| 516 | uacpi_u8 *vendor_data; |
| 517 | } uacpi_resource_pin_function; |
| 518 | |
| 519 | // type |
| 520 | #define UACPI_PIN_CONFIG_DEFAULT 0x00 |
| 521 | #define UACPI_PIN_CONFIG_BIAS_PULL_UP 0x01 |
| 522 | #define UACPI_PIN_CONFIG_BIAS_PULL_DOWN 0x02 |
| 523 | #define UACPI_PIN_CONFIG_BIAS_DEFAULT 0x03 |
| 524 | #define UACPI_PIN_CONFIG_BIAS_DISABLE 0x04 |
| 525 | #define UACPI_PIN_CONFIG_BIAS_HIGH_IMPEDANCE 0x05 |
| 526 | #define UACPI_PIN_CONFIG_BIAS_BUS_HOLD 0x06 |
| 527 | #define UACPI_PIN_CONFIG_DRIVE_OPEN_DRAIN 0x07 |
| 528 | #define UACPI_PIN_CONFIG_DRIVE_OPEN_SOURCE 0x08 |
| 529 | #define UACPI_PIN_CONFIG_DRIVE_PUSH_PULL 0x09 |
| 530 | #define UACPI_PIN_CONFIG_DRIVE_STRENGTH 0x0A |
| 531 | #define UACPI_PIN_CONFIG_SLEW_RATE 0x0B |
| 532 | #define UACPI_PIN_CONFIG_INPUT_DEBOUNCE 0x0C |
| 533 | #define UACPI_PIN_CONFIG_INPUT_SCHMITT_TRIGGER 0x0D |
| 534 | |
| 535 | typedef struct uacpi_resource_pin_configuration { |
| 536 | uacpi_u8 revision_id; |
| 537 | uacpi_u8 sharing; |
| 538 | uacpi_u8 direction; |
| 539 | uacpi_u8 type; |
| 540 | uacpi_u32 value; |
| 541 | uacpi_u16 pin_table_length; |
| 542 | uacpi_u16 vendor_data_length; |
| 543 | uacpi_resource_source source; |
| 544 | uacpi_u16 *pin_table; |
| 545 | uacpi_u8 *vendor_data; |
| 546 | } uacpi_resource_pin_configuration; |
| 547 | |
| 548 | typedef struct uacpi_resource_label { |
| 549 | uacpi_u16 length; |
| 550 | const uacpi_char *string; |
| 551 | } uacpi_resource_label; |
| 552 | |
| 553 | typedef struct uacpi_resource_pin_group { |
| 554 | uacpi_u8 revision_id; |
| 555 | uacpi_u8 direction; |
| 556 | uacpi_u16 pin_table_length; |
| 557 | uacpi_u16 vendor_data_length; |
| 558 | uacpi_resource_label label; |
| 559 | uacpi_u16 *pin_table; |
| 560 | uacpi_u8 *vendor_data; |
| 561 | } uacpi_resource_pin_group; |
| 562 | |
| 563 | typedef struct uacpi_resource_pin_group_function { |
| 564 | uacpi_u8 revision_id; |
| 565 | uacpi_u8 sharing; |
| 566 | uacpi_u8 direction; |
| 567 | uacpi_u16 function; |
| 568 | uacpi_u16 vendor_data_length; |
| 569 | uacpi_resource_source source; |
| 570 | uacpi_resource_label label; |
| 571 | uacpi_u8 *vendor_data; |
| 572 | } uacpi_resource_pin_group_function; |
| 573 | |
| 574 | typedef struct uacpi_resource_pin_group_configuration { |
| 575 | uacpi_u8 revision_id; |
| 576 | uacpi_u8 sharing; |
| 577 | uacpi_u8 direction; |
| 578 | uacpi_u8 type; |
| 579 | uacpi_u32 value; |
| 580 | uacpi_u16 vendor_data_length; |
| 581 | uacpi_resource_source source; |
| 582 | uacpi_resource_label label; |
| 583 | uacpi_u8 *vendor_data; |
| 584 | } uacpi_resource_pin_group_configuration; |
| 585 | |
| 586 | // scale |
| 587 | #define UACPI_SCALE_HZ 0b00 |
| 588 | #define UACPI_SCALE_KHZ 0b01 |
| 589 | #define UACPI_SCALE_MHZ 0b10 |
| 590 | |
| 591 | // frequency |
| 592 | #define UACPI_FREQUENCY_FIXED 0x0 |
| 593 | #define UACPI_FREQUENCY_VARIABLE 0x1 |
| 594 | |
| 595 | typedef struct uacpi_resource_clock_input { |
| 596 | uacpi_u8 revision_id; |
| 597 | uacpi_u8 frequency; |
| 598 | uacpi_u8 scale; |
| 599 | uacpi_u16 divisor; |
| 600 | uacpi_u32 numerator; |
| 601 | uacpi_resource_source source; |
| 602 | } uacpi_resource_clock_input; |
| 603 | |
| 604 | typedef struct uacpi_resource { |
| 605 | uacpi_u32 type; |
| 606 | uacpi_u32 length; |
| 607 | |
| 608 | union { |
| 609 | uacpi_resource_irq irq; |
| 610 | uacpi_resource_extended_irq extended_irq; |
| 611 | uacpi_resource_dma dma; |
| 612 | uacpi_resource_fixed_dma fixed_dma; |
| 613 | uacpi_resource_io io; |
| 614 | uacpi_resource_fixed_io fixed_io; |
| 615 | uacpi_resource_address16 address16; |
| 616 | uacpi_resource_address32 address32; |
| 617 | uacpi_resource_address64 address64; |
| 618 | uacpi_resource_address64_extended address64_extended; |
| 619 | uacpi_resource_memory24 memory24; |
| 620 | uacpi_resource_memory32 memory32; |
| 621 | uacpi_resource_fixed_memory32 fixed_memory32; |
| 622 | uacpi_resource_start_dependent start_dependent; |
| 623 | uacpi_resource_vendor vendor; |
| 624 | uacpi_resource_vendor_typed vendor_typed; |
| 625 | uacpi_resource_generic_register generic_register; |
| 626 | uacpi_resource_gpio_connection gpio_connection; |
| 627 | uacpi_resource_serial_bus_common serial_bus_common; |
| 628 | uacpi_resource_i2c_connection i2c_connection; |
| 629 | uacpi_resource_spi_connection spi_connection; |
| 630 | uacpi_resource_uart_connection uart_connection; |
| 631 | uacpi_resource_csi2_connection csi2_connection; |
| 632 | uacpi_resource_pin_function pin_function; |
| 633 | uacpi_resource_pin_configuration pin_configuration; |
| 634 | uacpi_resource_pin_group pin_group; |
| 635 | uacpi_resource_pin_group_function pin_group_function; |
| 636 | uacpi_resource_pin_group_configuration pin_group_configuration; |
| 637 | uacpi_resource_clock_input clock_input; |
| 638 | }; |
| 639 | } uacpi_resource; |
| 640 | |
| 641 | #define UACPI_NEXT_RESOURCE(cur) \ |
| 642 | ((uacpi_resource*)((uacpi_u8*)(cur) + (cur)->length)) |
| 643 | |
| 644 | typedef struct uacpi_resources { |
| 645 | /** |
| 646 | * Length of the 'entries' array in BYTES (NOT the count of resources), |
| 647 | * see comment above 'entries' for more information. |
| 648 | */ |
| 649 | uacpi_size length; |
| 650 | |
| 651 | /** |
| 652 | * Resources are variable length! See UACPI_NEXT_RESOURCE to see how to |
| 653 | * retrieve the next resource. You can alternatively use |
| 654 | * uacpi_for_each_resource instead of iterating manually. |
| 655 | * |
| 656 | * Resources are guaranteed to be naturally aligned and are always |
| 657 | * terminated by a resource of type UACPI_RESOURCE_TYPE_END_TAG. |
| 658 | */ |
| 659 | uacpi_resource *entries; |
| 660 | } uacpi_resources; |
| 661 | void uacpi_free_resources(uacpi_resources*); |
| 662 | |
| 663 | typedef uacpi_iteration_decision (*uacpi_resource_iteration_callback) |
| 664 | (void *user, uacpi_resource *resource); |
| 665 | |
| 666 | /** |
| 667 | * Evaluate the _CRS method for a 'device' and get the returned resource list |
| 668 | * via 'out_resources'. |
| 669 | * |
| 670 | * NOTE: the returned buffer must be released via uacpi_free_resources() |
| 671 | * |
| 672 | * If you don't need to keep the resource array for later use you can |
| 673 | * uacpi_for_each_device_resource(device, "_CRS", ...) instead, which takes |
| 674 | * care of iteration & memory management on its own. |
| 675 | */ |
| 676 | uacpi_status uacpi_get_current_resources( |
| 677 | uacpi_namespace_node *device, uacpi_resources **out_resources |
| 678 | ); |
| 679 | |
| 680 | /** |
| 681 | * Evaluate the _PRS method for a 'device' and get the returned resource list |
| 682 | * via 'out_resources'. |
| 683 | * |
| 684 | * NOTE: the returned buffer must be released via uacpi_free_resources() |
| 685 | * |
| 686 | * If you don't need to keep the resource array for later use you can |
| 687 | * uacpi_for_each_device_resource(device, "_PRS", ...) instead, which takes |
| 688 | * care of iteration & memory management on its own. |
| 689 | */ |
| 690 | uacpi_status uacpi_get_possible_resources( |
| 691 | uacpi_namespace_node *device, uacpi_resources **out_resources |
| 692 | ); |
| 693 | |
| 694 | /** |
| 695 | * Evaluate an arbitrary method that is expected to return an AML resource |
| 696 | * buffer for a 'device' and get the returned resource list via 'out_resources'. |
| 697 | * |
| 698 | * NOTE: the returned buffer must be released via uacpi_free_resources() |
| 699 | * |
| 700 | * If you don't need to keep the resource array for later use you can |
| 701 | * uacpi_for_each_device_resource(device, method, ...) instead, which takes |
| 702 | * care of iteration & memory management on its own. |
| 703 | */ |
| 704 | uacpi_status uacpi_get_device_resources( |
| 705 | uacpi_namespace_node *device, const uacpi_char *method, |
| 706 | uacpi_resources **out_resources |
| 707 | ); |
| 708 | |
| 709 | /** |
| 710 | * Set the configuration to be used by the 'device' by calling its _SRS method. |
| 711 | * |
| 712 | * Note that this expects 'resources' in the normal 'uacpi_resources' format, |
| 713 | * and not the raw AML resources bytestream, the conversion to the latter is |
| 714 | * done automatically by this API. If you want to _SRS a raw AML resources |
| 715 | * bytestream, use 'uacpi_execute' or similar API directly. |
| 716 | */ |
| 717 | uacpi_status uacpi_set_resources( |
| 718 | uacpi_namespace_node *device, uacpi_resources *resources |
| 719 | ); |
| 720 | |
| 721 | /** |
| 722 | * A convenience helper for iterating over the resource list returned by any |
| 723 | * of the uacpi_get_*_resources functions. |
| 724 | */ |
| 725 | uacpi_status uacpi_for_each_resource( |
| 726 | uacpi_resources *resources, uacpi_resource_iteration_callback cb, void *user |
| 727 | ); |
| 728 | |
| 729 | /** |
| 730 | * A shorthand for uacpi_get_device_resources() + uacpi_for_each_resource(). |
| 731 | * |
| 732 | * Use if you don't actually want to save the 'resources' list, but simply want |
| 733 | * to iterate it once to extract the resources you care about and then free it |
| 734 | * right away. |
| 735 | */ |
| 736 | uacpi_status uacpi_for_each_device_resource( |
| 737 | uacpi_namespace_node *device, const uacpi_char *method, |
| 738 | uacpi_resource_iteration_callback cb, void *user |
| 739 | ); |
| 740 | |
| 741 | /** |
| 742 | * Convert a single AML-encoded resource to native format. |
| 743 | * |
| 744 | * This should be used for converting Connection() fields (passed during IO on |
| 745 | * GeneralPurposeIO or GenericSerialBus operation regions) or other similar |
| 746 | * buffers with only one resource to native format. |
| 747 | * |
| 748 | * NOTE: the returned buffer must be released via uacpi_free_resource() |
| 749 | */ |
| 750 | uacpi_status uacpi_get_resource_from_buffer( |
| 751 | uacpi_data_view aml_buffer, uacpi_resource **out_resource |
| 752 | ); |
| 753 | void uacpi_free_resource(uacpi_resource*); |
| 754 | |
| 755 | #endif // !UACPI_BAREBONES_MODE |
| 756 | |
| 757 | #ifdef __cplusplus |
| 758 | } |
| 759 | #endif |
| 760 | |