Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Based on acpi.c from coreboot |
| 4 | * |
| 5 | * Copyright (C) 2015, Saket Sinha <saket.sinha89@gmail.com> |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 6 | * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <cpu.h> |
| 11 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 13 | #include <dm/uclass-internal.h> |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 14 | #include <mapmem.h> |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 15 | #include <serial.h> |
Andy Shevchenko | 87e9537 | 2017-07-21 22:32:02 +0300 | [diff] [blame] | 16 | #include <version.h> |
Simon Glass | 858fed1 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 17 | #include <acpi/acpi_table.h> |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 18 | #include <asm/acpi/global_nvs.h> |
Andy Shevchenko | 13a5d87 | 2017-07-21 22:32:04 +0300 | [diff] [blame] | 19 | #include <asm/ioapic.h> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 20 | #include <asm/lapic.h> |
Andy Shevchenko | 13a5d87 | 2017-07-21 22:32:04 +0300 | [diff] [blame] | 21 | #include <asm/mpspec.h> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 22 | #include <asm/tables.h> |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 23 | #include <asm/arch/global_nvs.h> |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 24 | #include <dm/acpi.h> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 25 | |
| 26 | /* |
Bin Meng | b063d5f | 2016-05-07 07:46:24 -0700 | [diff] [blame] | 27 | * IASL compiles the dsdt entries and writes the hex values |
| 28 | * to a C array AmlCode[] (see dsdt.c). |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 29 | */ |
| 30 | extern const unsigned char AmlCode[]; |
| 31 | |
Andy Shevchenko | 66d3e63 | 2018-01-10 19:40:15 +0200 | [diff] [blame] | 32 | /* ACPI RSDP address to be used in boot parameters */ |
Bin Meng | e102925 | 2018-01-30 05:01:16 -0800 | [diff] [blame] | 33 | static ulong acpi_rsdp_addr; |
Andy Shevchenko | 66d3e63 | 2018-01-10 19:40:15 +0200 | [diff] [blame] | 34 | |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 35 | static void acpi_create_facs(struct acpi_facs *facs) |
| 36 | { |
| 37 | memset((void *)facs, 0, sizeof(struct acpi_facs)); |
| 38 | |
| 39 | memcpy(facs->signature, "FACS", 4); |
| 40 | facs->length = sizeof(struct acpi_facs); |
| 41 | facs->hardware_signature = 0; |
| 42 | facs->firmware_waking_vector = 0; |
| 43 | facs->global_lock = 0; |
| 44 | facs->flags = 0; |
| 45 | facs->x_firmware_waking_vector_l = 0; |
| 46 | facs->x_firmware_waking_vector_h = 0; |
| 47 | facs->version = 1; |
| 48 | } |
| 49 | |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 50 | static int acpi_create_madt_lapic(struct acpi_madt_lapic *lapic, |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 51 | u8 cpu, u8 apic) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 52 | { |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 53 | lapic->type = ACPI_APIC_LAPIC; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 54 | lapic->length = sizeof(struct acpi_madt_lapic); |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 55 | lapic->flags = LOCAL_APIC_FLAG_ENABLED; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 56 | lapic->processor_id = cpu; |
| 57 | lapic->apic_id = apic; |
| 58 | |
| 59 | return lapic->length; |
| 60 | } |
| 61 | |
Bin Meng | 3c5234e | 2016-05-07 07:46:30 -0700 | [diff] [blame] | 62 | int acpi_create_madt_lapics(u32 current) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 63 | { |
| 64 | struct udevice *dev; |
George McCollister | 5a49f87 | 2016-06-07 13:40:18 -0500 | [diff] [blame] | 65 | int total_length = 0; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 66 | |
| 67 | for (uclass_find_first_device(UCLASS_CPU, &dev); |
| 68 | dev; |
| 69 | uclass_find_next_device(&dev)) { |
| 70 | struct cpu_platdata *plat = dev_get_parent_platdata(dev); |
George McCollister | 5a49f87 | 2016-06-07 13:40:18 -0500 | [diff] [blame] | 71 | int length = acpi_create_madt_lapic( |
| 72 | (struct acpi_madt_lapic *)current, |
| 73 | plat->cpu_id, plat->cpu_id); |
Bin Meng | 3c5234e | 2016-05-07 07:46:30 -0700 | [diff] [blame] | 74 | current += length; |
George McCollister | 5a49f87 | 2016-06-07 13:40:18 -0500 | [diff] [blame] | 75 | total_length += length; |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 76 | } |
| 77 | |
George McCollister | 5a49f87 | 2016-06-07 13:40:18 -0500 | [diff] [blame] | 78 | return total_length; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 79 | } |
| 80 | |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 81 | int acpi_create_madt_ioapic(struct acpi_madt_ioapic *ioapic, u8 id, |
| 82 | u32 addr, u32 gsi_base) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 83 | { |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 84 | ioapic->type = ACPI_APIC_IOAPIC; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 85 | ioapic->length = sizeof(struct acpi_madt_ioapic); |
| 86 | ioapic->reserved = 0x00; |
| 87 | ioapic->gsi_base = gsi_base; |
| 88 | ioapic->ioapic_id = id; |
| 89 | ioapic->ioapic_addr = addr; |
| 90 | |
| 91 | return ioapic->length; |
| 92 | } |
| 93 | |
| 94 | int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride, |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 95 | u8 bus, u8 source, u32 gsirq, u16 flags) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 96 | { |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 97 | irqoverride->type = ACPI_APIC_IRQ_SRC_OVERRIDE; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 98 | irqoverride->length = sizeof(struct acpi_madt_irqoverride); |
| 99 | irqoverride->bus = bus; |
| 100 | irqoverride->source = source; |
| 101 | irqoverride->gsirq = gsirq; |
| 102 | irqoverride->flags = flags; |
| 103 | |
| 104 | return irqoverride->length; |
| 105 | } |
| 106 | |
| 107 | int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi, |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 108 | u8 cpu, u16 flags, u8 lint) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 109 | { |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 110 | lapic_nmi->type = ACPI_APIC_LAPIC_NMI; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 111 | lapic_nmi->length = sizeof(struct acpi_madt_lapic_nmi); |
| 112 | lapic_nmi->flags = flags; |
| 113 | lapic_nmi->processor_id = cpu; |
| 114 | lapic_nmi->lint = lint; |
| 115 | |
| 116 | return lapic_nmi->length; |
| 117 | } |
| 118 | |
Andy Shevchenko | 13a5d87 | 2017-07-21 22:32:04 +0300 | [diff] [blame] | 119 | static int acpi_create_madt_irq_overrides(u32 current) |
| 120 | { |
| 121 | struct acpi_madt_irqoverride *irqovr; |
| 122 | u16 sci_flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH; |
| 123 | int length = 0; |
| 124 | |
| 125 | irqovr = (void *)current; |
| 126 | length += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0); |
| 127 | |
| 128 | irqovr = (void *)(current + length); |
| 129 | length += acpi_create_madt_irqoverride(irqovr, 0, 9, 9, sci_flags); |
| 130 | |
| 131 | return length; |
| 132 | } |
| 133 | |
| 134 | __weak u32 acpi_fill_madt(u32 current) |
| 135 | { |
| 136 | current += acpi_create_madt_lapics(current); |
| 137 | |
| 138 | current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current, |
| 139 | io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0); |
| 140 | |
| 141 | current += acpi_create_madt_irq_overrides(current); |
| 142 | |
| 143 | return current; |
| 144 | } |
| 145 | |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 146 | static void acpi_create_madt(struct acpi_madt *madt) |
| 147 | { |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 148 | struct acpi_table_header *header = &(madt->header); |
Bin Meng | a1ec7db | 2016-05-07 07:46:26 -0700 | [diff] [blame] | 149 | u32 current = (u32)madt + sizeof(struct acpi_madt); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 150 | |
| 151 | memset((void *)madt, 0, sizeof(struct acpi_madt)); |
| 152 | |
| 153 | /* Fill out header fields */ |
Bin Meng | b063d5f | 2016-05-07 07:46:24 -0700 | [diff] [blame] | 154 | acpi_fill_header(header, "APIC"); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 155 | header->length = sizeof(struct acpi_madt); |
Bin Meng | f662fe4 | 2016-05-07 07:46:28 -0700 | [diff] [blame] | 156 | header->revision = 4; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 157 | |
| 158 | madt->lapic_addr = LAPIC_DEFAULT_BASE; |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 159 | madt->flags = ACPI_MADT_PCAT_COMPAT; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 160 | |
| 161 | current = acpi_fill_madt(current); |
| 162 | |
| 163 | /* (Re)calculate length and checksum */ |
Bin Meng | a1ec7db | 2016-05-07 07:46:26 -0700 | [diff] [blame] | 164 | header->length = current - (u32)madt; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 165 | |
| 166 | header->checksum = table_compute_checksum((void *)madt, header->length); |
| 167 | } |
| 168 | |
Andy Shevchenko | c1ae980 | 2017-07-21 22:32:05 +0300 | [diff] [blame] | 169 | int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig, u32 base, |
| 170 | u16 seg_nr, u8 start, u8 end) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 171 | { |
| 172 | memset(mmconfig, 0, sizeof(*mmconfig)); |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 173 | mmconfig->base_address_l = base; |
| 174 | mmconfig->base_address_h = 0; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 175 | mmconfig->pci_segment_group_number = seg_nr; |
| 176 | mmconfig->start_bus_number = start; |
| 177 | mmconfig->end_bus_number = end; |
| 178 | |
| 179 | return sizeof(struct acpi_mcfg_mmconfig); |
| 180 | } |
| 181 | |
Andy Shevchenko | c1ae980 | 2017-07-21 22:32:05 +0300 | [diff] [blame] | 182 | __weak u32 acpi_fill_mcfg(u32 current) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 183 | { |
| 184 | current += acpi_create_mcfg_mmconfig |
| 185 | ((struct acpi_mcfg_mmconfig *)current, |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 186 | CONFIG_PCIE_ECAM_BASE, 0x0, 0x0, 255); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 187 | |
| 188 | return current; |
| 189 | } |
| 190 | |
| 191 | /* MCFG is defined in the PCI Firmware Specification 3.0 */ |
| 192 | static void acpi_create_mcfg(struct acpi_mcfg *mcfg) |
| 193 | { |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 194 | struct acpi_table_header *header = &(mcfg->header); |
Bin Meng | a1ec7db | 2016-05-07 07:46:26 -0700 | [diff] [blame] | 195 | u32 current = (u32)mcfg + sizeof(struct acpi_mcfg); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 196 | |
| 197 | memset((void *)mcfg, 0, sizeof(struct acpi_mcfg)); |
| 198 | |
| 199 | /* Fill out header fields */ |
Bin Meng | b063d5f | 2016-05-07 07:46:24 -0700 | [diff] [blame] | 200 | acpi_fill_header(header, "MCFG"); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 201 | header->length = sizeof(struct acpi_mcfg); |
Bin Meng | f662fe4 | 2016-05-07 07:46:28 -0700 | [diff] [blame] | 202 | header->revision = 1; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 203 | |
| 204 | current = acpi_fill_mcfg(current); |
| 205 | |
| 206 | /* (Re)calculate length and checksum */ |
Bin Meng | a1ec7db | 2016-05-07 07:46:26 -0700 | [diff] [blame] | 207 | header->length = current - (u32)mcfg; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 208 | header->checksum = table_compute_checksum((void *)mcfg, header->length); |
| 209 | } |
| 210 | |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 211 | __weak u32 acpi_fill_csrt(u32 current) |
| 212 | { |
| 213 | return current; |
| 214 | } |
| 215 | |
| 216 | static void acpi_create_csrt(struct acpi_csrt *csrt) |
| 217 | { |
| 218 | struct acpi_table_header *header = &(csrt->header); |
| 219 | u32 current = (u32)csrt + sizeof(struct acpi_csrt); |
| 220 | |
| 221 | memset((void *)csrt, 0, sizeof(struct acpi_csrt)); |
| 222 | |
| 223 | /* Fill out header fields */ |
| 224 | acpi_fill_header(header, "CSRT"); |
| 225 | header->length = sizeof(struct acpi_csrt); |
| 226 | header->revision = 0; |
| 227 | |
| 228 | current = acpi_fill_csrt(current); |
| 229 | |
| 230 | /* (Re)calculate length and checksum */ |
| 231 | header->length = current - (u32)csrt; |
| 232 | header->checksum = table_compute_checksum((void *)csrt, header->length); |
| 233 | } |
| 234 | |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 235 | static void acpi_create_spcr(struct acpi_spcr *spcr) |
| 236 | { |
| 237 | struct acpi_table_header *header = &(spcr->header); |
| 238 | struct serial_device_info serial_info = {0}; |
| 239 | ulong serial_address, serial_offset; |
Simon Glass | daaff93 | 2018-12-28 14:23:08 -0700 | [diff] [blame] | 240 | struct udevice *dev; |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 241 | uint serial_config; |
| 242 | uint serial_width; |
| 243 | int access_size; |
| 244 | int space_id; |
Andy Shevchenko | bf9c8e3 | 2019-02-28 17:19:54 +0200 | [diff] [blame] | 245 | int ret = -ENODEV; |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 246 | |
| 247 | /* Fill out header fields */ |
| 248 | acpi_fill_header(header, "SPCR"); |
| 249 | header->length = sizeof(struct acpi_spcr); |
| 250 | header->revision = 2; |
| 251 | |
Simon Glass | 896c164 | 2018-12-28 14:23:10 -0700 | [diff] [blame] | 252 | /* Read the device once, here. It is reused below */ |
Andy Shevchenko | bf9c8e3 | 2019-02-28 17:19:54 +0200 | [diff] [blame] | 253 | dev = gd->cur_serial_dev; |
| 254 | if (dev) |
Simon Glass | 896c164 | 2018-12-28 14:23:10 -0700 | [diff] [blame] | 255 | ret = serial_getinfo(dev, &serial_info); |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 256 | if (ret) |
| 257 | serial_info.type = SERIAL_CHIP_UNKNOWN; |
| 258 | |
| 259 | /* Encode chip type */ |
| 260 | switch (serial_info.type) { |
| 261 | case SERIAL_CHIP_16550_COMPATIBLE: |
| 262 | spcr->interface_type = ACPI_DBG2_16550_COMPATIBLE; |
| 263 | break; |
| 264 | case SERIAL_CHIP_UNKNOWN: |
| 265 | default: |
| 266 | spcr->interface_type = ACPI_DBG2_UNKNOWN; |
| 267 | break; |
| 268 | } |
| 269 | |
| 270 | /* Encode address space */ |
| 271 | switch (serial_info.addr_space) { |
| 272 | case SERIAL_ADDRESS_SPACE_MEMORY: |
| 273 | space_id = ACPI_ADDRESS_SPACE_MEMORY; |
| 274 | break; |
| 275 | case SERIAL_ADDRESS_SPACE_IO: |
| 276 | default: |
| 277 | space_id = ACPI_ADDRESS_SPACE_IO; |
| 278 | break; |
| 279 | } |
| 280 | |
| 281 | serial_width = serial_info.reg_width * 8; |
| 282 | serial_offset = serial_info.reg_offset << serial_info.reg_shift; |
| 283 | serial_address = serial_info.addr + serial_offset; |
| 284 | |
| 285 | /* Encode register access size */ |
| 286 | switch (serial_info.reg_shift) { |
| 287 | case 0: |
| 288 | access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
| 289 | break; |
| 290 | case 1: |
| 291 | access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
| 292 | break; |
| 293 | case 2: |
| 294 | access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 295 | break; |
| 296 | case 3: |
| 297 | access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS; |
| 298 | break; |
| 299 | default: |
| 300 | access_size = ACPI_ACCESS_SIZE_UNDEFINED; |
| 301 | break; |
| 302 | } |
| 303 | |
| 304 | debug("UART type %u @ %lx\n", spcr->interface_type, serial_address); |
| 305 | |
| 306 | /* Fill GAS */ |
| 307 | spcr->serial_port.space_id = space_id; |
| 308 | spcr->serial_port.bit_width = serial_width; |
| 309 | spcr->serial_port.bit_offset = 0; |
| 310 | spcr->serial_port.access_size = access_size; |
| 311 | spcr->serial_port.addrl = lower_32_bits(serial_address); |
| 312 | spcr->serial_port.addrh = upper_32_bits(serial_address); |
| 313 | |
| 314 | /* Encode baud rate */ |
| 315 | switch (serial_info.baudrate) { |
| 316 | case 9600: |
| 317 | spcr->baud_rate = 3; |
| 318 | break; |
| 319 | case 19200: |
| 320 | spcr->baud_rate = 4; |
| 321 | break; |
| 322 | case 57600: |
| 323 | spcr->baud_rate = 6; |
| 324 | break; |
| 325 | case 115200: |
| 326 | spcr->baud_rate = 7; |
| 327 | break; |
| 328 | default: |
| 329 | spcr->baud_rate = 0; |
| 330 | break; |
| 331 | } |
| 332 | |
Simon Glass | 896c164 | 2018-12-28 14:23:10 -0700 | [diff] [blame] | 333 | serial_config = SERIAL_DEFAULT_CONFIG; |
| 334 | if (dev) |
Simon Glass | daaff93 | 2018-12-28 14:23:08 -0700 | [diff] [blame] | 335 | ret = serial_getconfig(dev, &serial_config); |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 336 | |
| 337 | spcr->parity = SERIAL_GET_PARITY(serial_config); |
| 338 | spcr->stop_bits = SERIAL_GET_STOP(serial_config); |
| 339 | |
| 340 | /* No PCI devices for now */ |
| 341 | spcr->pci_device_id = 0xffff; |
| 342 | spcr->pci_vendor_id = 0xffff; |
| 343 | |
Andy Shevchenko | 225cc8a | 2020-02-27 17:21:56 +0200 | [diff] [blame] | 344 | /* |
| 345 | * SPCR has no clue if the UART base clock speed is different |
| 346 | * to the default one. However, the SPCR 1.04 defines baud rate |
| 347 | * 0 as a preconfigured state of UART and OS is supposed not |
| 348 | * to touch the configuration of the serial device. |
| 349 | */ |
| 350 | if (serial_info.clock != SERIAL_DEFAULT_CLOCK) |
| 351 | spcr->baud_rate = 0; |
| 352 | |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 353 | /* Fix checksum */ |
| 354 | header->checksum = table_compute_checksum((void *)spcr, header->length); |
| 355 | } |
| 356 | |
Miao Yan | 3b68c52 | 2016-01-20 01:57:06 -0800 | [diff] [blame] | 357 | /* |
Andy Shevchenko | 4b05bac | 2018-01-10 19:33:10 +0200 | [diff] [blame] | 358 | * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c |
Miao Yan | 3b68c52 | 2016-01-20 01:57:06 -0800 | [diff] [blame] | 359 | */ |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 360 | ulong write_acpi_tables(ulong start_addr) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 361 | { |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 362 | struct acpi_ctx sctx, *ctx = &sctx; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 363 | struct acpi_facs *facs; |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 364 | struct acpi_table_header *dsdt; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 365 | struct acpi_fadt *fadt; |
| 366 | struct acpi_mcfg *mcfg; |
| 367 | struct acpi_madt *madt; |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 368 | struct acpi_csrt *csrt; |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 369 | struct acpi_spcr *spcr; |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 370 | void *start; |
| 371 | ulong addr; |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 372 | int i; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 373 | |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 374 | start = map_sysmem(start_addr, 0); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 375 | |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 376 | debug("ACPI: Writing ACPI tables at %lx\n", start_addr); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 377 | |
Simon Glass | 9c442a6 | 2020-04-26 09:19:51 -0600 | [diff] [blame] | 378 | acpi_setup_base_tables(ctx, start); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 379 | |
| 380 | debug("ACPI: * FACS\n"); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 381 | facs = ctx->current; |
| 382 | acpi_inc_align(ctx, sizeof(struct acpi_facs)); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 383 | |
| 384 | acpi_create_facs(facs); |
| 385 | |
| 386 | debug("ACPI: * DSDT\n"); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 387 | dsdt = ctx->current; |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 388 | memcpy(dsdt, &AmlCode, sizeof(struct acpi_table_header)); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 389 | acpi_inc(ctx, sizeof(struct acpi_table_header)); |
| 390 | memcpy(ctx->current, |
Bin Meng | d90434b | 2016-05-11 07:45:05 -0700 | [diff] [blame] | 391 | (char *)&AmlCode + sizeof(struct acpi_table_header), |
| 392 | dsdt->length - sizeof(struct acpi_table_header)); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 393 | acpi_inc_align(ctx, dsdt->length - sizeof(struct acpi_table_header)); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 394 | |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 395 | /* Pack GNVS into the ACPI table area */ |
| 396 | for (i = 0; i < dsdt->length; i++) { |
| 397 | u32 *gnvs = (u32 *)((u32)dsdt + i); |
| 398 | if (*gnvs == ACPI_GNVS_ADDR) { |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 399 | ulong addr = (ulong)map_to_sysmem(ctx->current); |
| 400 | |
| 401 | debug("Fix up global NVS in DSDT to %#08lx\n", addr); |
| 402 | *gnvs = addr; |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 403 | break; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /* Update DSDT checksum since we patched the GNVS address */ |
| 408 | dsdt->checksum = 0; |
| 409 | dsdt->checksum = table_compute_checksum((void *)dsdt, dsdt->length); |
| 410 | |
| 411 | /* Fill in platform-specific global NVS variables */ |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 412 | acpi_create_gnvs(ctx->current); |
| 413 | acpi_inc_align(ctx, sizeof(struct acpi_global_nvs)); |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 414 | |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 415 | debug("ACPI: * FADT\n"); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 416 | fadt = ctx->current; |
| 417 | acpi_inc_align(ctx, sizeof(struct acpi_fadt)); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 418 | acpi_create_fadt(fadt, facs, dsdt); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 419 | acpi_add_table(ctx, fadt); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 420 | |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 421 | debug("ACPI: * MADT\n"); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 422 | madt = ctx->current; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 423 | acpi_create_madt(madt); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 424 | acpi_inc_align(ctx, madt->header.length); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 425 | acpi_add_table(ctx, madt); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 426 | |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 427 | debug("ACPI: * MCFG\n"); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 428 | mcfg = ctx->current; |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 429 | acpi_create_mcfg(mcfg); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 430 | acpi_inc_align(ctx, mcfg->header.length); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 431 | acpi_add_table(ctx, mcfg); |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 432 | |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 433 | debug("ACPI: * CSRT\n"); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 434 | csrt = ctx->current; |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 435 | acpi_create_csrt(csrt); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 436 | acpi_inc_align(ctx, csrt->header.length); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 437 | acpi_add_table(ctx, csrt); |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 438 | |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 439 | debug("ACPI: * SPCR\n"); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 440 | spcr = ctx->current; |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 441 | acpi_create_spcr(spcr); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 442 | acpi_inc_align(ctx, spcr->header.length); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 443 | acpi_add_table(ctx, spcr); |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 444 | |
Simon Glass | 179fb82 | 2020-04-26 09:19:48 -0600 | [diff] [blame] | 445 | acpi_write_dev_tables(ctx); |
| 446 | |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 447 | addr = map_to_sysmem(ctx->current); |
| 448 | debug("current = %lx\n", addr); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 449 | |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 450 | acpi_rsdp_addr = (unsigned long)ctx->rsdp; |
Bin Meng | d2d2218 | 2016-05-07 07:46:12 -0700 | [diff] [blame] | 451 | debug("ACPI: done\n"); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 452 | |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 453 | return addr; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 454 | } |
Bin Meng | 34bc74a | 2017-04-21 07:24:36 -0700 | [diff] [blame] | 455 | |
Bin Meng | e102925 | 2018-01-30 05:01:16 -0800 | [diff] [blame] | 456 | ulong acpi_get_rsdp_addr(void) |
| 457 | { |
| 458 | return acpi_rsdp_addr; |
| 459 | } |