2015-05-29 13:28:54 +03:00
|
|
|
/* Support for generating ACPI tables and passing them to Guests
|
|
|
|
*
|
|
|
|
* ARM virt ACPI generation
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008-2010 Kevin O'Connor <kevin@koconnor.net>
|
|
|
|
* Copyright (C) 2006 Fabrice Bellard
|
|
|
|
* Copyright (C) 2013 Red Hat Inc
|
|
|
|
*
|
|
|
|
* Author: Michael S. Tsirkin <mst@redhat.com>
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015 HUAWEI TECHNOLOGIES CO.,LTD.
|
|
|
|
*
|
|
|
|
* Author: Shannon Zhao <zhaoshenglong@huawei.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-12-07 19:23:45 +03:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2015-05-29 13:28:54 +03:00
|
|
|
#include "qemu-common.h"
|
|
|
|
#include "qemu/bitmap.h"
|
|
|
|
#include "trace.h"
|
|
|
|
#include "qom/cpu.h"
|
2016-10-11 09:56:52 +03:00
|
|
|
#include "target/arm/cpu.h"
|
2015-05-29 13:28:54 +03:00
|
|
|
#include "hw/acpi/acpi-defs.h"
|
|
|
|
#include "hw/acpi/acpi.h"
|
|
|
|
#include "hw/nvram/fw_cfg.h"
|
|
|
|
#include "hw/acpi/bios-linker-loader.h"
|
|
|
|
#include "hw/loader.h"
|
|
|
|
#include "hw/hw.h"
|
|
|
|
#include "hw/acpi/aml-build.h"
|
2015-05-29 13:28:57 +03:00
|
|
|
#include "hw/pci/pcie_host.h"
|
2015-05-29 13:28:59 +03:00
|
|
|
#include "hw/pci/pci.h"
|
2017-01-09 14:40:22 +03:00
|
|
|
#include "hw/arm/virt.h"
|
2016-05-12 15:22:28 +03:00
|
|
|
#include "sysemu/numa.h"
|
2016-10-04 15:28:09 +03:00
|
|
|
#include "kvm_arm.h"
|
2015-05-29 13:28:54 +03:00
|
|
|
|
2015-05-29 13:28:55 +03:00
|
|
|
#define ARM_SPI_BASE 32
|
2015-12-17 16:37:14 +03:00
|
|
|
#define ACPI_POWER_BUTTON_DEVICE "PWRB"
|
2015-05-29 13:28:55 +03:00
|
|
|
|
|
|
|
static void acpi_dsdt_add_cpus(Aml *scope, int smp_cpus)
|
|
|
|
{
|
|
|
|
uint16_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < smp_cpus; i++) {
|
2016-09-06 21:52:17 +03:00
|
|
|
Aml *dev = aml_device("C%.03X", i);
|
2015-05-29 13:28:55 +03:00
|
|
|
aml_append(dev, aml_name_decl("_HID", aml_string("ACPI0007")));
|
|
|
|
aml_append(dev, aml_name_decl("_UID", aml_int(i)));
|
|
|
|
aml_append(scope, dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap,
|
2015-12-17 16:37:13 +03:00
|
|
|
uint32_t uart_irq)
|
2015-05-29 13:28:55 +03:00
|
|
|
{
|
|
|
|
Aml *dev = aml_device("COM0");
|
|
|
|
aml_append(dev, aml_name_decl("_HID", aml_string("ARMH0011")));
|
|
|
|
aml_append(dev, aml_name_decl("_UID", aml_int(0)));
|
|
|
|
|
|
|
|
Aml *crs = aml_resource_template();
|
|
|
|
aml_append(crs, aml_memory32_fixed(uart_memmap->base,
|
|
|
|
uart_memmap->size, AML_READ_WRITE));
|
|
|
|
aml_append(crs,
|
|
|
|
aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
|
2015-12-17 16:37:13 +03:00
|
|
|
AML_EXCLUSIVE, &uart_irq, 1));
|
2015-05-29 13:28:55 +03:00
|
|
|
aml_append(dev, aml_name_decl("_CRS", crs));
|
2015-06-15 20:06:11 +03:00
|
|
|
|
|
|
|
/* The _ADR entry is used to link this device to the UART described
|
|
|
|
* in the SPCR table, i.e. SPCR.base_address.address == _ADR.
|
|
|
|
*/
|
|
|
|
aml_append(dev, aml_name_decl("_ADR", aml_int(uart_memmap->base)));
|
|
|
|
|
2015-05-29 13:28:55 +03:00
|
|
|
aml_append(scope, dev);
|
|
|
|
}
|
|
|
|
|
2016-02-19 21:20:28 +03:00
|
|
|
static void acpi_dsdt_add_fw_cfg(Aml *scope, const MemMapEntry *fw_cfg_memmap)
|
|
|
|
{
|
|
|
|
Aml *dev = aml_device("FWCF");
|
|
|
|
aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
|
|
|
|
/* device present, functioning, decoding, not shown in UI */
|
|
|
|
aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
|
|
|
|
|
|
|
|
Aml *crs = aml_resource_template();
|
|
|
|
aml_append(crs, aml_memory32_fixed(fw_cfg_memmap->base,
|
|
|
|
fw_cfg_memmap->size, AML_READ_WRITE));
|
|
|
|
aml_append(dev, aml_name_decl("_CRS", crs));
|
|
|
|
aml_append(scope, dev);
|
|
|
|
}
|
|
|
|
|
2015-05-29 13:28:55 +03:00
|
|
|
static void acpi_dsdt_add_flash(Aml *scope, const MemMapEntry *flash_memmap)
|
|
|
|
{
|
|
|
|
Aml *dev, *crs;
|
|
|
|
hwaddr base = flash_memmap->base;
|
2015-09-24 03:29:37 +03:00
|
|
|
hwaddr size = flash_memmap->size / 2;
|
2015-05-29 13:28:55 +03:00
|
|
|
|
|
|
|
dev = aml_device("FLS0");
|
|
|
|
aml_append(dev, aml_name_decl("_HID", aml_string("LNRO0015")));
|
|
|
|
aml_append(dev, aml_name_decl("_UID", aml_int(0)));
|
|
|
|
|
|
|
|
crs = aml_resource_template();
|
|
|
|
aml_append(crs, aml_memory32_fixed(base, size, AML_READ_WRITE));
|
|
|
|
aml_append(dev, aml_name_decl("_CRS", crs));
|
|
|
|
aml_append(scope, dev);
|
|
|
|
|
|
|
|
dev = aml_device("FLS1");
|
|
|
|
aml_append(dev, aml_name_decl("_HID", aml_string("LNRO0015")));
|
|
|
|
aml_append(dev, aml_name_decl("_UID", aml_int(1)));
|
|
|
|
crs = aml_resource_template();
|
|
|
|
aml_append(crs, aml_memory32_fixed(base + size, size, AML_READ_WRITE));
|
|
|
|
aml_append(dev, aml_name_decl("_CRS", crs));
|
|
|
|
aml_append(scope, dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void acpi_dsdt_add_virtio(Aml *scope,
|
|
|
|
const MemMapEntry *virtio_mmio_memmap,
|
2015-12-17 16:37:13 +03:00
|
|
|
uint32_t mmio_irq, int num)
|
2015-05-29 13:28:55 +03:00
|
|
|
{
|
|
|
|
hwaddr base = virtio_mmio_memmap->base;
|
|
|
|
hwaddr size = virtio_mmio_memmap->size;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
2015-12-17 16:37:13 +03:00
|
|
|
uint32_t irq = mmio_irq + i;
|
2015-05-29 13:28:55 +03:00
|
|
|
Aml *dev = aml_device("VR%02u", i);
|
|
|
|
aml_append(dev, aml_name_decl("_HID", aml_string("LNRO0005")));
|
|
|
|
aml_append(dev, aml_name_decl("_UID", aml_int(i)));
|
|
|
|
|
|
|
|
Aml *crs = aml_resource_template();
|
|
|
|
aml_append(crs, aml_memory32_fixed(base, size, AML_READ_WRITE));
|
|
|
|
aml_append(crs,
|
|
|
|
aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
|
2015-12-17 16:37:13 +03:00
|
|
|
AML_EXCLUSIVE, &irq, 1));
|
2015-05-29 13:28:55 +03:00
|
|
|
aml_append(dev, aml_name_decl("_CRS", crs));
|
|
|
|
aml_append(scope, dev);
|
|
|
|
base += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-17 16:37:13 +03:00
|
|
|
static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap,
|
|
|
|
uint32_t irq, bool use_highmem)
|
2015-05-29 13:28:59 +03:00
|
|
|
{
|
|
|
|
Aml *method, *crs, *ifctx, *UUID, *ifctx1, *elsectx, *buf;
|
|
|
|
int i, bus_no;
|
|
|
|
hwaddr base_mmio = memmap[VIRT_PCIE_MMIO].base;
|
|
|
|
hwaddr size_mmio = memmap[VIRT_PCIE_MMIO].size;
|
|
|
|
hwaddr base_pio = memmap[VIRT_PCIE_PIO].base;
|
|
|
|
hwaddr size_pio = memmap[VIRT_PCIE_PIO].size;
|
|
|
|
hwaddr base_ecam = memmap[VIRT_PCIE_ECAM].base;
|
|
|
|
hwaddr size_ecam = memmap[VIRT_PCIE_ECAM].size;
|
|
|
|
int nr_pcie_buses = size_ecam / PCIE_MMCFG_SIZE_MIN;
|
|
|
|
|
|
|
|
Aml *dev = aml_device("%s", "PCI0");
|
|
|
|
aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A08")));
|
|
|
|
aml_append(dev, aml_name_decl("_CID", aml_string("PNP0A03")));
|
|
|
|
aml_append(dev, aml_name_decl("_SEG", aml_int(0)));
|
|
|
|
aml_append(dev, aml_name_decl("_BBN", aml_int(0)));
|
|
|
|
aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
|
|
|
|
aml_append(dev, aml_name_decl("_UID", aml_string("PCI0")));
|
|
|
|
aml_append(dev, aml_name_decl("_STR", aml_unicode("PCIe 0 Device")));
|
2015-11-03 16:49:42 +03:00
|
|
|
aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
|
2015-05-29 13:28:59 +03:00
|
|
|
|
|
|
|
/* Declare the PCI Routing Table. */
|
|
|
|
Aml *rt_pkg = aml_package(nr_pcie_buses * PCI_NUM_PINS);
|
|
|
|
for (bus_no = 0; bus_no < nr_pcie_buses; bus_no++) {
|
|
|
|
for (i = 0; i < PCI_NUM_PINS; i++) {
|
|
|
|
int gsi = (i + bus_no) % PCI_NUM_PINS;
|
|
|
|
Aml *pkg = aml_package(4);
|
|
|
|
aml_append(pkg, aml_int((bus_no << 16) | 0xFFFF));
|
|
|
|
aml_append(pkg, aml_int(i));
|
|
|
|
aml_append(pkg, aml_name("GSI%d", gsi));
|
|
|
|
aml_append(pkg, aml_int(0));
|
|
|
|
aml_append(rt_pkg, pkg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aml_append(dev, aml_name_decl("_PRT", rt_pkg));
|
|
|
|
|
|
|
|
/* Create GSI link device */
|
|
|
|
for (i = 0; i < PCI_NUM_PINS; i++) {
|
2015-12-17 16:37:13 +03:00
|
|
|
uint32_t irqs = irq + i;
|
2015-05-29 13:28:59 +03:00
|
|
|
Aml *dev_gsi = aml_device("GSI%d", i);
|
|
|
|
aml_append(dev_gsi, aml_name_decl("_HID", aml_string("PNP0C0F")));
|
|
|
|
aml_append(dev_gsi, aml_name_decl("_UID", aml_int(0)));
|
|
|
|
crs = aml_resource_template();
|
|
|
|
aml_append(crs,
|
|
|
|
aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
|
2015-12-17 16:37:13 +03:00
|
|
|
AML_EXCLUSIVE, &irqs, 1));
|
2015-05-29 13:28:59 +03:00
|
|
|
aml_append(dev_gsi, aml_name_decl("_PRS", crs));
|
|
|
|
crs = aml_resource_template();
|
|
|
|
aml_append(crs,
|
|
|
|
aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
|
2015-12-17 16:37:13 +03:00
|
|
|
AML_EXCLUSIVE, &irqs, 1));
|
2015-05-29 13:28:59 +03:00
|
|
|
aml_append(dev_gsi, aml_name_decl("_CRS", crs));
|
2015-12-17 16:37:13 +03:00
|
|
|
method = aml_method("_SRS", 1, AML_NOTSERIALIZED);
|
2015-05-29 13:28:59 +03:00
|
|
|
aml_append(dev_gsi, method);
|
|
|
|
aml_append(dev, dev_gsi);
|
|
|
|
}
|
|
|
|
|
2015-12-17 16:37:13 +03:00
|
|
|
method = aml_method("_CBA", 0, AML_NOTSERIALIZED);
|
2015-05-29 13:28:59 +03:00
|
|
|
aml_append(method, aml_return(aml_int(base_ecam)));
|
|
|
|
aml_append(dev, method);
|
|
|
|
|
2015-12-17 16:37:13 +03:00
|
|
|
method = aml_method("_CRS", 0, AML_NOTSERIALIZED);
|
2015-05-29 13:28:59 +03:00
|
|
|
Aml *rbuf = aml_resource_template();
|
|
|
|
aml_append(rbuf,
|
|
|
|
aml_word_bus_number(AML_MIN_FIXED, AML_MAX_FIXED, AML_POS_DECODE,
|
|
|
|
0x0000, 0x0000, nr_pcie_buses - 1, 0x0000,
|
|
|
|
nr_pcie_buses));
|
|
|
|
aml_append(rbuf,
|
|
|
|
aml_dword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,
|
|
|
|
AML_NON_CACHEABLE, AML_READ_WRITE, 0x0000, base_mmio,
|
|
|
|
base_mmio + size_mmio - 1, 0x0000, size_mmio));
|
|
|
|
aml_append(rbuf,
|
|
|
|
aml_dword_io(AML_MIN_FIXED, AML_MAX_FIXED, AML_POS_DECODE,
|
|
|
|
AML_ENTIRE_RANGE, 0x0000, 0x0000, size_pio - 1, base_pio,
|
|
|
|
size_pio));
|
|
|
|
|
2015-09-07 12:39:29 +03:00
|
|
|
if (use_highmem) {
|
|
|
|
hwaddr base_mmio_high = memmap[VIRT_PCIE_MMIO_HIGH].base;
|
|
|
|
hwaddr size_mmio_high = memmap[VIRT_PCIE_MMIO_HIGH].size;
|
|
|
|
|
|
|
|
aml_append(rbuf,
|
|
|
|
aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,
|
|
|
|
AML_NON_CACHEABLE, AML_READ_WRITE, 0x0000,
|
2016-06-06 18:59:28 +03:00
|
|
|
base_mmio_high,
|
|
|
|
base_mmio_high + size_mmio_high - 1, 0x0000,
|
2015-09-07 12:39:29 +03:00
|
|
|
size_mmio_high));
|
|
|
|
}
|
|
|
|
|
2015-05-29 13:28:59 +03:00
|
|
|
aml_append(method, aml_name_decl("RBUF", rbuf));
|
|
|
|
aml_append(method, aml_return(rbuf));
|
|
|
|
aml_append(dev, method);
|
|
|
|
|
|
|
|
/* Declare an _OSC (OS Control Handoff) method */
|
|
|
|
aml_append(dev, aml_name_decl("SUPP", aml_int(0)));
|
|
|
|
aml_append(dev, aml_name_decl("CTRL", aml_int(0)));
|
2015-12-17 16:37:13 +03:00
|
|
|
method = aml_method("_OSC", 4, AML_NOTSERIALIZED);
|
2015-05-29 13:28:59 +03:00
|
|
|
aml_append(method,
|
|
|
|
aml_create_dword_field(aml_arg(3), aml_int(0), "CDW1"));
|
|
|
|
|
|
|
|
/* PCI Firmware Specification 3.0
|
|
|
|
* 4.5.1. _OSC Interface for PCI Host Bridge Devices
|
|
|
|
* The _OSC interface for a PCI/PCI-X/PCI Express hierarchy is
|
|
|
|
* identified by the Universal Unique IDentifier (UUID)
|
|
|
|
* 33DB4D5B-1FF7-401C-9657-7441C03DD766
|
|
|
|
*/
|
|
|
|
UUID = aml_touuid("33DB4D5B-1FF7-401C-9657-7441C03DD766");
|
|
|
|
ifctx = aml_if(aml_equal(aml_arg(0), UUID));
|
|
|
|
aml_append(ifctx,
|
|
|
|
aml_create_dword_field(aml_arg(3), aml_int(4), "CDW2"));
|
|
|
|
aml_append(ifctx,
|
|
|
|
aml_create_dword_field(aml_arg(3), aml_int(8), "CDW3"));
|
|
|
|
aml_append(ifctx, aml_store(aml_name("CDW2"), aml_name("SUPP")));
|
|
|
|
aml_append(ifctx, aml_store(aml_name("CDW3"), aml_name("CTRL")));
|
2015-12-10 02:41:17 +03:00
|
|
|
aml_append(ifctx, aml_store(aml_and(aml_name("CTRL"), aml_int(0x1D), NULL),
|
2015-05-29 13:28:59 +03:00
|
|
|
aml_name("CTRL")));
|
|
|
|
|
|
|
|
ifctx1 = aml_if(aml_lnot(aml_equal(aml_arg(1), aml_int(0x1))));
|
2015-12-10 02:41:16 +03:00
|
|
|
aml_append(ifctx1, aml_store(aml_or(aml_name("CDW1"), aml_int(0x08), NULL),
|
2015-05-29 13:28:59 +03:00
|
|
|
aml_name("CDW1")));
|
|
|
|
aml_append(ifctx, ifctx1);
|
|
|
|
|
|
|
|
ifctx1 = aml_if(aml_lnot(aml_equal(aml_name("CDW3"), aml_name("CTRL"))));
|
2015-12-10 02:41:16 +03:00
|
|
|
aml_append(ifctx1, aml_store(aml_or(aml_name("CDW1"), aml_int(0x10), NULL),
|
2015-05-29 13:28:59 +03:00
|
|
|
aml_name("CDW1")));
|
|
|
|
aml_append(ifctx, ifctx1);
|
|
|
|
|
|
|
|
aml_append(ifctx, aml_store(aml_name("CTRL"), aml_name("CDW3")));
|
|
|
|
aml_append(ifctx, aml_return(aml_arg(3)));
|
|
|
|
aml_append(method, ifctx);
|
|
|
|
|
|
|
|
elsectx = aml_else();
|
2015-12-10 02:41:16 +03:00
|
|
|
aml_append(elsectx, aml_store(aml_or(aml_name("CDW1"), aml_int(4), NULL),
|
2015-05-29 13:28:59 +03:00
|
|
|
aml_name("CDW1")));
|
|
|
|
aml_append(elsectx, aml_return(aml_arg(3)));
|
|
|
|
aml_append(method, elsectx);
|
|
|
|
aml_append(dev, method);
|
|
|
|
|
2015-12-17 16:37:13 +03:00
|
|
|
method = aml_method("_DSM", 4, AML_NOTSERIALIZED);
|
2015-05-29 13:28:59 +03:00
|
|
|
|
|
|
|
/* PCI Firmware Specification 3.0
|
|
|
|
* 4.6.1. _DSM for PCI Express Slot Information
|
|
|
|
* The UUID in _DSM in this context is
|
|
|
|
* {E5C937D0-3553-4D7A-9117-EA4D19C3434D}
|
|
|
|
*/
|
|
|
|
UUID = aml_touuid("E5C937D0-3553-4D7A-9117-EA4D19C3434D");
|
|
|
|
ifctx = aml_if(aml_equal(aml_arg(0), UUID));
|
|
|
|
ifctx1 = aml_if(aml_equal(aml_arg(2), aml_int(0)));
|
|
|
|
uint8_t byte_list[1] = {1};
|
|
|
|
buf = aml_buffer(1, byte_list);
|
|
|
|
aml_append(ifctx1, aml_return(buf));
|
|
|
|
aml_append(ifctx, ifctx1);
|
|
|
|
aml_append(method, ifctx);
|
|
|
|
|
|
|
|
byte_list[0] = 0;
|
|
|
|
buf = aml_buffer(1, byte_list);
|
|
|
|
aml_append(method, aml_return(buf));
|
|
|
|
aml_append(dev, method);
|
|
|
|
|
|
|
|
Aml *dev_rp0 = aml_device("%s", "RP0");
|
|
|
|
aml_append(dev_rp0, aml_name_decl("_ADR", aml_int(0)));
|
|
|
|
aml_append(dev, dev_rp0);
|
|
|
|
aml_append(scope, dev);
|
|
|
|
}
|
|
|
|
|
2015-12-17 16:37:14 +03:00
|
|
|
static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap,
|
|
|
|
uint32_t gpio_irq)
|
|
|
|
{
|
|
|
|
Aml *dev = aml_device("GPO0");
|
|
|
|
aml_append(dev, aml_name_decl("_HID", aml_string("ARMH0061")));
|
|
|
|
aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
|
|
|
|
aml_append(dev, aml_name_decl("_UID", aml_int(0)));
|
|
|
|
|
|
|
|
Aml *crs = aml_resource_template();
|
|
|
|
aml_append(crs, aml_memory32_fixed(gpio_memmap->base, gpio_memmap->size,
|
|
|
|
AML_READ_WRITE));
|
|
|
|
aml_append(crs, aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
|
|
|
|
AML_EXCLUSIVE, &gpio_irq, 1));
|
|
|
|
aml_append(dev, aml_name_decl("_CRS", crs));
|
2015-12-17 16:37:14 +03:00
|
|
|
|
|
|
|
Aml *aei = aml_resource_template();
|
|
|
|
/* Pin 3 for power button */
|
|
|
|
const uint32_t pin_list[1] = {3};
|
|
|
|
aml_append(aei, aml_gpio_int(AML_CONSUMER, AML_EDGE, AML_ACTIVE_HIGH,
|
|
|
|
AML_EXCLUSIVE, AML_PULL_UP, 0, pin_list, 1,
|
|
|
|
"GPO0", NULL, 0));
|
|
|
|
aml_append(dev, aml_name_decl("_AEI", aei));
|
|
|
|
|
|
|
|
/* _E03 is handle for power button */
|
|
|
|
Aml *method = aml_method("_E03", 0, AML_NOTSERIALIZED);
|
|
|
|
aml_append(method, aml_notify(aml_name(ACPI_POWER_BUTTON_DEVICE),
|
|
|
|
aml_int(0x80)));
|
|
|
|
aml_append(dev, method);
|
2015-12-17 16:37:14 +03:00
|
|
|
aml_append(scope, dev);
|
|
|
|
}
|
|
|
|
|
2015-12-17 16:37:14 +03:00
|
|
|
static void acpi_dsdt_add_power_button(Aml *scope)
|
|
|
|
{
|
|
|
|
Aml *dev = aml_device(ACPI_POWER_BUTTON_DEVICE);
|
|
|
|
aml_append(dev, aml_name_decl("_HID", aml_string("PNP0C0C")));
|
|
|
|
aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
|
|
|
|
aml_append(dev, aml_name_decl("_UID", aml_int(0)));
|
|
|
|
aml_append(scope, dev);
|
|
|
|
}
|
|
|
|
|
2015-05-29 13:28:56 +03:00
|
|
|
/* RSDP */
|
|
|
|
static GArray *
|
2016-05-19 16:19:29 +03:00
|
|
|
build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)
|
2015-05-29 13:28:56 +03:00
|
|
|
{
|
|
|
|
AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
|
2016-05-19 16:19:29 +03:00
|
|
|
unsigned rsdt_pa_size = sizeof(rsdp->rsdt_physical_address);
|
|
|
|
unsigned rsdt_pa_offset =
|
|
|
|
(char *)&rsdp->rsdt_physical_address - rsdp_table->data;
|
2015-05-29 13:28:56 +03:00
|
|
|
|
2016-05-19 16:19:26 +03:00
|
|
|
bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, rsdp_table, 16,
|
2015-05-29 13:28:56 +03:00
|
|
|
true /* fseg memory */);
|
|
|
|
|
|
|
|
memcpy(&rsdp->signature, "RSD PTR ", sizeof(rsdp->signature));
|
|
|
|
memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, sizeof(rsdp->oem_id));
|
|
|
|
rsdp->length = cpu_to_le32(sizeof(*rsdp));
|
|
|
|
rsdp->revision = 0x02;
|
|
|
|
|
|
|
|
/* Address to be filled by Guest linker */
|
2016-05-19 16:19:29 +03:00
|
|
|
bios_linker_loader_add_pointer(linker,
|
|
|
|
ACPI_BUILD_RSDP_FILE, rsdt_pa_offset, rsdt_pa_size,
|
|
|
|
ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset);
|
|
|
|
|
2015-05-29 13:28:56 +03:00
|
|
|
/* Checksum to be filled by Guest linker */
|
|
|
|
bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
|
2016-05-19 16:19:30 +03:00
|
|
|
(char *)rsdp - rsdp_table->data, sizeof *rsdp,
|
|
|
|
(char *)&rsdp->checksum - rsdp_table->data);
|
2015-05-29 13:28:56 +03:00
|
|
|
|
|
|
|
return rsdp_table;
|
|
|
|
}
|
|
|
|
|
2016-10-24 18:26:54 +03:00
|
|
|
static void
|
2017-01-09 14:40:22 +03:00
|
|
|
build_iort(GArray *table_data, BIOSLinker *linker)
|
2016-10-24 18:26:54 +03:00
|
|
|
{
|
|
|
|
int iort_start = table_data->len;
|
|
|
|
AcpiIortIdMapping *idmap;
|
|
|
|
AcpiIortItsGroup *its;
|
|
|
|
AcpiIortTable *iort;
|
|
|
|
size_t node_size, iort_length;
|
|
|
|
AcpiIortRC *rc;
|
|
|
|
|
|
|
|
iort = acpi_data_push(table_data, sizeof(*iort));
|
|
|
|
|
|
|
|
iort_length = sizeof(*iort);
|
|
|
|
iort->node_count = cpu_to_le32(2); /* RC and ITS nodes */
|
|
|
|
iort->node_offset = cpu_to_le32(sizeof(*iort));
|
|
|
|
|
|
|
|
/* ITS group node */
|
|
|
|
node_size = sizeof(*its) + sizeof(uint32_t);
|
|
|
|
iort_length += node_size;
|
|
|
|
its = acpi_data_push(table_data, node_size);
|
|
|
|
|
|
|
|
its->type = ACPI_IORT_NODE_ITS_GROUP;
|
|
|
|
its->length = cpu_to_le16(node_size);
|
|
|
|
its->its_count = cpu_to_le32(1);
|
|
|
|
its->identifiers[0] = 0; /* MADT translation_id */
|
|
|
|
|
|
|
|
/* Root Complex Node */
|
|
|
|
node_size = sizeof(*rc) + sizeof(*idmap);
|
|
|
|
iort_length += node_size;
|
|
|
|
rc = acpi_data_push(table_data, node_size);
|
|
|
|
|
|
|
|
rc->type = ACPI_IORT_NODE_PCI_ROOT_COMPLEX;
|
|
|
|
rc->length = cpu_to_le16(node_size);
|
|
|
|
rc->mapping_count = cpu_to_le32(1);
|
|
|
|
rc->mapping_offset = cpu_to_le32(sizeof(*rc));
|
|
|
|
|
|
|
|
/* fully coherent device */
|
|
|
|
rc->memory_properties.cache_coherency = cpu_to_le32(1);
|
|
|
|
rc->memory_properties.memory_flags = 0x3; /* CCA = CPM = DCAS = 1 */
|
|
|
|
rc->pci_segment_number = 0; /* MCFG pci_segment */
|
|
|
|
|
|
|
|
/* Identity RID mapping covering the whole input RID range */
|
|
|
|
idmap = &rc->id_mapping_array[0];
|
|
|
|
idmap->input_base = 0;
|
|
|
|
idmap->id_count = cpu_to_le32(0xFFFF);
|
|
|
|
idmap->output_base = 0;
|
|
|
|
/* output IORT node is the ITS group node (the first node) */
|
|
|
|
idmap->output_reference = cpu_to_le32(iort->node_offset);
|
|
|
|
|
|
|
|
iort->length = cpu_to_le32(iort_length);
|
|
|
|
|
|
|
|
build_header(linker, table_data, (void *)(table_data->data + iort_start),
|
|
|
|
"IORT", table_data->len - iort_start, 0, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2015-06-15 20:06:11 +03:00
|
|
|
static void
|
2017-01-09 14:40:22 +03:00
|
|
|
build_spcr(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
|
2015-06-15 20:06:11 +03:00
|
|
|
{
|
|
|
|
AcpiSerialPortConsoleRedirection *spcr;
|
2017-01-09 14:40:22 +03:00
|
|
|
const MemMapEntry *uart_memmap = &vms->memmap[VIRT_UART];
|
|
|
|
int irq = vms->irqmap[VIRT_UART] + ARM_SPI_BASE;
|
2015-06-15 20:06:11 +03:00
|
|
|
|
|
|
|
spcr = acpi_data_push(table_data, sizeof(*spcr));
|
|
|
|
|
|
|
|
spcr->interface_type = 0x3; /* ARM PL011 UART */
|
|
|
|
|
|
|
|
spcr->base_address.space_id = AML_SYSTEM_MEMORY;
|
|
|
|
spcr->base_address.bit_width = 8;
|
|
|
|
spcr->base_address.bit_offset = 0;
|
|
|
|
spcr->base_address.access_width = 1;
|
|
|
|
spcr->base_address.address = cpu_to_le64(uart_memmap->base);
|
|
|
|
|
|
|
|
spcr->interrupt_types = (1 << 3); /* Bit[3] ARMH GIC interrupt */
|
|
|
|
spcr->gsi = cpu_to_le32(irq); /* Global System Interrupt */
|
|
|
|
|
|
|
|
spcr->baud = 3; /* Baud Rate: 3 = 9600 */
|
|
|
|
spcr->parity = 0; /* No Parity */
|
|
|
|
spcr->stopbits = 1; /* 1 Stop bit */
|
|
|
|
spcr->flowctrl = (1 << 1); /* Bit[1] = RTS/CTS hardware flow control */
|
|
|
|
spcr->term_type = 0; /* Terminal Type: 0 = VT100 */
|
|
|
|
|
|
|
|
spcr->pci_device_id = 0xffff; /* PCI Device ID: not a PCI device */
|
|
|
|
spcr->pci_vendor_id = 0xffff; /* PCI Vendor ID: not a PCI device */
|
|
|
|
|
2015-12-02 10:20:57 +03:00
|
|
|
build_header(linker, table_data, (void *)spcr, "SPCR", sizeof(*spcr), 2,
|
2016-01-18 17:12:10 +03:00
|
|
|
NULL, NULL);
|
2015-06-15 20:06:11 +03:00
|
|
|
}
|
|
|
|
|
2016-05-12 15:22:28 +03:00
|
|
|
static void
|
2017-01-09 14:40:22 +03:00
|
|
|
build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
|
2016-05-12 15:22:28 +03:00
|
|
|
{
|
|
|
|
AcpiSystemResourceAffinityTable *srat;
|
|
|
|
AcpiSratProcessorGiccAffinity *core;
|
|
|
|
AcpiSratMemoryAffinity *numamem;
|
|
|
|
int i, j, srat_start;
|
|
|
|
uint64_t mem_base;
|
2017-01-09 14:40:22 +03:00
|
|
|
uint32_t *cpu_node = g_malloc0(vms->smp_cpus * sizeof(uint32_t));
|
2016-05-12 15:22:28 +03:00
|
|
|
|
2017-01-09 14:40:22 +03:00
|
|
|
for (i = 0; i < vms->smp_cpus; i++) {
|
2016-10-05 18:51:23 +03:00
|
|
|
j = numa_get_node_for_cpu(i);
|
|
|
|
if (j < nb_numa_nodes) {
|
2016-05-12 15:22:28 +03:00
|
|
|
cpu_node[i] = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
srat_start = table_data->len;
|
|
|
|
srat = acpi_data_push(table_data, sizeof(*srat));
|
|
|
|
srat->reserved1 = cpu_to_le32(1);
|
|
|
|
|
2017-01-09 14:40:22 +03:00
|
|
|
for (i = 0; i < vms->smp_cpus; ++i) {
|
2016-05-12 15:22:28 +03:00
|
|
|
core = acpi_data_push(table_data, sizeof(*core));
|
|
|
|
core->type = ACPI_SRAT_PROCESSOR_GICC;
|
|
|
|
core->length = sizeof(*core);
|
|
|
|
core->proximity = cpu_to_le32(cpu_node[i]);
|
|
|
|
core->acpi_processor_uid = cpu_to_le32(i);
|
|
|
|
core->flags = cpu_to_le32(1);
|
|
|
|
}
|
|
|
|
g_free(cpu_node);
|
|
|
|
|
2017-01-09 14:40:22 +03:00
|
|
|
mem_base = vms->memmap[VIRT_MEM].base;
|
2016-05-12 15:22:28 +03:00
|
|
|
for (i = 0; i < nb_numa_nodes; ++i) {
|
|
|
|
numamem = acpi_data_push(table_data, sizeof(*numamem));
|
|
|
|
build_srat_memory(numamem, mem_base, numa_info[i].node_mem, i,
|
|
|
|
MEM_AFFINITY_ENABLED);
|
|
|
|
mem_base += numa_info[i].node_mem;
|
|
|
|
}
|
|
|
|
|
2016-05-19 16:19:25 +03:00
|
|
|
build_header(linker, table_data, (void *)srat, "SRAT",
|
2016-05-12 15:22:28 +03:00
|
|
|
table_data->len - srat_start, 3, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2015-05-29 13:28:57 +03:00
|
|
|
static void
|
2017-01-09 14:40:22 +03:00
|
|
|
build_mcfg(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
|
2015-05-29 13:28:57 +03:00
|
|
|
{
|
|
|
|
AcpiTableMcfg *mcfg;
|
2017-01-09 14:40:22 +03:00
|
|
|
const MemMapEntry *memmap = vms->memmap;
|
2015-05-29 13:28:57 +03:00
|
|
|
int len = sizeof(*mcfg) + sizeof(mcfg->allocation[0]);
|
|
|
|
|
|
|
|
mcfg = acpi_data_push(table_data, len);
|
|
|
|
mcfg->allocation[0].address = cpu_to_le64(memmap[VIRT_PCIE_ECAM].base);
|
|
|
|
|
|
|
|
/* Only a single allocation so no need to play with segments */
|
|
|
|
mcfg->allocation[0].pci_segment = cpu_to_le16(0);
|
|
|
|
mcfg->allocation[0].start_bus_number = 0;
|
|
|
|
mcfg->allocation[0].end_bus_number = (memmap[VIRT_PCIE_ECAM].size
|
|
|
|
/ PCIE_MMCFG_SIZE_MIN) - 1;
|
|
|
|
|
2016-01-18 17:12:10 +03:00
|
|
|
build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL, NULL);
|
2015-05-29 13:28:57 +03:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:28:56 +03:00
|
|
|
/* GTDT */
|
|
|
|
static void
|
2016-05-19 16:19:25 +03:00
|
|
|
build_gtdt(GArray *table_data, BIOSLinker *linker)
|
2015-05-29 13:28:56 +03:00
|
|
|
{
|
|
|
|
int gtdt_start = table_data->len;
|
|
|
|
AcpiGenericTimerTable *gtdt;
|
|
|
|
|
|
|
|
gtdt = acpi_data_push(table_data, sizeof *gtdt);
|
|
|
|
/* The interrupt values are the same with the device tree when adding 16 */
|
2017-01-09 14:40:21 +03:00
|
|
|
gtdt->secure_el1_interrupt = cpu_to_le32(ARCH_TIMER_S_EL1_IRQ + 16);
|
2017-01-09 14:40:21 +03:00
|
|
|
gtdt->secure_el1_flags = cpu_to_le32(ACPI_GTDT_INTERRUPT_MODE_EDGE);
|
2015-05-29 13:28:56 +03:00
|
|
|
|
2017-01-09 14:40:21 +03:00
|
|
|
gtdt->non_secure_el1_interrupt = cpu_to_le32(ARCH_TIMER_NS_EL1_IRQ + 16);
|
2017-01-09 14:40:21 +03:00
|
|
|
gtdt->non_secure_el1_flags = cpu_to_le32(ACPI_GTDT_INTERRUPT_MODE_EDGE |
|
|
|
|
ACPI_GTDT_CAP_ALWAYS_ON);
|
2015-05-29 13:28:56 +03:00
|
|
|
|
2017-01-09 14:40:21 +03:00
|
|
|
gtdt->virtual_timer_interrupt = cpu_to_le32(ARCH_TIMER_VIRT_IRQ + 16);
|
2017-01-09 14:40:21 +03:00
|
|
|
gtdt->virtual_timer_flags = cpu_to_le32(ACPI_GTDT_INTERRUPT_MODE_EDGE);
|
2015-05-29 13:28:56 +03:00
|
|
|
|
2017-01-09 14:40:21 +03:00
|
|
|
gtdt->non_secure_el2_interrupt = cpu_to_le32(ARCH_TIMER_NS_EL2_IRQ + 16);
|
2017-01-09 14:40:21 +03:00
|
|
|
gtdt->non_secure_el2_flags = cpu_to_le32(ACPI_GTDT_INTERRUPT_MODE_EDGE);
|
2015-05-29 13:28:56 +03:00
|
|
|
|
|
|
|
build_header(linker, table_data,
|
|
|
|
(void *)(table_data->data + gtdt_start), "GTDT",
|
2016-01-18 17:12:10 +03:00
|
|
|
table_data->len - gtdt_start, 2, NULL, NULL);
|
2015-05-29 13:28:56 +03:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:28:56 +03:00
|
|
|
/* MADT */
|
|
|
|
static void
|
2017-01-09 14:40:22 +03:00
|
|
|
build_madt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
|
2015-05-29 13:28:56 +03:00
|
|
|
{
|
2017-01-09 14:40:22 +03:00
|
|
|
VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
|
2015-05-29 13:28:56 +03:00
|
|
|
int madt_start = table_data->len;
|
2017-01-09 14:40:22 +03:00
|
|
|
const MemMapEntry *memmap = vms->memmap;
|
|
|
|
const int *irqmap = vms->irqmap;
|
2015-05-29 13:28:56 +03:00
|
|
|
AcpiMultipleApicTable *madt;
|
|
|
|
AcpiMadtGenericDistributor *gicd;
|
2015-06-26 16:22:36 +03:00
|
|
|
AcpiMadtGenericMsiFrame *gic_msi;
|
2015-05-29 13:28:56 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
madt = acpi_data_push(table_data, sizeof *madt);
|
|
|
|
|
|
|
|
gicd = acpi_data_push(table_data, sizeof *gicd);
|
|
|
|
gicd->type = ACPI_APIC_GENERIC_DISTRIBUTOR;
|
|
|
|
gicd->length = sizeof(*gicd);
|
2017-01-09 14:40:21 +03:00
|
|
|
gicd->base_address = cpu_to_le64(memmap[VIRT_GIC_DIST].base);
|
2017-01-09 14:40:22 +03:00
|
|
|
gicd->version = vms->gic_version;
|
2015-05-29 13:28:56 +03:00
|
|
|
|
2017-01-09 14:40:22 +03:00
|
|
|
for (i = 0; i < vms->smp_cpus; i++) {
|
2017-01-09 14:40:21 +03:00
|
|
|
AcpiMadtGenericCpuInterface *gicc = acpi_data_push(table_data,
|
|
|
|
sizeof(*gicc));
|
2015-11-03 16:49:42 +03:00
|
|
|
ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(i));
|
|
|
|
|
2017-01-09 14:40:21 +03:00
|
|
|
gicc->type = ACPI_APIC_GENERIC_CPU_INTERFACE;
|
2015-11-03 16:49:42 +03:00
|
|
|
gicc->length = sizeof(*gicc);
|
2017-01-09 14:40:22 +03:00
|
|
|
if (vms->gic_version == 2) {
|
2017-01-09 14:40:21 +03:00
|
|
|
gicc->base_address = cpu_to_le64(memmap[VIRT_GIC_CPU].base);
|
2015-11-03 16:49:42 +03:00
|
|
|
}
|
2017-01-09 14:40:21 +03:00
|
|
|
gicc->cpu_interface_number = cpu_to_le32(i);
|
|
|
|
gicc->arm_mpidr = cpu_to_le64(armcpu->mp_affinity);
|
|
|
|
gicc->uid = cpu_to_le32(i);
|
2017-01-09 14:40:21 +03:00
|
|
|
gicc->flags = cpu_to_le32(ACPI_MADT_GICC_ENABLED);
|
2016-06-14 17:59:12 +03:00
|
|
|
|
2016-10-28 16:12:31 +03:00
|
|
|
if (arm_feature(&armcpu->env, ARM_FEATURE_PMU)) {
|
2016-06-14 17:59:12 +03:00
|
|
|
gicc->performance_interrupt = cpu_to_le32(PPI(VIRTUAL_PMU_IRQ));
|
|
|
|
}
|
2015-11-03 16:49:42 +03:00
|
|
|
}
|
|
|
|
|
2017-01-09 14:40:22 +03:00
|
|
|
if (vms->gic_version == 3) {
|
2016-10-04 15:28:09 +03:00
|
|
|
AcpiMadtGenericTranslator *gic_its;
|
2015-09-24 03:29:37 +03:00
|
|
|
AcpiMadtGenericRedistributor *gicr = acpi_data_push(table_data,
|
|
|
|
sizeof *gicr);
|
|
|
|
|
|
|
|
gicr->type = ACPI_APIC_GENERIC_REDISTRIBUTOR;
|
|
|
|
gicr->length = sizeof(*gicr);
|
|
|
|
gicr->base_address = cpu_to_le64(memmap[VIRT_GIC_REDIST].base);
|
|
|
|
gicr->range_length = cpu_to_le32(memmap[VIRT_GIC_REDIST].size);
|
2016-10-04 15:28:09 +03:00
|
|
|
|
2017-01-09 14:40:22 +03:00
|
|
|
if (its_class_name() && !vmc->no_its) {
|
2016-10-17 21:22:17 +03:00
|
|
|
gic_its = acpi_data_push(table_data, sizeof *gic_its);
|
|
|
|
gic_its->type = ACPI_APIC_GENERIC_TRANSLATOR;
|
|
|
|
gic_its->length = sizeof(*gic_its);
|
|
|
|
gic_its->translation_id = 0;
|
|
|
|
gic_its->base_address = cpu_to_le64(memmap[VIRT_GIC_ITS].base);
|
2016-10-04 15:28:09 +03:00
|
|
|
}
|
2015-09-24 03:29:37 +03:00
|
|
|
} else {
|
|
|
|
gic_msi = acpi_data_push(table_data, sizeof *gic_msi);
|
|
|
|
gic_msi->type = ACPI_APIC_GENERIC_MSI_FRAME;
|
|
|
|
gic_msi->length = sizeof(*gic_msi);
|
|
|
|
gic_msi->gic_msi_frame_id = 0;
|
|
|
|
gic_msi->base_address = cpu_to_le64(memmap[VIRT_GIC_V2M].base);
|
|
|
|
gic_msi->flags = cpu_to_le32(1);
|
|
|
|
gic_msi->spi_count = cpu_to_le16(NUM_GICV2M_SPIS);
|
|
|
|
gic_msi->spi_base = cpu_to_le16(irqmap[VIRT_GIC_V2M] + ARM_SPI_BASE);
|
|
|
|
}
|
2015-06-26 16:22:36 +03:00
|
|
|
|
2015-05-29 13:28:56 +03:00
|
|
|
build_header(linker, table_data,
|
|
|
|
(void *)(table_data->data + madt_start), "APIC",
|
2016-01-18 17:12:10 +03:00
|
|
|
table_data->len - madt_start, 3, NULL, NULL);
|
2015-05-29 13:28:56 +03:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:28:55 +03:00
|
|
|
/* FADT */
|
|
|
|
static void
|
2016-05-19 16:19:29 +03:00
|
|
|
build_fadt(GArray *table_data, BIOSLinker *linker, unsigned dsdt_tbl_offset)
|
2015-05-29 13:28:55 +03:00
|
|
|
{
|
|
|
|
AcpiFadtDescriptorRev5_1 *fadt = acpi_data_push(table_data, sizeof(*fadt));
|
2016-05-19 16:19:29 +03:00
|
|
|
unsigned dsdt_entry_offset = (char *)&fadt->dsdt - table_data->data;
|
2015-05-29 13:28:55 +03:00
|
|
|
|
|
|
|
/* Hardware Reduced = 1 and use PSCI 0.2+ and with HVC */
|
|
|
|
fadt->flags = cpu_to_le32(1 << ACPI_FADT_F_HW_REDUCED_ACPI);
|
2017-01-09 14:40:21 +03:00
|
|
|
fadt->arm_boot_flags = cpu_to_le16(ACPI_FADT_ARM_PSCI_COMPLIANT |
|
|
|
|
ACPI_FADT_ARM_PSCI_USE_HVC);
|
2015-05-29 13:28:55 +03:00
|
|
|
|
|
|
|
/* ACPI v5.1 (fadt->revision.fadt->minor_revision) */
|
|
|
|
fadt->minor_revision = 0x1;
|
|
|
|
|
|
|
|
/* DSDT address to be filled by Guest linker */
|
2016-05-19 16:19:29 +03:00
|
|
|
bios_linker_loader_add_pointer(linker,
|
|
|
|
ACPI_BUILD_TABLE_FILE, dsdt_entry_offset, sizeof(fadt->dsdt),
|
|
|
|
ACPI_BUILD_TABLE_FILE, dsdt_tbl_offset);
|
2015-05-29 13:28:55 +03:00
|
|
|
|
|
|
|
build_header(linker, table_data,
|
2016-01-18 17:12:10 +03:00
|
|
|
(void *)fadt, "FACP", sizeof(*fadt), 5, NULL, NULL);
|
2015-05-29 13:28:55 +03:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:28:55 +03:00
|
|
|
/* DSDT */
|
|
|
|
static void
|
2017-01-09 14:40:22 +03:00
|
|
|
build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
|
2015-05-29 13:28:55 +03:00
|
|
|
{
|
|
|
|
Aml *scope, *dsdt;
|
2017-01-09 14:40:22 +03:00
|
|
|
const MemMapEntry *memmap = vms->memmap;
|
|
|
|
const int *irqmap = vms->irqmap;
|
2015-05-29 13:28:55 +03:00
|
|
|
|
|
|
|
dsdt = init_aml_allocator();
|
|
|
|
/* Reserve space for header */
|
|
|
|
acpi_data_push(dsdt->buf, sizeof(AcpiTableHeader));
|
|
|
|
|
2016-01-15 17:11:31 +03:00
|
|
|
/* When booting the VM with UEFI, UEFI takes ownership of the RTC hardware.
|
|
|
|
* While UEFI can use libfdt to disable the RTC device node in the DTB that
|
|
|
|
* it passes to the OS, it cannot modify AML. Therefore, we won't generate
|
|
|
|
* the RTC ACPI device at all when using UEFI.
|
|
|
|
*/
|
2015-05-29 13:28:55 +03:00
|
|
|
scope = aml_scope("\\_SB");
|
2017-01-09 14:40:22 +03:00
|
|
|
acpi_dsdt_add_cpus(scope, vms->smp_cpus);
|
2015-05-29 13:28:55 +03:00
|
|
|
acpi_dsdt_add_uart(scope, &memmap[VIRT_UART],
|
|
|
|
(irqmap[VIRT_UART] + ARM_SPI_BASE));
|
|
|
|
acpi_dsdt_add_flash(scope, &memmap[VIRT_FLASH]);
|
2016-02-19 21:20:28 +03:00
|
|
|
acpi_dsdt_add_fw_cfg(scope, &memmap[VIRT_FW_CFG]);
|
2015-05-29 13:28:55 +03:00
|
|
|
acpi_dsdt_add_virtio(scope, &memmap[VIRT_MMIO],
|
|
|
|
(irqmap[VIRT_MMIO] + ARM_SPI_BASE), NUM_VIRTIO_TRANSPORTS);
|
2015-09-07 12:39:29 +03:00
|
|
|
acpi_dsdt_add_pci(scope, memmap, (irqmap[VIRT_PCIE] + ARM_SPI_BASE),
|
2017-01-09 14:40:22 +03:00
|
|
|
vms->highmem);
|
2015-12-17 16:37:14 +03:00
|
|
|
acpi_dsdt_add_gpio(scope, &memmap[VIRT_GPIO],
|
|
|
|
(irqmap[VIRT_GPIO] + ARM_SPI_BASE));
|
2015-12-17 16:37:14 +03:00
|
|
|
acpi_dsdt_add_power_button(scope);
|
2015-05-29 13:28:59 +03:00
|
|
|
|
2015-05-29 13:28:55 +03:00
|
|
|
aml_append(dsdt, scope);
|
|
|
|
|
|
|
|
/* copy AML table into ACPI tables blob and patch header there */
|
|
|
|
g_array_append_vals(table_data, dsdt->buf->data, dsdt->buf->len);
|
|
|
|
build_header(linker, table_data,
|
|
|
|
(void *)(table_data->data + table_data->len - dsdt->buf->len),
|
2016-01-18 17:12:10 +03:00
|
|
|
"DSDT", dsdt->buf->len, 2, NULL, NULL);
|
2015-05-29 13:28:55 +03:00
|
|
|
free_aml_allocator();
|
|
|
|
}
|
|
|
|
|
2015-05-29 13:28:54 +03:00
|
|
|
typedef
|
|
|
|
struct AcpiBuildState {
|
|
|
|
/* Copy of table in RAM (for patching). */
|
|
|
|
MemoryRegion *table_mr;
|
|
|
|
MemoryRegion *rsdp_mr;
|
|
|
|
MemoryRegion *linker_mr;
|
|
|
|
/* Is table patched? */
|
|
|
|
bool patched;
|
|
|
|
} AcpiBuildState;
|
|
|
|
|
|
|
|
static
|
2017-01-09 14:40:22 +03:00
|
|
|
void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
|
2015-05-29 13:28:54 +03:00
|
|
|
{
|
2017-01-09 14:40:22 +03:00
|
|
|
VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
|
2015-05-29 13:28:54 +03:00
|
|
|
GArray *table_offsets;
|
2015-05-29 13:28:56 +03:00
|
|
|
unsigned dsdt, rsdt;
|
2015-05-29 13:28:55 +03:00
|
|
|
GArray *tables_blob = tables->table_data;
|
2015-05-29 13:28:54 +03:00
|
|
|
|
|
|
|
table_offsets = g_array_new(false, true /* clear */,
|
|
|
|
sizeof(uint32_t));
|
|
|
|
|
2016-05-19 16:19:26 +03:00
|
|
|
bios_linker_loader_alloc(tables->linker,
|
|
|
|
ACPI_BUILD_TABLE_FILE, tables_blob,
|
2015-05-29 13:28:54 +03:00
|
|
|
64, false /* high memory */);
|
|
|
|
|
2015-05-29 13:28:55 +03:00
|
|
|
/* DSDT is pointed to by FADT */
|
2015-05-29 13:28:55 +03:00
|
|
|
dsdt = tables_blob->len;
|
2017-01-09 14:40:22 +03:00
|
|
|
build_dsdt(tables_blob, tables->linker, vms);
|
2015-05-29 13:28:55 +03:00
|
|
|
|
2015-06-26 16:22:36 +03:00
|
|
|
/* FADT MADT GTDT MCFG SPCR pointed to by RSDT */
|
2015-05-29 13:28:55 +03:00
|
|
|
acpi_add_table(table_offsets, tables_blob);
|
|
|
|
build_fadt(tables_blob, tables->linker, dsdt);
|
|
|
|
|
2015-05-29 13:28:56 +03:00
|
|
|
acpi_add_table(table_offsets, tables_blob);
|
2017-01-09 14:40:22 +03:00
|
|
|
build_madt(tables_blob, tables->linker, vms);
|
2015-05-29 13:28:56 +03:00
|
|
|
|
2015-05-29 13:28:56 +03:00
|
|
|
acpi_add_table(table_offsets, tables_blob);
|
|
|
|
build_gtdt(tables_blob, tables->linker);
|
|
|
|
|
2015-05-29 13:28:57 +03:00
|
|
|
acpi_add_table(table_offsets, tables_blob);
|
2017-01-09 14:40:22 +03:00
|
|
|
build_mcfg(tables_blob, tables->linker, vms);
|
2015-05-29 13:28:57 +03:00
|
|
|
|
2015-06-15 20:06:11 +03:00
|
|
|
acpi_add_table(table_offsets, tables_blob);
|
2017-01-09 14:40:22 +03:00
|
|
|
build_spcr(tables_blob, tables->linker, vms);
|
2015-06-15 20:06:11 +03:00
|
|
|
|
2016-05-12 15:22:28 +03:00
|
|
|
if (nb_numa_nodes > 0) {
|
|
|
|
acpi_add_table(table_offsets, tables_blob);
|
2017-01-09 14:40:22 +03:00
|
|
|
build_srat(tables_blob, tables->linker, vms);
|
2016-05-12 15:22:28 +03:00
|
|
|
}
|
|
|
|
|
2017-01-09 14:40:22 +03:00
|
|
|
if (its_class_name() && !vmc->no_its) {
|
2016-10-24 18:26:54 +03:00
|
|
|
acpi_add_table(table_offsets, tables_blob);
|
2017-01-09 14:40:22 +03:00
|
|
|
build_iort(tables_blob, tables->linker);
|
2016-10-24 18:26:54 +03:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:28:56 +03:00
|
|
|
/* RSDT is pointed to by RSDP */
|
2015-05-29 13:28:56 +03:00
|
|
|
rsdt = tables_blob->len;
|
2016-01-18 17:12:11 +03:00
|
|
|
build_rsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
|
2015-05-29 13:28:56 +03:00
|
|
|
|
2015-05-29 13:28:56 +03:00
|
|
|
/* RSDP is in FSEG memory, so allocate it separately */
|
|
|
|
build_rsdp(tables->rsdp, tables->linker, rsdt);
|
|
|
|
|
2015-05-29 13:28:54 +03:00
|
|
|
/* Cleanup memory that's no longer used. */
|
|
|
|
g_array_free(table_offsets, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void acpi_ram_update(MemoryRegion *mr, GArray *data)
|
|
|
|
{
|
|
|
|
uint32_t size = acpi_data_len(data);
|
|
|
|
|
|
|
|
/* Make sure RAM size is correct - in case it got changed
|
|
|
|
* e.g. by migration */
|
|
|
|
memory_region_ram_resize(mr, size, &error_abort);
|
|
|
|
|
|
|
|
memcpy(memory_region_get_ram_ptr(mr), data->data, size);
|
|
|
|
memory_region_set_dirty(mr, 0, size);
|
|
|
|
}
|
|
|
|
|
2015-11-05 17:32:49 +03:00
|
|
|
static void virt_acpi_build_update(void *build_opaque)
|
2015-05-29 13:28:54 +03:00
|
|
|
{
|
|
|
|
AcpiBuildState *build_state = build_opaque;
|
|
|
|
AcpiBuildTables tables;
|
|
|
|
|
|
|
|
/* No state to update or already patched? Nothing to do. */
|
|
|
|
if (!build_state || build_state->patched) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
build_state->patched = true;
|
|
|
|
|
|
|
|
acpi_build_tables_init(&tables);
|
|
|
|
|
2017-01-09 14:40:22 +03:00
|
|
|
virt_acpi_build(VIRT_MACHINE(qdev_get_machine()), &tables);
|
2015-05-29 13:28:54 +03:00
|
|
|
|
|
|
|
acpi_ram_update(build_state->table_mr, tables.table_data);
|
|
|
|
acpi_ram_update(build_state->rsdp_mr, tables.rsdp);
|
2016-05-19 16:19:25 +03:00
|
|
|
acpi_ram_update(build_state->linker_mr, tables.linker->cmd_blob);
|
2015-05-29 13:28:54 +03:00
|
|
|
|
|
|
|
acpi_build_tables_cleanup(&tables, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virt_acpi_build_reset(void *build_opaque)
|
|
|
|
{
|
|
|
|
AcpiBuildState *build_state = build_opaque;
|
|
|
|
build_state->patched = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MemoryRegion *acpi_add_rom_blob(AcpiBuildState *build_state,
|
|
|
|
GArray *blob, const char *name,
|
|
|
|
uint64_t max_size)
|
|
|
|
{
|
|
|
|
return rom_add_blob(name, blob->data, acpi_data_len(blob), max_size, -1,
|
loader: fix handling of custom address spaces when adding ROM blobs
* Commit 3e76099aacb4 ("loader: Allow a custom AddressSpace when loading
ROMs") introduced the "Rom.as" field:
(1) It modified the utility callers of rom_insert() to take "as" as a
new parameter from *their* callers, and set "rom->as" from that
parameter. The functions covered were rom_add_file() and
rom_add_elf_program().
(2) It also modified rom_insert() itself, to auto-assign
"&address_space_memory", in case the external caller passed -- and
the utility caller forwarded -- as=NULL.
Except, commit 3e76099aacb4 forgot to update the third utility caller of
rom_insert(), under point (1), namely rom_add_blob().
* Later, commit 5e774eb3bd264 ("loader: Add AddressSpace loading support
to uImages") added the load_uimage_as() function, and the
rom_add_blob_fixed_as() function-like macro, with the necessary changes
elsewhere to propagate the new "as" parameter to rom_add_blob():
load_uimage_as()
load_uboot_image()
rom_add_blob_fixed_as()
rom_add_blob()
At this point, the signature (and workings) of rom_add_blob() had been
broken already, and the rom_add_blob_fixed_as() macro passed its "_as"
parameter to rom_add_blob() as "callback_opaque". Given that the
"fw_callback" parameter itself was set to NULL (correctly), this did no
additional damage (the opaque arg would never be used), but ultimately
it broke the new functionality of load_uimage_as().
* The load_uimage_as() function would be put to use in one of the later
patches, commit e481a1f63c93 ("generic-loader: Add a generic loader").
* We can fix this only in a unified patch now. Append "AddressSpace *as"
to the signature of rom_add_blob(), and handle the new parameter. Pass
NULL from all current callers, except from rom_add_blob_fixed_as(),
where "_as" has to be bumped to the proper position.
* Note that rom_add_file() rejects the case when both "mr" and "as" are
passed in as non-NULL. The action that this is apparently supposed to
prevent is the
rom->mr = mr;
assignment (that's the only place where the "mr" parameter is used in
rom_add_file()). In rom_add_blob() though, we have no "mr" parameter,
and the actions done on the fw_cfg branch:
if (fw_file_name && fw_cfg) {
if (mc->rom_file_has_mr) {
data = rom_set_mr(rom, OBJECT(fw_cfg), devpath);
mr = rom->mr;
} else {
data = rom->data;
}
reflect those that are performed by rom_add_file() too (with mr==NULL):
if (rom->fw_file && fw_cfg) {
if ((!option_rom || mc->option_rom_has_mr) &&
mc->rom_file_has_mr) {
data = rom_set_mr(rom, OBJECT(fw_cfg), devpath);
} else {
data = rom->data;
}
Hence we need no additional restrictions in rom_add_blob().
* Stable is not affected as both problematic commits appeared first in
v2.8.0-rc0.
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Alistair Francis <alistair.francis@xilinx.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Michael Walle <michael@walle.cc>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Shannon Zhao <zhaoshenglong@huawei.com>
Cc: qemu-arm@nongnu.org
Cc: qemu-devel@nongnu.org
Fixes: 3e76099aacb4dae0d37ebf95305369e03d1491e6
Fixes: 5e774eb3bd264c76484906f4bd0fb38e00b8090e
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2016-11-29 22:55:32 +03:00
|
|
|
name, virt_acpi_build_update, build_state, NULL);
|
2015-05-29 13:28:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_virt_acpi_build = {
|
|
|
|
.name = "virt_acpi_build",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_BOOL(patched, AcpiBuildState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-01-09 14:40:22 +03:00
|
|
|
void virt_acpi_setup(VirtMachineState *vms)
|
2015-05-29 13:28:54 +03:00
|
|
|
{
|
|
|
|
AcpiBuildTables tables;
|
|
|
|
AcpiBuildState *build_state;
|
|
|
|
|
2017-01-09 14:40:23 +03:00
|
|
|
if (!vms->fw_cfg) {
|
2015-05-29 13:28:54 +03:00
|
|
|
trace_virt_acpi_setup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!acpi_enabled) {
|
|
|
|
trace_virt_acpi_setup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
build_state = g_malloc0(sizeof *build_state);
|
|
|
|
|
|
|
|
acpi_build_tables_init(&tables);
|
2017-01-09 14:40:22 +03:00
|
|
|
virt_acpi_build(vms, &tables);
|
2015-05-29 13:28:54 +03:00
|
|
|
|
|
|
|
/* Now expose it all to Guest */
|
|
|
|
build_state->table_mr = acpi_add_rom_blob(build_state, tables.table_data,
|
|
|
|
ACPI_BUILD_TABLE_FILE,
|
|
|
|
ACPI_BUILD_TABLE_MAX_SIZE);
|
|
|
|
assert(build_state->table_mr != NULL);
|
|
|
|
|
|
|
|
build_state->linker_mr =
|
2016-05-19 16:19:25 +03:00
|
|
|
acpi_add_rom_blob(build_state, tables.linker->cmd_blob,
|
|
|
|
"etc/table-loader", 0);
|
2015-05-29 13:28:54 +03:00
|
|
|
|
2017-01-09 14:40:23 +03:00
|
|
|
fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data,
|
|
|
|
acpi_data_len(tables.tcpalog));
|
2015-05-29 13:28:54 +03:00
|
|
|
|
|
|
|
build_state->rsdp_mr = acpi_add_rom_blob(build_state, tables.rsdp,
|
|
|
|
ACPI_BUILD_RSDP_FILE, 0);
|
|
|
|
|
|
|
|
qemu_register_reset(virt_acpi_build_reset, build_state);
|
|
|
|
virt_acpi_build_reset(build_state);
|
|
|
|
vmstate_register(NULL, 0, &vmstate_virt_acpi_build, build_state);
|
|
|
|
|
|
|
|
/* Cleanup tables but don't free the memory: we track it
|
|
|
|
* in build_state.
|
|
|
|
*/
|
|
|
|
acpi_build_tables_cleanup(&tables, false);
|
|
|
|
}
|