diff mbox

[12/27] dimm: add hotplug callback to DimmBus

Message ID 1385001528-12003-13-git-send-email-imammedo@redhat.com
State New
Headers show

Commit Message

Igor Mammedov Nov. 21, 2013, 2:38 a.m. UTC
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/pc.c          |   11 +++++++++++
 hw/mem/dimm.c         |    4 ++++
 include/hw/i386/pc.h  |    6 ++++++
 include/hw/mem/dimm.h |    4 ++++
 4 files changed, 25 insertions(+), 0 deletions(-)

Comments

Paolo Bonzini Nov. 25, 2013, 1:01 p.m. UTC | #1
Il 21/11/2013 03:38, Igor Mammedov ha scritto:
> diff --git a/include/hw/mem/dimm.h b/include/hw/mem/dimm.h
> index abedae2..b655006 100644
> --- a/include/hw/mem/dimm.h
> +++ b/include/hw/mem/dimm.h
> @@ -65,11 +65,15 @@ typedef struct DimmDeviceClass {
>   * @parent_obj: opaque parent object container
>   * @base: address from which to start mapping @DimmDevice
>   * @as: hot-plugabble memory area where @DimmDevice-s are attached
> + * @hotplug_dev: device that hotplugs realized DimmDevice
> + * @hotplug: hotplug callback set by the board
>   */
>  typedef struct DimmBus {
>      BusState parent_obj;
>      hwaddr base;
>      MemoryRegion as;
> +    DeviceState *hotplug_dev;
> +    hotplug_fn hotplug;
>  } DimmBus;
>  
>  /**
> 

So the alternatives here would be:

(1) have DimmDevice call hotplug/hot_unplug in DimmBus; add a
ACPIHotplugDimmBus subclass that connects to ACPI.

(2) have DeviceState call hotplug/hot_unplug in BusState; DimmBus does
nothing with it, and a ACPIHotplugDimmBus subclass implements it.

Paolo
Igor Mammedov Nov. 25, 2013, 2:40 p.m. UTC | #2
On Mon, 25 Nov 2013 14:01:51 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Il 21/11/2013 03:38, Igor Mammedov ha scritto:
> > diff --git a/include/hw/mem/dimm.h b/include/hw/mem/dimm.h
> > index abedae2..b655006 100644
> > --- a/include/hw/mem/dimm.h
> > +++ b/include/hw/mem/dimm.h
> > @@ -65,11 +65,15 @@ typedef struct DimmDeviceClass {
> >   * @parent_obj: opaque parent object container
> >   * @base: address from which to start mapping @DimmDevice
> >   * @as: hot-plugabble memory area where @DimmDevice-s are attached
> > + * @hotplug_dev: device that hotplugs realized DimmDevice
> > + * @hotplug: hotplug callback set by the board
> >   */
> >  typedef struct DimmBus {
> >      BusState parent_obj;
> >      hwaddr base;
> >      MemoryRegion as;
> > +    DeviceState *hotplug_dev;
> > +    hotplug_fn hotplug;
> >  } DimmBus;
> >  
> >  /**
> > 
> 
> So the alternatives here would be:
> 
> (1) have DimmDevice call hotplug/hot_unplug in DimmBus; add a
> ACPIHotplugDimmBus subclass that connects to ACPI.
> 
> (2) have DeviceState call hotplug/hot_unplug in BusState; DimmBus does
> nothing with it, and a ACPIHotplugDimmBus subclass implements it.

Thanks,
I'll try to implement it this way.

> Paolo
diff mbox

Patch

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index ba82c67..85d0862 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1225,6 +1225,17 @@  FWCfgState *pc_memory_init(MemoryRegion *system_memory,
     return fw_cfg;
 }
 
+void pc_acpi_dev_memory_hotplug_init(DimmBus *hotplug_mem_bus,
+                                     hotplug_fn hotplug,
+                                     Object *acpi_dev)
+{
+    g_assert(acpi_dev);
+    if (memory_region_size(&hotplug_mem_bus->as)) {
+        hotplug_mem_bus->hotplug_dev = DEVICE(acpi_dev);
+        hotplug_mem_bus->hotplug = hotplug;
+    }
+}
+
 qemu_irq *pc_allocate_cpu_irq(void)
 {
     return qemu_allocate_irqs(pic_irq_request, NULL, 1);
diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c
index b3c27cc..7029675 100644
--- a/hw/mem/dimm.c
+++ b/hw/mem/dimm.c
@@ -278,6 +278,10 @@  static void dimm_realize(DeviceState *dev, Error **errp)
 
     g_assert(dbc->register_memory);
     dbc->register_memory(bus, dimm, errp);
+
+    if (bus->hotplug) {
+        bus->hotplug(bus->hotplug_dev, dev, HOTPLUG_ENABLED);
+    }
 }
 
 static void dimm_finalize(Object *obj)
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index c4e8048..0c86ee5 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -12,6 +12,7 @@ 
 #include "qemu/bitmap.h"
 #include "sysemu/sysemu.h"
 #include "hw/pci/pci.h"
+#include "hw/mem/dimm.h"
 
 /* PC-style peripherals (also used by other machines).  */
 
@@ -148,6 +149,11 @@  FWCfgState *pc_memory_init(MemoryRegion *system_memory,
                            MemoryRegion *rom_memory,
                            MemoryRegion **ram_memory,
                            PcGuestInfo *guest_info);
+
+void pc_acpi_dev_memory_hotplug_init(DimmBus *hotplug_mem_bus,
+                                     hotplug_fn hotplug,
+                                     Object *acpi_dev);
+
 qemu_irq *pc_allocate_cpu_irq(void);
 DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus);
 void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
diff --git a/include/hw/mem/dimm.h b/include/hw/mem/dimm.h
index abedae2..b655006 100644
--- a/include/hw/mem/dimm.h
+++ b/include/hw/mem/dimm.h
@@ -65,11 +65,15 @@  typedef struct DimmDeviceClass {
  * @parent_obj: opaque parent object container
  * @base: address from which to start mapping @DimmDevice
  * @as: hot-plugabble memory area where @DimmDevice-s are attached
+ * @hotplug_dev: device that hotplugs realized DimmDevice
+ * @hotplug: hotplug callback set by the board
  */
 typedef struct DimmBus {
     BusState parent_obj;
     hwaddr base;
     MemoryRegion as;
+    DeviceState *hotplug_dev;
+    hotplug_fn hotplug;
 } DimmBus;
 
 /**