diff options
author | Avi Kivity <avi@redhat.com> | 2011-11-10 11:24:24 +0200 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-11-24 18:31:59 +0200 |
commit | 871321acb35d671afc3eb36c2d88519c2c03d017 (patch) | |
tree | 020ae730913b4790a1a24b23e93d7c93bfd2045d /hw/ds1225y.c | |
parent | 024e5bb664bda54b393e405f425f10fa9d3fbd1a (diff) | |
download | qemu-871321acb35d671afc3eb36c2d88519c2c03d017.zip qemu-871321acb35d671afc3eb36c2d88519c2c03d017.tar.gz qemu-871321acb35d671afc3eb36c2d88519c2c03d017.tar.bz2 |
ds1225y: convert to memory API
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'hw/ds1225y.c')
-rw-r--r-- | hw/ds1225y.c | 62 |
1 files changed, 14 insertions, 48 deletions
diff --git a/hw/ds1225y.c b/hw/ds1225y.c index 6852a61..a93fbe6 100644 --- a/hw/ds1225y.c +++ b/hw/ds1225y.c @@ -27,13 +27,14 @@ typedef struct { DeviceState qdev; + MemoryRegion iomem; uint32_t chip_size; char *filename; FILE *file; uint8_t *contents; } NvRamState; -static uint32_t nvram_readb (void *opaque, target_phys_addr_t addr) +static uint64_t nvram_read(void *opaque, target_phys_addr_t addr, unsigned size) { NvRamState *s = opaque; uint32_t val; @@ -43,25 +44,8 @@ static uint32_t nvram_readb (void *opaque, target_phys_addr_t addr) return val; } -static uint32_t nvram_readw (void *opaque, target_phys_addr_t addr) -{ - uint32_t v; - v = nvram_readb(opaque, addr); - v |= nvram_readb(opaque, addr + 1) << 8; - return v; -} - -static uint32_t nvram_readl (void *opaque, target_phys_addr_t addr) -{ - uint32_t v; - v = nvram_readb(opaque, addr); - v |= nvram_readb(opaque, addr + 1) << 8; - v |= nvram_readb(opaque, addr + 2) << 16; - v |= nvram_readb(opaque, addr + 3) << 24; - return v; -} - -static void nvram_writeb (void *opaque, target_phys_addr_t addr, uint32_t val) +static void nvram_write(void *opaque, target_phys_addr_t addr, uint64_t val, + unsigned size) { NvRamState *s = opaque; @@ -76,30 +60,14 @@ static void nvram_writeb (void *opaque, target_phys_addr_t addr, uint32_t val) } } -static void nvram_writew (void *opaque, target_phys_addr_t addr, uint32_t val) -{ - nvram_writeb(opaque, addr, val & 0xff); - nvram_writeb(opaque, addr + 1, (val >> 8) & 0xff); -} - -static void nvram_writel (void *opaque, target_phys_addr_t addr, uint32_t val) -{ - nvram_writeb(opaque, addr, val & 0xff); - nvram_writeb(opaque, addr + 1, (val >> 8) & 0xff); - nvram_writeb(opaque, addr + 2, (val >> 16) & 0xff); - nvram_writeb(opaque, addr + 3, (val >> 24) & 0xff); -} - -static CPUReadMemoryFunc * const nvram_read[] = { - &nvram_readb, - &nvram_readw, - &nvram_readl, -}; - -static CPUWriteMemoryFunc * const nvram_write[] = { - &nvram_writeb, - &nvram_writew, - &nvram_writel, +static const MemoryRegionOps nvram_ops = { + .read = nvram_read, + .write = nvram_write, + .impl = { + .min_access_size = 1, + .max_access_size = 1, + }, + .endianness = DEVICE_LITTLE_ENDIAN, }; static int nvram_post_load(void *opaque, int version_id) @@ -146,13 +114,11 @@ static int nvram_sysbus_initfn(SysBusDevice *dev) { NvRamState *s = &FROM_SYSBUS(SysBusNvRamState, dev)->nvram; FILE *file; - int s_io; s->contents = g_malloc0(s->chip_size); - s_io = cpu_register_io_memory(nvram_read, nvram_write, s, - DEVICE_NATIVE_ENDIAN); - sysbus_init_mmio(dev, s->chip_size, s_io); + memory_region_init_io(&s->iomem, &nvram_ops, s, "nvram", s->chip_size); + sysbus_init_mmio_region(dev, &s->iomem); /* Read current file */ file = fopen(s->filename, "rb"); |