From patchwork Fri Apr 20 04:16:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 153935 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 88CB3B7034 for ; Fri, 20 Apr 2012 15:23:22 +1000 (EST) Received: from localhost ([::1]:47045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SL5I2-0002pl-U0 for incoming@patchwork.ozlabs.org; Fri, 20 Apr 2012 00:17:46 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SL5HV-0001IG-3i for qemu-devel@nongnu.org; Fri, 20 Apr 2012 00:17:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SL5HR-0001sT-Tt for qemu-devel@nongnu.org; Fri, 20 Apr 2012 00:17:12 -0400 Received: from ozlabs.org ([203.10.76.45]:47068) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SL5HR-0001s1-I3 for qemu-devel@nongnu.org; Fri, 20 Apr 2012 00:17:09 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id AAC9AB6FD2; Fri, 20 Apr 2012 14:17:06 +1000 (EST) From: David Gibson To: aliguori@us.ibm.com Date: Fri, 20 Apr 2012 14:16:47 +1000 Message-Id: <1334895417-16415-4-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1334895417-16415-1-git-send-email-david@gibson.dropbear.id.au> References: <1334895417-16415-1-git-send-email-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 203.10.76.45 Cc: kwolf@redhat.com, mst@redhat.com, aik@ozlabs.ru, agraf@suse.de, qemu-devel@nongnu.org, kraxel@redhat.com, eduard.munteanu@linux360.ro, David Gibson Subject: [Qemu-devel] [PATCH 03/13] Implement cpu_physical_memory_zero() 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 This patch adds cpu_physical_memory_zero() function. This is equivalent to calling cpu_physical_memory_write() with a buffer full of zeroes, but avoids actually allocating such a buffer along the way. Signed-off-by: David Gibson --- cpu-common.h | 1 + exec.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/cpu-common.h b/cpu-common.h index dca5175..146429c 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -53,6 +53,7 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev); void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, int len, int is_write); +void cpu_physical_memory_zero(target_phys_addr_t addr, int len); static inline void cpu_physical_memory_read(target_phys_addr_t addr, void *buf, int len) { diff --git a/exec.c b/exec.c index 77d6866..0afe101 100644 --- a/exec.c +++ b/exec.c @@ -3874,6 +3874,59 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, } } +void cpu_physical_memory_zero(target_phys_addr_t addr, int len) +{ + int l; + uint8_t *ptr; + target_phys_addr_t page; + MemoryRegionSection *section; + + while (len > 0) { + page = addr & TARGET_PAGE_MASK; + l = (page + TARGET_PAGE_SIZE) - addr; + if (l > len) + l = len; + section = phys_page_find(page >> TARGET_PAGE_BITS); + + if (!memory_region_is_ram(section->mr)) { + target_phys_addr_t addr1; + addr1 = section_addr(section, addr); + /* XXX: could force cpu_single_env to NULL to avoid + potential bugs */ + if (l >= 4 && ((addr1 & 3) == 0)) { + /* 32 bit write access */ + io_mem_write(section->mr, addr1, 0, 4); + l = 4; + } else if (l >= 2 && ((addr1 & 1) == 0)) { + /* 16 bit write access */ + io_mem_write(section->mr, addr1, 0, 2); + l = 2; + } else { + /* 8 bit write access */ + io_mem_write(section->mr, addr1, 0, 1); + l = 1; + } + } else if (!section->readonly) { + ram_addr_t addr1; + addr1 = memory_region_get_ram_addr(section->mr) + + section_addr(section, addr); + /* RAM case */ + ptr = qemu_get_ram_ptr(addr1); + memset(ptr, 0, l); + if (!cpu_physical_memory_is_dirty(addr1)) { + /* invalidate code */ + tb_invalidate_phys_page_range(addr1, addr1 + l, 0); + /* set dirty bit */ + cpu_physical_memory_set_dirty_flags( + addr1, (0xff & ~CODE_DIRTY_FLAG)); + } + qemu_put_ram_ptr(ptr); + } + len -= l; + addr += l; + } +} + /* used for ROM loading : can write in RAM and ROM */ void cpu_physical_memory_write_rom(target_phys_addr_t addr, const uint8_t *buf, int len)