From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:48501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlReX-0001jL-30 for qemu-devel@nongnu.org; Mon, 25 Jul 2011 16:21:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QlReV-0005JP-7R for qemu-devel@nongnu.org; Mon, 25 Jul 2011 16:21:24 -0400 Received: from mail-yx0-f173.google.com ([209.85.213.173]:58791) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlReV-0005J0-4g for qemu-devel@nongnu.org; Mon, 25 Jul 2011 16:21:23 -0400 Received: by yxt3 with SMTP id 3so3016181yxt.4 for ; Mon, 25 Jul 2011 13:21:22 -0700 (PDT) Message-ID: <4E2DD03F.8040903@codemonkey.ws> Date: Mon, 25 Jul 2011 15:21:19 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1311602584-23409-1-git-send-email-avi@redhat.com> <1311602584-23409-23-git-send-email-avi@redhat.com> In-Reply-To: <1311602584-23409-23-git-send-email-avi@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 22/23] sysbus: add MemoryRegion based memory management API List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org On 07/25/2011 09:03 AM, Avi Kivity wrote: > Allow registering sysbus device memory using a MemoryRegion. Once all users > are converted, sysbus_init_mmio() and sysbus_init_mmio_cb() will be removed. > > Signed-off-by: Avi Kivity Reviewed-by: Anthony Liguori Regards, Anthony Liguori > --- > hw/sysbus.c | 27 ++++++++++++++++++++++++--- > hw/sysbus.h | 3 +++ > 2 files changed, 27 insertions(+), 3 deletions(-) > > diff --git a/hw/sysbus.c b/hw/sysbus.c > index 2e22be7..ea442ac 100644 > --- a/hw/sysbus.c > +++ b/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. */ > - cpu_register_physical_memory(dev->mmio[n].addr, dev->mmio[n].size, > - IO_MEM_UNASSIGNED); > + 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; > diff --git a/hw/sysbus.h b/hw/sysbus.h > index 4e8cb16..5f62e2d 100644 > --- a/hw/sysbus.h > +++ b/hw/sysbus.h > @@ -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);