From patchwork Fri Jan 6 18:58:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 134690 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 47873B6F18 for ; Sat, 7 Jan 2012 06:26:44 +1100 (EST) Received: from localhost ([::1]:35358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjFR3-0005Og-Mb for incoming@patchwork.ozlabs.org; Fri, 06 Jan 2012 14:26:41 -0500 Received: from eggs.gnu.org ([140.186.70.92]:43064) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjFQx-0005OV-9m for qemu-devel@nongnu.org; Fri, 06 Jan 2012 14:26:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RjFQv-00017W-3A for qemu-devel@nongnu.org; Fri, 06 Jan 2012 14:26:35 -0500 Received: from mnementh.archaic.org.uk ([81.2.115.146]:34614) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjFQu-00017E-Rd for qemu-devel@nongnu.org; Fri, 06 Jan 2012 14:26:33 -0500 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1RjEzk-0007Jg-Pp; Fri, 06 Jan 2012 18:58:28 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 6 Jan 2012 18:58:28 +0000 Message-Id: <1325876308-28097-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1325876308-28097-1-git-send-email-peter.maydell@linaro.org> References: <1325876308-28097-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 81.2.115.146 Cc: =?UTF-8?q?Beno=C3=AEt=20Canet?= , Avi Kivity , patches@linaro.org Subject: [Qemu-devel] [PATCH v4 2/2] hw/integratorcp: Simplify flash remap code 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 Use the new memory mutator API to simplify the flash remap code; this allows us to drop the flash_mapped flag. Signed-off-by: Peter Maydell Reviewed-by: Andreas Färber --- hw/integratorcp.c | 26 +++++++------------------- 1 files changed, 7 insertions(+), 19 deletions(-) diff --git a/hw/integratorcp.c b/hw/integratorcp.c index d9d8da3..e5712fc 100644 --- a/hw/integratorcp.c +++ b/hw/integratorcp.c @@ -21,7 +21,6 @@ typedef struct { MemoryRegion iomem; uint32_t memsz; MemoryRegion flash; - bool flash_mapped; uint32_t cm_osc; uint32_t cm_ctrl; uint32_t cm_lock; @@ -110,20 +109,12 @@ static uint64_t integratorcm_read(void *opaque, target_phys_addr_t offset, } } -static void integratorcm_do_remap(integratorcm_state *s, int flash) +static void integratorcm_do_remap(integratorcm_state *s) { - if (!flash) { - if (s->flash_mapped) { - sysbus_del_memory(&s->busdev, &s->flash); - s->flash_mapped = false; - } - } else { - if (!s->flash_mapped) { - sysbus_add_memory_overlap(&s->busdev, 0, &s->flash, 1); - s->flash_mapped = true; - } - } - //??? tlb_flush (cpu_single_env, 1); + /* Sync memory region state with CM_CTRL REMAP bit: + * bit 0 => flash at address 0; bit 1 => RAM + */ + memory_region_set_enabled(&s->flash, !(s->cm_ctrl & 4)); } static void integratorcm_set_ctrl(integratorcm_state *s, uint32_t value) @@ -131,9 +122,6 @@ static void integratorcm_set_ctrl(integratorcm_state *s, uint32_t value) if (value & 8) { qemu_system_reset_request(); } - if ((s->cm_ctrl ^ value) & 4) { - integratorcm_do_remap(s, (value & 4) == 0); - } if ((s->cm_ctrl ^ value) & 1) { /* (value & 1) != 0 means the green "MISC LED" is lit. * We don't have any nice place to display LEDs. printf is a bad @@ -143,6 +131,7 @@ static void integratorcm_set_ctrl(integratorcm_state *s, uint32_t value) } /* Note that the RESET bit [3] always reads as zero */ s->cm_ctrl = (s->cm_ctrl & ~5) | (value & 5); + integratorcm_do_remap(s); } static void integratorcm_update(integratorcm_state *s) @@ -263,13 +252,12 @@ static int integratorcm_init(SysBusDevice *dev) s->cm_init = 0x00000112; memory_region_init_ram(&s->flash, "integrator.flash", 0x100000); vmstate_register_ram_global(&s->flash); - s->flash_mapped = false; memory_region_init_io(&s->iomem, &integratorcm_ops, s, "integratorcm", 0x00800000); sysbus_init_mmio(dev, &s->iomem); - integratorcm_do_remap(s, 1); + integratorcm_do_remap(s); /* ??? Save/restore. */ return 0; }