From patchwork Mon Mar 14 21:12:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jordan.l.justen@intel.com X-Patchwork-Id: 86821 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BFC1BB70CD for ; Tue, 15 Mar 2011 08:15:19 +1100 (EST) Received: from localhost ([127.0.0.1]:52844 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzF57-0007Vf-3g for incoming@patchwork.ozlabs.org; Mon, 14 Mar 2011 17:13:37 -0400 Received: from [140.186.70.92] (port=36358 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzF4K-0007SH-1H for qemu-devel@nongnu.org; Mon, 14 Mar 2011 17:12:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PzF4I-0007d8-L6 for qemu-devel@nongnu.org; Mon, 14 Mar 2011 17:12:47 -0400 Received: from mga02.intel.com ([134.134.136.20]:35199) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PzF4I-0007cj-9R for qemu-devel@nongnu.org; Mon, 14 Mar 2011 17:12:46 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 14 Mar 2011 14:12:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.62,318,1297065600"; d="scan'208";a="720090630" Received: from localhost.localdomain (HELO jljusten-laptop.jf.intel.com) ([10.7.202.166]) by orsmga001.jf.intel.com with ESMTP; 14 Mar 2011 14:12:35 -0700 From: jordan.l.justen@intel.com To: qemu-devel@nongnu.org Date: Mon, 14 Mar 2011 14:12:03 -0700 Message-Id: <1300137123-16632-1-git-send-email-jordan.l.justen@intel.com> X-Mailer: git-send-email 1.7.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.20 Cc: Jordan Justen , jljusten@gmail.com Subject: [Qemu-devel] [PATCH] hw/pc: Support system flash memory with -pflash parameter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jordan Justen When -pflash is specified, it will be mapped just below the system rom (wjust below 4GB). If -pflash is specified on the command line, but -bios is not specified, then 'bios.bin' will NOT be loaded, and instead the -pflash flash image will be mapped just below 4GB in place of the normal rom image. --- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/pc.c | 155 +++++++++++++++++++++++++++--------- 3 files changed, 119 insertions(+), 38 deletions(-) diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak index 323fafb..ed1e364 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -18,3 +18,4 @@ CONFIG_IDE_PIIX=y CONFIG_NE2000_ISA=y CONFIG_PIIX_PCI=y CONFIG_SOUND=y +CONFIG_PFLASH_CFI01=y diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak index eff26d2..21223b8 100644 --- a/default-configs/x86_64-softmmu.mak +++ b/default-configs/x86_64-softmmu.mak @@ -18,3 +18,4 @@ CONFIG_IDE_PIIX=y CONFIG_NE2000_ISA=y CONFIG_PIIX_PCI=y CONFIG_SOUND=y +CONFIG_PFLASH_CFI01=y diff --git a/hw/pc.c b/hw/pc.c index 4dfdc0b..b48e2c1 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -41,6 +41,7 @@ #include "sysemu.h" #include "blockdev.h" #include "ui/qemu-spice.h" +#include "flash.h" /* output Bochs bios info messages */ //#define DEBUG_BIOS @@ -945,6 +946,119 @@ void pc_cpus_init(const char *cpu_model) } } +static void pc_isa_bios_init(ram_addr_t ram_offset, int ram_size) +{ + int isa_bios_size; + + /* map the last 128KB of the BIOS in ISA space */ + isa_bios_size = ram_size; + if (isa_bios_size > (128 * 1024)) + isa_bios_size = 128 * 1024; + cpu_register_physical_memory(0x100000 - isa_bios_size, + isa_bios_size, + (ram_offset + ram_size - isa_bios_size) | IO_MEM_ROM); +} + +static int pc_system_rom_init(void) +{ + int ret; + int bios_size; + ram_addr_t bios_offset; + char *filename; + + /* BIOS load */ + if (bios_name == NULL) + bios_name = BIOS_FILENAME; + filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); + if (filename) { + bios_size = get_image_size(filename); + } else { + bios_size = -1; + } + if (bios_size <= 0 || + (bios_size % 65536) != 0) { + goto bios_error; + } + bios_offset = qemu_ram_alloc(NULL, "pc.bios", bios_size); + ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1); + if (ret != 0) { + bios_error: + fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name); + exit(1); + } + if (filename) { + qemu_free(filename); + } + + pc_isa_bios_init(bios_offset, bios_size); + + /* map all the bios at the top of memory */ + cpu_register_physical_memory((uint32_t)(-bios_size), + bios_size, bios_offset | IO_MEM_ROM); + + return bios_size; +} + +static void pc_system_flash_init(DriveInfo *pflash_drv, int rom_size) +{ + BlockDriverState *bdrv; + int64_t size; + target_phys_addr_t phys_addr; + ram_addr_t addr; + int sector_bits, sector_size; + + bdrv = NULL; + + bdrv = pflash_drv->bdrv; + size = bdrv_getlength(pflash_drv->bdrv); + sector_bits = 12; + sector_size = 1 << sector_bits; + + if ((size % sector_size) != 0) { + fprintf(stderr, + "qemu: PC FLASH (pflash) size must be a multiple of 0x%x\n", + sector_size); + exit(1); + } + + phys_addr = 0x100000000ULL - rom_size - size; + addr = qemu_ram_alloc(NULL, "system.flash", size); + printf("flash addr: 0x%lx\n", (int64_t)phys_addr); +#if 1 + pflash_cfi01_register(phys_addr, addr, bdrv, + sector_size, size >> sector_bits, + 4, 0x0000, 0x0000, 0x0000, 0x0000, 0); +#else + pflash_cfi02_register(phys_addr, addr, bdrv, + sector_size, size >> sector_bits, + 1, 4, 0x0000, 0x0000, 0x0000, 0x0000, 0x55, 0xaa, 0); +#endif + if (rom_size == 0) { + pc_isa_bios_init(addr, size); + } +} + +static void pc_system_firmware_init(void) +{ + int flash_present, rom_present; + int rom_size; + DriveInfo *pflash_drv; + + pflash_drv = drive_get(IF_PFLASH, 0, 0); + flash_present = (pflash_drv != NULL); + rom_present = ((bios_name != NULL) || !flash_present); + + if (rom_present) { + rom_size = pc_system_rom_init(); + } else { + rom_size = 0; + } + + if (flash_present) { + pc_system_flash_init(pflash_drv, rom_size); + } +} + void pc_memory_init(ram_addr_t ram_size, const char *kernel_filename, const char *kernel_cmdline, @@ -952,11 +1066,9 @@ void pc_memory_init(ram_addr_t ram_size, ram_addr_t *below_4g_mem_size_p, ram_addr_t *above_4g_mem_size_p) { - char *filename; - int ret, linux_boot, i; - ram_addr_t ram_addr, bios_offset, option_rom_offset; + int linux_boot, i; + ram_addr_t ram_addr, option_rom_offset; ram_addr_t below_4g_mem_size, above_4g_mem_size = 0; - int bios_size, isa_bios_size; void *fw_cfg; if (ram_size >= 0xe0000000 ) { @@ -989,44 +1101,11 @@ void pc_memory_init(ram_addr_t ram_size, } #endif - /* BIOS load */ - if (bios_name == NULL) - bios_name = BIOS_FILENAME; - filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); - if (filename) { - bios_size = get_image_size(filename); - } else { - bios_size = -1; - } - if (bios_size <= 0 || - (bios_size % 65536) != 0) { - goto bios_error; - } - bios_offset = qemu_ram_alloc(NULL, "pc.bios", bios_size); - ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1); - if (ret != 0) { - bios_error: - fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name); - exit(1); - } - if (filename) { - qemu_free(filename); - } - /* map the last 128KB of the BIOS in ISA space */ - isa_bios_size = bios_size; - if (isa_bios_size > (128 * 1024)) - isa_bios_size = 128 * 1024; - cpu_register_physical_memory(0x100000 - isa_bios_size, - isa_bios_size, - (bios_offset + bios_size - isa_bios_size) | IO_MEM_ROM); + pc_system_firmware_init(); option_rom_offset = qemu_ram_alloc(NULL, "pc.rom", PC_ROM_SIZE); cpu_register_physical_memory(PC_ROM_MIN_VGA, PC_ROM_SIZE, option_rom_offset); - /* map all the bios at the top of memory */ - cpu_register_physical_memory((uint32_t)(-bios_size), - bios_size, bios_offset | IO_MEM_ROM); - fw_cfg = bochs_bios_init(); rom_set_fw(fw_cfg);