From patchwork Wed Feb 8 15:27:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 140169 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 01420B71B2 for ; Thu, 9 Feb 2012 02:29:54 +1100 (EST) Received: from localhost ([::1]:40758 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rv9Sn-0004un-I5 for incoming@patchwork.ozlabs.org; Wed, 08 Feb 2012 10:29:41 -0500 Received: from eggs.gnu.org ([140.186.70.92]:50043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rv9Re-00013p-N5 for qemu-devel@nongnu.org; Wed, 08 Feb 2012 10:28:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rv9RT-00005z-2j for qemu-devel@nongnu.org; Wed, 08 Feb 2012 10:28:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:29051) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rv9RS-00005h-R2 for qemu-devel@nongnu.org; Wed, 08 Feb 2012 10:28:19 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q18FSI7V019719 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 8 Feb 2012 10:28:18 -0500 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q18FSHFm025145 for ; Wed, 8 Feb 2012 10:28:17 -0500 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id C01DC250BAA; Wed, 8 Feb 2012 17:28:10 +0200 (IST) From: Avi Kivity To: qemu-devel@nongnu.org Date: Wed, 8 Feb 2012 17:27:50 +0200 Message-Id: <1328714879-18906-2-git-send-email-avi@redhat.com> In-Reply-To: <1328714879-18906-1-git-send-email-avi@redhat.com> References: <1328714879-18906-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 01/10] ioport: change portio_list not to use memory_region_set_offset() 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 memory_region_set_offset() will be going away soon, so don't use it. Use an alias instead. Signed-off-by: Avi Kivity --- ioport.c | 25 +++++++++++++++++++------ ioport.h | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ioport.c b/ioport.c index 36fa3a4..505b252 100644 --- a/ioport.c +++ b/ioport.c @@ -328,6 +328,7 @@ void portio_list_init(PortioList *piolist, piolist->ports = callbacks; piolist->nr = 0; piolist->regions = g_new0(MemoryRegion *, n); + piolist->aliases = g_new0(MemoryRegion *, n); piolist->address_space = NULL; piolist->opaque = opaque; piolist->name = name; @@ -336,6 +337,7 @@ void portio_list_init(PortioList *piolist, void portio_list_destroy(PortioList *piolist) { g_free(piolist->regions); + g_free(piolist->aliases); } static void portio_list_add_1(PortioList *piolist, @@ -345,7 +347,7 @@ static void portio_list_add_1(PortioList *piolist, { MemoryRegionPortio *pio; MemoryRegionOps *ops; - MemoryRegion *region; + MemoryRegion *region, *alias; unsigned i; /* Copy the sub-list and null-terminate it. */ @@ -362,12 +364,19 @@ static void portio_list_add_1(PortioList *piolist, ops->old_portio = pio; region = g_new(MemoryRegion, 1); + alias = g_new(MemoryRegion, 1); + /* + * Use an alias so that the callback is called with an absolute address, + * rather than an offset relative to to start + off_low. + */ memory_region_init_io(region, ops, piolist->opaque, piolist->name, - off_high - off_low); - memory_region_set_offset(region, start + off_low); + UINT64_MAX); + memory_region_init_alias(alias, piolist->name, + region, start + off_low, off_high - off_low); memory_region_add_subregion(piolist->address_space, - start + off_low, region); + start + off_low, alias); piolist->regions[piolist->nr++] = region; + piolist->aliases[piolist->nr++] = alias; } void portio_list_add(PortioList *piolist, @@ -409,15 +418,19 @@ void portio_list_add(PortioList *piolist, void portio_list_del(PortioList *piolist) { - MemoryRegion *mr; + MemoryRegion *mr, *alias; unsigned i; for (i = 0; i < piolist->nr; ++i) { mr = piolist->regions[i]; - memory_region_del_subregion(piolist->address_space, mr); + alias = piolist->aliases[i]; + memory_region_del_subregion(piolist->address_space, alias); + memory_region_destroy(alias); memory_region_destroy(mr); g_free((MemoryRegionOps *)mr->ops); g_free(mr); + g_free(alias); piolist->regions[i] = NULL; + piolist->aliases[i] = NULL; } } diff --git a/ioport.h b/ioport.h index ae3e9da..ab29c89 100644 --- a/ioport.h +++ b/ioport.h @@ -60,6 +60,7 @@ typedef struct PortioList { struct MemoryRegion *address_space; unsigned nr; struct MemoryRegion **regions; + struct MemoryRegion **aliases; void *opaque; const char *name; } PortioList;