From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:58263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmmmJ-0003FS-RX for qemu-devel@nongnu.org; Fri, 29 Jul 2011 09:07:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QmmmI-0004QV-3t for qemu-devel@nongnu.org; Fri, 29 Jul 2011 09:06:59 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]:44709) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmmmH-0004QM-VB for qemu-devel@nongnu.org; Fri, 29 Jul 2011 09:06:58 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by e9.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p6TCYHMs032688 for ; Fri, 29 Jul 2011 08:34:17 -0400 Received: from d03av06.boulder.ibm.com (d03av06.boulder.ibm.com [9.17.195.245]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p6TD6sM5124714 for ; Fri, 29 Jul 2011 09:06:55 -0400 Received: from d03av06.boulder.ibm.com (loopback [127.0.0.1]) by d03av06.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p6TDBifY010480 for ; Fri, 29 Jul 2011 07:11:44 -0600 Message-ID: <4E32B03F.3030305@us.ibm.com> Date: Fri, 29 Jul 2011 08:06:07 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1311629692-5734-1-git-send-email-jordan.l.justen@intel.com> <1311629692-5734-2-git-send-email-jordan.l.justen@intel.com> In-Reply-To: <1311629692-5734-2-git-send-email-jordan.l.justen@intel.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/2] pc: Support system flash memory with pflash List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jordan Justen Cc: qemu-devel@nongnu.org, Aurelien Jarno On 07/25/2011 04:34 PM, Jordan Justen wrote: > If a pflash image is found, then it is used for the system > firmware image. > > If a pflash image is not initially found, then a read-only > pflash device is created using the -bios filename. > > Signed-off-by: Jordan Justen > Cc: Anthony Liguori > Cc: Aurelien Jarno > --- > Makefile.target | 2 +- > default-configs/i386-softmmu.mak | 1 + > default-configs/x86_64-softmmu.mak | 1 + > hw/boards.h | 1 + > hw/pc.c | 46 +------------ > hw/pc.h | 2 + > hw/pcflash.c | 130 ++++++++++++++++++++++++++++++++++++ > vl.c | 2 +- > 8 files changed, 141 insertions(+), 44 deletions(-) > create mode 100644 hw/pcflash.c > > diff --git a/Makefile.target b/Makefile.target > index cde509b..4d8821f 100644 > --- a/Makefile.target > +++ b/Makefile.target > @@ -223,7 +223,7 @@ obj-$(CONFIG_IVSHMEM) += ivshmem.o > > # Hardware support > obj-i386-y += vga.o > -obj-i386-y += mc146818rtc.o i8259.o pc.o > +obj-i386-y += mc146818rtc.o i8259.o pc.o pcflash.o This should be able to live in hw-obj-y in Makefile.objs since it doesn't depend on any TARGET_ defines or CPUState. > diff --git a/hw/pc.c b/hw/pc.c > index a3e8539..cf7257b 100644 > --- a/hw/pc.c > +++ b/hw/pc.c > @@ -55,10 +55,6 @@ > #define DPRINTF(fmt, ...) > #endif > > -#define BIOS_FILENAME "bios.bin" > - > -#define PC_MAX_BIOS_SIZE (4 * 1024 * 1024) > - > /* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables. */ > #define ACPI_DATA_SIZE 0x10000 > #define BIOS_CFG_IOPORT 0x510 > @@ -963,10 +959,8 @@ void pc_memory_init(const char *kernel_filename, > ram_addr_t below_4g_mem_size, > ram_addr_t above_4g_mem_size) > { > - char *filename; > - int ret, linux_boot, i; > - ram_addr_t ram_addr, bios_offset, option_rom_offset; > - int bios_size, isa_bios_size; > + int linux_boot, i; > + ram_addr_t ram_addr, option_rom_offset; > void *fw_cfg; > > linux_boot = (kernel_filename != NULL); > @@ -983,44 +977,12 @@ void pc_memory_init(const char *kernel_filename, > ram_addr + below_4g_mem_size); > } > > - /* 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); > + /* Initialize ROM or flash ranges for PC firmware */ > + 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); > > diff --git a/hw/pc.h b/hw/pc.h > index 6d5730b..114816d 100644 > --- a/hw/pc.h > +++ b/hw/pc.h > @@ -238,4 +238,6 @@ static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd) > > int e820_add_entry(uint64_t, uint64_t, uint32_t); > > +void pc_system_firmware_init(void); > + > #endif > diff --git a/hw/pcflash.c b/hw/pcflash.c > new file mode 100644 > index 0000000..514b1ed > --- /dev/null > +++ b/hw/pcflash.c > @@ -0,0 +1,130 @@ > +/* > + * QEMU PC System Flash > + * > + * Copyright (c) 2003-2004 Fabrice Bellard > + * Copyright (c) 2011 Intel Corporation > + * > + * Permission is hereby granted, free of charge, to any person obtaining a copy > + * of this software and associated documentation files (the "Software"), to deal > + * in the Software without restriction, including without limitation the rights > + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell > + * copies of the Software, and to permit persons to whom the Software is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN > + * THE SOFTWARE. > + */ > + > +#include "hw.h" > +#include "pc.h" > +#include "hw/boards.h" > +#include "loader.h" > +#include "sysemu.h" > +#include "flash.h" > + > +#define BIOS_FILENAME "bios.bin" > + > +#define PC_MAX_BIOS_SIZE (4 * 1024 * 1024) > + > +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; > + } > + ram_offset = ram_offset + ram_size - isa_bios_size; > + cpu_register_physical_memory(0x100000 - isa_bios_size, > + isa_bios_size, > + ram_offset | IO_MEM_ROM); > +} > + > +static void pc_default_system_flash_init(void) > +{ > + QemuOpts *opts; > + QEMUMachine *machine; > + char *filename; > + > + if (bios_name == NULL) { > + bios_name = BIOS_FILENAME; > + } > + filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); > + fprintf(stderr, "ROM: %s\n", filename); > + > + opts = drive_add(IF_PFLASH, -1, filename, "readonly=on"); > + if (opts == NULL) { > + return; > + } > + > + machine = find_default_machine(); > + if (machine == NULL) { > + return; > + } > + > + drive_init(opts, machine->use_scsi); > +} > + > +static void pc_system_flash_init(DriveInfo *pflash_drv) > +{ > + 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 system firmware (pflash) must be a multiple of 0x%x\n", > + sector_size); > + exit(1); > + } > + > + phys_addr = 0x100000000ULL - size; > + addr = qemu_ram_alloc(NULL, "system.flash", size); > + pflash_cfi01_register(phys_addr, addr, bdrv, > + sector_size, size>> sector_bits, > + 4, 0x0000, 0x0000, 0x0000, 0x0000, 0); > + > + pc_isa_bios_init(addr, size); > +} > + > +void pc_system_firmware_init(void) > +{ > + int flash_present; > + DriveInfo *pflash_drv; > + > + pflash_drv = drive_get(IF_PFLASH, 0, 0); > + flash_present = (pflash_drv != NULL); > + > + if (!flash_present) { > + pc_default_system_flash_init(); > + pflash_drv = drive_get(IF_PFLASH, 0, 0); > + flash_present = (pflash_drv != NULL); > + } > + > + if (!flash_present) { > + fprintf(stderr, "qemu: PC system firmware (pflash) not available\n"); > + exit(1); > + } > + > + pc_system_flash_init(pflash_drv); > +} > + This didn't quite turn out how I had hoped but without touching every machine init, I don't see a better way. Regards, Anthony Liguori > diff --git a/vl.c b/vl.c > index 4b6688b..00d8fcb 100644 > --- a/vl.c > +++ b/vl.c > @@ -1063,7 +1063,7 @@ static QEMUMachine *find_machine(const char *name) > return NULL; > } > > -static QEMUMachine *find_default_machine(void) > +QEMUMachine *find_default_machine(void) > { > QEMUMachine *m; >