From patchwork Tue Dec 6 12:58:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 129692 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 B50DEB6F9B for ; Wed, 7 Dec 2011 01:02:35 +1100 (EST) Received: from localhost ([::1]:53320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXucC-0002ie-NE for incoming@patchwork.ozlabs.org; Tue, 06 Dec 2011 07:59:20 -0500 Received: from eggs.gnu.org ([140.186.70.92]:58948) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXubW-0000dt-42 for qemu-devel@nongnu.org; Tue, 06 Dec 2011 07:58:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RXubR-0002c1-4g for qemu-devel@nongnu.org; Tue, 06 Dec 2011 07:58:38 -0500 Received: from goliath.siemens.de ([192.35.17.28]:21798) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXubQ-0002bt-PG for qemu-devel@nongnu.org; Tue, 06 Dec 2011 07:58:33 -0500 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.13.6/8.13.6) with ESMTP id pB6CwUlL014239; Tue, 6 Dec 2011 13:58:30 +0100 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id pB6CwHqD011829; Tue, 6 Dec 2011 13:58:28 +0100 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Date: Tue, 6 Dec 2011 13:58:10 +0100 Message-Id: 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.28 Cc: Blue Swirl , Anthony Liguori , qemu-devel , kvm@vger.kernel.org, "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH v3 10/16] 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 dc5e35d..6d55cf6 100644 --- a/memory.c +++ b/memory.c @@ -1003,6 +1003,42 @@ void memory_region_init_rom_device(MemoryRegion *mr, mr->backend_registered = true; } +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 d5b47da..b479350 100644 --- a/memory.h +++ b/memory.h @@ -115,6 +115,7 @@ struct MemoryRegion { bool terminates; bool readable; bool readonly; /* For RAM regions */ + bool warning_printed; /* For reservations */ MemoryRegion *alias; target_phys_addr_t alias_offset; unsigned priority; @@ -242,6 +243,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 relaim all resources. * * @mr: the region to be destroyed. May not currently be a subregion