Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Helpers for ACPI table generation |
| 4 | * |
| 5 | * Based on acpi.c from coreboot |
| 6 | * |
| 7 | * Copyright 2019 Google LLC |
| 8 | * |
| 9 | * Copyright (C) 2015, Saket Sinha <saket.sinha89@gmail.com> |
| 10 | * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com> |
| 11 | */ |
| 12 | |
| 13 | #ifndef __ACPI_TABLE_H__ |
| 14 | #define __ACPI_TABLE_H__ |
| 15 | |
Simon Glass | 2a2ebf8 | 2020-09-22 12:45:39 -0600 | [diff] [blame] | 16 | #include <dm/acpi.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 17 | |
Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 18 | #define RSDP_SIG "RSD PTR " /* RSDP pointer signature */ |
| 19 | #define OEM_ID "U-BOOT" /* U-Boot */ |
| 20 | #define OEM_TABLE_ID "U-BOOTBL" /* U-Boot Table */ |
| 21 | #define ASLC_ID "INTL" /* Intel ASL Compiler */ |
| 22 | |
Simon Glass | d262898 | 2020-09-22 12:45:09 -0600 | [diff] [blame] | 23 | /* TODO(sjg@chromium.org): Figure out how to get compiler revision */ |
| 24 | #define ASL_REVISION 0 |
| 25 | |
Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 26 | #define ACPI_RSDP_REV_ACPI_1_0 0 |
| 27 | #define ACPI_RSDP_REV_ACPI_2_0 2 |
| 28 | |
Simon Glass | 89c2798 | 2020-04-08 16:57:37 -0600 | [diff] [blame] | 29 | #if !defined(__ACPI__) |
| 30 | |
Simon Glass | ee3cb7c | 2020-09-22 12:45:41 -0600 | [diff] [blame] | 31 | #include <linux/bitops.h> |
| 32 | |
Simon Glass | 86e1778 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 33 | struct acpi_ctx; |
| 34 | |
Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 35 | /* |
| 36 | * RSDP (Root System Description Pointer) |
| 37 | * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum |
| 38 | */ |
| 39 | struct acpi_rsdp { |
| 40 | char signature[8]; /* RSDP signature */ |
| 41 | u8 checksum; /* Checksum of the first 20 bytes */ |
| 42 | char oem_id[6]; /* OEM ID */ |
| 43 | u8 revision; /* 0 for ACPI 1.0, others 2 */ |
| 44 | u32 rsdt_address; /* Physical address of RSDT (32 bits) */ |
| 45 | u32 length; /* Total RSDP length (incl. extended part) */ |
| 46 | u64 xsdt_address; /* Physical address of XSDT (64 bits) */ |
| 47 | u8 ext_checksum; /* Checksum of the whole table */ |
| 48 | u8 reserved[3]; |
| 49 | }; |
| 50 | |
| 51 | /* Generic ACPI header, provided by (almost) all tables */ |
| 52 | struct __packed acpi_table_header { |
Simon Glass | 2a2ebf8 | 2020-09-22 12:45:39 -0600 | [diff] [blame] | 53 | char signature[ACPI_NAME_LEN]; /* ACPI signature (4 ASCII chars) */ |
Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 54 | u32 length; /* Table length in bytes (incl. header) */ |
| 55 | u8 revision; /* Table version (not ACPI version!) */ |
| 56 | volatile u8 checksum; /* To make sum of entire table == 0 */ |
| 57 | char oem_id[6]; /* OEM identification */ |
| 58 | char oem_table_id[8]; /* OEM table identification */ |
| 59 | u32 oem_revision; /* OEM revision number */ |
| 60 | char aslc_id[4]; /* ASL compiler vendor ID */ |
| 61 | u32 aslc_revision; /* ASL compiler revision number */ |
| 62 | }; |
| 63 | |
Simon Glass | d262898 | 2020-09-22 12:45:09 -0600 | [diff] [blame] | 64 | struct acpi_gen_regaddr { |
| 65 | u8 space_id; /* Address space ID */ |
| 66 | u8 bit_width; /* Register size in bits */ |
| 67 | u8 bit_offset; /* Register bit offset */ |
| 68 | u8 access_size; /* Access size */ |
| 69 | u32 addrl; /* Register address, low 32 bits */ |
| 70 | u32 addrh; /* Register address, high 32 bits */ |
| 71 | }; |
| 72 | |
Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 73 | /* A maximum number of 32 ACPI tables ought to be enough for now */ |
| 74 | #define MAX_ACPI_TABLES 32 |
| 75 | |
| 76 | /* RSDT (Root System Description Table) */ |
| 77 | struct acpi_rsdt { |
| 78 | struct acpi_table_header header; |
| 79 | u32 entry[MAX_ACPI_TABLES]; |
| 80 | }; |
| 81 | |
| 82 | /* XSDT (Extended System Description Table) */ |
| 83 | struct acpi_xsdt { |
| 84 | struct acpi_table_header header; |
| 85 | u64 entry[MAX_ACPI_TABLES]; |
| 86 | }; |
| 87 | |
Simon Glass | d262898 | 2020-09-22 12:45:09 -0600 | [diff] [blame] | 88 | /* HPET timers */ |
| 89 | struct __packed acpi_hpet { |
| 90 | struct acpi_table_header header; |
| 91 | u32 id; |
| 92 | struct acpi_gen_regaddr addr; |
| 93 | u8 number; |
| 94 | u16 min_tick; |
| 95 | u8 attributes; |
| 96 | }; |
| 97 | |
Simon Glass | 9179c35 | 2020-09-22 12:45:32 -0600 | [diff] [blame] | 98 | struct __packed acpi_tpm2 { |
| 99 | struct acpi_table_header header; |
| 100 | u16 platform_class; |
| 101 | u8 reserved[2]; |
| 102 | u64 control_area; |
| 103 | u32 start_method; |
| 104 | u8 msp[12]; |
| 105 | u32 laml; |
| 106 | u64 lasa; |
| 107 | }; |
| 108 | |
Simon Glass | 77bb1c6 | 2020-09-22 12:45:33 -0600 | [diff] [blame] | 109 | struct __packed acpi_tcpa { |
| 110 | struct acpi_table_header header; |
| 111 | u16 platform_class; |
| 112 | u32 laml; |
| 113 | u64 lasa; |
| 114 | }; |
| 115 | |
Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 116 | /* FADT Preferred Power Management Profile */ |
| 117 | enum acpi_pm_profile { |
| 118 | ACPI_PM_UNSPECIFIED = 0, |
| 119 | ACPI_PM_DESKTOP, |
| 120 | ACPI_PM_MOBILE, |
| 121 | ACPI_PM_WORKSTATION, |
| 122 | ACPI_PM_ENTERPRISE_SERVER, |
| 123 | ACPI_PM_SOHO_SERVER, |
| 124 | ACPI_PM_APPLIANCE_PC, |
| 125 | ACPI_PM_PERFORMANCE_SERVER, |
| 126 | ACPI_PM_TABLET |
| 127 | }; |
| 128 | |
| 129 | /* FADT flags for p_lvl2_lat and p_lvl3_lat */ |
| 130 | #define ACPI_FADT_C2_NOT_SUPPORTED 101 |
| 131 | #define ACPI_FADT_C3_NOT_SUPPORTED 1001 |
| 132 | |
| 133 | /* FADT Boot Architecture Flags */ |
| 134 | #define ACPI_FADT_LEGACY_FREE 0x00 |
| 135 | #define ACPI_FADT_LEGACY_DEVICES BIT(0) |
| 136 | #define ACPI_FADT_8042 BIT(1) |
| 137 | #define ACPI_FADT_VGA_NOT_PRESENT BIT(2) |
| 138 | #define ACPI_FADT_MSI_NOT_SUPPORTED BIT(3) |
| 139 | #define ACPI_FADT_NO_PCIE_ASPM_CONTROL BIT(4) |
| 140 | |
| 141 | /* FADT Feature Flags */ |
| 142 | #define ACPI_FADT_WBINVD BIT(0) |
| 143 | #define ACPI_FADT_WBINVD_FLUSH BIT(1) |
| 144 | #define ACPI_FADT_C1_SUPPORTED BIT(2) |
| 145 | #define ACPI_FADT_C2_MP_SUPPORTED BIT(3) |
| 146 | #define ACPI_FADT_POWER_BUTTON BIT(4) |
| 147 | #define ACPI_FADT_SLEEP_BUTTON BIT(5) |
| 148 | #define ACPI_FADT_FIXED_RTC BIT(6) |
| 149 | #define ACPI_FADT_S4_RTC_WAKE BIT(7) |
| 150 | #define ACPI_FADT_32BIT_TIMER BIT(8) |
| 151 | #define ACPI_FADT_DOCKING_SUPPORTED BIT(9) |
| 152 | #define ACPI_FADT_RESET_REGISTER BIT(10) |
| 153 | #define ACPI_FADT_SEALED_CASE BIT(11) |
| 154 | #define ACPI_FADT_HEADLESS BIT(12) |
| 155 | #define ACPI_FADT_SLEEP_TYPE BIT(13) |
| 156 | #define ACPI_FADT_PCI_EXPRESS_WAKE BIT(14) |
| 157 | #define ACPI_FADT_PLATFORM_CLOCK BIT(15) |
| 158 | #define ACPI_FADT_S4_RTC_VALID BIT(16) |
| 159 | #define ACPI_FADT_REMOTE_POWER_ON BIT(17) |
| 160 | #define ACPI_FADT_APIC_CLUSTER BIT(18) |
| 161 | #define ACPI_FADT_APIC_PHYSICAL BIT(19) |
| 162 | #define ACPI_FADT_HW_REDUCED_ACPI BIT(20) |
| 163 | #define ACPI_FADT_LOW_PWR_IDLE_S0 BIT(21) |
| 164 | |
| 165 | enum acpi_address_space_type { |
| 166 | ACPI_ADDRESS_SPACE_MEMORY = 0, /* System memory */ |
| 167 | ACPI_ADDRESS_SPACE_IO, /* System I/O */ |
| 168 | ACPI_ADDRESS_SPACE_PCI, /* PCI config space */ |
| 169 | ACPI_ADDRESS_SPACE_EC, /* Embedded controller */ |
| 170 | ACPI_ADDRESS_SPACE_SMBUS, /* SMBus */ |
| 171 | ACPI_ADDRESS_SPACE_PCC = 0x0a, /* Platform Comm. Channel */ |
| 172 | ACPI_ADDRESS_SPACE_FIXED = 0x7f /* Functional fixed hardware */ |
| 173 | }; |
| 174 | |
| 175 | enum acpi_address_space_size { |
| 176 | ACPI_ACCESS_SIZE_UNDEFINED = 0, |
| 177 | ACPI_ACCESS_SIZE_BYTE_ACCESS, |
| 178 | ACPI_ACCESS_SIZE_WORD_ACCESS, |
| 179 | ACPI_ACCESS_SIZE_DWORD_ACCESS, |
| 180 | ACPI_ACCESS_SIZE_QWORD_ACCESS |
| 181 | }; |
| 182 | |
Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 183 | /* FADT (Fixed ACPI Description Table) */ |
| 184 | struct __packed acpi_fadt { |
| 185 | struct acpi_table_header header; |
| 186 | u32 firmware_ctrl; |
| 187 | u32 dsdt; |
| 188 | u8 res1; |
| 189 | u8 preferred_pm_profile; |
| 190 | u16 sci_int; |
| 191 | u32 smi_cmd; |
| 192 | u8 acpi_enable; |
| 193 | u8 acpi_disable; |
| 194 | u8 s4bios_req; |
| 195 | u8 pstate_cnt; |
| 196 | u32 pm1a_evt_blk; |
| 197 | u32 pm1b_evt_blk; |
| 198 | u32 pm1a_cnt_blk; |
| 199 | u32 pm1b_cnt_blk; |
| 200 | u32 pm2_cnt_blk; |
| 201 | u32 pm_tmr_blk; |
| 202 | u32 gpe0_blk; |
| 203 | u32 gpe1_blk; |
| 204 | u8 pm1_evt_len; |
| 205 | u8 pm1_cnt_len; |
| 206 | u8 pm2_cnt_len; |
| 207 | u8 pm_tmr_len; |
| 208 | u8 gpe0_blk_len; |
| 209 | u8 gpe1_blk_len; |
| 210 | u8 gpe1_base; |
| 211 | u8 cst_cnt; |
| 212 | u16 p_lvl2_lat; |
| 213 | u16 p_lvl3_lat; |
| 214 | u16 flush_size; |
| 215 | u16 flush_stride; |
| 216 | u8 duty_offset; |
| 217 | u8 duty_width; |
| 218 | u8 day_alrm; |
| 219 | u8 mon_alrm; |
| 220 | u8 century; |
| 221 | u16 iapc_boot_arch; |
| 222 | u8 res2; |
| 223 | u32 flags; |
| 224 | struct acpi_gen_regaddr reset_reg; |
| 225 | u8 reset_value; |
| 226 | u16 arm_boot_arch; |
| 227 | u8 minor_revision; |
| 228 | u32 x_firmware_ctl_l; |
| 229 | u32 x_firmware_ctl_h; |
| 230 | u32 x_dsdt_l; |
| 231 | u32 x_dsdt_h; |
| 232 | struct acpi_gen_regaddr x_pm1a_evt_blk; |
| 233 | struct acpi_gen_regaddr x_pm1b_evt_blk; |
| 234 | struct acpi_gen_regaddr x_pm1a_cnt_blk; |
| 235 | struct acpi_gen_regaddr x_pm1b_cnt_blk; |
| 236 | struct acpi_gen_regaddr x_pm2_cnt_blk; |
| 237 | struct acpi_gen_regaddr x_pm_tmr_blk; |
| 238 | struct acpi_gen_regaddr x_gpe0_blk; |
| 239 | struct acpi_gen_regaddr x_gpe1_blk; |
| 240 | }; |
| 241 | |
Simon Glass | 91fe8b7 | 2020-04-08 16:57:38 -0600 | [diff] [blame] | 242 | /* FADT TABLE Revision values - note these do not match the ACPI revision */ |
| 243 | #define ACPI_FADT_REV_ACPI_1_0 1 |
| 244 | #define ACPI_FADT_REV_ACPI_2_0 3 |
| 245 | #define ACPI_FADT_REV_ACPI_3_0 4 |
| 246 | #define ACPI_FADT_REV_ACPI_4_0 4 |
| 247 | #define ACPI_FADT_REV_ACPI_5_0 5 |
| 248 | #define ACPI_FADT_REV_ACPI_6_0 6 |
| 249 | |
| 250 | /* MADT TABLE Revision values - note these do not match the ACPI revision */ |
| 251 | #define ACPI_MADT_REV_ACPI_3_0 2 |
| 252 | #define ACPI_MADT_REV_ACPI_4_0 3 |
| 253 | #define ACPI_MADT_REV_ACPI_5_0 3 |
| 254 | #define ACPI_MADT_REV_ACPI_6_0 5 |
| 255 | |
| 256 | #define ACPI_MCFG_REV_ACPI_3_0 1 |
| 257 | |
| 258 | /* IVRS Revision Field */ |
| 259 | #define IVRS_FORMAT_FIXED 0x01 /* Type 10h & 11h only */ |
| 260 | #define IVRS_FORMAT_MIXED 0x02 /* Type 10h, 11h, & 40h */ |
| 261 | |
Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 262 | /* FACS flags */ |
| 263 | #define ACPI_FACS_S4BIOS_F BIT(0) |
| 264 | #define ACPI_FACS_64BIT_WAKE_F BIT(1) |
| 265 | |
| 266 | /* FACS (Firmware ACPI Control Structure) */ |
| 267 | struct acpi_facs { |
Simon Glass | 2a2ebf8 | 2020-09-22 12:45:39 -0600 | [diff] [blame] | 268 | char signature[ACPI_NAME_LEN]; /* "FACS" */ |
Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 269 | u32 length; /* Length in bytes (>= 64) */ |
| 270 | u32 hardware_signature; /* Hardware signature */ |
| 271 | u32 firmware_waking_vector; /* Firmware waking vector */ |
| 272 | u32 global_lock; /* Global lock */ |
| 273 | u32 flags; /* FACS flags */ |
| 274 | u32 x_firmware_waking_vector_l; /* X FW waking vector, low */ |
| 275 | u32 x_firmware_waking_vector_h; /* X FW waking vector, high */ |
| 276 | u8 version; /* Version 2 */ |
| 277 | u8 res1[3]; |
| 278 | u32 ospm_flags; /* OSPM enabled flags */ |
| 279 | u8 res2[24]; |
| 280 | }; |
| 281 | |
| 282 | /* MADT flags */ |
| 283 | #define ACPI_MADT_PCAT_COMPAT BIT(0) |
| 284 | |
| 285 | /* MADT (Multiple APIC Description Table) */ |
| 286 | struct acpi_madt { |
| 287 | struct acpi_table_header header; |
| 288 | u32 lapic_addr; /* Local APIC address */ |
| 289 | u32 flags; /* Multiple APIC flags */ |
| 290 | }; |
| 291 | |
| 292 | /* MADT: APIC Structure Type*/ |
| 293 | enum acpi_apic_types { |
| 294 | ACPI_APIC_LAPIC = 0, /* Processor local APIC */ |
| 295 | ACPI_APIC_IOAPIC, /* I/O APIC */ |
| 296 | ACPI_APIC_IRQ_SRC_OVERRIDE, /* Interrupt source override */ |
| 297 | ACPI_APIC_NMI_SRC, /* NMI source */ |
| 298 | ACPI_APIC_LAPIC_NMI, /* Local APIC NMI */ |
| 299 | ACPI_APIC_LAPIC_ADDR_OVERRIDE, /* Local APIC address override */ |
| 300 | ACPI_APIC_IOSAPIC, /* I/O SAPIC */ |
| 301 | ACPI_APIC_LSAPIC, /* Local SAPIC */ |
| 302 | ACPI_APIC_PLATFORM_IRQ_SRC, /* Platform interrupt sources */ |
| 303 | ACPI_APIC_LX2APIC, /* Processor local x2APIC */ |
| 304 | ACPI_APIC_LX2APIC_NMI, /* Local x2APIC NMI */ |
| 305 | }; |
| 306 | |
| 307 | /* MADT: Processor Local APIC Structure */ |
| 308 | |
| 309 | #define LOCAL_APIC_FLAG_ENABLED BIT(0) |
| 310 | |
| 311 | struct acpi_madt_lapic { |
| 312 | u8 type; /* Type (0) */ |
| 313 | u8 length; /* Length in bytes (8) */ |
| 314 | u8 processor_id; /* ACPI processor ID */ |
| 315 | u8 apic_id; /* Local APIC ID */ |
| 316 | u32 flags; /* Local APIC flags */ |
| 317 | }; |
| 318 | |
| 319 | /* MADT: I/O APIC Structure */ |
| 320 | struct acpi_madt_ioapic { |
| 321 | u8 type; /* Type (1) */ |
| 322 | u8 length; /* Length in bytes (12) */ |
| 323 | u8 ioapic_id; /* I/O APIC ID */ |
| 324 | u8 reserved; |
| 325 | u32 ioapic_addr; /* I/O APIC address */ |
| 326 | u32 gsi_base; /* Global system interrupt base */ |
| 327 | }; |
| 328 | |
| 329 | /* MADT: Interrupt Source Override Structure */ |
| 330 | struct __packed acpi_madt_irqoverride { |
| 331 | u8 type; /* Type (2) */ |
| 332 | u8 length; /* Length in bytes (10) */ |
| 333 | u8 bus; /* ISA (0) */ |
| 334 | u8 source; /* Bus-relative int. source (IRQ) */ |
| 335 | u32 gsirq; /* Global system interrupt */ |
| 336 | u16 flags; /* MPS INTI flags */ |
| 337 | }; |
| 338 | |
| 339 | /* MADT: Local APIC NMI Structure */ |
| 340 | struct __packed acpi_madt_lapic_nmi { |
| 341 | u8 type; /* Type (4) */ |
| 342 | u8 length; /* Length in bytes (6) */ |
| 343 | u8 processor_id; /* ACPI processor ID */ |
| 344 | u16 flags; /* MPS INTI flags */ |
| 345 | u8 lint; /* Local APIC LINT# */ |
| 346 | }; |
| 347 | |
| 348 | /* MCFG (PCI Express MMIO config space BAR description table) */ |
| 349 | struct acpi_mcfg { |
| 350 | struct acpi_table_header header; |
| 351 | u8 reserved[8]; |
| 352 | }; |
| 353 | |
| 354 | struct acpi_mcfg_mmconfig { |
| 355 | u32 base_address_l; |
| 356 | u32 base_address_h; |
| 357 | u16 pci_segment_group_number; |
| 358 | u8 start_bus_number; |
| 359 | u8 end_bus_number; |
| 360 | u8 reserved[4]; |
| 361 | }; |
| 362 | |
| 363 | /* PM1_CNT bit defines */ |
| 364 | #define PM1_CNT_SCI_EN BIT(0) |
| 365 | |
| 366 | /* ACPI global NVS structure */ |
| 367 | struct acpi_global_nvs; |
| 368 | |
| 369 | /* CSRT (Core System Resource Table) */ |
| 370 | struct acpi_csrt { |
| 371 | struct acpi_table_header header; |
| 372 | }; |
| 373 | |
| 374 | struct acpi_csrt_group { |
| 375 | u32 length; |
| 376 | u32 vendor_id; |
| 377 | u32 subvendor_id; |
| 378 | u16 device_id; |
| 379 | u16 subdevice_id; |
| 380 | u16 revision; |
| 381 | u16 reserved; |
| 382 | u32 shared_info_length; |
| 383 | }; |
| 384 | |
| 385 | struct acpi_csrt_shared_info { |
| 386 | u16 major_version; |
| 387 | u16 minor_version; |
| 388 | u32 mmio_base_low; |
| 389 | u32 mmio_base_high; |
| 390 | u32 gsi_interrupt; |
| 391 | u8 interrupt_polarity; |
| 392 | u8 interrupt_mode; |
| 393 | u8 num_channels; |
| 394 | u8 dma_address_width; |
| 395 | u16 base_request_line; |
| 396 | u16 num_handshake_signals; |
| 397 | u32 max_block_size; |
| 398 | }; |
| 399 | |
Simon Glass | 540f0ba | 2020-09-22 12:45:16 -0600 | [diff] [blame] | 400 | /* Port types for ACPI _UPC object */ |
| 401 | enum acpi_upc_type { |
| 402 | UPC_TYPE_A, |
| 403 | UPC_TYPE_MINI_AB, |
| 404 | UPC_TYPE_EXPRESSCARD, |
| 405 | UPC_TYPE_USB3_A, |
| 406 | UPC_TYPE_USB3_B, |
| 407 | UPC_TYPE_USB3_MICRO_B, |
| 408 | UPC_TYPE_USB3_MICRO_AB, |
| 409 | UPC_TYPE_USB3_POWER_B, |
| 410 | UPC_TYPE_C_USB2_ONLY, |
| 411 | UPC_TYPE_C_USB2_SS_SWITCH, |
| 412 | UPC_TYPE_C_USB2_SS, |
| 413 | UPC_TYPE_PROPRIETARY = 0xff, |
| 414 | /* |
| 415 | * The following types are not directly defined in the ACPI |
| 416 | * spec but are used by coreboot to identify a USB device type. |
| 417 | */ |
| 418 | UPC_TYPE_INTERNAL = 0xff, |
| 419 | UPC_TYPE_UNUSED, |
| 420 | UPC_TYPE_HUB |
| 421 | }; |
| 422 | |
| 423 | enum dev_scope_type { |
| 424 | SCOPE_PCI_ENDPOINT = 1, |
| 425 | SCOPE_PCI_SUB = 2, |
| 426 | SCOPE_IOAPIC = 3, |
| 427 | SCOPE_MSI_HPET = 4, |
| 428 | SCOPE_ACPI_NAMESPACE_DEVICE = 5 |
| 429 | }; |
| 430 | |
| 431 | struct __packed dev_scope { |
| 432 | u8 type; |
| 433 | u8 length; |
| 434 | u8 reserved[2]; |
| 435 | u8 enumeration; |
| 436 | u8 start_bus; |
| 437 | struct { |
| 438 | u8 dev; |
| 439 | u8 fn; |
| 440 | } __packed path[0]; |
| 441 | }; |
| 442 | |
Simon Glass | bfeb5d4 | 2020-04-08 16:57:39 -0600 | [diff] [blame] | 443 | enum dmar_type { |
| 444 | DMAR_DRHD = 0, |
| 445 | DMAR_RMRR = 1, |
| 446 | DMAR_ATSR = 2, |
| 447 | DMAR_RHSA = 3, |
| 448 | DMAR_ANDD = 4 |
| 449 | }; |
| 450 | |
| 451 | enum { |
| 452 | DRHD_INCLUDE_PCI_ALL = BIT(0) |
| 453 | }; |
| 454 | |
| 455 | enum dmar_flags { |
| 456 | DMAR_INTR_REMAP = BIT(0), |
| 457 | DMAR_X2APIC_OPT_OUT = BIT(1), |
| 458 | DMAR_CTRL_PLATFORM_OPT_IN_FLAG = BIT(2), |
| 459 | }; |
| 460 | |
| 461 | struct dmar_entry { |
| 462 | u16 type; |
| 463 | u16 length; |
| 464 | u8 flags; |
| 465 | u8 reserved; |
| 466 | u16 segment; |
| 467 | u64 bar; |
| 468 | }; |
| 469 | |
| 470 | struct dmar_rmrr_entry { |
| 471 | u16 type; |
| 472 | u16 length; |
| 473 | u16 reserved; |
| 474 | u16 segment; |
| 475 | u64 bar; |
| 476 | u64 limit; |
| 477 | }; |
| 478 | |
| 479 | /* DMAR (DMA Remapping Reporting Structure) */ |
| 480 | struct __packed acpi_dmar { |
| 481 | struct acpi_table_header header; |
| 482 | u8 host_address_width; |
| 483 | u8 flags; |
| 484 | u8 reserved[10]; |
| 485 | struct dmar_entry structure[0]; |
| 486 | }; |
| 487 | |
Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 488 | /* DBG2 definitions are partially used for SPCR interface_type */ |
| 489 | |
| 490 | /* Types for port_type field */ |
| 491 | |
| 492 | #define ACPI_DBG2_SERIAL_PORT 0x8000 |
| 493 | #define ACPI_DBG2_1394_PORT 0x8001 |
| 494 | #define ACPI_DBG2_USB_PORT 0x8002 |
| 495 | #define ACPI_DBG2_NET_PORT 0x8003 |
| 496 | |
| 497 | /* Subtypes for port_subtype field */ |
| 498 | |
| 499 | #define ACPI_DBG2_16550_COMPATIBLE 0x0000 |
| 500 | #define ACPI_DBG2_16550_SUBSET 0x0001 |
| 501 | #define ACPI_DBG2_ARM_PL011 0x0003 |
| 502 | #define ACPI_DBG2_ARM_SBSA_32BIT 0x000D |
| 503 | #define ACPI_DBG2_ARM_SBSA_GENERIC 0x000E |
| 504 | #define ACPI_DBG2_ARM_DCC 0x000F |
| 505 | #define ACPI_DBG2_BCM2835 0x0010 |
| 506 | |
| 507 | #define ACPI_DBG2_1394_STANDARD 0x0000 |
| 508 | |
| 509 | #define ACPI_DBG2_USB_XHCI 0x0000 |
| 510 | #define ACPI_DBG2_USB_EHCI 0x0001 |
| 511 | |
| 512 | #define ACPI_DBG2_UNKNOWN 0x00FF |
| 513 | |
Simon Glass | f37979e | 2020-09-22 12:45:10 -0600 | [diff] [blame] | 514 | /* DBG2: Microsoft Debug Port Table 2 header */ |
| 515 | struct __packed acpi_dbg2_header { |
| 516 | struct acpi_table_header header; |
| 517 | u32 devices_offset; |
| 518 | u32 devices_count; |
| 519 | }; |
| 520 | |
| 521 | /* DBG2: Microsoft Debug Port Table 2 device entry */ |
| 522 | struct __packed acpi_dbg2_device { |
| 523 | u8 revision; |
| 524 | u16 length; |
| 525 | u8 address_count; |
| 526 | u16 namespace_string_length; |
| 527 | u16 namespace_string_offset; |
| 528 | u16 oem_data_length; |
| 529 | u16 oem_data_offset; |
| 530 | u16 port_type; |
| 531 | u16 port_subtype; |
| 532 | u8 reserved[2]; |
| 533 | u16 base_address_offset; |
| 534 | u16 address_size_offset; |
| 535 | }; |
| 536 | |
Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 537 | /* SPCR (Serial Port Console Redirection table) */ |
| 538 | struct __packed acpi_spcr { |
| 539 | struct acpi_table_header header; |
| 540 | u8 interface_type; |
| 541 | u8 reserved[3]; |
| 542 | struct acpi_gen_regaddr serial_port; |
| 543 | u8 interrupt_type; |
| 544 | u8 pc_interrupt; |
| 545 | u32 interrupt; /* Global system interrupt */ |
| 546 | u8 baud_rate; |
| 547 | u8 parity; |
| 548 | u8 stop_bits; |
| 549 | u8 flow_control; |
| 550 | u8 terminal_type; |
| 551 | u8 reserved1; |
| 552 | u16 pci_device_id; /* Must be 0xffff if not PCI device */ |
| 553 | u16 pci_vendor_id; /* Must be 0xffff if not PCI device */ |
| 554 | u8 pci_bus; |
| 555 | u8 pci_device; |
| 556 | u8 pci_function; |
| 557 | u32 pci_flags; |
| 558 | u8 pci_segment; |
| 559 | u32 reserved2; |
| 560 | }; |
| 561 | |
Simon Glass | 91fe8b7 | 2020-04-08 16:57:38 -0600 | [diff] [blame] | 562 | /* Tables defined/reserved by ACPI and generated by U-Boot */ |
| 563 | enum acpi_tables { |
| 564 | ACPITAB_BERT, |
| 565 | ACPITAB_DBG2, |
| 566 | ACPITAB_DMAR, |
| 567 | ACPITAB_DSDT, |
| 568 | ACPITAB_ECDT, |
| 569 | ACPITAB_FACS, |
| 570 | ACPITAB_FADT, |
| 571 | ACPITAB_HEST, |
| 572 | ACPITAB_HPET, |
| 573 | ACPITAB_IVRS, |
| 574 | ACPITAB_MADT, |
| 575 | ACPITAB_MCFG, |
| 576 | ACPITAB_NHLT, |
| 577 | ACPITAB_RSDP, |
| 578 | ACPITAB_RSDT, |
| 579 | ACPITAB_SLIT, |
| 580 | ACPITAB_SPCR, |
| 581 | ACPITAB_SPMI, |
| 582 | ACPITAB_SRAT, |
| 583 | ACPITAB_SSDT, |
| 584 | ACPITAB_TCPA, |
| 585 | ACPITAB_TPM2, |
| 586 | ACPITAB_VFCT, |
| 587 | ACPITAB_XSDT, |
| 588 | |
| 589 | ACPITAB_COUNT, |
| 590 | }; |
| 591 | |
| 592 | /** |
| 593 | * acpi_get_table_revision() - Get the revision number generated for a table |
| 594 | * |
| 595 | * This keeps the version-number information in one place |
| 596 | * |
| 597 | * @table: ACPI table to check |
| 598 | * @return version number that U-Boot generates |
| 599 | */ |
| 600 | int acpi_get_table_revision(enum acpi_tables table); |
| 601 | |
Simon Glass | bfeb5d4 | 2020-04-08 16:57:39 -0600 | [diff] [blame] | 602 | /** |
| 603 | * acpi_create_dmar() - Create a DMA Remapping Reporting (DMAR) table |
| 604 | * |
| 605 | * @dmar: Place to put the table |
| 606 | * @flags: DMAR flags to use |
| 607 | * @return 0 if OK, -ve on error |
| 608 | */ |
| 609 | int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags); |
| 610 | |
Simon Glass | 93f7f82 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 611 | /** |
Simon Glass | f37979e | 2020-09-22 12:45:10 -0600 | [diff] [blame] | 612 | * acpi_create_dbg2() - Create a DBG2 table |
| 613 | * |
| 614 | * This table describes how to access the debug UART |
| 615 | * |
| 616 | * @dbg2: Place to put information |
| 617 | * @port_type: Serial port type (see ACPI_DBG2_...) |
| 618 | * @port_subtype: Serial port sub-type (see ACPI_DBG2_...) |
| 619 | * @address: ACPI address of port |
| 620 | * @address_size: Size of address space |
| 621 | * @device_path: Path of device (created using acpi_device_path()) |
| 622 | */ |
| 623 | void acpi_create_dbg2(struct acpi_dbg2_header *dbg2, |
| 624 | int port_type, int port_subtype, |
| 625 | struct acpi_gen_regaddr *address, uint32_t address_size, |
| 626 | const char *device_path); |
| 627 | |
| 628 | /** |
Simon Glass | 93f7f82 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 629 | * acpi_fill_header() - Set up a new table header |
| 630 | * |
| 631 | * This sets all fields except length, revision, checksum and aslc_revision |
| 632 | * |
| 633 | * @header: ACPI header to update |
| 634 | * @signature: Table signature to use (4 characters) |
| 635 | */ |
| 636 | void acpi_fill_header(struct acpi_table_header *header, char *signature); |
| 637 | |
Simon Glass | 86e1778 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 638 | /** |
| 639 | * acpi_align() - Align the ACPI output pointer to a 16-byte boundary |
| 640 | * |
| 641 | * @ctx: ACPI context |
| 642 | */ |
| 643 | void acpi_align(struct acpi_ctx *ctx); |
| 644 | |
| 645 | /** |
| 646 | * acpi_align64() - Align the ACPI output pointer to a 64-byte boundary |
| 647 | * |
| 648 | * @ctx: ACPI context |
| 649 | */ |
| 650 | void acpi_align64(struct acpi_ctx *ctx); |
| 651 | |
| 652 | /** |
| 653 | * acpi_inc() - Increment the ACPI output pointer by a bit |
| 654 | * |
| 655 | * The pointer is NOT aligned afterwards. |
| 656 | * |
| 657 | * @ctx: ACPI context |
| 658 | * @amount: Amount to increment by |
| 659 | */ |
| 660 | void acpi_inc(struct acpi_ctx *ctx, uint amount); |
| 661 | |
| 662 | /** |
| 663 | * acpi_inc_align() - Increment the ACPI output pointer by a bit and align |
| 664 | * |
| 665 | * The pointer is aligned afterwards to a 16-byte boundary |
| 666 | * |
| 667 | * @ctx: ACPI context |
| 668 | * @amount: Amount to increment by |
| 669 | */ |
| 670 | void acpi_inc_align(struct acpi_ctx *ctx, uint amount); |
| 671 | |
Simon Glass | 29b3511 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 672 | /** |
| 673 | * acpi_add_table() - Add a new table to the RSDP and XSDT |
| 674 | * |
| 675 | * @ctx: ACPI context |
| 676 | * @table: Table to add |
| 677 | * @return 0 if OK, -E2BIG if too many tables |
| 678 | */ |
| 679 | int acpi_add_table(struct acpi_ctx *ctx, void *table); |
| 680 | |
Simon Glass | 7e586f6 | 2020-04-26 09:19:51 -0600 | [diff] [blame] | 681 | /** |
| 682 | * acpi_setup_base_tables() - Set up context along with RSDP, RSDT and XSDT |
| 683 | * |
| 684 | * Set up the context with the given start position. Some basic tables are |
| 685 | * always needed, so set them up as well. |
| 686 | * |
| 687 | * @ctx: Context to set up |
| 688 | */ |
| 689 | void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start); |
| 690 | |
Simon Glass | d2cb7a2 | 2020-11-04 09:57:25 -0700 | [diff] [blame] | 691 | /** |
| 692 | * acpi_write_rsdp() - Write out an RSDP indicating where the ACPI tables are |
| 693 | * |
| 694 | * @rsdp: Address to write RSDP |
| 695 | * @rsdt: Address of RSDT |
| 696 | * @xsdt: Address of XSDT |
| 697 | */ |
| 698 | void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, |
| 699 | struct acpi_xsdt *xsdt); |
| 700 | |
Simon Glass | 89c2798 | 2020-04-08 16:57:37 -0600 | [diff] [blame] | 701 | #endif /* !__ACPI__*/ |
| 702 | |
Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 703 | #include <asm/acpi_table.h> |
| 704 | |
| 705 | #endif /* __ACPI_TABLE_H__ */ |