|
|
9ae3a8 |
From b451ecc8fa5bb1283a1dddc20057282676ad2593 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
Message-Id: <b451ecc8fa5bb1283a1dddc20057282676ad2593.1387298827.git.minovotn@redhat.com>
|
|
|
9ae3a8 |
In-Reply-To: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
|
|
|
9ae3a8 |
References: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
|
|
|
9ae3a8 |
From: "Michael S. Tsirkin" <mst@redhat.com>
|
|
|
9ae3a8 |
Date: Tue, 17 Dec 2013 15:19:08 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 48/56] i386: ACPI table generation code from seabios
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Michael S. Tsirkin <mst@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1387293161-4085-49-git-send-email-mst@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 56354
|
|
|
9ae3a8 |
O-Subject: [PATCH qemu-kvm RHEL7.0 v2 48/57] i386: ACPI table generation code from seabios
|
|
|
9ae3a8 |
Bugzilla: 1034876
|
|
|
9ae3a8 |
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This adds C code for generating ACPI tables at runtime,
|
|
|
9ae3a8 |
imported from seabios git tree
|
|
|
9ae3a8 |
commit 51684b7ced75fb76776e8ee84833fcfb6ecf12dd
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Although ACPI tables come from a system BIOS on real hw,
|
|
|
9ae3a8 |
it makes sense that the ACPI tables are coupled with the
|
|
|
9ae3a8 |
virtual machine, since they have to abstract the x86 machine to
|
|
|
9ae3a8 |
the OS's.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This is widely desired as a way to avoid the churn
|
|
|
9ae3a8 |
and proliferation of QEMU-specific interfaces
|
|
|
9ae3a8 |
associated with ACPI tables in bios code.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Notes:
|
|
|
9ae3a8 |
As BIOS can reprogram devices prior to loading
|
|
|
9ae3a8 |
ACPI tables, we pre-format ACPI tables but defer loading
|
|
|
9ae3a8 |
hardware configuration there until tables are loaded.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
The code structure was intentionally kept as close
|
|
|
9ae3a8 |
to the seabios original as possible, to simplify
|
|
|
9ae3a8 |
comparison and making sure we didn't lose anything
|
|
|
9ae3a8 |
in translation.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Minor code duplication results, to help ensure there are no functional
|
|
|
9ae3a8 |
regressions, I think it's better to merge it like this and do more code
|
|
|
9ae3a8 |
changes in follow-up patches.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Cross-version compatibility concerns have been addressed:
|
|
|
9ae3a8 |
ACPI tables are exposed to guest as FW_CFG entries.
|
|
|
9ae3a8 |
When running with -M 1.5 and older, this patch disables ACPI
|
|
|
9ae3a8 |
table generation, and doesn't expose ACPI
|
|
|
9ae3a8 |
tables to guest.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
As table content is likely to change over time,
|
|
|
9ae3a8 |
the following measures are taken to simplify
|
|
|
9ae3a8 |
cross-version migration:
|
|
|
9ae3a8 |
- All tables besides the RSDP are packed in a single FW CFG entry.
|
|
|
9ae3a8 |
This entry size is currently 23K. We round it up to 64K
|
|
|
9ae3a8 |
to avoid too much churn there.
|
|
|
9ae3a8 |
- Tables are placed in special ROM blob (not mapped into guest memory)
|
|
|
9ae3a8 |
which is automatically migrated together with the guest, same
|
|
|
9ae3a8 |
as BIOS code.
|
|
|
9ae3a8 |
- Offsets where hardware configuration is loaded in ACPI tables
|
|
|
9ae3a8 |
are also migrated, this is in case future ACPI changes make us
|
|
|
9ae3a8 |
rearrange the tables in memory.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This patch reuses some code from SeaBIOS, which was originally under
|
|
|
9ae3a8 |
LGPLv2 and then relicensed to GPLv3 or LGPLv3, in QEMU under GPLv2+. This
|
|
|
9ae3a8 |
relicensing has been acked by all contributors that had contributed to the
|
|
|
9ae3a8 |
code since the v2->v3 relicense. ACKs approving the v2+ relicensing are
|
|
|
9ae3a8 |
listed below. The list might include ACKs from people not holding
|
|
|
9ae3a8 |
copyright on any parts of the reused code, but it's better to err on the
|
|
|
9ae3a8 |
side of caution and include them.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Affected SeaBIOS files (GPLv2+ license headers added)
|
|
|
9ae3a8 |
<http://thread.gmane.org/gmane.comp.bios.coreboot.seabios/5949>:
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
src/acpi-dsdt-cpu-hotplug.dsl
|
|
|
9ae3a8 |
src/acpi-dsdt-dbug.dsl
|
|
|
9ae3a8 |
src/acpi-dsdt-hpet.dsl
|
|
|
9ae3a8 |
src/acpi-dsdt-isa.dsl
|
|
|
9ae3a8 |
src/acpi-dsdt-pci-crs.dsl
|
|
|
9ae3a8 |
src/acpi.c
|
|
|
9ae3a8 |
src/acpi.h
|
|
|
9ae3a8 |
src/ssdt-misc.dsl
|
|
|
9ae3a8 |
src/ssdt-pcihp.dsl
|
|
|
9ae3a8 |
src/ssdt-proc.dsl
|
|
|
9ae3a8 |
tools/acpi_extract.py
|
|
|
9ae3a8 |
tools/acpi_extract_preprocess.py
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Each one of the listed people agreed to the following:
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
> If you allow the use of your contribution in QEMU under the
|
|
|
9ae3a8 |
> terms of GPLv2 or later as proposed by this patch,
|
|
|
9ae3a8 |
> please respond to this mail including the line:
|
|
|
9ae3a8 |
>
|
|
|
9ae3a8 |
> Acked-by: Name <email address>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
9ae3a8 |
Acked-by: Jan Kiszka <jan.kiszka@siemens.com>
|
|
|
9ae3a8 |
Acked-by: Jason Baron <jbaron@akamai.com>
|
|
|
9ae3a8 |
Acked-by: David Woodhouse <David.Woodhouse@intel.com>
|
|
|
9ae3a8 |
Acked-by: Gleb Natapov <gleb@redhat.com>
|
|
|
9ae3a8 |
Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
|
|
|
9ae3a8 |
Acked-by: Dave Frodin <dave.frodin@se-eng.com>
|
|
|
9ae3a8 |
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
Acked-by: Kevin O'Connor <kevin@koconnor.net>
|
|
|
9ae3a8 |
Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
Acked-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
|
|
|
9ae3a8 |
Acked-by: Isaku Yamahata <yamahata@valinux.co.jp>
|
|
|
9ae3a8 |
Acked-by: Magnus Christensson <magnus.christensson@intel.com>
|
|
|
9ae3a8 |
Acked-by: Hu Tao <hutao@cn.fujitsu.com>
|
|
|
9ae3a8 |
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
9ae3a8 |
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
|
|
|
9ae3a8 |
Tested-by: Igor Mammedov <imammedo@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 72c194f7e75cb64b2558111cb111adb49fbf4097)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Conflicts:
|
|
|
9ae3a8 |
hw/i386/pc_piix.c
|
|
|
9ae3a8 |
hw/i386/pc_q35.c
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
hw/i386/acpi-build.h | 9 +
|
|
|
9ae3a8 |
hw/i386/acpi-defs.h | 331 ++++++++++++++
|
|
|
9ae3a8 |
include/hw/i386/pc.h | 1 +
|
|
|
9ae3a8 |
hw/i386/acpi-build.c | 1214 +++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
hw/i386/pc.c | 2 +
|
|
|
9ae3a8 |
hw/i386/pc_piix.c | 5 +
|
|
|
9ae3a8 |
hw/i386/pc_q35.c | 2 +
|
|
|
9ae3a8 |
hw/i386/Makefile.objs | 4 +
|
|
|
9ae3a8 |
8 files changed, 1568 insertions(+)
|
|
|
9ae3a8 |
create mode 100644 hw/i386/acpi-build.h
|
|
|
9ae3a8 |
create mode 100644 hw/i386/acpi-defs.h
|
|
|
9ae3a8 |
create mode 100644 hw/i386/acpi-build.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Michal Novotny <minovotn@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
hw/i386/Makefile.objs | 4 +
|
|
|
9ae3a8 |
hw/i386/acpi-build.c | 1214 +++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
hw/i386/acpi-build.h | 9 +
|
|
|
9ae3a8 |
hw/i386/acpi-defs.h | 331 ++++++++++++++
|
|
|
9ae3a8 |
hw/i386/pc.c | 2 +
|
|
|
9ae3a8 |
hw/i386/pc_piix.c | 5 +
|
|
|
9ae3a8 |
hw/i386/pc_q35.c | 2 +
|
|
|
9ae3a8 |
include/hw/i386/pc.h | 1 +
|
|
|
9ae3a8 |
8 files changed, 1568 insertions(+)
|
|
|
9ae3a8 |
create mode 100644 hw/i386/acpi-build.c
|
|
|
9ae3a8 |
create mode 100644 hw/i386/acpi-build.h
|
|
|
9ae3a8 |
create mode 100644 hw/i386/acpi-defs.h
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
|
|
|
9ae3a8 |
index 71be2da..6754fd5 100644
|
|
|
9ae3a8 |
--- a/hw/i386/Makefile.objs
|
|
|
9ae3a8 |
+++ b/hw/i386/Makefile.objs
|
|
|
9ae3a8 |
@@ -4,7 +4,11 @@ obj-y += pc.o pc_piix.o pc_q35.o
|
|
|
9ae3a8 |
obj-$(CONFIG_XEN) += xen_domainbuild.o xen_machine_pv.o
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
obj-y += kvmvapic.o
|
|
|
9ae3a8 |
+obj-y += acpi-build.o
|
|
|
9ae3a8 |
obj-y += bios-linker-loader.o
|
|
|
9ae3a8 |
+hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
|
|
|
9ae3a8 |
+ hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \
|
|
|
9ae3a8 |
+ hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
|
|
|
9ae3a8 |
; then echo "$(2)"; else echo "$(3)"; fi ;)
|
|
|
9ae3a8 |
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
|
|
|
9ae3a8 |
new file mode 100644
|
|
|
9ae3a8 |
index 0000000..6cfa044
|
|
|
9ae3a8 |
--- /dev/null
|
|
|
9ae3a8 |
+++ b/hw/i386/acpi-build.c
|
|
|
9ae3a8 |
@@ -0,0 +1,1214 @@
|
|
|
9ae3a8 |
+/* Support for generating ACPI tables and passing them to Guests
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Copyright (C) 2008-2010 Kevin O'Connor <kevin@koconnor.net>
|
|
|
9ae3a8 |
+ * Copyright (C) 2006 Fabrice Bellard
|
|
|
9ae3a8 |
+ * Copyright (C) 2013 Red Hat Inc
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Author: Michael S. Tsirkin <mst@redhat.com>
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * This program is free software; you can redistribute it and/or modify
|
|
|
9ae3a8 |
+ * it under the terms of the GNU General Public License as published by
|
|
|
9ae3a8 |
+ * the Free Software Foundation; either version 2 of the License, or
|
|
|
9ae3a8 |
+ * (at your option) any later version.
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ * This program is distributed in the hope that it will be useful,
|
|
|
9ae3a8 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9ae3a8 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
9ae3a8 |
+ * GNU General Public License for more details.
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ * You should have received a copy of the GNU General Public License along
|
|
|
9ae3a8 |
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#include "acpi-build.h"
|
|
|
9ae3a8 |
+#include <stddef.h>
|
|
|
9ae3a8 |
+#include <glib.h>
|
|
|
9ae3a8 |
+#include "qemu-common.h"
|
|
|
9ae3a8 |
+#include "qemu/bitmap.h"
|
|
|
9ae3a8 |
+#include "qemu/range.h"
|
|
|
9ae3a8 |
+#include "hw/pci/pci.h"
|
|
|
9ae3a8 |
+#include "qom/cpu.h"
|
|
|
9ae3a8 |
+#include "hw/i386/pc.h"
|
|
|
9ae3a8 |
+#include "target-i386/cpu.h"
|
|
|
9ae3a8 |
+#include "hw/timer/hpet.h"
|
|
|
9ae3a8 |
+#include "hw/i386/acpi-defs.h"
|
|
|
9ae3a8 |
+#include "hw/acpi/acpi.h"
|
|
|
9ae3a8 |
+#include "hw/nvram/fw_cfg.h"
|
|
|
9ae3a8 |
+#include "bios-linker-loader.h"
|
|
|
9ae3a8 |
+#include "hw/loader.h"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* Supported chipsets: */
|
|
|
9ae3a8 |
+#include "hw/acpi/piix4.h"
|
|
|
9ae3a8 |
+#include "hw/i386/ich9.h"
|
|
|
9ae3a8 |
+#include "hw/pci/pci_bus.h"
|
|
|
9ae3a8 |
+#include "hw/pci-host/q35.h"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#include "hw/i386/q35-acpi-dsdt.hex"
|
|
|
9ae3a8 |
+#include "hw/i386/acpi-dsdt.hex"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#include "qapi/qmp/qint.h"
|
|
|
9ae3a8 |
+#include "qom/qom-qobject.h"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+typedef struct AcpiCpuInfo {
|
|
|
9ae3a8 |
+ DECLARE_BITMAP(found_cpus, MAX_CPUMASK_BITS + 1);
|
|
|
9ae3a8 |
+} AcpiCpuInfo;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+typedef struct AcpiMcfgInfo {
|
|
|
9ae3a8 |
+ uint64_t mcfg_base;
|
|
|
9ae3a8 |
+ uint32_t mcfg_size;
|
|
|
9ae3a8 |
+} AcpiMcfgInfo;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+typedef struct AcpiPmInfo {
|
|
|
9ae3a8 |
+ bool s3_disabled;
|
|
|
9ae3a8 |
+ bool s4_disabled;
|
|
|
9ae3a8 |
+ uint8_t s4_val;
|
|
|
9ae3a8 |
+ uint16_t sci_int;
|
|
|
9ae3a8 |
+ uint8_t acpi_enable_cmd;
|
|
|
9ae3a8 |
+ uint8_t acpi_disable_cmd;
|
|
|
9ae3a8 |
+ uint32_t gpe0_blk;
|
|
|
9ae3a8 |
+ uint32_t gpe0_blk_len;
|
|
|
9ae3a8 |
+ uint32_t io_base;
|
|
|
9ae3a8 |
+} AcpiPmInfo;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+typedef struct AcpiMiscInfo {
|
|
|
9ae3a8 |
+ bool has_hpet;
|
|
|
9ae3a8 |
+ DECLARE_BITMAP(slot_hotplug_enable, PCI_SLOT_MAX);
|
|
|
9ae3a8 |
+ const unsigned char *dsdt_code;
|
|
|
9ae3a8 |
+ unsigned dsdt_size;
|
|
|
9ae3a8 |
+ uint16_t pvpanic_port;
|
|
|
9ae3a8 |
+} AcpiMiscInfo;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void acpi_get_dsdt(AcpiMiscInfo *info)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ Object *piix = piix4_pm_find();
|
|
|
9ae3a8 |
+ Object *lpc = ich9_lpc_find();
|
|
|
9ae3a8 |
+ assert(!!piix != !!lpc);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (piix) {
|
|
|
9ae3a8 |
+ info->dsdt_code = AcpiDsdtAmlCode;
|
|
|
9ae3a8 |
+ info->dsdt_size = sizeof AcpiDsdtAmlCode;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (lpc) {
|
|
|
9ae3a8 |
+ info->dsdt_code = Q35AcpiDsdtAmlCode;
|
|
|
9ae3a8 |
+ info->dsdt_size = sizeof Q35AcpiDsdtAmlCode;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static
|
|
|
9ae3a8 |
+int acpi_add_cpu_info(Object *o, void *opaque)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ AcpiCpuInfo *cpu = opaque;
|
|
|
9ae3a8 |
+ uint64_t apic_id;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (object_dynamic_cast(o, TYPE_CPU)) {
|
|
|
9ae3a8 |
+ apic_id = object_property_get_int(o, "apic-id", NULL);
|
|
|
9ae3a8 |
+ assert(apic_id <= MAX_CPUMASK_BITS);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ set_bit(apic_id, cpu->found_cpus);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ object_child_foreach(o, acpi_add_cpu_info, opaque);
|
|
|
9ae3a8 |
+ return 0;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void acpi_get_cpu_info(AcpiCpuInfo *cpu)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ Object *root = object_get_root();
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ memset(cpu->found_cpus, 0, sizeof cpu->found_cpus);
|
|
|
9ae3a8 |
+ object_child_foreach(root, acpi_add_cpu_info, cpu);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void acpi_get_pm_info(AcpiPmInfo *pm)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ Object *piix = piix4_pm_find();
|
|
|
9ae3a8 |
+ Object *lpc = ich9_lpc_find();
|
|
|
9ae3a8 |
+ Object *obj = NULL;
|
|
|
9ae3a8 |
+ QObject *o;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (piix) {
|
|
|
9ae3a8 |
+ obj = piix;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (lpc) {
|
|
|
9ae3a8 |
+ obj = lpc;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ assert(obj);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Fill in optional s3/s4 related properties */
|
|
|
9ae3a8 |
+ o = object_property_get_qobject(obj, ACPI_PM_PROP_S3_DISABLED, NULL);
|
|
|
9ae3a8 |
+ if (o) {
|
|
|
9ae3a8 |
+ pm->s3_disabled = qint_get_int(qobject_to_qint(o));
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ pm->s3_disabled = false;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ o = object_property_get_qobject(obj, ACPI_PM_PROP_S4_DISABLED, NULL);
|
|
|
9ae3a8 |
+ if (o) {
|
|
|
9ae3a8 |
+ pm->s4_disabled = qint_get_int(qobject_to_qint(o));
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ pm->s4_disabled = false;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ o = object_property_get_qobject(obj, ACPI_PM_PROP_S4_VAL, NULL);
|
|
|
9ae3a8 |
+ if (o) {
|
|
|
9ae3a8 |
+ pm->s4_val = qint_get_int(qobject_to_qint(o));
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ pm->s4_val = false;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Fill in mandatory properties */
|
|
|
9ae3a8 |
+ pm->sci_int = object_property_get_int(obj, ACPI_PM_PROP_SCI_INT, NULL);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ pm->acpi_enable_cmd = object_property_get_int(obj,
|
|
|
9ae3a8 |
+ ACPI_PM_PROP_ACPI_ENABLE_CMD,
|
|
|
9ae3a8 |
+ NULL);
|
|
|
9ae3a8 |
+ pm->acpi_disable_cmd = object_property_get_int(obj,
|
|
|
9ae3a8 |
+ ACPI_PM_PROP_ACPI_DISABLE_CMD,
|
|
|
9ae3a8 |
+ NULL);
|
|
|
9ae3a8 |
+ pm->io_base = object_property_get_int(obj, ACPI_PM_PROP_PM_IO_BASE,
|
|
|
9ae3a8 |
+ NULL);
|
|
|
9ae3a8 |
+ pm->gpe0_blk = object_property_get_int(obj, ACPI_PM_PROP_GPE0_BLK,
|
|
|
9ae3a8 |
+ NULL);
|
|
|
9ae3a8 |
+ pm->gpe0_blk_len = object_property_get_int(obj, ACPI_PM_PROP_GPE0_BLK_LEN,
|
|
|
9ae3a8 |
+ NULL);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void acpi_get_hotplug_info(AcpiMiscInfo *misc)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ int i;
|
|
|
9ae3a8 |
+ PCIBus *bus = find_i440fx();
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (!bus) {
|
|
|
9ae3a8 |
+ /* Only PIIX supports ACPI hotplug */
|
|
|
9ae3a8 |
+ memset(misc->slot_hotplug_enable, 0, sizeof misc->slot_hotplug_enable);
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ memset(misc->slot_hotplug_enable, 0xff,
|
|
|
9ae3a8 |
+ DIV_ROUND_UP(PCI_SLOT_MAX, BITS_PER_BYTE));
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ for (i = 0; i < ARRAY_SIZE(bus->devices); ++i) {
|
|
|
9ae3a8 |
+ PCIDeviceClass *pc;
|
|
|
9ae3a8 |
+ PCIDevice *pdev = bus->devices[i];
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (!pdev) {
|
|
|
9ae3a8 |
+ continue;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ pc = PCI_DEVICE_GET_CLASS(pdev);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (pc->no_hotplug) {
|
|
|
9ae3a8 |
+ int slot = PCI_SLOT(i);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ clear_bit(slot, misc->slot_hotplug_enable);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void acpi_get_misc_info(AcpiMiscInfo *info)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ info->has_hpet = hpet_find();
|
|
|
9ae3a8 |
+ info->pvpanic_port = pvpanic_port();
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void acpi_get_pci_info(PcPciInfo *info)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ Object *pci_host;
|
|
|
9ae3a8 |
+ bool ambiguous;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ pci_host = object_resolve_path_type("", TYPE_PCI_HOST_BRIDGE, &ambiguous);
|
|
|
9ae3a8 |
+ g_assert(!ambiguous);
|
|
|
9ae3a8 |
+ g_assert(pci_host);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ info->w32.begin = object_property_get_int(pci_host,
|
|
|
9ae3a8 |
+ PCI_HOST_PROP_PCI_HOLE_START,
|
|
|
9ae3a8 |
+ NULL);
|
|
|
9ae3a8 |
+ info->w32.end = object_property_get_int(pci_host,
|
|
|
9ae3a8 |
+ PCI_HOST_PROP_PCI_HOLE_END,
|
|
|
9ae3a8 |
+ NULL);
|
|
|
9ae3a8 |
+ info->w64.begin = object_property_get_int(pci_host,
|
|
|
9ae3a8 |
+ PCI_HOST_PROP_PCI_HOLE64_START,
|
|
|
9ae3a8 |
+ NULL);
|
|
|
9ae3a8 |
+ info->w64.end = object_property_get_int(pci_host,
|
|
|
9ae3a8 |
+ PCI_HOST_PROP_PCI_HOLE64_END,
|
|
|
9ae3a8 |
+ NULL);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define ACPI_BUILD_APPNAME "Bochs"
|
|
|
9ae3a8 |
+#define ACPI_BUILD_APPNAME6 "BOCHS "
|
|
|
9ae3a8 |
+#define ACPI_BUILD_APPNAME4 "BXPC"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define ACPI_BUILD_DPRINTF(level, fmt, ...) do {} while (0)
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
|
|
|
9ae3a8 |
+#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void
|
|
|
9ae3a8 |
+build_header(GArray *linker, GArray *table_data,
|
|
|
9ae3a8 |
+ AcpiTableHeader *h, uint32_t sig, int len, uint8_t rev)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ h->signature = cpu_to_le32(sig);
|
|
|
9ae3a8 |
+ h->length = cpu_to_le32(len);
|
|
|
9ae3a8 |
+ h->revision = rev;
|
|
|
9ae3a8 |
+ memcpy(h->oem_id, ACPI_BUILD_APPNAME6, 6);
|
|
|
9ae3a8 |
+ memcpy(h->oem_table_id, ACPI_BUILD_APPNAME4, 4);
|
|
|
9ae3a8 |
+ memcpy(h->oem_table_id + 4, (void *)&sig, 4);
|
|
|
9ae3a8 |
+ h->oem_revision = cpu_to_le32(1);
|
|
|
9ae3a8 |
+ memcpy(h->asl_compiler_id, ACPI_BUILD_APPNAME4, 4);
|
|
|
9ae3a8 |
+ h->asl_compiler_revision = cpu_to_le32(1);
|
|
|
9ae3a8 |
+ h->checksum = 0;
|
|
|
9ae3a8 |
+ /* Checksum to be filled in by Guest linker */
|
|
|
9ae3a8 |
+ bios_linker_loader_add_checksum(linker, ACPI_BUILD_TABLE_FILE,
|
|
|
9ae3a8 |
+ table_data->data, h, len, &h->checksum);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static inline GArray *build_alloc_array(void)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ return g_array_new(false, true /* clear */, 1);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static inline void build_free_array(GArray *array)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ g_array_free(array, true);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static inline void build_prepend_byte(GArray *array, uint8_t val)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ g_array_prepend_val(array, val);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static inline void build_append_byte(GArray *array, uint8_t val)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ g_array_append_val(array, val);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static inline void build_append_array(GArray *array, GArray *val)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ g_array_append_vals(array, val->data, val->len);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void build_append_nameseg(GArray *array, const char *format, ...)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ GString *s = g_string_new("");
|
|
|
9ae3a8 |
+ va_list args;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ va_start(args, format);
|
|
|
9ae3a8 |
+ g_string_vprintf(s, format, args);
|
|
|
9ae3a8 |
+ va_end(args);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ assert(s->len == 4);
|
|
|
9ae3a8 |
+ g_array_append_vals(array, s->str, s->len);
|
|
|
9ae3a8 |
+ g_string_free(s, true);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* 5.4 Definition Block Encoding */
|
|
|
9ae3a8 |
+enum {
|
|
|
9ae3a8 |
+ PACKAGE_LENGTH_1BYTE_SHIFT = 6, /* Up to 63 - use extra 2 bits. */
|
|
|
9ae3a8 |
+ PACKAGE_LENGTH_2BYTE_SHIFT = 4,
|
|
|
9ae3a8 |
+ PACKAGE_LENGTH_3BYTE_SHIFT = 12,
|
|
|
9ae3a8 |
+ PACKAGE_LENGTH_4BYTE_SHIFT = 20,
|
|
|
9ae3a8 |
+};
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void build_prepend_package_length(GArray *package, unsigned min_bytes)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ uint8_t byte;
|
|
|
9ae3a8 |
+ unsigned length = package->len;
|
|
|
9ae3a8 |
+ unsigned length_bytes;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (length + 1 < (1 << PACKAGE_LENGTH_1BYTE_SHIFT)) {
|
|
|
9ae3a8 |
+ length_bytes = 1;
|
|
|
9ae3a8 |
+ } else if (length + 2 < (1 << PACKAGE_LENGTH_3BYTE_SHIFT)) {
|
|
|
9ae3a8 |
+ length_bytes = 2;
|
|
|
9ae3a8 |
+ } else if (length + 3 < (1 << PACKAGE_LENGTH_4BYTE_SHIFT)) {
|
|
|
9ae3a8 |
+ length_bytes = 3;
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ length_bytes = 4;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Force length to at least min_bytes.
|
|
|
9ae3a8 |
+ * This wastes memory but that's how bios did it.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ length_bytes = MAX(length_bytes, min_bytes);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* PkgLength is the length of the inclusive length of the data. */
|
|
|
9ae3a8 |
+ length += length_bytes;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ switch (length_bytes) {
|
|
|
9ae3a8 |
+ case 1:
|
|
|
9ae3a8 |
+ byte = length;
|
|
|
9ae3a8 |
+ build_prepend_byte(package, byte);
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
+ case 4:
|
|
|
9ae3a8 |
+ byte = length >> PACKAGE_LENGTH_4BYTE_SHIFT;
|
|
|
9ae3a8 |
+ build_prepend_byte(package, byte);
|
|
|
9ae3a8 |
+ length &= (1 << PACKAGE_LENGTH_4BYTE_SHIFT) - 1;
|
|
|
9ae3a8 |
+ /* fall through */
|
|
|
9ae3a8 |
+ case 3:
|
|
|
9ae3a8 |
+ byte = length >> PACKAGE_LENGTH_3BYTE_SHIFT;
|
|
|
9ae3a8 |
+ build_prepend_byte(package, byte);
|
|
|
9ae3a8 |
+ length &= (1 << PACKAGE_LENGTH_3BYTE_SHIFT) - 1;
|
|
|
9ae3a8 |
+ /* fall through */
|
|
|
9ae3a8 |
+ case 2:
|
|
|
9ae3a8 |
+ byte = length >> PACKAGE_LENGTH_2BYTE_SHIFT;
|
|
|
9ae3a8 |
+ build_prepend_byte(package, byte);
|
|
|
9ae3a8 |
+ length &= (1 << PACKAGE_LENGTH_2BYTE_SHIFT) - 1;
|
|
|
9ae3a8 |
+ /* fall through */
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ /*
|
|
|
9ae3a8 |
+ * Most significant two bits of byte zero indicate how many following bytes
|
|
|
9ae3a8 |
+ * are in PkgLength encoding.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ byte = ((length_bytes - 1) << PACKAGE_LENGTH_1BYTE_SHIFT) | length;
|
|
|
9ae3a8 |
+ build_prepend_byte(package, byte);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void build_package(GArray *package, uint8_t op, unsigned min_bytes)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ build_prepend_package_length(package, min_bytes);
|
|
|
9ae3a8 |
+ build_prepend_byte(package, op);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void build_append_value(GArray *table, uint32_t value, int size)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ uint8_t prefix;
|
|
|
9ae3a8 |
+ int i;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ switch (size) {
|
|
|
9ae3a8 |
+ case 1:
|
|
|
9ae3a8 |
+ prefix = 0x0A; /* BytePrefix */
|
|
|
9ae3a8 |
+ break;
|
|
|
9ae3a8 |
+ case 2:
|
|
|
9ae3a8 |
+ prefix = 0x0B; /* WordPrefix */
|
|
|
9ae3a8 |
+ break;
|
|
|
9ae3a8 |
+ case 4:
|
|
|
9ae3a8 |
+ prefix = 0x0C; /* DWordPrefix */
|
|
|
9ae3a8 |
+ break;
|
|
|
9ae3a8 |
+ default:
|
|
|
9ae3a8 |
+ assert(0);
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ build_append_byte(table, prefix);
|
|
|
9ae3a8 |
+ for (i = 0; i < size; ++i) {
|
|
|
9ae3a8 |
+ build_append_byte(table, value & 0xFF);
|
|
|
9ae3a8 |
+ value = value >> 8;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void build_append_notify_target(GArray *method, GArray *target_name,
|
|
|
9ae3a8 |
+ uint32_t value, int size)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ GArray *notify = build_alloc_array();
|
|
|
9ae3a8 |
+ uint8_t op = 0xA0; /* IfOp */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_append_byte(notify, 0x93); /* LEqualOp */
|
|
|
9ae3a8 |
+ build_append_byte(notify, 0x68); /* Arg0Op */
|
|
|
9ae3a8 |
+ build_append_value(notify, value, size);
|
|
|
9ae3a8 |
+ build_append_byte(notify, 0x86); /* NotifyOp */
|
|
|
9ae3a8 |
+ build_append_array(notify, target_name);
|
|
|
9ae3a8 |
+ build_append_byte(notify, 0x69); /* Arg1Op */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Pack it up */
|
|
|
9ae3a8 |
+ build_package(notify, op, 1);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_append_array(method, notify);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_free_array(notify);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define ACPI_PORT_SMI_CMD 0x00b2 /* TODO: this is APM_CNT_IOPORT */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static inline void *acpi_data_push(GArray *table_data, unsigned size)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ unsigned off = table_data->len;
|
|
|
9ae3a8 |
+ g_array_set_size(table_data, off + size);
|
|
|
9ae3a8 |
+ return table_data->data + off;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static unsigned acpi_data_len(GArray *table)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ return table->len * g_array_get_element_size(table);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void acpi_align_size(GArray *blob, unsigned align)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ /* Align size to multiple of given size. This reduces the chance
|
|
|
9ae3a8 |
+ * we need to change size in the future (breaking cross version migration).
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ g_array_set_size(blob, (ROUND_UP(acpi_data_len(blob), align) +
|
|
|
9ae3a8 |
+ g_array_get_element_size(blob) - 1) /
|
|
|
9ae3a8 |
+ g_array_get_element_size(blob));
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* Get pointer within table in a safe manner */
|
|
|
9ae3a8 |
+#define ACPI_BUILD_PTR(table, size, off, type) \
|
|
|
9ae3a8 |
+ ((type *)(acpi_data_get_ptr(table, size, off, sizeof(type))))
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static inline void *acpi_data_get_ptr(uint8_t *table_data, unsigned table_size,
|
|
|
9ae3a8 |
+ unsigned off, unsigned size)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ assert(off + size > off);
|
|
|
9ae3a8 |
+ assert(off + size <= table_size);
|
|
|
9ae3a8 |
+ return table_data + off;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static inline void acpi_add_table(GArray *table_offsets, GArray *table_data)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ uint32_t offset = cpu_to_le32(table_data->len);
|
|
|
9ae3a8 |
+ g_array_append_val(table_offsets, offset);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* FACS */
|
|
|
9ae3a8 |
+static void
|
|
|
9ae3a8 |
+build_facs(GArray *table_data, GArray *linker, PcGuestInfo *guest_info)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ AcpiFacsDescriptorRev1 *facs = acpi_data_push(table_data, sizeof *facs);
|
|
|
9ae3a8 |
+ facs->signature = cpu_to_le32(ACPI_FACS_SIGNATURE);
|
|
|
9ae3a8 |
+ facs->length = cpu_to_le32(sizeof(*facs));
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* Load chipset information in FADT */
|
|
|
9ae3a8 |
+static void fadt_setup(AcpiFadtDescriptorRev1 *fadt, AcpiPmInfo *pm)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ fadt->model = 1;
|
|
|
9ae3a8 |
+ fadt->reserved1 = 0;
|
|
|
9ae3a8 |
+ fadt->sci_int = cpu_to_le16(pm->sci_int);
|
|
|
9ae3a8 |
+ fadt->smi_cmd = cpu_to_le32(ACPI_PORT_SMI_CMD);
|
|
|
9ae3a8 |
+ fadt->acpi_enable = pm->acpi_enable_cmd;
|
|
|
9ae3a8 |
+ fadt->acpi_disable = pm->acpi_disable_cmd;
|
|
|
9ae3a8 |
+ /* EVT, CNT, TMR offset matches hw/acpi/core.c */
|
|
|
9ae3a8 |
+ fadt->pm1a_evt_blk = cpu_to_le32(pm->io_base);
|
|
|
9ae3a8 |
+ fadt->pm1a_cnt_blk = cpu_to_le32(pm->io_base + 0x04);
|
|
|
9ae3a8 |
+ fadt->pm_tmr_blk = cpu_to_le32(pm->io_base + 0x08);
|
|
|
9ae3a8 |
+ fadt->gpe0_blk = cpu_to_le32(pm->gpe0_blk);
|
|
|
9ae3a8 |
+ /* EVT, CNT, TMR length matches hw/acpi/core.c */
|
|
|
9ae3a8 |
+ fadt->pm1_evt_len = 4;
|
|
|
9ae3a8 |
+ fadt->pm1_cnt_len = 2;
|
|
|
9ae3a8 |
+ fadt->pm_tmr_len = 4;
|
|
|
9ae3a8 |
+ fadt->gpe0_blk_len = pm->gpe0_blk_len;
|
|
|
9ae3a8 |
+ fadt->plvl2_lat = cpu_to_le16(0xfff); /* C2 state not supported */
|
|
|
9ae3a8 |
+ fadt->plvl3_lat = cpu_to_le16(0xfff); /* C3 state not supported */
|
|
|
9ae3a8 |
+ fadt->flags = cpu_to_le32((1 << ACPI_FADT_F_WBINVD) |
|
|
|
9ae3a8 |
+ (1 << ACPI_FADT_F_PROC_C1) |
|
|
|
9ae3a8 |
+ (1 << ACPI_FADT_F_SLP_BUTTON) |
|
|
|
9ae3a8 |
+ (1 << ACPI_FADT_F_RTC_S4));
|
|
|
9ae3a8 |
+ fadt->flags |= cpu_to_le32(1 << ACPI_FADT_F_USE_PLATFORM_CLOCK);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* FADT */
|
|
|
9ae3a8 |
+static void
|
|
|
9ae3a8 |
+build_fadt(GArray *table_data, GArray *linker, AcpiPmInfo *pm,
|
|
|
9ae3a8 |
+ unsigned facs, unsigned dsdt)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ AcpiFadtDescriptorRev1 *fadt = acpi_data_push(table_data, sizeof(*fadt));
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ fadt->firmware_ctrl = cpu_to_le32(facs);
|
|
|
9ae3a8 |
+ /* FACS address to be filled by Guest linker */
|
|
|
9ae3a8 |
+ bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
|
|
|
9ae3a8 |
+ ACPI_BUILD_TABLE_FILE,
|
|
|
9ae3a8 |
+ table_data, &fadt->firmware_ctrl,
|
|
|
9ae3a8 |
+ sizeof fadt->firmware_ctrl);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ fadt->dsdt = cpu_to_le32(dsdt);
|
|
|
9ae3a8 |
+ /* DSDT address to be filled by Guest linker */
|
|
|
9ae3a8 |
+ bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
|
|
|
9ae3a8 |
+ ACPI_BUILD_TABLE_FILE,
|
|
|
9ae3a8 |
+ table_data, &fadt->dsdt,
|
|
|
9ae3a8 |
+ sizeof fadt->dsdt);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ fadt_setup(fadt, pm);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_header(linker, table_data,
|
|
|
9ae3a8 |
+ (void *)fadt, ACPI_FACP_SIGNATURE, sizeof(*fadt), 1);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void
|
|
|
9ae3a8 |
+build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
|
|
|
9ae3a8 |
+ PcGuestInfo *guest_info)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ int madt_start = table_data->len;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ AcpiMultipleApicTable *madt;
|
|
|
9ae3a8 |
+ AcpiMadtIoApic *io_apic;
|
|
|
9ae3a8 |
+ AcpiMadtIntsrcovr *intsrcovr;
|
|
|
9ae3a8 |
+ AcpiMadtLocalNmi *local_nmi;
|
|
|
9ae3a8 |
+ int i;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ madt = acpi_data_push(table_data, sizeof *madt);
|
|
|
9ae3a8 |
+ madt->local_apic_address = cpu_to_le32(APIC_DEFAULT_ADDRESS);
|
|
|
9ae3a8 |
+ madt->flags = cpu_to_le32(1);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ for (i = 0; i < guest_info->apic_id_limit; i++) {
|
|
|
9ae3a8 |
+ AcpiMadtProcessorApic *apic = acpi_data_push(table_data, sizeof *apic);
|
|
|
9ae3a8 |
+ apic->type = ACPI_APIC_PROCESSOR;
|
|
|
9ae3a8 |
+ apic->length = sizeof(*apic);
|
|
|
9ae3a8 |
+ apic->processor_id = i;
|
|
|
9ae3a8 |
+ apic->local_apic_id = i;
|
|
|
9ae3a8 |
+ if (test_bit(i, cpu->found_cpus)) {
|
|
|
9ae3a8 |
+ apic->flags = cpu_to_le32(1);
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ apic->flags = cpu_to_le32(0);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ io_apic = acpi_data_push(table_data, sizeof *io_apic);
|
|
|
9ae3a8 |
+ io_apic->type = ACPI_APIC_IO;
|
|
|
9ae3a8 |
+ io_apic->length = sizeof(*io_apic);
|
|
|
9ae3a8 |
+#define ACPI_BUILD_IOAPIC_ID 0x0
|
|
|
9ae3a8 |
+ io_apic->io_apic_id = ACPI_BUILD_IOAPIC_ID;
|
|
|
9ae3a8 |
+ io_apic->address = cpu_to_le32(IO_APIC_DEFAULT_ADDRESS);
|
|
|
9ae3a8 |
+ io_apic->interrupt = cpu_to_le32(0);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (guest_info->apic_xrupt_override) {
|
|
|
9ae3a8 |
+ intsrcovr = acpi_data_push(table_data, sizeof *intsrcovr);
|
|
|
9ae3a8 |
+ intsrcovr->type = ACPI_APIC_XRUPT_OVERRIDE;
|
|
|
9ae3a8 |
+ intsrcovr->length = sizeof(*intsrcovr);
|
|
|
9ae3a8 |
+ intsrcovr->source = 0;
|
|
|
9ae3a8 |
+ intsrcovr->gsi = cpu_to_le32(2);
|
|
|
9ae3a8 |
+ intsrcovr->flags = cpu_to_le16(0); /* conforms to bus specifications */
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ for (i = 1; i < 16; i++) {
|
|
|
9ae3a8 |
+#define ACPI_BUILD_PCI_IRQS ((1<<5) | (1<<9) | (1<<10) | (1<<11))
|
|
|
9ae3a8 |
+ if (!(ACPI_BUILD_PCI_IRQS & (1 << i))) {
|
|
|
9ae3a8 |
+ /* No need for a INT source override structure. */
|
|
|
9ae3a8 |
+ continue;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ intsrcovr = acpi_data_push(table_data, sizeof *intsrcovr);
|
|
|
9ae3a8 |
+ intsrcovr->type = ACPI_APIC_XRUPT_OVERRIDE;
|
|
|
9ae3a8 |
+ intsrcovr->length = sizeof(*intsrcovr);
|
|
|
9ae3a8 |
+ intsrcovr->source = i;
|
|
|
9ae3a8 |
+ intsrcovr->gsi = cpu_to_le32(i);
|
|
|
9ae3a8 |
+ intsrcovr->flags = cpu_to_le16(0xd); /* active high, level triggered */
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ local_nmi = acpi_data_push(table_data, sizeof *local_nmi);
|
|
|
9ae3a8 |
+ local_nmi->type = ACPI_APIC_LOCAL_NMI;
|
|
|
9ae3a8 |
+ local_nmi->length = sizeof(*local_nmi);
|
|
|
9ae3a8 |
+ local_nmi->processor_id = 0xff; /* all processors */
|
|
|
9ae3a8 |
+ local_nmi->flags = cpu_to_le16(0);
|
|
|
9ae3a8 |
+ local_nmi->lint = 1; /* ACPI_LINT1 */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_header(linker, table_data,
|
|
|
9ae3a8 |
+ (void *)(table_data->data + madt_start), ACPI_APIC_SIGNATURE,
|
|
|
9ae3a8 |
+ table_data->len - madt_start, 1);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* Encode a hex value */
|
|
|
9ae3a8 |
+static inline char acpi_get_hex(uint32_t val)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ val &= 0x0f;
|
|
|
9ae3a8 |
+ return (val <= 9) ? ('0' + val) : ('A' + val - 10);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#include "hw/i386/ssdt-proc.hex"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* 0x5B 0x83 ProcessorOp PkgLength NameString ProcID */
|
|
|
9ae3a8 |
+#define ACPI_PROC_OFFSET_CPUHEX (*ssdt_proc_name - *ssdt_proc_start + 2)
|
|
|
9ae3a8 |
+#define ACPI_PROC_OFFSET_CPUID1 (*ssdt_proc_name - *ssdt_proc_start + 4)
|
|
|
9ae3a8 |
+#define ACPI_PROC_OFFSET_CPUID2 (*ssdt_proc_id - *ssdt_proc_start)
|
|
|
9ae3a8 |
+#define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)
|
|
|
9ae3a8 |
+#define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start)
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* 0x5B 0x82 DeviceOp PkgLength NameString */
|
|
|
9ae3a8 |
+#define ACPI_PCIHP_OFFSET_HEX (*ssdt_pcihp_name - *ssdt_pcihp_start + 1)
|
|
|
9ae3a8 |
+#define ACPI_PCIHP_OFFSET_ID (*ssdt_pcihp_id - *ssdt_pcihp_start)
|
|
|
9ae3a8 |
+#define ACPI_PCIHP_OFFSET_ADR (*ssdt_pcihp_adr - *ssdt_pcihp_start)
|
|
|
9ae3a8 |
+#define ACPI_PCIHP_OFFSET_EJ0 (*ssdt_pcihp_ej0 - *ssdt_pcihp_start)
|
|
|
9ae3a8 |
+#define ACPI_PCIHP_SIZEOF (*ssdt_pcihp_end - *ssdt_pcihp_start)
|
|
|
9ae3a8 |
+#define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start)
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
|
|
|
9ae3a8 |
+#define ACPI_SSDT_HEADER_LENGTH 36
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#include "hw/i386/ssdt-misc.hex"
|
|
|
9ae3a8 |
+#include "hw/i386/ssdt-pcihp.hex"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void
|
|
|
9ae3a8 |
+build_append_notify(GArray *device, const char *name,
|
|
|
9ae3a8 |
+ const char *format, int skip, int count)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ int i;
|
|
|
9ae3a8 |
+ GArray *method = build_alloc_array();
|
|
|
9ae3a8 |
+ uint8_t op = 0x14; /* MethodOp */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_append_nameseg(method, name);
|
|
|
9ae3a8 |
+ build_append_byte(method, 0x02); /* MethodFlags: ArgCount */
|
|
|
9ae3a8 |
+ for (i = skip; i < count; i++) {
|
|
|
9ae3a8 |
+ GArray *target = build_alloc_array();
|
|
|
9ae3a8 |
+ build_append_nameseg(target, format, i);
|
|
|
9ae3a8 |
+ assert(i < 256); /* Fits in 1 byte */
|
|
|
9ae3a8 |
+ build_append_notify_target(method, target, i, 1);
|
|
|
9ae3a8 |
+ build_free_array(target);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ build_package(method, op, 2);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_append_array(device, method);
|
|
|
9ae3a8 |
+ build_free_array(method);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void patch_pcihp(int slot, uint8_t *ssdt_ptr, uint32_t eject)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ ssdt_ptr[ACPI_PCIHP_OFFSET_HEX] = acpi_get_hex(slot >> 4);
|
|
|
9ae3a8 |
+ ssdt_ptr[ACPI_PCIHP_OFFSET_HEX + 1] = acpi_get_hex(slot);
|
|
|
9ae3a8 |
+ ssdt_ptr[ACPI_PCIHP_OFFSET_ID] = slot;
|
|
|
9ae3a8 |
+ ssdt_ptr[ACPI_PCIHP_OFFSET_ADR + 2] = slot;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Runtime patching of ACPI_EJ0: to disable hotplug for a slot,
|
|
|
9ae3a8 |
+ * replace the method name: _EJ0 by ACPI_EJ0_.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ /* Sanity check */
|
|
|
9ae3a8 |
+ assert(!memcmp(ssdt_ptr + ACPI_PCIHP_OFFSET_EJ0, "_EJ0", 4));
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (!eject) {
|
|
|
9ae3a8 |
+ memcpy(ssdt_ptr + ACPI_PCIHP_OFFSET_EJ0, "EJ0_", 4);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ *ACPI_BUILD_PTR(start, size, acpi_pci32_start[0], uint32_t) =
|
|
|
9ae3a8 |
+ cpu_to_le32(pci->w32.begin);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ *ACPI_BUILD_PTR(start, size, acpi_pci32_end[0], uint32_t) =
|
|
|
9ae3a8 |
+ cpu_to_le32(pci->w32.end - 1);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (pci->w64.end || pci->w64.begin) {
|
|
|
9ae3a8 |
+ *ACPI_BUILD_PTR(start, size, acpi_pci64_valid[0], uint8_t) = 1;
|
|
|
9ae3a8 |
+ *ACPI_BUILD_PTR(start, size, acpi_pci64_start[0], uint64_t) =
|
|
|
9ae3a8 |
+ cpu_to_le64(pci->w64.begin);
|
|
|
9ae3a8 |
+ *ACPI_BUILD_PTR(start, size, acpi_pci64_end[0], uint64_t) =
|
|
|
9ae3a8 |
+ cpu_to_le64(pci->w64.end - 1);
|
|
|
9ae3a8 |
+ *ACPI_BUILD_PTR(start, size, acpi_pci64_length[0], uint64_t) =
|
|
|
9ae3a8 |
+ cpu_to_le64(pci->w64.end - pci->w64.begin);
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ *ACPI_BUILD_PTR(start, size, acpi_pci64_valid[0], uint8_t) = 0;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void
|
|
|
9ae3a8 |
+build_ssdt(GArray *table_data, GArray *linker,
|
|
|
9ae3a8 |
+ AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
|
|
|
9ae3a8 |
+ PcPciInfo *pci, PcGuestInfo *guest_info)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ int acpi_cpus = MIN(0xff, guest_info->apic_id_limit);
|
|
|
9ae3a8 |
+ int ssdt_start = table_data->len;
|
|
|
9ae3a8 |
+ uint8_t *ssdt_ptr;
|
|
|
9ae3a8 |
+ int i;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Copy header and patch values in the S3_ / S4_ / S5_ packages */
|
|
|
9ae3a8 |
+ ssdt_ptr = acpi_data_push(table_data, sizeof(ssdp_misc_aml));
|
|
|
9ae3a8 |
+ memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
|
|
|
9ae3a8 |
+ if (pm->s3_disabled) {
|
|
|
9ae3a8 |
+ ssdt_ptr[acpi_s3_name[0]] = 'X';
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (pm->s4_disabled) {
|
|
|
9ae3a8 |
+ ssdt_ptr[acpi_s4_name[0]] = 'X';
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ ssdt_ptr[acpi_s4_pkg[0] + 1] = ssdt_ptr[acpi_s4_pkg[0] + 3] =
|
|
|
9ae3a8 |
+ pm->s4_val;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ *(uint16_t *)(ssdt_ptr + *ssdt_isa_pest) =
|
|
|
9ae3a8 |
+ cpu_to_le16(misc->pvpanic_port);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ GArray *sb_scope = build_alloc_array();
|
|
|
9ae3a8 |
+ uint8_t op = 0x10; /* ScopeOp */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_append_nameseg(sb_scope, "_SB_");
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* build Processor object for each processor */
|
|
|
9ae3a8 |
+ for (i = 0; i < acpi_cpus; i++) {
|
|
|
9ae3a8 |
+ uint8_t *proc = acpi_data_push(sb_scope, ACPI_PROC_SIZEOF);
|
|
|
9ae3a8 |
+ memcpy(proc, ACPI_PROC_AML, ACPI_PROC_SIZEOF);
|
|
|
9ae3a8 |
+ proc[ACPI_PROC_OFFSET_CPUHEX] = acpi_get_hex(i >> 4);
|
|
|
9ae3a8 |
+ proc[ACPI_PROC_OFFSET_CPUHEX+1] = acpi_get_hex(i);
|
|
|
9ae3a8 |
+ proc[ACPI_PROC_OFFSET_CPUID1] = i;
|
|
|
9ae3a8 |
+ proc[ACPI_PROC_OFFSET_CPUID2] = i;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* build this code:
|
|
|
9ae3a8 |
+ * Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...}
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ /* Arg0 = Processor ID = APIC ID */
|
|
|
9ae3a8 |
+ build_append_notify(sb_scope, "NTFY", "CP%0.02X", 0, acpi_cpus);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" */
|
|
|
9ae3a8 |
+ build_append_byte(sb_scope, 0x08); /* NameOp */
|
|
|
9ae3a8 |
+ build_append_nameseg(sb_scope, "CPON");
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ GArray *package = build_alloc_array();
|
|
|
9ae3a8 |
+ uint8_t op = 0x12; /* PackageOp */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_append_byte(package, acpi_cpus); /* NumElements */
|
|
|
9ae3a8 |
+ for (i = 0; i < acpi_cpus; i++) {
|
|
|
9ae3a8 |
+ uint8_t b = test_bit(i, cpu->found_cpus) ? 0x01 : 0x00;
|
|
|
9ae3a8 |
+ build_append_byte(package, b);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_package(package, op, 2);
|
|
|
9ae3a8 |
+ build_append_array(sb_scope, package);
|
|
|
9ae3a8 |
+ build_free_array(package);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ GArray *pci0 = build_alloc_array();
|
|
|
9ae3a8 |
+ uint8_t op = 0x10; /* ScopeOp */;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_append_nameseg(pci0, "PCI0");
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* build Device object for each slot */
|
|
|
9ae3a8 |
+ for (i = 1; i < PCI_SLOT_MAX; i++) {
|
|
|
9ae3a8 |
+ bool eject = test_bit(i, misc->slot_hotplug_enable);
|
|
|
9ae3a8 |
+ void *pcihp = acpi_data_push(pci0, ACPI_PCIHP_SIZEOF);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
|
|
|
9ae3a8 |
+ patch_pcihp(i, pcihp, eject);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_append_notify(pci0, "PCNT", "S%0.02X_", 1, PCI_SLOT_MAX);
|
|
|
9ae3a8 |
+ build_package(pci0, op, 3);
|
|
|
9ae3a8 |
+ build_append_array(sb_scope, pci0);
|
|
|
9ae3a8 |
+ build_free_array(pci0);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_package(sb_scope, op, 3);
|
|
|
9ae3a8 |
+ build_append_array(table_data, sb_scope);
|
|
|
9ae3a8 |
+ build_free_array(sb_scope);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_header(linker, table_data,
|
|
|
9ae3a8 |
+ (void *)(table_data->data + ssdt_start),
|
|
|
9ae3a8 |
+ ACPI_SSDT_SIGNATURE, table_data->len - ssdt_start, 1);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void
|
|
|
9ae3a8 |
+build_hpet(GArray *table_data, GArray *linker)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ Acpi20Hpet *hpet;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ hpet = acpi_data_push(table_data, sizeof(*hpet));
|
|
|
9ae3a8 |
+ /* Note timer_block_id value must be kept in sync with value advertised by
|
|
|
9ae3a8 |
+ * emulated hpet
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ hpet->timer_block_id = cpu_to_le32(0x8086a201);
|
|
|
9ae3a8 |
+ hpet->addr.address = cpu_to_le64(HPET_BASE);
|
|
|
9ae3a8 |
+ build_header(linker, table_data,
|
|
|
9ae3a8 |
+ (void *)hpet, ACPI_HPET_SIGNATURE, sizeof(*hpet), 1);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void
|
|
|
9ae3a8 |
+acpi_build_srat_memory(AcpiSratMemoryAffinity *numamem,
|
|
|
9ae3a8 |
+ uint64_t base, uint64_t len, int node, int enabled)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ numamem->type = ACPI_SRAT_MEMORY;
|
|
|
9ae3a8 |
+ numamem->length = sizeof(*numamem);
|
|
|
9ae3a8 |
+ memset(numamem->proximity, 0, 4);
|
|
|
9ae3a8 |
+ numamem->proximity[0] = node;
|
|
|
9ae3a8 |
+ numamem->flags = cpu_to_le32(!!enabled);
|
|
|
9ae3a8 |
+ numamem->base_addr = cpu_to_le64(base);
|
|
|
9ae3a8 |
+ numamem->range_length = cpu_to_le64(len);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void
|
|
|
9ae3a8 |
+build_srat(GArray *table_data, GArray *linker,
|
|
|
9ae3a8 |
+ AcpiCpuInfo *cpu, PcGuestInfo *guest_info)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ AcpiSystemResourceAffinityTable *srat;
|
|
|
9ae3a8 |
+ AcpiSratProcessorAffinity *core;
|
|
|
9ae3a8 |
+ AcpiSratMemoryAffinity *numamem;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ int i;
|
|
|
9ae3a8 |
+ uint64_t curnode;
|
|
|
9ae3a8 |
+ int srat_start, numa_start, slots;
|
|
|
9ae3a8 |
+ uint64_t mem_len, mem_base, next_base;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ srat_start = table_data->len;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ srat = acpi_data_push(table_data, sizeof *srat);
|
|
|
9ae3a8 |
+ srat->reserved1 = cpu_to_le32(1);
|
|
|
9ae3a8 |
+ core = (void *)(srat + 1);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ for (i = 0; i < guest_info->apic_id_limit; ++i) {
|
|
|
9ae3a8 |
+ core = acpi_data_push(table_data, sizeof *core);
|
|
|
9ae3a8 |
+ core->type = ACPI_SRAT_PROCESSOR;
|
|
|
9ae3a8 |
+ core->length = sizeof(*core);
|
|
|
9ae3a8 |
+ core->local_apic_id = i;
|
|
|
9ae3a8 |
+ curnode = guest_info->node_cpu[i];
|
|
|
9ae3a8 |
+ core->proximity_lo = curnode;
|
|
|
9ae3a8 |
+ memset(core->proximity_hi, 0, 3);
|
|
|
9ae3a8 |
+ core->local_sapic_eid = 0;
|
|
|
9ae3a8 |
+ if (test_bit(i, cpu->found_cpus)) {
|
|
|
9ae3a8 |
+ core->flags = cpu_to_le32(1);
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ core->flags = cpu_to_le32(0);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* the memory map is a bit tricky, it contains at least one hole
|
|
|
9ae3a8 |
+ * from 640k-1M and possibly another one from 3.5G-4G.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ next_base = 0;
|
|
|
9ae3a8 |
+ numa_start = table_data->len;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ numamem = acpi_data_push(table_data, sizeof *numamem);
|
|
|
9ae3a8 |
+ acpi_build_srat_memory(numamem, 0, 640*1024, 0, 1);
|
|
|
9ae3a8 |
+ next_base = 1024 * 1024;
|
|
|
9ae3a8 |
+ for (i = 1; i < guest_info->numa_nodes + 1; ++i) {
|
|
|
9ae3a8 |
+ mem_base = next_base;
|
|
|
9ae3a8 |
+ mem_len = guest_info->node_mem[i - 1];
|
|
|
9ae3a8 |
+ if (i == 1) {
|
|
|
9ae3a8 |
+ mem_len -= 1024 * 1024;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ next_base = mem_base + mem_len;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Cut out the ACPI_PCI hole */
|
|
|
9ae3a8 |
+ if (mem_base <= guest_info->ram_size &&
|
|
|
9ae3a8 |
+ next_base > guest_info->ram_size) {
|
|
|
9ae3a8 |
+ mem_len -= next_base - guest_info->ram_size;
|
|
|
9ae3a8 |
+ if (mem_len > 0) {
|
|
|
9ae3a8 |
+ numamem = acpi_data_push(table_data, sizeof *numamem);
|
|
|
9ae3a8 |
+ acpi_build_srat_memory(numamem, mem_base, mem_len, i-1, 1);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ mem_base = 1ULL << 32;
|
|
|
9ae3a8 |
+ mem_len = next_base - guest_info->ram_size;
|
|
|
9ae3a8 |
+ next_base += (1ULL << 32) - guest_info->ram_size;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ numamem = acpi_data_push(table_data, sizeof *numamem);
|
|
|
9ae3a8 |
+ acpi_build_srat_memory(numamem, mem_base, mem_len, i - 1, 1);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ slots = (table_data->len - numa_start) / sizeof *numamem;
|
|
|
9ae3a8 |
+ for (; slots < guest_info->numa_nodes + 2; slots++) {
|
|
|
9ae3a8 |
+ numamem = acpi_data_push(table_data, sizeof *numamem);
|
|
|
9ae3a8 |
+ acpi_build_srat_memory(numamem, 0, 0, 0, 0);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_header(linker, table_data,
|
|
|
9ae3a8 |
+ (void *)(table_data->data + srat_start),
|
|
|
9ae3a8 |
+ ACPI_SRAT_SIGNATURE,
|
|
|
9ae3a8 |
+ table_data->len - srat_start, 1);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void
|
|
|
9ae3a8 |
+build_mcfg_q35(GArray *table_data, GArray *linker, AcpiMcfgInfo *info)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ AcpiTableMcfg *mcfg;
|
|
|
9ae3a8 |
+ uint32_t sig;
|
|
|
9ae3a8 |
+ int len = sizeof(*mcfg) + 1 * sizeof(mcfg->allocation[0]);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ mcfg = acpi_data_push(table_data, len);
|
|
|
9ae3a8 |
+ mcfg->allocation[0].address = cpu_to_le64(info->mcfg_base);
|
|
|
9ae3a8 |
+ /* Only a single allocation so no need to play with segments */
|
|
|
9ae3a8 |
+ mcfg->allocation[0].pci_segment = cpu_to_le16(0);
|
|
|
9ae3a8 |
+ mcfg->allocation[0].start_bus_number = 0;
|
|
|
9ae3a8 |
+ mcfg->allocation[0].end_bus_number = PCIE_MMCFG_BUS(info->mcfg_size - 1);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* MCFG is used for ECAM which can be enabled or disabled by guest.
|
|
|
9ae3a8 |
+ * To avoid table size changes (which create migration issues),
|
|
|
9ae3a8 |
+ * always create the table even if there are no allocations,
|
|
|
9ae3a8 |
+ * but set the signature to a reserved value in this case.
|
|
|
9ae3a8 |
+ * ACPI spec requires OSPMs to ignore such tables.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ if (info->mcfg_base == PCIE_BASE_ADDR_UNMAPPED) {
|
|
|
9ae3a8 |
+ sig = ACPI_RSRV_SIGNATURE;
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ sig = ACPI_MCFG_SIGNATURE;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ build_header(linker, table_data, (void *)mcfg, sig, len, 1);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void
|
|
|
9ae3a8 |
+build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ void *dsdt;
|
|
|
9ae3a8 |
+ assert(misc->dsdt_code && misc->dsdt_size);
|
|
|
9ae3a8 |
+ dsdt = acpi_data_push(table_data, misc->dsdt_size);
|
|
|
9ae3a8 |
+ memcpy(dsdt, misc->dsdt_code, misc->dsdt_size);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* Build final rsdt table */
|
|
|
9ae3a8 |
+static void
|
|
|
9ae3a8 |
+build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ AcpiRsdtDescriptorRev1 *rsdt;
|
|
|
9ae3a8 |
+ size_t rsdt_len;
|
|
|
9ae3a8 |
+ int i;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ rsdt_len = sizeof(*rsdt) + sizeof(uint32_t) * table_offsets->len;
|
|
|
9ae3a8 |
+ rsdt = acpi_data_push(table_data, rsdt_len);
|
|
|
9ae3a8 |
+ memcpy(rsdt->table_offset_entry, table_offsets->data,
|
|
|
9ae3a8 |
+ sizeof(uint32_t) * table_offsets->len);
|
|
|
9ae3a8 |
+ for (i = 0; i < table_offsets->len; ++i) {
|
|
|
9ae3a8 |
+ /* rsdt->table_offset_entry to be filled by Guest linker */
|
|
|
9ae3a8 |
+ bios_linker_loader_add_pointer(linker,
|
|
|
9ae3a8 |
+ ACPI_BUILD_TABLE_FILE,
|
|
|
9ae3a8 |
+ ACPI_BUILD_TABLE_FILE,
|
|
|
9ae3a8 |
+ table_data, &rsdt->table_offset_entry[i],
|
|
|
9ae3a8 |
+ sizeof(uint32_t));
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ build_header(linker, table_data,
|
|
|
9ae3a8 |
+ (void *)rsdt, ACPI_RSDT_SIGNATURE, rsdt_len, 1);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static GArray *
|
|
|
9ae3a8 |
+build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, 1,
|
|
|
9ae3a8 |
+ true /* fseg memory */);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ rsdp->signature = cpu_to_le64(ACPI_RSDP_SIGNATURE);
|
|
|
9ae3a8 |
+ memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
|
|
|
9ae3a8 |
+ rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
|
|
|
9ae3a8 |
+ /* Address to be filled by Guest linker */
|
|
|
9ae3a8 |
+ bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
|
|
|
9ae3a8 |
+ ACPI_BUILD_TABLE_FILE,
|
|
|
9ae3a8 |
+ rsdp_table, &rsdp->rsdt_physical_address,
|
|
|
9ae3a8 |
+ sizeof rsdp->rsdt_physical_address);
|
|
|
9ae3a8 |
+ rsdp->checksum = 0;
|
|
|
9ae3a8 |
+ /* Checksum to be filled by Guest linker */
|
|
|
9ae3a8 |
+ bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
|
|
|
9ae3a8 |
+ rsdp, rsdp, sizeof *rsdp, &rsdp->checksum);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return rsdp_table;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+typedef
|
|
|
9ae3a8 |
+struct AcpiBuildTables {
|
|
|
9ae3a8 |
+ GArray *table_data;
|
|
|
9ae3a8 |
+ GArray *rsdp;
|
|
|
9ae3a8 |
+ GArray *linker;
|
|
|
9ae3a8 |
+} AcpiBuildTables;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static inline void acpi_build_tables_init(AcpiBuildTables *tables)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ tables->rsdp = g_array_new(false, true /* clear */, 1);
|
|
|
9ae3a8 |
+ tables->table_data = g_array_new(false, true /* clear */, 1);
|
|
|
9ae3a8 |
+ tables->linker = bios_linker_loader_init();
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static inline void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ void *linker_data = bios_linker_loader_cleanup(tables->linker);
|
|
|
9ae3a8 |
+ if (mfre) {
|
|
|
9ae3a8 |
+ g_free(linker_data);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ g_array_free(tables->rsdp, mfre);
|
|
|
9ae3a8 |
+ g_array_free(tables->table_data, mfre);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+typedef
|
|
|
9ae3a8 |
+struct AcpiBuildState {
|
|
|
9ae3a8 |
+ /* Copy of table in RAM (for patching). */
|
|
|
9ae3a8 |
+ uint8_t *table_ram;
|
|
|
9ae3a8 |
+ uint32_t table_size;
|
|
|
9ae3a8 |
+ /* Is table patched? */
|
|
|
9ae3a8 |
+ uint8_t patched;
|
|
|
9ae3a8 |
+ PcGuestInfo *guest_info;
|
|
|
9ae3a8 |
+} AcpiBuildState;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ Object *pci_host;
|
|
|
9ae3a8 |
+ QObject *o;
|
|
|
9ae3a8 |
+ bool ambiguous;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ pci_host = object_resolve_path_type("", TYPE_PCI_HOST_BRIDGE, &ambiguous);
|
|
|
9ae3a8 |
+ g_assert(!ambiguous);
|
|
|
9ae3a8 |
+ g_assert(pci_host);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ o = object_property_get_qobject(pci_host, PCIE_HOST_MCFG_BASE, NULL);
|
|
|
9ae3a8 |
+ if (!o) {
|
|
|
9ae3a8 |
+ return false;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ mcfg->mcfg_base = qint_get_int(qobject_to_qint(o));
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ o = object_property_get_qobject(pci_host, PCIE_HOST_MCFG_SIZE, NULL);
|
|
|
9ae3a8 |
+ assert(o);
|
|
|
9ae3a8 |
+ mcfg->mcfg_size = qint_get_int(qobject_to_qint(o));
|
|
|
9ae3a8 |
+ return true;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static
|
|
|
9ae3a8 |
+void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ GArray *table_offsets;
|
|
|
9ae3a8 |
+ unsigned facs, dsdt, rsdt;
|
|
|
9ae3a8 |
+ AcpiCpuInfo cpu;
|
|
|
9ae3a8 |
+ AcpiPmInfo pm;
|
|
|
9ae3a8 |
+ AcpiMiscInfo misc;
|
|
|
9ae3a8 |
+ AcpiMcfgInfo mcfg;
|
|
|
9ae3a8 |
+ PcPciInfo pci;
|
|
|
9ae3a8 |
+ uint8_t *u;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ acpi_get_cpu_info(&cpu);
|
|
|
9ae3a8 |
+ acpi_get_pm_info(&pm);
|
|
|
9ae3a8 |
+ acpi_get_dsdt(&misc);
|
|
|
9ae3a8 |
+ acpi_get_hotplug_info(&misc);
|
|
|
9ae3a8 |
+ acpi_get_misc_info(&misc);
|
|
|
9ae3a8 |
+ acpi_get_pci_info(&pci;;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ table_offsets = g_array_new(false, true /* clear */,
|
|
|
9ae3a8 |
+ sizeof(uint32_t));
|
|
|
9ae3a8 |
+ ACPI_BUILD_DPRINTF(3, "init ACPI tables\n");
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ bios_linker_loader_alloc(tables->linker, ACPI_BUILD_TABLE_FILE,
|
|
|
9ae3a8 |
+ 64 /* Ensure FACS is aligned */,
|
|
|
9ae3a8 |
+ false /* high memory */);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /*
|
|
|
9ae3a8 |
+ * FACS is pointed to by FADT.
|
|
|
9ae3a8 |
+ * We place it first since it's the only table that has alignment
|
|
|
9ae3a8 |
+ * requirements.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ facs = tables->table_data->len;
|
|
|
9ae3a8 |
+ build_facs(tables->table_data, tables->linker, guest_info);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* DSDT is pointed to by FADT */
|
|
|
9ae3a8 |
+ dsdt = tables->table_data->len;
|
|
|
9ae3a8 |
+ build_dsdt(tables->table_data, tables->linker, &misc);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* ACPI tables pointed to by RSDT */
|
|
|
9ae3a8 |
+ acpi_add_table(table_offsets, tables->table_data);
|
|
|
9ae3a8 |
+ build_fadt(tables->table_data, tables->linker, &pm, facs, dsdt);
|
|
|
9ae3a8 |
+ acpi_add_table(table_offsets, tables->table_data);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_ssdt(tables->table_data, tables->linker, &cpu, &pm, &misc, &pci,
|
|
|
9ae3a8 |
+ guest_info);
|
|
|
9ae3a8 |
+ acpi_add_table(table_offsets, tables->table_data);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_madt(tables->table_data, tables->linker, &cpu, guest_info);
|
|
|
9ae3a8 |
+ acpi_add_table(table_offsets, tables->table_data);
|
|
|
9ae3a8 |
+ if (misc.has_hpet) {
|
|
|
9ae3a8 |
+ build_hpet(tables->table_data, tables->linker);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (guest_info->numa_nodes) {
|
|
|
9ae3a8 |
+ acpi_add_table(table_offsets, tables->table_data);
|
|
|
9ae3a8 |
+ build_srat(tables->table_data, tables->linker, &cpu, guest_info);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (acpi_get_mcfg(&mcfg)) {
|
|
|
9ae3a8 |
+ acpi_add_table(table_offsets, tables->table_data);
|
|
|
9ae3a8 |
+ build_mcfg_q35(tables->table_data, tables->linker, &mcfg);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Add tables supplied by user (if any) */
|
|
|
9ae3a8 |
+ for (u = acpi_table_first(); u; u = acpi_table_next(u)) {
|
|
|
9ae3a8 |
+ unsigned len = acpi_table_len(u);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ acpi_add_table(table_offsets, tables->table_data);
|
|
|
9ae3a8 |
+ g_array_append_vals(tables->table_data, u, len);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* RSDT is pointed to by RSDP */
|
|
|
9ae3a8 |
+ rsdt = tables->table_data->len;
|
|
|
9ae3a8 |
+ build_rsdt(tables->table_data, tables->linker, table_offsets);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* RSDP is in FSEG memory, so allocate it separately */
|
|
|
9ae3a8 |
+ build_rsdp(tables->rsdp, tables->linker, rsdt);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* We'll expose it all to Guest so align size to reduce
|
|
|
9ae3a8 |
+ * chance of size changes.
|
|
|
9ae3a8 |
+ * RSDP is small so it's easy to keep it immutable, no need to
|
|
|
9ae3a8 |
+ * bother with alignment.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ acpi_align_size(tables->table_data, 0x1000);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ acpi_align_size(tables->linker, 0x1000);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Cleanup memory that's no longer used. */
|
|
|
9ae3a8 |
+ g_array_free(table_offsets, true);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void acpi_build_update(void *build_opaque, uint32_t offset)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ AcpiBuildState *build_state = build_opaque;
|
|
|
9ae3a8 |
+ AcpiBuildTables tables;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* No state to update or already patched? Nothing to do. */
|
|
|
9ae3a8 |
+ if (!build_state || build_state->patched) {
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ build_state->patched = 1;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ acpi_build_tables_init(&tables);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ acpi_build(build_state->guest_info, &tables);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ assert(acpi_data_len(tables.table_data) == build_state->table_size);
|
|
|
9ae3a8 |
+ memcpy(build_state->table_ram, tables.table_data->data,
|
|
|
9ae3a8 |
+ build_state->table_size);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ acpi_build_tables_cleanup(&tables, true);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void acpi_build_reset(void *build_opaque)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ AcpiBuildState *build_state = build_opaque;
|
|
|
9ae3a8 |
+ build_state->patched = 0;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void *acpi_add_rom_blob(AcpiBuildState *build_state, GArray *blob,
|
|
|
9ae3a8 |
+ const char *name)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ return rom_add_blob(name, blob->data, acpi_data_len(blob), -1, name,
|
|
|
9ae3a8 |
+ acpi_build_update, build_state);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static const VMStateDescription vmstate_acpi_build = {
|
|
|
9ae3a8 |
+ .name = "acpi_build",
|
|
|
9ae3a8 |
+ .version_id = 1,
|
|
|
9ae3a8 |
+ .minimum_version_id = 1,
|
|
|
9ae3a8 |
+ .minimum_version_id_old = 1,
|
|
|
9ae3a8 |
+ .fields = (VMStateField[]) {
|
|
|
9ae3a8 |
+ VMSTATE_UINT8(patched, AcpiBuildState),
|
|
|
9ae3a8 |
+ VMSTATE_END_OF_LIST()
|
|
|
9ae3a8 |
+ },
|
|
|
9ae3a8 |
+};
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+void acpi_setup(PcGuestInfo *guest_info)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ AcpiBuildTables tables;
|
|
|
9ae3a8 |
+ AcpiBuildState *build_state;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (!guest_info->fw_cfg) {
|
|
|
9ae3a8 |
+ ACPI_BUILD_DPRINTF(3, "No fw cfg. Bailing out.\n");
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (!guest_info->has_acpi_build) {
|
|
|
9ae3a8 |
+ ACPI_BUILD_DPRINTF(3, "ACPI build disabled. Bailing out.\n");
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_state = g_malloc0(sizeof *build_state);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ build_state->guest_info = guest_info;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ acpi_build_tables_init(&tables);
|
|
|
9ae3a8 |
+ acpi_build(build_state->guest_info, &tables);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Now expose it all to Guest */
|
|
|
9ae3a8 |
+ build_state->table_ram = acpi_add_rom_blob(build_state, tables.table_data,
|
|
|
9ae3a8 |
+ ACPI_BUILD_TABLE_FILE);
|
|
|
9ae3a8 |
+ build_state->table_size = acpi_data_len(tables.table_data);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader");
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /*
|
|
|
9ae3a8 |
+ * RSDP is small so it's easy to keep it immutable, no need to
|
|
|
9ae3a8 |
+ * bother with ROM blobs.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
|
|
|
9ae3a8 |
+ tables.rsdp->data, acpi_data_len(tables.rsdp));
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ qemu_register_reset(acpi_build_reset, build_state);
|
|
|
9ae3a8 |
+ acpi_build_reset(build_state);
|
|
|
9ae3a8 |
+ vmstate_register(NULL, 0, &vmstate_acpi_build, build_state);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Cleanup tables but don't free the memory: we track it
|
|
|
9ae3a8 |
+ * in build_state.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ acpi_build_tables_cleanup(&tables, false);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
diff --git a/hw/i386/acpi-build.h b/hw/i386/acpi-build.h
|
|
|
9ae3a8 |
new file mode 100644
|
|
|
9ae3a8 |
index 0000000..e57b1aa
|
|
|
9ae3a8 |
--- /dev/null
|
|
|
9ae3a8 |
+++ b/hw/i386/acpi-build.h
|
|
|
9ae3a8 |
@@ -0,0 +1,9 @@
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#ifndef HW_I386_ACPI_BUILD_H
|
|
|
9ae3a8 |
+#define HW_I386_ACPI_BUILD_H
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#include "qemu/typedefs.h"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+void acpi_setup(PcGuestInfo *);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#endif
|
|
|
9ae3a8 |
diff --git a/hw/i386/acpi-defs.h b/hw/i386/acpi-defs.h
|
|
|
9ae3a8 |
new file mode 100644
|
|
|
9ae3a8 |
index 0000000..78ca204
|
|
|
9ae3a8 |
--- /dev/null
|
|
|
9ae3a8 |
+++ b/hw/i386/acpi-defs.h
|
|
|
9ae3a8 |
@@ -0,0 +1,331 @@
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * This program is free software; you can redistribute it and/or modify
|
|
|
9ae3a8 |
+ * it under the terms of the GNU General Public License as published by
|
|
|
9ae3a8 |
+ * the Free Software Foundation; either version 2 of the License, or
|
|
|
9ae3a8 |
+ * (at your option) any later version.
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ * This program is distributed in the hope that it will be useful,
|
|
|
9ae3a8 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9ae3a8 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
9ae3a8 |
+ * GNU General Public License for more details.
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ * You should have received a copy of the GNU General Public License along
|
|
|
9ae3a8 |
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+#ifndef QEMU_ACPI_DEFS_H
|
|
|
9ae3a8 |
+#define QEMU_ACPI_DEFS_H
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+enum {
|
|
|
9ae3a8 |
+ ACPI_FADT_F_WBINVD,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_WBINVD_FLUSH,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_PROC_C1,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_P_LVL2_UP,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_PWR_BUTTON,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_SLP_BUTTON,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_FIX_RTC,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_RTC_S4,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_TMR_VAL_EXT,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_DCK_CAP,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_RESET_REG_SUP,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_SEALED_CASE,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_HEADLESS,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_CPU_SW_SLP,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_PCI_EXP_WAK,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_USE_PLATFORM_CLOCK,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_S4_RTC_STS_VALID,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_REMOTE_POWER_ON_CAPABLE,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_FORCE_APIC_CLUSTER_MODEL,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_FORCE_APIC_PHYSICAL_DESTINATION_MODE,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_HW_REDUCED_ACPI,
|
|
|
9ae3a8 |
+ ACPI_FADT_F_LOW_POWER_S0_IDLE_CAPABLE,
|
|
|
9ae3a8 |
+};
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * ACPI 2.0 Generic Address Space definition.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+struct Acpi20GenericAddress {
|
|
|
9ae3a8 |
+ uint8_t address_space_id;
|
|
|
9ae3a8 |
+ uint8_t register_bit_width;
|
|
|
9ae3a8 |
+ uint8_t register_bit_offset;
|
|
|
9ae3a8 |
+ uint8_t reserved;
|
|
|
9ae3a8 |
+ uint64_t address;
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct Acpi20GenericAddress Acpi20GenericAddress;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define ACPI_RSDP_SIGNATURE 0x2052545020445352LL // "RSD PTR "
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+struct AcpiRsdpDescriptor { /* Root System Descriptor Pointer */
|
|
|
9ae3a8 |
+ uint64_t signature; /* ACPI signature, contains "RSD PTR " */
|
|
|
9ae3a8 |
+ uint8_t checksum; /* To make sum of struct == 0 */
|
|
|
9ae3a8 |
+ uint8_t oem_id [6]; /* OEM identification */
|
|
|
9ae3a8 |
+ uint8_t revision; /* Must be 0 for 1.0, 2 for 2.0 */
|
|
|
9ae3a8 |
+ uint32_t rsdt_physical_address; /* 32-bit physical address of RSDT */
|
|
|
9ae3a8 |
+ uint32_t length; /* XSDT Length in bytes including hdr */
|
|
|
9ae3a8 |
+ uint64_t xsdt_physical_address; /* 64-bit physical address of XSDT */
|
|
|
9ae3a8 |
+ uint8_t extended_checksum; /* Checksum of entire table */
|
|
|
9ae3a8 |
+ uint8_t reserved [3]; /* Reserved field must be 0 */
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiRsdpDescriptor AcpiRsdpDescriptor;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* Table structure from Linux kernel (the ACPI tables are under the
|
|
|
9ae3a8 |
+ BSD license) */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define ACPI_TABLE_HEADER_DEF /* ACPI common table header */ \
|
|
|
9ae3a8 |
+ uint32_t signature; /* ACPI signature (4 ASCII characters) */ \
|
|
|
9ae3a8 |
+ uint32_t length; /* Length of table, in bytes, including header */ \
|
|
|
9ae3a8 |
+ uint8_t revision; /* ACPI Specification minor version # */ \
|
|
|
9ae3a8 |
+ uint8_t checksum; /* To make sum of entire table == 0 */ \
|
|
|
9ae3a8 |
+ uint8_t oem_id [6]; /* OEM identification */ \
|
|
|
9ae3a8 |
+ uint8_t oem_table_id [8]; /* OEM table identification */ \
|
|
|
9ae3a8 |
+ uint32_t oem_revision; /* OEM revision number */ \
|
|
|
9ae3a8 |
+ uint8_t asl_compiler_id [4]; /* ASL compiler vendor ID */ \
|
|
|
9ae3a8 |
+ uint32_t asl_compiler_revision; /* ASL compiler revision number */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+struct AcpiTableHeader /* ACPI common table header */
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ ACPI_TABLE_HEADER_DEF
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiTableHeader AcpiTableHeader;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * ACPI 1.0 Fixed ACPI Description Table (FADT)
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+#define ACPI_FACP_SIGNATURE 0x50434146 // FACP
|
|
|
9ae3a8 |
+struct AcpiFadtDescriptorRev1
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ ACPI_TABLE_HEADER_DEF /* ACPI common table header */
|
|
|
9ae3a8 |
+ uint32_t firmware_ctrl; /* Physical address of FACS */
|
|
|
9ae3a8 |
+ uint32_t dsdt; /* Physical address of DSDT */
|
|
|
9ae3a8 |
+ uint8_t model; /* System Interrupt Model */
|
|
|
9ae3a8 |
+ uint8_t reserved1; /* Reserved */
|
|
|
9ae3a8 |
+ uint16_t sci_int; /* System vector of SCI interrupt */
|
|
|
9ae3a8 |
+ uint32_t smi_cmd; /* Port address of SMI command port */
|
|
|
9ae3a8 |
+ uint8_t acpi_enable; /* Value to write to smi_cmd to enable ACPI */
|
|
|
9ae3a8 |
+ uint8_t acpi_disable; /* Value to write to smi_cmd to disable ACPI */
|
|
|
9ae3a8 |
+ uint8_t S4bios_req; /* Value to write to SMI CMD to enter S4BIOS state */
|
|
|
9ae3a8 |
+ uint8_t reserved2; /* Reserved - must be zero */
|
|
|
9ae3a8 |
+ uint32_t pm1a_evt_blk; /* Port address of Power Mgt 1a acpi_event Reg Blk */
|
|
|
9ae3a8 |
+ uint32_t pm1b_evt_blk; /* Port address of Power Mgt 1b acpi_event Reg Blk */
|
|
|
9ae3a8 |
+ uint32_t pm1a_cnt_blk; /* Port address of Power Mgt 1a Control Reg Blk */
|
|
|
9ae3a8 |
+ uint32_t pm1b_cnt_blk; /* Port address of Power Mgt 1b Control Reg Blk */
|
|
|
9ae3a8 |
+ uint32_t pm2_cnt_blk; /* Port address of Power Mgt 2 Control Reg Blk */
|
|
|
9ae3a8 |
+ uint32_t pm_tmr_blk; /* Port address of Power Mgt Timer Ctrl Reg Blk */
|
|
|
9ae3a8 |
+ uint32_t gpe0_blk; /* Port addr of General Purpose acpi_event 0 Reg Blk */
|
|
|
9ae3a8 |
+ uint32_t gpe1_blk; /* Port addr of General Purpose acpi_event 1 Reg Blk */
|
|
|
9ae3a8 |
+ uint8_t pm1_evt_len; /* Byte length of ports at pm1_x_evt_blk */
|
|
|
9ae3a8 |
+ uint8_t pm1_cnt_len; /* Byte length of ports at pm1_x_cnt_blk */
|
|
|
9ae3a8 |
+ uint8_t pm2_cnt_len; /* Byte Length of ports at pm2_cnt_blk */
|
|
|
9ae3a8 |
+ uint8_t pm_tmr_len; /* Byte Length of ports at pm_tm_blk */
|
|
|
9ae3a8 |
+ uint8_t gpe0_blk_len; /* Byte Length of ports at gpe0_blk */
|
|
|
9ae3a8 |
+ uint8_t gpe1_blk_len; /* Byte Length of ports at gpe1_blk */
|
|
|
9ae3a8 |
+ uint8_t gpe1_base; /* Offset in gpe model where gpe1 events start */
|
|
|
9ae3a8 |
+ uint8_t reserved3; /* Reserved */
|
|
|
9ae3a8 |
+ uint16_t plvl2_lat; /* Worst case HW latency to enter/exit C2 state */
|
|
|
9ae3a8 |
+ uint16_t plvl3_lat; /* Worst case HW latency to enter/exit C3 state */
|
|
|
9ae3a8 |
+ uint16_t flush_size; /* Size of area read to flush caches */
|
|
|
9ae3a8 |
+ uint16_t flush_stride; /* Stride used in flushing caches */
|
|
|
9ae3a8 |
+ uint8_t duty_offset; /* Bit location of duty cycle field in p_cnt reg */
|
|
|
9ae3a8 |
+ uint8_t duty_width; /* Bit width of duty cycle field in p_cnt reg */
|
|
|
9ae3a8 |
+ uint8_t day_alrm; /* Index to day-of-month alarm in RTC CMOS RAM */
|
|
|
9ae3a8 |
+ uint8_t mon_alrm; /* Index to month-of-year alarm in RTC CMOS RAM */
|
|
|
9ae3a8 |
+ uint8_t century; /* Index to century in RTC CMOS RAM */
|
|
|
9ae3a8 |
+ uint8_t reserved4; /* Reserved */
|
|
|
9ae3a8 |
+ uint8_t reserved4a; /* Reserved */
|
|
|
9ae3a8 |
+ uint8_t reserved4b; /* Reserved */
|
|
|
9ae3a8 |
+ uint32_t flags;
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiFadtDescriptorRev1 AcpiFadtDescriptorRev1;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * ACPI 1.0 Root System Description Table (RSDT)
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+#define ACPI_RSDT_SIGNATURE 0x54445352 // RSDT
|
|
|
9ae3a8 |
+struct AcpiRsdtDescriptorRev1
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ ACPI_TABLE_HEADER_DEF /* ACPI common table header */
|
|
|
9ae3a8 |
+ uint32_t table_offset_entry[0]; /* Array of pointers to other */
|
|
|
9ae3a8 |
+ /* ACPI tables */
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiRsdtDescriptorRev1 AcpiRsdtDescriptorRev1;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * ACPI 1.0 Firmware ACPI Control Structure (FACS)
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+#define ACPI_FACS_SIGNATURE 0x53434146 // FACS
|
|
|
9ae3a8 |
+struct AcpiFacsDescriptorRev1
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ uint32_t signature; /* ACPI Signature */
|
|
|
9ae3a8 |
+ uint32_t length; /* Length of structure, in bytes */
|
|
|
9ae3a8 |
+ uint32_t hardware_signature; /* Hardware configuration signature */
|
|
|
9ae3a8 |
+ uint32_t firmware_waking_vector; /* ACPI OS waking vector */
|
|
|
9ae3a8 |
+ uint32_t global_lock; /* Global Lock */
|
|
|
9ae3a8 |
+ uint32_t flags;
|
|
|
9ae3a8 |
+ uint8_t resverved3 [40]; /* Reserved - must be zero */
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiFacsDescriptorRev1 AcpiFacsDescriptorRev1;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * Differentiated System Description Table (DSDT)
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+#define ACPI_DSDT_SIGNATURE 0x54445344 // DSDT
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * MADT values and structures
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* Values for MADT PCATCompat */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define ACPI_DUAL_PIC 0
|
|
|
9ae3a8 |
+#define ACPI_MULTIPLE_APIC 1
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* Master MADT */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define ACPI_APIC_SIGNATURE 0x43495041 // APIC
|
|
|
9ae3a8 |
+struct AcpiMultipleApicTable
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ ACPI_TABLE_HEADER_DEF /* ACPI common table header */
|
|
|
9ae3a8 |
+ uint32_t local_apic_address; /* Physical address of local APIC */
|
|
|
9ae3a8 |
+ uint32_t flags;
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiMultipleApicTable AcpiMultipleApicTable;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* Values for Type in APIC sub-headers */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define ACPI_APIC_PROCESSOR 0
|
|
|
9ae3a8 |
+#define ACPI_APIC_IO 1
|
|
|
9ae3a8 |
+#define ACPI_APIC_XRUPT_OVERRIDE 2
|
|
|
9ae3a8 |
+#define ACPI_APIC_NMI 3
|
|
|
9ae3a8 |
+#define ACPI_APIC_LOCAL_NMI 4
|
|
|
9ae3a8 |
+#define ACPI_APIC_ADDRESS_OVERRIDE 5
|
|
|
9ae3a8 |
+#define ACPI_APIC_IO_SAPIC 6
|
|
|
9ae3a8 |
+#define ACPI_APIC_LOCAL_SAPIC 7
|
|
|
9ae3a8 |
+#define ACPI_APIC_XRUPT_SOURCE 8
|
|
|
9ae3a8 |
+#define ACPI_APIC_RESERVED 9 /* 9 and greater are reserved */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * MADT sub-structures (Follow MULTIPLE_APIC_DESCRIPTION_TABLE)
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+#define ACPI_SUB_HEADER_DEF /* Common ACPI sub-structure header */\
|
|
|
9ae3a8 |
+ uint8_t type; \
|
|
|
9ae3a8 |
+ uint8_t length;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* Sub-structures for MADT */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+struct AcpiMadtProcessorApic
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ ACPI_SUB_HEADER_DEF
|
|
|
9ae3a8 |
+ uint8_t processor_id; /* ACPI processor id */
|
|
|
9ae3a8 |
+ uint8_t local_apic_id; /* Processor's local APIC id */
|
|
|
9ae3a8 |
+ uint32_t flags;
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiMadtProcessorApic AcpiMadtProcessorApic;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+struct AcpiMadtIoApic
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ ACPI_SUB_HEADER_DEF
|
|
|
9ae3a8 |
+ uint8_t io_apic_id; /* I/O APIC ID */
|
|
|
9ae3a8 |
+ uint8_t reserved; /* Reserved - must be zero */
|
|
|
9ae3a8 |
+ uint32_t address; /* APIC physical address */
|
|
|
9ae3a8 |
+ uint32_t interrupt; /* Global system interrupt where INTI
|
|
|
9ae3a8 |
+ * lines start */
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiMadtIoApic AcpiMadtIoApic;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+struct AcpiMadtIntsrcovr {
|
|
|
9ae3a8 |
+ ACPI_SUB_HEADER_DEF
|
|
|
9ae3a8 |
+ uint8_t bus;
|
|
|
9ae3a8 |
+ uint8_t source;
|
|
|
9ae3a8 |
+ uint32_t gsi;
|
|
|
9ae3a8 |
+ uint16_t flags;
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiMadtIntsrcovr AcpiMadtIntsrcovr;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+struct AcpiMadtLocalNmi {
|
|
|
9ae3a8 |
+ ACPI_SUB_HEADER_DEF
|
|
|
9ae3a8 |
+ uint8_t processor_id; /* ACPI processor id */
|
|
|
9ae3a8 |
+ uint16_t flags; /* MPS INTI flags */
|
|
|
9ae3a8 |
+ uint8_t lint; /* Local APIC LINT# */
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiMadtLocalNmi AcpiMadtLocalNmi;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * HPET Description Table
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+#define ACPI_HPET_SIGNATURE 0x54455048 // HPET
|
|
|
9ae3a8 |
+struct Acpi20Hpet {
|
|
|
9ae3a8 |
+ ACPI_TABLE_HEADER_DEF /* ACPI common table header */
|
|
|
9ae3a8 |
+ uint32_t timer_block_id;
|
|
|
9ae3a8 |
+ Acpi20GenericAddress addr;
|
|
|
9ae3a8 |
+ uint8_t hpet_number;
|
|
|
9ae3a8 |
+ uint16_t min_tick;
|
|
|
9ae3a8 |
+ uint8_t page_protect;
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct Acpi20Hpet Acpi20Hpet;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * SRAT (NUMA topology description) table
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define ACPI_SRAT_SIGNATURE 0x54415253 // SRAT
|
|
|
9ae3a8 |
+struct AcpiSystemResourceAffinityTable
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ ACPI_TABLE_HEADER_DEF
|
|
|
9ae3a8 |
+ uint32_t reserved1;
|
|
|
9ae3a8 |
+ uint32_t reserved2[2];
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiSystemResourceAffinityTable AcpiSystemResourceAffinityTable;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define ACPI_SRAT_PROCESSOR 0
|
|
|
9ae3a8 |
+#define ACPI_SRAT_MEMORY 1
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+struct AcpiSratProcessorAffinity
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ ACPI_SUB_HEADER_DEF
|
|
|
9ae3a8 |
+ uint8_t proximity_lo;
|
|
|
9ae3a8 |
+ uint8_t local_apic_id;
|
|
|
9ae3a8 |
+ uint32_t flags;
|
|
|
9ae3a8 |
+ uint8_t local_sapic_eid;
|
|
|
9ae3a8 |
+ uint8_t proximity_hi[3];
|
|
|
9ae3a8 |
+ uint32_t reserved;
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiSratProcessorAffinity AcpiSratProcessorAffinity;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+struct AcpiSratMemoryAffinity
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ ACPI_SUB_HEADER_DEF
|
|
|
9ae3a8 |
+ uint8_t proximity[4];
|
|
|
9ae3a8 |
+ uint16_t reserved1;
|
|
|
9ae3a8 |
+ uint64_t base_addr;
|
|
|
9ae3a8 |
+ uint64_t range_length;
|
|
|
9ae3a8 |
+ uint32_t reserved2;
|
|
|
9ae3a8 |
+ uint32_t flags;
|
|
|
9ae3a8 |
+ uint32_t reserved3[2];
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiSratMemoryAffinity AcpiSratMemoryAffinity;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* PCI fw r3.0 MCFG table. */
|
|
|
9ae3a8 |
+/* Subtable */
|
|
|
9ae3a8 |
+struct AcpiMcfgAllocation {
|
|
|
9ae3a8 |
+ uint64_t address; /* Base address, processor-relative */
|
|
|
9ae3a8 |
+ uint16_t pci_segment; /* PCI segment group number */
|
|
|
9ae3a8 |
+ uint8_t start_bus_number; /* Starting PCI Bus number */
|
|
|
9ae3a8 |
+ uint8_t end_bus_number; /* Final PCI Bus number */
|
|
|
9ae3a8 |
+ uint32_t reserved;
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiMcfgAllocation AcpiMcfgAllocation;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define ACPI_MCFG_SIGNATURE 0x4746434d // MCFG
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* Reserved signature: ignored by OSPM */
|
|
|
9ae3a8 |
+#define ACPI_RSRV_SIGNATURE 0x554d4551 // QEMU
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+struct AcpiTableMcfg {
|
|
|
9ae3a8 |
+ ACPI_TABLE_HEADER_DEF;
|
|
|
9ae3a8 |
+ uint8_t reserved[8];
|
|
|
9ae3a8 |
+ AcpiMcfgAllocation allocation[0];
|
|
|
9ae3a8 |
+} QEMU_PACKED;
|
|
|
9ae3a8 |
+typedef struct AcpiTableMcfg AcpiTableMcfg;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#endif
|
|
|
9ae3a8 |
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
|
|
|
9ae3a8 |
index 041e537..320f668 100644
|
|
|
9ae3a8 |
--- a/hw/i386/pc.c
|
|
|
9ae3a8 |
+++ b/hw/i386/pc.c
|
|
|
9ae3a8 |
@@ -56,6 +56,7 @@
|
|
|
9ae3a8 |
#include "hw/cpu/icc_bus.h"
|
|
|
9ae3a8 |
#include "hw/boards.h"
|
|
|
9ae3a8 |
#include "hw/pci/pci_host.h"
|
|
|
9ae3a8 |
+#include "acpi-build.h"
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* debug PC/ISA interrupts */
|
|
|
9ae3a8 |
//#define DEBUG_IRQ
|
|
|
9ae3a8 |
@@ -1035,6 +1036,7 @@ void pc_guest_info_machine_done(Notifier *notifier, void *data)
|
|
|
9ae3a8 |
PcGuestInfoState,
|
|
|
9ae3a8 |
machine_done);
|
|
|
9ae3a8 |
pc_fw_cfg_guest_info(&guest_info_state->info);
|
|
|
9ae3a8 |
+ acpi_setup(&guest_info_state->info);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
|
|
|
9ae3a8 |
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
|
|
|
9ae3a8 |
index 211ff8e..ffa35d3 100644
|
|
|
9ae3a8 |
--- a/hw/i386/pc_piix.c
|
|
|
9ae3a8 |
+++ b/hw/i386/pc_piix.c
|
|
|
9ae3a8 |
@@ -60,6 +60,7 @@ static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static bool smbios_type1_defaults = true;
|
|
|
9ae3a8 |
static bool has_pci_info = true;
|
|
|
9ae3a8 |
+static bool has_acpi_build = true;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* PC hardware initialisation */
|
|
|
9ae3a8 |
static void pc_init1(QEMUMachineInitArgs *args,
|
|
|
9ae3a8 |
@@ -123,6 +124,9 @@ static void pc_init1(QEMUMachineInitArgs *args,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ guest_info->has_acpi_build = has_acpi_build;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
guest_info->has_pci_info = has_pci_info;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* allocate ram and load rom/bios */
|
|
|
9ae3a8 |
@@ -899,6 +903,7 @@ static void pc_init_rhel650(QEMUMachineInitArgs *args)
|
|
|
9ae3a8 |
0, CPUID_EXT2_RDTSCP);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
rom_file_in_ram = false;
|
|
|
9ae3a8 |
+ has_acpi_build = false;
|
|
|
9ae3a8 |
pc_init_rhel700(args);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
|
|
|
9ae3a8 |
index 7a58b61..824295d 100644
|
|
|
9ae3a8 |
--- a/hw/i386/pc_q35.c
|
|
|
9ae3a8 |
+++ b/hw/i386/pc_q35.c
|
|
|
9ae3a8 |
@@ -50,6 +50,7 @@
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static bool smbios_type1_defaults = true;
|
|
|
9ae3a8 |
static bool has_pci_info = true;
|
|
|
9ae3a8 |
+static bool has_acpi_build = true;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* PC hardware initialisation */
|
|
|
9ae3a8 |
static void pc_q35_init(QEMUMachineInitArgs *args)
|
|
|
9ae3a8 |
@@ -110,6 +111,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
|
|
|
9ae3a8 |
guest_info->has_pci_info = has_pci_info;
|
|
|
9ae3a8 |
+ guest_info->has_acpi_build = has_acpi_build;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* allocate ram and load rom/bios */
|
|
|
9ae3a8 |
if (!xen_enabled()) {
|
|
|
9ae3a8 |
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
|
|
|
9ae3a8 |
index 8793715..5c69abe 100644
|
|
|
9ae3a8 |
--- a/include/hw/i386/pc.h
|
|
|
9ae3a8 |
+++ b/include/hw/i386/pc.h
|
|
|
9ae3a8 |
@@ -41,6 +41,7 @@ struct PcGuestInfo {
|
|
|
9ae3a8 |
uint64_t *node_mem;
|
|
|
9ae3a8 |
uint64_t *node_cpu;
|
|
|
9ae3a8 |
FWCfgState *fw_cfg;
|
|
|
9ae3a8 |
+ bool has_acpi_build;
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* parallel.c */
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.11.7
|
|
|
9ae3a8 |
|