From patchwork Thu Jun 13 14:29:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 251083 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0C7332C008A for ; Fri, 14 Jun 2013 00:29:59 +1000 (EST) Received: from localhost ([::1]:56977 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Un8XE-0003KE-Tc for incoming@patchwork.ozlabs.org; Thu, 13 Jun 2013 10:29:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Un8WZ-0003B5-UI for qemu-devel@nongnu.org; Thu, 13 Jun 2013 10:29:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Un8WS-00029O-VB for qemu-devel@nongnu.org; Thu, 13 Jun 2013 10:29:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16906) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Un8WS-00029E-Mk for qemu-devel@nongnu.org; Thu, 13 Jun 2013 10:29:08 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5DET7lp028970 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 13 Jun 2013 10:29:08 -0400 Received: from redhat.com (vpn-203-103.tlv.redhat.com [10.35.203.103]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id r5DET3td020584; Thu, 13 Jun 2013 10:29:04 -0400 Date: Thu, 13 Jun 2013 17:29:47 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1371133655-10186-2-git-send-email-mst@redhat.com> References: <1371133655-10186-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1371133655-10186-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Michael Walle Subject: [Qemu-devel] [PATCH RFC 1/3] loader: support for unmapped ROM blobs 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 Support ROM blobs not mapped into guest memory: let user pass in MR for memory serving as the backing store. Signed-off-by: Michael S. Tsirkin --- hw/core/loader.c | 32 +++++++++++++++++++++++++++++--- hw/lm32/lm32_hwsetup.h | 2 +- include/hw/loader.h | 4 ++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/hw/core/loader.c b/hw/core/loader.c index a711145..ac62454 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -542,6 +542,7 @@ struct Rom { size_t datasize; uint8_t *data; + MemoryRegion *mr; int isrom; char *fw_dir; char *fw_file; @@ -641,7 +642,7 @@ err: } int rom_add_blob(const char *name, const void *blob, size_t len, - hwaddr addr) + hwaddr addr, MemoryRegion *mr) { Rom *rom; @@ -651,6 +652,11 @@ int rom_add_blob(const char *name, const void *blob, size_t len, rom->romsize = len; rom->datasize = len; rom->data = g_malloc0(rom->datasize); + rom->mr = mr; + if (mr) { + assert(memory_region_is_ram(mr)); + rom->isrom = memory_region_is_rom(mr); + } memcpy(rom->data, blob, len); rom_insert(rom); return 0; @@ -697,7 +703,12 @@ static void rom_reset(void *unused) if (rom->data == NULL) { continue; } - cpu_physical_memory_write_rom(rom->addr, rom->data, rom->datasize); + if (rom->mr) { + void *host = memory_region_get_ram_ptr(rom->mr); + memcpy(host, rom->data, rom->datasize); + } else { + cpu_physical_memory_write_rom(rom->addr, rom->data, rom->datasize); + } if (rom->isrom) { /* rom needs to be written only once */ g_free(rom->data); @@ -713,6 +724,9 @@ int rom_load_all(void) Rom *rom; QTAILQ_FOREACH(rom, &roms, next) { + if (rom->mr) { + continue; + } if (rom->fw_file) { continue; } @@ -746,6 +760,9 @@ static Rom *find_rom(hwaddr addr) if (rom->fw_file) { continue; } + if (rom->mr) { + continue; + } if (rom->addr > addr) { continue; } @@ -773,6 +790,9 @@ int rom_copy(uint8_t *dest, hwaddr addr, size_t size) if (rom->fw_file) { continue; } + if (rom->mr) { + continue; + } if (rom->addr + rom->romsize < addr) { continue; } @@ -832,7 +852,13 @@ void do_info_roms(Monitor *mon, const QDict *qdict) Rom *rom; QTAILQ_FOREACH(rom, &roms, next) { - if (!rom->fw_file) { + if (rom->mr) { + monitor_printf(mon, "%s" + " size=0x%06zx name=\"%s\"\n", + rom->mr->name, + rom->romsize, + rom->name); + } else if (!rom->fw_file) { monitor_printf(mon, "addr=" TARGET_FMT_plx " size=0x%06zx mem=%s name=\"%s\"\n", rom->addr, rom->romsize, diff --git a/hw/lm32/lm32_hwsetup.h b/hw/lm32/lm32_hwsetup.h index 3449bd8..d6914d6 100644 --- a/hw/lm32/lm32_hwsetup.h +++ b/hw/lm32/lm32_hwsetup.h @@ -73,7 +73,7 @@ static inline void hwsetup_free(HWSetup *hw) static inline void hwsetup_create_rom(HWSetup *hw, hwaddr base) { - rom_add_blob("hwsetup", hw->data, TARGET_PAGE_SIZE, base); + rom_add_blob("hwsetup", hw->data, TARGET_PAGE_SIZE, base, NULL); } static inline void hwsetup_add_u8(HWSetup *hw, uint8_t u) diff --git a/include/hw/loader.h b/include/hw/loader.h index 15d4cc9..b39e7d1 100644 --- a/include/hw/loader.h +++ b/include/hw/loader.h @@ -27,7 +27,7 @@ void pstrcpy_targphys(const char *name, int rom_add_file(const char *file, const char *fw_dir, hwaddr addr, int32_t bootindex); int rom_add_blob(const char *name, const void *blob, size_t len, - hwaddr addr); + hwaddr addr, MemoryRegion *mr); int rom_add_elf_program(const char *name, void *data, size_t datasize, size_t romsize, hwaddr addr); int rom_load_all(void); @@ -39,7 +39,7 @@ void do_info_roms(Monitor *mon, const QDict *qdict); #define rom_add_file_fixed(_f, _a, _i) \ rom_add_file(_f, NULL, _a, _i) #define rom_add_blob_fixed(_f, _b, _l, _a) \ - rom_add_blob(_f, _b, _l, _a) + rom_add_blob(_f, _b, _l, _a, NULL) #define PC_ROM_MIN_VGA 0xc0000 #define PC_ROM_MIN_OPTION 0xc8000