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 | 9597189 | 2020-09-22 12:45:10 -0600 | [diff] [blame] | 18 | #include <acpi/acpi_device.h> |
Simon Glass | 858fed1 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 19 | #include <acpi/acpi_table.h> |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 20 | #include <asm/acpi/global_nvs.h> |
Andy Shevchenko | 13a5d87 | 2017-07-21 22:32:04 +0300 | [diff] [blame] | 21 | #include <asm/ioapic.h> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 22 | #include <asm/lapic.h> |
Andy Shevchenko | 13a5d87 | 2017-07-21 22:32:04 +0300 | [diff] [blame] | 23 | #include <asm/mpspec.h> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 24 | #include <asm/tables.h> |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 25 | #include <asm/arch/global_nvs.h> |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 26 | #include <dm/acpi.h> |
Simon Glass | 9ed41e7 | 2020-07-07 21:32:05 -0600 | [diff] [blame] | 27 | #include <linux/err.h> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 28 | |
| 29 | /* |
Bin Meng | b063d5f | 2016-05-07 07:46:24 -0700 | [diff] [blame] | 30 | * IASL compiles the dsdt entries and writes the hex values |
| 31 | * to a C array AmlCode[] (see dsdt.c). |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 32 | */ |
| 33 | extern const unsigned char AmlCode[]; |
| 34 | |
Andy Shevchenko | 66d3e63 | 2018-01-10 19:40:15 +0200 | [diff] [blame] | 35 | /* ACPI RSDP address to be used in boot parameters */ |
Bin Meng | e102925 | 2018-01-30 05:01:16 -0800 | [diff] [blame] | 36 | static ulong acpi_rsdp_addr; |
Andy Shevchenko | 66d3e63 | 2018-01-10 19:40:15 +0200 | [diff] [blame] | 37 | |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 38 | static void acpi_create_facs(struct acpi_facs *facs) |
| 39 | { |
| 40 | memset((void *)facs, 0, sizeof(struct acpi_facs)); |
| 41 | |
| 42 | memcpy(facs->signature, "FACS", 4); |
| 43 | facs->length = sizeof(struct acpi_facs); |
| 44 | facs->hardware_signature = 0; |
| 45 | facs->firmware_waking_vector = 0; |
| 46 | facs->global_lock = 0; |
| 47 | facs->flags = 0; |
| 48 | facs->x_firmware_waking_vector_l = 0; |
| 49 | facs->x_firmware_waking_vector_h = 0; |
| 50 | facs->version = 1; |
| 51 | } |
| 52 | |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 53 | static int acpi_create_madt_lapic(struct acpi_madt_lapic *lapic, |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 54 | u8 cpu, u8 apic) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 55 | { |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 56 | lapic->type = ACPI_APIC_LAPIC; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 57 | lapic->length = sizeof(struct acpi_madt_lapic); |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 58 | lapic->flags = LOCAL_APIC_FLAG_ENABLED; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 59 | lapic->processor_id = cpu; |
| 60 | lapic->apic_id = apic; |
| 61 | |
| 62 | return lapic->length; |
| 63 | } |
| 64 | |
Bin Meng | 3c5234e | 2016-05-07 07:46:30 -0700 | [diff] [blame] | 65 | int acpi_create_madt_lapics(u32 current) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 66 | { |
| 67 | struct udevice *dev; |
George McCollister | 5a49f87 | 2016-06-07 13:40:18 -0500 | [diff] [blame] | 68 | int total_length = 0; |
Simon Glass | fcae547 | 2020-09-22 12:45:31 -0600 | [diff] [blame^] | 69 | int cpu_num = 0; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 70 | |
| 71 | for (uclass_find_first_device(UCLASS_CPU, &dev); |
| 72 | dev; |
| 73 | uclass_find_next_device(&dev)) { |
| 74 | struct cpu_platdata *plat = dev_get_parent_platdata(dev); |
Simon Glass | fcae547 | 2020-09-22 12:45:31 -0600 | [diff] [blame^] | 75 | int length; |
| 76 | |
| 77 | length = acpi_create_madt_lapic( |
| 78 | (struct acpi_madt_lapic *)current, cpu_num++, |
| 79 | plat->cpu_id); |
Bin Meng | 3c5234e | 2016-05-07 07:46:30 -0700 | [diff] [blame] | 80 | current += length; |
George McCollister | 5a49f87 | 2016-06-07 13:40:18 -0500 | [diff] [blame] | 81 | total_length += length; |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 82 | } |
| 83 | |
George McCollister | 5a49f87 | 2016-06-07 13:40:18 -0500 | [diff] [blame] | 84 | return total_length; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 85 | } |
| 86 | |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 87 | int acpi_create_madt_ioapic(struct acpi_madt_ioapic *ioapic, u8 id, |
| 88 | u32 addr, u32 gsi_base) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 89 | { |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 90 | ioapic->type = ACPI_APIC_IOAPIC; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 91 | ioapic->length = sizeof(struct acpi_madt_ioapic); |
| 92 | ioapic->reserved = 0x00; |
| 93 | ioapic->gsi_base = gsi_base; |
| 94 | ioapic->ioapic_id = id; |
| 95 | ioapic->ioapic_addr = addr; |
| 96 | |
| 97 | return ioapic->length; |
| 98 | } |
| 99 | |
| 100 | int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride, |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 101 | u8 bus, u8 source, u32 gsirq, u16 flags) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 102 | { |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 103 | irqoverride->type = ACPI_APIC_IRQ_SRC_OVERRIDE; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 104 | irqoverride->length = sizeof(struct acpi_madt_irqoverride); |
| 105 | irqoverride->bus = bus; |
| 106 | irqoverride->source = source; |
| 107 | irqoverride->gsirq = gsirq; |
| 108 | irqoverride->flags = flags; |
| 109 | |
| 110 | return irqoverride->length; |
| 111 | } |
| 112 | |
| 113 | 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] | 114 | u8 cpu, u16 flags, u8 lint) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 115 | { |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 116 | lapic_nmi->type = ACPI_APIC_LAPIC_NMI; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 117 | lapic_nmi->length = sizeof(struct acpi_madt_lapic_nmi); |
| 118 | lapic_nmi->flags = flags; |
| 119 | lapic_nmi->processor_id = cpu; |
| 120 | lapic_nmi->lint = lint; |
| 121 | |
| 122 | return lapic_nmi->length; |
| 123 | } |
| 124 | |
Andy Shevchenko | 13a5d87 | 2017-07-21 22:32:04 +0300 | [diff] [blame] | 125 | static int acpi_create_madt_irq_overrides(u32 current) |
| 126 | { |
| 127 | struct acpi_madt_irqoverride *irqovr; |
| 128 | u16 sci_flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH; |
| 129 | int length = 0; |
| 130 | |
| 131 | irqovr = (void *)current; |
| 132 | length += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0); |
| 133 | |
| 134 | irqovr = (void *)(current + length); |
| 135 | length += acpi_create_madt_irqoverride(irqovr, 0, 9, 9, sci_flags); |
| 136 | |
| 137 | return length; |
| 138 | } |
| 139 | |
| 140 | __weak u32 acpi_fill_madt(u32 current) |
| 141 | { |
| 142 | current += acpi_create_madt_lapics(current); |
| 143 | |
| 144 | current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current, |
| 145 | io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0); |
| 146 | |
| 147 | current += acpi_create_madt_irq_overrides(current); |
| 148 | |
| 149 | return current; |
| 150 | } |
| 151 | |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 152 | static void acpi_create_madt(struct acpi_madt *madt) |
| 153 | { |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 154 | struct acpi_table_header *header = &(madt->header); |
Bin Meng | a1ec7db | 2016-05-07 07:46:26 -0700 | [diff] [blame] | 155 | u32 current = (u32)madt + sizeof(struct acpi_madt); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 156 | |
| 157 | memset((void *)madt, 0, sizeof(struct acpi_madt)); |
| 158 | |
| 159 | /* Fill out header fields */ |
Bin Meng | b063d5f | 2016-05-07 07:46:24 -0700 | [diff] [blame] | 160 | acpi_fill_header(header, "APIC"); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 161 | header->length = sizeof(struct acpi_madt); |
Simon Glass | f3694aa | 2020-07-16 21:22:37 -0600 | [diff] [blame] | 162 | header->revision = ACPI_MADT_REV_ACPI_3_0; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 163 | |
| 164 | madt->lapic_addr = LAPIC_DEFAULT_BASE; |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 165 | madt->flags = ACPI_MADT_PCAT_COMPAT; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 166 | |
| 167 | current = acpi_fill_madt(current); |
| 168 | |
| 169 | /* (Re)calculate length and checksum */ |
Bin Meng | a1ec7db | 2016-05-07 07:46:26 -0700 | [diff] [blame] | 170 | header->length = current - (u32)madt; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 171 | |
| 172 | header->checksum = table_compute_checksum((void *)madt, header->length); |
| 173 | } |
| 174 | |
Andy Shevchenko | c1ae980 | 2017-07-21 22:32:05 +0300 | [diff] [blame] | 175 | int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig, u32 base, |
| 176 | u16 seg_nr, u8 start, u8 end) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 177 | { |
| 178 | memset(mmconfig, 0, sizeof(*mmconfig)); |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 179 | mmconfig->base_address_l = base; |
| 180 | mmconfig->base_address_h = 0; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 181 | mmconfig->pci_segment_group_number = seg_nr; |
| 182 | mmconfig->start_bus_number = start; |
| 183 | mmconfig->end_bus_number = end; |
| 184 | |
| 185 | return sizeof(struct acpi_mcfg_mmconfig); |
| 186 | } |
| 187 | |
Andy Shevchenko | c1ae980 | 2017-07-21 22:32:05 +0300 | [diff] [blame] | 188 | __weak u32 acpi_fill_mcfg(u32 current) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 189 | { |
| 190 | current += acpi_create_mcfg_mmconfig |
| 191 | ((struct acpi_mcfg_mmconfig *)current, |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 192 | CONFIG_PCIE_ECAM_BASE, 0x0, 0x0, 255); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 193 | |
| 194 | return current; |
| 195 | } |
| 196 | |
| 197 | /* MCFG is defined in the PCI Firmware Specification 3.0 */ |
| 198 | static void acpi_create_mcfg(struct acpi_mcfg *mcfg) |
| 199 | { |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 200 | struct acpi_table_header *header = &(mcfg->header); |
Bin Meng | a1ec7db | 2016-05-07 07:46:26 -0700 | [diff] [blame] | 201 | u32 current = (u32)mcfg + sizeof(struct acpi_mcfg); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 202 | |
| 203 | memset((void *)mcfg, 0, sizeof(struct acpi_mcfg)); |
| 204 | |
| 205 | /* Fill out header fields */ |
Bin Meng | b063d5f | 2016-05-07 07:46:24 -0700 | [diff] [blame] | 206 | acpi_fill_header(header, "MCFG"); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 207 | header->length = sizeof(struct acpi_mcfg); |
Bin Meng | f662fe4 | 2016-05-07 07:46:28 -0700 | [diff] [blame] | 208 | header->revision = 1; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 209 | |
| 210 | current = acpi_fill_mcfg(current); |
| 211 | |
| 212 | /* (Re)calculate length and checksum */ |
Bin Meng | a1ec7db | 2016-05-07 07:46:26 -0700 | [diff] [blame] | 213 | header->length = current - (u32)mcfg; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 214 | header->checksum = table_compute_checksum((void *)mcfg, header->length); |
| 215 | } |
| 216 | |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 217 | __weak u32 acpi_fill_csrt(u32 current) |
| 218 | { |
Simon Glass | 9eb8004 | 2020-07-07 21:32:24 -0600 | [diff] [blame] | 219 | return 0; |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 220 | } |
| 221 | |
Simon Glass | 9eb8004 | 2020-07-07 21:32:24 -0600 | [diff] [blame] | 222 | static int acpi_create_csrt(struct acpi_csrt *csrt) |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 223 | { |
| 224 | struct acpi_table_header *header = &(csrt->header); |
| 225 | u32 current = (u32)csrt + sizeof(struct acpi_csrt); |
Simon Glass | 9eb8004 | 2020-07-07 21:32:24 -0600 | [diff] [blame] | 226 | uint ptr; |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 227 | |
| 228 | memset((void *)csrt, 0, sizeof(struct acpi_csrt)); |
| 229 | |
| 230 | /* Fill out header fields */ |
| 231 | acpi_fill_header(header, "CSRT"); |
| 232 | header->length = sizeof(struct acpi_csrt); |
| 233 | header->revision = 0; |
| 234 | |
Simon Glass | 9eb8004 | 2020-07-07 21:32:24 -0600 | [diff] [blame] | 235 | ptr = acpi_fill_csrt(current); |
| 236 | if (!ptr) |
| 237 | return -ENOENT; |
| 238 | current = ptr; |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 239 | |
| 240 | /* (Re)calculate length and checksum */ |
| 241 | header->length = current - (u32)csrt; |
| 242 | header->checksum = table_compute_checksum((void *)csrt, header->length); |
Simon Glass | 9eb8004 | 2020-07-07 21:32:24 -0600 | [diff] [blame] | 243 | |
| 244 | return 0; |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 245 | } |
| 246 | |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 247 | static void acpi_create_spcr(struct acpi_spcr *spcr) |
| 248 | { |
| 249 | struct acpi_table_header *header = &(spcr->header); |
| 250 | struct serial_device_info serial_info = {0}; |
| 251 | ulong serial_address, serial_offset; |
Simon Glass | daaff93 | 2018-12-28 14:23:08 -0700 | [diff] [blame] | 252 | struct udevice *dev; |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 253 | uint serial_config; |
| 254 | uint serial_width; |
| 255 | int access_size; |
| 256 | int space_id; |
Andy Shevchenko | bf9c8e3 | 2019-02-28 17:19:54 +0200 | [diff] [blame] | 257 | int ret = -ENODEV; |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 258 | |
Wolfgang Wallner | 13c23e9 | 2020-09-16 16:57:53 +0200 | [diff] [blame] | 259 | memset((void *)spcr, 0, sizeof(struct acpi_spcr)); |
| 260 | |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 261 | /* Fill out header fields */ |
| 262 | acpi_fill_header(header, "SPCR"); |
| 263 | header->length = sizeof(struct acpi_spcr); |
| 264 | header->revision = 2; |
| 265 | |
Simon Glass | 896c164 | 2018-12-28 14:23:10 -0700 | [diff] [blame] | 266 | /* Read the device once, here. It is reused below */ |
Andy Shevchenko | bf9c8e3 | 2019-02-28 17:19:54 +0200 | [diff] [blame] | 267 | dev = gd->cur_serial_dev; |
| 268 | if (dev) |
Simon Glass | 896c164 | 2018-12-28 14:23:10 -0700 | [diff] [blame] | 269 | ret = serial_getinfo(dev, &serial_info); |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 270 | if (ret) |
| 271 | serial_info.type = SERIAL_CHIP_UNKNOWN; |
| 272 | |
| 273 | /* Encode chip type */ |
| 274 | switch (serial_info.type) { |
| 275 | case SERIAL_CHIP_16550_COMPATIBLE: |
| 276 | spcr->interface_type = ACPI_DBG2_16550_COMPATIBLE; |
| 277 | break; |
| 278 | case SERIAL_CHIP_UNKNOWN: |
| 279 | default: |
| 280 | spcr->interface_type = ACPI_DBG2_UNKNOWN; |
| 281 | break; |
| 282 | } |
| 283 | |
| 284 | /* Encode address space */ |
| 285 | switch (serial_info.addr_space) { |
| 286 | case SERIAL_ADDRESS_SPACE_MEMORY: |
| 287 | space_id = ACPI_ADDRESS_SPACE_MEMORY; |
| 288 | break; |
| 289 | case SERIAL_ADDRESS_SPACE_IO: |
| 290 | default: |
| 291 | space_id = ACPI_ADDRESS_SPACE_IO; |
| 292 | break; |
| 293 | } |
| 294 | |
| 295 | serial_width = serial_info.reg_width * 8; |
| 296 | serial_offset = serial_info.reg_offset << serial_info.reg_shift; |
| 297 | serial_address = serial_info.addr + serial_offset; |
| 298 | |
| 299 | /* Encode register access size */ |
| 300 | switch (serial_info.reg_shift) { |
| 301 | case 0: |
| 302 | access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
| 303 | break; |
| 304 | case 1: |
| 305 | access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
| 306 | break; |
| 307 | case 2: |
| 308 | access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 309 | break; |
| 310 | case 3: |
| 311 | access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS; |
| 312 | break; |
| 313 | default: |
| 314 | access_size = ACPI_ACCESS_SIZE_UNDEFINED; |
| 315 | break; |
| 316 | } |
| 317 | |
| 318 | debug("UART type %u @ %lx\n", spcr->interface_type, serial_address); |
| 319 | |
| 320 | /* Fill GAS */ |
| 321 | spcr->serial_port.space_id = space_id; |
| 322 | spcr->serial_port.bit_width = serial_width; |
| 323 | spcr->serial_port.bit_offset = 0; |
| 324 | spcr->serial_port.access_size = access_size; |
| 325 | spcr->serial_port.addrl = lower_32_bits(serial_address); |
| 326 | spcr->serial_port.addrh = upper_32_bits(serial_address); |
| 327 | |
| 328 | /* Encode baud rate */ |
| 329 | switch (serial_info.baudrate) { |
| 330 | case 9600: |
| 331 | spcr->baud_rate = 3; |
| 332 | break; |
| 333 | case 19200: |
| 334 | spcr->baud_rate = 4; |
| 335 | break; |
| 336 | case 57600: |
| 337 | spcr->baud_rate = 6; |
| 338 | break; |
| 339 | case 115200: |
| 340 | spcr->baud_rate = 7; |
| 341 | break; |
| 342 | default: |
| 343 | spcr->baud_rate = 0; |
| 344 | break; |
| 345 | } |
| 346 | |
Simon Glass | 896c164 | 2018-12-28 14:23:10 -0700 | [diff] [blame] | 347 | serial_config = SERIAL_DEFAULT_CONFIG; |
| 348 | if (dev) |
Simon Glass | daaff93 | 2018-12-28 14:23:08 -0700 | [diff] [blame] | 349 | ret = serial_getconfig(dev, &serial_config); |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 350 | |
| 351 | spcr->parity = SERIAL_GET_PARITY(serial_config); |
| 352 | spcr->stop_bits = SERIAL_GET_STOP(serial_config); |
| 353 | |
| 354 | /* No PCI devices for now */ |
| 355 | spcr->pci_device_id = 0xffff; |
| 356 | spcr->pci_vendor_id = 0xffff; |
| 357 | |
Andy Shevchenko | 225cc8a | 2020-02-27 17:21:56 +0200 | [diff] [blame] | 358 | /* |
| 359 | * SPCR has no clue if the UART base clock speed is different |
| 360 | * to the default one. However, the SPCR 1.04 defines baud rate |
| 361 | * 0 as a preconfigured state of UART and OS is supposed not |
| 362 | * to touch the configuration of the serial device. |
| 363 | */ |
| 364 | if (serial_info.clock != SERIAL_DEFAULT_CLOCK) |
| 365 | spcr->baud_rate = 0; |
| 366 | |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 367 | /* Fix checksum */ |
| 368 | header->checksum = table_compute_checksum((void *)spcr, header->length); |
| 369 | } |
| 370 | |
Simon Glass | f0a8d68 | 2020-07-07 13:12:07 -0600 | [diff] [blame] | 371 | void acpi_create_ssdt(struct acpi_ctx *ctx, struct acpi_table_header *ssdt, |
| 372 | const char *oem_table_id) |
| 373 | { |
| 374 | memset((void *)ssdt, '\0', sizeof(struct acpi_table_header)); |
| 375 | |
| 376 | acpi_fill_header(ssdt, "SSDT"); |
| 377 | ssdt->revision = acpi_get_table_revision(ACPITAB_SSDT); |
| 378 | ssdt->aslc_revision = 1; |
| 379 | ssdt->length = sizeof(struct acpi_table_header); |
| 380 | |
| 381 | acpi_inc(ctx, sizeof(struct acpi_table_header)); |
| 382 | |
| 383 | acpi_fill_ssdt(ctx); |
| 384 | |
| 385 | /* (Re)calculate length and checksum. */ |
| 386 | ssdt->length = ctx->current - (void *)ssdt; |
| 387 | ssdt->checksum = table_compute_checksum((void *)ssdt, ssdt->length); |
| 388 | } |
| 389 | |
Miao Yan | 3b68c52 | 2016-01-20 01:57:06 -0800 | [diff] [blame] | 390 | /* |
Andy Shevchenko | 4b05bac | 2018-01-10 19:33:10 +0200 | [diff] [blame] | 391 | * 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] | 392 | */ |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 393 | ulong write_acpi_tables(ulong start_addr) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 394 | { |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 395 | struct acpi_ctx sctx, *ctx = &sctx; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 396 | struct acpi_facs *facs; |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 397 | struct acpi_table_header *dsdt; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 398 | struct acpi_fadt *fadt; |
Simon Glass | f0a8d68 | 2020-07-07 13:12:07 -0600 | [diff] [blame] | 399 | struct acpi_table_header *ssdt; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 400 | struct acpi_mcfg *mcfg; |
| 401 | struct acpi_madt *madt; |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 402 | struct acpi_csrt *csrt; |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 403 | struct acpi_spcr *spcr; |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 404 | void *start; |
| 405 | ulong addr; |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 406 | int i; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 407 | |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 408 | start = map_sysmem(start_addr, 0); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 409 | |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 410 | debug("ACPI: Writing ACPI tables at %lx\n", start_addr); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 411 | |
Simon Glass | 9c442a6 | 2020-04-26 09:19:51 -0600 | [diff] [blame] | 412 | acpi_setup_base_tables(ctx, start); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 413 | |
| 414 | debug("ACPI: * FACS\n"); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 415 | facs = ctx->current; |
| 416 | acpi_inc_align(ctx, sizeof(struct acpi_facs)); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 417 | |
| 418 | acpi_create_facs(facs); |
| 419 | |
| 420 | debug("ACPI: * DSDT\n"); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 421 | dsdt = ctx->current; |
Simon Glass | 6ca9315 | 2020-07-07 13:12:09 -0600 | [diff] [blame] | 422 | |
| 423 | /* Put the table header first */ |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 424 | memcpy(dsdt, &AmlCode, sizeof(struct acpi_table_header)); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 425 | acpi_inc(ctx, sizeof(struct acpi_table_header)); |
Simon Glass | 6ca9315 | 2020-07-07 13:12:09 -0600 | [diff] [blame] | 426 | |
| 427 | /* If the table is not empty, allow devices to inject things */ |
| 428 | if (dsdt->length >= sizeof(struct acpi_table_header)) |
| 429 | acpi_inject_dsdt(ctx); |
| 430 | |
| 431 | /* Copy in the AML code itself if any (after the header) */ |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 432 | memcpy(ctx->current, |
Bin Meng | d90434b | 2016-05-11 07:45:05 -0700 | [diff] [blame] | 433 | (char *)&AmlCode + sizeof(struct acpi_table_header), |
| 434 | dsdt->length - sizeof(struct acpi_table_header)); |
Simon Glass | 6ca9315 | 2020-07-07 13:12:09 -0600 | [diff] [blame] | 435 | |
Wolfgang Wallner | aa20282 | 2020-09-16 16:57:52 +0200 | [diff] [blame] | 436 | acpi_inc(ctx, dsdt->length - sizeof(struct acpi_table_header)); |
Simon Glass | 6fe570a | 2020-09-22 12:44:53 -0600 | [diff] [blame] | 437 | dsdt->length = ctx->current - (void *)dsdt; |
| 438 | acpi_align(ctx); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 439 | |
Simon Glass | 6fe570a | 2020-09-22 12:44:53 -0600 | [diff] [blame] | 440 | if (!IS_ENABLED(CONFIG_ACPI_GNVS_EXTERNAL)) { |
| 441 | /* Pack GNVS into the ACPI table area */ |
| 442 | for (i = 0; i < dsdt->length; i++) { |
| 443 | u32 *gnvs = (u32 *)((u32)dsdt + i); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 444 | |
Simon Glass | 6fe570a | 2020-09-22 12:44:53 -0600 | [diff] [blame] | 445 | if (*gnvs == ACPI_GNVS_ADDR) { |
| 446 | *gnvs = map_to_sysmem(ctx->current); |
| 447 | debug("Fix up global NVS in DSDT to %#08x\n", |
| 448 | *gnvs); |
| 449 | break; |
| 450 | } |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 451 | } |
Simon Glass | 6fe570a | 2020-09-22 12:44:53 -0600 | [diff] [blame] | 452 | |
| 453 | /* |
| 454 | * Fill in platform-specific global NVS variables. If this fails |
| 455 | * we cannot return the error but this should only happen while |
| 456 | * debugging. |
| 457 | */ |
| 458 | addr = acpi_create_gnvs(ctx->current); |
| 459 | if (IS_ERR_VALUE(addr)) |
| 460 | printf("Error: Gailed to create GNVS\n"); |
| 461 | acpi_inc_align(ctx, sizeof(struct acpi_global_nvs)); |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Simon Glass | 6ca9315 | 2020-07-07 13:12:09 -0600 | [diff] [blame] | 464 | /* |
| 465 | * Recalculate the length and update the DSDT checksum since we patched |
| 466 | * the GNVS address. Set the checksum to zero since it is part of the |
| 467 | * region being checksummed. |
| 468 | */ |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 469 | dsdt->checksum = 0; |
| 470 | dsdt->checksum = table_compute_checksum((void *)dsdt, dsdt->length); |
| 471 | |
Simon Glass | 9ed41e7 | 2020-07-07 21:32:05 -0600 | [diff] [blame] | 472 | /* |
| 473 | * Fill in platform-specific global NVS variables. If this fails we |
| 474 | * cannot return the error but this should only happen while debugging. |
| 475 | */ |
| 476 | addr = acpi_create_gnvs(ctx->current); |
| 477 | if (IS_ERR_VALUE(addr)) |
| 478 | printf("Error: Failed to create GNVS\n"); |
| 479 | |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 480 | acpi_inc_align(ctx, sizeof(struct acpi_global_nvs)); |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 481 | |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 482 | debug("ACPI: * FADT\n"); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 483 | fadt = ctx->current; |
| 484 | acpi_inc_align(ctx, sizeof(struct acpi_fadt)); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 485 | acpi_create_fadt(fadt, facs, dsdt); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 486 | acpi_add_table(ctx, fadt); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 487 | |
Simon Glass | f0a8d68 | 2020-07-07 13:12:07 -0600 | [diff] [blame] | 488 | debug("ACPI: * SSDT\n"); |
| 489 | ssdt = (struct acpi_table_header *)ctx->current; |
| 490 | acpi_create_ssdt(ctx, ssdt, OEM_TABLE_ID); |
| 491 | if (ssdt->length > sizeof(struct acpi_table_header)) { |
| 492 | acpi_inc_align(ctx, ssdt->length); |
| 493 | acpi_add_table(ctx, ssdt); |
| 494 | } |
| 495 | |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 496 | debug("ACPI: * MCFG\n"); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 497 | mcfg = ctx->current; |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 498 | acpi_create_mcfg(mcfg); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 499 | acpi_inc_align(ctx, mcfg->header.length); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 500 | acpi_add_table(ctx, mcfg); |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 501 | |
Simon Glass | c7c46e8 | 2020-07-07 13:12:04 -0600 | [diff] [blame] | 502 | debug("ACPI: * MADT\n"); |
| 503 | madt = ctx->current; |
| 504 | acpi_create_madt(madt); |
| 505 | acpi_inc_align(ctx, madt->header.length); |
| 506 | acpi_add_table(ctx, madt); |
| 507 | |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 508 | debug("ACPI: * CSRT\n"); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 509 | csrt = ctx->current; |
Simon Glass | 9eb8004 | 2020-07-07 21:32:24 -0600 | [diff] [blame] | 510 | if (!acpi_create_csrt(csrt)) { |
| 511 | acpi_inc_align(ctx, csrt->header.length); |
| 512 | acpi_add_table(ctx, csrt); |
| 513 | } |
Andy Shevchenko | 607dbd1 | 2019-07-14 19:23:57 +0300 | [diff] [blame] | 514 | |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 515 | debug("ACPI: * SPCR\n"); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 516 | spcr = ctx->current; |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 517 | acpi_create_spcr(spcr); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 518 | acpi_inc_align(ctx, spcr->header.length); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 519 | acpi_add_table(ctx, spcr); |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 520 | |
Simon Glass | 179fb82 | 2020-04-26 09:19:48 -0600 | [diff] [blame] | 521 | acpi_write_dev_tables(ctx); |
| 522 | |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 523 | addr = map_to_sysmem(ctx->current); |
| 524 | debug("current = %lx\n", addr); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 525 | |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 526 | acpi_rsdp_addr = (unsigned long)ctx->rsdp; |
Bin Meng | d2d2218 | 2016-05-07 07:46:12 -0700 | [diff] [blame] | 527 | debug("ACPI: done\n"); |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 528 | |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 529 | return addr; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 530 | } |
Bin Meng | 34bc74a | 2017-04-21 07:24:36 -0700 | [diff] [blame] | 531 | |
Bin Meng | e102925 | 2018-01-30 05:01:16 -0800 | [diff] [blame] | 532 | ulong acpi_get_rsdp_addr(void) |
| 533 | { |
| 534 | return acpi_rsdp_addr; |
| 535 | } |
Simon Glass | 4ffe8b0 | 2020-09-22 12:45:09 -0600 | [diff] [blame] | 536 | |
| 537 | /** |
| 538 | * acpi_write_hpet() - Write out a HPET table |
| 539 | * |
| 540 | * Write out the table for High-Precision Event Timers |
| 541 | * |
| 542 | * @hpet: Place to put HPET table |
| 543 | */ |
| 544 | static int acpi_create_hpet(struct acpi_hpet *hpet) |
| 545 | { |
| 546 | struct acpi_table_header *header = &hpet->header; |
| 547 | struct acpi_gen_regaddr *addr = &hpet->addr; |
| 548 | |
| 549 | /* |
| 550 | * See IA-PC HPET (High Precision Event Timers) Specification v1.0a |
| 551 | * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/software-developers-hpet-spec-1-0a.pdf |
| 552 | */ |
| 553 | memset((void *)hpet, '\0', sizeof(struct acpi_hpet)); |
| 554 | |
| 555 | /* Fill out header fields. */ |
| 556 | acpi_fill_header(header, "HPET"); |
| 557 | |
| 558 | header->aslc_revision = ASL_REVISION; |
| 559 | header->length = sizeof(struct acpi_hpet); |
| 560 | header->revision = acpi_get_table_revision(ACPITAB_HPET); |
| 561 | |
| 562 | /* Fill out HPET address */ |
| 563 | addr->space_id = 0; /* Memory */ |
| 564 | addr->bit_width = 64; |
| 565 | addr->bit_offset = 0; |
| 566 | addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff; |
| 567 | addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32; |
| 568 | |
| 569 | hpet->id = *(u32 *)CONFIG_HPET_ADDRESS; |
| 570 | hpet->number = 0; |
| 571 | hpet->min_tick = 0; /* HPET_MIN_TICKS */ |
| 572 | |
| 573 | header->checksum = table_compute_checksum(hpet, |
| 574 | sizeof(struct acpi_hpet)); |
| 575 | |
| 576 | return 0; |
| 577 | } |
| 578 | |
| 579 | int acpi_write_hpet(struct acpi_ctx *ctx) |
| 580 | { |
| 581 | struct acpi_hpet *hpet; |
| 582 | int ret; |
| 583 | |
| 584 | log_debug("ACPI: * HPET\n"); |
| 585 | |
| 586 | hpet = ctx->current; |
| 587 | acpi_inc_align(ctx, sizeof(struct acpi_hpet)); |
| 588 | acpi_create_hpet(hpet); |
| 589 | ret = acpi_add_table(ctx, hpet); |
| 590 | if (ret) |
| 591 | return log_msg_ret("add", ret); |
| 592 | |
| 593 | return 0; |
| 594 | } |
Simon Glass | 9597189 | 2020-09-22 12:45:10 -0600 | [diff] [blame] | 595 | |
| 596 | int acpi_write_dbg2_pci_uart(struct acpi_ctx *ctx, struct udevice *dev, |
| 597 | uint access_size) |
| 598 | { |
| 599 | struct acpi_dbg2_header *dbg2 = ctx->current; |
| 600 | char path[ACPI_PATH_MAX]; |
| 601 | struct acpi_gen_regaddr address; |
| 602 | phys_addr_t addr; |
| 603 | int ret; |
| 604 | |
| 605 | if (!device_active(dev)) { |
| 606 | log_info("Device not enabled\n"); |
| 607 | return -EACCES; |
| 608 | } |
| 609 | /* |
| 610 | * PCI devices don't remember their resource allocation information in |
| 611 | * U-Boot at present. We assume that MMIO is used for the UART and that |
| 612 | * the address space is 32 bytes: ns16550 uses 8 registers of up to |
| 613 | * 32-bits each. This is only for debugging so it is not a big deal. |
| 614 | */ |
| 615 | addr = dm_pci_read_bar32(dev, 0); |
| 616 | printf("UART addr %lx\n", (ulong)addr); |
| 617 | |
| 618 | memset(&address, '\0', sizeof(address)); |
| 619 | address.space_id = ACPI_ADDRESS_SPACE_MEMORY; |
| 620 | address.addrl = (uint32_t)addr; |
| 621 | address.addrh = (uint32_t)((addr >> 32) & 0xffffffff); |
| 622 | address.access_size = access_size; |
| 623 | |
| 624 | ret = acpi_device_path(dev, path, sizeof(path)); |
| 625 | if (ret) |
| 626 | return log_msg_ret("path", ret); |
| 627 | acpi_create_dbg2(dbg2, ACPI_DBG2_SERIAL_PORT, |
| 628 | ACPI_DBG2_16550_COMPATIBLE, &address, 0x1000, path); |
| 629 | |
| 630 | acpi_inc_align(ctx, dbg2->header.length); |
| 631 | acpi_add_table(ctx, dbg2); |
| 632 | |
| 633 | return 0; |
| 634 | } |
Simon Glass | 87cf8d2 | 2020-09-22 12:45:16 -0600 | [diff] [blame] | 635 | |
| 636 | void acpi_fadt_common(struct acpi_fadt *fadt, struct acpi_facs *facs, |
| 637 | void *dsdt) |
| 638 | { |
| 639 | struct acpi_table_header *header = &fadt->header; |
| 640 | |
| 641 | memset((void *)fadt, '\0', sizeof(struct acpi_fadt)); |
| 642 | |
| 643 | acpi_fill_header(header, "FACP"); |
| 644 | header->length = sizeof(struct acpi_fadt); |
| 645 | header->revision = 4; |
| 646 | memcpy(header->oem_id, OEM_ID, 6); |
| 647 | memcpy(header->oem_table_id, OEM_TABLE_ID, 8); |
| 648 | memcpy(header->aslc_id, ASLC_ID, 4); |
| 649 | header->aslc_revision = 1; |
| 650 | |
| 651 | fadt->firmware_ctrl = (unsigned long)facs; |
| 652 | fadt->dsdt = (unsigned long)dsdt; |
| 653 | |
| 654 | fadt->x_firmware_ctl_l = (unsigned long)facs; |
| 655 | fadt->x_firmware_ctl_h = 0; |
| 656 | fadt->x_dsdt_l = (unsigned long)dsdt; |
| 657 | fadt->x_dsdt_h = 0; |
| 658 | |
| 659 | fadt->preferred_pm_profile = ACPI_PM_MOBILE; |
| 660 | |
| 661 | /* Use ACPI 3.0 revision */ |
| 662 | fadt->header.revision = 4; |
| 663 | } |
| 664 | |
| 665 | void acpi_create_dmar_drhd(struct acpi_ctx *ctx, uint flags, uint segment, |
| 666 | u64 bar) |
| 667 | { |
| 668 | struct dmar_entry *drhd = ctx->current; |
| 669 | |
| 670 | memset(drhd, '\0', sizeof(*drhd)); |
| 671 | drhd->type = DMAR_DRHD; |
| 672 | drhd->length = sizeof(*drhd); /* will be fixed up later */ |
| 673 | drhd->flags = flags; |
| 674 | drhd->segment = segment; |
| 675 | drhd->bar = bar; |
| 676 | acpi_inc(ctx, drhd->length); |
| 677 | } |
| 678 | |
| 679 | void acpi_create_dmar_rmrr(struct acpi_ctx *ctx, uint segment, u64 bar, |
| 680 | u64 limit) |
| 681 | { |
| 682 | struct dmar_rmrr_entry *rmrr = ctx->current; |
| 683 | |
| 684 | memset(rmrr, '\0', sizeof(*rmrr)); |
| 685 | rmrr->type = DMAR_RMRR; |
| 686 | rmrr->length = sizeof(*rmrr); /* will be fixed up later */ |
| 687 | rmrr->segment = segment; |
| 688 | rmrr->bar = bar; |
| 689 | rmrr->limit = limit; |
| 690 | acpi_inc(ctx, rmrr->length); |
| 691 | } |
| 692 | |
| 693 | void acpi_dmar_drhd_fixup(struct acpi_ctx *ctx, void *base) |
| 694 | { |
| 695 | struct dmar_entry *drhd = base; |
| 696 | |
| 697 | drhd->length = ctx->current - base; |
| 698 | } |
| 699 | |
| 700 | void acpi_dmar_rmrr_fixup(struct acpi_ctx *ctx, void *base) |
| 701 | { |
| 702 | struct dmar_rmrr_entry *rmrr = base; |
| 703 | |
| 704 | rmrr->length = ctx->current - base; |
| 705 | } |
| 706 | |
| 707 | static int acpi_create_dmar_ds(struct acpi_ctx *ctx, enum dev_scope_type type, |
| 708 | uint enumeration_id, pci_dev_t bdf) |
| 709 | { |
| 710 | /* we don't support longer paths yet */ |
| 711 | const size_t dev_scope_length = sizeof(struct dev_scope) + 2; |
| 712 | struct dev_scope *ds = ctx->current; |
| 713 | |
| 714 | memset(ds, '\0', dev_scope_length); |
| 715 | ds->type = type; |
| 716 | ds->length = dev_scope_length; |
| 717 | ds->enumeration = enumeration_id; |
| 718 | ds->start_bus = PCI_BUS(bdf); |
| 719 | ds->path[0].dev = PCI_DEV(bdf); |
| 720 | ds->path[0].fn = PCI_FUNC(bdf); |
| 721 | |
| 722 | return ds->length; |
| 723 | } |
| 724 | |
| 725 | int acpi_create_dmar_ds_pci_br(struct acpi_ctx *ctx, pci_dev_t bdf) |
| 726 | { |
| 727 | return acpi_create_dmar_ds(ctx, SCOPE_PCI_SUB, 0, bdf); |
| 728 | } |
| 729 | |
| 730 | int acpi_create_dmar_ds_pci(struct acpi_ctx *ctx, pci_dev_t bdf) |
| 731 | { |
| 732 | return acpi_create_dmar_ds(ctx, SCOPE_PCI_ENDPOINT, 0, bdf); |
| 733 | } |
| 734 | |
| 735 | int acpi_create_dmar_ds_ioapic(struct acpi_ctx *ctx, uint enumeration_id, |
| 736 | pci_dev_t bdf) |
| 737 | { |
| 738 | return acpi_create_dmar_ds(ctx, SCOPE_IOAPIC, enumeration_id, bdf); |
| 739 | } |
| 740 | |
| 741 | int acpi_create_dmar_ds_msi_hpet(struct acpi_ctx *ctx, uint enumeration_id, |
| 742 | pci_dev_t bdf) |
| 743 | { |
| 744 | return acpi_create_dmar_ds(ctx, SCOPE_MSI_HPET, enumeration_id, bdf); |
| 745 | } |