blob: eeacfe9b06ce6fc0fe8c5da57bf0cca7c58371f3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Saket Sinha331141a2015-08-22 12:20:55 +05302/*
3 * Based on acpi.c from coreboot
4 *
5 * Copyright (C) 2015, Saket Sinha <saket.sinha89@gmail.com>
Bin Meng44256b02016-05-07 07:46:25 -07006 * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
Saket Sinha331141a2015-08-22 12:20:55 +05307 */
8
9#include <common.h>
10#include <cpu.h>
11#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Saket Sinha331141a2015-08-22 12:20:55 +053013#include <dm/uclass-internal.h>
Simon Glass0e113842020-04-26 09:19:47 -060014#include <mapmem.h>
Andy Shevchenko4ca48c92018-11-20 23:52:38 +020015#include <serial.h>
Andy Shevchenko87e95372017-07-21 22:32:02 +030016#include <version.h>
Simon Glassf0a8d682020-07-07 13:12:07 -060017#include <acpi/acpigen.h>
Simon Glass858fed12020-04-08 16:57:36 -060018#include <acpi/acpi_table.h>
Bin Mengd9050c62016-06-17 02:13:16 -070019#include <asm/acpi/global_nvs.h>
Andy Shevchenko13a5d872017-07-21 22:32:04 +030020#include <asm/ioapic.h>
Saket Sinha331141a2015-08-22 12:20:55 +053021#include <asm/lapic.h>
Andy Shevchenko13a5d872017-07-21 22:32:04 +030022#include <asm/mpspec.h>
Saket Sinha331141a2015-08-22 12:20:55 +053023#include <asm/tables.h>
Bin Mengd9050c62016-06-17 02:13:16 -070024#include <asm/arch/global_nvs.h>
Simon Glass0e113842020-04-26 09:19:47 -060025#include <dm/acpi.h>
Saket Sinha331141a2015-08-22 12:20:55 +053026
27/*
Bin Mengb063d5f2016-05-07 07:46:24 -070028 * IASL compiles the dsdt entries and writes the hex values
29 * to a C array AmlCode[] (see dsdt.c).
Saket Sinha331141a2015-08-22 12:20:55 +053030 */
31extern const unsigned char AmlCode[];
32
Andy Shevchenko66d3e632018-01-10 19:40:15 +020033/* ACPI RSDP address to be used in boot parameters */
Bin Menge1029252018-01-30 05:01:16 -080034static ulong acpi_rsdp_addr;
Andy Shevchenko66d3e632018-01-10 19:40:15 +020035
Bin Meng44256b02016-05-07 07:46:25 -070036static void acpi_create_facs(struct acpi_facs *facs)
37{
38 memset((void *)facs, 0, sizeof(struct acpi_facs));
39
40 memcpy(facs->signature, "FACS", 4);
41 facs->length = sizeof(struct acpi_facs);
42 facs->hardware_signature = 0;
43 facs->firmware_waking_vector = 0;
44 facs->global_lock = 0;
45 facs->flags = 0;
46 facs->x_firmware_waking_vector_l = 0;
47 facs->x_firmware_waking_vector_h = 0;
48 facs->version = 1;
49}
50
Saket Sinha331141a2015-08-22 12:20:55 +053051static int acpi_create_madt_lapic(struct acpi_madt_lapic *lapic,
Bin Meng44256b02016-05-07 07:46:25 -070052 u8 cpu, u8 apic)
Saket Sinha331141a2015-08-22 12:20:55 +053053{
Bin Meng44256b02016-05-07 07:46:25 -070054 lapic->type = ACPI_APIC_LAPIC;
Saket Sinha331141a2015-08-22 12:20:55 +053055 lapic->length = sizeof(struct acpi_madt_lapic);
Bin Meng44256b02016-05-07 07:46:25 -070056 lapic->flags = LOCAL_APIC_FLAG_ENABLED;
Saket Sinha331141a2015-08-22 12:20:55 +053057 lapic->processor_id = cpu;
58 lapic->apic_id = apic;
59
60 return lapic->length;
61}
62
Bin Meng3c5234e2016-05-07 07:46:30 -070063int acpi_create_madt_lapics(u32 current)
Saket Sinha331141a2015-08-22 12:20:55 +053064{
65 struct udevice *dev;
George McCollister5a49f872016-06-07 13:40:18 -050066 int total_length = 0;
Saket Sinha331141a2015-08-22 12:20:55 +053067
68 for (uclass_find_first_device(UCLASS_CPU, &dev);
69 dev;
70 uclass_find_next_device(&dev)) {
71 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
George McCollister5a49f872016-06-07 13:40:18 -050072 int length = acpi_create_madt_lapic(
73 (struct acpi_madt_lapic *)current,
74 plat->cpu_id, plat->cpu_id);
Bin Meng3c5234e2016-05-07 07:46:30 -070075 current += length;
George McCollister5a49f872016-06-07 13:40:18 -050076 total_length += length;
Bin Meng44256b02016-05-07 07:46:25 -070077 }
78
George McCollister5a49f872016-06-07 13:40:18 -050079 return total_length;
Saket Sinha331141a2015-08-22 12:20:55 +053080}
81
Bin Meng44256b02016-05-07 07:46:25 -070082int acpi_create_madt_ioapic(struct acpi_madt_ioapic *ioapic, u8 id,
83 u32 addr, u32 gsi_base)
Saket Sinha331141a2015-08-22 12:20:55 +053084{
Bin Meng6a421582016-05-07 07:46:21 -070085 ioapic->type = ACPI_APIC_IOAPIC;
Saket Sinha331141a2015-08-22 12:20:55 +053086 ioapic->length = sizeof(struct acpi_madt_ioapic);
87 ioapic->reserved = 0x00;
88 ioapic->gsi_base = gsi_base;
89 ioapic->ioapic_id = id;
90 ioapic->ioapic_addr = addr;
91
92 return ioapic->length;
93}
94
95int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride,
Bin Meng44256b02016-05-07 07:46:25 -070096 u8 bus, u8 source, u32 gsirq, u16 flags)
Saket Sinha331141a2015-08-22 12:20:55 +053097{
Bin Meng6a421582016-05-07 07:46:21 -070098 irqoverride->type = ACPI_APIC_IRQ_SRC_OVERRIDE;
Saket Sinha331141a2015-08-22 12:20:55 +053099 irqoverride->length = sizeof(struct acpi_madt_irqoverride);
100 irqoverride->bus = bus;
101 irqoverride->source = source;
102 irqoverride->gsirq = gsirq;
103 irqoverride->flags = flags;
104
105 return irqoverride->length;
106}
107
108int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi,
Bin Meng44256b02016-05-07 07:46:25 -0700109 u8 cpu, u16 flags, u8 lint)
Saket Sinha331141a2015-08-22 12:20:55 +0530110{
Bin Meng6a421582016-05-07 07:46:21 -0700111 lapic_nmi->type = ACPI_APIC_LAPIC_NMI;
Saket Sinha331141a2015-08-22 12:20:55 +0530112 lapic_nmi->length = sizeof(struct acpi_madt_lapic_nmi);
113 lapic_nmi->flags = flags;
114 lapic_nmi->processor_id = cpu;
115 lapic_nmi->lint = lint;
116
117 return lapic_nmi->length;
118}
119
Andy Shevchenko13a5d872017-07-21 22:32:04 +0300120static int acpi_create_madt_irq_overrides(u32 current)
121{
122 struct acpi_madt_irqoverride *irqovr;
123 u16 sci_flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH;
124 int length = 0;
125
126 irqovr = (void *)current;
127 length += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0);
128
129 irqovr = (void *)(current + length);
130 length += acpi_create_madt_irqoverride(irqovr, 0, 9, 9, sci_flags);
131
132 return length;
133}
134
135__weak u32 acpi_fill_madt(u32 current)
136{
137 current += acpi_create_madt_lapics(current);
138
139 current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current,
140 io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0);
141
142 current += acpi_create_madt_irq_overrides(current);
143
144 return current;
145}
146
Saket Sinha331141a2015-08-22 12:20:55 +0530147static void acpi_create_madt(struct acpi_madt *madt)
148{
Bin Meng6a421582016-05-07 07:46:21 -0700149 struct acpi_table_header *header = &(madt->header);
Bin Menga1ec7db2016-05-07 07:46:26 -0700150 u32 current = (u32)madt + sizeof(struct acpi_madt);
Saket Sinha331141a2015-08-22 12:20:55 +0530151
152 memset((void *)madt, 0, sizeof(struct acpi_madt));
153
154 /* Fill out header fields */
Bin Mengb063d5f2016-05-07 07:46:24 -0700155 acpi_fill_header(header, "APIC");
Saket Sinha331141a2015-08-22 12:20:55 +0530156 header->length = sizeof(struct acpi_madt);
Bin Mengf662fe42016-05-07 07:46:28 -0700157 header->revision = 4;
Saket Sinha331141a2015-08-22 12:20:55 +0530158
159 madt->lapic_addr = LAPIC_DEFAULT_BASE;
Bin Meng6a421582016-05-07 07:46:21 -0700160 madt->flags = ACPI_MADT_PCAT_COMPAT;
Saket Sinha331141a2015-08-22 12:20:55 +0530161
162 current = acpi_fill_madt(current);
163
164 /* (Re)calculate length and checksum */
Bin Menga1ec7db2016-05-07 07:46:26 -0700165 header->length = current - (u32)madt;
Saket Sinha331141a2015-08-22 12:20:55 +0530166
167 header->checksum = table_compute_checksum((void *)madt, header->length);
168}
169
Andy Shevchenkoc1ae9802017-07-21 22:32:05 +0300170int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig, u32 base,
171 u16 seg_nr, u8 start, u8 end)
Saket Sinha331141a2015-08-22 12:20:55 +0530172{
173 memset(mmconfig, 0, sizeof(*mmconfig));
Bin Meng6a421582016-05-07 07:46:21 -0700174 mmconfig->base_address_l = base;
175 mmconfig->base_address_h = 0;
Saket Sinha331141a2015-08-22 12:20:55 +0530176 mmconfig->pci_segment_group_number = seg_nr;
177 mmconfig->start_bus_number = start;
178 mmconfig->end_bus_number = end;
179
180 return sizeof(struct acpi_mcfg_mmconfig);
181}
182
Andy Shevchenkoc1ae9802017-07-21 22:32:05 +0300183__weak u32 acpi_fill_mcfg(u32 current)
Saket Sinha331141a2015-08-22 12:20:55 +0530184{
185 current += acpi_create_mcfg_mmconfig
186 ((struct acpi_mcfg_mmconfig *)current,
Bin Meng44256b02016-05-07 07:46:25 -0700187 CONFIG_PCIE_ECAM_BASE, 0x0, 0x0, 255);
Saket Sinha331141a2015-08-22 12:20:55 +0530188
189 return current;
190}
191
192/* MCFG is defined in the PCI Firmware Specification 3.0 */
193static void acpi_create_mcfg(struct acpi_mcfg *mcfg)
194{
Bin Meng6a421582016-05-07 07:46:21 -0700195 struct acpi_table_header *header = &(mcfg->header);
Bin Menga1ec7db2016-05-07 07:46:26 -0700196 u32 current = (u32)mcfg + sizeof(struct acpi_mcfg);
Saket Sinha331141a2015-08-22 12:20:55 +0530197
198 memset((void *)mcfg, 0, sizeof(struct acpi_mcfg));
199
200 /* Fill out header fields */
Bin Mengb063d5f2016-05-07 07:46:24 -0700201 acpi_fill_header(header, "MCFG");
Saket Sinha331141a2015-08-22 12:20:55 +0530202 header->length = sizeof(struct acpi_mcfg);
Bin Mengf662fe42016-05-07 07:46:28 -0700203 header->revision = 1;
Saket Sinha331141a2015-08-22 12:20:55 +0530204
205 current = acpi_fill_mcfg(current);
206
207 /* (Re)calculate length and checksum */
Bin Menga1ec7db2016-05-07 07:46:26 -0700208 header->length = current - (u32)mcfg;
Saket Sinha331141a2015-08-22 12:20:55 +0530209 header->checksum = table_compute_checksum((void *)mcfg, header->length);
210}
211
Andy Shevchenko607dbd12019-07-14 19:23:57 +0300212__weak u32 acpi_fill_csrt(u32 current)
213{
214 return current;
215}
216
217static void acpi_create_csrt(struct acpi_csrt *csrt)
218{
219 struct acpi_table_header *header = &(csrt->header);
220 u32 current = (u32)csrt + sizeof(struct acpi_csrt);
221
222 memset((void *)csrt, 0, sizeof(struct acpi_csrt));
223
224 /* Fill out header fields */
225 acpi_fill_header(header, "CSRT");
226 header->length = sizeof(struct acpi_csrt);
227 header->revision = 0;
228
229 current = acpi_fill_csrt(current);
230
231 /* (Re)calculate length and checksum */
232 header->length = current - (u32)csrt;
233 header->checksum = table_compute_checksum((void *)csrt, header->length);
234}
235
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200236static void acpi_create_spcr(struct acpi_spcr *spcr)
237{
238 struct acpi_table_header *header = &(spcr->header);
239 struct serial_device_info serial_info = {0};
240 ulong serial_address, serial_offset;
Simon Glassdaaff932018-12-28 14:23:08 -0700241 struct udevice *dev;
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200242 uint serial_config;
243 uint serial_width;
244 int access_size;
245 int space_id;
Andy Shevchenkobf9c8e32019-02-28 17:19:54 +0200246 int ret = -ENODEV;
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200247
248 /* Fill out header fields */
249 acpi_fill_header(header, "SPCR");
250 header->length = sizeof(struct acpi_spcr);
251 header->revision = 2;
252
Simon Glass896c1642018-12-28 14:23:10 -0700253 /* Read the device once, here. It is reused below */
Andy Shevchenkobf9c8e32019-02-28 17:19:54 +0200254 dev = gd->cur_serial_dev;
255 if (dev)
Simon Glass896c1642018-12-28 14:23:10 -0700256 ret = serial_getinfo(dev, &serial_info);
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200257 if (ret)
258 serial_info.type = SERIAL_CHIP_UNKNOWN;
259
260 /* Encode chip type */
261 switch (serial_info.type) {
262 case SERIAL_CHIP_16550_COMPATIBLE:
263 spcr->interface_type = ACPI_DBG2_16550_COMPATIBLE;
264 break;
265 case SERIAL_CHIP_UNKNOWN:
266 default:
267 spcr->interface_type = ACPI_DBG2_UNKNOWN;
268 break;
269 }
270
271 /* Encode address space */
272 switch (serial_info.addr_space) {
273 case SERIAL_ADDRESS_SPACE_MEMORY:
274 space_id = ACPI_ADDRESS_SPACE_MEMORY;
275 break;
276 case SERIAL_ADDRESS_SPACE_IO:
277 default:
278 space_id = ACPI_ADDRESS_SPACE_IO;
279 break;
280 }
281
282 serial_width = serial_info.reg_width * 8;
283 serial_offset = serial_info.reg_offset << serial_info.reg_shift;
284 serial_address = serial_info.addr + serial_offset;
285
286 /* Encode register access size */
287 switch (serial_info.reg_shift) {
288 case 0:
289 access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
290 break;
291 case 1:
292 access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
293 break;
294 case 2:
295 access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
296 break;
297 case 3:
298 access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS;
299 break;
300 default:
301 access_size = ACPI_ACCESS_SIZE_UNDEFINED;
302 break;
303 }
304
305 debug("UART type %u @ %lx\n", spcr->interface_type, serial_address);
306
307 /* Fill GAS */
308 spcr->serial_port.space_id = space_id;
309 spcr->serial_port.bit_width = serial_width;
310 spcr->serial_port.bit_offset = 0;
311 spcr->serial_port.access_size = access_size;
312 spcr->serial_port.addrl = lower_32_bits(serial_address);
313 spcr->serial_port.addrh = upper_32_bits(serial_address);
314
315 /* Encode baud rate */
316 switch (serial_info.baudrate) {
317 case 9600:
318 spcr->baud_rate = 3;
319 break;
320 case 19200:
321 spcr->baud_rate = 4;
322 break;
323 case 57600:
324 spcr->baud_rate = 6;
325 break;
326 case 115200:
327 spcr->baud_rate = 7;
328 break;
329 default:
330 spcr->baud_rate = 0;
331 break;
332 }
333
Simon Glass896c1642018-12-28 14:23:10 -0700334 serial_config = SERIAL_DEFAULT_CONFIG;
335 if (dev)
Simon Glassdaaff932018-12-28 14:23:08 -0700336 ret = serial_getconfig(dev, &serial_config);
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200337
338 spcr->parity = SERIAL_GET_PARITY(serial_config);
339 spcr->stop_bits = SERIAL_GET_STOP(serial_config);
340
341 /* No PCI devices for now */
342 spcr->pci_device_id = 0xffff;
343 spcr->pci_vendor_id = 0xffff;
344
Andy Shevchenko225cc8a2020-02-27 17:21:56 +0200345 /*
346 * SPCR has no clue if the UART base clock speed is different
347 * to the default one. However, the SPCR 1.04 defines baud rate
348 * 0 as a preconfigured state of UART and OS is supposed not
349 * to touch the configuration of the serial device.
350 */
351 if (serial_info.clock != SERIAL_DEFAULT_CLOCK)
352 spcr->baud_rate = 0;
353
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200354 /* Fix checksum */
355 header->checksum = table_compute_checksum((void *)spcr, header->length);
356}
357
Simon Glassf0a8d682020-07-07 13:12:07 -0600358void acpi_create_ssdt(struct acpi_ctx *ctx, struct acpi_table_header *ssdt,
359 const char *oem_table_id)
360{
361 memset((void *)ssdt, '\0', sizeof(struct acpi_table_header));
362
363 acpi_fill_header(ssdt, "SSDT");
364 ssdt->revision = acpi_get_table_revision(ACPITAB_SSDT);
365 ssdt->aslc_revision = 1;
366 ssdt->length = sizeof(struct acpi_table_header);
367
368 acpi_inc(ctx, sizeof(struct acpi_table_header));
369
370 acpi_fill_ssdt(ctx);
371
372 /* (Re)calculate length and checksum. */
373 ssdt->length = ctx->current - (void *)ssdt;
374 ssdt->checksum = table_compute_checksum((void *)ssdt, ssdt->length);
375}
376
Miao Yan3b68c522016-01-20 01:57:06 -0800377/*
Andy Shevchenko4b05bac2018-01-10 19:33:10 +0200378 * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c
Miao Yan3b68c522016-01-20 01:57:06 -0800379 */
Simon Glass0e113842020-04-26 09:19:47 -0600380ulong write_acpi_tables(ulong start_addr)
Saket Sinha331141a2015-08-22 12:20:55 +0530381{
Simon Glass0e113842020-04-26 09:19:47 -0600382 struct acpi_ctx sctx, *ctx = &sctx;
Saket Sinha331141a2015-08-22 12:20:55 +0530383 struct acpi_facs *facs;
Bin Meng6a421582016-05-07 07:46:21 -0700384 struct acpi_table_header *dsdt;
Saket Sinha331141a2015-08-22 12:20:55 +0530385 struct acpi_fadt *fadt;
Simon Glassf0a8d682020-07-07 13:12:07 -0600386 struct acpi_table_header *ssdt;
Saket Sinha331141a2015-08-22 12:20:55 +0530387 struct acpi_mcfg *mcfg;
388 struct acpi_madt *madt;
Andy Shevchenko607dbd12019-07-14 19:23:57 +0300389 struct acpi_csrt *csrt;
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200390 struct acpi_spcr *spcr;
Simon Glass0e113842020-04-26 09:19:47 -0600391 void *start;
392 ulong addr;
Bin Mengd9050c62016-06-17 02:13:16 -0700393 int i;
Saket Sinha331141a2015-08-22 12:20:55 +0530394
Simon Glass0e113842020-04-26 09:19:47 -0600395 start = map_sysmem(start_addr, 0);
Saket Sinha331141a2015-08-22 12:20:55 +0530396
Simon Glass0e113842020-04-26 09:19:47 -0600397 debug("ACPI: Writing ACPI tables at %lx\n", start_addr);
Saket Sinha331141a2015-08-22 12:20:55 +0530398
Simon Glass9c442a62020-04-26 09:19:51 -0600399 acpi_setup_base_tables(ctx, start);
Saket Sinha331141a2015-08-22 12:20:55 +0530400
401 debug("ACPI: * FACS\n");
Simon Glass0e113842020-04-26 09:19:47 -0600402 facs = ctx->current;
403 acpi_inc_align(ctx, sizeof(struct acpi_facs));
Saket Sinha331141a2015-08-22 12:20:55 +0530404
405 acpi_create_facs(facs);
406
407 debug("ACPI: * DSDT\n");
Simon Glass0e113842020-04-26 09:19:47 -0600408 dsdt = ctx->current;
Simon Glass6ca93152020-07-07 13:12:09 -0600409
410 /* Put the table header first */
Bin Meng6a421582016-05-07 07:46:21 -0700411 memcpy(dsdt, &AmlCode, sizeof(struct acpi_table_header));
Simon Glass0e113842020-04-26 09:19:47 -0600412 acpi_inc(ctx, sizeof(struct acpi_table_header));
Simon Glass6ca93152020-07-07 13:12:09 -0600413
414 /* If the table is not empty, allow devices to inject things */
415 if (dsdt->length >= sizeof(struct acpi_table_header))
416 acpi_inject_dsdt(ctx);
417
418 /* Copy in the AML code itself if any (after the header) */
Simon Glass0e113842020-04-26 09:19:47 -0600419 memcpy(ctx->current,
Bin Mengd90434b2016-05-11 07:45:05 -0700420 (char *)&AmlCode + sizeof(struct acpi_table_header),
421 dsdt->length - sizeof(struct acpi_table_header));
Simon Glass6ca93152020-07-07 13:12:09 -0600422
Simon Glass0e113842020-04-26 09:19:47 -0600423 acpi_inc_align(ctx, dsdt->length - sizeof(struct acpi_table_header));
Saket Sinha331141a2015-08-22 12:20:55 +0530424
Bin Mengd9050c62016-06-17 02:13:16 -0700425 /* Pack GNVS into the ACPI table area */
426 for (i = 0; i < dsdt->length; i++) {
427 u32 *gnvs = (u32 *)((u32)dsdt + i);
428 if (*gnvs == ACPI_GNVS_ADDR) {
Simon Glass0e113842020-04-26 09:19:47 -0600429 ulong addr = (ulong)map_to_sysmem(ctx->current);
430
431 debug("Fix up global NVS in DSDT to %#08lx\n", addr);
432 *gnvs = addr;
Bin Mengd9050c62016-06-17 02:13:16 -0700433 break;
434 }
435 }
436
Simon Glass6ca93152020-07-07 13:12:09 -0600437 /*
438 * Recalculate the length and update the DSDT checksum since we patched
439 * the GNVS address. Set the checksum to zero since it is part of the
440 * region being checksummed.
441 */
442 dsdt->length = ctx->current - (void *)dsdt;
Bin Mengd9050c62016-06-17 02:13:16 -0700443 dsdt->checksum = 0;
444 dsdt->checksum = table_compute_checksum((void *)dsdt, dsdt->length);
445
446 /* Fill in platform-specific global NVS variables */
Simon Glass0e113842020-04-26 09:19:47 -0600447 acpi_create_gnvs(ctx->current);
448 acpi_inc_align(ctx, sizeof(struct acpi_global_nvs));
Bin Mengd9050c62016-06-17 02:13:16 -0700449
Saket Sinha331141a2015-08-22 12:20:55 +0530450 debug("ACPI: * FADT\n");
Simon Glass0e113842020-04-26 09:19:47 -0600451 fadt = ctx->current;
452 acpi_inc_align(ctx, sizeof(struct acpi_fadt));
Saket Sinha331141a2015-08-22 12:20:55 +0530453 acpi_create_fadt(fadt, facs, dsdt);
Simon Glass575a5472020-04-26 09:19:50 -0600454 acpi_add_table(ctx, fadt);
Saket Sinha331141a2015-08-22 12:20:55 +0530455
Simon Glassf0a8d682020-07-07 13:12:07 -0600456 debug("ACPI: * SSDT\n");
457 ssdt = (struct acpi_table_header *)ctx->current;
458 acpi_create_ssdt(ctx, ssdt, OEM_TABLE_ID);
459 if (ssdt->length > sizeof(struct acpi_table_header)) {
460 acpi_inc_align(ctx, ssdt->length);
461 acpi_add_table(ctx, ssdt);
462 }
463
Bin Meng44256b02016-05-07 07:46:25 -0700464 debug("ACPI: * MCFG\n");
Simon Glass0e113842020-04-26 09:19:47 -0600465 mcfg = ctx->current;
Bin Meng44256b02016-05-07 07:46:25 -0700466 acpi_create_mcfg(mcfg);
Simon Glass0e113842020-04-26 09:19:47 -0600467 acpi_inc_align(ctx, mcfg->header.length);
Simon Glass575a5472020-04-26 09:19:50 -0600468 acpi_add_table(ctx, mcfg);
Bin Meng44256b02016-05-07 07:46:25 -0700469
Simon Glassc7c46e82020-07-07 13:12:04 -0600470 debug("ACPI: * MADT\n");
471 madt = ctx->current;
472 acpi_create_madt(madt);
473 acpi_inc_align(ctx, madt->header.length);
474 acpi_add_table(ctx, madt);
475
Andy Shevchenko607dbd12019-07-14 19:23:57 +0300476 debug("ACPI: * CSRT\n");
Simon Glass0e113842020-04-26 09:19:47 -0600477 csrt = ctx->current;
Andy Shevchenko607dbd12019-07-14 19:23:57 +0300478 acpi_create_csrt(csrt);
Simon Glass0e113842020-04-26 09:19:47 -0600479 acpi_inc_align(ctx, csrt->header.length);
Simon Glass575a5472020-04-26 09:19:50 -0600480 acpi_add_table(ctx, csrt);
Andy Shevchenko607dbd12019-07-14 19:23:57 +0300481
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200482 debug("ACPI: * SPCR\n");
Simon Glass0e113842020-04-26 09:19:47 -0600483 spcr = ctx->current;
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200484 acpi_create_spcr(spcr);
Simon Glass0e113842020-04-26 09:19:47 -0600485 acpi_inc_align(ctx, spcr->header.length);
Simon Glass575a5472020-04-26 09:19:50 -0600486 acpi_add_table(ctx, spcr);
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200487
Simon Glass179fb822020-04-26 09:19:48 -0600488 acpi_write_dev_tables(ctx);
489
Simon Glass0e113842020-04-26 09:19:47 -0600490 addr = map_to_sysmem(ctx->current);
491 debug("current = %lx\n", addr);
Saket Sinha331141a2015-08-22 12:20:55 +0530492
Simon Glass575a5472020-04-26 09:19:50 -0600493 acpi_rsdp_addr = (unsigned long)ctx->rsdp;
Bin Mengd2d22182016-05-07 07:46:12 -0700494 debug("ACPI: done\n");
Saket Sinha331141a2015-08-22 12:20:55 +0530495
Simon Glass0e113842020-04-26 09:19:47 -0600496 return addr;
Saket Sinha331141a2015-08-22 12:20:55 +0530497}
Bin Meng34bc74a2017-04-21 07:24:36 -0700498
Bin Menge1029252018-01-30 05:01:16 -0800499ulong acpi_get_rsdp_addr(void)
500{
501 return acpi_rsdp_addr;
502}