Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * coreboot ACPI support - headers and defines. |
| 5 | */ |
| 6 | |
Furquan Shaikh | 56eafbb | 2020-04-30 18:38:55 -0700 | [diff] [blame] | 7 | #ifndef __ACPI_ACPI_H__ |
| 8 | #define __ACPI_ACPI_H__ |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 9 | |
| 10 | /* |
| 11 | * The type and enable fields are common in ACPI, but the |
| 12 | * values themselves are hardware implementation defined. |
| 13 | */ |
| 14 | #if CONFIG(ACPI_INTEL_HARDWARE_SLEEP_VALUES) |
| 15 | #define SLP_EN (1 << 13) |
| 16 | #define SLP_TYP_SHIFT 10 |
| 17 | #define SLP_TYP (7 << SLP_TYP_SHIFT) |
| 18 | #define SLP_TYP_S0 0 |
| 19 | #define SLP_TYP_S1 1 |
| 20 | #define SLP_TYP_S3 5 |
| 21 | #define SLP_TYP_S4 6 |
| 22 | #define SLP_TYP_S5 7 |
| 23 | #elif CONFIG(ACPI_AMD_HARDWARE_SLEEP_VALUES) |
| 24 | #define SLP_EN (1 << 13) |
| 25 | #define SLP_TYP_SHIFT 10 |
| 26 | #define SLP_TYP (7 << SLP_TYP_SHIFT) |
| 27 | #define SLP_TYP_S0 0 |
| 28 | #define SLP_TYP_S1 1 |
| 29 | #define SLP_TYP_S3 3 |
| 30 | #define SLP_TYP_S4 4 |
| 31 | #define SLP_TYP_S5 5 |
| 32 | #endif |
| 33 | |
Duncan Laurie | 4247ba3 | 2020-05-27 12:26:41 -0700 | [diff] [blame] | 34 | /* ACPI Device Sleep States */ |
| 35 | #define ACPI_DEVICE_SLEEP_D0 0 |
| 36 | #define ACPI_DEVICE_SLEEP_D1 1 |
| 37 | #define ACPI_DEVICE_SLEEP_D2 2 |
| 38 | #define ACPI_DEVICE_SLEEP_D3 3 |
| 39 | #define ACPI_DEVICE_SLEEP_D3_HOT ACPI_DEVICE_SLEEP_D3 |
| 40 | #define ACPI_DEVICE_SLEEP_D3_COLD 4 |
| 41 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 42 | #define ACPI_TABLE_CREATOR "COREBOOT" /* Must be exactly 8 bytes long! */ |
| 43 | #define OEM_ID "COREv4" /* Must be exactly 6 bytes long! */ |
Elyes HAOUAS | 288426d | 2020-10-01 16:52:26 +0200 | [diff] [blame] | 44 | #define ACPI_DSDT_REV_1 0x01 /* DSDT revision: ACPI v1 */ |
Elyes HAOUAS | 7f53ec6 | 2020-10-05 16:33:52 +0200 | [diff] [blame] | 45 | #define ACPI_DSDT_REV_2 0x02 /* DSDT revision: ACPI v2.0 and greater */ |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 46 | |
| 47 | #if !defined(__ASSEMBLER__) && !defined(__ACPI__) |
| 48 | #include <commonlib/helpers.h> |
| 49 | #include <device/device.h> |
| 50 | #include <uuid.h> |
| 51 | #include <cper.h> |
Kyösti Mälkki | ac0dc4a | 2020-11-18 07:40:21 +0200 | [diff] [blame] | 52 | #include <romstage_handoff.h> |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 53 | #include <types.h> |
| 54 | |
| 55 | #define RSDP_SIG "RSD PTR " /* RSDT pointer signature */ |
| 56 | #define ASLC "CORE" /* Must be exactly 4 bytes long! */ |
| 57 | |
Raul E Rangel | 1c0b9f2 | 2020-07-09 11:58:38 -0600 | [diff] [blame] | 58 | #define ACPI_NAME_BUFFER_SIZE 5 /* 4 chars + 1 NUL */ |
| 59 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 60 | /* |
| 61 | * The assigned ACPI ID for the coreboot project is 'BOOT' |
| 62 | * http://www.uefi.org/acpi_id_list |
| 63 | */ |
| 64 | #define COREBOOT_ACPI_ID "BOOT" /* ACPI ID for coreboot HIDs */ |
| 65 | |
| 66 | /* List of ACPI HID that use the coreboot ACPI ID */ |
| 67 | enum coreboot_acpi_ids { |
| 68 | COREBOOT_ACPI_ID_CBTABLE = 0x0000, /* BOOT0000 */ |
| 69 | COREBOOT_ACPI_ID_MAX = 0xFFFF, /* BOOTFFFF */ |
| 70 | }; |
| 71 | |
| 72 | enum acpi_tables { |
| 73 | /* Tables defined by ACPI and used by coreboot */ |
Jonathan Zhang | 2a4e1f4 | 2021-04-01 11:43:37 -0700 | [diff] [blame] | 74 | BERT, DBG2, DMAR, DSDT, EINJ, FACS, FADT, HEST, HMAT, HPET, IVRS, MADT, |
| 75 | MCFG, RSDP, RSDT, SLIT, SRAT, SSDT, TCPA, TPM2, XSDT, ECDT, LPIT, |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 76 | /* Additional proprietary tables used by coreboot */ |
Jason Glenesk | 61624b2 | 2020-11-02 20:06:23 -0800 | [diff] [blame] | 77 | VFCT, NHLT, SPMI, CRAT |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | /* RSDP (Root System Description Pointer) */ |
| 81 | typedef struct acpi_rsdp { |
| 82 | char signature[8]; /* RSDP signature */ |
| 83 | u8 checksum; /* Checksum of the first 20 bytes */ |
| 84 | char oem_id[6]; /* OEM ID */ |
| 85 | u8 revision; /* RSDP revision */ |
| 86 | u32 rsdt_address; /* Physical address of RSDT (32 bits) */ |
| 87 | u32 length; /* Total RSDP length (incl. extended part) */ |
| 88 | u64 xsdt_address; /* Physical address of XSDT (64 bits) */ |
| 89 | u8 ext_checksum; /* Checksum of the whole table */ |
| 90 | u8 reserved[3]; |
| 91 | } __packed acpi_rsdp_t; |
| 92 | |
| 93 | /* GAS (Generic Address Structure) */ |
| 94 | typedef struct acpi_gen_regaddr { |
| 95 | u8 space_id; /* Address space ID */ |
| 96 | u8 bit_width; /* Register size in bits */ |
| 97 | u8 bit_offset; /* Register bit offset */ |
| 98 | u8 access_size; /* Access size since ACPI 2.0c */ |
| 99 | u32 addrl; /* Register address, low 32 bits */ |
| 100 | u32 addrh; /* Register address, high 32 bits */ |
| 101 | } __packed acpi_addr_t; |
| 102 | |
Elyes HAOUAS | 5f5fd85 | 2020-10-15 12:24:00 +0200 | [diff] [blame] | 103 | #define ACPI_ADDRESS_SPACE_MEMORY 0 /* System memory */ |
| 104 | #define ACPI_ADDRESS_SPACE_IO 1 /* System I/O */ |
| 105 | #define ACPI_ADDRESS_SPACE_PCI 2 /* PCI config space */ |
| 106 | #define ACPI_ADDRESS_SPACE_EC 3 /* Embedded controller */ |
| 107 | #define ACPI_ADDRESS_SPACE_SMBUS 4 /* SMBus */ |
| 108 | #define ACPI_ADDRESS_SPACE_CMOS 5 /* SystemCMOS */ |
| 109 | #define ACPI_ADDRESS_SPACE_PCI_BAR_TARGET 6 /* PciBarTarget */ |
| 110 | #define ACPI_ADDRESS_SPACE_IPMI 7 /* IPMI */ |
| 111 | #define ACPI_ADDRESS_SPACE_GENERAL_PURPOSE_IO 8 /* GeneralPurposeIO */ |
| 112 | #define ACPI_ADDRESS_SPACE_GENERIC_SERIAL_BUS 9 /* GenericSerialBus */ |
| 113 | #define ACPI_ADDRESS_SPACE_PCC 0x0A /* Platform Comm. Channel */ |
| 114 | #define ACPI_ADDRESS_SPACE_FIXED 0x7f /* Functional fixed hardware */ |
| 115 | #define ACPI_FFIXEDHW_VENDOR_INTEL 1 /* Intel */ |
| 116 | #define ACPI_FFIXEDHW_CLASS_HLT 0 /* C1 Halt */ |
| 117 | #define ACPI_FFIXEDHW_CLASS_IO_HLT 1 /* C1 I/O then Halt */ |
| 118 | #define ACPI_FFIXEDHW_CLASS_MWAIT 2 /* MWAIT Native C-state */ |
| 119 | #define ACPI_FFIXEDHW_FLAG_HW_COORD 1 /* Hardware Coordination bit */ |
| 120 | #define ACPI_FFIXEDHW_FLAG_BM_STS 2 /* BM_STS avoidance bit */ |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 121 | /* 0x80-0xbf: Reserved */ |
| 122 | /* 0xc0-0xff: OEM defined */ |
| 123 | |
| 124 | /* Access size definitions for Generic address structure */ |
| 125 | #define ACPI_ACCESS_SIZE_UNDEFINED 0 /* Undefined (legacy reasons) */ |
| 126 | #define ACPI_ACCESS_SIZE_BYTE_ACCESS 1 |
| 127 | #define ACPI_ACCESS_SIZE_WORD_ACCESS 2 |
| 128 | #define ACPI_ACCESS_SIZE_DWORD_ACCESS 3 |
| 129 | #define ACPI_ACCESS_SIZE_QWORD_ACCESS 4 |
| 130 | |
Michael Niewöhner | ab088c9 | 2021-09-23 17:04:35 +0200 | [diff] [blame] | 131 | /* Macros for common resource types */ |
| 132 | #define ACPI_REG_MSR(address, offset, width) \ |
| 133 | { \ |
| 134 | .space_id = ACPI_ADDRESS_SPACE_FIXED, \ |
| 135 | .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \ |
| 136 | .addrl = address, \ |
| 137 | .bit_offset = offset, \ |
| 138 | .bit_width = width, \ |
| 139 | } |
| 140 | |
| 141 | #define ACPI_REG_UNSUPPORTED {0} |
| 142 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 143 | /* Common ACPI HIDs */ |
| 144 | #define ACPI_HID_FDC "PNP0700" |
| 145 | #define ACPI_HID_KEYBOARD "PNP0303" |
| 146 | #define ACPI_HID_MOUSE "PNP0F03" |
| 147 | #define ACPI_HID_COM "PNP0501" |
| 148 | #define ACPI_HID_LPT "PNP0400" |
| 149 | #define ACPI_HID_PNP "PNP0C02" |
| 150 | #define ACPI_HID_CONTAINER "PNP0A05" |
| 151 | |
| 152 | /* Generic ACPI header, provided by (almost) all tables */ |
| 153 | typedef struct acpi_table_header { |
| 154 | char signature[4]; /* ACPI signature (4 ASCII characters) */ |
| 155 | u32 length; /* Table length in bytes (incl. header) */ |
| 156 | u8 revision; /* Table version (not ACPI version!) */ |
| 157 | u8 checksum; /* To make sum of entire table == 0 */ |
| 158 | char oem_id[6]; /* OEM identification */ |
| 159 | char oem_table_id[8]; /* OEM table identification */ |
| 160 | u32 oem_revision; /* OEM revision number */ |
| 161 | char asl_compiler_id[4]; /* ASL compiler vendor ID */ |
| 162 | u32 asl_compiler_revision; /* ASL compiler revision number */ |
| 163 | } __packed acpi_header_t; |
| 164 | |
| 165 | /* A maximum number of 32 ACPI tables ought to be enough for now. */ |
| 166 | #define MAX_ACPI_TABLES 32 |
| 167 | |
| 168 | /* RSDT (Root System Description Table) */ |
| 169 | typedef struct acpi_rsdt { |
| 170 | acpi_header_t header; |
| 171 | u32 entry[MAX_ACPI_TABLES]; |
| 172 | } __packed acpi_rsdt_t; |
| 173 | |
| 174 | /* XSDT (Extended System Description Table) */ |
| 175 | typedef struct acpi_xsdt { |
| 176 | acpi_header_t header; |
| 177 | u64 entry[MAX_ACPI_TABLES]; |
| 178 | } __packed acpi_xsdt_t; |
| 179 | |
| 180 | /* HPET timers */ |
| 181 | typedef struct acpi_hpet { |
| 182 | acpi_header_t header; |
| 183 | u32 id; |
| 184 | acpi_addr_t addr; |
| 185 | u8 number; |
| 186 | u16 min_tick; |
| 187 | u8 attributes; |
| 188 | } __packed acpi_hpet_t; |
| 189 | |
| 190 | /* MCFG (PCI Express MMIO config space BAR description table) */ |
| 191 | typedef struct acpi_mcfg { |
| 192 | acpi_header_t header; |
| 193 | u8 reserved[8]; |
| 194 | } __packed acpi_mcfg_t; |
| 195 | |
| 196 | typedef struct acpi_tcpa { |
| 197 | acpi_header_t header; |
| 198 | u16 platform_class; |
| 199 | u32 laml; |
| 200 | u64 lasa; |
| 201 | } __packed acpi_tcpa_t; |
| 202 | |
| 203 | typedef struct acpi_tpm2 { |
| 204 | acpi_header_t header; |
| 205 | u16 platform_class; |
| 206 | u8 reserved[2]; |
| 207 | u64 control_area; |
| 208 | u32 start_method; |
| 209 | u8 msp[12]; |
| 210 | u32 laml; |
| 211 | u64 lasa; |
| 212 | } __packed acpi_tpm2_t; |
| 213 | |
| 214 | typedef struct acpi_mcfg_mmconfig { |
| 215 | u32 base_address; |
| 216 | u32 base_reserved; |
| 217 | u16 pci_segment_group_number; |
| 218 | u8 start_bus_number; |
| 219 | u8 end_bus_number; |
| 220 | u8 reserved[4]; |
| 221 | } __packed acpi_mcfg_mmconfig_t; |
| 222 | |
Jonathan Zhang | 2a4e1f4 | 2021-04-01 11:43:37 -0700 | [diff] [blame] | 223 | /* |
| 224 | * HMAT (Heterogeneous Memory Attribute Table) |
| 225 | * ACPI spec 6.4 section 5.2.27 |
| 226 | */ |
| 227 | typedef struct acpi_hmat { |
| 228 | acpi_header_t header; |
| 229 | u32 resv; |
| 230 | /* Followed by HMAT table structure[n] */ |
| 231 | } __packed acpi_hmat_t; |
| 232 | |
| 233 | /* HMAT: Memory Proximity Domain Attributes structure */ |
| 234 | typedef struct acpi_hmat_mpda { |
| 235 | u16 type; /* Type (0) */ |
| 236 | u16 resv; |
| 237 | u32 length; /* Length in bytes (40) */ |
| 238 | u16 flags; |
| 239 | u16 resv1; |
| 240 | u32 proximity_domain_initiator; |
| 241 | u32 proximity_domain_memory; |
| 242 | u32 resv2; |
| 243 | u64 resv3; |
| 244 | u64 resv4; |
| 245 | } __packed acpi_hmat_mpda_t; |
| 246 | |
| 247 | /* HMAT: System Locality Latency and Bandwidth Information structure */ |
| 248 | typedef struct acpi_hmat_sllbi { |
| 249 | u16 type; /* Type (1) */ |
| 250 | u16 resv; |
| 251 | u32 length; /* Length in bytes */ |
| 252 | u8 flags; |
| 253 | u8 data_type; |
| 254 | /* |
| 255 | * Transfer size defined as a 5-biased power of 2 exponent, |
| 256 | * when the bandwidth/latency value is achieved. |
| 257 | */ |
| 258 | u8 min_transfer_size; |
| 259 | u8 resv1; |
| 260 | u32 num_initiator_domains; |
| 261 | u32 num_target_domains; |
| 262 | u32 resv2; |
| 263 | u64 entry_base_unit; |
| 264 | /* Followed by initiator proximity domain list */ |
| 265 | /* Followed by target proximity domain list */ |
| 266 | /* Followed by latency / bandwidth values */ |
| 267 | } __packed acpi_hmat_sllbi_t; |
| 268 | |
| 269 | /* HMAT: Memory Side Cache Information structure */ |
| 270 | typedef struct acpi_hmat_msci { |
| 271 | u16 type; /* Type (2) */ |
| 272 | u16 resv; |
| 273 | u32 length; /* Length in bytes */ |
| 274 | u32 domain; /* Proximity domain for the memory */ |
| 275 | u32 resv1; |
| 276 | u64 cache_size; |
| 277 | /* Describes level, associativity, write policy, cache line size */ |
| 278 | u32 cache_attributes; |
| 279 | u16 resv2; |
| 280 | /* |
| 281 | * Number of SMBIOS handlers that contribute to the |
| 282 | * memory side cache physical devices |
| 283 | */ |
| 284 | u16 num_handlers; |
| 285 | /* Followed by SMBIOS handlers*/ |
| 286 | } __packed acpi_hmat_msci_t; |
| 287 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 288 | /* SRAT (System Resource Affinity Table) */ |
| 289 | typedef struct acpi_srat { |
| 290 | acpi_header_t header; |
| 291 | u32 resv; |
| 292 | u64 resv1; |
| 293 | /* Followed by static resource allocation structure[n] */ |
| 294 | } __packed acpi_srat_t; |
| 295 | |
Jonathan Zhang | 3164b64 | 2021-04-21 17:51:31 -0700 | [diff] [blame] | 296 | #define ACPI_SRAT_STRUCTURE_LAPIC 0 |
| 297 | #define ACPI_SRAT_STRUCTURE_MEM 1 |
| 298 | #define ACPI_SRAT_STRUCTURE_GIA 5 |
| 299 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 300 | /* SRAT: Processor Local APIC/SAPIC Affinity Structure */ |
| 301 | typedef struct acpi_srat_lapic { |
| 302 | u8 type; /* Type (0) */ |
| 303 | u8 length; /* Length in bytes (16) */ |
| 304 | u8 proximity_domain_7_0; /* Proximity domain bits[7:0] */ |
| 305 | u8 apic_id; /* Local APIC ID */ |
| 306 | u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */ |
| 307 | u8 local_sapic_eid; /* Local SAPIC EID */ |
| 308 | u8 proximity_domain_31_8[3]; /* Proximity domain bits[31:8] */ |
| 309 | u32 clock_domain; /* _CDM Clock Domain */ |
| 310 | } __packed acpi_srat_lapic_t; |
| 311 | |
| 312 | /* SRAT: Memory Affinity Structure */ |
| 313 | typedef struct acpi_srat_mem { |
| 314 | u8 type; /* Type (1) */ |
| 315 | u8 length; /* Length in bytes (40) */ |
| 316 | u32 proximity_domain; /* Proximity domain */ |
| 317 | u16 resv; |
| 318 | u32 base_address_low; /* Mem range base address, low */ |
| 319 | u32 base_address_high; /* Mem range base address, high */ |
| 320 | u32 length_low; /* Mem range length, low */ |
| 321 | u32 length_high; /* Mem range length, high */ |
| 322 | u32 resv1; |
| 323 | u32 flags; /* Enable bit 0, hot pluggable bit 1; Non Volatile bit 2, |
| 324 | * other bits reserved to 0 |
| 325 | */ |
| 326 | u32 resv2[2]; |
| 327 | } __packed acpi_srat_mem_t; |
| 328 | |
Jonathan Zhang | 3164b64 | 2021-04-21 17:51:31 -0700 | [diff] [blame] | 329 | /* SRAT: Generic Initiator Affinity Structure (ACPI spec 6.4 section 5.2.16.6) */ |
| 330 | typedef struct acpi_srat_gia { |
| 331 | u8 type; /* Type (5) */ |
| 332 | u8 length; /* Length in bytes (32) */ |
| 333 | u8 resv; |
| 334 | u8 dev_handle_type; /* Device handle type */ |
| 335 | u32 proximity_domain; /*Proximity domain */ |
| 336 | u8 dev_handle[16]; /* Device handle */ |
| 337 | u32 flags; |
| 338 | u32 resv1; |
| 339 | } __packed acpi_srat_gia_t; |
| 340 | |
| 341 | #define ACPI_SRAT_GIA_DEV_HANDLE_ACPI 0 |
| 342 | #define ACPI_SRAT_GIA_DEV_HANDLE_PCI 1 |
| 343 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 344 | /* SLIT (System Locality Distance Information Table) */ |
| 345 | typedef struct acpi_slit { |
| 346 | acpi_header_t header; |
| 347 | /* Followed by static resource allocation 8+byte[num*num] */ |
| 348 | } __packed acpi_slit_t; |
| 349 | |
| 350 | /* MADT (Multiple APIC Description Table) */ |
| 351 | typedef struct acpi_madt { |
| 352 | acpi_header_t header; |
| 353 | u32 lapic_addr; /* Local APIC address */ |
| 354 | u32 flags; /* Multiple APIC flags */ |
| 355 | } __packed acpi_madt_t; |
| 356 | |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 357 | /* |
| 358 | * LPIT (Low Power Idle Table) |
| 359 | * Conforms to "Intel Low Power S0 Idle" specification, rev 002 from July 2017. |
| 360 | */ |
| 361 | typedef struct acpi_lpit { |
| 362 | acpi_header_t header; |
| 363 | } __packed acpi_lpit_t; |
| 364 | |
| 365 | /* LPIT: LPI descriptor flags */ |
| 366 | typedef struct acpi_lpi_flags { |
| 367 | uint32_t disabled : 1; |
| 368 | uint32_t counter_not_available : 1; |
| 369 | uint32_t reserved : 30; |
| 370 | } __packed acpi_lpi_desc_flags_t; |
| 371 | |
| 372 | /* LPIT: LPI descriptor types */ |
| 373 | enum acpi_lpi_desc_type { |
| 374 | ACPI_LPI_DESC_TYPE_NATIVE_CSTATE = 0x00, |
| 375 | /* type >= 1 reserved */ |
| 376 | }; |
| 377 | |
| 378 | /* LPIT: LPI descriptor header */ |
| 379 | typedef struct acpi_lpi_desc_hdr { |
| 380 | uint32_t type; |
| 381 | uint32_t length; |
| 382 | uint16_t uid; |
| 383 | uint16_t reserved; |
| 384 | } __packed acpi_lpi_desc_hdr_t; |
| 385 | |
| 386 | #define ACPI_LPIT_CTR_FREQ_TSC 0 |
| 387 | |
| 388 | /* LPIT: Native C-state instruction based LPI structure */ |
| 389 | typedef struct acpi_lpi_desc_ncst { |
| 390 | acpi_lpi_desc_hdr_t header; |
| 391 | acpi_lpi_desc_flags_t flags; |
| 392 | acpi_addr_t entry_trigger; /* Entry trigger C-state */ |
| 393 | uint32_t min_residency; /* Minimum residency or "break-even" in microseconds */ |
| 394 | uint32_t max_latency; /* Worst case exit latency in microseconds */ |
| 395 | acpi_addr_t residency_counter; |
| 396 | uint64_t counter_frequency; /* Frequency in cycles per second - 0 means TSC freq */ |
| 397 | } __packed acpi_lpi_desc_ncst_t; |
| 398 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 399 | /* VFCT image header */ |
| 400 | typedef struct acpi_vfct_image_hdr { |
| 401 | u32 PCIBus; |
| 402 | u32 PCIDevice; |
| 403 | u32 PCIFunction; |
| 404 | u16 VendorID; |
| 405 | u16 DeviceID; |
| 406 | u16 SSVID; |
| 407 | u16 SSID; |
| 408 | u32 Revision; |
| 409 | u32 ImageLength; |
| 410 | u8 VbiosContent; // dummy - copy VBIOS here |
| 411 | } __packed acpi_vfct_image_hdr_t; |
| 412 | |
| 413 | /* VFCT (VBIOS Fetch Table) */ |
| 414 | typedef struct acpi_vfct { |
| 415 | acpi_header_t header; |
| 416 | u8 TableUUID[16]; |
| 417 | u32 VBIOSImageOffset; |
| 418 | u32 Lib1ImageOffset; |
| 419 | u32 Reserved[4]; |
| 420 | acpi_vfct_image_hdr_t image_hdr; |
| 421 | } __packed acpi_vfct_t; |
| 422 | |
| 423 | typedef struct acpi_ivrs_info { |
| 424 | } __packed acpi_ivrs_info_t; |
| 425 | |
| 426 | /* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 10h */ |
| 427 | typedef struct acpi_ivrs_ivhd { |
| 428 | uint8_t type; |
| 429 | uint8_t flags; |
| 430 | uint16_t length; |
| 431 | uint16_t device_id; |
| 432 | uint16_t capability_offset; |
| 433 | uint32_t iommu_base_low; |
| 434 | uint32_t iommu_base_high; |
| 435 | uint16_t pci_segment_group; |
| 436 | uint16_t iommu_info; |
| 437 | uint32_t iommu_feature_info; |
| 438 | uint8_t entry[0]; |
| 439 | } __packed acpi_ivrs_ivhd_t; |
| 440 | |
| 441 | /* IVRS (I/O Virtualization Reporting Structure) Type 10h */ |
| 442 | typedef struct acpi_ivrs { |
| 443 | acpi_header_t header; |
| 444 | uint32_t iv_info; |
| 445 | uint32_t reserved[2]; |
| 446 | struct acpi_ivrs_ivhd ivhd; |
| 447 | } __packed acpi_ivrs_t; |
| 448 | |
Jason Glenesk | 61624b2 | 2020-11-02 20:06:23 -0800 | [diff] [blame] | 449 | /* CRAT (Component Resource Affinity Table Structure) */ |
| 450 | struct acpi_crat_header { |
| 451 | acpi_header_t header; |
| 452 | uint32_t total_entries; |
| 453 | uint16_t num_nodes; |
| 454 | uint8_t reserved[6]; |
| 455 | } __packed; |
| 456 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 457 | /* IVHD Type 11h IOMMU Attributes */ |
| 458 | typedef struct ivhd11_iommu_attr { |
| 459 | uint32_t reserved1 : 13; |
| 460 | uint32_t perf_counters : 4; |
| 461 | uint32_t perf_counter_banks : 6; |
| 462 | uint32_t msi_num_ppr : 5; |
| 463 | uint32_t reserved2 : 4; |
| 464 | } __packed ivhd11_iommu_attr_t; |
| 465 | |
| 466 | /* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 11h */ |
| 467 | typedef struct acpi_ivrs_ivhd_11 { |
| 468 | uint8_t type; |
| 469 | uint8_t flags; |
| 470 | uint16_t length; |
| 471 | uint16_t device_id; |
| 472 | uint16_t capability_offset; |
| 473 | uint32_t iommu_base_low; |
| 474 | uint32_t iommu_base_high; |
| 475 | uint16_t pci_segment_group; |
| 476 | uint16_t iommu_info; |
| 477 | struct ivhd11_iommu_attr iommu_attributes; |
| 478 | uint32_t efr_reg_image_low; |
| 479 | uint32_t efr_reg_image_high; |
| 480 | uint32_t reserved[2]; |
| 481 | uint8_t entry[0]; |
| 482 | } __packed acpi_ivrs_ivhd11_t; |
| 483 | |
| 484 | enum dev_scope_type { |
| 485 | SCOPE_PCI_ENDPOINT = 1, |
| 486 | SCOPE_PCI_SUB = 2, |
| 487 | SCOPE_IOAPIC = 3, |
| 488 | SCOPE_MSI_HPET = 4, |
| 489 | SCOPE_ACPI_NAMESPACE_DEVICE = 5 |
| 490 | }; |
| 491 | |
| 492 | typedef struct dev_scope { |
| 493 | u8 type; |
| 494 | u8 length; |
| 495 | u8 reserved[2]; |
| 496 | u8 enumeration; |
| 497 | u8 start_bus; |
| 498 | struct { |
| 499 | u8 dev; |
| 500 | u8 fn; |
| 501 | } __packed path[0]; |
| 502 | } __packed dev_scope_t; |
| 503 | |
| 504 | enum dmar_type { |
| 505 | DMAR_DRHD = 0, |
| 506 | DMAR_RMRR = 1, |
| 507 | DMAR_ATSR = 2, |
| 508 | DMAR_RHSA = 3, |
John Zhao | 6edbb18 | 2021-03-24 11:55:09 -0700 | [diff] [blame] | 509 | DMAR_ANDD = 4, |
| 510 | DMAR_SATC = 5 |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 511 | }; |
| 512 | |
| 513 | enum { |
| 514 | DRHD_INCLUDE_PCI_ALL = 1 |
| 515 | }; |
| 516 | |
John Zhao | 091532d | 2021-04-17 16:03:21 -0700 | [diff] [blame] | 517 | enum { |
| 518 | ATC_REQUIRED = 1 |
| 519 | }; |
| 520 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 521 | enum dmar_flags { |
| 522 | DMAR_INTR_REMAP = 1 << 0, |
| 523 | DMAR_X2APIC_OPT_OUT = 1 << 1, |
| 524 | DMA_CTRL_PLATFORM_OPT_IN_FLAG = 1 << 2, |
| 525 | }; |
| 526 | |
| 527 | typedef struct dmar_entry { |
| 528 | u16 type; |
| 529 | u16 length; |
| 530 | u8 flags; |
| 531 | u8 reserved; |
| 532 | u16 segment; |
| 533 | u64 bar; |
| 534 | } __packed dmar_entry_t; |
| 535 | |
| 536 | typedef struct dmar_rmrr_entry { |
| 537 | u16 type; |
| 538 | u16 length; |
| 539 | u16 reserved; |
| 540 | u16 segment; |
| 541 | u64 bar; |
| 542 | u64 limit; |
| 543 | } __packed dmar_rmrr_entry_t; |
| 544 | |
| 545 | typedef struct dmar_atsr_entry { |
| 546 | u16 type; |
| 547 | u16 length; |
| 548 | u8 flags; |
| 549 | u8 reserved; |
| 550 | u16 segment; |
| 551 | } __packed dmar_atsr_entry_t; |
| 552 | |
| 553 | typedef struct dmar_rhsa_entry { |
| 554 | u16 type; |
| 555 | u16 length; |
| 556 | u32 reserved; |
| 557 | u64 base_address; |
| 558 | u32 proximity_domain; |
| 559 | } __packed dmar_rhsa_entry_t; |
| 560 | |
| 561 | typedef struct dmar_andd_entry { |
| 562 | u16 type; |
| 563 | u16 length; |
| 564 | u8 reserved[3]; |
| 565 | u8 device_number; |
| 566 | u8 device_name[]; |
| 567 | } __packed dmar_andd_entry_t; |
| 568 | |
John Zhao | 6edbb18 | 2021-03-24 11:55:09 -0700 | [diff] [blame] | 569 | typedef struct dmar_satc_entry { |
| 570 | u16 type; |
| 571 | u16 length; |
| 572 | u8 flags; |
| 573 | u8 reserved; |
| 574 | u16 segment_number; |
John Zhao | 6edbb18 | 2021-03-24 11:55:09 -0700 | [diff] [blame] | 575 | } __packed dmar_satc_entry_t; |
| 576 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 577 | /* DMAR (DMA Remapping Reporting Structure) */ |
| 578 | typedef struct acpi_dmar { |
| 579 | acpi_header_t header; |
| 580 | u8 host_address_width; |
| 581 | u8 flags; |
| 582 | u8 reserved[10]; |
| 583 | dmar_entry_t structure[0]; |
| 584 | } __packed acpi_dmar_t; |
| 585 | |
| 586 | /* MADT: APIC Structure Types */ |
| 587 | enum acpi_apic_types { |
| 588 | LOCAL_APIC, /* Processor local APIC */ |
| 589 | IO_APIC, /* I/O APIC */ |
| 590 | IRQ_SOURCE_OVERRIDE, /* Interrupt source override */ |
| 591 | NMI_TYPE, /* NMI source */ |
| 592 | LOCAL_APIC_NMI, /* Local APIC NMI */ |
| 593 | LAPIC_ADDRESS_OVERRIDE, /* Local APIC address override */ |
| 594 | IO_SAPIC, /* I/O SAPIC */ |
| 595 | LOCAL_SAPIC, /* Local SAPIC */ |
| 596 | PLATFORM_IRQ_SOURCES, /* Platform interrupt sources */ |
| 597 | LOCAL_X2APIC, /* Processor local x2APIC */ |
| 598 | LOCAL_X2APIC_NMI, /* Local x2APIC NMI */ |
| 599 | GICC, /* GIC CPU Interface */ |
| 600 | GICD, /* GIC Distributor */ |
| 601 | GIC_MSI_FRAME, /* GIC MSI Frame */ |
| 602 | GICR, /* GIC Redistributor */ |
| 603 | GIC_ITS, /* Interrupt Translation Service */ |
| 604 | /* 0x10-0x7f: Reserved */ |
| 605 | /* 0x80-0xff: Reserved for OEM use */ |
| 606 | }; |
| 607 | |
| 608 | /* MADT: Processor Local APIC Structure */ |
| 609 | typedef struct acpi_madt_lapic { |
| 610 | u8 type; /* Type (0) */ |
| 611 | u8 length; /* Length in bytes (8) */ |
| 612 | u8 processor_id; /* ACPI processor ID */ |
| 613 | u8 apic_id; /* Local APIC ID */ |
| 614 | u32 flags; /* Local APIC flags */ |
| 615 | } __packed acpi_madt_lapic_t; |
| 616 | |
| 617 | /* MADT: Local APIC NMI Structure */ |
| 618 | typedef struct acpi_madt_lapic_nmi { |
| 619 | u8 type; /* Type (4) */ |
| 620 | u8 length; /* Length in bytes (6) */ |
| 621 | u8 processor_id; /* ACPI processor ID */ |
| 622 | u16 flags; /* MPS INTI flags */ |
| 623 | u8 lint; /* Local APIC LINT# */ |
| 624 | } __packed acpi_madt_lapic_nmi_t; |
| 625 | |
Raul E Rangel | f5552ce | 2021-02-11 11:27:56 -0700 | [diff] [blame] | 626 | #define ACPI_MADT_LAPIC_NMI_ALL_PROCESSORS 0xff |
| 627 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 628 | /* MADT: I/O APIC Structure */ |
| 629 | typedef struct acpi_madt_ioapic { |
| 630 | u8 type; /* Type (1) */ |
| 631 | u8 length; /* Length in bytes (12) */ |
| 632 | u8 ioapic_id; /* I/O APIC ID */ |
| 633 | u8 reserved; |
| 634 | u32 ioapic_addr; /* I/O APIC address */ |
| 635 | u32 gsi_base; /* Global system interrupt base */ |
| 636 | } __packed acpi_madt_ioapic_t; |
| 637 | |
| 638 | /* MADT: Interrupt Source Override Structure */ |
| 639 | typedef struct acpi_madt_irqoverride { |
| 640 | u8 type; /* Type (2) */ |
| 641 | u8 length; /* Length in bytes (10) */ |
| 642 | u8 bus; /* ISA (0) */ |
| 643 | u8 source; /* Bus-relative int. source (IRQ) */ |
| 644 | u32 gsirq; /* Global system interrupt */ |
| 645 | u16 flags; /* MPS INTI flags */ |
| 646 | } __packed acpi_madt_irqoverride_t; |
| 647 | |
| 648 | /* MADT: Processor Local x2APIC Structure */ |
| 649 | typedef struct acpi_madt_lx2apic { |
| 650 | u8 type; /* Type (9) */ |
| 651 | u8 length; /* Length in bytes (16) */ |
| 652 | u16 reserved; |
| 653 | u32 x2apic_id; /* Local x2APIC ID */ |
| 654 | u32 flags; /* Same as Local APIC flags */ |
| 655 | u32 processor_id; /* ACPI processor ID */ |
| 656 | } __packed acpi_madt_lx2apic_t; |
| 657 | |
| 658 | /* MADT: Processor Local x2APIC NMI Structure */ |
| 659 | typedef struct acpi_madt_lx2apic_nmi { |
| 660 | u8 type; /* Type (10) */ |
| 661 | u8 length; /* Length in bytes (12) */ |
| 662 | u16 flags; /* Same as MPS INTI flags */ |
| 663 | u32 processor_id; /* ACPI processor ID */ |
| 664 | u8 lint; /* Local APIC LINT# */ |
| 665 | u8 reserved[3]; |
| 666 | } __packed acpi_madt_lx2apic_nmi_t; |
| 667 | |
| 668 | #define ACPI_DBG2_PORT_SERIAL 0x8000 |
| 669 | #define ACPI_DBG2_PORT_SERIAL_16550 0x0000 |
| 670 | #define ACPI_DBG2_PORT_SERIAL_16550_DBGP 0x0001 |
| 671 | #define ACPI_DBG2_PORT_SERIAL_ARM_PL011 0x0003 |
| 672 | #define ACPI_DBG2_PORT_SERIAL_ARM_SBSA 0x000e |
| 673 | #define ACPI_DBG2_PORT_SERIAL_ARM_DDC 0x000f |
| 674 | #define ACPI_DBG2_PORT_SERIAL_BCM2835 0x0010 |
| 675 | #define ACPI_DBG2_PORT_IEEE1394 0x8001 |
| 676 | #define ACPI_DBG2_PORT_IEEE1394_STANDARD 0x0000 |
| 677 | #define ACPI_DBG2_PORT_USB 0x8002 |
| 678 | #define ACPI_DBG2_PORT_USB_XHCI 0x0000 |
| 679 | #define ACPI_DBG2_PORT_USB_EHCI 0x0001 |
| 680 | #define ACPI_DBG2_PORT_NET 0x8003 |
| 681 | |
| 682 | /* DBG2: Microsoft Debug Port Table 2 header */ |
| 683 | typedef struct acpi_dbg2_header { |
| 684 | acpi_header_t header; |
| 685 | uint32_t devices_offset; |
| 686 | uint32_t devices_count; |
| 687 | } __attribute__((packed)) acpi_dbg2_header_t; |
| 688 | |
| 689 | /* DBG2: Microsoft Debug Port Table 2 device entry */ |
| 690 | typedef struct acpi_dbg2_device { |
| 691 | uint8_t revision; |
| 692 | uint16_t length; |
| 693 | uint8_t address_count; |
| 694 | uint16_t namespace_string_length; |
| 695 | uint16_t namespace_string_offset; |
| 696 | uint16_t oem_data_length; |
| 697 | uint16_t oem_data_offset; |
| 698 | uint16_t port_type; |
| 699 | uint16_t port_subtype; |
| 700 | uint8_t reserved[2]; |
| 701 | uint16_t base_address_offset; |
| 702 | uint16_t address_size_offset; |
| 703 | } __attribute__((packed)) acpi_dbg2_device_t; |
| 704 | |
| 705 | /* FADT (Fixed ACPI Description Table) */ |
| 706 | typedef struct acpi_fadt { |
| 707 | acpi_header_t header; |
| 708 | u32 firmware_ctrl; |
| 709 | u32 dsdt; |
| 710 | u8 reserved; /* Should be 0 */ |
| 711 | u8 preferred_pm_profile; |
| 712 | u16 sci_int; |
| 713 | u32 smi_cmd; |
| 714 | u8 acpi_enable; |
| 715 | u8 acpi_disable; |
| 716 | u8 s4bios_req; |
| 717 | u8 pstate_cnt; |
| 718 | u32 pm1a_evt_blk; |
| 719 | u32 pm1b_evt_blk; |
| 720 | u32 pm1a_cnt_blk; |
| 721 | u32 pm1b_cnt_blk; |
| 722 | u32 pm2_cnt_blk; |
| 723 | u32 pm_tmr_blk; |
| 724 | u32 gpe0_blk; |
| 725 | u32 gpe1_blk; |
| 726 | u8 pm1_evt_len; |
| 727 | u8 pm1_cnt_len; |
| 728 | u8 pm2_cnt_len; |
| 729 | u8 pm_tmr_len; |
| 730 | u8 gpe0_blk_len; |
| 731 | u8 gpe1_blk_len; |
| 732 | u8 gpe1_base; |
| 733 | u8 cst_cnt; |
| 734 | u16 p_lvl2_lat; |
| 735 | u16 p_lvl3_lat; |
| 736 | u16 flush_size; |
| 737 | u16 flush_stride; |
| 738 | u8 duty_offset; |
| 739 | u8 duty_width; |
| 740 | u8 day_alrm; |
| 741 | u8 mon_alrm; |
| 742 | u8 century; |
| 743 | u16 iapc_boot_arch; |
| 744 | u8 res2; |
| 745 | u32 flags; |
| 746 | acpi_addr_t reset_reg; |
| 747 | u8 reset_value; |
| 748 | u16 ARM_boot_arch; /* Revision 6 only, Revision 5: Must be zero */ |
| 749 | u8 FADT_MinorVersion; /* Revision 6 only, Revision 5: Must be zero */ |
| 750 | u32 x_firmware_ctl_l; |
| 751 | u32 x_firmware_ctl_h; |
| 752 | u32 x_dsdt_l; |
| 753 | u32 x_dsdt_h; |
| 754 | acpi_addr_t x_pm1a_evt_blk; |
| 755 | acpi_addr_t x_pm1b_evt_blk; |
| 756 | acpi_addr_t x_pm1a_cnt_blk; |
| 757 | acpi_addr_t x_pm1b_cnt_blk; |
| 758 | acpi_addr_t x_pm2_cnt_blk; |
| 759 | acpi_addr_t x_pm_tmr_blk; |
| 760 | acpi_addr_t x_gpe0_blk; |
| 761 | acpi_addr_t x_gpe1_blk; |
| 762 | /* Revision 5 */ |
| 763 | acpi_addr_t sleep_control_reg; |
| 764 | acpi_addr_t sleep_status_reg; |
| 765 | /* Revision 6 */ |
| 766 | u64 hypervisor_vendor_identity; |
| 767 | } __packed acpi_fadt_t; |
| 768 | |
| 769 | /* FADT TABLE Revision values */ |
| 770 | #define ACPI_FADT_REV_ACPI_1_0 1 |
| 771 | #define ACPI_FADT_REV_ACPI_2_0 3 |
| 772 | #define ACPI_FADT_REV_ACPI_3_0 4 |
| 773 | #define ACPI_FADT_REV_ACPI_4_0 4 |
| 774 | #define ACPI_FADT_REV_ACPI_5_0 5 |
| 775 | #define ACPI_FADT_REV_ACPI_6_0 6 |
| 776 | |
| 777 | /* Flags for p_lvl2_lat and p_lvl3_lat */ |
| 778 | #define ACPI_FADT_C2_NOT_SUPPORTED 101 |
| 779 | #define ACPI_FADT_C3_NOT_SUPPORTED 1001 |
| 780 | |
| 781 | /* FADT Feature Flags */ |
| 782 | #define ACPI_FADT_WBINVD (1 << 0) |
| 783 | #define ACPI_FADT_WBINVD_FLUSH (1 << 1) |
| 784 | #define ACPI_FADT_C1_SUPPORTED (1 << 2) |
| 785 | #define ACPI_FADT_C2_MP_SUPPORTED (1 << 3) |
| 786 | #define ACPI_FADT_POWER_BUTTON (1 << 4) |
| 787 | #define ACPI_FADT_SLEEP_BUTTON (1 << 5) |
| 788 | #define ACPI_FADT_FIXED_RTC (1 << 6) |
| 789 | #define ACPI_FADT_S4_RTC_WAKE (1 << 7) |
| 790 | #define ACPI_FADT_32BIT_TIMER (1 << 8) |
| 791 | #define ACPI_FADT_DOCKING_SUPPORTED (1 << 9) |
| 792 | #define ACPI_FADT_RESET_REGISTER (1 << 10) |
| 793 | #define ACPI_FADT_SEALED_CASE (1 << 11) |
| 794 | #define ACPI_FADT_HEADLESS (1 << 12) |
| 795 | #define ACPI_FADT_SLEEP_TYPE (1 << 13) |
| 796 | #define ACPI_FADT_PCI_EXPRESS_WAKE (1 << 14) |
| 797 | #define ACPI_FADT_PLATFORM_CLOCK (1 << 15) |
| 798 | #define ACPI_FADT_S4_RTC_VALID (1 << 16) |
| 799 | #define ACPI_FADT_REMOTE_POWER_ON (1 << 17) |
| 800 | #define ACPI_FADT_APIC_CLUSTER (1 << 18) |
| 801 | #define ACPI_FADT_APIC_PHYSICAL (1 << 19) |
| 802 | /* Bits 20-31: reserved ACPI 3.0 & 4.0 */ |
| 803 | #define ACPI_FADT_HW_REDUCED_ACPI (1 << 20) |
| 804 | #define ACPI_FADT_LOW_PWR_IDLE_S0 (1 << 21) |
| 805 | /* bits 22-31: reserved since ACPI 5.0 */ |
| 806 | |
| 807 | /* FADT Boot Architecture Flags */ |
| 808 | #define ACPI_FADT_LEGACY_DEVICES (1 << 0) |
| 809 | #define ACPI_FADT_8042 (1 << 1) |
| 810 | #define ACPI_FADT_VGA_NOT_PRESENT (1 << 2) |
| 811 | #define ACPI_FADT_MSI_NOT_SUPPORTED (1 << 3) |
| 812 | #define ACPI_FADT_NO_PCIE_ASPM_CONTROL (1 << 4) |
| 813 | #define ACPI_FADT_NO_CMOS_RTC (1 << 5) |
| 814 | #define ACPI_FADT_LEGACY_FREE 0x00 /* No legacy devices (including 8042) */ |
| 815 | |
| 816 | /* FADT ARM Boot Architecture Flags */ |
| 817 | #define ACPI_FADT_ARM_PSCI_COMPLIANT (1 << 0) |
| 818 | #define ACPI_FADT_ARM_PSCI_USE_HVC (1 << 1) |
| 819 | /* bits 2-16: reserved since ACPI 5.1 */ |
| 820 | |
| 821 | /* FADT Preferred Power Management Profile */ |
| 822 | enum acpi_preferred_pm_profiles { |
| 823 | PM_UNSPECIFIED = 0, |
| 824 | PM_DESKTOP = 1, |
| 825 | PM_MOBILE = 2, |
| 826 | PM_WORKSTATION = 3, |
| 827 | PM_ENTERPRISE_SERVER = 4, |
| 828 | PM_SOHO_SERVER = 5, |
| 829 | PM_APPLIANCE_PC = 6, |
| 830 | PM_PERFORMANCE_SERVER = 7, |
| 831 | PM_TABLET = 8, /* ACPI 5.0 & greater */ |
| 832 | }; |
| 833 | |
| 834 | /* FACS (Firmware ACPI Control Structure) */ |
| 835 | typedef struct acpi_facs { |
| 836 | char signature[4]; /* "FACS" */ |
| 837 | u32 length; /* Length in bytes (>= 64) */ |
| 838 | u32 hardware_signature; /* Hardware signature */ |
| 839 | u32 firmware_waking_vector; /* Firmware waking vector */ |
| 840 | u32 global_lock; /* Global lock */ |
| 841 | u32 flags; /* FACS flags */ |
| 842 | u32 x_firmware_waking_vector_l; /* X FW waking vector, low */ |
| 843 | u32 x_firmware_waking_vector_h; /* X FW waking vector, high */ |
| 844 | u8 version; /* FACS version */ |
| 845 | u8 resv1[3]; /* This value is 0 */ |
| 846 | u32 ospm_flags; /* 64BIT_WAKE_F */ |
| 847 | u8 resv2[24]; /* This value is 0 */ |
| 848 | } __packed acpi_facs_t; |
| 849 | |
| 850 | /* FACS flags */ |
| 851 | #define ACPI_FACS_S4BIOS_F (1 << 0) |
| 852 | #define ACPI_FACS_64BIT_WAKE_F (1 << 1) |
| 853 | /* Bits 31..2: reserved */ |
| 854 | |
| 855 | /* ECDT (Embedded Controller Boot Resources Table) */ |
| 856 | typedef struct acpi_ecdt { |
| 857 | acpi_header_t header; |
| 858 | acpi_addr_t ec_control; /* EC control register */ |
| 859 | acpi_addr_t ec_data; /* EC data register */ |
| 860 | u32 uid; /* UID */ |
| 861 | u8 gpe_bit; /* GPE bit */ |
| 862 | u8 ec_id[]; /* EC ID */ |
| 863 | } __packed acpi_ecdt_t; |
| 864 | |
| 865 | /* HEST (Hardware Error Source Table) */ |
| 866 | typedef struct acpi_hest { |
| 867 | acpi_header_t header; |
| 868 | u32 error_source_count; |
| 869 | /* error_source_struct(s) */ |
| 870 | } __packed acpi_hest_t; |
| 871 | |
| 872 | /* Error Source Descriptors */ |
| 873 | typedef struct acpi_hest_esd { |
| 874 | u16 type; |
| 875 | u16 source_id; |
| 876 | u16 resv; |
| 877 | u8 flags; |
| 878 | u8 enabled; |
| 879 | u32 prealloc_erecords; /* The number of error records to |
| 880 | * pre-allocate for this error source. |
| 881 | */ |
| 882 | u32 max_section_per_record; |
| 883 | } __packed acpi_hest_esd_t; |
| 884 | |
| 885 | /* Hardware Error Notification */ |
| 886 | typedef struct acpi_hest_hen { |
| 887 | u8 type; |
| 888 | u8 length; |
| 889 | u16 conf_we; /* Configuration Write Enable */ |
| 890 | u32 poll_interval; |
| 891 | u32 vector; |
| 892 | u32 sw2poll_threshold_val; |
| 893 | u32 sw2poll_threshold_win; |
| 894 | u32 error_threshold_val; |
| 895 | u32 error_threshold_win; |
| 896 | } __packed acpi_hest_hen_t; |
| 897 | |
| 898 | /* BERT (Boot Error Record Table) */ |
| 899 | typedef struct acpi_bert { |
| 900 | acpi_header_t header; |
| 901 | u32 region_length; |
| 902 | u64 error_region; |
| 903 | } __packed acpi_bert_t; |
| 904 | |
| 905 | /* Generic Error Data Entry */ |
| 906 | typedef struct acpi_hest_generic_data { |
| 907 | guid_t section_type; |
| 908 | u32 error_severity; |
| 909 | u16 revision; |
| 910 | u8 validation_bits; |
| 911 | u8 flags; |
| 912 | u32 data_length; |
| 913 | guid_t fru_id; |
| 914 | u8 fru_text[20]; |
| 915 | /* error data */ |
| 916 | } __packed acpi_hest_generic_data_t; |
| 917 | |
| 918 | /* Generic Error Data Entry v300 */ |
| 919 | typedef struct acpi_hest_generic_data_v300 { |
| 920 | guid_t section_type; |
| 921 | u32 error_severity; |
| 922 | u16 revision; |
| 923 | u8 validation_bits; |
| 924 | u8 flags; /* see CPER Section Descriptor, Flags field */ |
| 925 | u32 data_length; |
| 926 | guid_t fru_id; |
| 927 | u8 fru_text[20]; |
| 928 | cper_timestamp_t timestamp; |
| 929 | /* error data */ |
| 930 | } __packed acpi_hest_generic_data_v300_t; |
| 931 | #define HEST_GENERIC_ENTRY_V300 0x300 |
| 932 | |
| 933 | /* Both Generic Error Status & Generic Error Data Entry, Error Severity field */ |
| 934 | #define ACPI_GENERROR_SEV_RECOVERABLE 0 |
| 935 | #define ACPI_GENERROR_SEV_FATAL 1 |
| 936 | #define ACPI_GENERROR_SEV_CORRECTED 2 |
| 937 | #define ACPI_GENERROR_SEV_NONE 3 |
| 938 | |
| 939 | /* Generic Error Data Entry, Validation Bits field */ |
| 940 | #define ACPI_GENERROR_VALID_FRUID BIT(0) |
| 941 | #define ACPI_GENERROR_VALID_FRUID_TEXT BIT(1) |
| 942 | #define ACPI_GENERROR_VALID_TIMESTAMP BIT(2) |
| 943 | |
Felix Held | 403fa86 | 2021-07-26 22:43:00 +0200 | [diff] [blame] | 944 | /* |
| 945 | * Generic Error Status Block |
| 946 | * |
| 947 | * If there is a raw data section at the end of the generic error status block after the |
| 948 | * zero or more generic error data entries, raw_data_length indicates the length of the raw |
| 949 | * section and raw_data_offset is the offset of the beginning of the raw data section from |
| 950 | * the start of the acpi_generic_error_status block it is contained in. So if raw_data_length |
| 951 | * is non-zero, raw_data_offset must be at least sizeof(acpi_generic_error_status_t). |
| 952 | */ |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 953 | typedef struct acpi_generic_error_status { |
| 954 | u32 block_status; |
| 955 | u32 raw_data_offset; /* must follow any generic entries */ |
| 956 | u32 raw_data_length; |
| 957 | u32 data_length; /* generic data */ |
| 958 | u32 error_severity; |
| 959 | /* Generic Error Data structures, zero or more entries */ |
| 960 | } __packed acpi_generic_error_status_t; |
| 961 | |
| 962 | /* Generic Status Block, Block Status values */ |
| 963 | #define GENERIC_ERR_STS_UNCORRECTABLE_VALID BIT(0) |
| 964 | #define GENERIC_ERR_STS_CORRECTABLE_VALID BIT(1) |
| 965 | #define GENERIC_ERR_STS_MULT_UNCORRECTABLE BIT(2) |
| 966 | #define GENERIC_ERR_STS_MULT_CORRECTABLE BIT(3) |
| 967 | #define GENERIC_ERR_STS_ENTRY_COUNT_SHIFT 4 |
| 968 | #define GENERIC_ERR_STS_ENTRY_COUNT_MAX 0x3ff |
| 969 | #define GENERIC_ERR_STS_ENTRY_COUNT_MASK \ |
| 970 | (GENERIC_ERR_STS_ENTRY_COUNT_MAX \ |
| 971 | << GENERIC_ERR_STS_ENTRY_COUNT_SHIFT) |
| 972 | |
| 973 | typedef struct acpi_cstate { |
| 974 | u8 ctype; |
| 975 | u16 latency; |
| 976 | u32 power; |
| 977 | acpi_addr_t resource; |
| 978 | } __packed acpi_cstate_t; |
| 979 | |
Jason Glenesk | ca36aed | 2020-09-15 21:01:57 -0700 | [diff] [blame] | 980 | struct acpi_sw_pstate { |
| 981 | u32 core_freq; |
| 982 | u32 power; |
| 983 | u32 transition_latency; |
| 984 | u32 bus_master_latency; |
| 985 | u32 control_value; |
| 986 | u32 status_value; |
| 987 | } __packed; |
| 988 | |
| 989 | struct acpi_xpss_sw_pstate { |
| 990 | u64 core_freq; |
| 991 | u64 power; |
| 992 | u64 transition_latency; |
| 993 | u64 bus_master_latency; |
| 994 | u64 control_value; |
| 995 | u64 status_value; |
| 996 | u64 control_mask; |
| 997 | u64 status_mask; |
| 998 | } __packed; |
| 999 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1000 | typedef struct acpi_tstate { |
| 1001 | u32 percent; |
| 1002 | u32 power; |
| 1003 | u32 latency; |
| 1004 | u32 control; |
| 1005 | u32 status; |
| 1006 | } __packed acpi_tstate_t; |
| 1007 | |
Raul E Rangel | c704832 | 2021-04-19 15:58:25 -0600 | [diff] [blame] | 1008 | enum acpi_lpi_state_flags { |
| 1009 | ACPI_LPI_STATE_DISABLED = 0, |
| 1010 | ACPI_LPI_STATE_ENABLED |
| 1011 | }; |
| 1012 | |
| 1013 | /* Low Power Idle State */ |
| 1014 | struct acpi_lpi_state { |
| 1015 | u32 min_residency_us; |
| 1016 | u32 worst_case_wakeup_latency_us; |
| 1017 | u32 flags; |
| 1018 | u32 arch_context_lost_flags; |
| 1019 | u32 residency_counter_frequency_hz; |
| 1020 | u32 enabled_parent_state; |
| 1021 | acpi_addr_t entry_method; |
| 1022 | acpi_addr_t residency_counter_register; |
| 1023 | acpi_addr_t usage_counter_register; |
| 1024 | const char *state_name; |
| 1025 | }; |
| 1026 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1027 | /* Port types for ACPI _UPC object */ |
| 1028 | enum acpi_upc_type { |
| 1029 | UPC_TYPE_A, |
| 1030 | UPC_TYPE_MINI_AB, |
| 1031 | UPC_TYPE_EXPRESSCARD, |
| 1032 | UPC_TYPE_USB3_A, |
| 1033 | UPC_TYPE_USB3_B, |
| 1034 | UPC_TYPE_USB3_MICRO_B, |
| 1035 | UPC_TYPE_USB3_MICRO_AB, |
| 1036 | UPC_TYPE_USB3_POWER_B, |
| 1037 | UPC_TYPE_C_USB2_ONLY, |
| 1038 | UPC_TYPE_C_USB2_SS_SWITCH, |
| 1039 | UPC_TYPE_C_USB2_SS, |
| 1040 | UPC_TYPE_PROPRIETARY = 0xff, |
| 1041 | /* |
| 1042 | * The following types are not directly defined in the ACPI |
| 1043 | * spec but are used by coreboot to identify a USB device type. |
| 1044 | */ |
| 1045 | UPC_TYPE_INTERNAL = 0xff, |
| 1046 | UPC_TYPE_UNUSED, |
| 1047 | UPC_TYPE_HUB |
| 1048 | }; |
| 1049 | |
| 1050 | enum acpi_ipmi_interface_type { |
| 1051 | IPMI_INTERFACE_RESERVED = 0, |
| 1052 | IPMI_INTERFACE_KCS, |
| 1053 | IPMI_INTERFACE_SMIC, |
| 1054 | IPMI_INTERFACE_BT, |
| 1055 | IPMI_INTERFACE_SSIF, |
| 1056 | }; |
| 1057 | |
| 1058 | #define ACPI_IPMI_PCI_DEVICE_FLAG (1 << 0) |
| 1059 | #define ACPI_IPMI_INT_TYPE_SCI (1 << 0) |
| 1060 | #define ACPI_IPMI_INT_TYPE_APIC (1 << 1) |
| 1061 | |
| 1062 | /* ACPI IPMI 2.0 */ |
| 1063 | struct acpi_spmi { |
| 1064 | acpi_header_t header; |
| 1065 | u8 interface_type; |
| 1066 | u8 reserved; |
| 1067 | u16 specification_revision; |
| 1068 | u8 interrupt_type; |
| 1069 | u8 gpe; |
| 1070 | u8 reserved2; |
| 1071 | u8 pci_device_flag; |
| 1072 | |
| 1073 | u32 global_system_interrupt; |
| 1074 | acpi_addr_t base_address; |
| 1075 | union { |
| 1076 | struct { |
| 1077 | u8 pci_segment_group; |
| 1078 | u8 pci_bus; |
| 1079 | u8 pci_device; |
| 1080 | u8 pci_function; |
| 1081 | }; |
| 1082 | u8 uid[4]; |
| 1083 | }; |
| 1084 | u8 reserved3; |
| 1085 | } __packed; |
| 1086 | |
Rocky Phagura | eff0713 | 2021-01-10 15:42:50 -0800 | [diff] [blame] | 1087 | /* EINJ APEI Standard Definitions */ |
| 1088 | /* EINJ Error Types |
| 1089 | Refer to the ACPI spec, EINJ section, for more info on bit definitions |
| 1090 | */ |
| 1091 | #define ACPI_EINJ_CPU_CE (1 << 0) |
| 1092 | #define ACPI_EINJ_CPU_UCE (1 << 1) |
| 1093 | #define ACPI_EINJ_CPU_UCE_FATAL (1 << 2) |
| 1094 | #define ACPI_EINJ_MEM_CE (1 << 3) |
| 1095 | #define ACPI_EINJ_MEM_UCE (1 << 4) |
| 1096 | #define ACPI_EINJ_MEM_UCE_FATAL (1 << 5) |
| 1097 | #define ACPI_EINJ_PCIE_CE (1 << 6) |
| 1098 | #define ACPI_EINJ_PCIE_UCE_NON_FATAL (1 << 7) |
| 1099 | #define ACPI_EINJ_PCIE_UCE_FATAL (1 << 8) |
| 1100 | #define ACPI_EINJ_PLATFORM_CE (1 << 9) |
| 1101 | #define ACPI_EINJ_PLATFORM_UCE (1 << 10) |
| 1102 | #define ACPI_EINJ_PLATFORM_UCE_FATAL (1 << 11) |
| 1103 | #define ACPI_EINJ_VENDOR_DEFINED (1 << 31) |
| 1104 | #define ACPI_EINJ_DEFAULT_CAP (ACPI_EINJ_MEM_CE | ACPI_EINJ_MEM_UCE | \ |
| 1105 | ACPI_EINJ_PCIE_CE | ACPI_EINJ_PCIE_UCE_FATAL) |
| 1106 | |
| 1107 | /* EINJ actions */ |
| 1108 | #define ACTION_COUNT 9 |
| 1109 | #define BEGIN_INJECT_OP 0x00 |
| 1110 | #define GET_TRIGGER_ACTION_TABLE 0x01 |
| 1111 | #define SET_ERROR_TYPE 0x02 |
| 1112 | #define GET_ERROR_TYPE 0x03 |
| 1113 | #define END_INJECT_OP 0x04 |
| 1114 | #define EXECUTE_INJECT_OP 0x05 |
| 1115 | #define CHECK_BUSY_STATUS 0x06 |
| 1116 | #define GET_CMD_STATUS 0x07 |
| 1117 | #define SET_ERROR_TYPE_WITH_ADDRESS 0x08 |
| 1118 | #define TRIGGER_ERROR 0xFF |
| 1119 | |
| 1120 | /* EINJ Instructions */ |
| 1121 | #define READ_REGISTER 0x00 |
| 1122 | #define READ_REGISTER_VALUE 0x01 |
| 1123 | #define WRITE_REGISTER 0x02 |
| 1124 | #define WRITE_REGISTER_VALUE 0x03 |
| 1125 | #define NO_OP 0x04 |
| 1126 | |
| 1127 | /* EINJ (Error Injection Table) */ |
| 1128 | typedef struct acpi_gen_regaddr1 { |
| 1129 | u8 space_id; /* Address space ID */ |
| 1130 | u8 bit_width; /* Register size in bits */ |
| 1131 | u8 bit_offset; /* Register bit offset */ |
| 1132 | u8 access_size; /* Access size since ACPI 2.0c */ |
| 1133 | u64 addr; /* Register address */ |
| 1134 | } __packed acpi_addr64_t; |
| 1135 | |
| 1136 | /* Instruction entry */ |
| 1137 | typedef struct acpi_einj_action_table { |
| 1138 | u8 action; |
| 1139 | u8 instruction; |
| 1140 | u16 flags; |
| 1141 | acpi_addr64_t reg; |
| 1142 | u64 value; |
| 1143 | u64 mask; |
| 1144 | } __packed acpi_einj_action_table_t; |
| 1145 | |
| 1146 | typedef struct acpi_injection_header { |
| 1147 | u32 einj_header_size; |
| 1148 | u32 flags; |
| 1149 | u32 entry_count; |
| 1150 | } __packed acpi_injection_header_t; |
| 1151 | |
| 1152 | typedef struct acpi_einj_trigger_table { |
| 1153 | u32 header_size; |
| 1154 | u32 revision; |
| 1155 | u32 table_size; |
| 1156 | u32 entry_count; |
| 1157 | acpi_einj_action_table_t trigger_action[1]; |
| 1158 | } __packed acpi_einj_trigger_table_t; |
| 1159 | |
| 1160 | typedef struct set_error_type { |
| 1161 | u32 errtype; |
| 1162 | u32 vendorerrortype; |
| 1163 | u32 flags; |
| 1164 | u32 apicid; |
| 1165 | u64 memaddr; |
| 1166 | u64 memrange; |
| 1167 | u32 pciesbdf; |
| 1168 | } __packed set_error_type_t; |
| 1169 | |
| 1170 | #define EINJ_PARAM_NUM 6 |
| 1171 | typedef struct acpi_einj_smi { |
| 1172 | u64 op_state; |
| 1173 | u64 err_inject[EINJ_PARAM_NUM]; |
| 1174 | u64 trigger_action_table; |
| 1175 | u64 err_inj_cap; |
| 1176 | u64 op_status; |
| 1177 | u64 cmd_sts; |
| 1178 | u64 einj_addr; |
| 1179 | u64 einj_addr_msk; |
| 1180 | set_error_type_t setaddrtable; |
| 1181 | u64 reserved[50]; |
| 1182 | } __packed acpi_einj_smi_t; |
| 1183 | |
| 1184 | /* EINJ Flags */ |
| 1185 | #define EINJ_DEF_TRIGGER_PORT 0xb2 |
| 1186 | #define FLAG_PRESERVE 0x01 |
| 1187 | #define FLAG_IGNORE 0x00 |
| 1188 | |
| 1189 | /* EINJ Registers */ |
| 1190 | #define EINJ_REG_MEMORY(address) \ |
| 1191 | { \ |
| 1192 | .space_id = ACPI_ADDRESS_SPACE_MEMORY, \ |
| 1193 | .bit_width = 64, \ |
| 1194 | .bit_offset = 0, \ |
| 1195 | .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \ |
| 1196 | .addr = address} |
| 1197 | |
| 1198 | #define EINJ_REG_IO() \ |
| 1199 | { \ |
| 1200 | .space_id = ACPI_ADDRESS_SPACE_IO, \ |
| 1201 | .bit_width = 0x10, \ |
| 1202 | .bit_offset = 0, \ |
| 1203 | .access_size = ACPI_ACCESS_SIZE_WORD_ACCESS, \ |
| 1204 | .addr = EINJ_DEF_TRIGGER_PORT} /* HW dependent code can override this also */ |
| 1205 | |
| 1206 | typedef struct acpi_einj { |
| 1207 | acpi_header_t header; |
| 1208 | acpi_injection_header_t inj_header; |
| 1209 | acpi_einj_action_table_t action_table[ACTION_COUNT]; |
| 1210 | } __packed acpi_einj_t; |
| 1211 | |
| 1212 | |
| 1213 | void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions); |
| 1214 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1215 | unsigned long fw_cfg_acpi_tables(unsigned long start); |
| 1216 | |
| 1217 | /* These are implemented by the target port or north/southbridge. */ |
| 1218 | unsigned long write_acpi_tables(unsigned long addr); |
| 1219 | unsigned long acpi_fill_madt(unsigned long current); |
| 1220 | unsigned long acpi_fill_mcfg(unsigned long current); |
| 1221 | unsigned long acpi_fill_ivrs_ioapic(acpi_ivrs_t *ivrs, unsigned long current); |
| 1222 | void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id); |
| 1223 | void acpi_write_bert(acpi_bert_t *bert, uintptr_t region, size_t length); |
| 1224 | void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt); |
Kyösti Mälkki | f9aac92 | 2020-05-30 16:16:28 +0300 | [diff] [blame] | 1225 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1226 | void acpi_fill_fadt(acpi_fadt_t *fadt); |
Angel Pons | 79572e4 | 2020-07-13 00:17:43 +0200 | [diff] [blame] | 1227 | void arch_fill_fadt(acpi_fadt_t *fadt); |
Kyösti Mälkki | f9aac92 | 2020-05-30 16:16:28 +0300 | [diff] [blame] | 1228 | void soc_fill_fadt(acpi_fadt_t *fadt); |
Kyösti Mälkki | 02fd15d | 2020-06-02 03:34:43 +0300 | [diff] [blame] | 1229 | void mainboard_fill_fadt(acpi_fadt_t *fadt); |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1230 | |
Kyösti Mälkki | 2ab4a96 | 2020-06-30 11:41:47 +0300 | [diff] [blame] | 1231 | void acpi_fill_gnvs(void); |
Kyösti Mälkki | 3dc1792 | 2021-03-16 19:01:48 +0200 | [diff] [blame] | 1232 | void acpi_fill_cnvs(void); |
Kyösti Mälkki | 2ab4a96 | 2020-06-30 11:41:47 +0300 | [diff] [blame] | 1233 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1234 | void update_ssdt(void *ssdt); |
| 1235 | void update_ssdtx(void *ssdtx, int i); |
| 1236 | |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1237 | unsigned long acpi_fill_lpit(unsigned long current); |
| 1238 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1239 | /* These can be used by the target port. */ |
| 1240 | u8 acpi_checksum(u8 *table, u32 length); |
| 1241 | |
| 1242 | void acpi_add_table(acpi_rsdp_t *rsdp, void *table); |
| 1243 | |
| 1244 | int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic); |
| 1245 | int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr, |
| 1246 | u32 gsi_base); |
| 1247 | int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride, |
| 1248 | u8 bus, u8 source, u32 gsirq, u16 flags); |
| 1249 | int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu, |
| 1250 | u16 flags, u8 lint); |
| 1251 | void acpi_create_madt(acpi_madt_t *madt); |
| 1252 | unsigned long acpi_create_madt_lapics(unsigned long current); |
| 1253 | unsigned long acpi_create_madt_lapic_nmis(unsigned long current, u16 flags, |
| 1254 | u8 lint); |
| 1255 | int acpi_create_madt_lx2apic(acpi_madt_lx2apic_t *lapic, u32 cpu, u32 apic); |
| 1256 | int acpi_create_madt_lx2apic_nmi(acpi_madt_lx2apic_nmi_t *lapic_nmi, u32 cpu, |
| 1257 | u16 flags, u8 lint); |
| 1258 | int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic); |
| 1259 | int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek, |
| 1260 | u32 flags); |
Jonathan Zhang | 3164b64 | 2021-04-21 17:51:31 -0700 | [diff] [blame] | 1261 | /* |
| 1262 | * Given the Generic Initiator device's BDF, the proximity domain's ID |
| 1263 | * and flag, create Generic Initiator Affinity structure in SRAT. |
| 1264 | */ |
| 1265 | int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain, |
| 1266 | u16 seg, u8 bus, u8 dev, u8 func, u32 flags); |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1267 | int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base, |
| 1268 | u16 seg_nr, u8 start, u8 end); |
| 1269 | unsigned long acpi_create_srat_lapics(unsigned long current); |
| 1270 | void acpi_create_srat(acpi_srat_t *srat, |
| 1271 | unsigned long (*acpi_fill_srat)(unsigned long current)); |
| 1272 | |
| 1273 | void acpi_create_slit(acpi_slit_t *slit, |
| 1274 | unsigned long (*acpi_fill_slit)(unsigned long current)); |
| 1275 | |
Jonathan Zhang | 2a4e1f4 | 2021-04-01 11:43:37 -0700 | [diff] [blame] | 1276 | /* |
| 1277 | * Create a Memory Proximity Domain Attributes structure for HMAT, |
| 1278 | * given proximity domain for the attached initiaor, and |
| 1279 | * proximimity domain for the memory. |
| 1280 | */ |
| 1281 | int acpi_create_hmat_mpda(acpi_hmat_mpda_t *mpda, u32 initiator, u32 memory); |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1282 | /* Create Heterogeneous Memory Attribute Table */ |
Jonathan Zhang | 2a4e1f4 | 2021-04-01 11:43:37 -0700 | [diff] [blame] | 1283 | void acpi_create_hmat(acpi_hmat_t *hmat, |
| 1284 | unsigned long (*acpi_fill_hmat)(unsigned long current)); |
| 1285 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1286 | void acpi_create_vfct(const struct device *device, |
| 1287 | acpi_vfct_t *vfct, |
| 1288 | unsigned long (*acpi_fill_vfct)(const struct device *device, |
| 1289 | acpi_vfct_t *vfct_struct, |
| 1290 | unsigned long current)); |
| 1291 | |
| 1292 | void acpi_create_ipmi(const struct device *device, |
| 1293 | struct acpi_spmi *spmi, |
| 1294 | const u16 ipmi_revision, |
| 1295 | const acpi_addr_t *addr, |
| 1296 | const enum acpi_ipmi_interface_type type, |
| 1297 | const s8 gpe_interrupt, |
| 1298 | const u32 apic_interrupt, |
| 1299 | const u32 uid); |
| 1300 | |
| 1301 | void acpi_create_ivrs(acpi_ivrs_t *ivrs, |
| 1302 | unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct, |
| 1303 | unsigned long current)); |
| 1304 | |
Jason Glenesk | 61624b2 | 2020-11-02 20:06:23 -0800 | [diff] [blame] | 1305 | void acpi_create_crat(struct acpi_crat_header *crat, |
| 1306 | unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct, |
| 1307 | unsigned long current)); |
| 1308 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1309 | void acpi_create_hpet(acpi_hpet_t *hpet); |
| 1310 | unsigned long acpi_write_hpet(const struct device *device, unsigned long start, |
| 1311 | acpi_rsdp_t *rsdp); |
| 1312 | |
| 1313 | /* cpu/intel/speedstep/acpi.c */ |
| 1314 | void generate_cpu_entries(const struct device *device); |
| 1315 | |
| 1316 | void acpi_create_mcfg(acpi_mcfg_t *mcfg); |
| 1317 | |
| 1318 | void acpi_create_facs(acpi_facs_t *facs); |
| 1319 | |
| 1320 | void acpi_create_dbg2(acpi_dbg2_header_t *dbg2_header, |
| 1321 | int port_type, int port_subtype, |
| 1322 | acpi_addr_t *address, uint32_t address_size, |
| 1323 | const char *device_path); |
| 1324 | |
| 1325 | unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current, |
| 1326 | const struct device *dev, uint8_t access_size); |
| 1327 | void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags, |
| 1328 | unsigned long (*acpi_fill_dmar)(unsigned long)); |
| 1329 | unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags, |
| 1330 | u16 segment, u64 bar); |
| 1331 | unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment, |
| 1332 | u64 bar, u64 limit); |
| 1333 | unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags, |
| 1334 | u16 segment); |
| 1335 | unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr, |
| 1336 | u32 proximity_domain); |
| 1337 | unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number, |
| 1338 | const char *device_name); |
John Zhao | 6edbb18 | 2021-03-24 11:55:09 -0700 | [diff] [blame] | 1339 | unsigned long acpi_create_dmar_satc(unsigned long current, u8 flags, |
John Zhao | 091532d | 2021-04-17 16:03:21 -0700 | [diff] [blame] | 1340 | u16 segment); |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1341 | void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current); |
| 1342 | void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current); |
| 1343 | void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current); |
John Zhao | 6edbb18 | 2021-03-24 11:55:09 -0700 | [diff] [blame] | 1344 | void acpi_dmar_satc_fixup(unsigned long base, unsigned long current); |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1345 | unsigned long acpi_create_dmar_ds_pci_br(unsigned long current, |
| 1346 | u8 bus, u8 dev, u8 fn); |
| 1347 | unsigned long acpi_create_dmar_ds_pci(unsigned long current, |
| 1348 | u8 bus, u8 dev, u8 fn); |
| 1349 | unsigned long acpi_create_dmar_ds_ioapic(unsigned long current, |
| 1350 | u8 enumeration_id, |
| 1351 | u8 bus, u8 dev, u8 fn); |
| 1352 | unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current, |
| 1353 | u8 enumeration_id, |
| 1354 | u8 bus, u8 dev, u8 fn); |
| 1355 | void acpi_write_hest(acpi_hest_t *hest, |
| 1356 | unsigned long (*acpi_fill_hest)(acpi_hest_t *hest)); |
| 1357 | |
| 1358 | unsigned long acpi_create_hest_error_source(acpi_hest_t *hest, |
| 1359 | acpi_hest_esd_t *esd, u16 type, void *data, u16 len); |
| 1360 | |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1361 | void acpi_create_lpit(acpi_lpit_t *lpit); |
| 1362 | unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid); |
| 1363 | |
Felix Held | f7dbf4a | 2021-06-07 16:56:04 +0200 | [diff] [blame] | 1364 | /* chipsets that select ACPI_BERT must implement this function */ |
Felix Held | 2940548 | 2021-05-28 16:01:57 +0200 | [diff] [blame] | 1365 | enum cb_err acpi_soc_get_bert_region(void **region, size_t *length); |
Francois Toguo | 522e0db | 2021-01-21 09:55:19 -0800 | [diff] [blame] | 1366 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1367 | /* For ACPI S3 support. */ |
Kyösti Mälkki | a4c0e1a | 2020-06-18 08:28:12 +0300 | [diff] [blame] | 1368 | void __noreturn acpi_resume(void *wake_vec); |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1369 | void mainboard_suspend_resume(void); |
| 1370 | void *acpi_find_wakeup_vector(void); |
| 1371 | |
| 1372 | /* ACPI_Sn assignments are defined to always equal the sleep state numbers */ |
| 1373 | enum { |
| 1374 | ACPI_S0 = 0, |
| 1375 | ACPI_S1 = 1, |
| 1376 | ACPI_S2 = 2, |
| 1377 | ACPI_S3 = 3, |
| 1378 | ACPI_S4 = 4, |
| 1379 | ACPI_S5 = 5, |
| 1380 | }; |
| 1381 | |
| 1382 | #if CONFIG(ACPI_INTEL_HARDWARE_SLEEP_VALUES) \ |
| 1383 | || CONFIG(ACPI_AMD_HARDWARE_SLEEP_VALUES) |
| 1384 | /* Given the provided PM1 control register return the ACPI sleep type. */ |
| 1385 | static inline int acpi_sleep_from_pm1(uint32_t pm1_cnt) |
| 1386 | { |
| 1387 | switch (((pm1_cnt) & SLP_TYP) >> SLP_TYP_SHIFT) { |
| 1388 | case SLP_TYP_S0: return ACPI_S0; |
| 1389 | case SLP_TYP_S1: return ACPI_S1; |
| 1390 | case SLP_TYP_S3: return ACPI_S3; |
| 1391 | case SLP_TYP_S4: return ACPI_S4; |
| 1392 | case SLP_TYP_S5: return ACPI_S5; |
| 1393 | } |
| 1394 | return -1; |
| 1395 | } |
| 1396 | #endif |
| 1397 | |
Kyösti Mälkki | e0d3868 | 2020-06-07 12:01:58 +0300 | [diff] [blame] | 1398 | uint8_t acpi_get_preferred_pm_profile(void); |
| 1399 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1400 | /* Returns ACPI_Sx values. */ |
| 1401 | int acpi_get_sleep_type(void); |
| 1402 | |
| 1403 | /* Read and clear GPE status */ |
| 1404 | int acpi_get_gpe(int gpe); |
| 1405 | |
Kyösti Mälkki | 0a9e72e | 2019-08-11 01:22:28 +0300 | [diff] [blame] | 1406 | /* Once we enter payload, is SMI handler installed and capable of |
| 1407 | responding to APM_CNT Advanced Power Management Control commands. */ |
| 1408 | static inline int permanent_smi_handler(void) |
| 1409 | { |
| 1410 | return CONFIG(HAVE_SMI_HANDLER); |
| 1411 | } |
| 1412 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1413 | static inline int acpi_s3_resume_allowed(void) |
| 1414 | { |
| 1415 | return CONFIG(HAVE_ACPI_RESUME); |
| 1416 | } |
| 1417 | |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1418 | static inline int acpi_is_wakeup_s3(void) |
| 1419 | { |
Kyösti Mälkki | 4a3f67a | 2020-06-18 13:44:29 +0300 | [diff] [blame] | 1420 | if (!acpi_s3_resume_allowed()) |
| 1421 | return 0; |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1422 | |
Kyösti Mälkki | 4a3f67a | 2020-06-18 13:44:29 +0300 | [diff] [blame] | 1423 | if (ENV_ROMSTAGE_OR_BEFORE) |
| 1424 | return (acpi_get_sleep_type() == ACPI_S3); |
| 1425 | |
Kyösti Mälkki | ac0dc4a | 2020-11-18 07:40:21 +0200 | [diff] [blame] | 1426 | return romstage_handoff_is_resume(); |
Kyösti Mälkki | 4a3f67a | 2020-06-18 13:44:29 +0300 | [diff] [blame] | 1427 | } |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1428 | |
| 1429 | static inline uintptr_t acpi_align_current(uintptr_t current) |
| 1430 | { |
| 1431 | return ALIGN_UP(current, 16); |
| 1432 | } |
| 1433 | |
| 1434 | /* ACPI table revisions should match the revision of the ACPI spec |
| 1435 | * supported. This function keeps the table versions synced. This could |
| 1436 | * be made into a weak function if there is ever a need to override the |
| 1437 | * coreboot default ACPI spec version supported. */ |
| 1438 | int get_acpi_table_revision(enum acpi_tables table); |
| 1439 | |
Kyösti Mälkki | 94e0465 | 2020-06-01 13:26:22 +0300 | [diff] [blame] | 1440 | #endif // !defined(__ASSEMBLER__) && !defined(__ACPI__) |
Furquan Shaikh | e084463 | 2020-05-02 10:23:37 -0700 | [diff] [blame] | 1441 | |
Furquan Shaikh | 56eafbb | 2020-04-30 18:38:55 -0700 | [diff] [blame] | 1442 | #endif /* __ACPI_ACPI_H__ */ |