From patchwork Tue Dec 20 16:08:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 5895 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 644A823E0E for ; Tue, 20 Dec 2011 16:09:05 +0000 (UTC) Received: from mail-ey0-f180.google.com (mail-ey0-f180.google.com [209.85.215.180]) by fiordland.canonical.com (Postfix) with ESMTP id 5250CA18200 for ; Tue, 20 Dec 2011 16:09:05 +0000 (UTC) Received: by eaac11 with SMTP id c11so3477129eaa.11 for ; Tue, 20 Dec 2011 08:09:05 -0800 (PST) Received: by 10.205.120.14 with SMTP id fw14mr854341bkc.53.1324397344908; Tue, 20 Dec 2011 08:09:04 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.82.144 with SMTP id ac16cs16257bkc; Tue, 20 Dec 2011 08:09:03 -0800 (PST) Received: by 10.204.151.76 with SMTP id b12mr830347bkw.139.1324397342636; Tue, 20 Dec 2011 08:09:02 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id r44si1195716weq.6.2011.12.20.08.09.02 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 20 Dec 2011 08:09:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1Rd2FM-00087p-26; Tue, 20 Dec 2011 16:08:56 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, =?UTF-8?q?Beno=C3=AEt=20Canet?= , Anthony Liguori , Avi Kivity Subject: [PATCH v2 2/2] hw/integratorcp: Simplify flash remap code Date: Tue, 20 Dec 2011 16:08:56 +0000 Message-Id: <1324397336-31206-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1324397336-31206-1-git-send-email-peter.maydell@linaro.org> References: <1324397336-31206-1-git-send-email-peter.maydell@linaro.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 --- hw/integratorcp.c | 26 +++++++++----------------- 1 files changed, 9 insertions(+), 17 deletions(-) diff --git a/hw/integratorcp.c b/hw/integratorcp.c index 8e4c154..fb243e1 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,16 @@ 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; - } + /* Sync memory region state with CM_CTRL REMAP bit: + * bit 0 => flash at address 0; bit 1 => RAM + */ + if (s->cm_ctrl & 4) { + memory_region_set_enabled(&s->flash, 0); } else { - if (!s->flash_mapped) { - sysbus_add_memory_overlap(&s->busdev, 0, &s->flash, 1); - s->flash_mapped = true; - } + memory_region_set_enabled(&s->flash, 1); } - //??? tlb_flush (cpu_single_env, 1); } static void integratorcm_set_ctrl(integratorcm_state *s, uint32_t value) @@ -131,9 +126,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 +135,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) @@ -262,13 +255,12 @@ static int integratorcm_init(SysBusDevice *dev) memcpy(integrator_spd + 73, "QEMU-MEMORY", 11); s->cm_init = 0x00000112; memory_region_init_ram(&s->flash, NULL, "integrator.flash", 0x100000); - 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; }