From patchwork Sun Jul 17 11:13:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 105048 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 85CB1B6F7F for ; Sun, 17 Jul 2011 23:41:48 +1000 (EST) Received: from localhost ([::1]:55964 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QiRbN-0004vM-44 for incoming@patchwork.ozlabs.org; Sun, 17 Jul 2011 09:41:45 -0400 Received: from eggs.gnu.org ([140.186.70.92]:42794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QiPIz-0005YT-Jj for qemu-devel@nongnu.org; Sun, 17 Jul 2011 07:15:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QiPIt-0007ek-6T for qemu-devel@nongnu.org; Sun, 17 Jul 2011 07:14:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61330) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QiPIs-0007db-Mm for qemu-devel@nongnu.org; Sun, 17 Jul 2011 07:14:31 -0400 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 p6HBETZ6002270 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 17 Jul 2011 07:14:30 -0400 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 p6HBESPf006943; Sun, 17 Jul 2011 07:14:29 -0400 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 0AC2B250B39; Sun, 17 Jul 2011 14:14:27 +0300 (IDT) From: Avi Kivity To: qemu-devel@nongnu.org Date: Sun, 17 Jul 2011 14:13:36 +0300 Message-Id: <1310901265-32051-10-git-send-email-avi@redhat.com> In-Reply-To: <1310901265-32051-1-git-send-email-avi@redhat.com> References: <1310901265-32051-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 Cc: kvm@vger.kernel.org Subject: [Qemu-devel] [RFC v4 09/58] memory: add backward compatibility for old portio registration 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 Signed-off-by: Avi Kivity --- memory.c | 32 ++++++++++++++++++++++++++++++++ memory.h | 17 +++++++++++++++++ 2 files changed, 49 insertions(+), 0 deletions(-) diff --git a/memory.c b/memory.c index 62bd60b..bb04952 100644 --- a/memory.c +++ b/memory.c @@ -211,6 +211,21 @@ static AddressSpace address_space_memory = { .ops = &address_space_ops_memory, }; +static const MemoryRegionPortio *find_portio(MemoryRegion *mr, uint64_t offset, + unsigned width, bool write) +{ + const MemoryRegionPortio *mrp; + + for (mrp = mr->ops->old_portio; mrp->size; ++mrp) { + if (offset >= mrp->offset && offset < mrp->offset + mrp->len + && width == mrp->size + && (write ? (bool)mrp->write : (bool)mrp->read)) { + return mrp; + } + } + return NULL; +} + static void memory_region_iorange_read(IORange *iorange, uint64_t offset, unsigned width, @@ -218,6 +233,15 @@ static void memory_region_iorange_read(IORange *iorange, { MemoryRegion *mr = container_of(iorange, MemoryRegion, iorange); + if (mr->ops->old_portio) { + const MemoryRegionPortio *mrp = find_portio(mr, offset, width, false); + + *data = ((uint64_t)1 << (width * 8)) - 1; + if (mrp) { + *data = mrp->read(mr->opaque, offset - mrp->offset); + } + return; + } *data = mr->ops->read(mr->opaque, offset, width); } @@ -228,6 +252,14 @@ static void memory_region_iorange_write(IORange *iorange, { MemoryRegion *mr = container_of(iorange, MemoryRegion, iorange); + if (mr->ops->old_portio) { + const MemoryRegionPortio *mrp = find_portio(mr, offset, width, true); + + if (mrp) { + mrp->write(mr->opaque, offset - mrp->offset, data); + } + return; + } mr->ops->write(mr->opaque, offset, data, width); } diff --git a/memory.h b/memory.h index 2afbf13..f026eae 100644 --- a/memory.h +++ b/memory.h @@ -10,9 +10,11 @@ #include "targphys.h" #include "qemu-queue.h" #include "iorange.h" +#include "ioport.h" typedef struct MemoryRegionOps MemoryRegionOps; typedef struct MemoryRegion MemoryRegion; +typedef struct MemoryRegionPortio MemoryRegionPortio; /* Must match *_DIRTY_FLAGS in cpu-all.h. To be replaced with dynamic * registration. @@ -65,6 +67,11 @@ struct MemoryRegionOps { */ bool unaligned; } impl; + + /* If .read and .write are not present, old_portio may be used for + * backwards compatibility with old portio registration + */ + const MemoryRegionPortio *old_portio; }; typedef struct CoalescedMemoryRange CoalescedMemoryRange; @@ -92,6 +99,16 @@ struct MemoryRegion { uint8_t dirty_log_mask; }; +struct MemoryRegionPortio { + uint32_t offset; + uint32_t len; + unsigned size; + IOPortReadFunc *read; + IOPortWriteFunc *write; +}; + +#define PORTIO_END { } + /* Initialize a memory region * * The region typically acts as a container for other memory regions.