blob: 8219376e170824c5e067bfd0ea6b4062fec5ac7d [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>
Simon Glass9ed41e72020-07-07 21:32:05 -060026#include <linux/err.h>
Saket Sinha331141a2015-08-22 12:20:55 +053027
28/*
Bin Mengb063d5f2016-05-07 07:46:24 -070029 * IASL compiles the dsdt entries and writes the hex values
30 * to a C array AmlCode[] (see dsdt.c).
Saket Sinha331141a2015-08-22 12:20:55 +053031 */
32extern const unsigned char AmlCode[];
33
Andy Shevchenko66d3e632018-01-10 19:40:15 +020034/* ACPI RSDP address to be used in boot parameters */
Bin Menge1029252018-01-30 05:01:16 -080035static ulong acpi_rsdp_addr;
Andy Shevchenko66d3e632018-01-10 19:40:15 +020036
Bin Meng44256b02016-05-07 07:46:25 -070037static 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 Sinha331141a2015-08-22 12:20:55 +053052static int acpi_create_madt_lapic(struct acpi_madt_lapic *lapic,
Bin Meng44256b02016-05-07 07:46:25 -070053 u8 cpu, u8 apic)
Saket Sinha331141a2015-08-22 12:20:55 +053054{
Bin Meng44256b02016-05-07 07:46:25 -070055 lapic->type = ACPI_APIC_LAPIC;
Saket Sinha331141a2015-08-22 12:20:55 +053056 lapic->length = sizeof(struct acpi_madt_lapic);
Bin Meng44256b02016-05-07 07:46:25 -070057 lapic->flags = LOCAL_APIC_FLAG_ENABLED;
Saket Sinha331141a2015-08-22 12:20:55 +053058 lapic->processor_id = cpu;
59 lapic->apic_id = apic;
60
61 return lapic->length;
62}
63
Bin Meng3c5234e2016-05-07 07:46:30 -070064int acpi_create_madt_lapics(u32 current)
Saket Sinha331141a2015-08-22 12:20:55 +053065{
66 struct udevice *dev;
George McCollister5a49f872016-06-07 13:40:18 -050067 int total_length = 0;
Saket Sinha331141a2015-08-22 12:20:55 +053068
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 McCollister5a49f872016-06-07 13:40:18 -050073 int length = acpi_create_madt_lapic(
74 (struct acpi_madt_lapic *)current,
75 plat->cpu_id, plat->cpu_id);
Bin Meng3c5234e2016-05-07 07:46:30 -070076 current += length;
George McCollister5a49f872016-06-07 13:40:18 -050077 total_length += length;
Bin Meng44256b02016-05-07 07:46:25 -070078 }
79
George McCollister5a49f872016-06-07 13:40:18 -050080 return total_length;
Saket Sinha331141a2015-08-22 12:20:55 +053081}
82
Bin Meng44256b02016-05-07 07:46:25 -070083int acpi_create_madt_ioapic(struct acpi_madt_ioapic *ioapic, u8 id,
84 u32 addr, u32 gsi_base)
Saket Sinha331141a2015-08-22 12:20:55 +053085{
Bin Meng6a421582016-05-07 07:46:21 -070086 ioapic->type = ACPI_APIC_IOAPIC;
Saket Sinha331141a2015-08-22 12:20:55 +053087 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
96int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride,
Bin Meng44256b02016-05-07 07:46:25 -070097 u8 bus, u8 source, u32 gsirq, u16 flags)
Saket Sinha331141a2015-08-22 12:20:55 +053098{
Bin Meng6a421582016-05-07 07:46:21 -070099 irqoverride->type = ACPI_APIC_IRQ_SRC_OVERRIDE;
Saket Sinha331141a2015-08-22 12:20:55 +0530100 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
109int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi,
Bin Meng44256b02016-05-07 07:46:25 -0700110 u8 cpu, u16 flags, u8 lint)
Saket Sinha331141a2015-08-22 12:20:55 +0530111{
Bin Meng6a421582016-05-07 07:46:21 -0700112 lapic_nmi->type = ACPI_APIC_LAPIC_NMI;
Saket Sinha331141a2015-08-22 12:20:55 +0530113 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 Shevchenko13a5d872017-07-21 22:32:04 +0300121static 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 Sinha331141a2015-08-22 12:20:55 +0530148static void acpi_create_madt(struct acpi_madt *madt)
149{
Bin Meng6a421582016-05-07 07:46:21 -0700150 struct acpi_table_header *header = &(madt->header);
Bin Menga1ec7db2016-05-07 07:46:26 -0700151 u32 current = (u32)madt + sizeof(struct acpi_madt);
Saket Sinha331141a2015-08-22 12:20:55 +0530152
153 memset((void *)madt, 0, sizeof(struct acpi_madt));
154
155 /* Fill out header fields */
Bin Mengb063d5f2016-05-07 07:46:24 -0700156 acpi_fill_header(header, "APIC");
Saket Sinha331141a2015-08-22 12:20:55 +0530157 header->length = sizeof(struct acpi_madt);
Bin Mengf662fe42016-05-07 07:46:28 -0700158 header->revision = 4;
Saket Sinha331141a2015-08-22 12:20:55 +0530159
160 madt->lapic_addr = LAPIC_DEFAULT_BASE;
Bin Meng6a421582016-05-07 07:46:21 -0700161 madt->flags = ACPI_MADT_PCAT_COMPAT;
Saket Sinha331141a2015-08-22 12:20:55 +0530162
163 current = acpi_fill_madt(current);
164
165 /* (Re)calculate length and checksum */
Bin Menga1ec7db2016-05-07 07:46:26 -0700166 header->length = current - (u32)madt;
Saket Sinha331141a2015-08-22 12:20:55 +0530167
168 header->checksum = table_compute_checksum((void *)madt, header->length);
169}
170
Andy Shevchenkoc1ae9802017-07-21 22:32:05 +0300171int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig, u32 base,
172 u16 seg_nr, u8 start, u8 end)
Saket Sinha331141a2015-08-22 12:20:55 +0530173{
174 memset(mmconfig, 0, sizeof(*mmconfig));
Bin Meng6a421582016-05-07 07:46:21 -0700175 mmconfig->base_address_l = base;
176 mmconfig->base_address_h = 0;
Saket Sinha331141a2015-08-22 12:20:55 +0530177 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 Shevchenkoc1ae9802017-07-21 22:32:05 +0300184__weak u32 acpi_fill_mcfg(u32 current)
Saket Sinha331141a2015-08-22 12:20:55 +0530185{
186 current += acpi_create_mcfg_mmconfig
187 ((struct acpi_mcfg_mmconfig *)current,
Bin Meng44256b02016-05-07 07:46:25 -0700188 CONFIG_PCIE_ECAM_BASE, 0x0, 0x0, 255);
Saket Sinha331141a2015-08-22 12:20:55 +0530189
190 return current;
191}
192
193/* MCFG is defined in the PCI Firmware Specification 3.0 */
194static void acpi_create_mcfg(struct acpi_mcfg *mcfg)
195{
Bin Meng6a421582016-05-07 07:46:21 -0700196 struct acpi_table_header *header = &(mcfg->header);
Bin Menga1ec7db2016-05-07 07:46:26 -0700197 u32 current = (u32)mcfg + sizeof(struct acpi_mcfg);
Saket Sinha331141a2015-08-22 12:20:55 +0530198
199 memset((void *)mcfg, 0, sizeof(struct acpi_mcfg));
200
201 /* Fill out header fields */
Bin Mengb063d5f2016-05-07 07:46:24 -0700202 acpi_fill_header(header, "MCFG");
Saket Sinha331141a2015-08-22 12:20:55 +0530203 header->length = sizeof(struct acpi_mcfg);
Bin Mengf662fe42016-05-07 07:46:28 -0700204 header->revision = 1;
Saket Sinha331141a2015-08-22 12:20:55 +0530205
206 current = acpi_fill_mcfg(current);
207
208 /* (Re)calculate length and checksum */
Bin Menga1ec7db2016-05-07 07:46:26 -0700209 header->length = current - (u32)mcfg;
Saket Sinha331141a2015-08-22 12:20:55 +0530210 header->checksum = table_compute_checksum((void *)mcfg, header->length);
211}
212
Andy Shevchenko607dbd12019-07-14 19:23:57 +0300213__weak u32 acpi_fill_csrt(u32 current)
214{
215 return current;
216}
217
218static void acpi_create_csrt(struct acpi_csrt *csrt)
219{
220 struct acpi_table_header *header = &(csrt->header);
221 u32 current = (u32)csrt + sizeof(struct acpi_csrt);
222
223 memset((void *)csrt, 0, sizeof(struct acpi_csrt));
224
225 /* Fill out header fields */
226 acpi_fill_header(header, "CSRT");
227 header->length = sizeof(struct acpi_csrt);
228 header->revision = 0;
229
230 current = acpi_fill_csrt(current);
231
232 /* (Re)calculate length and checksum */
233 header->length = current - (u32)csrt;
234 header->checksum = table_compute_checksum((void *)csrt, header->length);
235}
236
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200237static void acpi_create_spcr(struct acpi_spcr *spcr)
238{
239 struct acpi_table_header *header = &(spcr->header);
240 struct serial_device_info serial_info = {0};
241 ulong serial_address, serial_offset;
Simon Glassdaaff932018-12-28 14:23:08 -0700242 struct udevice *dev;
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200243 uint serial_config;
244 uint serial_width;
245 int access_size;
246 int space_id;
Andy Shevchenkobf9c8e32019-02-28 17:19:54 +0200247 int ret = -ENODEV;
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200248
249 /* Fill out header fields */
250 acpi_fill_header(header, "SPCR");
251 header->length = sizeof(struct acpi_spcr);
252 header->revision = 2;
253
Simon Glass896c1642018-12-28 14:23:10 -0700254 /* Read the device once, here. It is reused below */
Andy Shevchenkobf9c8e32019-02-28 17:19:54 +0200255 dev = gd->cur_serial_dev;
256 if (dev)
Simon Glass896c1642018-12-28 14:23:10 -0700257 ret = serial_getinfo(dev, &serial_info);
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200258 if (ret)
259 serial_info.type = SERIAL_CHIP_UNKNOWN;
260
261 /* Encode chip type */
262 switch (serial_info.type) {
263 case SERIAL_CHIP_16550_COMPATIBLE:
264 spcr->interface_type = ACPI_DBG2_16550_COMPATIBLE;
265 break;
266 case SERIAL_CHIP_UNKNOWN:
267 default:
268 spcr->interface_type = ACPI_DBG2_UNKNOWN;
269 break;
270 }
271
272 /* Encode address space */
273 switch (serial_info.addr_space) {
274 case SERIAL_ADDRESS_SPACE_MEMORY:
275 space_id = ACPI_ADDRESS_SPACE_MEMORY;
276 break;
277 case SERIAL_ADDRESS_SPACE_IO:
278 default:
279 space_id = ACPI_ADDRESS_SPACE_IO;
280 break;
281 }
282
283 serial_width = serial_info.reg_width * 8;
284 serial_offset = serial_info.reg_offset << serial_info.reg_shift;
285 serial_address = serial_info.addr + serial_offset;
286
287 /* Encode register access size */
288 switch (serial_info.reg_shift) {
289 case 0:
290 access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
291 break;
292 case 1:
293 access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
294 break;
295 case 2:
296 access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
297 break;
298 case 3:
299 access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS;
300 break;
301 default:
302 access_size = ACPI_ACCESS_SIZE_UNDEFINED;
303 break;
304 }
305
306 debug("UART type %u @ %lx\n", spcr->interface_type, serial_address);
307
308 /* Fill GAS */
309 spcr->serial_port.space_id = space_id;
310 spcr->serial_port.bit_width = serial_width;
311 spcr->serial_port.bit_offset = 0;
312 spcr->serial_port.access_size = access_size;
313 spcr->serial_port.addrl = lower_32_bits(serial_address);
314 spcr->serial_port.addrh = upper_32_bits(serial_address);
315
316 /* Encode baud rate */
317 switch (serial_info.baudrate) {
318 case 9600:
319 spcr->baud_rate = 3;
320 break;
321 case 19200:
322 spcr->baud_rate = 4;
323 break;
324 case 57600:
325 spcr->baud_rate = 6;
326 break;
327 case 115200:
328 spcr->baud_rate = 7;
329 break;
330 default:
331 spcr->baud_rate = 0;
332 break;
333 }
334
Simon Glass896c1642018-12-28 14:23:10 -0700335 serial_config = SERIAL_DEFAULT_CONFIG;
336 if (dev)
Simon Glassdaaff932018-12-28 14:23:08 -0700337 ret = serial_getconfig(dev, &serial_config);
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200338
339 spcr->parity = SERIAL_GET_PARITY(serial_config);
340 spcr->stop_bits = SERIAL_GET_STOP(serial_config);
341
342 /* No PCI devices for now */
343 spcr->pci_device_id = 0xffff;
344 spcr->pci_vendor_id = 0xffff;
345
Andy Shevchenko225cc8a2020-02-27 17:21:56 +0200346 /*
347 * SPCR has no clue if the UART base clock speed is different
348 * to the default one. However, the SPCR 1.04 defines baud rate
349 * 0 as a preconfigured state of UART and OS is supposed not
350 * to touch the configuration of the serial device.
351 */
352 if (serial_info.clock != SERIAL_DEFAULT_CLOCK)
353 spcr->baud_rate = 0;
354
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200355 /* Fix checksum */
356 header->checksum = table_compute_checksum((void *)spcr, header->length);
357}
358
Simon Glassf0a8d682020-07-07 13:12:07 -0600359void acpi_create_ssdt(struct acpi_ctx *ctx, struct acpi_table_header *ssdt,
360 const char *oem_table_id)
361{
362 memset((void *)ssdt, '\0', sizeof(struct acpi_table_header));
363
364 acpi_fill_header(ssdt, "SSDT");
365 ssdt->revision = acpi_get_table_revision(ACPITAB_SSDT);
366 ssdt->aslc_revision = 1;
367 ssdt->length = sizeof(struct acpi_table_header);
368
369 acpi_inc(ctx, sizeof(struct acpi_table_header));
370
371 acpi_fill_ssdt(ctx);
372
373 /* (Re)calculate length and checksum. */
374 ssdt->length = ctx->current - (void *)ssdt;
375 ssdt->checksum = table_compute_checksum((void *)ssdt, ssdt->length);
376}
377
Miao Yan3b68c522016-01-20 01:57:06 -0800378/*
Andy Shevchenko4b05bac2018-01-10 19:33:10 +0200379 * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c
Miao Yan3b68c522016-01-20 01:57:06 -0800380 */
Simon Glass0e113842020-04-26 09:19:47 -0600381ulong write_acpi_tables(ulong start_addr)
Saket Sinha331141a2015-08-22 12:20:55 +0530382{
Simon Glass0e113842020-04-26 09:19:47 -0600383 struct acpi_ctx sctx, *ctx = &sctx;
Saket Sinha331141a2015-08-22 12:20:55 +0530384 struct acpi_facs *facs;
Bin Meng6a421582016-05-07 07:46:21 -0700385 struct acpi_table_header *dsdt;
Saket Sinha331141a2015-08-22 12:20:55 +0530386 struct acpi_fadt *fadt;
Simon Glassf0a8d682020-07-07 13:12:07 -0600387 struct acpi_table_header *ssdt;
Saket Sinha331141a2015-08-22 12:20:55 +0530388 struct acpi_mcfg *mcfg;
389 struct acpi_madt *madt;
Andy Shevchenko607dbd12019-07-14 19:23:57 +0300390 struct acpi_csrt *csrt;
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200391 struct acpi_spcr *spcr;
Simon Glass0e113842020-04-26 09:19:47 -0600392 void *start;
393 ulong addr;
Bin Mengd9050c62016-06-17 02:13:16 -0700394 int i;
Saket Sinha331141a2015-08-22 12:20:55 +0530395
Simon Glass0e113842020-04-26 09:19:47 -0600396 start = map_sysmem(start_addr, 0);
Saket Sinha331141a2015-08-22 12:20:55 +0530397
Simon Glass0e113842020-04-26 09:19:47 -0600398 debug("ACPI: Writing ACPI tables at %lx\n", start_addr);
Saket Sinha331141a2015-08-22 12:20:55 +0530399
Simon Glass9c442a62020-04-26 09:19:51 -0600400 acpi_setup_base_tables(ctx, start);
Saket Sinha331141a2015-08-22 12:20:55 +0530401
402 debug("ACPI: * FACS\n");
Simon Glass0e113842020-04-26 09:19:47 -0600403 facs = ctx->current;
404 acpi_inc_align(ctx, sizeof(struct acpi_facs));
Saket Sinha331141a2015-08-22 12:20:55 +0530405
406 acpi_create_facs(facs);
407
408 debug("ACPI: * DSDT\n");
Simon Glass0e113842020-04-26 09:19:47 -0600409 dsdt = ctx->current;
Simon Glass6ca93152020-07-07 13:12:09 -0600410
411 /* Put the table header first */
Bin Meng6a421582016-05-07 07:46:21 -0700412 memcpy(dsdt, &AmlCode, sizeof(struct acpi_table_header));
Simon Glass0e113842020-04-26 09:19:47 -0600413 acpi_inc(ctx, sizeof(struct acpi_table_header));
Simon Glass6ca93152020-07-07 13:12:09 -0600414
415 /* If the table is not empty, allow devices to inject things */
416 if (dsdt->length >= sizeof(struct acpi_table_header))
417 acpi_inject_dsdt(ctx);
418
419 /* Copy in the AML code itself if any (after the header) */
Simon Glass0e113842020-04-26 09:19:47 -0600420 memcpy(ctx->current,
Bin Mengd90434b2016-05-11 07:45:05 -0700421 (char *)&AmlCode + sizeof(struct acpi_table_header),
422 dsdt->length - sizeof(struct acpi_table_header));
Simon Glass6ca93152020-07-07 13:12:09 -0600423
Simon Glass0e113842020-04-26 09:19:47 -0600424 acpi_inc_align(ctx, dsdt->length - sizeof(struct acpi_table_header));
Saket Sinha331141a2015-08-22 12:20:55 +0530425
Bin Mengd9050c62016-06-17 02:13:16 -0700426 /* Pack GNVS into the ACPI table area */
427 for (i = 0; i < dsdt->length; i++) {
428 u32 *gnvs = (u32 *)((u32)dsdt + i);
429 if (*gnvs == ACPI_GNVS_ADDR) {
Simon Glass0e113842020-04-26 09:19:47 -0600430 ulong addr = (ulong)map_to_sysmem(ctx->current);
431
432 debug("Fix up global NVS in DSDT to %#08lx\n", addr);
433 *gnvs = addr;
Bin Mengd9050c62016-06-17 02:13:16 -0700434 break;
435 }
436 }
437
Simon Glass6ca93152020-07-07 13:12:09 -0600438 /*
439 * Recalculate the length and update the DSDT checksum since we patched
440 * the GNVS address. Set the checksum to zero since it is part of the
441 * region being checksummed.
442 */
443 dsdt->length = ctx->current - (void *)dsdt;
Bin Mengd9050c62016-06-17 02:13:16 -0700444 dsdt->checksum = 0;
445 dsdt->checksum = table_compute_checksum((void *)dsdt, dsdt->length);
446
Simon Glass9ed41e72020-07-07 21:32:05 -0600447 /*
448 * Fill in platform-specific global NVS variables. If this fails we
449 * cannot return the error but this should only happen while debugging.
450 */
451 addr = acpi_create_gnvs(ctx->current);
452 if (IS_ERR_VALUE(addr))
453 printf("Error: Failed to create GNVS\n");
454
Simon Glass0e113842020-04-26 09:19:47 -0600455 acpi_inc_align(ctx, sizeof(struct acpi_global_nvs));
Bin Mengd9050c62016-06-17 02:13:16 -0700456
Saket Sinha331141a2015-08-22 12:20:55 +0530457 debug("ACPI: * FADT\n");
Simon Glass0e113842020-04-26 09:19:47 -0600458 fadt = ctx->current;
459 acpi_inc_align(ctx, sizeof(struct acpi_fadt));
Saket Sinha331141a2015-08-22 12:20:55 +0530460 acpi_create_fadt(fadt, facs, dsdt);
Simon Glass575a5472020-04-26 09:19:50 -0600461 acpi_add_table(ctx, fadt);
Saket Sinha331141a2015-08-22 12:20:55 +0530462
Simon Glassf0a8d682020-07-07 13:12:07 -0600463 debug("ACPI: * SSDT\n");
464 ssdt = (struct acpi_table_header *)ctx->current;
465 acpi_create_ssdt(ctx, ssdt, OEM_TABLE_ID);
466 if (ssdt->length > sizeof(struct acpi_table_header)) {
467 acpi_inc_align(ctx, ssdt->length);
468 acpi_add_table(ctx, ssdt);
469 }
470
Bin Meng44256b02016-05-07 07:46:25 -0700471 debug("ACPI: * MCFG\n");
Simon Glass0e113842020-04-26 09:19:47 -0600472 mcfg = ctx->current;
Bin Meng44256b02016-05-07 07:46:25 -0700473 acpi_create_mcfg(mcfg);
Simon Glass0e113842020-04-26 09:19:47 -0600474 acpi_inc_align(ctx, mcfg->header.length);
Simon Glass575a5472020-04-26 09:19:50 -0600475 acpi_add_table(ctx, mcfg);
Bin Meng44256b02016-05-07 07:46:25 -0700476
Simon Glassc7c46e82020-07-07 13:12:04 -0600477 debug("ACPI: * MADT\n");
478 madt = ctx->current;
479 acpi_create_madt(madt);
480 acpi_inc_align(ctx, madt->header.length);
481 acpi_add_table(ctx, madt);
482
Andy Shevchenko607dbd12019-07-14 19:23:57 +0300483 debug("ACPI: * CSRT\n");
Simon Glass0e113842020-04-26 09:19:47 -0600484 csrt = ctx->current;
Andy Shevchenko607dbd12019-07-14 19:23:57 +0300485 acpi_create_csrt(csrt);
Simon Glass0e113842020-04-26 09:19:47 -0600486 acpi_inc_align(ctx, csrt->header.length);
Simon Glass575a5472020-04-26 09:19:50 -0600487 acpi_add_table(ctx, csrt);
Andy Shevchenko607dbd12019-07-14 19:23:57 +0300488
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200489 debug("ACPI: * SPCR\n");
Simon Glass0e113842020-04-26 09:19:47 -0600490 spcr = ctx->current;
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200491 acpi_create_spcr(spcr);
Simon Glass0e113842020-04-26 09:19:47 -0600492 acpi_inc_align(ctx, spcr->header.length);
Simon Glass575a5472020-04-26 09:19:50 -0600493 acpi_add_table(ctx, spcr);
Andy Shevchenko4ca48c92018-11-20 23:52:38 +0200494
Simon Glass179fb822020-04-26 09:19:48 -0600495 acpi_write_dev_tables(ctx);
496
Simon Glass0e113842020-04-26 09:19:47 -0600497 addr = map_to_sysmem(ctx->current);
498 debug("current = %lx\n", addr);
Saket Sinha331141a2015-08-22 12:20:55 +0530499
Simon Glass575a5472020-04-26 09:19:50 -0600500 acpi_rsdp_addr = (unsigned long)ctx->rsdp;
Bin Mengd2d22182016-05-07 07:46:12 -0700501 debug("ACPI: done\n");
Saket Sinha331141a2015-08-22 12:20:55 +0530502
Simon Glass0e113842020-04-26 09:19:47 -0600503 return addr;
Saket Sinha331141a2015-08-22 12:20:55 +0530504}
Bin Meng34bc74a2017-04-21 07:24:36 -0700505
Bin Menge1029252018-01-30 05:01:16 -0800506ulong acpi_get_rsdp_addr(void)
507{
508 return acpi_rsdp_addr;
509}