hw/pc: Support system flash memory with -pflash parameter
PATCH v3 1/1 hw/pc: Support system flash memory with -pflash parameter
If -pflash is specified and -bios is specified then pflash will be mapped just below the system rom using hw/pflash_cfi01.c.
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 | 161 +++++++++++++++++++++++++++--------- 3 files changed, 125 insertions(+), 38 deletions(-)
default-configs/i386-softmmu.mak +1 -0
@@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=y CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y +CONFIG_PFLASH_CFI01=y
default-configs/x86_64-softmmu.mak +1 -0
@@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=y CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y +CONFIG_PFLASH_CFI01=y
hw/pc.c +123 -38
190 lines not on this page · raw message
Signature · 1 line
1.7.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v3 1/1 hw/pc: Support system flash memory with -pflash parameter
Does this fall under the trivial patch category?
Thanks,
-Jordan
---------- Forwarded message ----------
From: Jordan Justen <[email protected]>
Date: Thu, Mar 31, 2011 at 11:25
Subject: [Qemu-devel] [PATCH v3] hw/pc: Support system flash memory with -pflash parameter
To: [email protected]
Cc: Jordan Justen <[email protected]>
If -pflash is specified and -bios is specified then pflash will be mapped just below the system rom using hw/pflash_cfi01.c.
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 | 161 +++++++++++++++++++++++++++---------
3 files changed, 125 insertions(+), 38 deletions(-)
default-configs/i386-softmmu.mak +0 -0
@@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=y
CONFIG_SOUND=y
CONFIG_HPET=y
CONFIG_APPLESMC=y
+CONFIG_PFLASH_CFI01=y
(quoted diff) +0 -0
b/default-configs/x86_64-softmmu.mak
index 8895028..eca9284 100644
default-configs/x86_64-softmmu.mak +0 -0
@@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=y
CONFIG_SOUND=y
CONFIG_HPET=y
CONFIG_APPLESMC=y
+CONFIG_PFLASH_CFI01=y
hw/pc.c +0 -0
@@ -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
@@ -957,6 +958,124 @@ 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;
+ }
+ 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 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) {
+ ret = -1;
+ } else {
+ 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) {
+ 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: -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);
+ DPRINTF("flash addr: 0x%lx\n", (int64_t)phys_addr);
+ pflash_cfi01_register(phys_addr, addr, bdrv,
+ sector_size, size >> sector_bits,
+ 4, 0x0000, 0x0000, 0x0000, 0x0000, 0); +
+ 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);
+
+ /* Load rom if -bios is used or if -pflash is not used */
+ rom_present = ((bios_name != NULL) || !flash_present);
+
+ /* If rom is present, then it is mapped just below 4GB */
+ if (rom_present) {
+ rom_size = pc_system_rom_init();
+ } else {
+ rom_size = 0;
+ }
+
+ /* If flash is present, then it is mapped just below the rom, or
+ * just below 4GB when rom is not present. */
+ 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,
@@ -964,11 +1083,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 ) {
@@ -994,44 +1111,12 @@ void pc_memory_init(ram_addr_t ram_size, 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);
--
1.7.1
Quoted 8 lines · Jordan Justen
If -pflash is specified and -bios is specified then pflash will be mapped just below the system rom using
hw/pflash_cfi01.c.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.
Quoted 6 lines
Signed-off-by Jordan Justen <[email protected]>--- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/pc.c | 161 +++++++++++++++++++++++++++--------- 3 files changed, 125 insertions(+), 38 deletions(-)
Quoted 221 lines
default-configs/i386-softmmu.mak +1
-0@@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=y CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y +CONFIG_PFLASH_CFI01=ydefault-configs/x86_64-softmmu.mak +1
-0@@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=y CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y +CONFIG_PFLASH_CFI01=yhw/pc.c +123
-38@@ -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 @@ -957,6 +958,124 @@ 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 ; + } + 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 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 ) { + ret =-1 ; + }else { + 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 ) { +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: -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); +DPRINTF ("flash addr: 0x%lx\n" , (int64_t )phys_addr); +pflash_cfi01_register (phys_addr, addr, bdrv, + sector_size, size >> sector_bits, +4 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0 ); + +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 ); + +/* Load rom if -bios is used or if -pflash is not used */ + rom_present = ((bios_name !=NULL ) || !flash_present); + +/* If rom is present, then it is mapped just below 4GB */ +if (rom_present) { + rom_size =pc_system_rom_init (); + }else { + rom_size =0 ; + } + +/* If flash is present, then it is mapped just below the rom, or +* just below 4GB when rom is not present. */ +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,@@ -964,11 +1083,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 ) {@@ -994,44 +1111,12 @@ void pc_memory_init(ram_addr_t ram_size, 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);Signature · 1 line
1.7.1
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Ping? Cc:ed Anthony the maintainer of pc.c
Quoted 245 lines · Aurelien Jarno
Quoted 8 lines · Jordan Justen
If -pflash is specified and -bios is specified then pflash will be mapped just below the system rom using
hw/pflash_cfi01.c.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.
Quoted 6 lines
Signed-off-by Jordan Justen <[email protected]>--- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/pc.c | 161 +++++++++++++++++++++++++++--------- 3 files changed, 125 insertions(+), 38 deletions(-)Reviewed-by Aurelien Jarno <[email protected]>Quoted 221 lines
default-configs/i386-softmmu.mak +1
-0@@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=y CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y +CONFIG_PFLASH_CFI01=ydefault-configs/x86_64-softmmu.mak +1
-0@@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=y CONFIG_SOUND=y CONFIG_HPET=y CONFIG_APPLESMC=y +CONFIG_PFLASH_CFI01=yhw/pc.c +123
-38@@ -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 @@ -957,6 +958,124 @@ 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 ; + } + 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 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 ) { + ret =-1 ; + }else { + 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 ) { +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: -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); +DPRINTF ("flash addr: 0x%lx\n" , (int64_t )phys_addr); +pflash_cfi01_register (phys_addr, addr, bdrv, + sector_size, size >> sector_bits, +4 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0 ); + +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 ); + +/* Load rom if -bios is used or if -pflash is not used */ + rom_present = ((bios_name !=NULL ) || !flash_present); + +/* If rom is present, then it is mapped just below 4GB */ +if (rom_present) { + rom_size =pc_system_rom_init (); + }else { + rom_size =0 ; + } + +/* If flash is present, then it is mapped just below the rom, or +* just below 4GB when rom is not present. */ +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,@@ -964,11 +1083,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 ) {@@ -994,44 +1111,12 @@ void pc_memory_init(ram_addr_t ram_size, 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);Signature · 1 line
1.7.1Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Quoted 1 line · Aurelien Jarno
Ping? Cc:ed Anthony the maintainer of
pc.c
Sorry, I've been meaning to rebase this and add your reviewed-by.
Would that be the right next step in this case?
-Jordan
Quoted 253 lines · Aurelien Jarno
Quoted 234 lines · Jordan Justen
Quoted 8 lines
If -pflash is specified and -bios is specified then pflash will be mapped just below the system rom using
hw/pflash_cfi01.c.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.
Quoted 6 lines
Signed-off-by Jordan Justen <[email protected]>---
default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 +
hw/pc.c | 161 +++++++++++++++++++++++++++---------3 files changed, 125 insertions(+), 38 deletions(-)Reviewed-by Aurelien Jarno <[email protected]>Quoted 216 lines
default-configs/i386-softmmu.mak +0
-0@@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=yCONFIG_SOUND=y
CONFIG_HPET=y
CONFIG_APPLESMC=ydefault-configs/i386-softmmu.mak +1
-0+CONFIG_PFLASH_CFI01=ydefault-configs/x86_64-softmmu.mak +0
-0@@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=yCONFIG_SOUND=y
CONFIG_HPET=y
CONFIG_APPLESMC=ydefault-configs/x86_64-softmmu.mak +1
-0+CONFIG_PFLASH_CFI01=yhw/pc.c +123
-38@@ -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@@ -957,6 +958,124 @@ 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; + } + 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 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) { + ret = -1; + } else { + 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) { + 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: -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); + DPRINTF("flash addr: 0x%lx\n", (int64_t)phys_addr); + pflash_cfi01_register(phys_addr, addr, bdrv, + sector_size, size >> sector_bits, + 4, 0x0000, 0x0000, 0x0000, 0x0000, 0); + + 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); + + /* Load rom if -bios is used or if -pflash is not used */ + rom_present = ((bios_name != NULL) || !flash_present); + + /* If rom is present, then it is mapped just below 4GB */ + if (rom_present) { + rom_size = pc_system_rom_init(); + } else { + rom_size = 0; + } + + /* If flash is present, then it is mapped just below the rom, or + * just below 4GB when rom is not present. */ + 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,@@ -964,11 +1083,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 ) {@@ -994,44 +1111,12 @@ void pc_memory_init(ram_addr_t ram_size, 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);Quoted 11 lines
Quoted 5 lines
--
1.7.1--
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net--
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Quoted 7 lines · Jordan Justen
Quoted 1 line · Aurelien Jarno
Ping? Cc:ed Anthony the maintainer of
pc.cSorry, I've been meaning to rebase this and add your reviewed-by.
Would that be the right next step in this case?
Sorry, I wasn't very clear. Nothing to be done on your side. I am pinging other QEMU maintainers so that they can review the patch, and Anthony Liguori so he can ack it.
Quoted 253 lines
Quoted 252 lines · Aurelien Jarno
Quoted 234 lines · Jordan Justen
Quoted 8 lines
If -pflash is specified and -bios is specified then pflash will be mapped just below the system rom using
hw/pflash_cfi01.c.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.
Quoted 6 lines
Signed-off-by Jordan Justen <[email protected]>---
default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 +
hw/pc.c | 161 +++++++++++++++++++++++++++---------3 files changed, 125 insertions(+), 38 deletions(-)Reviewed-by Aurelien Jarno <[email protected]>Quoted 216 lines
default-configs/i386-softmmu.mak +0
-0@@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=yCONFIG_SOUND=y
CONFIG_HPET=y
CONFIG_APPLESMC=ydefault-configs/i386-softmmu.mak +1
-0+CONFIG_PFLASH_CFI01=ydefault-configs/x86_64-softmmu.mak +0
-0@@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=yCONFIG_SOUND=y
CONFIG_HPET=y
CONFIG_APPLESMC=ydefault-configs/x86_64-softmmu.mak +1
-0+CONFIG_PFLASH_CFI01=yhw/pc.c +123
-38@@ -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@@ -957,6 +958,124 @@ 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; + } + 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 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) { + ret = -1; + } else { + 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) { + 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: -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); + DPRINTF("flash addr: 0x%lx\n", (int64_t)phys_addr); + pflash_cfi01_register(phys_addr, addr, bdrv, + sector_size, size >> sector_bits, + 4, 0x0000, 0x0000, 0x0000, 0x0000, 0); + + 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); + + /* Load rom if -bios is used or if -pflash is not used */ + rom_present = ((bios_name != NULL) || !flash_present); + + /* If rom is present, then it is mapped just below 4GB */ + if (rom_present) { + rom_size = pc_system_rom_init(); + } else { + rom_size = 0; + } + + /* If flash is present, then it is mapped just below the rom, or + * just below 4GB when rom is not present. */ + 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,@@ -964,11 +1083,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 ) {@@ -994,44 +1111,12 @@ void pc_memory_init(ram_addr_t ram_size, 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);Quoted 11 lines
Quoted 5 lines
--
1.7.1--
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net--
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net