Patchwork [0.14?,v2,3/4] ioapic: Prepare for base address relocation

login
register
mail settings
Submitter Jan Kiszka
Date Feb. 3, 2011, 6:25 p.m.
Message ID <31ea67667019d29d5ef051a5b0b8a287e1278e35.1296757518.git.jan.kiszka@siemens.com>
Download mbox | patch
Permalink /patch/81698/
State New
Headers show

Comments

Jan Kiszka - Feb. 3, 2011, 6:25 p.m.
The registers of real IOAPICs can be relocated during runtime (via
chipset registers). We don't support this yet, but qemu-kvm carries the
current base address in its version 2 vmstate.

To align both implementations for migratability, add the proper
infrastructure to accept initial as well as updated base addresses and
include the current address in the vmstate. This is done in a way that
will also allow multiple IOAPICs in the future.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 hw/ioapic.c  |   19 +++++++++++++++++++
 hw/ioapic.h  |    4 ++++
 hw/pc_piix.c |    4 +---
 3 files changed, 24 insertions(+), 3 deletions(-)

Patch

diff --git a/hw/ioapic.c b/hw/ioapic.c
index edf99cc..705803c 100644
--- a/hw/ioapic.c
+++ b/hw/ioapic.c
@@ -63,6 +63,8 @@  struct IOAPICState {
 
     uint32_t irr;
     uint64_t ioredtbl[IOAPIC_NUM_PINS];
+    uint64_t default_base_address;
+    uint64_t current_base_address;
 };
 
 static IOAPICState *ioapics[MAX_IOAPICS];
@@ -238,7 +240,9 @@  static int ioapic_post_load(void *opaque, int version_id)
     if (version_id == 1) {
         /* set sane values */
         s->irr = 0;
+        s->current_base_address = s->default_base_address;
     }
+    sysbus_mmio_map(&s->busdev, 0, s->current_base_address);
     return 0;
 }
 
@@ -251,17 +255,27 @@  static const VMStateDescription vmstate_ioapic = {
     .fields      = (VMStateField []) {
         VMSTATE_UINT8(id, IOAPICState),
         VMSTATE_UINT8(ioregsel, IOAPICState),
+        VMSTATE_UINT64_V(current_base_address, IOAPICState, 2),
         VMSTATE_UINT32_V(irr, IOAPICState, 2),
         VMSTATE_UINT64_ARRAY(ioredtbl, IOAPICState, IOAPIC_NUM_PINS),
         VMSTATE_END_OF_LIST()
     }
 };
 
+void ioapic_set_base_address(DeviceState *d, target_phys_addr_t addr)
+{
+    IOAPICState *s = DO_UPCAST(IOAPICState, busdev.qdev, d);
+
+    s->current_base_address = addr;
+    sysbus_mmio_map(&s->busdev, 0, addr);
+}
+
 static void ioapic_reset(DeviceState *d)
 {
     IOAPICState *s = DO_UPCAST(IOAPICState, busdev.qdev, d);
     int i;
 
+    ioapic_set_base_address(d, s->default_base_address);
     s->id = 0;
     s->ioregsel = 0;
     s->irr = 0;
@@ -310,6 +324,11 @@  static SysBusDeviceInfo ioapic_info = {
     .qdev.vmsd = &vmstate_ioapic,
     .qdev.reset = ioapic_reset,
     .qdev.no_user = 1,
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_UINT64("default_base_address", IOAPICState,
+                           default_base_address, IOAPIC_DEFAULT_BASE_ADDRESS),
+        DEFINE_PROP_END_OF_LIST()
+    }
 };
 
 static void ioapic_register_devices(void)
diff --git a/hw/ioapic.h b/hw/ioapic.h
index c441567..1130d60 100644
--- a/hw/ioapic.h
+++ b/hw/ioapic.h
@@ -17,4 +17,8 @@ 
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#define IOAPIC_DEFAULT_BASE_ADDRESS    0xfec00000
+
 void ioapic_eio_broadcast(int vector);
+
+void ioapic_set_base_address(DeviceState *d, target_phys_addr_t addr);
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 7b74473..82dce4c 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -25,6 +25,7 @@ 
 #include "hw.h"
 #include "pc.h"
 #include "apic.h"
+#include "ioapic.h"
 #include "pci.h"
 #include "usb-uhci.h"
 #include "usb-ohci.h"
@@ -46,13 +47,10 @@  static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 static void ioapic_init(IsaIrqState *isa_irq_state)
 {
     DeviceState *dev;
-    SysBusDevice *d;
     unsigned int i;
 
     dev = qdev_create(NULL, "ioapic");
     qdev_init_nofail(dev);
-    d = sysbus_from_qdev(dev);
-    sysbus_mmio_map(d, 0, 0xfec00000);
 
     for (i = 0; i < IOAPIC_NUM_PINS; i++) {
         isa_irq_state->ioapic[i] = qdev_get_gpio_in(dev, i);