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