[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 16/35] pc: add memory hotplug handler to PC_MACHINE
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH 16/35] pc: add memory hotplug handler to PC_MACHINE |
Date: |
Fri, 4 Apr 2014 15:36:41 +0200 |
that will perform mapping of DIMM device into guest's RAM address space
Signed-off-by: Igor Mammedov <address@hidden>
---
hw/i386/pc.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
include/hw/i386/pc.h | 8 ++++++++
2 files changed, 60 insertions(+)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index b164e37..4038e2c 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -58,6 +58,7 @@
#include "hw/boards.h"
#include "hw/pci/pci_host.h"
#include "acpi-build.h"
+#include "hw/mem/dimm.h"
/* debug PC/ISA interrupts */
//#define DEBUG_IRQ
@@ -1479,12 +1480,63 @@ void qemu_register_pc_machine(QEMUMachine *m)
g_free(name);
}
+static void pc_dimm_plug(HotplugHandler *hotplug_dev,
+ DeviceState *dev, Error **errp)
+{
+ PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+ DimmDevice *dimm = DIMM(dev);
+ DimmDeviceClass *ddc = DIMM_GET_CLASS(dimm);
+ MemoryRegion *mr = ddc->get_memory_region(dimm);
+
+ memory_region_add_subregion(&pcms->hotplug_memory,
+ dimm->start - pcms->hotplug_memory_base,
+ mr);
+ vmstate_register_ram(mr, dev);
+}
+
+static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
+ DeviceState *dev, Error **errp)
+{
+ if (object_dynamic_cast(OBJECT(dev), TYPE_DIMM)) {
+ pc_dimm_plug(hotplug_dev, dev, errp);
+ }
+}
+
+static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
+ DeviceState *dev)
+{
+ PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(machine);
+
+ if (object_dynamic_cast(OBJECT(dev), TYPE_DIMM)) {
+ return HOTPLUG_HANDLER(machine);
+ }
+
+ return pcmc->get_hotplug_handler ?
+ pcmc->get_hotplug_handler(machine, dev) : NULL;
+}
+
+static void pc_machine_class_init(ObjectClass *oc, void *data)
+{
+ MachineClass *mc = MACHINE_CLASS(oc);
+ PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
+ HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
+
+ pcmc->get_hotplug_handler = mc->get_hotplug_handler;
+ mc->get_hotplug_handler = pc_get_hotpug_handler;
+ hc->plug = pc_machine_device_plug_cb;
+}
+
static const TypeInfo pc_machine_info = {
.name = TYPE_PC_MACHINE,
.parent = TYPE_MACHINE,
.abstract = true,
.instance_size = sizeof(PCMachineState),
.class_size = sizeof(PCMachineClass),
+ .class_init = pc_machine_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_HOTPLUG_HANDLER },
+ { }
+ },
};
static void pc_machine_register_types(void)
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 36f2f52..059e137 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -31,9 +31,17 @@ struct PCMachineState {
MemoryRegion hotplug_memory;
};
+/**
+ * PCMachineClass:
+ * @get_hotplug_handler: pointer to parent class callback @get_hotplug_handler
+ */
struct PCMachineClass {
/*< private >*/
MachineClass parent_class;
+
+ /*< public >*/
+ HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
+ DeviceState *dev);
};
typedef struct PCMachineState PCMachineState;
--
1.9.0
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, (continued)
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Michael S. Tsirkin, 2014/04/07
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Igor Mammedov, 2014/04/07
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Michael S. Tsirkin, 2014/04/07
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Igor Mammedov, 2014/04/07
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Michael S. Tsirkin, 2014/04/07
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Igor Mammedov, 2014/04/11
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Michael S. Tsirkin, 2014/04/07
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Paolo Bonzini, 2014/04/11
[Qemu-devel] [PATCH 22/35] trace: add DIMM slot & address allocation for target-i386, Igor Mammedov, 2014/04/04
[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 <=
[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