Skip to contentSkip to conversation

option rom loading via fw_cfg

RFC PATCH In review Gerd Hoffmann 2 participants 7 messages Dec 16, 2009 – Dec 17, 2009

lore
Share & tools
lore
#0 lore raw

cover option rom loading via fw_cfg

Hi,

quick draft of a file xfer api for fw_cfg, qemu side only, not tested yet, to be used for option roms.

comments?

cheers,
Gerd

#1 lore raw

PATCH 1/3 fw_cfg: make calls typesafe

---
 hw/fw_cfg.c |   26 ++++++++++++--------------
 hw/fw_cfg.h |   16 +++++++++-------
 2 files changed, 21 insertions(+), 21 deletions(-)
hw/fw_cfg.c +12 -14
index b25afff..2e3662d 100644
@@ -45,11 +45,11 @@ typedef struct _FWCfgEntry {
     FWCfgCallback callback;
 } FWCfgEntry;
 
-typedef struct _FWCfgState {
+struct _FWCfgState {
     FWCfgEntry entries[2][FW_CFG_MAX_ENTRY];
     uint16_t cur_entry;
     uint32_t cur_offset;
-} FWCfgState;
+};
 
 static void fw_cfg_write(FWCfgState *s, uint8_t value)
 {
@@ -210,9 +210,8 @@ static const VMStateDescription vmstate_fw_cfg = {
     }
 };
 
-int fw_cfg_add_bytes(void *opaque, uint16_t key, uint8_t *data, uint32_t len)
+int fw_cfg_add_bytes(FWCfgState *s, uint16_t key, uint8_t *data, uint32_t len)
 {
-    FWCfgState *s = opaque;
     int arch = !!(key & FW_CFG_ARCH_LOCAL);
 
     key &= FW_CFG_ENTRY_MASK;
@@ -226,37 +225,36 @@ int fw_cfg_add_bytes(void *opaque, uint16_t key, uint8_t *data, uint32_t len)
     return 1;
 }
 
-int fw_cfg_add_i16(void *opaque, uint16_t key, uint16_t value)
+int fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value)
 {
     uint16_t *copy;
 
     copy = qemu_malloc(sizeof(value));
     *copy = cpu_to_le16(value);
-    return fw_cfg_add_bytes(opaque, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_i32(void *opaque, uint16_t key, uint32_t value)
+int fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value)
 {
     uint32_t *copy;
 
     copy = qemu_malloc(sizeof(value));
     *copy = cpu_to_le32(value);
-    return fw_cfg_add_bytes(opaque, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_i64(void *opaque, uint16_t key, uint64_t value)
+int fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
 {
     uint64_t *copy;
 
     copy = qemu_malloc(sizeof(value));
     *copy = cpu_to_le64(value);
-    return fw_cfg_add_bytes(opaque, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_callback(void *opaque, uint16_t key, FWCfgCallback callback,
+int fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
                         void *callback_opaque, uint8_t *data, size_t len)
 {
-    FWCfgState *s = opaque;
     int arch = !!(key & FW_CFG_ARCH_LOCAL);
 
     if (!(key & FW_CFG_WRITE_CHANNEL))
@@ -275,8 +273,8 @@ int fw_cfg_add_callback(void *opaque, uint16_t key, FWCfgCallback callback,
     return 1;
 }
 
-void *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
-		target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
+FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
+                        target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
 {
     FWCfgState *s;
     int io_ctl_memory, io_data_memory;
hw/fw_cfg.h +9 -7
index 7070c94..b06665e 100644
@@ -37,14 +37,16 @@
 #ifndef NO_QEMU_PROTOS
 typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
 
-int fw_cfg_add_bytes(void *opaque, uint16_t key, uint8_t *data, uint32_t len);
-int fw_cfg_add_i16(void *opaque, uint16_t key, uint16_t value);
-int fw_cfg_add_i32(void *opaque, uint16_t key, uint32_t value);
-int fw_cfg_add_i64(void *opaque, uint16_t key, uint64_t value);
-int fw_cfg_add_callback(void *opaque, uint16_t key, FWCfgCallback callback,
+typedef struct _FWCfgState FWCfgState;
+int fw_cfg_add_bytes(FWCfgState *s, uint16_t key, uint8_t *data, uint32_t len);
+int fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
+int fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
+int fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
+int fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
                         void *callback_opaque, uint8_t *data, size_t len);
-void *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
-		target_phys_addr_t crl_addr, target_phys_addr_t data_addr);
+int fw_cfg_add_file(FWCfgState *s, uint8_t type, uint8_t *data, uint32_t len);
+FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
+                        target_phys_addr_t crl_addr, target_phys_addr_t data_addr);
 
 #endif /* NO_QEMU_PROTOS */
 
Signature · 1 line
1.6.5.2
#2 lore raw

PATCH 2/3 fw_cfg: file xfer api

In reply to Gerd Hoffmann
---
 hw/fw_cfg.c |   22 ++++++++++++++++++++++
 hw/fw_cfg.h |   22 +++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletions(-)
hw/fw_cfg.c +22 -0
index 2e3662d..1dd7d6a 100644
@@ -47,6 +47,7 @@ typedef struct _FWCfgEntry {
 
 struct _FWCfgState {
     FWCfgEntry entries[2][FW_CFG_MAX_ENTRY];
+    FWCfgFiles *files;
     uint16_t cur_entry;
     uint32_t cur_offset;
 };
@@ -273,6 +274,27 @@ int fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
     return 1;
 }
 
+int fw_cfg_add_file(FWCfgState *s, uint8_t type, uint8_t *data, uint32_t len)
+{
+    if (!s->files) {
+        int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;
+        s->files = qemu_mallocz(dsize);
+        fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, (uint8_t*)s->files, dsize);
+    }
+    if (s->files->count == FW_CFG_FILE_SLOTS) {
+        fprintf(stderr, "fw_cfg: out of file slots\n");
+        return 0;
+    }
+
+    fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + s->files->count, data, len);
+    s->files->f[s->files->count].type   = type;
+    s->files->f[s->files->count].size   = len;
+    s->files->f[s->files->count].select = FW_CFG_FILE_FIRST + s->files->count;
+    s->files->count++;
+
+    return 1;
+}
+
 FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
                         target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
 {
hw/fw_cfg.h +21 -1
index b06665e..460d64d 100644
@@ -26,7 +26,11 @@
 #define FW_CFG_SETUP_ADDR       0x16
 #define FW_CFG_SETUP_SIZE       0x17
 #define FW_CFG_SETUP_DATA       0x18
-#define FW_CFG_MAX_ENTRY        0x19
+#define FW_CFG_FILE_DIR         0x19
+
+#define FW_CFG_FILE_FIRST       0x20
+#define FW_CFG_FILE_SLOTS       0x10
+#define FW_CFG_MAX_ENTRY        (FW_CFG_FILE_FIRST+FW_CFG_FILE_SLOTS)
 
 #define FW_CFG_WRITE_CHANNEL    0x4000
 #define FW_CFG_ARCH_LOCAL       0x8000
@@ -34,6 +38,22 @@
 
 #define FW_CFG_INVALID          0xffff
 
+#define FW_CFG_FILE_TYPE_UNKNOWN    0
+#define FW_CFG_FILE_TYPE_VGABIOS    1
+#define FW_CFG_FILE_TYPE_OPTIONROM  2
+
+typedef struct FWCfgFile {
+    uint32_t  size;        /* file size */
+    uint16_t  select;      /* write this to 0x510 to read it */
+    uint8_t   type;        /* vga, option, other? */
+    uint8_t   reserved;
+} FWCfgFile;
+
+typedef struct FWCfgFiles {
+    uint32_t  count;
+    FWCfgFile f[];
+} FWCfgFiles;
+
 #ifndef NO_QEMU_PROTOS
 typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
 
Signature · 1 line
1.6.5.2
#3 lore raw

PATCH 3/3 roms: use fw_cfg file xfer api

In reply to Gerd Hoffmann
---
 hw/loader.c |   23 ++++++++++++++++++++---
 hw/loader.h |    5 +++--
 hw/pc.c     |    2 ++
 3 files changed, 25 insertions(+), 5 deletions(-)
hw/loader.c +20 -3
index 2d7a2c4..d1d05ed 100644
@@ -48,6 +48,7 @@
 #include "sysemu.h"
 #include "uboot_image.h"
 #include "loader.h"
+#include "fw_cfg.h"
 
 #include <zlib.h>
 
@@ -528,6 +529,7 @@ struct Rom {
     uint8_t *data;
     int align;
     int isrom;
+    int type;
 
     target_phys_addr_t min;
     target_phys_addr_t max;
@@ -556,7 +558,7 @@ static void rom_insert(Rom *rom)
     QTAILQ_INSERT_TAIL(&roms, rom, next);
 }
 
-int rom_add_file(const char *file,
+int rom_add_file(const char *file, int fw_file_type,
                  target_phys_addr_t min, target_phys_addr_t max, int align)
 {
     Rom *rom;
@@ -576,6 +578,7 @@ int rom_add_file(const char *file,
         goto err;
     }
 
+    rom->type    = fw_file_type;
     rom->align   = align;
     rom->min     = min;
     rom->max     = max;
@@ -623,14 +626,16 @@ int rom_add_vga(const char *file)
 {
     if (!rom_enable_driver_roms)
         return 0;
-    return rom_add_file(file, PC_ROM_MIN_VGA, PC_ROM_MAX, PC_ROM_ALIGN);
+    return rom_add_file(file, FW_CFG_FILE_TYPE_VGABIOS,
+                        PC_ROM_MIN_VGA, PC_ROM_MAX, PC_ROM_ALIGN);
 }
 
 int rom_add_option(const char *file)
 {
     if (!rom_enable_driver_roms)
         return 0;
-    return rom_add_file(file, PC_ROM_MIN_OPTION, PC_ROM_MAX, PC_ROM_ALIGN);
+    return rom_add_file(file, FW_CFG_FILE_TYPE_OPTIONROM,
+                        PC_ROM_MIN_OPTION, PC_ROM_MAX, PC_ROM_ALIGN);
 }
 
 static void rom_reset(void *unused)
@@ -692,6 +697,18 @@ int rom_load_all(void)
     return 0;
 }
 
+int rom_load_fw(void *fw_cfg)
+{
+    Rom *rom;
+
+    QTAILQ_FOREACH(rom, &roms, next) {
+        if (!rom->type)
+            continue;
+        fw_cfg_add_file(fw_cfg, rom->type, rom->data, rom->romsize);
+    }
+    return 0;
+}
+
 static Rom *find_rom(target_phys_addr_t addr)
 {
     Rom *rom;
hw/loader.h +3 -2
index b3311a3..2de52e1 100644
@@ -19,17 +19,18 @@ void pstrcpy_targphys(const char *name,
                       target_phys_addr_t dest, int buf_size,
                       const char *source);
 
-int rom_add_file(const char *file,
+int rom_add_file(const char *file, int fw_file_type,
                  target_phys_addr_t min, target_phys_addr_t max, int align);
 int rom_add_blob(const char *name, const void *blob, size_t len,
                  target_phys_addr_t min, target_phys_addr_t max, int align);
 int rom_load_all(void);
+int rom_load_fw(void *fw_cfg);
 int rom_copy(uint8_t *dest, target_phys_addr_t addr, size_t size);
 void *rom_ptr(target_phys_addr_t addr);
 void do_info_roms(Monitor *mon);
 
 #define rom_add_file_fixed(_f, _a)              \
-    rom_add_file(_f, _a, 0, 0)
+    rom_add_file(_f, 0, _a, 0, 0)
 #define rom_add_blob_fixed(_f, _b, _l, _a)      \
     rom_add_blob(_f, _b, _l, _a, 0, 0)
 
hw/pc.c +2 -0
index 147a9a7..be70f50 100644
@@ -1248,6 +1248,8 @@ static void pc_init1(ram_addr_t ram_size,
             }
         }
     }
+
+    rom_load_fw(fw_cfg);
 }
 
 static void pc_init_pci(ram_addr_t ram_size,
Signature · 1 line
1.6.5.2
#4 lore raw
In reply to Gerd Hoffmann

Am 16.12.2009 um 18:46 schrieb Gerd Hoffmann <[email protected]>:

Quoted 6 lines

Hi,

quick draft of a file xfer api for fw_cfg, qemu side only, not tested yet, to be used for option roms.

comments?

2/3 is missing here.

How does elf rom loading come into play here? We'll need both - a firmware rom blob (openbios) and a fw_cfg rom blob for elf (multiboot).

Alex

#5 lore raw
Quoted 11 lines · Alexander Graf

Am 16.12.2009 um 18:46 schrieb Gerd Hoffmann <[email protected]>:

Quoted 6 lines

Hi,

quick draft of a file xfer api for fw_cfg, qemu side only, not tested yet, to be used for option roms.

comments?

2/3 is missing here.

Hmm, I got it via qemu-devel. Maybe it is just delayed for you.

Quoted 2 lines

How does elf rom loading come into play here? We'll need both - a
firmware rom blob (openbios) and a fw_cfg rom blob for elf (multiboot).

--verbose please

Do you talk about ppc?

Current rom loading code will stay, we can't drop it. We might be able to simplify it a bit some day when all option rom loading goes via seabios because everything but option roms will be loaded at a fixed address. But seabios itself can't be loaded via fw_cfg (chicken, egg).

cheers,
Gerd

#6 lore raw
Quoted 11 lines · Gerd Hoffmann
Quoted 10 lines · Alexander Graf

Am 16.12.2009 um 18:46 schrieb Gerd Hoffmann <[email protected]>:

Quoted 6 lines

Hi,

quick draft of a file xfer api for fw_cfg, qemu side only, not tested yet, to be used for option roms.

comments?

Quoted 8 lines
Quoted 1 line

2/3 is missing here.

Hmm, I got it via qemu-devel. Maybe it is just delayed for you.

Quoted 2 lines

How does elf rom loading come into play here? We'll need both - a
firmware rom blob (openbios) and a fw_cfg rom blob for elf (multiboot).

--verbose please

I was wondering if you were completely changing the semantics of the rom infrastructure. Currently a rom is a synonym for "load this chunk of memory on bootup".

With elf binaries, we're currently always creating "rom" chunks. What we do in the multiboot code is to take those rom chunks and put them in a fw_cfg variable.

I just wanted to make sure you're aware of that concept and don't accidently break it :-).

Quoted 8 lines

Do you talk about ppc?

Current rom loading code will stay, we can't drop it. We might be able to simplify it a bit some day when all option rom loading goes via seabios because everything but option roms will be loaded at a fixed address. But seabios itself can't be loaded via fw_cfg (chicken, egg).

Ok :-). I would've reassured myself before writing this mail, but the important patch implementing those parts is 2/3.

Alex