From patchwork Thu Feb 14 12:45:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 220435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9122A2C0094 for ; Thu, 14 Feb 2013 23:46:29 +1100 (EST) Received: from localhost ([::1]:39687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5yCp-0005gu-RN for incoming@patchwork.ozlabs.org; Thu, 14 Feb 2013 07:46:27 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5yCT-0004x1-Es for qemu-devel@nongnu.org; Thu, 14 Feb 2013 07:46:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U5yCP-0005HC-N5 for qemu-devel@nongnu.org; Thu, 14 Feb 2013 07:46:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:17452) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5yCP-0005Gr-Fy for qemu-devel@nongnu.org; Thu, 14 Feb 2013 07:46:01 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1ECjxVU006174 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 14 Feb 2013 07:45:59 -0500 Received: from redhat.com (vpn-200-169.tlv.redhat.com [10.35.200.169]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id r1ECjuvW025455; Thu, 14 Feb 2013 07:45:57 -0500 Date: Thu, 14 Feb 2013 14:45:56 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20130214124555.GA13861@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: avi.kivity@gmail.com, gleb@redhat.com Subject: [Qemu-devel] [PATCH RFC] memory: drop _overlap variant X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org overlap flag in the region is currently unused, most devices have no idea whether their region overlaps with anything, so drop it, assume that all regions can overlap and always require priority. It's also not clear how should devices allocate priorities. As a first step, define a set of symbolic priority names so it's easier to grep for. The result of this patch is that it's easy to see who uses a given priority. To avoid breaking build, this patch should be combined with a patch updating all devices. I have it working but am not sending this yet to avoid unnecessary load on list, so this patch shoul dnot be applied as is. Will send the full version if people don't object to this one. Signed-off-by: Michael S. Tsirkin Cc: avi.kivity@gmail.com diff --git a/hw/sysbus.c b/hw/sysbus.c index 6d9d1df..f039cb8 100644 --- a/hw/sysbus.c +++ b/hw/sysbus.c @@ -61,9 +61,8 @@ void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr) memory_region_del_subregion(get_system_memory(), dev->mmio[n].memory); } dev->mmio[n].addr = addr; - memory_region_add_subregion(get_system_memory(), - addr, - dev->mmio[n].memory); + memory_region_add_subregion(get_system_memory(), addr, + dev->mmio[n].memory, MEMORY_PRIO_LOWEST); } @@ -215,16 +214,10 @@ static char *sysbus_get_fw_dev_path(DeviceState *dev) } void sysbus_add_memory(SysBusDevice *dev, hwaddr addr, - MemoryRegion *mem) -{ - memory_region_add_subregion(get_system_memory(), addr, mem); -} - -void sysbus_add_memory_overlap(SysBusDevice *dev, hwaddr addr, - MemoryRegion *mem, unsigned priority) + MemoryRegion *mem, MemoryRegionPriority priority) { - memory_region_add_subregion_overlap(get_system_memory(), addr, mem, - priority); + memory_region_add_subregion(get_system_memory(), addr, mem, + priority); } void sysbus_del_memory(SysBusDevice *dev, MemoryRegion *mem) @@ -235,7 +228,8 @@ void sysbus_del_memory(SysBusDevice *dev, MemoryRegion *mem) void sysbus_add_io(SysBusDevice *dev, hwaddr addr, MemoryRegion *mem) { - memory_region_add_subregion(get_system_io(), addr, mem); + memory_region_add_subregion(get_system_io(), addr, mem, + MEMORY_PRIO_LOWEST); } void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem) diff --git a/hw/sysbus.h b/hw/sysbus.h index a7fcded..4059c03 100644 --- a/hw/sysbus.h +++ b/hw/sysbus.h @@ -57,9 +57,7 @@ void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size); void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq); void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr); void sysbus_add_memory(SysBusDevice *dev, hwaddr addr, - MemoryRegion *mem); -void sysbus_add_memory_overlap(SysBusDevice *dev, hwaddr addr, - MemoryRegion *mem, unsigned priority); + MemoryRegion *mem, MemoryRegionPriority priority); void sysbus_del_memory(SysBusDevice *dev, MemoryRegion *mem); void sysbus_add_io(SysBusDevice *dev, hwaddr addr, MemoryRegion *mem); diff --git a/include/exec/memory.h b/include/exec/memory.h index 2322732..af1e0fa 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -147,6 +147,14 @@ struct MemoryRegion { MemoryRegionIoeventfd *ioeventfds; }; +typedef enum MemoryRegionPriority { + MEMORY_PRIO_LOWEST = 0x0, + MEMORY_PRIO_LOW = 0x1, + MEMORY_PRIO_MEDIUM = 0x2, + MEMORY_PRIO_HIGH = 1000, + MEMORY_PRIO_HIGHEST = UINT_MAX, +} MemoryRegionPriority; + struct MemoryRegionPortio { uint32_t offset; uint32_t len; @@ -628,27 +636,9 @@ void memory_region_del_eventfd(MemoryRegion *mr, /** * memory_region_add_subregion: Add a subregion to a container. * - * Adds a subregion at @offset. The subregion may not overlap with other - * subregions (except for those explicitly marked as overlapping). A region - * may only be added once as a subregion (unless removed with - * memory_region_del_subregion()); use memory_region_init_alias() if you - * want a region to be a subregion in multiple locations. - * - * @mr: the region to contain the new subregion; must be a container - * initialized with memory_region_init(). - * @offset: the offset relative to @mr where @subregion is added. - * @subregion: the subregion to be added. - */ -void memory_region_add_subregion(MemoryRegion *mr, - hwaddr offset, - MemoryRegion *subregion); -/** - * memory_region_add_subregion_overlap: Add a subregion to a container - * with overlap. - * * Adds a subregion at @offset. The subregion may overlap with other * subregions. Conflicts are resolved by having a higher @priority hide a - * lower @priority. Subregions without priority are taken as @priority 0. + * lower @priority. * A region may only be added once as a subregion (unless removed with * memory_region_del_subregion()); use memory_region_init_alias() if you * want a region to be a subregion in multiple locations. @@ -659,10 +649,10 @@ void memory_region_add_subregion(MemoryRegion *mr, * @subregion: the subregion to be added. * @priority: used for resolving overlaps; highest priority wins. */ -void memory_region_add_subregion_overlap(MemoryRegion *mr, - hwaddr offset, - MemoryRegion *subregion, - unsigned priority); +void memory_region_add_subregion(MemoryRegion *mr, + hwaddr offset, + MemoryRegion *subregion, + MemoryRegionPriority priority); /** * memory_region_get_ram_addr: Get the ram address associated with a memory diff --git a/memory.c b/memory.c index cd7d5e0..4a2c5cd 100644 --- a/memory.c +++ b/memory.c @@ -806,7 +806,6 @@ void memory_region_init(MemoryRegion *mr, mr->rom_device = false; mr->destructor = memory_region_destructor_none; mr->priority = 0; - mr->may_overlap = false; mr->alias = NULL; QTAILQ_INIT(&mr->subregions); memset(&mr->subregions_link, 0, sizeof mr->subregions_link); @@ -1318,9 +1317,6 @@ static void memory_region_add_subregion_common(MemoryRegion *mr, subregion->parent = mr; subregion->addr = offset; QTAILQ_FOREACH(other, &mr->subregions, subregions_link) { - if (subregion->may_overlap || other->may_overlap) { - continue; - } if (int128_gt(int128_make64(offset), int128_add(int128_make64(other->addr), other->size)) || int128_le(int128_add(int128_make64(offset), subregion->size), @@ -1353,19 +1349,9 @@ done: void memory_region_add_subregion(MemoryRegion *mr, hwaddr offset, - MemoryRegion *subregion) + MemoryRegion *subregion, + MemoryRegionPriority priority) { - subregion->may_overlap = false; - subregion->priority = 0; - memory_region_add_subregion_common(mr, offset, subregion); -} - -void memory_region_add_subregion_overlap(MemoryRegion *mr, - hwaddr offset, - MemoryRegion *subregion, - unsigned priority) -{ - subregion->may_overlap = true; subregion->priority = priority; memory_region_add_subregion_common(mr, offset, subregion); } @@ -1396,7 +1382,6 @@ void memory_region_set_address(MemoryRegion *mr, hwaddr addr) { MemoryRegion *parent = mr->parent; unsigned priority = mr->priority; - bool may_overlap = mr->may_overlap; if (addr == mr->addr || !parent) { mr->addr = addr; @@ -1405,11 +1390,7 @@ void memory_region_set_address(MemoryRegion *mr, hwaddr addr) memory_region_transaction_begin(); memory_region_del_subregion(parent, mr); - if (may_overlap) { - memory_region_add_subregion_overlap(parent, addr, mr, priority); - } else { - memory_region_add_subregion(parent, addr, mr); - } + memory_region_add_subregion(parent, addr, mr, priority); memory_region_transaction_commit(); }