diff -BbuNr ioemu-remote-orig/hw/xen_platform.c ioemu-dir/hw/xen_platform.c --- ioemu-remote-orig/hw/xen_platform.c 2008-07-10 11:55:14.803079583 +0100 +++ ioemu-dir/hw/xen_platform.c 2008-07-10 13:16:09.574483833 +0100 @@ -31,10 +30,64 @@ extern FILE *logfile; -static void platform_ioport_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) +#define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */ + +typedef struct PCIXenPlatformState { - /* nothing yet */ + PCIDevice pci_dev; + uint8_t platform_flags; +} PCIXenPlatformState; + +static uint32_t xen_platform_ioport_readb(void *opaque, uint32_t addr) +{ + PCIXenPlatformState *s = opaque; + int ret; + + addr &= 0xff; + + switch (addr) + { + case 0: + ret = s->platform_flags; + break; + default: + fprintf(logfile,"xen_platform: not implemented read(b) addr=0x%x\n", addr); + ret = 0; + break; + } + return ret; +} + +static void xen_platform_ioport_writeb(void *opaque, uint32_t addr, uint32_t val) +{ + PCIXenPlatformState *d = opaque; + + addr &= 0xff; + val &= 0xff; + + switch (addr) + { + case 0: /* Platform flags */ + { + hvmmem_type_t mem_type = ( val & PFFLAG_ROM_LOCK ) ? HVMMEM_ram_ro : HVMMEM_ram_rw; + if ( xc_hvm_set_mem_type( xc_handle, domid, mem_type, 0xc0, 0x40) ) + fprintf(logfile,"xen_platform: unable to change ro/rw state of ROM memory area! \n"); + else + d->platform_flags = val & PFFLAG_ROM_LOCK; + break; + } + default: + fprintf(logfile,"xen_platform: not implemented write(b) addr=0x%x\n", addr); + break; + } +} + + +static void platform_ioport_map(PCIDevice *pci_dev, int region_num, uint32_t addr, uint32_t size, int type) +{ + PCIXenPlatformState *d = (PCIXenPlatformState *)pci_dev; + register_ioport_write(addr, size, 1, xen_platform_ioport_writeb, d); + register_ioport_read(addr, size, 1, xen_platform_ioport_readb, d); } static uint32_t platform_mmio_read(void *opaque, target_phys_addr_t addr) @@ -112,30 +165,37 @@ void xen_pci_save(QEMUFile *f, void *opaque) { - PCIDevice *d = opaque; + PCIXenPlatformState *d = opaque; - pci_device_save(d, f); + pci_device_save(&d->pci_dev, f); + qemu_put_8s(f, &d->platform_flags); } int xen_pci_load(QEMUFile *f, void *opaque, int version_id) { - PCIDevice *d = opaque; + PCIXenPlatformState *d = opaque; if (version_id != 1) return -EINVAL; - return pci_device_load(d, f); + pci_device_load(&d->pci_dev, f); + qemu_get_8s(f, &d->platform_flags); + /* Need to ensure the ROM r/w calls get made according to saved flag state. */ + xen_platform_ioport_writeb(d,0,d->platform_flags); + return 0; } void pci_xen_platform_init(PCIBus *bus) { - PCIDevice *d; + PCIXenPlatformState *d; struct pci_config_header *pch; + d = qemu_mallocz(sizeof(PCIXenPlatformState)); + printf("Register xen platform.\n"); - d = pci_register_device(bus, "xen-platform", sizeof(PCIDevice), -1, NULL, - NULL); - pch = (struct pci_config_header *)d->config; + d = (PCIXenPlatformState *) pci_register_device(bus, "xen-platform", + sizeof(PCIXenPlatformState), -1, NULL, NULL); + pch = (struct pci_config_header *)d->pci_dev.config; pch->vendor_id = 0x5853; pch->device_id = 0x0001; pch->command = 3; /* IO and memory access */ @@ -151,13 +211,16 @@ pch->subsystem_vendor_id = pch->vendor_id; /* Duplicate vendor id. */ pch->subsystem_id = 0x0001; /* Hardcode sub-id as 1. */ - pci_register_io_region(d, 0, 0x100, PCI_ADDRESS_SPACE_IO, + pci_register_io_region((PCIDevice *)d, 0, 0x100, PCI_ADDRESS_SPACE_IO, platform_ioport_map); /* reserve 16MB mmio address for share memory*/ - pci_register_io_region(d, 1, 0x1000000, PCI_ADDRESS_SPACE_MEM_PREFETCH, + pci_register_io_region((PCIDevice *)d, 1, 0x1000000, PCI_ADDRESS_SPACE_MEM_PREFETCH, platform_mmio_map); + /* Make ROM areas read-write until set RO by guest or restore */ + xen_platform_ioport_writeb(d,0,0); + register_savevm("platform", 0, 1, xen_pci_save, xen_pci_load, d); printf("Done register platform.\n"); }