From patchwork Thu Jan 19 11:25:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 136835 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 1C41C1007D3 for ; Thu, 19 Jan 2012 23:31:48 +1100 (EST) Received: from localhost ([::1]:48159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rnq8R-0004Le-5S for incoming@patchwork.ozlabs.org; Thu, 19 Jan 2012 06:26:27 -0500 Received: from eggs.gnu.org ([140.186.70.92]:50366) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rnq7Y-0002jQ-PN for qemu-devel@nongnu.org; Thu, 19 Jan 2012 06:25:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rnq7P-0008Cg-Qn for qemu-devel@nongnu.org; Thu, 19 Jan 2012 06:25:32 -0500 Received: from thoth.sbs.de ([192.35.17.2]:28000) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rnq7P-0008B0-Fo for qemu-devel@nongnu.org; Thu, 19 Jan 2012 06:25:23 -0500 Received: from mail1.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.13.6/8.13.6) with ESMTP id q0JBPFXs020791; Thu, 19 Jan 2012 12:25:15 +0100 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id q0JBPAMR027843; Thu, 19 Jan 2012 12:25:15 +0100 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Date: Thu, 19 Jan 2012 12:25:04 +0100 Message-Id: <1660e72d4fbbd87e34eb4017d7e7c0ff4e29ca84.1326972302.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 192.35.17.2 Cc: Blue Swirl , Anthony Liguori , qemu-devel , kvm@vger.kernel.org, "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH v8 12/18] memory: Introduce memory_region_init_reservation 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 Introduce a memory region type that can reserve I/O space. Such regions are useful for modeling I/O that is only handled outside of QEMU, i.e. in the context of an accelerator like KVM. Any access to such a region from QEMU is a bug, but could theoretically be triggered by guest code (DMA to reserved region). So only warning about such events once, then ignore them. Signed-off-by: Jan Kiszka --- memory.c | 36 ++++++++++++++++++++++++++++++++++++ memory.h | 16 ++++++++++++++++ 2 files changed, 52 insertions(+), 0 deletions(-) diff --git a/memory.c b/memory.c index 6201a37..68e5cdf 100644 --- a/memory.c +++ b/memory.c @@ -1049,6 +1049,42 @@ void memory_region_init_rom_device(MemoryRegion *mr, mr->ram_addr |= cpu_register_io_memory(mr); } +static uint64_t invalid_read(void *opaque, target_phys_addr_t addr, + unsigned size) +{ + MemoryRegion *mr = opaque; + + if (!mr->warning_printed) { + fprintf(stderr, "Invalid read from memory region %s\n", mr->name); + mr->warning_printed = true; + } + return -1U; +} + +static void invalid_write(void *opaque, target_phys_addr_t addr, uint64_t data, + unsigned size) +{ + MemoryRegion *mr = opaque; + + if (!mr->warning_printed) { + fprintf(stderr, "Invalid write to memory region %s\n", mr->name); + mr->warning_printed = true; + } +} + +static const MemoryRegionOps reservation_ops = { + .read = invalid_read, + .write = invalid_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +void memory_region_init_reservation(MemoryRegion *mr, + const char *name, + uint64_t size) +{ + memory_region_init_io(mr, &reservation_ops, mr, name, size); +} + void memory_region_destroy(MemoryRegion *mr) { assert(QTAILQ_EMPTY(&mr->subregions)); diff --git a/memory.h b/memory.h index d48b08b..34c69cf 100644 --- a/memory.h +++ b/memory.h @@ -126,6 +126,7 @@ struct MemoryRegion { bool readonly; /* For RAM regions */ bool enabled; bool rom_device; + bool warning_printed; /* For reservations */ MemoryRegion *alias; target_phys_addr_t alias_offset; unsigned priority; @@ -280,6 +281,21 @@ void memory_region_init_rom_device(MemoryRegion *mr, uint64_t size); /** + * memory_region_init_reservation: Initialize a memory region that reserves + * I/O space. + * + * A reservation region primariy serves debugging purposes. It claims I/O + * space that is not supposed to be handled by QEMU itself. Any access via + * the memory API will cause an abort(). + * + * @mr: the #MemoryRegion to be initialized + * @name: used for debugging; not visible to the user or ABI + * @size: size of the region. + */ +void memory_region_init_reservation(MemoryRegion *mr, + const char *name, + uint64_t size); +/** * memory_region_destroy: Destroy a memory region and reclaim all resources. * * @mr: the region to be destroyed. May not currently be a subregion