Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Based on acpi.c from coreboot |
| 3 | * |
| 4 | * Copyright (C) 2015, Saket Sinha <saket.sinha89@gmail.com> |
Bin Meng | 728c4af | 2016-05-07 07:46:22 -0700 | [diff] [blame^] | 5 | * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com> |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
Bin Meng | 8a8c035 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 10 | #define RSDP_SIG "RSD PTR " /* RSDP pointer signature */ |
| 11 | #define OEM_ID "U-BOOT" /* U-Boot */ |
| 12 | #define OEM_TABLE_ID "U-BOOTBL" /* U-Boot Table */ |
| 13 | #define ASLC_ID "INTL" /* Intel ASL Compiler */ |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 14 | |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 15 | #define ACPI_RSDP_REV_ACPI_1_0 0 |
| 16 | #define ACPI_RSDP_REV_ACPI_2_0 2 |
| 17 | |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 18 | /* |
| 19 | * RSDP (Root System Description Pointer) |
| 20 | * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum |
| 21 | */ |
| 22 | struct acpi_rsdp { |
| 23 | char signature[8]; /* RSDP signature */ |
| 24 | u8 checksum; /* Checksum of the first 20 bytes */ |
| 25 | char oem_id[6]; /* OEM ID */ |
Bin Meng | 728c4af | 2016-05-07 07:46:22 -0700 | [diff] [blame^] | 26 | u8 revision; /* 0 for ACPI 1.0, others 2 */ |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 27 | u32 rsdt_address; /* Physical address of RSDT (32 bits) */ |
| 28 | u32 length; /* Total RSDP length (incl. extended part) */ |
| 29 | u64 xsdt_address; /* Physical address of XSDT (64 bits) */ |
| 30 | u8 ext_checksum; /* Checksum of the whole table */ |
| 31 | u8 reserved[3]; |
| 32 | }; |
| 33 | |
Bin Meng | 728c4af | 2016-05-07 07:46:22 -0700 | [diff] [blame^] | 34 | #define ACPI_REV_ACPI_1_0 1 |
| 35 | #define ACPI_REV_ACPI_2_0 1 |
| 36 | #define ACPI_REV_ACPI_3_0 2 |
| 37 | #define ACPI_REV_ACPI_4_0 3 |
| 38 | #define ACPI_REV_ACPI_5_0 5 |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 39 | |
| 40 | /* Generic ACPI header, provided by (almost) all tables */ |
Bin Meng | 8a8c035 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 41 | struct acpi_table_header { |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 42 | char signature[4]; /* ACPI signature (4 ASCII characters) */ |
| 43 | u32 length; /* Table length in bytes (incl. header) */ |
| 44 | u8 revision; /* Table version (not ACPI version!) */ |
| 45 | volatile u8 checksum; /* To make sum of entire table == 0 */ |
| 46 | char oem_id[6]; /* OEM identification */ |
| 47 | char oem_table_id[8]; /* OEM table identification */ |
| 48 | u32 oem_revision; /* OEM revision number */ |
Bin Meng | 8a8c035 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 49 | char aslc_id[4]; /* ASL compiler vendor ID */ |
| 50 | u32 aslc_revision; /* ASL compiler revision number */ |
| 51 | }; |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 52 | |
| 53 | /* A maximum number of 32 ACPI tables ought to be enough for now */ |
Bin Meng | 728c4af | 2016-05-07 07:46:22 -0700 | [diff] [blame^] | 54 | #define MAX_ACPI_TABLES 32 |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 55 | |
| 56 | /* RSDT (Root System Description Table) */ |
| 57 | struct acpi_rsdt { |
| 58 | struct acpi_table_header header; |
| 59 | u32 entry[MAX_ACPI_TABLES]; |
| 60 | }; |
| 61 | |
| 62 | /* XSDT (Extended System Description Table) */ |
| 63 | struct acpi_xsdt { |
| 64 | struct acpi_table_header header; |
| 65 | u64 entry[MAX_ACPI_TABLES]; |
| 66 | }; |
| 67 | |
Bin Meng | 728c4af | 2016-05-07 07:46:22 -0700 | [diff] [blame^] | 68 | /* FADT Preferred Power Management Profile */ |
| 69 | enum acpi_pm_profile { |
| 70 | ACPI_PM_UNSPECIFIED = 0, |
| 71 | ACPI_PM_DESKTOP, |
| 72 | ACPI_PM_MOBILE, |
| 73 | ACPI_PM_WORKSTATION, |
| 74 | ACPI_PM_ENTERPRISE_SERVER, |
| 75 | ACPI_PM_SOHO_SERVER, |
| 76 | ACPI_PM_APPLIANCE_PC, |
| 77 | ACPI_PM_PERFORMANCE_SERVER, |
| 78 | ACPI_PM_TABLET |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 79 | }; |
| 80 | |
Bin Meng | 728c4af | 2016-05-07 07:46:22 -0700 | [diff] [blame^] | 81 | /* FADT flags for p_lvl2_lat and p_lvl3_lat */ |
| 82 | #define ACPI_FADT_C2_NOT_SUPPORTED 101 |
| 83 | #define ACPI_FADT_C3_NOT_SUPPORTED 1001 |
| 84 | |
| 85 | /* FADT Boot Architecture Flags */ |
| 86 | #define ACPI_FADT_LEGACY_FREE 0x00 |
| 87 | #define ACPI_FADT_LEGACY_DEVICES (1 << 0) |
| 88 | #define ACPI_FADT_8042 (1 << 1) |
| 89 | #define ACPI_FADT_VGA_NOT_PRESENT (1 << 2) |
| 90 | #define ACPI_FADT_MSI_NOT_SUPPORTED (1 << 3) |
| 91 | #define ACPI_FADT_NO_PCIE_ASPM_CONTROL (1 << 4) |
| 92 | |
| 93 | /* FADT Feature Flags */ |
| 94 | #define ACPI_FADT_WBINVD (1 << 0) |
| 95 | #define ACPI_FADT_WBINVD_FLUSH (1 << 1) |
| 96 | #define ACPI_FADT_C1_SUPPORTED (1 << 2) |
| 97 | #define ACPI_FADT_C2_MP_SUPPORTED (1 << 3) |
| 98 | #define ACPI_FADT_POWER_BUTTON (1 << 4) |
| 99 | #define ACPI_FADT_SLEEP_BUTTON (1 << 5) |
| 100 | #define ACPI_FADT_FIXED_RTC (1 << 6) |
| 101 | #define ACPI_FADT_S4_RTC_WAKE (1 << 7) |
| 102 | #define ACPI_FADT_32BIT_TIMER (1 << 8) |
| 103 | #define ACPI_FADT_DOCKING_SUPPORTED (1 << 9) |
| 104 | #define ACPI_FADT_RESET_REGISTER (1 << 10) |
| 105 | #define ACPI_FADT_SEALED_CASE (1 << 11) |
| 106 | #define ACPI_FADT_HEADLESS (1 << 12) |
| 107 | #define ACPI_FADT_SLEEP_TYPE (1 << 13) |
| 108 | #define ACPI_FADT_PCI_EXPRESS_WAKE (1 << 14) |
| 109 | #define ACPI_FADT_PLATFORM_CLOCK (1 << 15) |
| 110 | #define ACPI_FADT_S4_RTC_VALID (1 << 16) |
| 111 | #define ACPI_FADT_REMOTE_POWER_ON (1 << 17) |
| 112 | #define ACPI_FADT_APIC_CLUSTER (1 << 18) |
| 113 | #define ACPI_FADT_APIC_PHYSICAL (1 << 19) |
| 114 | #define ACPI_FADT_HW_REDUCED_ACPI (1 << 20) |
| 115 | #define ACPI_FADT_LOW_PWR_IDLE_S0 (1 << 21) |
| 116 | |
| 117 | enum acpi_address_space_type { |
| 118 | ACPI_ADDRESS_SPACE_MEMORY = 0, /* System memory */ |
| 119 | ACPI_ADDRESS_SPACE_IO, /* System I/O */ |
| 120 | ACPI_ADDRESS_SPACE_PCI, /* PCI config space */ |
| 121 | ACPI_ADDRESS_SPACE_EC, /* Embedded controller */ |
| 122 | ACPI_ADDRESS_SPACE_SMBUS, /* SMBus */ |
| 123 | ACPI_ADDRESS_SPACE_PCC = 0x0a, /* Platform Comm. Channel */ |
| 124 | ACPI_ADDRESS_SPACE_FIXED = 0x7f /* Functional fixed hardware */ |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 125 | }; |
| 126 | |
Bin Meng | 728c4af | 2016-05-07 07:46:22 -0700 | [diff] [blame^] | 127 | enum acpi_address_space_size { |
| 128 | ACPI_ACCESS_SIZE_UNDEFINED = 0, |
| 129 | ACPI_ACCESS_SIZE_BYTE_ACCESS, |
| 130 | ACPI_ACCESS_SIZE_WORD_ACCESS, |
| 131 | ACPI_ACCESS_SIZE_DWORD_ACCESS, |
| 132 | ACPI_ACCESS_SIZE_QWORD_ACCESS |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 133 | }; |
| 134 | |
Bin Meng | 728c4af | 2016-05-07 07:46:22 -0700 | [diff] [blame^] | 135 | struct acpi_gen_regaddr { |
| 136 | u8 space_id; /* Address space ID */ |
| 137 | u8 bit_width; /* Register size in bits */ |
| 138 | u8 bit_offset; /* Register bit offset */ |
| 139 | u8 access_size; /* Access size */ |
| 140 | u32 addrl; /* Register address, low 32 bits */ |
| 141 | u32 addrh; /* Register address, high 32 bits */ |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | /* FADT (Fixed ACPI Description Table) */ |
| 145 | struct __packed acpi_fadt { |
| 146 | struct acpi_table_header header; |
| 147 | u32 firmware_ctrl; |
| 148 | u32 dsdt; |
Bin Meng | 8a8c035 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 149 | u8 res1; |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 150 | u8 preferred_pm_profile; |
| 151 | u16 sci_int; |
| 152 | u32 smi_cmd; |
| 153 | u8 acpi_enable; |
| 154 | u8 acpi_disable; |
| 155 | u8 s4bios_req; |
| 156 | u8 pstate_cnt; |
| 157 | u32 pm1a_evt_blk; |
| 158 | u32 pm1b_evt_blk; |
| 159 | u32 pm1a_cnt_blk; |
| 160 | u32 pm1b_cnt_blk; |
| 161 | u32 pm2_cnt_blk; |
| 162 | u32 pm_tmr_blk; |
| 163 | u32 gpe0_blk; |
| 164 | u32 gpe1_blk; |
| 165 | u8 pm1_evt_len; |
| 166 | u8 pm1_cnt_len; |
| 167 | u8 pm2_cnt_len; |
| 168 | u8 pm_tmr_len; |
| 169 | u8 gpe0_blk_len; |
| 170 | u8 gpe1_blk_len; |
| 171 | u8 gpe1_base; |
| 172 | u8 cst_cnt; |
| 173 | u16 p_lvl2_lat; |
| 174 | u16 p_lvl3_lat; |
| 175 | u16 flush_size; |
| 176 | u16 flush_stride; |
| 177 | u8 duty_offset; |
| 178 | u8 duty_width; |
| 179 | u8 day_alrm; |
| 180 | u8 mon_alrm; |
| 181 | u8 century; |
| 182 | u16 iapc_boot_arch; |
| 183 | u8 res2; |
| 184 | u32 flags; |
| 185 | struct acpi_gen_regaddr reset_reg; |
| 186 | u8 reset_value; |
| 187 | u8 res3; |
| 188 | u8 res4; |
| 189 | u8 res5; |
| 190 | u32 x_firmware_ctl_l; |
| 191 | u32 x_firmware_ctl_h; |
| 192 | u32 x_dsdt_l; |
| 193 | u32 x_dsdt_h; |
| 194 | struct acpi_gen_regaddr x_pm1a_evt_blk; |
| 195 | struct acpi_gen_regaddr x_pm1b_evt_blk; |
| 196 | struct acpi_gen_regaddr x_pm1a_cnt_blk; |
| 197 | struct acpi_gen_regaddr x_pm1b_cnt_blk; |
| 198 | struct acpi_gen_regaddr x_pm2_cnt_blk; |
| 199 | struct acpi_gen_regaddr x_pm_tmr_blk; |
| 200 | struct acpi_gen_regaddr x_gpe0_blk; |
| 201 | struct acpi_gen_regaddr x_gpe1_blk; |
| 202 | }; |
| 203 | |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 204 | /* FACS flags */ |
| 205 | #define ACPI_FACS_S4BIOS_F (1 << 0) |
| 206 | #define ACPI_FACS_64BIT_WAKE_F (1 << 1) |
Bin Meng | 728c4af | 2016-05-07 07:46:22 -0700 | [diff] [blame^] | 207 | |
| 208 | /* FACS (Firmware ACPI Control Structure) */ |
| 209 | struct acpi_facs { |
| 210 | char signature[4]; /* "FACS" */ |
| 211 | u32 length; /* Length in bytes (>= 64) */ |
| 212 | u32 hardware_signature; /* Hardware signature */ |
| 213 | u32 firmware_waking_vector; /* Firmware waking vector */ |
| 214 | u32 global_lock; /* Global lock */ |
| 215 | u32 flags; /* FACS flags */ |
| 216 | u32 x_firmware_waking_vector_l; /* X FW waking vector, low */ |
| 217 | u32 x_firmware_waking_vector_h; /* X FW waking vector, high */ |
| 218 | u8 version; /* Version 2 */ |
| 219 | u8 res1[3]; |
| 220 | u32 ospm_flags; /* OSPM enabled flags */ |
| 221 | u8 res2[24]; |
| 222 | }; |
| 223 | |
| 224 | /* MADT flags */ |
| 225 | #define ACPI_MADT_PCAT_COMPAT (1 << 0) |
| 226 | |
| 227 | /* MADT (Multiple APIC Description Table) */ |
| 228 | struct acpi_madt { |
| 229 | struct acpi_table_header header; |
| 230 | u32 lapic_addr; /* Local APIC address */ |
| 231 | u32 flags; /* Multiple APIC flags */ |
| 232 | }; |
| 233 | |
| 234 | /* MADT: APIC Structure Type*/ |
| 235 | enum acpi_apic_types { |
| 236 | ACPI_APIC_LAPIC = 0, /* Processor local APIC */ |
| 237 | ACPI_APIC_IOAPIC, /* I/O APIC */ |
| 238 | ACPI_APIC_IRQ_SRC_OVERRIDE, /* Interrupt source override */ |
| 239 | ACPI_APIC_NMI_SRC, /* NMI source */ |
| 240 | ACPI_APIC_LAPIC_NMI, /* Local APIC NMI */ |
| 241 | ACPI_APIC_LAPIC_ADDR_OVERRIDE, /* Local APIC address override */ |
| 242 | ACPI_APIC_IOSAPIC, /* I/O SAPIC */ |
| 243 | ACPI_APIC_LSAPIC, /* Local SAPIC */ |
| 244 | ACPI_APIC_PLATFORM_IRQ_SRC, /* Platform interrupt sources */ |
| 245 | ACPI_APIC_LX2APIC, /* Processor local x2APIC */ |
| 246 | ACPI_APIC_LX2APIC_NMI, /* Local x2APIC NMI */ |
| 247 | }; |
| 248 | |
| 249 | /* MADT: Processor Local APIC Structure */ |
| 250 | |
| 251 | #define LOCAL_APIC_FLAG_ENABLED (1 << 0) |
| 252 | |
| 253 | struct acpi_madt_lapic { |
| 254 | u8 type; /* Type (0) */ |
| 255 | u8 length; /* Length in bytes (8) */ |
| 256 | u8 processor_id; /* ACPI processor ID */ |
| 257 | u8 apic_id; /* Local APIC ID */ |
| 258 | u32 flags; /* Local APIC flags */ |
| 259 | }; |
| 260 | |
| 261 | /* MADT: I/O APIC Structure */ |
| 262 | struct acpi_madt_ioapic { |
| 263 | u8 type; /* Type (1) */ |
| 264 | u8 length; /* Length in bytes (12) */ |
| 265 | u8 ioapic_id; /* I/O APIC ID */ |
| 266 | u8 reserved; |
| 267 | u32 ioapic_addr; /* I/O APIC address */ |
| 268 | u32 gsi_base; /* Global system interrupt base */ |
| 269 | }; |
| 270 | |
| 271 | /* MADT: Interrupt Source Override Structure */ |
| 272 | struct __packed acpi_madt_irqoverride { |
| 273 | u8 type; /* Type (2) */ |
| 274 | u8 length; /* Length in bytes (10) */ |
| 275 | u8 bus; /* ISA (0) */ |
| 276 | u8 source; /* Bus-relative int. source (IRQ) */ |
| 277 | u32 gsirq; /* Global system interrupt */ |
| 278 | u16 flags; /* MPS INTI flags */ |
| 279 | }; |
| 280 | |
| 281 | /* MADT: Local APIC NMI Structure */ |
| 282 | struct __packed acpi_madt_lapic_nmi { |
| 283 | u8 type; /* Type (4) */ |
| 284 | u8 length; /* Length in bytes (6) */ |
| 285 | u8 processor_id; /* ACPI processor ID */ |
| 286 | u16 flags; /* MPS INTI flags */ |
| 287 | u8 lint; /* Local APIC LINT# */ |
| 288 | }; |
| 289 | |
| 290 | /* MCFG (PCI Express MMIO config space BAR description table) */ |
| 291 | struct acpi_mcfg { |
| 292 | struct acpi_table_header header; |
| 293 | u8 reserved[8]; |
| 294 | }; |
| 295 | |
| 296 | struct acpi_mcfg_mmconfig { |
| 297 | u32 base_address_l; |
| 298 | u32 base_address_h; |
| 299 | u16 pci_segment_group_number; |
| 300 | u8 start_bus_number; |
| 301 | u8 end_bus_number; |
| 302 | u8 reserved[4]; |
| 303 | }; |
| 304 | |
| 305 | #define OEM_REVISION 42 |
| 306 | #define ASL_COMPILER_REVISION 42 |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 307 | |
| 308 | /* These can be used by the target port */ |
| 309 | |
| 310 | unsigned long acpi_create_madt_lapics(unsigned long current); |
| 311 | int acpi_create_madt_ioapic(struct acpi_madt_ioapic *ioapic, u8 id, u32 addr, |
| 312 | u32 gsi_base); |
| 313 | int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride, |
| 314 | u8 bus, u8 source, u32 gsirq, u16 flags); |
| 315 | unsigned long acpi_fill_madt(unsigned long current); |
| 316 | void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs, |
| 317 | void *dsdt); |
| 318 | int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi, u8 cpu, |
| 319 | u16 flags, u8 lint); |
Bin Meng | 358bb3f | 2016-02-27 22:58:00 -0800 | [diff] [blame] | 320 | u32 write_acpi_tables(u32 start); |