From patchwork Mon Jul 25 14:02:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 106705 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 C086EB6F8A for ; Tue, 26 Jul 2011 01:27:39 +1000 (EST) Received: from localhost ([::1]:53991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlLm0-0007LM-Bn for incoming@patchwork.ozlabs.org; Mon, 25 Jul 2011 10:04:44 -0400 Received: from eggs.gnu.org ([140.186.70.92]:47351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlLki-0003xq-Mm for qemu-devel@nongnu.org; Mon, 25 Jul 2011 10:03:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QlLkU-00053E-Bu for qemu-devel@nongnu.org; Mon, 25 Jul 2011 10:03:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4264) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlLkU-00051y-3g for qemu-devel@nongnu.org; Mon, 25 Jul 2011 10:03:10 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6PE39Uj013252 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 25 Jul 2011 10:03:09 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p6PE38N0019011; Mon, 25 Jul 2011 10:03:08 -0400 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id DB2B1250B3E; Mon, 25 Jul 2011 17:03:06 +0300 (IDT) From: Avi Kivity To: qemu-devel@nongnu.org Date: Mon, 25 Jul 2011 17:02:49 +0300 Message-Id: <1311602584-23409-9-git-send-email-avi@redhat.com> In-Reply-To: <1311602584-23409-1-git-send-email-avi@redhat.com> References: <1311602584-23409-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 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] [PATCH 08/23] memory: I/O address space support 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 Allow registering I/O ports via the same mechanism as mmio ranges. Signed-off-by: Avi Kivity Reviewed-by: Anthony Liguori --- exec-memory.h | 3 ++ memory.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- memory.h | 2 + 3 files changed, 64 insertions(+), 1 deletions(-) diff --git a/exec-memory.h b/exec-memory.h index 7eb9085..aad21b5 100644 --- a/exec-memory.h +++ b/exec-memory.h @@ -18,6 +18,9 @@ MemoryRegion *get_system_memory(void); /* Set the root memory region. This region is the system memory map. */ void set_system_memory_map(MemoryRegion *mr); +/* Set the I/O memory region. This region is the I/O memory map. */ +void set_system_io_map(MemoryRegion *mr); + #endif #endif diff --git a/memory.c b/memory.c index bc8bfa2..62bd60b 100644 --- a/memory.c +++ b/memory.c @@ -13,6 +13,7 @@ #include "memory.h" #include "exec-memory.h" +#include "ioport.h" #include typedef struct AddrRange AddrRange; @@ -210,6 +211,52 @@ static AddressSpace address_space_memory = { .ops = &address_space_ops_memory, }; +static void memory_region_iorange_read(IORange *iorange, + uint64_t offset, + unsigned width, + uint64_t *data) +{ + MemoryRegion *mr = container_of(iorange, MemoryRegion, iorange); + + *data = mr->ops->read(mr->opaque, offset, width); +} + +static void memory_region_iorange_write(IORange *iorange, + uint64_t offset, + unsigned width, + uint64_t data) +{ + MemoryRegion *mr = container_of(iorange, MemoryRegion, iorange); + + mr->ops->write(mr->opaque, offset, data, width); +} + +static const IORangeOps memory_region_iorange_ops = { + .read = memory_region_iorange_read, + .write = memory_region_iorange_write, +}; + +static void as_io_range_add(AddressSpace *as, FlatRange *fr) +{ + iorange_init(&fr->mr->iorange, &memory_region_iorange_ops, + fr->addr.start,fr->addr.size); + ioport_register(&fr->mr->iorange); +} + +static void as_io_range_del(AddressSpace *as, FlatRange *fr) +{ + isa_unassign_ioport(fr->addr.start, fr->addr.size); +} + +static const AddressSpaceOps address_space_ops_io = { + .range_add = as_io_range_add, + .range_del = as_io_range_del, +}; + +static AddressSpace address_space_io = { + .ops = &address_space_ops_io, +}; + /* Render a memory region into the global view. Ranges in @view obscure * ranges in @mr. */ @@ -358,7 +405,12 @@ static void address_space_update_topology(AddressSpace *as) static void memory_region_update_topology(void) { - address_space_update_topology(&address_space_memory); + if (address_space_memory.root) { + address_space_update_topology(&address_space_memory); + } + if (address_space_io.root) { + address_space_update_topology(&address_space_io); + } } void memory_region_init(MemoryRegion *mr, @@ -772,3 +824,9 @@ void set_system_memory_map(MemoryRegion *mr) address_space_memory.root = mr; memory_region_update_topology(); } + +void set_system_io_map(MemoryRegion *mr) +{ + address_space_io.root = mr; + memory_region_update_topology(); +} diff --git a/memory.h b/memory.h index 0994b18..2afbf13 100644 --- a/memory.h +++ b/memory.h @@ -9,6 +9,7 @@ #include "cpu-common.h" #include "targphys.h" #include "qemu-queue.h" +#include "iorange.h" typedef struct MemoryRegionOps MemoryRegionOps; typedef struct MemoryRegion MemoryRegion; @@ -78,6 +79,7 @@ struct MemoryRegion { target_phys_addr_t offset; bool backend_registered; ram_addr_t ram_addr; + IORange iorange; bool terminates; MemoryRegion *alias; target_phys_addr_t alias_offset;