]> git.ipfire.org Git - thirdparty/qemu.git/blame - hw/arm/virt-acpi-build.c
Include migration/vmstate.h less
[thirdparty/qemu.git] / hw / arm / virt-acpi-build.c
CommitLineData
f5d8c8cd
SZ
1/* Support for generating ACPI tables and passing them to Guests
2 *
3 * ARM virt ACPI generation
4 *
5 * Copyright (C) 2008-2010 Kevin O'Connor <kevin@koconnor.net>
6 * Copyright (C) 2006 Fabrice Bellard
7 * Copyright (C) 2013 Red Hat Inc
8 *
9 * Author: Michael S. Tsirkin <mst@redhat.com>
10 *
11 * Copyright (c) 2015 HUAWEI TECHNOLOGIES CO.,LTD.
12 *
13 * Author: Shannon Zhao <zhaoshenglong@huawei.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, see <http://www.gnu.org/licenses/>.
27 */
28
12b16722 29#include "qemu/osdep.h"
da34e65c 30#include "qapi/error.h"
f5d8c8cd
SZ
31#include "qemu/bitmap.h"
32#include "trace.h"
33#include "qom/cpu.h"
fcf5ef2a 34#include "target/arm/cpu.h"
f5d8c8cd
SZ
35#include "hw/acpi/acpi-defs.h"
36#include "hw/acpi/acpi.h"
37#include "hw/nvram/fw_cfg.h"
38#include "hw/acpi/bios-linker-loader.h"
f5d8c8cd
SZ
39#include "hw/hw.h"
40#include "hw/acpi/aml-build.h"
82f76c67 41#include "hw/acpi/utils.h"
48cefd94 42#include "hw/acpi/pci.h"
84344884 43#include "hw/pci/pcie_host.h"
d4e5de1a 44#include "hw/pci/pci.h"
d05fdab4 45#include "hw/arm/virt.h"
2b302e1e 46#include "sysemu/numa.h"
71e8a915 47#include "sysemu/reset.h"
13e5c54d 48#include "kvm_arm.h"
d6454270 49#include "migration/vmstate.h"
f5d8c8cd 50
dfccd8cf 51#define ARM_SPI_BASE 32
ac6aa59a 52#define ACPI_POWER_BUTTON_DEVICE "PWRB"
dfccd8cf
SZ
53
54static void acpi_dsdt_add_cpus(Aml *scope, int smp_cpus)
55{
56 uint16_t i;
57
58 for (i = 0; i < smp_cpus; i++) {
f460be43 59 Aml *dev = aml_device("C%.03X", i);
dfccd8cf
SZ
60 aml_append(dev, aml_name_decl("_HID", aml_string("ACPI0007")));
61 aml_append(dev, aml_name_decl("_UID", aml_int(i)));
62 aml_append(scope, dev);
63 }
64}
65
66static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap,
45fcf539 67 uint32_t uart_irq)
dfccd8cf
SZ
68{
69 Aml *dev = aml_device("COM0");
70 aml_append(dev, aml_name_decl("_HID", aml_string("ARMH0011")));
71 aml_append(dev, aml_name_decl("_UID", aml_int(0)));
72
73 Aml *crs = aml_resource_template();
74 aml_append(crs, aml_memory32_fixed(uart_memmap->base,
75 uart_memmap->size, AML_READ_WRITE));
76 aml_append(crs,
77 aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
45fcf539 78 AML_EXCLUSIVE, &uart_irq, 1));
dfccd8cf 79 aml_append(dev, aml_name_decl("_CRS", crs));
f264d51d
AJ
80
81 /* The _ADR entry is used to link this device to the UART described
82 * in the SPCR table, i.e. SPCR.base_address.address == _ADR.
83 */
84 aml_append(dev, aml_name_decl("_ADR", aml_int(uart_memmap->base)));
85
dfccd8cf
SZ
86 aml_append(scope, dev);
87}
88
70bee80d
GS
89static void acpi_dsdt_add_fw_cfg(Aml *scope, const MemMapEntry *fw_cfg_memmap)
90{
91 Aml *dev = aml_device("FWCF");
92 aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
93 /* device present, functioning, decoding, not shown in UI */
94 aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
3b5c492b 95 aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
70bee80d
GS
96
97 Aml *crs = aml_resource_template();
98 aml_append(crs, aml_memory32_fixed(fw_cfg_memmap->base,
99 fw_cfg_memmap->size, AML_READ_WRITE));
100 aml_append(dev, aml_name_decl("_CRS", crs));
101 aml_append(scope, dev);
102}
103
dfccd8cf
SZ
104static void acpi_dsdt_add_flash(Aml *scope, const MemMapEntry *flash_memmap)
105{
106 Aml *dev, *crs;
107 hwaddr base = flash_memmap->base;
cd37aaf8 108 hwaddr size = flash_memmap->size / 2;
dfccd8cf
SZ
109
110 dev = aml_device("FLS0");
111 aml_append(dev, aml_name_decl("_HID", aml_string("LNRO0015")));
112 aml_append(dev, aml_name_decl("_UID", aml_int(0)));
113
114 crs = aml_resource_template();
115 aml_append(crs, aml_memory32_fixed(base, size, AML_READ_WRITE));
116 aml_append(dev, aml_name_decl("_CRS", crs));
117 aml_append(scope, dev);
118
119 dev = aml_device("FLS1");
120 aml_append(dev, aml_name_decl("_HID", aml_string("LNRO0015")));
121 aml_append(dev, aml_name_decl("_UID", aml_int(1)));
122 crs = aml_resource_template();
123 aml_append(crs, aml_memory32_fixed(base + size, size, AML_READ_WRITE));
124 aml_append(dev, aml_name_decl("_CRS", crs));
125 aml_append(scope, dev);
126}
127
128static void acpi_dsdt_add_virtio(Aml *scope,
129 const MemMapEntry *virtio_mmio_memmap,
45fcf539 130 uint32_t mmio_irq, int num)
dfccd8cf
SZ
131{
132 hwaddr base = virtio_mmio_memmap->base;
133 hwaddr size = virtio_mmio_memmap->size;
dfccd8cf
SZ
134 int i;
135
136 for (i = 0; i < num; i++) {
45fcf539 137 uint32_t irq = mmio_irq + i;
dfccd8cf
SZ
138 Aml *dev = aml_device("VR%02u", i);
139 aml_append(dev, aml_name_decl("_HID", aml_string("LNRO0005")));
140 aml_append(dev, aml_name_decl("_UID", aml_int(i)));
76266d99 141 aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
dfccd8cf
SZ
142
143 Aml *crs = aml_resource_template();
144 aml_append(crs, aml_memory32_fixed(base, size, AML_READ_WRITE));
145 aml_append(crs,
146 aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
45fcf539 147 AML_EXCLUSIVE, &irq, 1));
dfccd8cf
SZ
148 aml_append(dev, aml_name_decl("_CRS", crs));
149 aml_append(scope, dev);
150 base += size;
151 }
152}
153
45fcf539 154static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap,
601d626d 155 uint32_t irq, bool use_highmem, bool highmem_ecam)
d4e5de1a 156{
601d626d 157 int ecam_id = VIRT_ECAM_ID(highmem_ecam);
d4e5de1a
SZ
158 Aml *method, *crs, *ifctx, *UUID, *ifctx1, *elsectx, *buf;
159 int i, bus_no;
160 hwaddr base_mmio = memmap[VIRT_PCIE_MMIO].base;
161 hwaddr size_mmio = memmap[VIRT_PCIE_MMIO].size;
162 hwaddr base_pio = memmap[VIRT_PCIE_PIO].base;
163 hwaddr size_pio = memmap[VIRT_PCIE_PIO].size;
601d626d
EA
164 hwaddr base_ecam = memmap[ecam_id].base;
165 hwaddr size_ecam = memmap[ecam_id].size;
d4e5de1a
SZ
166 int nr_pcie_buses = size_ecam / PCIE_MMCFG_SIZE_MIN;
167
168 Aml *dev = aml_device("%s", "PCI0");
169 aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A08")));
170 aml_append(dev, aml_name_decl("_CID", aml_string("PNP0A03")));
171 aml_append(dev, aml_name_decl("_SEG", aml_int(0)));
172 aml_append(dev, aml_name_decl("_BBN", aml_int(0)));
173 aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
174 aml_append(dev, aml_name_decl("_UID", aml_string("PCI0")));
175 aml_append(dev, aml_name_decl("_STR", aml_unicode("PCIe 0 Device")));
bc64b96c 176 aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
d4e5de1a
SZ
177
178 /* Declare the PCI Routing Table. */
601d626d 179 Aml *rt_pkg = aml_varpackage(nr_pcie_buses * PCI_NUM_PINS);
d4e5de1a
SZ
180 for (bus_no = 0; bus_no < nr_pcie_buses; bus_no++) {
181 for (i = 0; i < PCI_NUM_PINS; i++) {
182 int gsi = (i + bus_no) % PCI_NUM_PINS;
183 Aml *pkg = aml_package(4);
184 aml_append(pkg, aml_int((bus_no << 16) | 0xFFFF));
185 aml_append(pkg, aml_int(i));
186 aml_append(pkg, aml_name("GSI%d", gsi));
187 aml_append(pkg, aml_int(0));
188 aml_append(rt_pkg, pkg);
189 }
190 }
191 aml_append(dev, aml_name_decl("_PRT", rt_pkg));
192
193 /* Create GSI link device */
194 for (i = 0; i < PCI_NUM_PINS; i++) {
45fcf539 195 uint32_t irqs = irq + i;
d4e5de1a
SZ
196 Aml *dev_gsi = aml_device("GSI%d", i);
197 aml_append(dev_gsi, aml_name_decl("_HID", aml_string("PNP0C0F")));
198 aml_append(dev_gsi, aml_name_decl("_UID", aml_int(0)));
199 crs = aml_resource_template();
200 aml_append(crs,
201 aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
45fcf539 202 AML_EXCLUSIVE, &irqs, 1));
d4e5de1a
SZ
203 aml_append(dev_gsi, aml_name_decl("_PRS", crs));
204 crs = aml_resource_template();
205 aml_append(crs,
206 aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
45fcf539 207 AML_EXCLUSIVE, &irqs, 1));
d4e5de1a 208 aml_append(dev_gsi, aml_name_decl("_CRS", crs));
4dbfc881 209 method = aml_method("_SRS", 1, AML_NOTSERIALIZED);
d4e5de1a
SZ
210 aml_append(dev_gsi, method);
211 aml_append(dev, dev_gsi);
212 }
213
4dbfc881 214 method = aml_method("_CBA", 0, AML_NOTSERIALIZED);
d4e5de1a
SZ
215 aml_append(method, aml_return(aml_int(base_ecam)));
216 aml_append(dev, method);
217
4dbfc881 218 method = aml_method("_CRS", 0, AML_NOTSERIALIZED);
d4e5de1a
SZ
219 Aml *rbuf = aml_resource_template();
220 aml_append(rbuf,
221 aml_word_bus_number(AML_MIN_FIXED, AML_MAX_FIXED, AML_POS_DECODE,
222 0x0000, 0x0000, nr_pcie_buses - 1, 0x0000,
223 nr_pcie_buses));
224 aml_append(rbuf,
225 aml_dword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,
226 AML_NON_CACHEABLE, AML_READ_WRITE, 0x0000, base_mmio,
227 base_mmio + size_mmio - 1, 0x0000, size_mmio));
228 aml_append(rbuf,
229 aml_dword_io(AML_MIN_FIXED, AML_MAX_FIXED, AML_POS_DECODE,
230 AML_ENTIRE_RANGE, 0x0000, 0x0000, size_pio - 1, base_pio,
231 size_pio));
232
5125f9cd 233 if (use_highmem) {
bf424a12
EA
234 hwaddr base_mmio_high = memmap[VIRT_HIGH_PCIE_MMIO].base;
235 hwaddr size_mmio_high = memmap[VIRT_HIGH_PCIE_MMIO].size;
5125f9cd
PF
236
237 aml_append(rbuf,
238 aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,
239 AML_NON_CACHEABLE, AML_READ_WRITE, 0x0000,
e40c3d2e
AB
240 base_mmio_high,
241 base_mmio_high + size_mmio_high - 1, 0x0000,
5125f9cd
PF
242 size_mmio_high));
243 }
244
d4e5de1a
SZ
245 aml_append(method, aml_name_decl("RBUF", rbuf));
246 aml_append(method, aml_return(rbuf));
247 aml_append(dev, method);
248
249 /* Declare an _OSC (OS Control Handoff) method */
250 aml_append(dev, aml_name_decl("SUPP", aml_int(0)));
251 aml_append(dev, aml_name_decl("CTRL", aml_int(0)));
4dbfc881 252 method = aml_method("_OSC", 4, AML_NOTSERIALIZED);
d4e5de1a
SZ
253 aml_append(method,
254 aml_create_dword_field(aml_arg(3), aml_int(0), "CDW1"));
255
256 /* PCI Firmware Specification 3.0
257 * 4.5.1. _OSC Interface for PCI Host Bridge Devices
258 * The _OSC interface for a PCI/PCI-X/PCI Express hierarchy is
259 * identified by the Universal Unique IDentifier (UUID)
260 * 33DB4D5B-1FF7-401C-9657-7441C03DD766
261 */
262 UUID = aml_touuid("33DB4D5B-1FF7-401C-9657-7441C03DD766");
263 ifctx = aml_if(aml_equal(aml_arg(0), UUID));
264 aml_append(ifctx,
265 aml_create_dword_field(aml_arg(3), aml_int(4), "CDW2"));
266 aml_append(ifctx,
267 aml_create_dword_field(aml_arg(3), aml_int(8), "CDW3"));
268 aml_append(ifctx, aml_store(aml_name("CDW2"), aml_name("SUPP")));
269 aml_append(ifctx, aml_store(aml_name("CDW3"), aml_name("CTRL")));
5530427f 270 aml_append(ifctx, aml_store(aml_and(aml_name("CTRL"), aml_int(0x1D), NULL),
d4e5de1a
SZ
271 aml_name("CTRL")));
272
273 ifctx1 = aml_if(aml_lnot(aml_equal(aml_arg(1), aml_int(0x1))));
ca3df95d 274 aml_append(ifctx1, aml_store(aml_or(aml_name("CDW1"), aml_int(0x08), NULL),
d4e5de1a
SZ
275 aml_name("CDW1")));
276 aml_append(ifctx, ifctx1);
277
278 ifctx1 = aml_if(aml_lnot(aml_equal(aml_name("CDW3"), aml_name("CTRL"))));
ca3df95d 279 aml_append(ifctx1, aml_store(aml_or(aml_name("CDW1"), aml_int(0x10), NULL),
d4e5de1a
SZ
280 aml_name("CDW1")));
281 aml_append(ifctx, ifctx1);
282
283 aml_append(ifctx, aml_store(aml_name("CTRL"), aml_name("CDW3")));
284 aml_append(ifctx, aml_return(aml_arg(3)));
285 aml_append(method, ifctx);
286
287 elsectx = aml_else();
ca3df95d 288 aml_append(elsectx, aml_store(aml_or(aml_name("CDW1"), aml_int(4), NULL),
d4e5de1a
SZ
289 aml_name("CDW1")));
290 aml_append(elsectx, aml_return(aml_arg(3)));
291 aml_append(method, elsectx);
292 aml_append(dev, method);
293
4dbfc881 294 method = aml_method("_DSM", 4, AML_NOTSERIALIZED);
d4e5de1a
SZ
295
296 /* PCI Firmware Specification 3.0
297 * 4.6.1. _DSM for PCI Express Slot Information
298 * The UUID in _DSM in this context is
299 * {E5C937D0-3553-4D7A-9117-EA4D19C3434D}
300 */
301 UUID = aml_touuid("E5C937D0-3553-4D7A-9117-EA4D19C3434D");
302 ifctx = aml_if(aml_equal(aml_arg(0), UUID));
303 ifctx1 = aml_if(aml_equal(aml_arg(2), aml_int(0)));
304 uint8_t byte_list[1] = {1};
305 buf = aml_buffer(1, byte_list);
306 aml_append(ifctx1, aml_return(buf));
307 aml_append(ifctx, ifctx1);
308 aml_append(method, ifctx);
309
310 byte_list[0] = 0;
311 buf = aml_buffer(1, byte_list);
312 aml_append(method, aml_return(buf));
313 aml_append(dev, method);
314
315 Aml *dev_rp0 = aml_device("%s", "RP0");
316 aml_append(dev_rp0, aml_name_decl("_ADR", aml_int(0)));
317 aml_append(dev, dev_rp0);
ebfcc03b
AB
318
319 Aml *dev_res0 = aml_device("%s", "RES0");
320 aml_append(dev_res0, aml_name_decl("_HID", aml_string("PNP0C02")));
321 crs = aml_resource_template();
601d626d
EA
322 aml_append(crs,
323 aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,
324 AML_NON_CACHEABLE, AML_READ_WRITE, 0x0000, base_ecam,
325 base_ecam + size_ecam - 1, 0x0000, size_ecam));
ebfcc03b
AB
326 aml_append(dev_res0, aml_name_decl("_CRS", crs));
327 aml_append(dev, dev_res0);
d4e5de1a
SZ
328 aml_append(scope, dev);
329}
330
aeb1a36d
SZ
331static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap,
332 uint32_t gpio_irq)
333{
334 Aml *dev = aml_device("GPO0");
335 aml_append(dev, aml_name_decl("_HID", aml_string("ARMH0061")));
336 aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
337 aml_append(dev, aml_name_decl("_UID", aml_int(0)));
338
339 Aml *crs = aml_resource_template();
340 aml_append(crs, aml_memory32_fixed(gpio_memmap->base, gpio_memmap->size,
341 AML_READ_WRITE));
342 aml_append(crs, aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
343 AML_EXCLUSIVE, &gpio_irq, 1));
344 aml_append(dev, aml_name_decl("_CRS", crs));
c1a158b7
SZ
345
346 Aml *aei = aml_resource_template();
347 /* Pin 3 for power button */
348 const uint32_t pin_list[1] = {3};
349 aml_append(aei, aml_gpio_int(AML_CONSUMER, AML_EDGE, AML_ACTIVE_HIGH,
350 AML_EXCLUSIVE, AML_PULL_UP, 0, pin_list, 1,
351 "GPO0", NULL, 0));
352 aml_append(dev, aml_name_decl("_AEI", aei));
353
354 /* _E03 is handle for power button */
355 Aml *method = aml_method("_E03", 0, AML_NOTSERIALIZED);
356 aml_append(method, aml_notify(aml_name(ACPI_POWER_BUTTON_DEVICE),
357 aml_int(0x80)));
358 aml_append(dev, method);
aeb1a36d
SZ
359 aml_append(scope, dev);
360}
361
ac6aa59a
SZ
362static void acpi_dsdt_add_power_button(Aml *scope)
363{
364 Aml *dev = aml_device(ACPI_POWER_BUTTON_DEVICE);
365 aml_append(dev, aml_name_decl("_HID", aml_string("PNP0C0C")));
366 aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
367 aml_append(dev, aml_name_decl("_UID", aml_int(0)));
368 aml_append(scope, dev);
369}
370
e78f1222 371static void
a703b4f6 372build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
e78f1222 373{
a703b4f6 374 int nb_nodes, iort_start = table_data->len;
e78f1222
PM
375 AcpiIortIdMapping *idmap;
376 AcpiIortItsGroup *its;
377 AcpiIortTable *iort;
a703b4f6 378 AcpiIortSmmu3 *smmu;
6e3e7239 379 size_t node_size, iort_node_offset, iort_length, smmu_offset = 0;
e78f1222
PM
380 AcpiIortRC *rc;
381
382 iort = acpi_data_push(table_data, sizeof(*iort));
383
a703b4f6
PM
384 if (vms->iommu == VIRT_IOMMU_SMMUV3) {
385 nb_nodes = 3; /* RC, ITS, SMMUv3 */
386 } else {
387 nb_nodes = 2; /* RC, ITS */
388 }
389
e78f1222 390 iort_length = sizeof(*iort);
a703b4f6 391 iort->node_count = cpu_to_le32(nb_nodes);
6e3e7239
SZ
392 /*
393 * Use a copy in case table_data->data moves during acpi_data_push
394 * operations.
395 */
396 iort_node_offset = sizeof(*iort);
397 iort->node_offset = cpu_to_le32(iort_node_offset);
e78f1222
PM
398
399 /* ITS group node */
400 node_size = sizeof(*its) + sizeof(uint32_t);
401 iort_length += node_size;
402 its = acpi_data_push(table_data, node_size);
403
404 its->type = ACPI_IORT_NODE_ITS_GROUP;
405 its->length = cpu_to_le16(node_size);
406 its->its_count = cpu_to_le32(1);
407 its->identifiers[0] = 0; /* MADT translation_id */
408
a703b4f6 409 if (vms->iommu == VIRT_IOMMU_SMMUV3) {
41c4fb94 410 int irq = vms->irqmap[VIRT_SMMU] + ARM_SPI_BASE;
a703b4f6
PM
411
412 /* SMMUv3 node */
6e3e7239 413 smmu_offset = iort_node_offset + node_size;
a703b4f6
PM
414 node_size = sizeof(*smmu) + sizeof(*idmap);
415 iort_length += node_size;
416 smmu = acpi_data_push(table_data, node_size);
417
418 smmu->type = ACPI_IORT_NODE_SMMU_V3;
419 smmu->length = cpu_to_le16(node_size);
420 smmu->mapping_count = cpu_to_le32(1);
421 smmu->mapping_offset = cpu_to_le32(sizeof(*smmu));
422 smmu->base_address = cpu_to_le64(vms->memmap[VIRT_SMMU].base);
29bbccc2 423 smmu->flags = cpu_to_le32(ACPI_IORT_SMMU_V3_COHACC_OVERRIDE);
a703b4f6
PM
424 smmu->event_gsiv = cpu_to_le32(irq);
425 smmu->pri_gsiv = cpu_to_le32(irq + 1);
426 smmu->gerr_gsiv = cpu_to_le32(irq + 2);
427 smmu->sync_gsiv = cpu_to_le32(irq + 3);
428
429 /* Identity RID mapping covering the whole input RID range */
430 idmap = &smmu->id_mapping_array[0];
431 idmap->input_base = 0;
432 idmap->id_count = cpu_to_le32(0xFFFF);
433 idmap->output_base = 0;
434 /* output IORT node is the ITS group node (the first node) */
6e3e7239 435 idmap->output_reference = cpu_to_le32(iort_node_offset);
a703b4f6
PM
436 }
437
e78f1222
PM
438 /* Root Complex Node */
439 node_size = sizeof(*rc) + sizeof(*idmap);
440 iort_length += node_size;
441 rc = acpi_data_push(table_data, node_size);
442
443 rc->type = ACPI_IORT_NODE_PCI_ROOT_COMPLEX;
444 rc->length = cpu_to_le16(node_size);
445 rc->mapping_count = cpu_to_le32(1);
446 rc->mapping_offset = cpu_to_le32(sizeof(*rc));
447
448 /* fully coherent device */
449 rc->memory_properties.cache_coherency = cpu_to_le32(1);
450 rc->memory_properties.memory_flags = 0x3; /* CCA = CPM = DCAS = 1 */
451 rc->pci_segment_number = 0; /* MCFG pci_segment */
452
453 /* Identity RID mapping covering the whole input RID range */
454 idmap = &rc->id_mapping_array[0];
455 idmap->input_base = 0;
456 idmap->id_count = cpu_to_le32(0xFFFF);
457 idmap->output_base = 0;
a703b4f6
PM
458
459 if (vms->iommu == VIRT_IOMMU_SMMUV3) {
460 /* output IORT node is the smmuv3 node */
461 idmap->output_reference = cpu_to_le32(smmu_offset);
462 } else {
463 /* output IORT node is the ITS group node (the first node) */
6e3e7239 464 idmap->output_reference = cpu_to_le32(iort_node_offset);
a703b4f6 465 }
e78f1222 466
6e3e7239
SZ
467 /*
468 * Update the pointer address in case table_data->data moves during above
469 * acpi_data_push operations.
470 */
471 iort = (AcpiIortTable *)(table_data->data + iort_start);
e78f1222
PM
472 iort->length = cpu_to_le32(iort_length);
473
474 build_header(linker, table_data, (void *)(table_data->data + iort_start),
475 "IORT", table_data->len - iort_start, 0, NULL, NULL);
476}
477
f264d51d 478static void
da4f09a7 479build_spcr(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
f264d51d
AJ
480{
481 AcpiSerialPortConsoleRedirection *spcr;
da4f09a7
AJ
482 const MemMapEntry *uart_memmap = &vms->memmap[VIRT_UART];
483 int irq = vms->irqmap[VIRT_UART] + ARM_SPI_BASE;
4d027afe 484 int spcr_start = table_data->len;
f264d51d
AJ
485
486 spcr = acpi_data_push(table_data, sizeof(*spcr));
487
488 spcr->interface_type = 0x3; /* ARM PL011 UART */
489
490 spcr->base_address.space_id = AML_SYSTEM_MEMORY;
491 spcr->base_address.bit_width = 8;
492 spcr->base_address.bit_offset = 0;
493 spcr->base_address.access_width = 1;
494 spcr->base_address.address = cpu_to_le64(uart_memmap->base);
495
496 spcr->interrupt_types = (1 << 3); /* Bit[3] ARMH GIC interrupt */
497 spcr->gsi = cpu_to_le32(irq); /* Global System Interrupt */
498
499 spcr->baud = 3; /* Baud Rate: 3 = 9600 */
500 spcr->parity = 0; /* No Parity */
501 spcr->stopbits = 1; /* 1 Stop bit */
502 spcr->flowctrl = (1 << 1); /* Bit[1] = RTS/CTS hardware flow control */
503 spcr->term_type = 0; /* Terminal Type: 0 = VT100 */
504
505 spcr->pci_device_id = 0xffff; /* PCI Device ID: not a PCI device */
506 spcr->pci_vendor_id = 0xffff; /* PCI Vendor ID: not a PCI device */
507
4d027afe
Z
508 build_header(linker, table_data, (void *)(table_data->data + spcr_start),
509 "SPCR", table_data->len - spcr_start, 2, NULL, NULL);
f264d51d
AJ
510}
511
2b302e1e 512static void
da4f09a7 513build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
2b302e1e
SZ
514{
515 AcpiSystemResourceAffinityTable *srat;
516 AcpiSratProcessorGiccAffinity *core;
517 AcpiSratMemoryAffinity *numamem;
4ccf5826 518 int i, srat_start;
2b302e1e 519 uint64_t mem_base;
4ccf5826
IM
520 MachineClass *mc = MACHINE_GET_CLASS(vms);
521 const CPUArchIdList *cpu_list = mc->possible_cpu_arch_ids(MACHINE(vms));
2b302e1e
SZ
522
523 srat_start = table_data->len;
524 srat = acpi_data_push(table_data, sizeof(*srat));
525 srat->reserved1 = cpu_to_le32(1);
526
4ccf5826 527 for (i = 0; i < cpu_list->len; ++i) {
2b302e1e
SZ
528 core = acpi_data_push(table_data, sizeof(*core));
529 core->type = ACPI_SRAT_PROCESSOR_GICC;
530 core->length = sizeof(*core);
d41f3e75 531 core->proximity = cpu_to_le32(cpu_list->cpus[i].props.node_id);
2b302e1e
SZ
532 core->acpi_processor_uid = cpu_to_le32(i);
533 core->flags = cpu_to_le32(1);
534 }
2b302e1e 535
da4f09a7 536 mem_base = vms->memmap[VIRT_MEM].base;
2b302e1e 537 for (i = 0; i < nb_numa_nodes; ++i) {
66c353ce
SZ
538 if (numa_info[i].node_mem > 0) {
539 numamem = acpi_data_push(table_data, sizeof(*numamem));
540 build_srat_memory(numamem, mem_base, numa_info[i].node_mem, i,
541 MEM_AFFINITY_ENABLED);
542 mem_base += numa_info[i].node_mem;
543 }
2b302e1e
SZ
544 }
545
4d027afe
Z
546 build_header(linker, table_data, (void *)(table_data->data + srat_start),
547 "SRAT", table_data->len - srat_start, 3, NULL, NULL);
2b302e1e
SZ
548}
549
ee246400
SZ
550/* GTDT */
551static void
8dd845d3 552build_gtdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
ee246400 553{
8dd845d3 554 VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
ee246400
SZ
555 int gtdt_start = table_data->len;
556 AcpiGenericTimerTable *gtdt;
8dd845d3
AJ
557 uint32_t irqflags;
558
559 if (vmc->claim_edge_triggered_timers) {
560 irqflags = ACPI_GTDT_INTERRUPT_MODE_EDGE;
561 } else {
562 irqflags = ACPI_GTDT_INTERRUPT_MODE_LEVEL;
563 }
ee246400
SZ
564
565 gtdt = acpi_data_push(table_data, sizeof *gtdt);
566 /* The interrupt values are the same with the device tree when adding 16 */
330afe05 567 gtdt->secure_el1_interrupt = cpu_to_le32(ARCH_TIMER_S_EL1_IRQ + 16);
8dd845d3 568 gtdt->secure_el1_flags = cpu_to_le32(irqflags);
ee246400 569
330afe05 570 gtdt->non_secure_el1_interrupt = cpu_to_le32(ARCH_TIMER_NS_EL1_IRQ + 16);
8dd845d3 571 gtdt->non_secure_el1_flags = cpu_to_le32(irqflags |
aca4bbf4 572 ACPI_GTDT_CAP_ALWAYS_ON);
ee246400 573
330afe05 574 gtdt->virtual_timer_interrupt = cpu_to_le32(ARCH_TIMER_VIRT_IRQ + 16);
8dd845d3 575 gtdt->virtual_timer_flags = cpu_to_le32(irqflags);
ee246400 576
330afe05 577 gtdt->non_secure_el2_interrupt = cpu_to_le32(ARCH_TIMER_NS_EL2_IRQ + 16);
8dd845d3 578 gtdt->non_secure_el2_flags = cpu_to_le32(irqflags);
ee246400
SZ
579
580 build_header(linker, table_data,
581 (void *)(table_data->data + gtdt_start), "GTDT",
37ad223c 582 table_data->len - gtdt_start, 2, NULL, NULL);
ee246400
SZ
583}
584
982d06c5
SZ
585/* MADT */
586static void
da4f09a7 587build_madt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
982d06c5 588{
da4f09a7 589 VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
982d06c5 590 int madt_start = table_data->len;
da4f09a7
AJ
591 const MemMapEntry *memmap = vms->memmap;
592 const int *irqmap = vms->irqmap;
982d06c5
SZ
593 AcpiMultipleApicTable *madt;
594 AcpiMadtGenericDistributor *gicd;
ca793736 595 AcpiMadtGenericMsiFrame *gic_msi;
982d06c5
SZ
596 int i;
597
598 madt = acpi_data_push(table_data, sizeof *madt);
599
982d06c5
SZ
600 gicd = acpi_data_push(table_data, sizeof *gicd);
601 gicd->type = ACPI_APIC_GENERIC_DISTRIBUTOR;
602 gicd->length = sizeof(*gicd);
330afe05 603 gicd->base_address = cpu_to_le64(memmap[VIRT_GIC_DIST].base);
da4f09a7 604 gicd->version = vms->gic_version;
982d06c5 605
da4f09a7 606 for (i = 0; i < vms->smp_cpus; i++) {
6e2ed65f
AJ
607 AcpiMadtGenericCpuInterface *gicc = acpi_data_push(table_data,
608 sizeof(*gicc));
5d9c1756
SZ
609 ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(i));
610
6e2ed65f 611 gicc->type = ACPI_APIC_GENERIC_CPU_INTERFACE;
f2fbface 612 gicc->length = sizeof(*gicc);
da4f09a7 613 if (vms->gic_version == 2) {
330afe05 614 gicc->base_address = cpu_to_le64(memmap[VIRT_GIC_CPU].base);
55ef3233
LM
615 gicc->gich_base_address = cpu_to_le64(memmap[VIRT_GIC_HYP].base);
616 gicc->gicv_base_address = cpu_to_le64(memmap[VIRT_GIC_VCPU].base);
f2fbface 617 }
330afe05
AJ
618 gicc->cpu_interface_number = cpu_to_le32(i);
619 gicc->arm_mpidr = cpu_to_le64(armcpu->mp_affinity);
620 gicc->uid = cpu_to_le32(i);
6e2ed65f 621 gicc->flags = cpu_to_le32(ACPI_MADT_GICC_ENABLED);
8433dee0 622
929e754d 623 if (arm_feature(&armcpu->env, ARM_FEATURE_PMU)) {
8433dee0
SZ
624 gicc->performance_interrupt = cpu_to_le32(PPI(VIRTUAL_PMU_IRQ));
625 }
55ef3233
LM
626 if (vms->virt) {
627 gicc->vgic_interrupt = cpu_to_le32(PPI(ARCH_GIC_MAINT_IRQ));
f29cacfb 628 }
f2fbface
SZ
629 }
630
da4f09a7 631 if (vms->gic_version == 3) {
13e5c54d 632 AcpiMadtGenericTranslator *gic_its;
a1de312f 633 int nb_redist_regions = virt_gicv3_redist_region_count(vms);
b92ad394
PF
634 AcpiMadtGenericRedistributor *gicr = acpi_data_push(table_data,
635 sizeof *gicr);
636
637 gicr->type = ACPI_APIC_GENERIC_REDISTRIBUTOR;
638 gicr->length = sizeof(*gicr);
639 gicr->base_address = cpu_to_le64(memmap[VIRT_GIC_REDIST].base);
640 gicr->range_length = cpu_to_le32(memmap[VIRT_GIC_REDIST].size);
13e5c54d 641
a1de312f
EA
642 if (nb_redist_regions == 2) {
643 gicr = acpi_data_push(table_data, sizeof(*gicr));
644 gicr->type = ACPI_APIC_GENERIC_REDISTRIBUTOR;
645 gicr->length = sizeof(*gicr);
bf424a12
EA
646 gicr->base_address =
647 cpu_to_le64(memmap[VIRT_HIGH_GIC_REDIST2].base);
648 gicr->range_length =
649 cpu_to_le32(memmap[VIRT_HIGH_GIC_REDIST2].size);
a1de312f
EA
650 }
651
da4f09a7 652 if (its_class_name() && !vmc->no_its) {
13cda487
AJ
653 gic_its = acpi_data_push(table_data, sizeof *gic_its);
654 gic_its->type = ACPI_APIC_GENERIC_TRANSLATOR;
655 gic_its->length = sizeof(*gic_its);
656 gic_its->translation_id = 0;
657 gic_its->base_address = cpu_to_le64(memmap[VIRT_GIC_ITS].base);
13e5c54d 658 }
b92ad394 659 } else {
b92ad394
PF
660 gic_msi = acpi_data_push(table_data, sizeof *gic_msi);
661 gic_msi->type = ACPI_APIC_GENERIC_MSI_FRAME;
662 gic_msi->length = sizeof(*gic_msi);
663 gic_msi->gic_msi_frame_id = 0;
664 gic_msi->base_address = cpu_to_le64(memmap[VIRT_GIC_V2M].base);
665 gic_msi->flags = cpu_to_le32(1);
666 gic_msi->spi_count = cpu_to_le16(NUM_GICV2M_SPIS);
667 gic_msi->spi_base = cpu_to_le16(irqmap[VIRT_GIC_V2M] + ARM_SPI_BASE);
668 }
ca793736 669
982d06c5
SZ
670 build_header(linker, table_data,
671 (void *)(table_data->data + madt_start), "APIC",
37ad223c 672 table_data->len - madt_start, 3, NULL, NULL);
982d06c5
SZ
673}
674
c2f7c0c3 675/* FADT */
8612f8bd
IM
676static void build_fadt_rev5(GArray *table_data, BIOSLinker *linker,
677 VirtMachineState *vms, unsigned dsdt_tbl_offset)
c2f7c0c3 678{
dd1b2037
IM
679 /* ACPI v5.1 */
680 AcpiFadtData fadt = {
681 .rev = 5,
682 .minor_ver = 1,
683 .flags = 1 << ACPI_FADT_F_HW_REDUCED_ACPI,
684 .xdsdt_tbl_offset = &dsdt_tbl_offset,
685 };
79e993a0
AJ
686
687 switch (vms->psci_conduit) {
688 case QEMU_PSCI_CONDUIT_DISABLED:
dd1b2037 689 fadt.arm_boot_arch = 0;
79e993a0
AJ
690 break;
691 case QEMU_PSCI_CONDUIT_HVC:
dd1b2037
IM
692 fadt.arm_boot_arch = ACPI_FADT_ARM_PSCI_COMPLIANT |
693 ACPI_FADT_ARM_PSCI_USE_HVC;
79e993a0
AJ
694 break;
695 case QEMU_PSCI_CONDUIT_SMC:
dd1b2037 696 fadt.arm_boot_arch = ACPI_FADT_ARM_PSCI_COMPLIANT;
79e993a0
AJ
697 break;
698 default:
699 g_assert_not_reached();
700 }
c2f7c0c3 701
dd1b2037 702 build_fadt(table_data, linker, &fadt, NULL, NULL);
c2f7c0c3
SZ
703}
704
dfccd8cf
SZ
705/* DSDT */
706static void
da4f09a7 707build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
dfccd8cf
SZ
708{
709 Aml *scope, *dsdt;
da4f09a7
AJ
710 const MemMapEntry *memmap = vms->memmap;
711 const int *irqmap = vms->irqmap;
dfccd8cf
SZ
712
713 dsdt = init_aml_allocator();
714 /* Reserve space for header */
715 acpi_data_push(dsdt->buf, sizeof(AcpiTableHeader));
716
67736a25
SZ
717 /* When booting the VM with UEFI, UEFI takes ownership of the RTC hardware.
718 * While UEFI can use libfdt to disable the RTC device node in the DTB that
719 * it passes to the OS, it cannot modify AML. Therefore, we won't generate
720 * the RTC ACPI device at all when using UEFI.
721 */
dfccd8cf 722 scope = aml_scope("\\_SB");
da4f09a7 723 acpi_dsdt_add_cpus(scope, vms->smp_cpus);
dfccd8cf
SZ
724 acpi_dsdt_add_uart(scope, &memmap[VIRT_UART],
725 (irqmap[VIRT_UART] + ARM_SPI_BASE));
dfccd8cf 726 acpi_dsdt_add_flash(scope, &memmap[VIRT_FLASH]);
70bee80d 727 acpi_dsdt_add_fw_cfg(scope, &memmap[VIRT_FW_CFG]);
dfccd8cf
SZ
728 acpi_dsdt_add_virtio(scope, &memmap[VIRT_MMIO],
729 (irqmap[VIRT_MMIO] + ARM_SPI_BASE), NUM_VIRTIO_TRANSPORTS);
5125f9cd 730 acpi_dsdt_add_pci(scope, memmap, (irqmap[VIRT_PCIE] + ARM_SPI_BASE),
601d626d 731 vms->highmem, vms->highmem_ecam);
aeb1a36d
SZ
732 acpi_dsdt_add_gpio(scope, &memmap[VIRT_GPIO],
733 (irqmap[VIRT_GPIO] + ARM_SPI_BASE));
ac6aa59a 734 acpi_dsdt_add_power_button(scope);
d4e5de1a 735
dfccd8cf
SZ
736 aml_append(dsdt, scope);
737
738 /* copy AML table into ACPI tables blob and patch header there */
739 g_array_append_vals(table_data, dsdt->buf->data, dsdt->buf->len);
740 build_header(linker, table_data,
741 (void *)(table_data->data + table_data->len - dsdt->buf->len),
37ad223c 742 "DSDT", dsdt->buf->len, 2, NULL, NULL);
dfccd8cf
SZ
743 free_aml_allocator();
744}
745
f5d8c8cd
SZ
746typedef
747struct AcpiBuildState {
748 /* Copy of table in RAM (for patching). */
749 MemoryRegion *table_mr;
750 MemoryRegion *rsdp_mr;
751 MemoryRegion *linker_mr;
752 /* Is table patched? */
753 bool patched;
f5d8c8cd
SZ
754} AcpiBuildState;
755
756static
da4f09a7 757void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
f5d8c8cd 758{
da4f09a7 759 VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
f5d8c8cd 760 GArray *table_offsets;
cb51ac2f 761 unsigned dsdt, xsdt;
dfccd8cf 762 GArray *tables_blob = tables->table_data;
f5d8c8cd
SZ
763
764 table_offsets = g_array_new(false, true /* clear */,
765 sizeof(uint32_t));
766
ad9671b8
IM
767 bios_linker_loader_alloc(tables->linker,
768 ACPI_BUILD_TABLE_FILE, tables_blob,
f5d8c8cd
SZ
769 64, false /* high memory */);
770
dfccd8cf 771 /* DSDT is pointed to by FADT */
c2f7c0c3 772 dsdt = tables_blob->len;
da4f09a7 773 build_dsdt(tables_blob, tables->linker, vms);
dfccd8cf 774
d0652b57 775 /* FADT MADT GTDT MCFG SPCR pointed to by RSDT */
c2f7c0c3 776 acpi_add_table(table_offsets, tables_blob);
8612f8bd 777 build_fadt_rev5(tables_blob, tables->linker, vms, dsdt);
c2f7c0c3 778
982d06c5 779 acpi_add_table(table_offsets, tables_blob);
da4f09a7 780 build_madt(tables_blob, tables->linker, vms);
982d06c5 781
ee246400 782 acpi_add_table(table_offsets, tables_blob);
8dd845d3 783 build_gtdt(tables_blob, tables->linker, vms);
ee246400 784
84344884 785 acpi_add_table(table_offsets, tables_blob);
48cefd94
WY
786 {
787 AcpiMcfgInfo mcfg = {
788 .base = vms->memmap[VIRT_ECAM_ID(vms->highmem_ecam)].base,
789 .size = vms->memmap[VIRT_ECAM_ID(vms->highmem_ecam)].size,
790 };
791 build_mcfg(tables_blob, tables->linker, &mcfg);
792 }
84344884 793
f264d51d 794 acpi_add_table(table_offsets, tables_blob);
da4f09a7 795 build_spcr(tables_blob, tables->linker, vms);
f264d51d 796
2b302e1e
SZ
797 if (nb_numa_nodes > 0) {
798 acpi_add_table(table_offsets, tables_blob);
da4f09a7 799 build_srat(tables_blob, tables->linker, vms);
94a66456
AJ
800 if (have_numa_distance) {
801 acpi_add_table(table_offsets, tables_blob);
802 build_slit(tables_blob, tables->linker);
803 }
2b302e1e
SZ
804 }
805
da4f09a7 806 if (its_class_name() && !vmc->no_its) {
e78f1222 807 acpi_add_table(table_offsets, tables_blob);
a703b4f6 808 build_iort(tables_blob, tables->linker, vms);
e78f1222
PM
809 }
810
cb51ac2f
AB
811 /* XSDT is pointed to by RSDP */
812 xsdt = tables_blob->len;
813 build_xsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
243bdb79 814
d4bec5d8 815 /* RSDP is in FSEG memory, so allocate it separately */
5c5fce1a
SO
816 {
817 AcpiRsdpData rsdp_data = {
818 .revision = 2,
819 .oem_id = ACPI_BUILD_APPNAME6,
820 .xsdt_tbl_offset = &xsdt,
821 .rsdt_tbl_offset = NULL,
822 };
823 build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
824 }
d4bec5d8 825
f5d8c8cd
SZ
826 /* Cleanup memory that's no longer used. */
827 g_array_free(table_offsets, true);
828}
829
830static void acpi_ram_update(MemoryRegion *mr, GArray *data)
831{
832 uint32_t size = acpi_data_len(data);
833
834 /* Make sure RAM size is correct - in case it got changed
835 * e.g. by migration */
836 memory_region_ram_resize(mr, size, &error_abort);
837
838 memcpy(memory_region_get_ram_ptr(mr), data->data, size);
839 memory_region_set_dirty(mr, 0, size);
840}
841
3f8752b4 842static void virt_acpi_build_update(void *build_opaque)
f5d8c8cd
SZ
843{
844 AcpiBuildState *build_state = build_opaque;
845 AcpiBuildTables tables;
846
847 /* No state to update or already patched? Nothing to do. */
848 if (!build_state || build_state->patched) {
849 return;
850 }
851 build_state->patched = true;
852
853 acpi_build_tables_init(&tables);
854
4dad9e74 855 virt_acpi_build(VIRT_MACHINE(qdev_get_machine()), &tables);
f5d8c8cd
SZ
856
857 acpi_ram_update(build_state->table_mr, tables.table_data);
858 acpi_ram_update(build_state->rsdp_mr, tables.rsdp);
0e9b9eda 859 acpi_ram_update(build_state->linker_mr, tables.linker->cmd_blob);
f5d8c8cd 860
f5d8c8cd
SZ
861 acpi_build_tables_cleanup(&tables, true);
862}
863
864static void virt_acpi_build_reset(void *build_opaque)
865{
866 AcpiBuildState *build_state = build_opaque;
867 build_state->patched = false;
868}
869
f5d8c8cd
SZ
870static const VMStateDescription vmstate_virt_acpi_build = {
871 .name = "virt_acpi_build",
872 .version_id = 1,
873 .minimum_version_id = 1,
874 .fields = (VMStateField[]) {
875 VMSTATE_BOOL(patched, AcpiBuildState),
876 VMSTATE_END_OF_LIST()
877 },
878};
879
e9a8e474 880void virt_acpi_setup(VirtMachineState *vms)
f5d8c8cd
SZ
881{
882 AcpiBuildTables tables;
883 AcpiBuildState *build_state;
884
af1f60a4 885 if (!vms->fw_cfg) {
f5d8c8cd
SZ
886 trace_virt_acpi_setup();
887 return;
888 }
889
890 if (!acpi_enabled) {
891 trace_virt_acpi_setup();
892 return;
893 }
894
895 build_state = g_malloc0(sizeof *build_state);
f5d8c8cd
SZ
896
897 acpi_build_tables_init(&tables);
da4f09a7 898 virt_acpi_build(vms, &tables);
f5d8c8cd
SZ
899
900 /* Now expose it all to Guest */
82f76c67
WY
901 build_state->table_mr = acpi_add_rom_blob(virt_acpi_build_update,
902 build_state, tables.table_data,
903 ACPI_BUILD_TABLE_FILE,
904 ACPI_BUILD_TABLE_MAX_SIZE);
f5d8c8cd
SZ
905 assert(build_state->table_mr != NULL);
906
907 build_state->linker_mr =
82f76c67
WY
908 acpi_add_rom_blob(virt_acpi_build_update, build_state,
909 tables.linker->cmd_blob, "etc/table-loader", 0);
f5d8c8cd 910
af1f60a4
AJ
911 fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data,
912 acpi_data_len(tables.tcpalog));
f5d8c8cd 913
82f76c67
WY
914 build_state->rsdp_mr = acpi_add_rom_blob(virt_acpi_build_update,
915 build_state, tables.rsdp,
916 ACPI_BUILD_RSDP_FILE, 0);
f5d8c8cd
SZ
917
918 qemu_register_reset(virt_acpi_build_reset, build_state);
919 virt_acpi_build_reset(build_state);
920 vmstate_register(NULL, 0, &vmstate_virt_acpi_build, build_state);
921
922 /* Cleanup tables but don't free the memory: we track it
923 * in build_state.
924 */
925 acpi_build_tables_cleanup(&tables, false);
926}