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 | ab5efd5 | 2016-05-07 07:46:25 -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 | |
| 10 | #include <common.h> |
| 11 | #include <cpu.h> |
| 12 | #include <dm.h> |
| 13 | #include <dm/uclass-internal.h> |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 14 | #include <asm/acpi_table.h> |
Bin Meng | 6aef68d | 2016-05-11 07:45:03 -0700 | [diff] [blame] | 15 | #include <asm/io.h> |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 16 | #include <asm/lapic.h> |
| 17 | #include <asm/tables.h> |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 18 | |
| 19 | /* |
Bin Meng | dfbb18b | 2016-05-07 07:46:24 -0700 | [diff] [blame] | 20 | * IASL compiles the dsdt entries and writes the hex values |
| 21 | * to a C array AmlCode[] (see dsdt.c). |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 22 | */ |
| 23 | extern const unsigned char AmlCode[]; |
| 24 | |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 25 | static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, |
| 26 | struct acpi_xsdt *xsdt) |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 27 | { |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 28 | memset(rsdp, 0, sizeof(struct acpi_rsdp)); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 29 | |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 30 | memcpy(rsdp->signature, RSDP_SIG, 8); |
| 31 | memcpy(rsdp->oem_id, OEM_ID, 6); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 32 | |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 33 | rsdp->length = sizeof(struct acpi_rsdp); |
| 34 | rsdp->rsdt_address = (u32)rsdt; |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 35 | |
| 36 | /* |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 37 | * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2 |
| 38 | * |
| 39 | * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2. |
| 40 | * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR |
| 41 | * revision 0) |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 42 | */ |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 43 | if (xsdt == NULL) { |
| 44 | rsdp->revision = ACPI_RSDP_REV_ACPI_1_0; |
| 45 | } else { |
| 46 | rsdp->xsdt_address = (u64)(u32)xsdt; |
| 47 | rsdp->revision = ACPI_RSDP_REV_ACPI_2_0; |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 48 | } |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 49 | |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 50 | /* Calculate checksums */ |
| 51 | rsdp->checksum = table_compute_checksum((void *)rsdp, 20); |
| 52 | rsdp->ext_checksum = table_compute_checksum((void *)rsdp, |
| 53 | sizeof(struct acpi_rsdp)); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 54 | } |
| 55 | |
Bin Meng | dfbb18b | 2016-05-07 07:46:24 -0700 | [diff] [blame] | 56 | void acpi_fill_header(struct acpi_table_header *header, char *signature) |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 57 | { |
Bin Meng | dfbb18b | 2016-05-07 07:46:24 -0700 | [diff] [blame] | 58 | memcpy(header->signature, signature, 4); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 59 | memcpy(header->oem_id, OEM_ID, 6); |
Bin Meng | 8a8c035 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 60 | memcpy(header->oem_table_id, OEM_TABLE_ID, 8); |
| 61 | memcpy(header->aslc_id, ASLC_ID, 4); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 62 | } |
| 63 | |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 64 | static void acpi_write_rsdt(struct acpi_rsdt *rsdt) |
| 65 | { |
Bin Meng | 8a8c035 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 66 | struct acpi_table_header *header = &(rsdt->header); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 67 | |
| 68 | /* Fill out header fields */ |
Bin Meng | dfbb18b | 2016-05-07 07:46:24 -0700 | [diff] [blame] | 69 | acpi_fill_header(header, "RSDT"); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 70 | header->length = sizeof(struct acpi_rsdt); |
Bin Meng | 7e6343e | 2016-05-07 07:46:28 -0700 | [diff] [blame] | 71 | header->revision = 1; |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 72 | |
| 73 | /* Entries are filled in later, we come with an empty set */ |
| 74 | |
| 75 | /* Fix checksum */ |
| 76 | header->checksum = table_compute_checksum((void *)rsdt, |
| 77 | sizeof(struct acpi_rsdt)); |
| 78 | } |
| 79 | |
| 80 | static void acpi_write_xsdt(struct acpi_xsdt *xsdt) |
| 81 | { |
Bin Meng | 8a8c035 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 82 | struct acpi_table_header *header = &(xsdt->header); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 83 | |
| 84 | /* Fill out header fields */ |
Bin Meng | dfbb18b | 2016-05-07 07:46:24 -0700 | [diff] [blame] | 85 | acpi_fill_header(header, "XSDT"); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 86 | header->length = sizeof(struct acpi_xsdt); |
Bin Meng | 7e6343e | 2016-05-07 07:46:28 -0700 | [diff] [blame] | 87 | header->revision = 1; |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 88 | |
| 89 | /* Entries are filled in later, we come with an empty set */ |
| 90 | |
| 91 | /* Fix checksum */ |
| 92 | header->checksum = table_compute_checksum((void *)xsdt, |
| 93 | sizeof(struct acpi_xsdt)); |
| 94 | } |
| 95 | |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 96 | /** |
| 97 | * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length |
| 98 | * and checksum. |
| 99 | */ |
| 100 | static void acpi_add_table(struct acpi_rsdp *rsdp, void *table) |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 101 | { |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 102 | int i, entries_num; |
| 103 | struct acpi_rsdt *rsdt; |
| 104 | struct acpi_xsdt *xsdt = NULL; |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 105 | |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 106 | /* The RSDT is mandatory while the XSDT is not */ |
| 107 | rsdt = (struct acpi_rsdt *)rsdp->rsdt_address; |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 108 | |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 109 | if (rsdp->xsdt_address) |
| 110 | xsdt = (struct acpi_xsdt *)((u32)rsdp->xsdt_address); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 111 | |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 112 | /* This should always be MAX_ACPI_TABLES */ |
| 113 | entries_num = ARRAY_SIZE(rsdt->entry); |
| 114 | |
| 115 | for (i = 0; i < entries_num; i++) { |
| 116 | if (rsdt->entry[i] == 0) |
| 117 | break; |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 118 | } |
| 119 | |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 120 | if (i >= entries_num) { |
| 121 | debug("ACPI: Error: too many tables\n"); |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | /* Add table to the RSDT */ |
| 126 | rsdt->entry[i] = (u32)table; |
| 127 | |
| 128 | /* Fix RSDT length or the kernel will assume invalid entries */ |
| 129 | rsdt->header.length = sizeof(struct acpi_table_header) + |
| 130 | (sizeof(u32) * (i + 1)); |
| 131 | |
| 132 | /* Re-calculate checksum */ |
| 133 | rsdt->header.checksum = 0; |
| 134 | rsdt->header.checksum = table_compute_checksum((u8 *)rsdt, |
| 135 | rsdt->header.length); |
| 136 | |
| 137 | /* |
| 138 | * And now the same thing for the XSDT. We use the same index as for |
| 139 | * now we want the XSDT and RSDT to always be in sync in U-Boot |
| 140 | */ |
| 141 | if (xsdt) { |
| 142 | /* Add table to the XSDT */ |
| 143 | xsdt->entry[i] = (u64)(u32)table; |
| 144 | |
| 145 | /* Fix XSDT length */ |
| 146 | xsdt->header.length = sizeof(struct acpi_table_header) + |
| 147 | (sizeof(u64) * (i + 1)); |
| 148 | |
| 149 | /* Re-calculate checksum */ |
| 150 | xsdt->header.checksum = 0; |
| 151 | xsdt->header.checksum = table_compute_checksum((u8 *)xsdt, |
| 152 | xsdt->header.length); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | static void acpi_create_facs(struct acpi_facs *facs) |
| 157 | { |
| 158 | memset((void *)facs, 0, sizeof(struct acpi_facs)); |
| 159 | |
| 160 | memcpy(facs->signature, "FACS", 4); |
| 161 | facs->length = sizeof(struct acpi_facs); |
| 162 | facs->hardware_signature = 0; |
| 163 | facs->firmware_waking_vector = 0; |
| 164 | facs->global_lock = 0; |
| 165 | facs->flags = 0; |
| 166 | facs->x_firmware_waking_vector_l = 0; |
| 167 | facs->x_firmware_waking_vector_h = 0; |
| 168 | facs->version = 1; |
| 169 | } |
| 170 | |
| 171 | static int acpi_create_madt_lapic(struct acpi_madt_lapic *lapic, |
| 172 | u8 cpu, u8 apic) |
| 173 | { |
| 174 | lapic->type = ACPI_APIC_LAPIC; |
| 175 | lapic->length = sizeof(struct acpi_madt_lapic); |
| 176 | lapic->flags = LOCAL_APIC_FLAG_ENABLED; |
| 177 | lapic->processor_id = cpu; |
| 178 | lapic->apic_id = apic; |
| 179 | |
| 180 | return lapic->length; |
| 181 | } |
| 182 | |
Bin Meng | fc4f5cc | 2016-05-07 07:46:30 -0700 | [diff] [blame] | 183 | int acpi_create_madt_lapics(u32 current) |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 184 | { |
| 185 | struct udevice *dev; |
Bin Meng | fc4f5cc | 2016-05-07 07:46:30 -0700 | [diff] [blame] | 186 | int length = 0; |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 187 | |
| 188 | for (uclass_find_first_device(UCLASS_CPU, &dev); |
| 189 | dev; |
| 190 | uclass_find_next_device(&dev)) { |
| 191 | struct cpu_platdata *plat = dev_get_parent_platdata(dev); |
| 192 | |
Bin Meng | fc4f5cc | 2016-05-07 07:46:30 -0700 | [diff] [blame] | 193 | length += acpi_create_madt_lapic( |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 194 | (struct acpi_madt_lapic *)current, |
| 195 | plat->cpu_id, plat->cpu_id); |
Bin Meng | fc4f5cc | 2016-05-07 07:46:30 -0700 | [diff] [blame] | 196 | current += length; |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Bin Meng | fc4f5cc | 2016-05-07 07:46:30 -0700 | [diff] [blame] | 199 | return length; |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | int acpi_create_madt_ioapic(struct acpi_madt_ioapic *ioapic, u8 id, |
| 203 | u32 addr, u32 gsi_base) |
| 204 | { |
| 205 | ioapic->type = ACPI_APIC_IOAPIC; |
| 206 | ioapic->length = sizeof(struct acpi_madt_ioapic); |
| 207 | ioapic->reserved = 0x00; |
| 208 | ioapic->gsi_base = gsi_base; |
| 209 | ioapic->ioapic_id = id; |
| 210 | ioapic->ioapic_addr = addr; |
| 211 | |
| 212 | return ioapic->length; |
| 213 | } |
| 214 | |
| 215 | int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride, |
| 216 | u8 bus, u8 source, u32 gsirq, u16 flags) |
| 217 | { |
| 218 | irqoverride->type = ACPI_APIC_IRQ_SRC_OVERRIDE; |
| 219 | irqoverride->length = sizeof(struct acpi_madt_irqoverride); |
| 220 | irqoverride->bus = bus; |
| 221 | irqoverride->source = source; |
| 222 | irqoverride->gsirq = gsirq; |
| 223 | irqoverride->flags = flags; |
| 224 | |
| 225 | return irqoverride->length; |
| 226 | } |
| 227 | |
| 228 | int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi, |
| 229 | u8 cpu, u16 flags, u8 lint) |
| 230 | { |
| 231 | lapic_nmi->type = ACPI_APIC_LAPIC_NMI; |
| 232 | lapic_nmi->length = sizeof(struct acpi_madt_lapic_nmi); |
| 233 | lapic_nmi->flags = flags; |
| 234 | lapic_nmi->processor_id = cpu; |
| 235 | lapic_nmi->lint = lint; |
| 236 | |
| 237 | return lapic_nmi->length; |
| 238 | } |
| 239 | |
| 240 | static void acpi_create_madt(struct acpi_madt *madt) |
| 241 | { |
| 242 | struct acpi_table_header *header = &(madt->header); |
Bin Meng | 7e79a6b | 2016-05-07 07:46:26 -0700 | [diff] [blame] | 243 | u32 current = (u32)madt + sizeof(struct acpi_madt); |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 244 | |
| 245 | memset((void *)madt, 0, sizeof(struct acpi_madt)); |
| 246 | |
| 247 | /* Fill out header fields */ |
| 248 | acpi_fill_header(header, "APIC"); |
| 249 | header->length = sizeof(struct acpi_madt); |
Bin Meng | 7e6343e | 2016-05-07 07:46:28 -0700 | [diff] [blame] | 250 | header->revision = 4; |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 251 | |
| 252 | madt->lapic_addr = LAPIC_DEFAULT_BASE; |
| 253 | madt->flags = ACPI_MADT_PCAT_COMPAT; |
| 254 | |
| 255 | current = acpi_fill_madt(current); |
| 256 | |
| 257 | /* (Re)calculate length and checksum */ |
Bin Meng | 7e79a6b | 2016-05-07 07:46:26 -0700 | [diff] [blame] | 258 | header->length = current - (u32)madt; |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 259 | |
| 260 | header->checksum = table_compute_checksum((void *)madt, header->length); |
| 261 | } |
| 262 | |
| 263 | static int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig, |
| 264 | u32 base, u16 seg_nr, u8 start, u8 end) |
| 265 | { |
| 266 | memset(mmconfig, 0, sizeof(*mmconfig)); |
| 267 | mmconfig->base_address_l = base; |
| 268 | mmconfig->base_address_h = 0; |
| 269 | mmconfig->pci_segment_group_number = seg_nr; |
| 270 | mmconfig->start_bus_number = start; |
| 271 | mmconfig->end_bus_number = end; |
| 272 | |
| 273 | return sizeof(struct acpi_mcfg_mmconfig); |
| 274 | } |
| 275 | |
Bin Meng | 7e79a6b | 2016-05-07 07:46:26 -0700 | [diff] [blame] | 276 | static u32 acpi_fill_mcfg(u32 current) |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 277 | { |
| 278 | current += acpi_create_mcfg_mmconfig |
| 279 | ((struct acpi_mcfg_mmconfig *)current, |
| 280 | CONFIG_PCIE_ECAM_BASE, 0x0, 0x0, 255); |
| 281 | |
| 282 | return current; |
| 283 | } |
| 284 | |
| 285 | /* MCFG is defined in the PCI Firmware Specification 3.0 */ |
| 286 | static void acpi_create_mcfg(struct acpi_mcfg *mcfg) |
| 287 | { |
| 288 | struct acpi_table_header *header = &(mcfg->header); |
Bin Meng | 7e79a6b | 2016-05-07 07:46:26 -0700 | [diff] [blame] | 289 | u32 current = (u32)mcfg + sizeof(struct acpi_mcfg); |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 290 | |
| 291 | memset((void *)mcfg, 0, sizeof(struct acpi_mcfg)); |
| 292 | |
| 293 | /* Fill out header fields */ |
| 294 | acpi_fill_header(header, "MCFG"); |
| 295 | header->length = sizeof(struct acpi_mcfg); |
Bin Meng | 7e6343e | 2016-05-07 07:46:28 -0700 | [diff] [blame] | 296 | header->revision = 1; |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 297 | |
| 298 | current = acpi_fill_mcfg(current); |
| 299 | |
| 300 | /* (Re)calculate length and checksum */ |
Bin Meng | 7e79a6b | 2016-05-07 07:46:26 -0700 | [diff] [blame] | 301 | header->length = current - (u32)mcfg; |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 302 | header->checksum = table_compute_checksum((void *)mcfg, header->length); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 303 | } |
| 304 | |
Bin Meng | 6aef68d | 2016-05-11 07:45:03 -0700 | [diff] [blame] | 305 | static void enter_acpi_mode(int pm1_cnt) |
| 306 | { |
| 307 | /* |
| 308 | * PM1_CNT register bit0 selects the power management event to be |
| 309 | * either an SCI or SMI interrupt. When this bit is set, then power |
| 310 | * management events will generate an SCI interrupt. When this bit |
| 311 | * is reset power management events will generate an SMI interrupt. |
| 312 | * |
| 313 | * Per ACPI spec, it is the responsibility of the hardware to set |
| 314 | * or reset this bit. OSPM always preserves this bit position. |
| 315 | * |
| 316 | * U-Boot does not support SMI. And we don't have plan to support |
| 317 | * anything running in SMM within U-Boot. To create a legacy-free |
| 318 | * system, and expose ourselves to OSPM as working under ACPI mode |
| 319 | * already, turn this bit on. |
| 320 | */ |
| 321 | outw(PM1_CNT_SCI_EN, pm1_cnt); |
| 322 | } |
| 323 | |
Miao Yan | fa287b1 | 2016-01-20 01:57:06 -0800 | [diff] [blame] | 324 | /* |
| 325 | * QEMU's version of write_acpi_tables is defined in |
Tom Rini | dd6f3ab | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 326 | * arch/x86/cpu/qemu/acpi_table.c |
Miao Yan | fa287b1 | 2016-01-20 01:57:06 -0800 | [diff] [blame] | 327 | */ |
Bin Meng | 358bb3f | 2016-02-27 22:58:00 -0800 | [diff] [blame] | 328 | u32 write_acpi_tables(u32 start) |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 329 | { |
Bin Meng | 358bb3f | 2016-02-27 22:58:00 -0800 | [diff] [blame] | 330 | u32 current; |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 331 | struct acpi_rsdp *rsdp; |
| 332 | struct acpi_rsdt *rsdt; |
| 333 | struct acpi_xsdt *xsdt; |
| 334 | struct acpi_facs *facs; |
Bin Meng | 8a8c035 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 335 | struct acpi_table_header *dsdt; |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 336 | struct acpi_fadt *fadt; |
| 337 | struct acpi_mcfg *mcfg; |
| 338 | struct acpi_madt *madt; |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 339 | |
| 340 | current = start; |
| 341 | |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 342 | /* Align ACPI tables to 16 byte */ |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 343 | current = ALIGN(current, 16); |
| 344 | |
Bin Meng | dca4d1a | 2016-05-07 07:46:12 -0700 | [diff] [blame] | 345 | debug("ACPI: Writing ACPI tables at %x\n", start); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 346 | |
| 347 | /* We need at least an RSDP and an RSDT Table */ |
| 348 | rsdp = (struct acpi_rsdp *)current; |
| 349 | current += sizeof(struct acpi_rsdp); |
| 350 | current = ALIGN(current, 16); |
| 351 | rsdt = (struct acpi_rsdt *)current; |
| 352 | current += sizeof(struct acpi_rsdt); |
| 353 | current = ALIGN(current, 16); |
| 354 | xsdt = (struct acpi_xsdt *)current; |
| 355 | current += sizeof(struct acpi_xsdt); |
Bin Meng | 25e133e | 2016-05-07 07:46:27 -0700 | [diff] [blame] | 356 | /* |
| 357 | * Per ACPI spec, the FACS table address must be aligned to a 64 byte |
| 358 | * boundary (Windows checks this, but Linux does not). |
| 359 | */ |
| 360 | current = ALIGN(current, 64); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 361 | |
| 362 | /* clear all table memory */ |
| 363 | memset((void *)start, 0, current - start); |
| 364 | |
| 365 | acpi_write_rsdp(rsdp, rsdt, xsdt); |
| 366 | acpi_write_rsdt(rsdt); |
| 367 | acpi_write_xsdt(xsdt); |
| 368 | |
| 369 | debug("ACPI: * FACS\n"); |
| 370 | facs = (struct acpi_facs *)current; |
| 371 | current += sizeof(struct acpi_facs); |
| 372 | current = ALIGN(current, 16); |
| 373 | |
| 374 | acpi_create_facs(facs); |
| 375 | |
| 376 | debug("ACPI: * DSDT\n"); |
Bin Meng | 8a8c035 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 377 | dsdt = (struct acpi_table_header *)current; |
| 378 | memcpy(dsdt, &AmlCode, sizeof(struct acpi_table_header)); |
Bin Meng | 10fcabe | 2016-05-11 07:45:05 -0700 | [diff] [blame] | 379 | current += sizeof(struct acpi_table_header); |
| 380 | memcpy((char *)current, |
| 381 | (char *)&AmlCode + sizeof(struct acpi_table_header), |
| 382 | dsdt->length - sizeof(struct acpi_table_header)); |
| 383 | current += dsdt->length - sizeof(struct acpi_table_header); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 384 | current = ALIGN(current, 16); |
| 385 | |
| 386 | debug("ACPI: * FADT\n"); |
| 387 | fadt = (struct acpi_fadt *)current; |
| 388 | current += sizeof(struct acpi_fadt); |
| 389 | current = ALIGN(current, 16); |
| 390 | acpi_create_fadt(fadt, facs, dsdt); |
| 391 | acpi_add_table(rsdp, fadt); |
| 392 | |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 393 | debug("ACPI: * MADT\n"); |
| 394 | madt = (struct acpi_madt *)current; |
| 395 | acpi_create_madt(madt); |
Bin Meng | 10fcabe | 2016-05-11 07:45:05 -0700 | [diff] [blame] | 396 | current += madt->header.length; |
| 397 | acpi_add_table(rsdp, madt); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 398 | current = ALIGN(current, 16); |
| 399 | |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 400 | debug("ACPI: * MCFG\n"); |
| 401 | mcfg = (struct acpi_mcfg *)current; |
| 402 | acpi_create_mcfg(mcfg); |
Bin Meng | 10fcabe | 2016-05-11 07:45:05 -0700 | [diff] [blame] | 403 | current += mcfg->header.length; |
| 404 | acpi_add_table(rsdp, mcfg); |
| 405 | current = ALIGN(current, 16); |
Bin Meng | ab5efd5 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 406 | |
Bin Meng | dca4d1a | 2016-05-07 07:46:12 -0700 | [diff] [blame] | 407 | debug("current = %x\n", current); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 408 | |
Bin Meng | dca4d1a | 2016-05-07 07:46:12 -0700 | [diff] [blame] | 409 | debug("ACPI: done\n"); |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 410 | |
Bin Meng | 6aef68d | 2016-05-11 07:45:03 -0700 | [diff] [blame] | 411 | /* |
| 412 | * Other than waiting for OSPM to request us to switch to ACPI mode, |
| 413 | * do it by ourselves, since SMI will not be triggered. |
| 414 | */ |
| 415 | enter_acpi_mode(fadt->pm1a_cnt_blk); |
| 416 | |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 417 | return current; |
| 418 | } |