@@ -42,6 +42,24 @@ int cpu_register_io_memory(CPUReadMemoryFunc * const *mem_read,
void *opaque);
void cpu_unregister_io_memory(int table_address);
+typedef struct CpuIoMemoryHandler CpuIoMemoryHandler;
+/* len is guaranteed to be one of 1, 2 or 4 and does not need
+ * to be range checked. */
+typedef void CpuWriteMemorySimple(CpuIoMemoryHandler *,
+ target_phys_addr_t addr,
+ uint32_t value, int len);
+typedef uint32_t CpuReadMemorySimple(CpuIoMemoryHandler *,
+ target_phys_addr_t addr, int len);
+
+struct CpuIoMemoryHandler {
+ CpuWriteMemorySimple *write;
+ CpuReadMemorySimple *read;
+};
+
+/* Helper routine for when we want to use a single routine with
+ * length instead. */
+int cpu_register_io_memory_simple(struct CpuIoMemoryHandler *);
+
void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
int len, int is_write);
static inline void cpu_physical_memory_read(target_phys_addr_t addr,
@@ -3065,6 +3065,67 @@ void cpu_unregister_io_memory(int io_table_address)
io_mem_used[io_index] = 0;
}
+static void cpu_io_memory_simple_writeb(void *opaque, target_phys_addr_t addr,
+ uint32_t value)
+{
+ struct CpuIoMemoryHandler *handler = opaque;
+ handler->write(handler, addr, value, 1);
+}
+
+static uint32_t cpu_io_memory_simple_readb(void *opaque,
+ target_phys_addr_t addr)
+{
+ struct CpuIoMemoryHandler *handler = opaque;
+ return handler->read(handler, addr, 1);
+}
+
+static void cpu_io_memory_simple_writew(void *opaque, target_phys_addr_t addr,
+ uint32_t value)
+{
+ struct CpuIoMemoryHandler *handler = opaque;
+ handler->write(handler, addr, value, 2);
+}
+
+static uint32_t cpu_io_memory_simple_readw(void *opaque,
+ target_phys_addr_t addr)
+{
+ struct CpuIoMemoryHandler *handler = opaque;
+ return handler->read(handler, addr, 2);
+}
+
+static void cpu_io_memory_simple_writel(void *opaque, target_phys_addr_t addr,
+ uint32_t value)
+{
+ struct CpuIoMemoryHandler *handler = opaque;
+ handler->write(handler, addr, value, 4);
+}
+
+static uint32_t cpu_io_memory_simple_readl(void *opaque,
+ target_phys_addr_t addr)
+{
+ struct CpuIoMemoryHandler *handler = opaque;
+ return handler->read(handler, addr, 4);
+}
+
+static CPUWriteMemoryFunc * const cpu_io_memory_simple_write[] = {
+ &cpu_io_memory_simple_writeb,
+ &cpu_io_memory_simple_writew,
+ &cpu_io_memory_simple_writel,
+};
+
+static CPUReadMemoryFunc * const cpu_io_memory_simple_read[] = {
+ &cpu_io_memory_simple_readb,
+ &cpu_io_memory_simple_readw,
+ &cpu_io_memory_simple_readl,
+};
+
+int cpu_register_io_memory_simple(struct CPUIoMemoryHandler *handler)
+{
+ return cpu_register_io_memory(cpu_io_memory_simple_read,
+ cpu_io_memory_simple_write,
+ handler);
+}
+
static void io_mem_init(void)
{
int i;