From patchwork Sun Sep 18 12:54:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 115237 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2360DB6FA0 for ; Sun, 18 Sep 2011 22:54:54 +1000 (EST) Received: from localhost ([::1]:47638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R5GtW-0001Z3-CG for incoming@patchwork.ozlabs.org; Sun, 18 Sep 2011 08:54:50 -0400 Received: from eggs.gnu.org ([140.186.70.92]:45849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R5GtR-0001Yy-A4 for qemu-devel@nongnu.org; Sun, 18 Sep 2011 08:54:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R5GtP-00084M-UZ for qemu-devel@nongnu.org; Sun, 18 Sep 2011 08:54:45 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]:45405) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R5GtP-00084G-G7 for qemu-devel@nongnu.org; Sun, 18 Sep 2011 08:54:43 -0400 Received: from smtp02.web.de ( [172.20.0.184]) by fmmailgate02.web.de (Postfix) with ESMTP id 881551AB95654; Sun, 18 Sep 2011 14:54:32 +0200 (CEST) Received: from [88.65.36.224] (helo=mchn199C.mchp.siemens.de) by smtp02.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #2) id 1R5GtE-00024g-00; Sun, 18 Sep 2011 14:54:32 +0200 Message-ID: <4E75EA08.4090809@web.de> Date: Sun, 18 Sep 2011 14:54:32 +0200 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Avi Kivity X-Enigmail-Version: 1.3.1 X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX18zhNKahOay5i8jorXt+s6PJT8h3jn3o2k0zLR5 S5OhuCoOzoNLbEAyMrSo4JFaEIsacj28LEAS8wB16u+EUro+VB AJd3L7iI8= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 217.72.192.227 Cc: qemu-devel , Richard Henderson Subject: [Qemu-devel] [PATCH] isa: Avoid using obsolete memory_region_set_offset for old portio 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 From: Jan Kiszka We can express the offset of old portio completely via MemoryRegionPortio::offset by splitting up regions of different offsets and adjusting those offsets appropriately. Signed-off-by: Jan Kiszka --- Will write a patch to remove MemoryRegion::offset now. hw/isa-bus.c | 28 ++++++++++------------------ memory.c | 15 +++++++-------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/hw/isa-bus.c b/hw/isa-bus.c index 27c76b4..558312d 100644 --- a/hw/isa-bus.c +++ b/hw/isa-bus.c @@ -107,19 +107,14 @@ static void isa_register_portio_1(ISADevice *dev, MemoryRegion *region; unsigned i; - if (off_low == 0 && pio_init[count].size == 0) { - /* Special case simple adjustments. */ - pio = (MemoryRegionPortio *) pio_init; - } else { - /* Copy the sub-list and null-terminate it. */ - pio = g_new(MemoryRegionPortio, count + 1); - memcpy(pio, pio_init, sizeof(MemoryRegionPortio) * count); - memset(pio + count, 0, sizeof(MemoryRegionPortio)); - - /* Adjust the offsets to all be zero-based for the region. */ - for (i = 0; i < count; ++i) { - pio[i].offset -= off_low; - } + /* Copy the sub-list and null-terminate it. */ + pio = g_new(MemoryRegionPortio, count + 1); + memcpy(pio, pio_init, sizeof(MemoryRegionPortio) * count); + memset(pio + count, 0, sizeof(MemoryRegionPortio)); + + /* Adjust the offsets to be absolute. */ + for (i = 0; i < count; ++i) { + pio[i].offset += start; } ops = g_new0(MemoryRegionOps, 1); @@ -127,7 +122,6 @@ static void isa_register_portio_1(ISADevice *dev, region = g_new(MemoryRegion, 1); memory_region_init_io(region, ops, opaque, name, off_high - off_low); - memory_region_set_offset(region, start + off_low); memory_region_add_subregion(isabus->address_space_io, start + off_low, region); } @@ -154,8 +148,8 @@ void isa_register_portio_list(ISADevice *dev, uint16_t start, assert(pio->offset >= off_last); off_last = pio->offset; - /* If we see a hole, break the region. */ - if (off_last > off_high) { + /* If we see a new offset, break the region. */ + if (off_last > off_low) { isa_register_portio_1(dev, pio_start, count, start, off_low, off_high, opaque, name); /* ... and start collecting anew. */ @@ -163,8 +157,6 @@ void isa_register_portio_list(ISADevice *dev, uint16_t start, off_low = off_last; off_high = off_low + pio->len; count = 0; - } else if (off_last + pio->len > off_high) { - off_high = off_last + pio->len; } } diff --git a/memory.c b/memory.c index aef4702..51f0297 100644 --- a/memory.c +++ b/memory.c @@ -375,8 +375,7 @@ static const MemoryRegionPortio *find_portio(MemoryRegion *mr, uint64_t offset, const MemoryRegionPortio *mrp; for (mrp = mr->ops->old_portio; mrp->size; ++mrp) { - if (offset >= mrp->offset && offset < mrp->offset + mrp->len - && width == mrp->size + if (offset < mrp->len && width == mrp->size && (write ? (bool)mrp->write : (bool)mrp->read)) { return mrp; } @@ -396,12 +395,12 @@ static void memory_region_iorange_read(IORange *iorange, *data = ((uint64_t)1 << (width * 8)) - 1; if (mrp) { - *data = mrp->read(mr->opaque, offset + mr->offset); + *data = mrp->read(mr->opaque, offset + mrp->offset); } else if (width == 2) { mrp = find_portio(mr, offset, 1, false); assert(mrp); - *data = mrp->read(mr->opaque, offset + mr->offset) | - (mrp->read(mr->opaque, offset + mr->offset + 1) << 8); + *data = mrp->read(mr->opaque, offset + mrp->offset) | + (mrp->read(mr->opaque, offset + mrp->offset + 1) << 8); } return; } @@ -423,12 +422,12 @@ static void memory_region_iorange_write(IORange *iorange, const MemoryRegionPortio *mrp = find_portio(mr, offset, width, true); if (mrp) { - mrp->write(mr->opaque, offset + mr->offset, data); + mrp->write(mr->opaque, offset + mrp->offset, data); } else if (width == 2) { mrp = find_portio(mr, offset, 1, false); assert(mrp); - mrp->write(mr->opaque, offset + mr->offset, data & 0xff); - mrp->write(mr->opaque, offset + mr->offset + 1, data >> 8); + mrp->write(mr->opaque, offset + mrp->offset, data & 0xff); + mrp->write(mr->opaque, offset + mrp->offset + 1, data >> 8); } return; }