blob: e0e72f775345ceafb7e2d6748a3bcebbe9287d10 [file] [log] [blame]
Patrick Georgi11f00792020-03-04 15:10:45 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer688b3852004-01-28 16:56:14 +00002/*
Martin Roth20bbd812019-08-30 21:09:37 -06003 * coreboot ACPI Table support
Stefan Reinauer777224c2005-01-19 14:06:41 +00004 */
5
Stefan Reinauer14e22772010-04-27 06:56:47 +00006/*
Stefan Reinauer777224c2005-01-19 14:06:41 +00007 * Each system port implementing ACPI has to provide two functions:
Stefan Reinauer14e22772010-04-27 06:56:47 +00008 *
Stefan Reinauer777224c2005-01-19 14:06:41 +00009 * write_acpi_tables()
10 * acpi_dump_apics()
Stefan Reinauer14e22772010-04-27 06:56:47 +000011 *
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000012 * See Kontron 986LCD-M port for a good example of an ACPI implementation
13 * in coreboot.
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000014 */
Stefan Reinauer688b3852004-01-28 16:56:14 +000015
Furquan Shaikh76cedd22020-05-02 10:24:23 -070016#include <acpi/acpi.h>
17#include <acpi/acpi_ivrs.h>
18#include <acpi/acpigen.h>
Felix Held972d9f22022-02-23 16:32:20 +010019#include <arch/hpet.h>
Kyösti Mälkkiae1b2d42023-04-10 16:45:39 +030020#include <arch/smp/mpspec.h>
Jianjun Wang8565b94a2022-03-02 10:20:26 +080021#include <cbfs.h>
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000022#include <cbmem.h>
Elyes HAOUASe2d152c2019-06-21 07:06:50 +020023#include <commonlib/helpers.h>
Jianjun Wang8565b94a2022-03-02 10:20:26 +080024#include <commonlib/sort.h>
25#include <console/console.h>
Duncan Laurie11290c42012-10-03 19:07:05 -070026#include <cpu/cpu.h>
Jianjun Wang8565b94a2022-03-02 10:20:26 +080027#include <device/mmio.h>
28#include <device/pci.h>
29#include <pc80/mc146818rtc.h>
30#include <string.h>
Elyes HAOUAScdd2f632021-02-11 19:37:11 +010031#include <types.h>
Elyes HAOUAS26071aa2019-02-15 08:21:33 +010032#include <version.h>
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000033
Kyösti Mälkkic7da0272021-06-08 11:37:08 +030034#if ENV_X86
35#include <arch/ioapic.h>
36#endif
37
Patrick Rudolphcfe08ff2019-09-10 15:40:47 +020038static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp);
39
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000040u8 acpi_checksum(u8 *table, u32 length)
Stefan Reinauer688b3852004-01-28 16:56:14 +000041{
Uwe Hermann622824c2010-11-19 15:14:42 +000042 u8 ret = 0;
Stefan Reinauer688b3852004-01-28 16:56:14 +000043 while (length--) {
44 ret += *table;
45 table++;
46 }
Stefan Reinauera7648c22004-01-29 17:31:34 +000047 return -ret;
Stefan Reinauer688b3852004-01-28 16:56:14 +000048}
49
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000050/**
Uwe Hermann622824c2010-11-19 15:14:42 +000051 * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length
52 * and checksum.
Stefan Reinauer06feb882004-02-03 16:11:35 +000053 */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000054void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
Stefan Reinauer688b3852004-01-28 16:56:14 +000055{
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000056 int i, entries_num;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000057 acpi_rsdt_t *rsdt;
58 acpi_xsdt_t *xsdt = NULL;
59
Uwe Hermann622824c2010-11-19 15:14:42 +000060 /* The RSDT is mandatory... */
Stefan Reinauerdefee172015-06-18 01:11:19 -070061 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000062
Uwe Hermann622824c2010-11-19 15:14:42 +000063 /* ...while the XSDT is not. */
64 if (rsdp->xsdt_address)
Stefan Reinauerdefee172015-06-18 01:11:19 -070065 xsdt = (acpi_xsdt_t *)((uintptr_t)rsdp->xsdt_address);
Stefan Reinauer14e22772010-04-27 06:56:47 +000066
Uwe Hermann622824c2010-11-19 15:14:42 +000067 /* This should always be MAX_ACPI_TABLES. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000068 entries_num = ARRAY_SIZE(rsdt->entry);
Stefan Reinauer14e22772010-04-27 06:56:47 +000069
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000070 for (i = 0; i < entries_num; i++) {
Uwe Hermann622824c2010-11-19 15:14:42 +000071 if (rsdt->entry[i] == 0)
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000072 break;
Stefan Reinauer688b3852004-01-28 16:56:14 +000073 }
74
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000075 if (i >= entries_num) {
Uwe Hermann622824c2010-11-19 15:14:42 +000076 printk(BIOS_ERR, "ACPI: Error: Could not add ACPI table, "
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +030077 "too many tables.\n");
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000078 return;
79 }
80
Uwe Hermann622824c2010-11-19 15:14:42 +000081 /* Add table to the RSDT. */
Stefan Reinauerdefee172015-06-18 01:11:19 -070082 rsdt->entry[i] = (uintptr_t)table;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000083
Uwe Hermann622824c2010-11-19 15:14:42 +000084 /* Fix RSDT length or the kernel will assume invalid entries. */
85 rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i + 1));
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000086
Uwe Hermann622824c2010-11-19 15:14:42 +000087 /* Re-calculate checksum. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000088 rsdt->header.checksum = 0; /* Hope this won't get optimized away */
Uwe Hermann622824c2010-11-19 15:14:42 +000089 rsdt->header.checksum = acpi_checksum((u8 *)rsdt, rsdt->header.length);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000090
Uwe Hermann622824c2010-11-19 15:14:42 +000091 /*
92 * And now the same thing for the XSDT. We use the same index as for
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000093 * now we want the XSDT and RSDT to always be in sync in coreboot.
94 */
95 if (xsdt) {
Uwe Hermann622824c2010-11-19 15:14:42 +000096 /* Add table to the XSDT. */
Stefan Reinauerdefee172015-06-18 01:11:19 -070097 xsdt->entry[i] = (u64)(uintptr_t)table;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000098
Uwe Hermann622824c2010-11-19 15:14:42 +000099 /* Fix XSDT length. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000100 xsdt->header.length = sizeof(acpi_header_t) +
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300101 (sizeof(u64) * (i + 1));
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000102
Uwe Hermann622824c2010-11-19 15:14:42 +0000103 /* Re-calculate checksum. */
104 xsdt->header.checksum = 0;
105 xsdt->header.checksum = acpi_checksum((u8 *)xsdt,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300106 xsdt->header.length);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000107 }
108
Uwe Hermann622824c2010-11-19 15:14:42 +0000109 printk(BIOS_DEBUG, "ACPI: added table %d/%d, length now %d\n",
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300110 i + 1, entries_num, rsdt->header.length);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000111}
112
Arthur Heymans9362dd72023-06-08 19:56:51 +0200113static int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300114 u16 seg_nr, u8 start, u8 end)
Stefan Reinauer26d431a2009-01-20 19:17:51 +0000115{
Vladimir Serbinenko60fccdc2014-10-05 11:05:16 +0200116 memset(mmconfig, 0, sizeof(*mmconfig));
Rudolf Mareke6409f22007-11-03 12:50:26 +0000117 mmconfig->base_address = base;
118 mmconfig->base_reserved = 0;
119 mmconfig->pci_segment_group_number = seg_nr;
120 mmconfig->start_bus_number = start;
121 mmconfig->end_bus_number = end;
Uwe Hermann622824c2010-11-19 15:14:42 +0000122
123 return sizeof(acpi_mcfg_mmconfig_t);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000124}
125
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +0300126static int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000127{
Himanshu Sahdev8c09b822019-10-21 18:50:50 +0530128 lapic->type = LOCAL_APIC; /* Local APIC structure */
Uwe Hermann622824c2010-11-19 15:14:42 +0000129 lapic->length = sizeof(acpi_madt_lapic_t);
130 lapic->flags = (1 << 0); /* Processor/LAPIC enabled */
131 lapic->processor_id = cpu;
132 lapic->apic_id = apic;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000133
Uwe Hermann622824c2010-11-19 15:14:42 +0000134 return lapic->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000135}
136
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +0300137static int acpi_create_madt_lx2apic(acpi_madt_lx2apic_t *lapic, u32 cpu, u32 apic)
Patrick Rudolph56a3ef22020-03-24 17:29:49 +0100138{
139 lapic->type = LOCAL_X2APIC; /* Local APIC structure */
140 lapic->reserved = 0;
141 lapic->length = sizeof(acpi_madt_lx2apic_t);
142 lapic->flags = (1 << 0); /* Processor/LAPIC enabled */
143 lapic->processor_id = cpu;
144 lapic->x2apic_id = apic;
145
146 return lapic->length;
147}
148
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +0300149unsigned long acpi_create_madt_one_lapic(unsigned long current, u32 index, u32 lapic_id)
150{
151 if (lapic_id <= ACPI_MADT_MAX_LAPIC_ID)
152 current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, index,
153 lapic_id);
154 else
155 current += acpi_create_madt_lx2apic((acpi_madt_lx2apic_t *)current, index,
156 lapic_id);
157
158 return current;
159}
160
Arthur Heymans85474292022-11-04 14:00:35 +0100161/* Increase if necessary. Currently all x86 CPUs only have 2 SMP threads */
162#define MAX_THREAD_ID 1
163/*
164 * From ACPI 6.4 spec:
165 * "The advent of multi-threaded processors yielded multiple logical processors
166 * executing on common processor hardware. ACPI defines logical processors in
167 * an identical manner as physical processors. To ensure that non
168 * multi-threading aware OSPM implementations realize optimal performance on
169 * platforms containing multi-threaded processors, two guidelines should be
170 * followed. The first is the same as above, that is, OSPM should initialize
171 * processors in the order that they appear in the MADT. The second is that
172 * platform firmware should list the first logical processor of each of the
173 * individual multi-threaded processors in the MADT before listing any of the
174 * second logical processors. This approach should be used for all successive
175 * logical processors."
176 */
Kyösti Mälkki899c7132021-06-16 11:06:26 +0300177static unsigned long acpi_create_madt_lapics(unsigned long current)
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000178{
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100179 struct device *cpu;
Arthur Heymans85474292022-11-04 14:00:35 +0100180 int index, apic_ids[CONFIG_MAX_CPUS] = {0}, num_cpus = 0, sort_start = 0;
181 for (unsigned int thread_id = 0; thread_id <= MAX_THREAD_ID; thread_id++) {
182 for (cpu = all_devices; cpu; cpu = cpu->next) {
183 if (!is_enabled_cpu(cpu))
184 continue;
185 if (num_cpus >= ARRAY_SIZE(apic_ids))
186 break;
187 if (cpu->path.apic.thread_id != thread_id)
188 continue;
189 apic_ids[num_cpus++] = cpu->path.apic.apic_id;
190 }
191 bubblesort(&apic_ids[sort_start], num_cpus - sort_start, NUM_ASCENDING);
192 sort_start = num_cpus;
Werner Zehdb561e62019-02-19 13:39:56 +0100193 }
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +0300194 for (index = 0; index < num_cpus; index++)
195 current = acpi_create_madt_one_lapic(current, index, apic_ids[index]);
Uwe Hermann622824c2010-11-19 15:14:42 +0000196
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000197 return current;
198}
199
Arthur Heymans9362dd72023-06-08 19:56:51 +0200200static int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300201 u32 gsi_base)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000202{
Himanshu Sahdev8c09b822019-10-21 18:50:50 +0530203 ioapic->type = IO_APIC; /* I/O APIC structure */
Uwe Hermann622824c2010-11-19 15:14:42 +0000204 ioapic->length = sizeof(acpi_madt_ioapic_t);
205 ioapic->reserved = 0x00;
206 ioapic->gsi_base = gsi_base;
207 ioapic->ioapic_id = id;
208 ioapic->ioapic_addr = addr;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000209
Uwe Hermann622824c2010-11-19 15:14:42 +0000210 return ioapic->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000211}
212
Kyösti Mälkkic7da0272021-06-08 11:37:08 +0300213#if ENV_X86
214/* For a system with multiple I/O APICs it's required that the one potentially
215 routing i8259 via ExtNMI delivery calls this first to get GSI #0. */
216int acpi_create_madt_ioapic_from_hw(acpi_madt_ioapic_t *ioapic, u32 addr)
217{
218 static u32 gsi_base;
219 u32 my_base;
220 u8 id = get_ioapic_id((void *)(uintptr_t)addr);
221 u8 count = ioapic_get_max_vectors((void *)(uintptr_t)addr);
222
223 my_base = gsi_base;
224 gsi_base += count;
225 return acpi_create_madt_ioapic(ioapic, id, addr, my_base);
226}
227#endif
228
Kyösti Mälkkie742b682023-04-10 17:03:32 +0300229static u16 acpi_sci_int(void)
Kyösti Mälkkiae1b2d42023-04-10 16:45:39 +0300230{
231#if ENV_X86
232 u8 gsi, irq, flags;
233
234 ioapic_get_sci_pin(&gsi, &irq, &flags);
235
236 /* ACPI Release 6.5, 5.2.9 and 5.2.15.5. */
237 if (!CONFIG(ACPI_HAVE_PCAT_8259))
238 return gsi;
239
240 assert(irq < 16);
241 return irq;
242#else
243 return 0;
244#endif
245}
246
Arthur Heymans9362dd72023-06-08 19:56:51 +0200247static int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
Stefan Reinauer06feb882004-02-03 16:11:35 +0000248 u8 bus, u8 source, u32 gsirq, u16 flags)
249{
Himanshu Sahdev8c09b822019-10-21 18:50:50 +0530250 irqoverride->type = IRQ_SOURCE_OVERRIDE; /* Interrupt source override */
Uwe Hermann622824c2010-11-19 15:14:42 +0000251 irqoverride->length = sizeof(acpi_madt_irqoverride_t);
252 irqoverride->bus = bus;
253 irqoverride->source = source;
254 irqoverride->gsirq = gsirq;
255 irqoverride->flags = flags;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000256
Uwe Hermann622824c2010-11-19 15:14:42 +0000257 return irqoverride->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000258}
259
Arthur Heymans9362dd72023-06-08 19:56:51 +0200260static int acpi_create_madt_sci_override(acpi_madt_irqoverride_t *irqoverride)
Kyösti Mälkkiae1b2d42023-04-10 16:45:39 +0300261{
262 u8 gsi, irq, flags;
263
264 ioapic_get_sci_pin(&gsi, &irq, &flags);
265
266 if (!CONFIG(ACPI_HAVE_PCAT_8259))
267 irq = gsi;
268
269 irqoverride->type = IRQ_SOURCE_OVERRIDE; /* Interrupt source override */
270 irqoverride->length = sizeof(acpi_madt_irqoverride_t);
271 irqoverride->bus = MP_BUS_ISA;
272 irqoverride->source = irq;
273 irqoverride->gsirq = gsi;
274 irqoverride->flags = flags;
275
276 return irqoverride->length;
277}
278
Kyösti Mälkki10bdee12023-04-11 01:00:17 +0300279static unsigned long acpi_create_madt_ioapic_gsi0_default(unsigned long current)
280{
281 current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
282
283 current += acpi_create_madt_irqoverride((void *)current, MP_BUS_ISA, 0, 2,
284 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH);
285
286 current += acpi_create_madt_sci_override((void *)current);
287
288 return current;
289}
290
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +0300291static int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300292 u16 flags, u8 lint)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000293{
Himanshu Sahdev8c09b822019-10-21 18:50:50 +0530294 lapic_nmi->type = LOCAL_APIC_NMI; /* Local APIC NMI structure */
Uwe Hermann622824c2010-11-19 15:14:42 +0000295 lapic_nmi->length = sizeof(acpi_madt_lapic_nmi_t);
296 lapic_nmi->flags = flags;
297 lapic_nmi->processor_id = cpu;
298 lapic_nmi->lint = lint;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000299
Uwe Hermann622824c2010-11-19 15:14:42 +0000300 return lapic_nmi->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000301}
302
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +0300303static int acpi_create_madt_lx2apic_nmi(acpi_madt_lx2apic_nmi_t *lapic_nmi, u32 cpu,
Patrick Rudolph56a3ef22020-03-24 17:29:49 +0100304 u16 flags, u8 lint)
305{
306 lapic_nmi->type = LOCAL_X2APIC_NMI; /* Local APIC NMI structure */
307 lapic_nmi->length = sizeof(acpi_madt_lx2apic_nmi_t);
308 lapic_nmi->flags = flags;
309 lapic_nmi->processor_id = cpu;
310 lapic_nmi->lint = lint;
311 lapic_nmi->reserved[0] = 0;
312 lapic_nmi->reserved[1] = 0;
313 lapic_nmi->reserved[2] = 0;
314
315 return lapic_nmi->length;
316}
317
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +0300318unsigned long acpi_create_madt_lapic_nmis(unsigned long current)
Kyösti Mälkki66b5e1b2022-11-12 21:13:45 +0200319{
320 const u16 flags = MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH;
321
Kyösti Mälkki66b5e1b2022-11-12 21:13:45 +0200322 /* 1: LINT1 connect to NMI */
323 /* create all subtables for processors */
324 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current,
325 ACPI_MADT_LAPIC_NMI_ALL_PROCESSORS, flags, 1);
326
327 if (!CONFIG(XAPIC_ONLY))
328 current += acpi_create_madt_lx2apic_nmi((acpi_madt_lx2apic_nmi_t *)current,
329 ACPI_MADT_LX2APIC_NMI_ALL_PROCESSORS, flags, 1);
330
331 return current;
332}
333
Arthur Heymans9362dd72023-06-08 19:56:51 +0200334static unsigned long acpi_create_madt_lapics_with_nmis(unsigned long current)
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +0300335{
336 current = acpi_create_madt_lapics(current);
337 current = acpi_create_madt_lapic_nmis(current);
338 return current;
339}
340
Arthur Heymans9368cf92023-04-25 16:07:49 +0200341static void acpi_create_madt(acpi_madt_t *madt)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000342{
Uwe Hermann622824c2010-11-19 15:14:42 +0000343 acpi_header_t *header = &(madt->header);
344 unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000345
Stefan Reinauer06feb882004-02-03 16:11:35 +0000346 memset((void *)madt, 0, sizeof(acpi_madt_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000347
John Zhao2ba303e2019-05-28 16:48:14 -0700348 if (!header)
349 return;
350
Uwe Hermann622824c2010-11-19 15:14:42 +0000351 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000352 memcpy(header->signature, "APIC", 4);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000353 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000354 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000355 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000356
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100357 header->asl_compiler_revision = asl_revision;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000358 header->length = sizeof(acpi_madt_t);
Marc Jones93a51762018-08-22 18:57:24 -0600359 header->revision = get_acpi_table_revision(MADT);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000360
Furquan Shaikhb1859a62020-04-30 21:27:47 -0700361 madt->lapic_addr = cpu_get_lapic_addr();
Nico Huber9df72e02018-11-24 18:25:50 +0100362 if (CONFIG(ACPI_HAVE_PCAT_8259))
363 madt->flags |= 1;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000364
Kyösti Mälkki69a13962023-04-08 14:10:48 +0300365 if (CONFIG(ACPI_COMMON_MADT_LAPIC))
366 current = acpi_create_madt_lapics_with_nmis(current);
367
Kyösti Mälkki10bdee12023-04-11 01:00:17 +0300368 if (CONFIG(ACPI_COMMON_MADT_IOAPIC))
369 current = acpi_create_madt_ioapic_gsi0_default(current);
370
371 if (CONFIG(ACPI_CUSTOM_MADT))
Kyösti Mälkkia5fa5342022-11-18 13:23:52 +0200372 current = acpi_fill_madt(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000373
Uwe Hermann622824c2010-11-19 15:14:42 +0000374 /* (Re)calculate length and checksum. */
375 header->length = current - (unsigned long)madt;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000376
Uwe Hermann622824c2010-11-19 15:14:42 +0000377 header->checksum = acpi_checksum((void *)madt, header->length);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000378}
379
Kyösti Mälkkib54388d2021-02-14 15:09:45 +0200380static unsigned long acpi_fill_mcfg(unsigned long current)
381{
382 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
Shelley Chen4e9bb332021-10-20 15:43:45 -0700383 CONFIG_ECAM_MMCONF_BASE_ADDRESS, 0, 0,
384 CONFIG_ECAM_MMCONF_BUS_NUMBER - 1);
Kyösti Mälkkib54388d2021-02-14 15:09:45 +0200385 return current;
386}
387
Uwe Hermann622824c2010-11-19 15:14:42 +0000388/* MCFG is defined in the PCI Firmware Specification 3.0. */
Arthur Heymans9368cf92023-04-25 16:07:49 +0200389static void acpi_create_mcfg(acpi_mcfg_t *mcfg)
Rudolf Mareke6409f22007-11-03 12:50:26 +0000390{
Uwe Hermann622824c2010-11-19 15:14:42 +0000391 acpi_header_t *header = &(mcfg->header);
392 unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000393
Rudolf Mareke6409f22007-11-03 12:50:26 +0000394 memset((void *)mcfg, 0, sizeof(acpi_mcfg_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000395
John Zhao2ba303e2019-05-28 16:48:14 -0700396 if (!header)
397 return;
398
Uwe Hermann622824c2010-11-19 15:14:42 +0000399 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000400 memcpy(header->signature, "MCFG", 4);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000401 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000402 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000403 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000404
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100405 header->asl_compiler_revision = asl_revision;
Rudolf Mareke6409f22007-11-03 12:50:26 +0000406 header->length = sizeof(acpi_mcfg_t);
Marc Jones93a51762018-08-22 18:57:24 -0600407 header->revision = get_acpi_table_revision(MCFG);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000408
Shelley Chen4e9bb332021-10-20 15:43:45 -0700409 if (CONFIG(ECAM_MMCONF_SUPPORT))
Kyösti Mälkkib54388d2021-02-14 15:09:45 +0200410 current = acpi_fill_mcfg(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000411
Uwe Hermann622824c2010-11-19 15:14:42 +0000412 /* (Re)calculate length and checksum. */
413 header->length = current - (unsigned long)mcfg;
414 header->checksum = acpi_checksum((void *)mcfg, header->length);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000415}
416
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200417static void *get_tcpa_log(u32 *size)
418{
419 const struct cbmem_entry *ce;
420 const u32 tcpa_default_log_len = 0x10000;
421 void *lasa;
Philipp Deppenwiese791ba972018-07-30 01:15:20 +0200422 ce = cbmem_entry_find(CBMEM_ID_TCPA_TCG_LOG);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200423 if (ce) {
424 lasa = cbmem_entry_start(ce);
425 *size = cbmem_entry_size(ce);
426 printk(BIOS_DEBUG, "TCPA log found at %p\n", lasa);
427 return lasa;
428 }
Philipp Deppenwiese791ba972018-07-30 01:15:20 +0200429 lasa = cbmem_add(CBMEM_ID_TCPA_TCG_LOG, tcpa_default_log_len);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200430 if (!lasa) {
431 printk(BIOS_ERR, "TCPA log creation failed\n");
432 return NULL;
433 }
434
435 printk(BIOS_DEBUG, "TCPA log created at %p\n", lasa);
Lee Leahy024b13d2017-03-16 13:41:11 -0700436 memset(lasa, 0, tcpa_default_log_len);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200437
438 *size = tcpa_default_log_len;
439 return lasa;
440}
441
442static void acpi_create_tcpa(acpi_tcpa_t *tcpa)
443{
444 acpi_header_t *header = &(tcpa->header);
445 u32 tcpa_log_len;
446 void *lasa;
447
448 memset((void *)tcpa, 0, sizeof(acpi_tcpa_t));
449
450 lasa = get_tcpa_log(&tcpa_log_len);
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700451 if (!lasa)
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200452 return;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200453
John Zhao2ba303e2019-05-28 16:48:14 -0700454 if (!header)
455 return;
456
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200457 /* Fill out header fields. */
458 memcpy(header->signature, "TCPA", 4);
459 memcpy(header->oem_id, OEM_ID, 6);
460 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
461 memcpy(header->asl_compiler_id, ASLC, 4);
462
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100463 header->asl_compiler_revision = asl_revision;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200464 header->length = sizeof(acpi_tcpa_t);
Marc Jones93a51762018-08-22 18:57:24 -0600465 header->revision = get_acpi_table_revision(TCPA);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200466
467 tcpa->platform_class = 0;
468 tcpa->laml = tcpa_log_len;
Elyes Haouas3141fbad2022-11-18 15:22:32 +0100469 tcpa->lasa = (uintptr_t)lasa;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200470
471 /* Calculate checksum. */
472 header->checksum = acpi_checksum((void *)tcpa, header->length);
473}
474
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100475static void *get_tpm2_log(u32 *size)
476{
477 const struct cbmem_entry *ce;
478 const u32 tpm2_default_log_len = 0x10000;
479 void *lasa;
480 ce = cbmem_entry_find(CBMEM_ID_TPM2_TCG_LOG);
481 if (ce) {
482 lasa = cbmem_entry_start(ce);
483 *size = cbmem_entry_size(ce);
484 printk(BIOS_DEBUG, "TPM2 log found at %p\n", lasa);
485 return lasa;
486 }
487 lasa = cbmem_add(CBMEM_ID_TPM2_TCG_LOG, tpm2_default_log_len);
488 if (!lasa) {
489 printk(BIOS_ERR, "TPM2 log creation failed\n");
490 return NULL;
491 }
492
493 printk(BIOS_DEBUG, "TPM2 log created at %p\n", lasa);
494 memset(lasa, 0, tpm2_default_log_len);
495
496 *size = tpm2_default_log_len;
497 return lasa;
498}
499
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200500static void acpi_create_tpm2(acpi_tpm2_t *tpm2)
501{
502 acpi_header_t *header = &(tpm2->header);
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100503 u32 tpm2_log_len;
504 void *lasa;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200505
506 memset((void *)tpm2, 0, sizeof(acpi_tpm2_t));
507
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100508 /*
509 * Some payloads like SeaBIOS depend on log area to use TPM2.
510 * Get the memory size and address of TPM2 log area or initialize it.
511 */
512 lasa = get_tpm2_log(&tpm2_log_len);
513 if (!lasa)
514 tpm2_log_len = 0;
515
John Zhao2ba303e2019-05-28 16:48:14 -0700516 if (!header)
517 return;
518
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200519 /* Fill out header fields. */
520 memcpy(header->signature, "TPM2", 4);
521 memcpy(header->oem_id, OEM_ID, 6);
522 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
523 memcpy(header->asl_compiler_id, ASLC, 4);
524
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100525 header->asl_compiler_revision = asl_revision;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200526 header->length = sizeof(acpi_tpm2_t);
527 header->revision = get_acpi_table_revision(TPM2);
528
529 /* Hard to detect for coreboot. Just set it to 0 */
530 tpm2->platform_class = 0;
Christian Walter26e0d4c2019-07-14 15:47:23 +0200531 if (CONFIG(CRB_TPM)) {
532 /* Must be set to 7 for CRB Support */
533 tpm2->control_area = CONFIG_CRB_TPM_BASE_ADDRESS + 0x40;
534 tpm2->start_method = 7;
535 } else {
536 /* Must be set to 0 for FIFO interface support */
537 tpm2->control_area = 0;
538 tpm2->start_method = 6;
539 }
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200540 memset(tpm2->msp, 0, sizeof(tpm2->msp));
541
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100542 /* Fill the log area size and start address fields. */
543 tpm2->laml = tpm2_log_len;
Elyes Haouas3141fbad2022-11-18 15:22:32 +0100544 tpm2->lasa = (uintptr_t)lasa;
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100545
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200546 /* Calculate checksum. */
547 header->checksum = acpi_checksum((void *)tpm2, header->length);
548}
549
Duncan Laurie37319032016-05-26 12:47:05 -0700550static void acpi_ssdt_write_cbtable(void)
551{
552 const struct cbmem_entry *cbtable;
553 uintptr_t base;
554 uint32_t size;
555
556 cbtable = cbmem_entry_find(CBMEM_ID_CBTABLE);
557 if (!cbtable)
558 return;
559 base = (uintptr_t)cbmem_entry_start(cbtable);
560 size = cbmem_entry_size(cbtable);
561
562 acpigen_write_device("CTBL");
563 acpigen_write_coreboot_hid(COREBOOT_ACPI_ID_CBTABLE);
564 acpigen_write_name_integer("_UID", 0);
David Wu5dff3962018-03-21 16:48:53 +0800565 acpigen_write_STA(ACPI_STATUS_DEVICE_HIDDEN_ON);
Duncan Laurie37319032016-05-26 12:47:05 -0700566 acpigen_write_name("_CRS");
567 acpigen_write_resourcetemplate_header();
568 acpigen_write_mem32fixed(0, base, size);
569 acpigen_write_resourcetemplate_footer();
570 acpigen_pop_len();
571}
572
Arthur Heymans9368cf92023-04-25 16:07:49 +0200573static void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000574{
Uwe Hermann622824c2010-11-19 15:14:42 +0000575 unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t);
576
Rudolf Marek293b5f52009-02-01 18:35:15 +0000577 memset((void *)ssdt, 0, sizeof(acpi_header_t));
Uwe Hermann622824c2010-11-19 15:14:42 +0000578
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000579 memcpy(&ssdt->signature, "SSDT", 4);
Marc Jones93a51762018-08-22 18:57:24 -0600580 ssdt->revision = get_acpi_table_revision(SSDT);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000581 memcpy(&ssdt->oem_id, OEM_ID, 6);
582 memcpy(&ssdt->oem_table_id, oem_table_id, 8);
583 ssdt->oem_revision = 42;
Uwe Hermann622824c2010-11-19 15:14:42 +0000584 memcpy(&ssdt->asl_compiler_id, ASLC, 4);
Elyes HAOUAS26071aa2019-02-15 08:21:33 +0100585 ssdt->asl_compiler_revision = asl_revision;
Rudolf Marek293b5f52009-02-01 18:35:15 +0000586 ssdt->length = sizeof(acpi_header_t);
587
Elyes Haouas3141fbad2022-11-18 15:22:32 +0100588 acpigen_set_current((char *)current);
Duncan Laurie37319032016-05-26 12:47:05 -0700589
590 /* Write object to declare coreboot tables */
591 acpi_ssdt_write_cbtable();
592
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200593 {
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100594 struct device *dev;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200595 for (dev = all_devices; dev; dev = dev->next)
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -0700596 if (dev->enabled && dev->ops && dev->ops->acpi_fill_ssdt)
Nico Huber68680dd2020-03-31 17:34:52 +0200597 dev->ops->acpi_fill_ssdt(dev);
Elyes Haouas3141fbad2022-11-18 15:22:32 +0100598 current = (unsigned long)acpigen_get_current();
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200599 }
Rudolf Marek293b5f52009-02-01 18:35:15 +0000600
Uwe Hermann622824c2010-11-19 15:14:42 +0000601 /* (Re)calculate length and checksum. */
Rudolf Marek293b5f52009-02-01 18:35:15 +0000602 ssdt->length = current - (unsigned long)ssdt;
603 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
604}
605
Stefan Reinauerf622d592005-11-26 16:56:05 +0000606int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
607{
Myles Watson0b4c9f02009-03-10 18:06:47 +0000608 memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000609
Uwe Hermann622824c2010-11-19 15:14:42 +0000610 lapic->type = 0; /* Processor local APIC/SAPIC affinity structure */
611 lapic->length = sizeof(acpi_srat_lapic_t);
612 lapic->flags = (1 << 0); /* Enabled (the use of this structure). */
613 lapic->proximity_domain_7_0 = node;
614 /* TODO: proximity_domain_31_8, local SAPIC EID, clock domain. */
615 lapic->apic_id = apic;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000616
Uwe Hermann622824c2010-11-19 15:14:42 +0000617 return lapic->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000618}
619
Naresh Solanki76835cc2023-01-20 19:13:02 +0100620int acpi_create_srat_x2apic(acpi_srat_x2apic_t *x2apic, u32 node, u32 apic)
621{
622 memset((void *)x2apic, 0, sizeof(acpi_srat_x2apic_t));
623
624 x2apic->type = 2; /* Processor x2APIC structure */
625 x2apic->length = sizeof(acpi_srat_x2apic_t);
626 x2apic->flags = (1 << 0); /* Enabled (the use of this structure). */
627 x2apic->proximity_domain = node;
628 x2apic->x2apic_id = apic;
629
630 return x2apic->length;
631}
632
Uwe Hermann622824c2010-11-19 15:14:42 +0000633int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300634 u32 flags)
Stefan Reinauerf622d592005-11-26 16:56:05 +0000635{
Uwe Hermann622824c2010-11-19 15:14:42 +0000636 mem->type = 1; /* Memory affinity structure */
637 mem->length = sizeof(acpi_srat_mem_t);
638 mem->base_address_low = (basek << 10);
639 mem->base_address_high = (basek >> (32 - 10));
640 mem->length_low = (sizek << 10);
641 mem->length_high = (sizek >> (32 - 10));
642 mem->proximity_domain = node;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000643 mem->flags = flags;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000644
Uwe Hermann622824c2010-11-19 15:14:42 +0000645 return mem->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000646}
647
Jonathan Zhang3164b642021-04-21 17:51:31 -0700648int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain,
649 u16 seg, u8 bus, u8 dev, u8 func, u32 flags)
650{
651 gia->type = ACPI_SRAT_STRUCTURE_GIA;
652 gia->length = sizeof(acpi_srat_gia_t);
653 gia->proximity_domain = proximity_domain;
654 gia->dev_handle_type = ACPI_SRAT_GIA_DEV_HANDLE_PCI;
655 /* First two bytes has segment number */
656 memcpy(gia->dev_handle, &seg, 2);
657 gia->dev_handle[2] = bus; /* Byte 2 has bus number */
658 /* Byte 3 has bits 7:3 for dev, bits 2:0 for func */
659 gia->dev_handle[3] = PCI_SLOT(dev) | PCI_FUNC(func);
660 gia->flags = flags;
661
662 return gia->length;
663}
664
Uwe Hermann622824c2010-11-19 15:14:42 +0000665/* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200666void acpi_create_srat(acpi_srat_t *srat,
667 unsigned long (*acpi_fill_srat)(unsigned long current))
Stefan Reinauerf622d592005-11-26 16:56:05 +0000668{
Uwe Hermann622824c2010-11-19 15:14:42 +0000669 acpi_header_t *header = &(srat->header);
670 unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000671
Uwe Hermann622824c2010-11-19 15:14:42 +0000672 memset((void *)srat, 0, sizeof(acpi_srat_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000673
John Zhao2ba303e2019-05-28 16:48:14 -0700674 if (!header)
675 return;
676
Uwe Hermann622824c2010-11-19 15:14:42 +0000677 /* Fill out header fields. */
678 memcpy(header->signature, "SRAT", 4);
679 memcpy(header->oem_id, OEM_ID, 6);
680 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
681 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000682
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100683 header->asl_compiler_revision = asl_revision;
Uwe Hermann622824c2010-11-19 15:14:42 +0000684 header->length = sizeof(acpi_srat_t);
Marc Jones93a51762018-08-22 18:57:24 -0600685 header->revision = get_acpi_table_revision(SRAT);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000686
Uwe Hermann622824c2010-11-19 15:14:42 +0000687 srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */
Stefan Reinauerf622d592005-11-26 16:56:05 +0000688
Uwe Hermann622824c2010-11-19 15:14:42 +0000689 current = acpi_fill_srat(current);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000690
Uwe Hermann622824c2010-11-19 15:14:42 +0000691 /* (Re)calculate length and checksum. */
692 header->length = current - (unsigned long)srat;
693 header->checksum = acpi_checksum((void *)srat, header->length);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000694}
695
Jonathan Zhang3dcafa82022-05-11 13:11:20 -0700696int acpi_create_cedt_chbs(acpi_cedt_chbs_t *chbs, u32 uid, u32 cxl_ver, u64 base)
697{
698 memset((void *)chbs, 0, sizeof(acpi_cedt_chbs_t));
699
700 chbs->type = ACPI_CEDT_STRUCTURE_CHBS;
701 chbs->length = sizeof(acpi_cedt_chbs_t);
702 chbs->uid = uid;
703 chbs->cxl_ver = cxl_ver;
704 chbs->base = base;
705
706 /*
707 * CXL spec 2.0 section 9.14.1.2 "CXL CHBS"
708 * CXL 1.1 spec compliant host bridge: 8KB
709 * CXL 2.0 spec compliant host bridge: 64KB
710 */
711 if (cxl_ver == ACPI_CEDT_CHBS_CXL_VER_1_1)
712 chbs->len = 8 * KiB;
713 else if (cxl_ver == ACPI_CEDT_CHBS_CXL_VER_2_0)
714 chbs->len = 64 * KiB;
715 else
716 printk(BIOS_ERR, "ACPI(%s:%s): Incorrect CXL version:%d\n", __FILE__, __func__,
717 cxl_ver);
718
719 return chbs->length;
720}
721
722int acpi_create_cedt_cfmws(acpi_cedt_cfmws_t *cfmws, u64 base_hpa, u64 window_size, u8 eniw,
723 u32 hbig, u16 restriction, u16 qtg_id, const u32 *interleave_target)
724{
725 memset((void *)cfmws, 0, sizeof(acpi_cedt_cfmws_t));
726
727 cfmws->type = ACPI_CEDT_STRUCTURE_CFMWS;
728
729 u8 niw = 0;
730 if (eniw >= 8)
731 printk(BIOS_ERR, "ACPI(%s:%s): Incorrect eniw::%d\n", __FILE__, __func__, eniw);
732 else
733 /* NIW = 2 ** ENIW */
734 niw = 0x1 << eniw;
735 /* 36 + 4 * NIW */
736 cfmws->length = sizeof(acpi_cedt_cfmws_t) + 4 * niw;
737
738 cfmws->base_hpa = base_hpa;
739 cfmws->window_size = window_size;
740 cfmws->eniw = eniw;
741
742 // 0: Standard Modulo Arithmetic. Other values reserved.
743 cfmws->interleave_arithmetic = 0;
744
745 cfmws->hbig = hbig;
746 cfmws->restriction = restriction;
747 cfmws->qtg_id = qtg_id;
748 memcpy(&cfmws->interleave_target, interleave_target, 4 * niw);
749
750 return cfmws->length;
751}
752
753void acpi_create_cedt(acpi_cedt_t *cedt, unsigned long (*acpi_fill_cedt)(unsigned long current))
754{
755 acpi_header_t *header = &(cedt->header);
756 unsigned long current = (unsigned long)cedt + sizeof(acpi_cedt_t);
757
758 memset((void *)cedt, 0, sizeof(acpi_cedt_t));
759
760 if (!header)
761 return;
762
763 /* Fill out header fields. */
764 memcpy(header->signature, "CEDT", 4);
765 memcpy(header->oem_id, OEM_ID, 6);
766 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
767 memcpy(header->asl_compiler_id, ASLC, 4);
768
769 header->asl_compiler_revision = asl_revision;
770 header->length = sizeof(acpi_cedt_t);
771 header->revision = get_acpi_table_revision(CEDT);
772
773 current = acpi_fill_cedt(current);
774
775 /* (Re)calculate length and checksum. */
776 header->length = current - (unsigned long)cedt;
777 header->checksum = acpi_checksum((void *)cedt, header->length);
778}
779
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -0700780int acpi_create_hmat_mpda(acpi_hmat_mpda_t *mpda, u32 initiator, u32 memory)
781{
782 memset((void *)mpda, 0, sizeof(acpi_hmat_mpda_t));
783
784 mpda->type = 0; /* Memory Proximity Domain Attributes structure */
785 mpda->length = sizeof(acpi_hmat_mpda_t);
786 /*
787 * Proximity Domain for Attached Initiator field is valid.
788 * Bit 1 and bit 2 are reserved since HMAT revision 2.
789 */
790 mpda->flags = (1 << 0);
791 mpda->proximity_domain_initiator = initiator;
792 mpda->proximity_domain_memory = memory;
793
794 return mpda->length;
795}
796
797void acpi_create_hmat(acpi_hmat_t *hmat,
798 unsigned long (*acpi_fill_hmat)(unsigned long current))
799{
800 acpi_header_t *header = &(hmat->header);
801 unsigned long current = (unsigned long)hmat + sizeof(acpi_hmat_t);
802
803 memset((void *)hmat, 0, sizeof(acpi_hmat_t));
804
805 if (!header)
806 return;
807
808 /* Fill out header fields. */
809 memcpy(header->signature, "HMAT", 4);
810 memcpy(header->oem_id, OEM_ID, 6);
811 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
812 memcpy(header->asl_compiler_id, ASLC, 4);
813
814 header->asl_compiler_revision = asl_revision;
815 header->length = sizeof(acpi_hmat_t);
816 header->revision = get_acpi_table_revision(HMAT);
817
818 current = acpi_fill_hmat(current);
819
820 /* (Re)calculate length and checksum. */
821 header->length = current - (unsigned long)hmat;
822 header->checksum = acpi_checksum((void *)hmat, header->length);
823}
824
Nico Hubere561f352015-10-26 11:51:25 +0100825void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
Lee Leahy024b13d2017-03-16 13:41:11 -0700826 unsigned long (*acpi_fill_dmar)(unsigned long))
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200827{
828 acpi_header_t *header = &(dmar->header);
829 unsigned long current = (unsigned long)dmar + sizeof(acpi_dmar_t);
830
831 memset((void *)dmar, 0, sizeof(acpi_dmar_t));
832
John Zhao2ba303e2019-05-28 16:48:14 -0700833 if (!header)
834 return;
835
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200836 /* Fill out header fields. */
837 memcpy(header->signature, "DMAR", 4);
838 memcpy(header->oem_id, OEM_ID, 6);
839 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
840 memcpy(header->asl_compiler_id, ASLC, 4);
841
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100842 header->asl_compiler_revision = asl_revision;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200843 header->length = sizeof(acpi_dmar_t);
Marc Jones93a51762018-08-22 18:57:24 -0600844 header->revision = get_acpi_table_revision(DMAR);
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200845
Jacob Laskaf3f654d2016-03-15 21:53:27 -0500846 dmar->host_address_width = cpu_phys_address_size() - 1;
Nico Hubere561f352015-10-26 11:51:25 +0100847 dmar->flags = flags;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200848
849 current = acpi_fill_dmar(current);
850
851 /* (Re)calculate length and checksum. */
852 header->length = current - (unsigned long)dmar;
853 header->checksum = acpi_checksum((void *)dmar, header->length);
854}
855
856unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
Matt DeVillier7866d492018-03-29 14:59:57 +0200857 u16 segment, u64 bar)
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200858{
859 dmar_entry_t *drhd = (dmar_entry_t *)current;
860 memset(drhd, 0, sizeof(*drhd));
861 drhd->type = DMAR_DRHD;
862 drhd->length = sizeof(*drhd); /* will be fixed up later */
863 drhd->flags = flags;
864 drhd->segment = segment;
865 drhd->bar = bar;
866
867 return drhd->length;
868}
869
Matt DeVillier7866d492018-03-29 14:59:57 +0200870unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
871 u64 bar, u64 limit)
872{
873 dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)current;
874 memset(rmrr, 0, sizeof(*rmrr));
875 rmrr->type = DMAR_RMRR;
876 rmrr->length = sizeof(*rmrr); /* will be fixed up later */
877 rmrr->segment = segment;
878 rmrr->bar = bar;
879 rmrr->limit = limit;
880
881 return rmrr->length;
882}
883
Werner Zehd4d76952016-07-27 06:56:36 +0200884unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
885 u16 segment)
886{
887 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)current;
888 memset(atsr, 0, sizeof(*atsr));
889 atsr->type = DMAR_ATSR;
890 atsr->length = sizeof(*atsr); /* will be fixed up later */
891 atsr->flags = flags;
892 atsr->segment = segment;
893
894 return atsr->length;
895}
896
John Zhao76e70672019-04-04 11:03:28 -0700897unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
898 u32 proximity_domain)
899{
900 dmar_rhsa_entry_t *rhsa = (dmar_rhsa_entry_t *)current;
901 memset(rhsa, 0, sizeof(*rhsa));
902 rhsa->type = DMAR_RHSA;
903 rhsa->length = sizeof(*rhsa);
904 rhsa->base_address = base_addr;
905 rhsa->proximity_domain = proximity_domain;
906
907 return rhsa->length;
908}
909
910unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
911 const char *device_name)
912{
913 dmar_andd_entry_t *andd = (dmar_andd_entry_t *)current;
914 int andd_len = sizeof(dmar_andd_entry_t) + strlen(device_name) + 1;
915 memset(andd, 0, andd_len);
916 andd->type = DMAR_ANDD;
917 andd->length = andd_len;
918 andd->device_number = device_number;
919 memcpy(&andd->device_name, device_name, strlen(device_name));
920
921 return andd->length;
922}
923
John Zhao091532d2021-04-17 16:03:21 -0700924unsigned long acpi_create_dmar_satc(unsigned long current, u8 flags, u16 segment)
John Zhao6edbb182021-03-24 11:55:09 -0700925{
926 dmar_satc_entry_t *satc = (dmar_satc_entry_t *)current;
John Zhao091532d2021-04-17 16:03:21 -0700927 int satc_len = sizeof(dmar_satc_entry_t);
John Zhao6edbb182021-03-24 11:55:09 -0700928 memset(satc, 0, satc_len);
929 satc->type = DMAR_SATC;
930 satc->length = satc_len;
931 satc->flags = flags;
932 satc->segment_number = segment;
John Zhao6edbb182021-03-24 11:55:09 -0700933
934 return satc->length;
935}
936
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200937void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current)
938{
939 dmar_entry_t *drhd = (dmar_entry_t *)base;
940 drhd->length = current - base;
941}
942
Matt DeVillier7866d492018-03-29 14:59:57 +0200943void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current)
944{
945 dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)base;
946 rmrr->length = current - base;
947}
948
Werner Zehd4d76952016-07-27 06:56:36 +0200949void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current)
950{
951 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)base;
952 atsr->length = current - base;
953}
954
John Zhao6edbb182021-03-24 11:55:09 -0700955void acpi_dmar_satc_fixup(unsigned long base, unsigned long current)
956{
957 dmar_satc_entry_t *satc = (dmar_satc_entry_t *)base;
958 satc->length = current - base;
959}
960
Matt DeVillier7866d492018-03-29 14:59:57 +0200961static unsigned long acpi_create_dmar_ds(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100962 enum dev_scope_type type, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200963{
Nico Huber6c4751d2015-10-26 12:03:54 +0100964 /* we don't support longer paths yet */
965 const size_t dev_scope_length = sizeof(dev_scope_t) + 2;
966
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200967 dev_scope_t *ds = (dev_scope_t *)current;
Nico Huber6c4751d2015-10-26 12:03:54 +0100968 memset(ds, 0, dev_scope_length);
969 ds->type = type;
970 ds->length = dev_scope_length;
971 ds->enumeration = enumeration_id;
972 ds->start_bus = bus;
973 ds->path[0].dev = dev;
974 ds->path[0].fn = fn;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200975
976 return ds->length;
977}
978
Matt DeVillier7866d492018-03-29 14:59:57 +0200979unsigned long acpi_create_dmar_ds_pci_br(unsigned long current, u8 bus,
Werner Zeh21a5bff2016-07-27 07:07:20 +0200980 u8 dev, u8 fn)
981{
Matt DeVillier7866d492018-03-29 14:59:57 +0200982 return acpi_create_dmar_ds(current,
Werner Zeh21a5bff2016-07-27 07:07:20 +0200983 SCOPE_PCI_SUB, 0, bus, dev, fn);
984}
985
Matt DeVillier7866d492018-03-29 14:59:57 +0200986unsigned long acpi_create_dmar_ds_pci(unsigned long current, u8 bus,
Nico Huber6c4751d2015-10-26 12:03:54 +0100987 u8 dev, u8 fn)
988{
Matt DeVillier7866d492018-03-29 14:59:57 +0200989 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100990 SCOPE_PCI_ENDPOINT, 0, bus, dev, fn);
991}
992
Matt DeVillier7866d492018-03-29 14:59:57 +0200993unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100994 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
995{
Matt DeVillier7866d492018-03-29 14:59:57 +0200996 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100997 SCOPE_IOAPIC, enumeration_id, bus, dev, fn);
998}
999
Arthur Heymansbc8f8592022-12-02 13:17:39 +01001000unsigned long acpi_create_dmar_ds_ioapic_from_hw(unsigned long current,
1001 u32 addr, u8 bus, u8 dev, u8 fn)
1002{
1003 u8 enumeration_id = get_ioapic_id((void *)(uintptr_t)addr);
1004 return acpi_create_dmar_ds(current,
1005 SCOPE_IOAPIC, enumeration_id, bus, dev, fn);
1006}
1007
Matt DeVillier7866d492018-03-29 14:59:57 +02001008unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +01001009 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
1010{
Matt DeVillier7866d492018-03-29 14:59:57 +02001011 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +01001012 SCOPE_MSI_HPET, enumeration_id, bus, dev, fn);
1013}
1014
Uwe Hermann622824c2010-11-19 15:14:42 +00001015/* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +02001016void acpi_create_slit(acpi_slit_t *slit,
1017 unsigned long (*acpi_fill_slit)(unsigned long current))
Yinghai Lud4b278c2006-10-04 20:46:15 +00001018{
Uwe Hermann622824c2010-11-19 15:14:42 +00001019 acpi_header_t *header = &(slit->header);
1020 unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t);
Yinghai Lud4b278c2006-10-04 20:46:15 +00001021
Uwe Hermann622824c2010-11-19 15:14:42 +00001022 memset((void *)slit, 0, sizeof(acpi_slit_t));
Yinghai Lud4b278c2006-10-04 20:46:15 +00001023
John Zhao2ba303e2019-05-28 16:48:14 -07001024 if (!header)
1025 return;
1026
Uwe Hermann622824c2010-11-19 15:14:42 +00001027 /* Fill out header fields. */
1028 memcpy(header->signature, "SLIT", 4);
1029 memcpy(header->oem_id, OEM_ID, 6);
1030 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1031 memcpy(header->asl_compiler_id, ASLC, 4);
Yinghai Lud4b278c2006-10-04 20:46:15 +00001032
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001033 header->asl_compiler_revision = asl_revision;
Uwe Hermann622824c2010-11-19 15:14:42 +00001034 header->length = sizeof(acpi_slit_t);
Marc Jones93a51762018-08-22 18:57:24 -06001035 header->revision = get_acpi_table_revision(SLIT);
Yinghai Lud4b278c2006-10-04 20:46:15 +00001036
Uwe Hermann622824c2010-11-19 15:14:42 +00001037 current = acpi_fill_slit(current);
Yinghai Lud4b278c2006-10-04 20:46:15 +00001038
Uwe Hermann622824c2010-11-19 15:14:42 +00001039 /* (Re)calculate length and checksum. */
1040 header->length = current - (unsigned long)slit;
1041 header->checksum = acpi_checksum((void *)slit, header->length);
Yinghai Lud4b278c2006-10-04 20:46:15 +00001042}
1043
Uwe Hermann622824c2010-11-19 15:14:42 +00001044/* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */
Arthur Heymans9368cf92023-04-25 16:07:49 +02001045static void acpi_create_hpet(acpi_hpet_t *hpet)
Stefan Reinauer688b3852004-01-28 16:56:14 +00001046{
Uwe Hermann622824c2010-11-19 15:14:42 +00001047 acpi_header_t *header = &(hpet->header);
1048 acpi_addr_t *addr = &(hpet->addr);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001049
Stefan Reinauera7648c22004-01-29 17:31:34 +00001050 memset((void *)hpet, 0, sizeof(acpi_hpet_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +00001051
John Zhao2ba303e2019-05-28 16:48:14 -07001052 if (!header)
1053 return;
1054
Uwe Hermann622824c2010-11-19 15:14:42 +00001055 /* Fill out header fields. */
Stefan Reinauer4704dc52009-07-22 01:11:37 +00001056 memcpy(header->signature, "HPET", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +00001057 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001058 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +00001059 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001060
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001061 header->asl_compiler_revision = asl_revision;
Stefan Reinauer688b3852004-01-28 16:56:14 +00001062 header->length = sizeof(acpi_hpet_t);
Marc Jones93a51762018-08-22 18:57:24 -06001063 header->revision = get_acpi_table_revision(HPET);
Stefan Reinauer688b3852004-01-28 16:56:14 +00001064
Uwe Hermann622824c2010-11-19 15:14:42 +00001065 /* Fill out HPET address. */
Elyes HAOUAS04071f42020-07-20 17:05:24 +02001066 addr->space_id = ACPI_ADDRESS_SPACE_MEMORY;
Uwe Hermann622824c2010-11-19 15:14:42 +00001067 addr->bit_width = 64;
1068 addr->bit_offset = 0;
Felix Held972d9f22022-02-23 16:32:20 +01001069 addr->addrl = HPET_BASE_ADDRESS & 0xffffffff;
1070 addr->addrh = ((unsigned long long)HPET_BASE_ADDRESS) >> 32;
Stefan Reinauer688b3852004-01-28 16:56:14 +00001071
Felix Held972d9f22022-02-23 16:32:20 +01001072 hpet->id = read32p(HPET_BASE_ADDRESS);
Uwe Hermann622824c2010-11-19 15:14:42 +00001073 hpet->number = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +02001074 hpet->min_tick = CONFIG_HPET_MIN_TICKS;
Stefan Reinauer14e22772010-04-27 06:56:47 +00001075
Uwe Hermann622824c2010-11-19 15:14:42 +00001076 header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +00001077}
Uwe Hermann622824c2010-11-19 15:14:42 +00001078
Rocky Phaguraeff07132021-01-10 15:42:50 -08001079/*
1080 * This method adds the ACPI error injection capability. It fills the default information.
1081 * HW dependent code (caller) can modify the defaults upon return. If no changes are necessary
1082 * and the defaults are acceptable then caller can simply add the table (acpi_add_table).
1083 * INPUTS:
1084 * einj - ptr to the starting location of EINJ table
1085 * actions - number of actions to trigger an error (HW dependent)
1086 * addr - address of trigger action table. This should be ACPI reserved memory and it will be
1087 * shared between OS and FW.
1088 */
1089void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions)
1090{
1091 int i;
1092 acpi_header_t *header = &(einj->header);
1093 acpi_injection_header_t *inj_header = &(einj->inj_header);
1094 acpi_einj_smi_t *einj_smi = (acpi_einj_smi_t *)addr;
1095 acpi_einj_trigger_table_t *tat;
1096 if (!header)
1097 return;
1098
1099 printk(BIOS_DEBUG, "%s einj_smi = %p\n", __func__, einj_smi);
1100 memset(einj_smi, 0, sizeof(acpi_einj_smi_t));
Jonathan Zhangd5d9b282022-11-07 17:30:14 -08001101 tat = (acpi_einj_trigger_table_t *)((uint8_t *)einj_smi + sizeof(acpi_einj_smi_t));
Rocky Phaguraeff07132021-01-10 15:42:50 -08001102 tat->header_size = 16;
1103 tat->revision = 0;
1104 tat->table_size = sizeof(acpi_einj_trigger_table_t) +
1105 sizeof(acpi_einj_action_table_t) * actions - 1;
1106 tat->entry_count = actions;
1107 printk(BIOS_DEBUG, "%s trigger_action_table = %p\n", __func__, tat);
1108
1109 for (i = 0; i < actions; i++) {
1110 tat->trigger_action[i].action = TRIGGER_ERROR;
1111 tat->trigger_action[i].instruction = NO_OP;
1112 tat->trigger_action[i].flags = FLAG_IGNORE;
1113 tat->trigger_action[i].reg.space_id = ACPI_ADDRESS_SPACE_MEMORY;
1114 tat->trigger_action[i].reg.bit_width = 64;
1115 tat->trigger_action[i].reg.bit_offset = 0;
1116 tat->trigger_action[i].reg.access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS;
1117 tat->trigger_action[i].reg.addr = 0;
1118 tat->trigger_action[i].value = 0;
1119 tat->trigger_action[i].mask = 0xFFFFFFFF;
1120 }
1121
1122 acpi_einj_action_table_t default_actions[ACTION_COUNT] = {
1123 [0] = {
1124 .action = BEGIN_INJECT_OP,
1125 .instruction = WRITE_REGISTER_VALUE,
1126 .flags = FLAG_PRESERVE,
1127 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_state),
1128 .value = 0,
1129 .mask = 0xFFFFFFFF
1130 },
1131 [1] = {
1132 .action = GET_TRIGGER_ACTION_TABLE,
1133 .instruction = READ_REGISTER,
1134 .flags = FLAG_IGNORE,
1135 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->trigger_action_table),
1136 .value = 0,
1137 .mask = 0xFFFFFFFFFFFFFFFF
1138 },
1139 [2] = {
1140 .action = SET_ERROR_TYPE,
1141 .instruction = WRITE_REGISTER,
1142 .flags = FLAG_PRESERVE,
1143 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->err_inject[0]),
1144 .value = 0,
1145 .mask = 0xFFFFFFFF
1146 },
1147 [3] = {
1148 .action = GET_ERROR_TYPE,
1149 .instruction = READ_REGISTER,
1150 .flags = FLAG_IGNORE,
1151 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->err_inj_cap),
1152 .value = 0,
1153 .mask = 0xFFFFFFFF
1154 },
1155 [4] = {
1156 .action = END_INJECT_OP,
1157 .instruction = WRITE_REGISTER_VALUE,
1158 .flags = FLAG_PRESERVE,
1159 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_state),
1160 .value = 0,
1161 .mask = 0xFFFFFFFF
1162
1163 },
1164 [5] = {
1165 .action = EXECUTE_INJECT_OP,
1166 .instruction = WRITE_REGISTER_VALUE,
1167 .flags = FLAG_PRESERVE,
1168 .reg = EINJ_REG_IO(),
1169 .value = 0x9a,
1170 .mask = 0xFFFF,
1171 },
1172 [6] = {
1173 .action = CHECK_BUSY_STATUS,
1174 .instruction = READ_REGISTER_VALUE,
1175 .flags = FLAG_IGNORE,
1176 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_status),
1177 .value = 1,
1178 .mask = 1,
1179 },
1180 [7] = {
1181 .action = GET_CMD_STATUS,
1182 .instruction = READ_REGISTER,
1183 .flags = FLAG_PRESERVE,
1184 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->cmd_sts),
1185 .value = 0,
1186 .mask = 0x1fe,
1187 },
1188 [8] = {
1189 .action = SET_ERROR_TYPE_WITH_ADDRESS,
1190 .instruction = WRITE_REGISTER,
1191 .flags = FLAG_PRESERVE,
1192 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->setaddrtable),
1193 .value = 1,
1194 .mask = 0xffffffff
1195 }
1196 };
1197
1198 einj_smi->err_inj_cap = ACPI_EINJ_DEFAULT_CAP;
Elyes Haouas3141fbad2022-11-18 15:22:32 +01001199 einj_smi->trigger_action_table = (u64)(uintptr_t)tat;
Rocky Phaguraeff07132021-01-10 15:42:50 -08001200
1201 for (i = 0; i < ACTION_COUNT; i++)
1202 printk(BIOS_DEBUG, "default_actions[%d].reg.addr is %llx\n", i,
1203 default_actions[i].reg.addr);
1204
Rocky Phagurab46a9e52021-05-21 13:34:03 -07001205 memset((void *)einj, 0, sizeof(*einj));
Rocky Phaguraeff07132021-01-10 15:42:50 -08001206
1207 /* Fill out header fields. */
1208 memcpy(header->signature, "EINJ", 4);
1209 memcpy(header->oem_id, OEM_ID, 6);
1210 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1211 memcpy(header->asl_compiler_id, ASLC, 4);
1212
1213 header->asl_compiler_revision = asl_revision;
1214 header->length = sizeof(acpi_einj_t);
1215 header->revision = 1;
1216 inj_header->einj_header_size = sizeof(acpi_injection_header_t);
1217 inj_header->entry_count = ACTION_COUNT;
1218
1219 printk(BIOS_DEBUG, "%s einj->action_table = %p\n",
1220 __func__, einj->action_table);
1221 memcpy((void *)einj->action_table, (void *)default_actions, sizeof(einj->action_table));
Rocky Phagurab46a9e52021-05-21 13:34:03 -07001222 header->checksum = acpi_checksum((void *)einj, sizeof(*einj));
Rocky Phaguraeff07132021-01-10 15:42:50 -08001223}
1224
Furquan Shaikh0f007d82020-04-24 06:41:18 -07001225void acpi_create_vfct(const struct device *device,
Himanshu Sahdev7f1da072019-10-21 15:27:19 +05301226 acpi_vfct_t *vfct,
Furquan Shaikh0f007d82020-04-24 06:41:18 -07001227 unsigned long (*acpi_fill_vfct)(const struct device *device,
Himanshu Sahdev7f1da072019-10-21 15:27:19 +05301228 acpi_vfct_t *vfct_struct, unsigned long current))
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +02001229{
1230 acpi_header_t *header = &(vfct->header);
Himanshu Sahdev7f1da072019-10-21 15:27:19 +05301231 unsigned long current = (unsigned long)vfct + sizeof(acpi_vfct_t);
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +02001232
Himanshu Sahdev7f1da072019-10-21 15:27:19 +05301233 memset((void *)vfct, 0, sizeof(acpi_vfct_t));
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +02001234
John Zhao2ba303e2019-05-28 16:48:14 -07001235 if (!header)
1236 return;
1237
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +02001238 /* Fill out header fields. */
1239 memcpy(header->signature, "VFCT", 4);
1240 memcpy(header->oem_id, OEM_ID, 6);
1241 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1242 memcpy(header->asl_compiler_id, ASLC, 4);
1243
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001244 header->asl_compiler_revision = asl_revision;
Marc Jones93a51762018-08-22 18:57:24 -06001245 header->revision = get_acpi_table_revision(VFCT);
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +02001246
1247 current = acpi_fill_vfct(device, vfct, current);
1248
Kyösti Mälkkifb493792019-06-30 06:29:52 +03001249 /* If no BIOS image, return with header->length == 0. */
1250 if (!vfct->VBIOSImageOffset)
1251 return;
1252
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +02001253 /* (Re)calculate length and checksum. */
1254 header->length = current - (unsigned long)vfct;
1255 header->checksum = acpi_checksum((void *)vfct, header->length);
1256}
1257
Furquan Shaikh0f007d82020-04-24 06:41:18 -07001258void acpi_create_ipmi(const struct device *device,
Patrick Rudolph9d98e5a2019-06-14 19:00:04 +02001259 struct acpi_spmi *spmi,
1260 const u16 ipmi_revision,
1261 const acpi_addr_t *addr,
1262 const enum acpi_ipmi_interface_type type,
1263 const s8 gpe_interrupt,
1264 const u32 apic_interrupt,
1265 const u32 uid)
1266{
1267 acpi_header_t *header = &(spmi->header);
1268 memset((void *)spmi, 0, sizeof(struct acpi_spmi));
1269
1270 /* Fill out header fields. */
1271 memcpy(header->signature, "SPMI", 4);
1272 memcpy(header->oem_id, OEM_ID, 6);
1273 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1274 memcpy(header->asl_compiler_id, ASLC, 4);
1275
1276 header->asl_compiler_revision = asl_revision;
1277 header->length = sizeof(struct acpi_spmi);
1278 header->revision = get_acpi_table_revision(SPMI);
1279
1280 spmi->reserved = 1;
1281
1282 if (device->path.type == DEVICE_PATH_PCI) {
1283 spmi->pci_device_flag = ACPI_IPMI_PCI_DEVICE_FLAG;
1284 spmi->pci_bus = device->bus->secondary;
1285 spmi->pci_device = device->path.pci.devfn >> 3;
1286 spmi->pci_function = device->path.pci.devfn & 0x7;
1287 } else if (type != IPMI_INTERFACE_SSIF) {
1288 memcpy(spmi->uid, &uid, sizeof(spmi->uid));
1289 }
1290
1291 spmi->base_address = *addr;
1292 spmi->specification_revision = ipmi_revision;
1293
1294 spmi->interface_type = type;
1295
1296 if (gpe_interrupt >= 0 && gpe_interrupt < 32) {
1297 spmi->gpe = gpe_interrupt;
1298 spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_SCI;
1299 }
1300 if (apic_interrupt > 0) {
1301 spmi->global_system_interrupt = apic_interrupt;
1302 spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_APIC;
1303 }
1304
1305 /* Calculate checksum. */
1306 header->checksum = acpi_checksum((void *)spmi, header->length);
1307}
1308
Timothy Pearsonff8ccf02015-08-11 17:48:32 -05001309void acpi_create_ivrs(acpi_ivrs_t *ivrs,
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001310 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
1311 unsigned long current))
Timothy Pearsonff8ccf02015-08-11 17:48:32 -05001312{
1313 acpi_header_t *header = &(ivrs->header);
1314 unsigned long current = (unsigned long)ivrs + sizeof(acpi_ivrs_t);
1315
1316 memset((void *)ivrs, 0, sizeof(acpi_ivrs_t));
1317
John Zhao2ba303e2019-05-28 16:48:14 -07001318 if (!header)
1319 return;
1320
Timothy Pearsonff8ccf02015-08-11 17:48:32 -05001321 /* Fill out header fields. */
1322 memcpy(header->signature, "IVRS", 4);
1323 memcpy(header->oem_id, OEM_ID, 6);
1324 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1325 memcpy(header->asl_compiler_id, ASLC, 4);
1326
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001327 header->asl_compiler_revision = asl_revision;
Timothy Pearsonff8ccf02015-08-11 17:48:32 -05001328 header->length = sizeof(acpi_ivrs_t);
Marc Jones93a51762018-08-22 18:57:24 -06001329 header->revision = get_acpi_table_revision(IVRS);
Timothy Pearsonff8ccf02015-08-11 17:48:32 -05001330
1331 current = acpi_fill_ivrs(ivrs, current);
1332
1333 /* (Re)calculate length and checksum. */
1334 header->length = current - (unsigned long)ivrs;
1335 header->checksum = acpi_checksum((void *)ivrs, header->length);
1336}
1337
Jason Glenesk61624b22020-11-02 20:06:23 -08001338void acpi_create_crat(struct acpi_crat_header *crat,
1339 unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct,
1340 unsigned long current))
1341{
1342 acpi_header_t *header = &(crat->header);
1343 unsigned long current = (unsigned long)crat + sizeof(struct acpi_crat_header);
1344
1345 memset((void *)crat, 0, sizeof(struct acpi_crat_header));
1346
1347 if (!header)
1348 return;
1349
1350 /* Fill out header fields. */
1351 memcpy(header->signature, "CRAT", 4);
1352 memcpy(header->oem_id, OEM_ID, 6);
1353 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1354 memcpy(header->asl_compiler_id, ASLC, 4);
1355
1356 header->asl_compiler_revision = asl_revision;
1357 header->length = sizeof(struct acpi_crat_header);
1358 header->revision = get_acpi_table_revision(CRAT);
1359
1360 current = acpi_fill_crat(crat, current);
1361
1362 /* (Re)calculate length and checksum. */
1363 header->length = current - (unsigned long)crat;
1364 header->checksum = acpi_checksum((void *)crat, header->length);
1365}
1366
Furquan Shaikh0f007d82020-04-24 06:41:18 -07001367unsigned long acpi_write_hpet(const struct device *device, unsigned long current,
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001368 acpi_rsdp_t *rsdp)
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001369{
1370 acpi_hpet_t *hpet;
1371
1372 /*
1373 * We explicitly add these tables later on:
1374 */
1375 printk(BIOS_DEBUG, "ACPI: * HPET\n");
1376
Elyes Haouas3141fbad2022-11-18 15:22:32 +01001377 hpet = (acpi_hpet_t *)current;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001378 current += sizeof(acpi_hpet_t);
Felix Heldc4697122019-06-20 13:50:17 +02001379 current = ALIGN_UP(current, 16);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001380 acpi_create_hpet(hpet);
1381 acpi_add_table(rsdp, hpet);
1382
1383 return current;
1384}
1385
Arthur Heymans9368cf92023-04-25 16:07:49 +02001386static void acpi_create_dbg2(acpi_dbg2_header_t *dbg2,
Duncan Lauriee4a36c72017-11-11 19:33:25 -08001387 int port_type, int port_subtype,
1388 acpi_addr_t *address, uint32_t address_size,
1389 const char *device_path)
1390{
1391 uintptr_t current;
1392 acpi_dbg2_device_t *device;
1393 uint32_t *dbg2_addr_size;
1394 acpi_header_t *header;
1395 size_t path_len;
1396 const char *path;
1397 char *namespace;
1398
1399 /* Fill out header fields. */
1400 current = (uintptr_t)dbg2;
1401 memset(dbg2, 0, sizeof(acpi_dbg2_header_t));
1402 header = &(dbg2->header);
John Zhao2ba303e2019-05-28 16:48:14 -07001403
1404 if (!header)
1405 return;
1406
Marc Jones93a51762018-08-22 18:57:24 -06001407 header->revision = get_acpi_table_revision(DBG2);
Duncan Lauriee4a36c72017-11-11 19:33:25 -08001408 memcpy(header->signature, "DBG2", 4);
1409 memcpy(header->oem_id, OEM_ID, 6);
1410 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1411 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001412 header->asl_compiler_revision = asl_revision;
Duncan Lauriee4a36c72017-11-11 19:33:25 -08001413
1414 /* One debug device defined */
1415 dbg2->devices_offset = sizeof(acpi_dbg2_header_t);
1416 dbg2->devices_count = 1;
1417 current += sizeof(acpi_dbg2_header_t);
1418
1419 /* Device comes after the header */
1420 device = (acpi_dbg2_device_t *)current;
1421 memset(device, 0, sizeof(acpi_dbg2_device_t));
1422 current += sizeof(acpi_dbg2_device_t);
1423
1424 device->revision = 0;
1425 device->address_count = 1;
1426 device->port_type = port_type;
1427 device->port_subtype = port_subtype;
1428
1429 /* Base Address comes after device structure */
1430 memcpy((void *)current, address, sizeof(acpi_addr_t));
1431 device->base_address_offset = current - (uintptr_t)device;
1432 current += sizeof(acpi_addr_t);
1433
1434 /* Address Size comes after address structure */
1435 dbg2_addr_size = (uint32_t *)current;
1436 device->address_size_offset = current - (uintptr_t)device;
1437 *dbg2_addr_size = address_size;
1438 current += sizeof(uint32_t);
1439
1440 /* Namespace string comes last, use '.' if not provided */
1441 path = device_path ? : ".";
1442 /* Namespace string length includes NULL terminator */
1443 path_len = strlen(path) + 1;
1444 namespace = (char *)current;
1445 device->namespace_string_length = path_len;
1446 device->namespace_string_offset = current - (uintptr_t)device;
1447 strncpy(namespace, path, path_len);
1448 current += path_len;
1449
1450 /* Update structure lengths and checksum */
1451 device->length = current - (uintptr_t)device;
1452 header->length = current - (uintptr_t)dbg2;
1453 header->checksum = acpi_checksum((uint8_t *)dbg2, header->length);
1454}
1455
1456unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
Aamir Bohrae825d3f2019-07-30 10:11:41 +05301457 const struct device *dev, uint8_t access_size)
Duncan Lauriee4a36c72017-11-11 19:33:25 -08001458{
1459 acpi_dbg2_header_t *dbg2 = (acpi_dbg2_header_t *)current;
1460 struct resource *res;
1461 acpi_addr_t address;
1462
1463 if (!dev) {
Wim Vervoorn6cd52432020-02-03 14:41:46 +01001464 printk(BIOS_DEBUG, "%s: Device not found\n", __func__);
Duncan Lauriee4a36c72017-11-11 19:33:25 -08001465 return current;
1466 }
Mario Scheithauerf1eb0ea2017-11-21 13:52:53 +01001467 if (!dev->enabled) {
1468 printk(BIOS_INFO, "%s: Device not enabled\n", __func__);
1469 return current;
1470 }
Angel Pons32d09be2021-11-03 13:27:45 +01001471 res = probe_resource(dev, PCI_BASE_ADDRESS_0);
Duncan Lauriee4a36c72017-11-11 19:33:25 -08001472 if (!res) {
1473 printk(BIOS_ERR, "%s: Unable to find resource for %s\n",
1474 __func__, dev_path(dev));
1475 return current;
1476 }
1477
1478 memset(&address, 0, sizeof(address));
1479 if (res->flags & IORESOURCE_IO)
1480 address.space_id = ACPI_ADDRESS_SPACE_IO;
1481 else if (res->flags & IORESOURCE_MEM)
1482 address.space_id = ACPI_ADDRESS_SPACE_MEMORY;
1483 else {
1484 printk(BIOS_ERR, "%s: Unknown address space type\n", __func__);
1485 return current;
1486 }
1487
1488 address.addrl = (uint32_t)res->base;
1489 address.addrh = (uint32_t)((res->base >> 32) & 0xffffffff);
1490 address.access_size = access_size;
1491
1492 acpi_create_dbg2(dbg2,
1493 ACPI_DBG2_PORT_SERIAL,
1494 ACPI_DBG2_PORT_SERIAL_16550,
1495 &address, res->size,
1496 acpi_device_path(dev));
1497
1498 if (dbg2->header.length) {
1499 current += dbg2->header.length;
1500 current = acpi_align_current(current);
1501 acpi_add_table(rsdp, dbg2);
1502 }
1503
1504 return current;
1505}
1506
Arthur Heymans9368cf92023-04-25 16:07:49 +02001507static void acpi_create_facs(acpi_facs_t *facs)
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +00001508{
Uwe Hermann622824c2010-11-19 15:14:42 +00001509 memset((void *)facs, 0, sizeof(acpi_facs_t));
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +00001510
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001511 memcpy(facs->signature, "FACS", 4);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +00001512 facs->length = sizeof(acpi_facs_t);
1513 facs->hardware_signature = 0;
1514 facs->firmware_waking_vector = 0;
1515 facs->global_lock = 0;
1516 facs->flags = 0;
1517 facs->x_firmware_waking_vector_l = 0;
1518 facs->x_firmware_waking_vector_h = 0;
Marc Jones93a51762018-08-22 18:57:24 -06001519 facs->version = get_acpi_table_revision(FACS);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +00001520}
Stefan Reinauer777224c2005-01-19 14:06:41 +00001521
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001522static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +00001523{
Uwe Hermann622824c2010-11-19 15:14:42 +00001524 acpi_header_t *header = &(rsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001525
John Zhao2ba303e2019-05-28 16:48:14 -07001526 if (!header)
1527 return;
1528
Uwe Hermann622824c2010-11-19 15:14:42 +00001529 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001530 memcpy(header->signature, "RSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001531 memcpy(header->oem_id, oem_id, 6);
1532 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +00001533 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001534
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001535 header->asl_compiler_revision = asl_revision;
Stefan Reinauer688b3852004-01-28 16:56:14 +00001536 header->length = sizeof(acpi_rsdt_t);
Marc Jones93a51762018-08-22 18:57:24 -06001537 header->revision = get_acpi_table_revision(RSDT);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001538
Uwe Hermann622824c2010-11-19 15:14:42 +00001539 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauer688b3852004-01-28 16:56:14 +00001540
Uwe Hermann622824c2010-11-19 15:14:42 +00001541 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001542 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +00001543}
1544
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001545static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +00001546{
Uwe Hermann622824c2010-11-19 15:14:42 +00001547 acpi_header_t *header = &(xsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001548
John Zhao2ba303e2019-05-28 16:48:14 -07001549 if (!header)
1550 return;
1551
Uwe Hermann622824c2010-11-19 15:14:42 +00001552 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001553 memcpy(header->signature, "XSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001554 memcpy(header->oem_id, oem_id, 6);
1555 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001556 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001557
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001558 header->asl_compiler_revision = asl_revision;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001559 header->length = sizeof(acpi_xsdt_t);
Marc Jones93a51762018-08-22 18:57:24 -06001560 header->revision = get_acpi_table_revision(XSDT);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001561
Uwe Hermann622824c2010-11-19 15:14:42 +00001562 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001563
Uwe Hermann622824c2010-11-19 15:14:42 +00001564 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001565 header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t));
1566}
1567
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001568static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt,
1569 acpi_xsdt_t *xsdt, char *oem_id)
Stefan Reinauer688b3852004-01-28 16:56:14 +00001570{
Stefan Reinauerd18faac2009-11-05 18:06:43 +00001571 memset(rsdp, 0, sizeof(acpi_rsdp_t));
Uwe Hermann622824c2010-11-19 15:14:42 +00001572
Stefan Reinauer688b3852004-01-28 16:56:14 +00001573 memcpy(rsdp->signature, RSDP_SIG, 8);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001574 memcpy(rsdp->oem_id, oem_id, 6);
Uwe Hermann622824c2010-11-19 15:14:42 +00001575
1576 rsdp->length = sizeof(acpi_rsdp_t);
Stefan Reinauerdefee172015-06-18 01:11:19 -07001577 rsdp->rsdt_address = (uintptr_t)rsdt;
Uwe Hermann622824c2010-11-19 15:14:42 +00001578
1579 /*
1580 * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2.
1581 *
1582 * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
1583 * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
1584 * revision 0).
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001585 */
1586 if (xsdt == NULL) {
Uwe Hermann622824c2010-11-19 15:14:42 +00001587 rsdp->revision = 0;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001588 } else {
Stefan Reinauerdefee172015-06-18 01:11:19 -07001589 rsdp->xsdt_address = (u64)(uintptr_t)xsdt;
Marc Jones93a51762018-08-22 18:57:24 -06001590 rsdp->revision = get_acpi_table_revision(RSDP);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001591 }
Uwe Hermann622824c2010-11-19 15:14:42 +00001592
1593 /* Calculate checksums. */
1594 rsdp->checksum = acpi_checksum((void *)rsdp, 20);
1595 rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +00001596}
1597
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001598unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1599 acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len)
zbaocaf494c82012-04-13 13:57:14 +08001600{
1601 acpi_header_t *header = &(hest->header);
1602 acpi_hest_hen_t *hen;
1603 void *pos;
1604 u16 len;
1605
1606 pos = esd;
1607 memset(pos, 0, sizeof(acpi_hest_esd_t));
1608 len = 0;
1609 esd->type = type; /* MCE */
1610 esd->source_id = hest->error_source_count;
1611 esd->flags = 0; /* FIRMWARE_FIRST */
1612 esd->enabled = 1;
1613 esd->prealloc_erecords = 1;
1614 esd->max_section_per_record = 0x1;
1615
1616 len += sizeof(acpi_hest_esd_t);
1617 pos = esd + 1;
1618
1619 switch (type) {
1620 case 0: /* MCE */
1621 break;
1622 case 1: /* CMC */
Elyes Haouas3141fbad2022-11-18 15:22:32 +01001623 hen = (acpi_hest_hen_t *)(pos);
zbaocaf494c82012-04-13 13:57:14 +08001624 memset(pos, 0, sizeof(acpi_hest_hen_t));
1625 hen->type = 3; /* SCI? */
1626 hen->length = sizeof(acpi_hest_hen_t);
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001627 hen->conf_we = 0; /* Configuration Write Enable. */
zbaocaf494c82012-04-13 13:57:14 +08001628 hen->poll_interval = 0;
1629 hen->vector = 0;
1630 hen->sw2poll_threshold_val = 0;
1631 hen->sw2poll_threshold_win = 0;
1632 hen->error_threshold_val = 0;
1633 hen->error_threshold_win = 0;
1634 len += sizeof(acpi_hest_hen_t);
1635 pos = hen + 1;
1636 break;
1637 case 2: /* NMI */
1638 case 6: /* AER Root Port */
1639 case 7: /* AER Endpoint */
1640 case 8: /* AER Bridge */
1641 case 9: /* Generic Hardware Error Source. */
1642 /* TODO: */
1643 break;
1644 default:
1645 printk(BIOS_DEBUG, "Invalid type of Error Source.");
1646 break;
1647 }
Lee Leahy024b13d2017-03-16 13:41:11 -07001648 hest->error_source_count++;
zbaocaf494c82012-04-13 13:57:14 +08001649
1650 memcpy(pos, data, data_len);
1651 len += data_len;
John Zhao2ba303e2019-05-28 16:48:14 -07001652 if (header)
1653 header->length += len;
zbaocaf494c82012-04-13 13:57:14 +08001654
1655 return len;
1656}
1657
1658/* ACPI 4.0 */
Vladimir Serbinenko807127f2014-11-09 13:36:18 +01001659void acpi_write_hest(acpi_hest_t *hest,
1660 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest))
zbaocaf494c82012-04-13 13:57:14 +08001661{
1662 acpi_header_t *header = &(hest->header);
1663
1664 memset(hest, 0, sizeof(acpi_hest_t));
1665
John Zhao2ba303e2019-05-28 16:48:14 -07001666 if (!header)
1667 return;
1668
zbaocaf494c82012-04-13 13:57:14 +08001669 memcpy(header->signature, "HEST", 4);
1670 memcpy(header->oem_id, OEM_ID, 6);
1671 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1672 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001673 header->asl_compiler_revision = asl_revision;
zbaocaf494c82012-04-13 13:57:14 +08001674 header->length += sizeof(acpi_hest_t);
Marc Jones93a51762018-08-22 18:57:24 -06001675 header->revision = get_acpi_table_revision(HEST);
zbaocaf494c82012-04-13 13:57:14 +08001676
1677 acpi_fill_hest(hest);
1678
1679 /* Calculate checksums. */
1680 header->checksum = acpi_checksum((void *)hest, header->length);
1681}
1682
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001683/* ACPI 3.0b */
Arthur Heymans9368cf92023-04-25 16:07:49 +02001684static void acpi_write_bert(acpi_bert_t *bert, uintptr_t region, size_t length)
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001685{
1686 acpi_header_t *header = &(bert->header);
1687
1688 memset(bert, 0, sizeof(acpi_bert_t));
1689
John Zhao2ba303e2019-05-28 16:48:14 -07001690 if (!header)
1691 return;
1692
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001693 memcpy(header->signature, "BERT", 4);
1694 memcpy(header->oem_id, OEM_ID, 6);
1695 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1696 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001697 header->asl_compiler_revision = asl_revision;
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001698 header->length += sizeof(acpi_bert_t);
1699 header->revision = get_acpi_table_revision(BERT);
1700
1701 bert->error_region = region;
1702 bert->region_length = length;
1703
1704 /* Calculate checksums. */
1705 header->checksum = acpi_checksum((void *)bert, header->length);
1706}
1707
Angel Pons79572e42020-07-13 00:17:43 +02001708__weak void arch_fill_fadt(acpi_fadt_t *fadt) { }
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001709__weak void soc_fill_fadt(acpi_fadt_t *fadt) { }
Kyösti Mälkki02fd15d2020-06-02 03:34:43 +03001710__weak void mainboard_fill_fadt(acpi_fadt_t *fadt) { }
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001711
Arthur Heymans9368cf92023-04-25 16:07:49 +02001712static void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt)
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001713{
1714 acpi_header_t *header = &(fadt->header);
1715
Elyes Haouas3141fbad2022-11-18 15:22:32 +01001716 memset((void *)fadt, 0, sizeof(acpi_fadt_t));
John Zhao2ba303e2019-05-28 16:48:14 -07001717
1718 if (!header)
1719 return;
1720
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001721 memcpy(header->signature, "FACP", 4);
1722 header->length = sizeof(acpi_fadt_t);
Marc Jones93a51762018-08-22 18:57:24 -06001723 header->revision = get_acpi_table_revision(FADT);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001724 memcpy(header->oem_id, OEM_ID, 6);
1725 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1726 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUAS26071aa2019-02-15 08:21:33 +01001727 header->asl_compiler_revision = asl_revision;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001728
Elyes Haouas532e0432022-02-21 18:13:58 +01001729 fadt->FADT_MinorVersion = get_acpi_fadt_minor_version();
Elyes Haouas3141fbad2022-11-18 15:22:32 +01001730 fadt->firmware_ctrl = (unsigned long)facs;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001731 fadt->x_firmware_ctl_l = (unsigned long)facs;
1732 fadt->x_firmware_ctl_h = 0;
Kyösti Mälkkid4acee82020-06-03 07:20:55 +03001733
Elyes Haouas3141fbad2022-11-18 15:22:32 +01001734 fadt->dsdt = (unsigned long)dsdt;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001735 fadt->x_dsdt_l = (unsigned long)dsdt;
1736 fadt->x_dsdt_h = 0;
1737
Kyösti Mälkkid4acee82020-06-03 07:20:55 +03001738 /* should be 0 ACPI 3.0 */
1739 fadt->reserved = 0;
1740
Kyösti Mälkki67c48a32023-04-14 10:20:03 +03001741 /* P_LVLx latencies are not used as CPU _CST will override them. */
1742 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
1743 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
1744
Kyösti Mälkki9ff97972023-04-14 15:37:27 +03001745 /* Use CPU _PTC instead to provide P_CNT details. */
1746 fadt->duty_offset = 0;
1747 fadt->duty_width = 0;
1748
Kyösti Mälkkie0d38682020-06-07 12:01:58 +03001749 fadt->preferred_pm_profile = acpi_get_preferred_pm_profile();
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001750
Kyösti Mälkkie742b682023-04-10 17:03:32 +03001751 fadt->sci_int = acpi_sci_int();
1752
Angel Pons79572e42020-07-13 00:17:43 +02001753 arch_fill_fadt(fadt);
1754
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +02001755 acpi_fill_fadt(fadt);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001756
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001757 soc_fill_fadt(fadt);
Kyösti Mälkki02fd15d2020-06-02 03:34:43 +03001758 mainboard_fill_fadt(fadt);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001759
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001760 header->checksum =
Elyes Haouas3141fbad2022-11-18 15:22:32 +01001761 acpi_checksum((void *)fadt, header->length);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001762}
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001763
Arthur Heymans9368cf92023-04-25 16:07:49 +02001764static void acpi_create_lpit(acpi_lpit_t *lpit)
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001765{
1766 acpi_header_t *header = &(lpit->header);
1767 unsigned long current = (unsigned long)lpit + sizeof(acpi_lpit_t);
1768
1769 memset((void *)lpit, 0, sizeof(acpi_lpit_t));
1770
1771 if (!header)
1772 return;
1773
1774 /* Fill out header fields. */
1775 memcpy(header->signature, "LPIT", 4);
1776 memcpy(header->oem_id, OEM_ID, 6);
1777 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1778 memcpy(header->asl_compiler_id, ASLC, 4);
1779
1780 header->asl_compiler_revision = asl_revision;
1781 header->revision = get_acpi_table_revision(LPIT);
1782 header->oem_revision = 42;
1783 header->length = sizeof(acpi_lpit_t);
1784
1785 current = acpi_fill_lpit(current);
1786
1787 /* (Re)calculate length and checksum. */
1788 header->length = current - (unsigned long)lpit;
1789 header->checksum = acpi_checksum((void *)lpit, header->length);
1790}
1791
1792unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid)
1793{
1794 memset(lpi_desc, 0, sizeof(acpi_lpi_desc_ncst_t));
1795 lpi_desc->header.length = sizeof(acpi_lpi_desc_ncst_t);
1796 lpi_desc->header.type = ACPI_LPI_DESC_TYPE_NATIVE_CSTATE;
1797 lpi_desc->header.uid = uid;
1798
1799 return lpi_desc->header.length;
1800}
1801
Arthur Heymans90464072023-06-07 12:53:50 +02001802static uint8_t acpi_spcr_type(void)
1803{
1804 /* 16550-compatible with parameters defined in Generic Address Structure */
1805 if (CONFIG(DRIVERS_UART_8250IO) || CONFIG(DRIVERS_UART_8250MEM))
1806 return 0x12;
1807 if (CONFIG(DRIVERS_UART_PL011))
1808 return 0x3;
1809
1810 printk(BIOS_ERR, "%s: unknown serial type\n", __func__);
1811 return 0xff;
1812}
1813
1814static void acpi_create_spcr(acpi_spcr_t *spcr)
1815{
1816 acpi_header_t *header = &(spcr->header);
1817 struct lb_serial serial;
1818
1819 /* The caller checks the header size, so call this first */
1820 memset((void *)spcr, 0, sizeof(acpi_spcr_t));
1821
1822 if (!CONFIG(CONSOLE_SERIAL))
1823 return;
1824
1825 if (fill_lb_serial(&serial) != CB_SUCCESS)
1826 return;
1827
1828 memcpy(header->signature, "SPCR", 4);
1829 header->length = sizeof(acpi_spcr_t);
1830 header->revision = get_acpi_table_revision(SPCR);
1831 memcpy(header->oem_id, OEM_ID, 6);
1832 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1833 memcpy(header->asl_compiler_id, ASLC, 4);
1834 header->asl_compiler_revision = asl_revision;
1835
1836 spcr->interface_type = acpi_spcr_type();
1837 assert(serial.type == LB_SERIAL_TYPE_IO_MAPPED
1838 || serial.type == LB_SERIAL_TYPE_MEMORY_MAPPED);
1839 spcr->base_address.space_id = serial.type == LB_SERIAL_TYPE_IO_MAPPED ?
1840 ACPI_ADDRESS_SPACE_IO : ACPI_ADDRESS_SPACE_MEMORY;
1841 spcr->base_address.bit_width = serial.regwidth * 8;
1842 spcr->base_address.bit_offset = 0;
1843 switch (serial.regwidth) {
1844 case 1:
1845 spcr->base_address.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
1846 break;
1847 case 2:
1848 spcr->base_address.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
1849 break;
1850 case 4:
1851 spcr->base_address.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
1852 break;
1853 default:
1854 printk(BIOS_ERR, "%s, Invalid serial regwidth\n", __func__);
1855 }
1856
1857 spcr->base_address.addrl = serial.baseaddr;
1858 spcr->base_address.addrh = 0;
1859 spcr->interrupt_type = 0;
1860 spcr->irq = 0;
1861 spcr->configured_baudrate = 0; /* Have the OS use whatever is currently set */
1862 spcr->parity = 0;
1863 spcr->stop_bits = 1;
1864 spcr->flow_control = 0;
1865 spcr->terminal_type = 2; /* 2 = VT-UTF8 */
1866 spcr->language = 0;
1867 spcr->pci_did = 0xffff;
1868 spcr->pci_vid = 0xffff;
1869}
1870
Aaron Durbin64031672018-04-21 14:45:32 -06001871unsigned long __weak fw_cfg_acpi_tables(unsigned long start)
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001872{
1873 return 0;
1874}
1875
Raul E Rangel6b446b92021-11-19 11:38:35 -07001876void preload_acpi_dsdt(void)
1877{
1878 const char *file = CONFIG_CBFS_PREFIX "/dsdt.aml";
1879
1880 if (!CONFIG(CBFS_PRELOAD))
1881 return;
1882
1883 printk(BIOS_DEBUG, "Preloading %s\n", file);
1884 cbfs_preload(file);
1885}
1886
Arthur Heymans2e7e2d92022-03-03 22:28:27 +01001887static uintptr_t coreboot_rsdp;
1888
1889uintptr_t get_coreboot_rsdp(void)
1890{
1891 return coreboot_rsdp;
1892}
1893
Arthur Heymans0ad766c2023-06-07 10:45:59 +02001894static void acpixtract_compatible_hexdump(const void *memory, size_t length)
1895{
1896 size_t i, j;
1897 uint8_t *line;
1898 size_t num_bytes;
1899
1900 for (i = 0; i < length; i += 16) {
1901 num_bytes = MIN(length - i, 16);
1902 line = ((uint8_t *)memory) + i;
1903
1904 printk(BIOS_SPEW, " %04zX:", i);
1905 for (j = 0; j < num_bytes; j++)
1906 printk(BIOS_SPEW, " %02x", line[j]);
1907 for (; j < 16; j++)
1908 printk(BIOS_SPEW, " ");
1909 printk(BIOS_SPEW, " ");
1910 for (j = 0; j < num_bytes; j++)
1911 printk(BIOS_SPEW, "%c",
1912 isprint(line[j]) ? line[j] : '.');
1913 printk(BIOS_SPEW, "\n");
1914 }
1915}
1916
1917static void acpidump_print(void *table_ptr)
1918{
1919 const acpi_header_t *header = (acpi_header_t *)table_ptr;
1920 const size_t table_size = header->length;
1921 printk(BIOS_SPEW, "%.4s @ 0x0000000000000000\n", header->signature);
1922 acpixtract_compatible_hexdump(table_ptr, table_size);
1923 printk(BIOS_SPEW, "\n");
1924}
1925
Arthur Heymans7ebebf72023-06-17 14:08:46 +02001926unsigned long write_acpi_tables(const unsigned long start)
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001927{
1928 unsigned long current;
1929 acpi_rsdp_t *rsdp;
Arthur Heymans0ad766c2023-06-07 10:45:59 +02001930 acpi_rsdt_t *rsdt = NULL;
1931 acpi_xsdt_t *xsdt = NULL;
1932 acpi_fadt_t *fadt = NULL;
1933 acpi_facs_t *facs = NULL;
1934 acpi_header_t *slic_file, *slic = NULL;
1935 acpi_header_t *ssdt = NULL;
1936 acpi_header_t *dsdt_file, *dsdt = NULL;
1937 acpi_mcfg_t *mcfg = NULL;
1938 acpi_tcpa_t *tcpa = NULL;
1939 acpi_tpm2_t *tpm2 = NULL;
1940 acpi_madt_t *madt = NULL;
1941 acpi_lpit_t *lpit = NULL;
1942 acpi_bert_t *bert = NULL;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +11001943 struct device *dev;
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001944 unsigned long fw;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001945 size_t slic_size, dsdt_size;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001946 char oem_id[6], oem_table_id[8];
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001947
1948 current = start;
1949
1950 /* Align ACPI tables to 16byte */
Aaron Durbin07a1b282015-12-10 17:07:38 -06001951 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001952
Patrick Rudolphcfe08ff2019-09-10 15:40:47 +02001953 /* Special case for qemu */
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001954 fw = fw_cfg_acpi_tables(current);
Patrick Rudolphcfe08ff2019-09-10 15:40:47 +02001955 if (fw) {
1956 rsdp = NULL;
1957 /* Find RSDP. */
1958 for (void *p = (void *)current; p < (void *)fw; p += 16) {
1959 if (valid_rsdp((acpi_rsdp_t *)p)) {
1960 rsdp = p;
Bin Mengf3027b82023-05-09 15:21:49 +08001961 coreboot_rsdp = (uintptr_t)rsdp;
Patrick Rudolphcfe08ff2019-09-10 15:40:47 +02001962 break;
1963 }
1964 }
1965 if (!rsdp)
1966 return fw;
1967
1968 /* Add BOOT0000 for Linux google firmware driver */
1969 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
1970 ssdt = (acpi_header_t *)fw;
1971 current = (unsigned long)ssdt + sizeof(acpi_header_t);
1972
1973 memset((void *)ssdt, 0, sizeof(acpi_header_t));
1974
1975 memcpy(&ssdt->signature, "SSDT", 4);
1976 ssdt->revision = get_acpi_table_revision(SSDT);
1977 memcpy(&ssdt->oem_id, OEM_ID, 6);
1978 memcpy(&ssdt->oem_table_id, oem_table_id, 8);
1979 ssdt->oem_revision = 42;
1980 memcpy(&ssdt->asl_compiler_id, ASLC, 4);
1981 ssdt->asl_compiler_revision = asl_revision;
1982 ssdt->length = sizeof(acpi_header_t);
1983
Elyes Haouas3141fbad2022-11-18 15:22:32 +01001984 acpigen_set_current((char *)current);
Patrick Rudolphcfe08ff2019-09-10 15:40:47 +02001985
1986 /* Write object to declare coreboot tables */
1987 acpi_ssdt_write_cbtable();
1988
1989 /* (Re)calculate length and checksum. */
1990 ssdt->length = current - (unsigned long)ssdt;
1991 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
1992
1993 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
1994
1995 acpi_add_table(rsdp, ssdt);
1996
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001997 return fw;
Patrick Rudolphcfe08ff2019-09-10 15:40:47 +02001998 }
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001999
Julius Werner834b3ec2020-03-04 16:52:08 -08002000 dsdt_file = cbfs_map(CONFIG_CBFS_PREFIX "/dsdt.aml", &dsdt_size);
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02002001 if (!dsdt_file) {
2002 printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n");
Arthur Heymans0600aa62023-06-17 14:13:54 +02002003 return start;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02002004 }
2005
2006 if (dsdt_file->length > dsdt_size
Elyes HAOUAS7d87e762016-10-03 22:11:07 +02002007 || dsdt_file->length < sizeof(acpi_header_t)
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02002008 || memcmp(dsdt_file->signature, "DSDT", 4) != 0) {
2009 printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n");
Grzegorz Bernacki042ac352023-04-21 13:19:58 +00002010 cbfs_unmap(dsdt_file);
Arthur Heymans0600aa62023-06-17 14:13:54 +02002011 return start;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02002012 }
2013
Julius Werner834b3ec2020-03-04 16:52:08 -08002014 slic_file = cbfs_map(CONFIG_CBFS_PREFIX "/slic", &slic_size);
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +02002015 if (slic_file
2016 && (slic_file->length > slic_size
Elyes HAOUAS7d87e762016-10-03 22:11:07 +02002017 || slic_file->length < sizeof(acpi_header_t)
Benjamin Doron2b2dc0c2020-09-12 02:55:57 +00002018 || (memcmp(slic_file->signature, "SLIC", 4) != 0
2019 && memcmp(slic_file->signature, "MSDM", 4) != 0))) {
Grzegorz Bernacki042ac352023-04-21 13:19:58 +00002020 cbfs_unmap(slic_file);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01002021 slic_file = 0;
2022 }
2023
2024 if (slic_file) {
2025 memcpy(oem_id, slic_file->oem_id, 6);
2026 memcpy(oem_table_id, slic_file->oem_table_id, 8);
2027 } else {
2028 memcpy(oem_id, OEM_ID, 6);
2029 memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8);
2030 }
2031
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002032 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
2033
2034 /* We need at least an RSDP and an RSDT Table */
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002035 rsdp = (acpi_rsdp_t *)current;
Arthur Heymans2e7e2d92022-03-03 22:28:27 +01002036 coreboot_rsdp = (uintptr_t)rsdp;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002037 current += sizeof(acpi_rsdp_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06002038 current = acpi_align_current(current);
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002039 rsdt = (acpi_rsdt_t *)current;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002040 current += sizeof(acpi_rsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06002041 current = acpi_align_current(current);
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002042 xsdt = (acpi_xsdt_t *)current;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002043 current += sizeof(acpi_xsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06002044 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002045
2046 /* clear all table memory */
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002047 memset((void *)start, 0, current - start);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002048
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01002049 acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id);
2050 acpi_write_rsdt(rsdt, oem_id, oem_table_id);
2051 acpi_write_xsdt(xsdt, oem_id, oem_table_id);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002052
2053 printk(BIOS_DEBUG, "ACPI: * FACS\n");
Felix Heldc4697122019-06-20 13:50:17 +02002054 current = ALIGN_UP(current, 64);
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002055 facs = (acpi_facs_t *)current;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002056 current += sizeof(acpi_facs_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06002057 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002058 acpi_create_facs(facs);
2059
2060 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002061 dsdt = (acpi_header_t *)current;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02002062 memcpy(dsdt, dsdt_file, sizeof(acpi_header_t));
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02002063 if (dsdt->length >= sizeof(acpi_header_t)) {
2064 current += sizeof(acpi_header_t);
2065
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002066 acpigen_set_current((char *)current);
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03002067
Kyösti Mälkki37eb24b2021-01-11 18:40:37 +02002068 if (CONFIG(ACPI_SOC_NVS))
2069 acpi_fill_gnvs();
Kyösti Mälkki3dc17922021-03-16 19:01:48 +02002070 if (CONFIG(CHROMEOS_NVS))
2071 acpi_fill_cnvs();
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03002072
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02002073 for (dev = all_devices; dev; dev = dev->next)
Nico Huber68680dd2020-03-31 17:34:52 +02002074 if (dev->ops && dev->ops->acpi_inject_dsdt)
2075 dev->ops->acpi_inject_dsdt(dev);
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002076 current = (unsigned long)acpigen_get_current();
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02002077 memcpy((char *)current,
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02002078 (char *)dsdt_file + sizeof(acpi_header_t),
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02002079 dsdt->length - sizeof(acpi_header_t));
2080 current += dsdt->length - sizeof(acpi_header_t);
2081
2082 /* (Re)calculate length and checksum. */
2083 dsdt->length = current - (unsigned long)dsdt;
2084 dsdt->checksum = 0;
2085 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
2086 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002087
Aaron Durbin07a1b282015-12-10 17:07:38 -06002088 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002089
2090 printk(BIOS_DEBUG, "ACPI: * FADT\n");
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002091 fadt = (acpi_fadt_t *)current;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002092 current += sizeof(acpi_fadt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06002093 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002094
2095 acpi_create_fadt(fadt, facs, dsdt);
2096 acpi_add_table(rsdp, fadt);
2097
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01002098 if (slic_file) {
2099 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
2100 slic = (acpi_header_t *)current;
2101 memcpy(slic, slic_file, slic_file->length);
2102 current += slic_file->length;
Aaron Durbin07a1b282015-12-10 17:07:38 -06002103 current = acpi_align_current(current);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01002104 acpi_add_table(rsdp, slic);
Grzegorz Bernacki042ac352023-04-21 13:19:58 +00002105 cbfs_unmap(slic_file);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01002106 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002107
Grzegorz Bernacki042ac352023-04-21 13:19:58 +00002108 /*
2109 * cbfs_unmap() uses mem_pool_free() which works correctly only
2110 * if freeing is done in reverse order than memory allocation.
2111 * This is why unmapping of dsdt_file must be done after
2112 * unmapping slic file.
2113 */
2114 cbfs_unmap(dsdt_file);
2115
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002116 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
2117 ssdt = (acpi_header_t *)current;
2118 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +02002119 if (ssdt->length > sizeof(acpi_header_t)) {
2120 current += ssdt->length;
2121 acpi_add_table(rsdp, ssdt);
Aaron Durbin07a1b282015-12-10 17:07:38 -06002122 current = acpi_align_current(current);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +02002123 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002124
2125 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002126 mcfg = (acpi_mcfg_t *)current;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002127 acpi_create_mcfg(mcfg);
2128 if (mcfg->header.length > sizeof(acpi_mcfg_t)) {
2129 current += mcfg->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -06002130 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002131 acpi_add_table(rsdp, mcfg);
2132 }
2133
Julius Wernercd49cce2019-03-05 16:53:33 -08002134 if (CONFIG(TPM1)) {
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02002135 printk(BIOS_DEBUG, "ACPI: * TCPA\n");
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002136 tcpa = (acpi_tcpa_t *)current;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02002137 acpi_create_tcpa(tcpa);
2138 if (tcpa->header.length >= sizeof(acpi_tcpa_t)) {
2139 current += tcpa->header.length;
2140 current = acpi_align_current(current);
2141 acpi_add_table(rsdp, tcpa);
2142 }
2143 }
2144
Julius Wernercd49cce2019-03-05 16:53:33 -08002145 if (CONFIG(TPM2)) {
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02002146 printk(BIOS_DEBUG, "ACPI: * TPM2\n");
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002147 tpm2 = (acpi_tpm2_t *)current;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02002148 acpi_create_tpm2(tpm2);
2149 if (tpm2->header.length >= sizeof(acpi_tpm2_t)) {
2150 current += tpm2->header.length;
2151 current = acpi_align_current(current);
2152 acpi_add_table(rsdp, tpm2);
2153 }
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +02002154 }
2155
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01002156 if (CONFIG(ACPI_LPIT)) {
2157 printk(BIOS_DEBUG, "ACPI: * LPIT\n");
2158
2159 lpit = (acpi_lpit_t *)current;
2160 acpi_create_lpit(lpit);
2161 if (lpit->header.length >= sizeof(acpi_lpit_t)) {
2162 current += lpit->header.length;
2163 current = acpi_align_current(current);
2164 acpi_add_table(rsdp, lpit);
2165 }
2166 }
2167
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002168 printk(BIOS_DEBUG, "ACPI: * MADT\n");
2169
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002170 madt = (acpi_madt_t *)current;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002171 acpi_create_madt(madt);
2172 if (madt->header.length > sizeof(acpi_madt_t)) {
Lee Leahy024b13d2017-03-16 13:41:11 -07002173 current += madt->header.length;
2174 acpi_add_table(rsdp, madt);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002175 }
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01002176
Aaron Durbin07a1b282015-12-10 17:07:38 -06002177 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002178
Felix Heldfba479262021-05-28 16:11:43 +02002179 if (CONFIG(ACPI_BERT)) {
Francois Toguo522e0db2021-01-21 09:55:19 -08002180 void *region;
2181 size_t size;
Elyes Haouas3141fbad2022-11-18 15:22:32 +01002182 bert = (acpi_bert_t *)current;
Felix Heldfba479262021-05-28 16:11:43 +02002183 if (acpi_soc_get_bert_region(&region, &size) == CB_SUCCESS) {
2184 printk(BIOS_DEBUG, "ACPI: * BERT\n");
2185 acpi_write_bert(bert, (uintptr_t)region, size);
2186 if (bert->header.length >= sizeof(acpi_bert_t)) {
2187 current += bert->header.length;
2188 acpi_add_table(rsdp, bert);
2189 }
2190 current = acpi_align_current(current);
Francois Toguo522e0db2021-01-21 09:55:19 -08002191 }
Francois Toguo522e0db2021-01-21 09:55:19 -08002192 }
2193
Arthur Heymans90464072023-06-07 12:53:50 +02002194 printk(BIOS_DEBUG, "ACPI: * SPCR\n");
2195 acpi_spcr_t * const spcr = (acpi_spcr_t *)current;
2196 acpi_create_spcr(spcr);
2197 if (spcr->header.length >= sizeof(acpi_spcr_t)) {
2198 current += spcr->header.length;
2199 acpi_add_table(rsdp, spcr);
2200 }
2201 current = acpi_align_current(current);
2202
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002203 printk(BIOS_DEBUG, "current = %lx\n", current);
2204
2205 for (dev = all_devices; dev; dev = dev->next) {
2206 if (dev->ops && dev->ops->write_acpi_tables) {
Lee Leahy6f80ccc2017-03-16 15:18:22 -07002207 current = dev->ops->write_acpi_tables(dev, current,
2208 rsdp);
Aaron Durbin07a1b282015-12-10 17:07:38 -06002209 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002210 }
2211 }
2212
2213 printk(BIOS_INFO, "ACPI: done.\n");
Arthur Heymans0ad766c2023-06-07 10:45:59 +02002214
2215 if (CONFIG(DEBUG_ACPICA_COMPATIBLE)) {
2216 printk(BIOS_DEBUG, "Printing ACPI tables in ACPICA compatible format\n");
Arthur Heymans3e523b42023-06-15 17:04:16 +02002217 for (size_t i = 0; xsdt->entry[i] != 0; i++) {
2218 acpidump_print((void *)(uintptr_t)xsdt->entry[i]);
Arthur Heymans0ad766c2023-06-07 10:45:59 +02002219 }
2220 printk(BIOS_DEBUG, "Done printing ACPI tables in ACPICA compatible format\n");
2221 }
2222
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002223 return current;
2224}
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02002225
Rudolf Marek33cafe52009-04-13 18:07:02 +00002226static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
2227{
2228 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
2229 return NULL;
2230
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00002231 printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp);
Rudolf Marek33cafe52009-04-13 18:07:02 +00002232
2233 if (acpi_checksum((void *)rsdp, 20) != 0)
2234 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00002235 printk(BIOS_DEBUG, "Checksum 1 passed\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00002236
2237 if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
2238 rsdp->length) != 0))
2239 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00002240 printk(BIOS_DEBUG, "Checksum 2 passed all OK\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00002241
2242 return rsdp;
2243}
2244
Rudolf Marek33cafe52009-04-13 18:07:02 +00002245void *acpi_find_wakeup_vector(void)
2246{
2247 char *p, *end;
Rudolf Marek33cafe52009-04-13 18:07:02 +00002248 acpi_rsdt_t *rsdt;
2249 acpi_facs_t *facs;
Martin Rothc5f49262012-12-14 19:17:55 -07002250 acpi_fadt_t *fadt = NULL;
Kyösti Mälkki072d436b2016-06-17 08:44:40 +03002251 acpi_rsdp_t *rsdp = NULL;
Uwe Hermann622824c2010-11-19 15:14:42 +00002252 void *wake_vec;
Rudolf Marek33cafe52009-04-13 18:07:02 +00002253 int i;
2254
Kyösti Mälkkib8c7ea02020-11-17 16:41:38 +02002255 if (!acpi_is_wakeup_s3())
Rudolf Marek33cafe52009-04-13 18:07:02 +00002256 return NULL;
2257
Uwe Hermann622824c2010-11-19 15:14:42 +00002258 printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00002259
Uwe Hermann622824c2010-11-19 15:14:42 +00002260 /* Find RSDP. */
2261 for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) {
Lee Leahy0b5678f2017-03-16 16:01:40 -07002262 rsdp = valid_rsdp((acpi_rsdp_t *)p);
2263 if (rsdp)
Rudolf Marek33cafe52009-04-13 18:07:02 +00002264 break;
2265 }
2266
Angel Pons98a68ad2018-11-04 12:25:25 +01002267 if (rsdp == NULL) {
2268 printk(BIOS_ALERT,
2269 "No RSDP found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00002270 return NULL;
Angel Pons98a68ad2018-11-04 12:25:25 +01002271 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00002272
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00002273 printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp);
Stefan Reinauer71a30182015-07-30 16:28:13 -07002274 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauer14e22772010-04-27 06:56:47 +00002275
Uwe Hermann622824c2010-11-19 15:14:42 +00002276 end = (char *)rsdt + rsdt->header.length;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00002277 printk(BIOS_DEBUG, "RSDT found at %p ends at %p\n", rsdt, end);
Rudolf Marek33cafe52009-04-13 18:07:02 +00002278
Uwe Hermann622824c2010-11-19 15:14:42 +00002279 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
Stefan Reinauer71a30182015-07-30 16:28:13 -07002280 fadt = (acpi_fadt_t *)(uintptr_t)rsdt->entry[i];
Stefan Reinauercdfe3762009-07-21 22:15:43 +00002281 if (strncmp((char *)fadt, "FACP", 4) == 0)
Rudolf Marek33cafe52009-04-13 18:07:02 +00002282 break;
2283 fadt = NULL;
2284 }
2285
Angel Pons98a68ad2018-11-04 12:25:25 +01002286 if (fadt == NULL) {
2287 printk(BIOS_ALERT,
2288 "No FADT found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00002289 return NULL;
Angel Pons98a68ad2018-11-04 12:25:25 +01002290 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00002291
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00002292 printk(BIOS_DEBUG, "FADT found at %p\n", fadt);
Stefan Reinauer71a30182015-07-30 16:28:13 -07002293 facs = (acpi_facs_t *)(uintptr_t)fadt->firmware_ctrl;
Rudolf Marek33cafe52009-04-13 18:07:02 +00002294
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00002295 if (facs == NULL) {
Angel Pons98a68ad2018-11-04 12:25:25 +01002296 printk(BIOS_ALERT,
2297 "No FACS found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00002298 return NULL;
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00002299 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00002300
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00002301 printk(BIOS_DEBUG, "FACS found at %p\n", facs);
Stefan Reinauer71a30182015-07-30 16:28:13 -07002302 wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00002303 printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec);
Uwe Hermann622824c2010-11-19 15:14:42 +00002304
Rudolf Marek33cafe52009-04-13 18:07:02 +00002305 return wake_vec;
2306}
2307
Aaron Durbin64031672018-04-21 14:45:32 -06002308__weak int acpi_get_gpe(int gpe)
Duncan Laurie1f6e6812016-09-19 12:04:19 -07002309{
2310 return -1; /* implemented by SOC */
2311}
Marc Jones93a51762018-08-22 18:57:24 -06002312
Elyes Haouas8b950f42022-02-16 12:08:16 +01002313u8 get_acpi_fadt_minor_version(void)
2314{
2315 return ACPI_FADT_MINOR_VERSION_0;
2316}
2317
Marc Jones93a51762018-08-22 18:57:24 -06002318int get_acpi_table_revision(enum acpi_tables table)
2319{
2320 switch (table) {
2321 case FADT:
Elyes Haouas8b950f42022-02-16 12:08:16 +01002322 return ACPI_FADT_REV_ACPI_6;
Elyes HAOUASf288b392018-11-11 15:22:30 +01002323 case MADT: /* ACPI 3.0: 2, ACPI 4.0/5.0: 3, ACPI 6.2b/6.3: 5 */
Patrick Rudolph56a3ef22020-03-24 17:29:49 +01002324 return 3;
Marc Jones93a51762018-08-22 18:57:24 -06002325 case MCFG:
2326 return 1;
2327 case TCPA:
2328 return 2;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02002329 case TPM2:
2330 return 4;
Martin Roth0949e732021-10-01 14:28:22 -06002331 case SSDT: /* ACPI 3.0 up to 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06002332 return 2;
Jonathan Zhanga3311b92022-12-01 17:13:41 -08002333 case SRAT: /* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 up to 6.4: 3 */
2334 return 3;
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07002335 case HMAT: /* ACPI 6.4: 2 */
2336 return 2;
Marc Jones93a51762018-08-22 18:57:24 -06002337 case DMAR:
2338 return 1;
Martin Roth0949e732021-10-01 14:28:22 -06002339 case SLIT: /* ACPI 2.0 up to 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06002340 return 1;
Patrick Rudolph9d98e5a2019-06-14 19:00:04 +02002341 case SPMI: /* IMPI 2.0 */
2342 return 5;
Marc Jones93a51762018-08-22 18:57:24 -06002343 case HPET: /* Currently 1. Table added in ACPI 2.0. */
2344 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01002345 case VFCT: /* ACPI 2.0/3.0/4.0: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06002346 return 1;
2347 case IVRS:
Jason Glenesk1916f892020-07-24 02:51:30 -07002348 return IVRS_FORMAT_MIXED;
Marc Jones93a51762018-08-22 18:57:24 -06002349 case DBG2:
2350 return 0;
Martin Roth0949e732021-10-01 14:28:22 -06002351 case FACS: /* ACPI 2.0/3.0: 1, ACPI 4.0 up to 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06002352 return 1;
Martin Roth0949e732021-10-01 14:28:22 -06002353 case RSDT: /* ACPI 1.0 up to 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06002354 return 1;
Martin Roth0949e732021-10-01 14:28:22 -06002355 case XSDT: /* ACPI 2.0 up to 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06002356 return 1;
Martin Roth0949e732021-10-01 14:28:22 -06002357 case RSDP: /* ACPI 2.0 up to 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06002358 return 2;
Rocky Phaguraeff07132021-01-10 15:42:50 -08002359 case EINJ:
2360 return 1;
Marc Jones93a51762018-08-22 18:57:24 -06002361 case HEST:
2362 return 1;
2363 case NHLT:
2364 return 5;
Marshall Dawson44705c62018-09-04 13:47:15 -06002365 case BERT:
2366 return 1;
Jonathan Zhanga3311b92022-12-01 17:13:41 -08002367 case CEDT: /* CXL 3.0 section 9.17.1 */
2368 return 1;
Jason Glenesk61624b22020-11-02 20:06:23 -08002369 case CRAT:
2370 return 1;
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01002371 case LPIT: /* ACPI 5.1 up to 6.3: 0 */
2372 return 0;
Arthur Heymans90464072023-06-07 12:53:50 +02002373 case SPCR:
2374 return 4;
Marc Jones93a51762018-08-22 18:57:24 -06002375 default:
2376 return -1;
2377 }
2378 return -1;
2379}