ia64/xen-unstable

changeset 18027:d5efa03793a2

ioemu: create a rom-protect platform flag.

Signed-off-by: Trolle Selander <trolle.selander@eu.citrix.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jul 10 16:15:37 2008 +0100 (2008-07-10)
parents f454f2cac170
children 07c7aef164cf
files tools/ioemu/hw/xen_platform.c
line diff
     1.1 --- a/tools/ioemu/hw/xen_platform.c	Thu Jul 10 15:45:18 2008 +0100
     1.2 +++ b/tools/ioemu/hw/xen_platform.c	Thu Jul 10 16:15:37 2008 +0100
     1.3 @@ -28,10 +28,52 @@
     1.4  
     1.5  extern FILE *logfile;
     1.6  
     1.7 -static void platform_ioport_map(PCIDevice *pci_dev, int region_num,
     1.8 -                                uint32_t addr, uint32_t size, int type)
     1.9 +#define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */
    1.10 +
    1.11 +typedef struct PCIXenPlatformState
    1.12  {
    1.13 -    /* nothing yet */
    1.14 +  PCIDevice  pci_dev;
    1.15 +  uint8_t    platform_flags;
    1.16 +} PCIXenPlatformState;
    1.17 +
    1.18 +static uint32_t xen_platform_ioport_readb(void *opaque, uint32_t addr)
    1.19 +{
    1.20 +    PCIXenPlatformState *s = opaque;
    1.21 +
    1.22 +    addr &= 0xff;
    1.23 +
    1.24 +    return (addr == 0) ? s->platform_flags : ~0u;
    1.25 +}
    1.26 +                              
    1.27 +static void xen_platform_ioport_writeb(void *opaque, uint32_t addr, uint32_t val)
    1.28 +{
    1.29 +    PCIXenPlatformState *d = opaque;
    1.30 +
    1.31 +    addr &= 0xff;
    1.32 +    val  &= 0xff;
    1.33 +
    1.34 +    switch (addr) {
    1.35 +    case 0: /* Platform flags */ {
    1.36 +        hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ?
    1.37 +            HVMMEM_ram_ro : HVMMEM_ram_rw;
    1.38 +        if (xc_hvm_set_mem_type(xc_handle, domid, mem_type, 0xc0, 0x40))
    1.39 +            fprintf(logfile,"xen_platform: unable to change ro/rw "
    1.40 +                    "state of ROM memory area!\n");
    1.41 +        else
    1.42 +            d->platform_flags = val & PFFLAG_ROM_LOCK;
    1.43 +        break;
    1.44 +    }
    1.45 +    default:
    1.46 +        break;
    1.47 +    }
    1.48 +}
    1.49 +
    1.50 +
    1.51 +static void platform_ioport_map(PCIDevice *pci_dev, int region_num, uint32_t addr, uint32_t size, int type)
    1.52 +{
    1.53 +    PCIXenPlatformState *d = (PCIXenPlatformState *)pci_dev;
    1.54 +    register_ioport_write(addr, size, 1, xen_platform_ioport_writeb, d);
    1.55 +    register_ioport_read(addr, size, 1, xen_platform_ioport_readb, d);
    1.56  }
    1.57  
    1.58  static uint32_t platform_mmio_read(void *opaque, target_phys_addr_t addr)
    1.59 @@ -109,30 +151,42 @@ struct pci_config_header {
    1.60  
    1.61  void xen_pci_save(QEMUFile *f, void *opaque)
    1.62  {
    1.63 -    PCIDevice *d = opaque;
    1.64 +    PCIXenPlatformState *d = opaque;
    1.65  
    1.66 -    pci_device_save(d, f);
    1.67 +    pci_device_save(&d->pci_dev, f);
    1.68 +    qemu_put_8s(f, &d->platform_flags);
    1.69  }
    1.70  
    1.71  int xen_pci_load(QEMUFile *f, void *opaque, int version_id)
    1.72  {
    1.73 -    PCIDevice *d = opaque;
    1.74 +    PCIXenPlatformState *d = opaque;
    1.75 +    int ret;
    1.76  
    1.77 -    if (version_id != 1)
    1.78 +    if (version_id > 2)
    1.79          return -EINVAL;
    1.80  
    1.81 -    return pci_device_load(d, f);
    1.82 +    ret = pci_device_load(&d->pci_dev, f);
    1.83 +    if (ret < 0)
    1.84 +        return ret;
    1.85 +
    1.86 +    if (version_id >= 2) {
    1.87 +        uint8_t flags;
    1.88 +        qemu_get_8s(f, &flags);
    1.89 +        xen_platform_ioport_writeb(d, 0, flags);
    1.90 +    }
    1.91 +
    1.92 +    return 0;
    1.93  }
    1.94  
    1.95  void pci_xen_platform_init(PCIBus *bus)
    1.96  {
    1.97 -    PCIDevice *d;
    1.98 +    PCIXenPlatformState *d;
    1.99      struct pci_config_header *pch;
   1.100  
   1.101      printf("Register xen platform.\n");
   1.102 -    d = pci_register_device(bus, "xen-platform", sizeof(PCIDevice), -1, NULL,
   1.103 -			    NULL);
   1.104 -    pch = (struct pci_config_header *)d->config;
   1.105 +    d = (PCIXenPlatformState *)pci_register_device(
   1.106 +        bus, "xen-platform", sizeof(PCIXenPlatformState), -1, NULL, NULL);
   1.107 +    pch = (struct pci_config_header *)d->pci_dev.config;
   1.108      pch->vendor_id = 0x5853;
   1.109      pch->device_id = 0x0001;
   1.110      pch->command = 3; /* IO and memory access */
   1.111 @@ -148,13 +202,15 @@ void pci_xen_platform_init(PCIBus *bus)
   1.112      pch->subsystem_vendor_id = pch->vendor_id; /* Duplicate vendor id.  */
   1.113      pch->subsystem_id        = 0x0001;         /* Hardcode sub-id as 1. */
   1.114  
   1.115 -    pci_register_io_region(d, 0, 0x100, PCI_ADDRESS_SPACE_IO,
   1.116 -                           platform_ioport_map);
   1.117 +    pci_register_io_region(&d->pci_dev, 0, 0x100,
   1.118 +                           PCI_ADDRESS_SPACE_IO, platform_ioport_map);
   1.119  
   1.120      /* reserve 16MB mmio address for share memory*/
   1.121 -    pci_register_io_region(d, 1, 0x1000000, PCI_ADDRESS_SPACE_MEM_PREFETCH,
   1.122 -			   platform_mmio_map);
   1.123 +    pci_register_io_region(&d->pci_dev, 1, 0x1000000,
   1.124 +                           PCI_ADDRESS_SPACE_MEM_PREFETCH, platform_mmio_map);
   1.125  
   1.126 -    register_savevm("platform", 0, 1, xen_pci_save, xen_pci_load, d);
   1.127 +    xen_platform_ioport_writeb(d, 0, 0);
   1.128 +
   1.129 +    register_savevm("platform", 0, 2, xen_pci_save, xen_pci_load, d);
   1.130      printf("Done register platform.\n");
   1.131  }