diff options
-rw-r--r-- | hw/milkymist-uart.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/hw/milkymist-uart.c b/hw/milkymist-uart.c index e8e309de7c..128cd8cc38 100644 --- a/hw/milkymist-uart.c +++ b/hw/milkymist-uart.c @@ -35,7 +35,9 @@ enum { struct MilkymistUartState { SysBusDevice busdev; + MemoryRegion regs_region; CharDriverState *chr; + qemu_irq rx_irq; qemu_irq tx_irq; @@ -43,7 +45,8 @@ struct MilkymistUartState { }; typedef struct MilkymistUartState MilkymistUartState; -static uint32_t uart_read(void *opaque, target_phys_addr_t addr) +static uint64_t uart_read(void *opaque, target_phys_addr_t addr, + unsigned size) { MilkymistUartState *s = opaque; uint32_t r = 0; @@ -66,7 +69,8 @@ static uint32_t uart_read(void *opaque, target_phys_addr_t addr) return r; } -static void uart_write(void *opaque, target_phys_addr_t addr, uint32_t value) +static void uart_write(void *opaque, target_phys_addr_t addr, uint64_t value, + unsigned size) { MilkymistUartState *s = opaque; unsigned char ch = value; @@ -93,16 +97,14 @@ static void uart_write(void *opaque, target_phys_addr_t addr, uint32_t value) } } -static CPUReadMemoryFunc * const uart_read_fn[] = { - NULL, - NULL, - &uart_read, -}; - -static CPUWriteMemoryFunc * const uart_write_fn[] = { - NULL, - NULL, - &uart_write, +static const MemoryRegionOps uart_mmio_ops = { + .read = uart_read, + .write = uart_write, + .valid = { + .min_access_size = 4, + .max_access_size = 4, + }, + .endianness = DEVICE_NATIVE_ENDIAN, }; static void uart_rx(void *opaque, const uint8_t *buf, int size) @@ -136,14 +138,13 @@ static void milkymist_uart_reset(DeviceState *d) static int milkymist_uart_init(SysBusDevice *dev) { MilkymistUartState *s = FROM_SYSBUS(typeof(*s), dev); - int uart_regs; sysbus_init_irq(dev, &s->rx_irq); sysbus_init_irq(dev, &s->tx_irq); - uart_regs = cpu_register_io_memory(uart_read_fn, uart_write_fn, s, - DEVICE_NATIVE_ENDIAN); - sysbus_init_mmio(dev, R_MAX * 4, uart_regs); + memory_region_init_io(&s->regs_region, &uart_mmio_ops, s, + "milkymist-uart", R_MAX * 4); + sysbus_init_mmio_region(dev, &s->regs_region); s->chr = qdev_init_chardev(&dev->qdev); if (s->chr) { |