[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 31/35] pc: ACPI BIOS: implement memory hotplug inter
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH 31/35] pc: ACPI BIOS: implement memory hotplug interface |
Date: |
Fri, 4 Apr 2014 15:36:56 +0200 |
- provides static SSDT object for memory hotplug
- SSDT template for memory devices and runtime generator
of them in SSDT table.
Signed-off-by: Vasilis Liaskovitis <address@hidden>
Signed-off-by: Igor Mammedov <address@hidden>
---
hw/i386/Makefile.objs | 3 +-
hw/i386/acpi-build.c | 37 ++++++++++++
hw/i386/ssdt-mem.dsl | 75 +++++++++++++++++++++++
hw/i386/ssdt-misc.dsl | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 277 insertions(+), 1 deletion(-)
create mode 100644 hw/i386/ssdt-mem.dsl
diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 3df1612..fd04fc2 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -9,7 +9,8 @@ obj-y += acpi-build.o
obj-y += bios-linker-loader.o
hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \
- hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex
+ hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
+ hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex
iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
; then echo "$(2)"; else echo "$(3)"; fi ;)
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index a5d3fbf..6649480 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -37,6 +37,7 @@
#include "bios-linker-loader.h"
#include "hw/loader.h"
#include "hw/isa/isa.h"
+#include "hw/acpi/memory_hotplug.h"
/* Supported chipsets: */
#include "hw/acpi/piix4.h"
@@ -664,6 +665,14 @@ static inline char acpi_get_hex(uint32_t val)
#define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start)
#define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start)
+#include "hw/i386/ssdt-mem.hex"
+
+/* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
+#define ACPI_MEM_OFFSET_HEX (*ssdt_mem_name - *ssdt_mem_start + 2)
+#define ACPI_MEM_OFFSET_ID (*ssdt_mem_id - *ssdt_mem_start + 7)
+#define ACPI_MEM_SIZEOF (*ssdt_mem_end - *ssdt_mem_start)
+#define ACPI_MEM_AML (ssdm_mem_aml + *ssdt_mem_start)
+
#define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
#define ACPI_SSDT_HEADER_LENGTH 36
@@ -999,6 +1008,8 @@ build_ssdt(GArray *table_data, GArray *linker,
AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
PcPciInfo *pci, PcGuestInfo *guest_info)
{
+ MachineState *machine = MACHINE(qdev_get_machine());
+ uint32_t nr_mem = machine->init_args.ram_slots;
unsigned acpi_cpus = guest_info->apic_id_limit;
int ssdt_start = table_data->len;
uint8_t *ssdt_ptr;
@@ -1027,6 +1038,9 @@ build_ssdt(GArray *table_data, GArray *linker,
ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
ssdt_isa_pest[0], 16, misc->pvpanic_port);
+ ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
+ ssdt_mctrl_nr_slots[0], 32, nr_mem);
+
{
GArray *sb_scope = build_alloc_array();
uint8_t op = 0x10; /* ScopeOp */
@@ -1080,6 +1094,29 @@ build_ssdt(GArray *table_data, GArray *linker,
build_free_array(package);
}
+ if (nr_mem) {
+ /*
+ * current device naming scheme dosen't support
+ * more that 256 memory devices
+ */
+ assert(nr_mem <= 256);
+ /* build memory devices */
+ for (i = 0; i < nr_mem; i++) {
+ char id[3];
+ uint8_t *mem = acpi_data_push(sb_scope, ACPI_MEM_SIZEOF);
+
+ snprintf(id, sizeof(id), "%02X", i);
+ memcpy(mem, ACPI_MEM_AML, ACPI_MEM_SIZEOF);
+ memcpy(mem + ACPI_MEM_OFFSET_HEX, id, 2);
+ memcpy(mem + ACPI_MEM_OFFSET_ID, id, 2);
+ }
+
+ /* build Method(MTFY, 2) {
+ * If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ...
+ */
+ build_append_notify_method(sb_scope, "MTFY", "MP%0.02X", nr_mem);
+ }
+
{
AcpiBuildPciBusHotplugState hotplug_state;
Object *pci_host;
diff --git a/hw/i386/ssdt-mem.dsl b/hw/i386/ssdt-mem.dsl
new file mode 100644
index 0000000..7f68750
--- /dev/null
+++ b/hw/i386/ssdt-mem.dsl
@@ -0,0 +1,75 @@
+/*
+ * Memory hotplug ACPI DSDT static objects definitions
+ *
+ * Copyright ProfitBricks GmbH 2012
+ * Copyright (C) 2013 Red Hat Inc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>
+ */
+
+/* This file is the basis for the ssdt_mem[] variable in src/acpi.c.
+ * It defines the contents of the memory device object. At
+ * runtime, a dynamically generated SSDT will contain one copy of this
+ * AML snippet for every possible memory device in the system. The
+ * objects will be placed in the \_SB_ namespace.
+ *
+ * In addition to the aml code generated from this file, the
+ * src/acpi.c file creates a MTFY method with an entry for each memdevice:
+ * Method(MTFY, 2) {
+ * If (LEqual(Arg0, 0x00)) { Notify(MP00, Arg1) }
+ * If (LEqual(Arg0, 0x01)) { Notify(MP01, Arg1) }
+ * ...
+ * }
+ */
+ACPI_EXTRACT_ALL_CODE ssdm_mem_aml
+
+DefinitionBlock ("ssdt-mem.aml", "SSDT", 0x02, "BXPC", "CSSDT", 0x1)
+{
+
+ External(\_SB.MHPD.MCRS, MethodObj)
+ External(\_SB.MHPD.MRST, MethodObj)
+ External(\_SB.MHPD.MOST, MethodObj)
+ External(\_SB.MHPD.MPXM, MethodObj)
+
+ Scope(\_SB) {
+/* v------------------ DO NOT EDIT ------------------v */
+ ACPI_EXTRACT_DEVICE_START ssdt_mem_start
+ ACPI_EXTRACT_DEVICE_END ssdt_mem_end
+ ACPI_EXTRACT_DEVICE_STRING ssdt_mem_name
+ Device(MPAA) {
+ ACPI_EXTRACT_NAME_STRING ssdt_mem_id
+ Name(_UID, "0xAA")
+/* ^------------------ DO NOT EDIT ------------------^
+ * Don't change the above without also updating the C code.
+ */
+ Name(_HID, EISAID("PNP0C80"))
+
+ Method(_CRS, 0) {
+ Return(\_SB.MHPD.MCRS(_UID))
+ }
+
+ Method(_STA, 0) {
+ Return(\_SB.MHPD.MRST(_UID))
+ }
+
+ Method(_PXM, 0) {
+ Return(\_SB.MHPD.MPXM(_UID))
+ }
+
+ Method(_OST, 3) {
+ \_SB.MHPD.MOST(_UID, Arg0, Arg1, Arg2)
+ }
+ }
+ }
+}
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index a4484b8..d1caaed 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -12,6 +12,7 @@
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#include "hw/acpi/acpi_defs.h"
ACPI_EXTRACT_ALL_CODE ssdp_misc_aml
@@ -116,4 +117,166 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC",
"BXSSDTSUSP", 0x1)
}
}
}
+
+ External(MTFY, MethodObj)
+ Scope(\_SB) {
+ Device(MHPD) {
+ Name(_HID, "ACPI0004")
+ Name(_UID, "Memory hotplug resources")
+
+ ACPI_EXTRACT_NAME_DWORD_CONST ssdt_mctrl_nr_slots
+ Name(MDNR, 0x12345678)
+
+ /* Memory hotplug IO registers */
+ OperationRegion(HPMR, SystemIO, ACPI_MEMORY_HOTPLUG_BASE,
+ ACPI_MEMORY_HOTPLUG_IO_LEN)
+
+ Name(_CRS, ResourceTemplate() {
+ IO(Decode16, ACPI_MEMORY_HOTPLUG_BASE,
ACPI_MEMORY_HOTPLUG_BASE,
+ 0, ACPI_MEMORY_HOTPLUG_IO_LEN, IO)
+ })
+
+ Method(_STA, 0) {
+ If (LEqual(MDNR, Zero)) {
+ Return(0x0)
+ }
+ /* present, functioning, decoding, not shown in UI */
+ Return(0xB)
+ }
+
+ Field(HPMR, DWordAcc, NoLock, Preserve) {
+ MRBL, 32, // DIMM start addr Low word, read only
+ MRBH, 32, // DIMM start addr Hi word, read only
+ MRLL, 32, // DIMM size Low word, read only
+ MRLH, 32, // DIMM size Hi word, read only
+ MPX, 32, // DIMM node proximity, read only
+ }
+ Field(HPMR, ByteAcc, NoLock, Preserve) {
+ Offset(20),
+ MES, 1, // 1 if DIMM enabled used by _STA, read only
+ MINS, 1, // (read) 1 if DIMM has a insert event. (write) 1
after MTFY() to clear event
+ }
+
+ Mutex (MLCK, 0)
+ Field (HPMR, DWordAcc, NoLock, Preserve) {
+ MSEL, 32, // DIMM selector, write only
+ MOEV, 32, // _OST event code, write only
+ MOSC, 32, // _OST status code, write only
+ }
+
+ Method(MESC, 0, Serialized) {
+ If (LEqual(MDNR, Zero)) {
+ Return(Zero)
+ }
+
+ Store(Zero, Local0) // Mem devs iterrator
+ Acquire(MLCK, 0xFFFF)
+ while (LLess(Local0, MDNR)) {
+ Store(Local0, MSEL) // select Local0 DIMM
+ If (LEqual(MINS, One)) { // Memory device needs check
+ MTFY(Local0, 1)
+ Store(1, MINS)
+ }
+ // TODO: handle memory eject request
+ Add(Local0, One, Local0) // goto next DIMM
+ }
+ Release(MLCK)
+ Return(One)
+ }
+
+ Method(MRST, 1) {
+ Store(Zero, Local0)
+
+ Acquire(MLCK, 0xFFFF)
+ Store(ToInteger(Arg0), MSEL) // select DIMM
+
+ If (LEqual(MES, One)) {
+ Store(0xF, Local0)
+ }
+
+ Release(MLCK)
+ Return(Local0)
+ }
+
+ Method(MCRS, 1, Serialized) {
+ Acquire(MLCK, 0xFFFF)
+ Store(ToInteger(Arg0), MSEL) // select DIMM
+
+ Name(MR64, ResourceTemplate() {
+ QWordMemory(ResourceProducer, PosDecode, MinFixed,
MaxFixed,
+ Cacheable, ReadWrite,
+ 0x0000000000000000, // Address Space Granularity
+ 0x0000000000000000, // Address Range Minimum
+ 0xFFFFFFFFFFFFFFFE, // Address Range Maximum
+ 0x0000000000000000, // Address Translation Offset
+ 0xFFFFFFFFFFFFFFFF, // Address Length
+ ,, MW64, AddressRangeMemory, TypeStatic)
+ })
+
+ CreateDWordField(MR64, 14, MINL)
+ CreateDWordField(MR64, 18, MINH)
+ CreateDWordField(MR64, 38, LENL)
+ CreateDWordField(MR64, 42, LENH)
+ CreateDWordField(MR64, 22, MAXL)
+ CreateDWordField(MR64, 26, MAXH)
+
+ Store(MRBH, MINH)
+ Store(MRBL, MINL)
+ Store(MRLH, LENH)
+ Store(MRLL, LENL)
+
+ // 64-bit math: MAX = MIN + LEN - 1
+ Add(MINL, LENL, MAXL)
+ Add(MINH, LENH, MAXH)
+ If (LLess(MAXL, MINL)) {
+ Add(MAXH, One, MAXH)
+ }
+ If (LLess(MAXL, One)) {
+ Subtract(MAXH, One, MAXH)
+ }
+ Subtract(MAXL, One, MAXL)
+
+ If (LEqual(MAXH, Zero)){
+ Name(MR32, ResourceTemplate() {
+ DWordMemory(ResourceProducer, PosDecode, MinFixed,
MaxFixed,
+ Cacheable, ReadWrite,
+ 0x00000000, // Address Space Granularity
+ 0x00000000, // Address Range Minimum
+ 0xFFFFFFFE, // Address Range Maximum
+ 0x00000000, // Address Translation Offset
+ 0xFFFFFFFF, // Address Length
+ ,, MW32, AddressRangeMemory, TypeStatic)
+ })
+ CreateDWordField(MR32, MW32._MIN, MIN)
+ CreateDWordField(MR32, MW32._MAX, MAX)
+ CreateDWordField(MR32, MW32._LEN, LEN)
+ Store(MINL, MIN)
+ Store(MAXL, MAX)
+ Store(LENL, LEN)
+
+ Release(MLCK)
+ Return(MR32)
+ }
+
+ Release(MLCK)
+ Return(MR64)
+ }
+
+ Method(MPXM, 1) {
+ Acquire(MLCK, 0xFFFF)
+ Store(ToInteger(Arg0), MSEL) // select DIMM
+ Store(MPX, Local0)
+ Release(MLCK)
+ Return(Local0)
+ }
+
+ Method(MOST, 4) {
+ Acquire(MLCK, 0xFFFF)
+ Store(ToInteger(Arg0), MSEL) // select DIMM
+ Store(Arg1, MOEV)
+ Store(Arg2, MOSC)
+ Release(MLCK)
+ }
+ } // Device()
+ } // Scope()
}
--
1.9.0
- [Qemu-devel] [PATCH 25/35] pc: ich9 lpc: make it work with global/compat properties, (continued)
- [Qemu-devel] [PATCH 25/35] pc: ich9 lpc: make it work with global/compat properties, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 16/35] pc: add memory hotplug handler to PC_MACHINE, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 27/35] pc: migrate piix4 & ich9 MemHotplugState, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 26/35] acpi:ich9: add memory hotplug handling, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 32/35] pc: ACPI BIOS: use enum for defining memory affinity flags, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 29/35] pc: ACPI BIOS: punch holes in PCI0._CRS for memory hotplug IO region, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 33/35] pc: ACPI BIOS: reserve SRAT entry for hotplug mem hole, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 34/35] pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35 machines, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 31/35] pc: ACPI BIOS: implement memory hotplug interface,
Igor Mammedov <=
- Message not available
- [Qemu-devel] [PATCH 30/35] pc: ACPI BIOS: name CPU hotplug ACPI0004 device, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 28/35] pc: propagate memory hotplug event to ACPI device, Igor Mammedov, 2014/04/04