sysbus: add MemoryRegion based memory management API
Allow registering sysbus device memory using a MemoryRegion. Once all users are converted, sysbus_init_mmio() and sysbus_init_mmio_cb() will be removed. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
79ff8cb0df
commit
ec3bb837a2
23
hw/sysbus.c
23
hw/sysbus.c
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "sysbus.h"
|
||||
#include "monitor.h"
|
||||
#include "exec-memory.h"
|
||||
|
||||
static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
|
||||
static char *sysbus_get_fw_dev_path(DeviceState *dev);
|
||||
|
@ -49,11 +50,20 @@ void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr)
|
|||
}
|
||||
if (dev->mmio[n].addr != (target_phys_addr_t)-1) {
|
||||
/* Unregister previous mapping. */
|
||||
if (dev->mmio[n].memory) {
|
||||
memory_region_del_subregion(get_system_memory(),
|
||||
dev->mmio[n].memory);
|
||||
} else {
|
||||
cpu_register_physical_memory(dev->mmio[n].addr, dev->mmio[n].size,
|
||||
IO_MEM_UNASSIGNED);
|
||||
}
|
||||
}
|
||||
dev->mmio[n].addr = addr;
|
||||
if (dev->mmio[n].cb) {
|
||||
if (dev->mmio[n].memory) {
|
||||
memory_region_add_subregion(get_system_memory(),
|
||||
addr,
|
||||
dev->mmio[n].memory);
|
||||
} else if (dev->mmio[n].cb) {
|
||||
dev->mmio[n].cb(dev, addr);
|
||||
} else {
|
||||
cpu_register_physical_memory(addr, dev->mmio[n].size,
|
||||
|
@ -107,6 +117,17 @@ void sysbus_init_mmio_cb(SysBusDevice *dev, target_phys_addr_t size,
|
|||
dev->mmio[n].cb = cb;
|
||||
}
|
||||
|
||||
void sysbus_init_mmio_region(SysBusDevice *dev, MemoryRegion *memory)
|
||||
{
|
||||
int n;
|
||||
|
||||
assert(dev->num_mmio < QDEV_MAX_MMIO);
|
||||
n = dev->num_mmio++;
|
||||
dev->mmio[n].addr = -1;
|
||||
dev->mmio[n].size = memory_region_size(memory);
|
||||
dev->mmio[n].memory = memory;
|
||||
}
|
||||
|
||||
void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size)
|
||||
{
|
||||
pio_addr_t i;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
/* Devices attached directly to the main system bus. */
|
||||
|
||||
#include "qdev.h"
|
||||
#include "memory.h"
|
||||
|
||||
#define QDEV_MAX_MMIO 32
|
||||
#define QDEV_MAX_PIO 32
|
||||
|
@ -23,6 +24,7 @@ struct SysBusDevice {
|
|||
target_phys_addr_t size;
|
||||
mmio_mapfunc cb;
|
||||
ram_addr_t iofunc;
|
||||
MemoryRegion *memory;
|
||||
} mmio[QDEV_MAX_MMIO];
|
||||
int num_pio;
|
||||
pio_addr_t pio[QDEV_MAX_PIO];
|
||||
|
@ -46,6 +48,7 @@ void sysbus_init_mmio(SysBusDevice *dev, target_phys_addr_t size,
|
|||
ram_addr_t iofunc);
|
||||
void sysbus_init_mmio_cb(SysBusDevice *dev, target_phys_addr_t size,
|
||||
mmio_mapfunc cb);
|
||||
void sysbus_init_mmio_region(SysBusDevice *dev, MemoryRegion *memory);
|
||||
void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
|
||||
void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
|
||||
void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
|
||||
|
|
Loading…
Reference in a new issue