Skip to contentSkip to conversation

rom loading saga continued

PATCH Applied Gerd Hoffmann 2 participants 12 messages Jan 8, 2010 – Jan 12, 2010

lore
Share & tools
lore
#9 lore raw

PATCH 4/6 roms: rework rom loading via fw

In reply to Gerd Hoffmann

This patch changes the way rom loading via fw_cfg is handled. Instead of having pc_init1() call a function which passed all roms to the firmware config we simply pass a pointer to fw_cfg to the rom loader.

Advantage: loading roms via firmware works also for devices which are initialized after pc_init1(), i.e. everyting added via -device.

---
 hw/loader.c |   15 +++++----------
 hw/loader.h |    2 +-
 hw/pc.c     |    3 +--
 3 files changed, 7 insertions(+), 13 deletions(-)
hw/loader.c +5 -10
index 38ee2da..b3bbd77 100644
@@ -535,6 +535,7 @@ struct Rom {
     QTAILQ_ENTRY(Rom) next;
 };
 
+static FWCfgState *fw_cfg;
 static QTAILQ_HEAD(, Rom) roms = QTAILQ_HEAD_INITIALIZER(roms);
 int rom_enable_driver_roms;
 
@@ -592,6 +593,8 @@ int rom_add_file(const char *file, const char *fw_dir,
     }
     close(fd);
     rom_insert(rom);
+    if (rom->fw_file && fw_cfg)
+        fw_cfg_add_file(fw_cfg, rom->fw_dir, rom->fw_file, rom->data, rom->romsize);
     return 0;
 
 err:
@@ -681,17 +684,9 @@ int rom_load_all(void)
     return 0;
 }
 
-int rom_load_fw(void *fw_cfg)
+void rom_set_fw(void *f)
 {
-    Rom *rom;
-
-    QTAILQ_FOREACH(rom, &roms, next) {
-        if (!rom->fw_file) {
-            continue;
-        }
-        fw_cfg_add_file(fw_cfg, rom->fw_dir, rom->fw_file, rom->data, rom->romsize);
-    }
-    return 0;
+    fw_cfg = f;
 }
 
 static Rom *find_rom(target_phys_addr_t addr)
hw/loader.h +1 -1
index 698160b..8ff3c94 100644
@@ -25,7 +25,7 @@ int rom_add_file(const char *file, const char *fw_dir,
 int rom_add_blob(const char *name, const void *blob, size_t len,
                  target_phys_addr_t addr);
 int rom_load_all(void);
-int rom_load_fw(void *fw_cfg);
+void rom_set_fw(void *f);
 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);
hw/pc.c +1 -2
index ea5ac8e..3ed43f5 100644
@@ -1099,6 +1099,7 @@ static void pc_init1(ram_addr_t ram_size,
                                  bios_size, bios_offset | IO_MEM_ROM);
 
     fw_cfg = bochs_bios_init();
+    rom_set_fw(fw_cfg);
 
     if (linux_boot) {
         load_linux(fw_cfg, kernel_filename, initrd_filename, kernel_cmdline, below_4g_mem_size);
@@ -1259,8 +1260,6 @@ 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
#0 lore raw

cover rom loading saga continued

Hi,

Here is a patch series trying to address 0.11 compatibility issues.

First, there is a patch which adds a 0.12 machine type for the new release and fixes up the 0.11 one. Unlike the version posted yesterday as single patch it actually compiles ...

The following patches allow to load pci roms via fw_cfg interface, so no pci rom bar is added to the pci devices, making them look like they did in qemu 0.11 and older.

Finally compat properties are added to the 0.11 and 0.10 machine types.

This should get us a step closer to make 0.11 -> 0.12 migration work.

cheers,
Gerd

#7 lore raw

PATCH 2/6 roms: minor fixes and cleanups.

Changes:
- Drop extra file argument from rom_add_file().
- Drop fw_dir check in do_info_roms, we allways have a dir name.
- code style fixes.

---
 hw/loader.c |   38 +++++++++++++++++++++++---------------
 hw/loader.h |    5 +++--
 2 files changed, 26 insertions(+), 17 deletions(-)
hw/loader.c +23 -15
index 3aba47c..38ee2da 100644
@@ -556,7 +556,7 @@ static void rom_insert(Rom *rom)
     QTAILQ_INSERT_TAIL(&roms, rom, next);
 }
 
-int rom_add_file(const char *file, const char *fw_dir, const char *fw_file,
+int rom_add_file(const char *file, const char *fw_dir,
                  target_phys_addr_t addr)
 {
     Rom *rom;
@@ -576,8 +576,10 @@ int rom_add_file(const char *file, const char *fw_dir, const char *fw_file,
         goto err;
     }
 
-    rom->fw_dir  = fw_dir  ? qemu_strdup(fw_dir)  : NULL;
-    rom->fw_file = fw_file ? qemu_strdup(fw_file) : NULL;
+    if (fw_dir) {
+        rom->fw_dir  = qemu_strdup(fw_dir);
+        rom->fw_file = qemu_strdup(file);
+    }
     rom->addr    = addr;
     rom->romsize = lseek(fd, 0, SEEK_END);
     rom->data    = qemu_mallocz(rom->romsize);
@@ -621,14 +623,14 @@ int rom_add_vga(const char *file)
 {
     if (!rom_enable_driver_roms)
         return 0;
-    return rom_add_file(file, "vgaroms", file, 0);
+    return rom_add_file(file, "vgaroms", 0);
 }
 
 int rom_add_option(const char *file)
 {
     if (!rom_enable_driver_roms)
         return 0;
-    return rom_add_file(file, "genroms", file, 0);
+    return rom_add_file(file, "genroms", 0);
 }
 
 static void rom_reset(void *unused)
@@ -639,8 +641,9 @@ static void rom_reset(void *unused)
         if (rom->fw_file) {
             continue;
         }
-        if (rom->data == NULL)
+        if (rom->data == NULL) {
             continue;
+        }
         cpu_physical_memory_write_rom(rom->addr, rom->data, rom->romsize);
         if (rom->isrom) {
             /* rom needs to be written only once */
@@ -683,8 +686,9 @@ int rom_load_fw(void *fw_cfg)
     Rom *rom;
 
     QTAILQ_FOREACH(rom, &roms, next) {
-        if (!rom->fw_file)
+        if (!rom->fw_file) {
             continue;
+        }
         fw_cfg_add_file(fw_cfg, rom->fw_dir, rom->fw_file, rom->data, rom->romsize);
     }
     return 0;
@@ -698,10 +702,12 @@ static Rom *find_rom(target_phys_addr_t addr)
         if (rom->fw_file) {
             continue;
         }
-        if (rom->addr > addr)
+        if (rom->addr > addr) {
             continue;
-        if (rom->addr + rom->romsize < addr)
+        }
+        if (rom->addr + rom->romsize < addr) {
             continue;
+        }
         return rom;
     }
     return NULL;
@@ -723,12 +729,15 @@ int rom_copy(uint8_t *dest, target_phys_addr_t addr, size_t size)
         if (rom->fw_file) {
             continue;
         }
-        if (rom->addr + rom->romsize < addr)
+        if (rom->addr + rom->romsize < addr) {
             continue;
-        if (rom->addr > end)
+        }
+        if (rom->addr > end) {
             break;
-        if (!rom->data)
+        }
+        if (!rom->data) {
             continue;
+        }
 
         d = dest + (rom->addr - addr);
         s = rom->data;
@@ -771,10 +780,9 @@ void do_info_roms(Monitor *mon)
                            rom->isrom ? "rom" : "ram",
                            rom->name);
         } else {
-            monitor_printf(mon, "fw=%s%s%s"
+            monitor_printf(mon, "fw=%s/%s"
                            " size=0x%06zx name=\"%s\" \n",
-                           rom->fw_dir ? rom->fw_dir : "",
-                           rom->fw_dir ? "/" : "",
+                           rom->fw_dir,
                            rom->fw_file,
                            rom->romsize,
                            rom->name);
hw/loader.h +3 -2
index 77beb0e..698160b 100644
@@ -19,7 +19,8 @@ void pstrcpy_targphys(const char *name,
                       target_phys_addr_t dest, int buf_size,
                       const char *source);
 
-int rom_add_file(const char *file, const char *fw_dir, const char *fw_file,
+
+int rom_add_file(const char *file, const char *fw_dir,
                  target_phys_addr_t addr);
 int rom_add_blob(const char *name, const void *blob, size_t len,
                  target_phys_addr_t addr);
@@ -30,7 +31,7 @@ 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, NULL, NULL, _a)
+    rom_add_file(_f, NULL, _a)
 #define rom_add_blob_fixed(_f, _b, _l, _a)      \
     rom_add_blob(_f, _b, _l, _a)
 
Signature · 1 line
1.6.5.2
#11 lore raw

PATCH 6/6 pc: add rombar to compat properties for pc-0.10 and pc-0.11

In reply to Gerd Hoffmann

So '-M pc-0.10' and '-M pc-0.11' will use the fw_cfg rom load method by default.

---
 hw/pc.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
hw/pc.c +8 -0
index 3ed43f5..825501c 100644
@@ -1315,6 +1315,10 @@ static QEMUMachine pc_machine_v0_11 = {
             .driver   = "virtio-blk-pci",
             .property = "vectors",
             .value    = stringify(0),
+        },{
+            .driver   = "PCI",
+            .property = "rombar",
+            .value    = stringify(0),
         },
         { /* end of list */ }
     }
@@ -1342,6 +1346,10 @@ static QEMUMachine pc_machine_v0_10 = {
             .driver   = "virtio-blk-pci",
             .property = "vectors",
             .value    = stringify(0),
+        },{
+            .driver   = "PCI",
+            .property = "rombar",
+            .value    = stringify(0),
         },
         { /* end of list */ }
     },
Signature · 1 line
1.6.5.2
#1 lore raw

PATCH 1/6 pc: add machine type for 0.12

In reply to Gerd Hoffmann

Add a new machine type for qemu 0.12.

Also fixup the 0.11 machine type: msi for virtio-blk-pci was enabled after the 0.11 release, so turn it off in the 0.11 machine type.

---
 hw/pc.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
hw/pc.c +17 -1
index 83f8dd0..ea5ac8e 100644
@@ -1298,7 +1298,7 @@ void cmos_set_s3_resume(void)
 }
 
 static QEMUMachine pc_machine = {
-    .name = "pc-0.11",
+    .name = "pc-0.12",
     .alias = "pc",
     .desc = "Standard PC",
     .init = pc_init_pci,
@@ -1306,6 +1306,21 @@ static QEMUMachine pc_machine = {
     .is_default = 1,
 };
 
+static QEMUMachine pc_machine_v0_11 = {
+    .name = "pc-0.11",
+    .desc = "Standard PC, qemu 0.11",
+    .init = pc_init_pci,
+    .max_cpus = 255,
+    .compat_props = (GlobalProperty[]) {
+        {
+            .driver   = "virtio-blk-pci",
+            .property = "vectors",
+            .value    = stringify(0),
+        },
+        { /* end of list */ }
+    }
+};
+
 static QEMUMachine pc_machine_v0_10 = {
     .name = "pc-0.10",
     .desc = "Standard PC, qemu 0.10",
@@ -1343,6 +1358,7 @@ static QEMUMachine isapc_machine = {
 static void pc_machine_init(void)
 {
     qemu_register_machine(&pc_machine);
+    qemu_register_machine(&pc_machine_v0_11);
     qemu_register_machine(&pc_machine_v0_10);
     qemu_register_machine(&isapc_machine);
 }
Signature · 1 line
1.6.5.2
#10 lore raw

PATCH 5/6 pci: allow loading roms via fw_cfg.

In reply to Gerd Hoffmann

This patch adds a pci bus property 'rombar' which specifies whenever the pci rom should be loaded via pci rom bar (default) or via fw_cfg. The later can be used for compatibility with older qemu versions where no pci rom bar is present.

---
 hw/pci.c |   15 +++++++++++++++
 hw/pci.h |    1 +
 2 files changed, 16 insertions(+), 0 deletions(-)
hw/pci.c +15 -0
index 0814383..c584dba 100644
@@ -65,6 +65,7 @@ static struct BusInfo pci_bus_info = {
     .props      = (Property[]) {
         DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1),
         DEFINE_PROP_STRING("romfile", PCIDevice, romfile),
+        DEFINE_PROP_UINT32("rombar",  PCIDevice, rom_bar, 1),
         DEFINE_PROP_END_OF_LIST()
     }
 };
@@ -1477,6 +1478,20 @@ static int pci_add_option_rom(PCIDevice *pdev)
     if (strlen(pdev->romfile) == 0)
         return 0;
 
+    if (!pdev->rom_bar) {
+        /*
+         * Load rom via fw_cfg instead of creating a rom bar,
+         * for 0.11 compatibility.
+         */
+        int class = pci_get_word(pdev->config + PCI_CLASS_DEVICE);
+        if (class == 0x0300) {
+            rom_add_vga(pdev->romfile);
+        } else {
+            rom_add_option(pdev->romfile);
+        }
+        return 0;
+    }
+
     path = qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->romfile);
     if (path == NULL) {
         path = qemu_strdup(pdev->romfile);
hw/pci.h +1 -0
index fd16460..5d8bf97 100644
@@ -244,6 +244,7 @@ struct PCIDevice {
     /* Location of option rom */
     char *romfile;
     ram_addr_t rom_offset;
+    uint32_t rom_bar;
 };
 
 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
Signature · 1 line
1.6.5.2
#8 lore raw

PATCH 3/6 fw_cfg: rom loader tweaks.

In reply to Gerd Hoffmann

Changes:
- make dir argument mandatory, we allways have one anyway (vgaroms or genroms).
- check for duplicates, skip loading if found.

---
 hw/fw_cfg.c |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)
hw/fw_cfg.c +11 -7
index fe9c527..ea120ba 100644
@@ -278,7 +278,7 @@ int fw_cfg_add_file(FWCfgState *s,  const char *dir, const char *filename,
                     uint8_t *data, uint32_t len)
 {
     const char *basename;
-    int index;
+    int i, index;
 
     if (!s->files) {
         int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;
@@ -300,13 +300,17 @@ int fw_cfg_add_file(FWCfgState *s,  const char *dir, const char *filename,
     } else {
         basename = filename;
     }
-    if (dir) {
-        snprintf(s->files->f[index].name, sizeof(s->files->f[index].name),
-                 "%s/%s", dir, basename);
-    } else {
-        snprintf(s->files->f[index].name, sizeof(s->files->f[index].name),
-                 "%s", basename);
+
+    snprintf(s->files->f[index].name, sizeof(s->files->f[index].name),
+             "%s/%s", dir, basename);
+    for (i = 0; i < index; i++) {
+        if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
+            FW_CFG_DPRINTF("%s: skip duplicate: %s\n", __FUNCTION__,
+                           s->files->f[index].name);
+            return 1;
+        }
     }
+
     s->files->f[index].size   = cpu_to_be32(len);
     s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
     FW_CFG_DPRINTF("%s: #%d: %s (%d bytes)\n", __FUNCTION__,
Signature · 1 line
1.6.5.2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/6] pc: add machine type for 0.12

In reply to Gerd Hoffmann
Quoted 7 lines · Gerd Hoffmann

Add a new machine type for qemu 0.12.

Also fixup the 0.11 machine type: msi for virtio-blk-pci was enabled after the 0.11 release, so turn it off in the 0.11 machine type.

Applied all. Thanks.

Regards,

Anthony Liguori

Quoted 48 lines
---
  hw/pc.c |   18 +++++++++++++++++-
  1 files changed, 17 insertions(+), 1 deletions(-)
hw/pc.c +17 -1
index 83f8dd0..ea5ac8e 100644
@@ -1298,7 +1298,7 @@ void cmos_set_s3_resume(void)
  }
 
  static QEMUMachine pc_machine = {
-    .name = "pc-0.11",
+    .name = "pc-0.12",
      .alias = "pc",
      .desc = "Standard PC",
      .init = pc_init_pci,
@@ -1306,6 +1306,21 @@ static QEMUMachine pc_machine = {
      .is_default = 1,
  };
 
+static QEMUMachine pc_machine_v0_11 = {
+    .name = "pc-0.11",
+    .desc = "Standard PC, qemu 0.11",
+    .init = pc_init_pci,
+    .max_cpus = 255,
+    .compat_props = (GlobalProperty[]) {
+        {
+            .driver   = "virtio-blk-pci",
+            .property = "vectors",
+            .value    = stringify(0),
+        },
+        { /* end of list */ }
+    }
+};
+
  static QEMUMachine pc_machine_v0_10 = {
      .name = "pc-0.10",
      .desc = "Standard PC, qemu 0.10",
@@ -1343,6 +1358,7 @@ static QEMUMachine isapc_machine = {
  static void pc_machine_init(void)
  {
      qemu_register_machine(&pc_machine);
+    qemu_register_machine(&pc_machine_v0_11);
      qemu_register_machine(&pc_machine_v0_10);
      qemu_register_machine(&isapc_machine);
  }
#3 lore raw

Re: [Qemu-devel] [PATCH 1/6] pc: add machine type for 0.12

Quoted 9 lines · Anthony Liguori
Quoted 6 lines · Gerd Hoffmann

Add a new machine type for qemu 0.12.

Also fixup the 0.11 machine type: msi for virtio-blk-pci was enabled after the 0.11 release, so turn it off in the 0.11 machine type.

Applied all. Thanks.

Note: this is intented to be applied to 0.12 too. Forgot to mention in $subject. The series description should have made that clear though.

On a related note: Tried to check staging for stable. anthony-queue.git seems to be unused now though (last update a few weeks ago) Can you post a summary of which git trees are where right now and what is planned (transition to git.qemu.org?).

thanks,
Gerd

#4 lore raw

Re: [Qemu-devel] [PATCH 1/6] pc: add machine type for 0.12

Quoted 4 lines · Gerd Hoffmann
Quoted 3 lines · Anthony Liguori
Quoted 2 lines · Gerd Hoffmann

Add a new machine type for qemu 0.12.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Also fixup the 0.11 machine type: msi for virtio-blk-pci was enabled after the 0.11 release, so turn it off in the 0.11 machine type.

Applied all. Thanks.

Note: this is intented to be applied to 0.12 too. Forgot to mention in $subject. The series description should have made that clear though.

Thanks, I'll make sure to pull those in to stable.

Quoted 1 line

On a related note: Tried to check staging for stable. anthony-queue.git seems to be unused now though (last update a few weeks ago) Can you post a summary of which git trees are where right now and what is planned (transition to git.qemu.org?).

I'm trying something a little different. I'm using a different mechanism to track patches and trying to make sure to always push patches on a daily basis. If this works out, a staging tree won't make sense anymore. Give me a week or two to see how this works and I'll make sure to explain my new process.

Regards,

Anthony Liguori

Quoted 3 lines

thanks,
Gerd

#5 lore raw

Re: [Qemu-devel] [PATCH 1/6] pc: add machine type for 0.12

In reply to Gerd Hoffmann
Quoted 4 lines · Gerd Hoffmann
Quoted 3 lines · Anthony Liguori
Quoted 2 lines · Gerd Hoffmann

Add a new machine type for qemu 0.12.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Also fixup the 0.11 machine type: msi for virtio-blk-pci was enabled after the 0.11 release, so turn it off in the 0.11 machine type.

Applied all. Thanks.

Note: this is intented to be applied to 0.12 too. Forgot to mention in $subject. The series description should have made that clear though.

Can you rebase this series to stable and submit? I rebased myself but one of the rom loader patches didn't apply and I'm concerned we're missing a previous patch here. If you can take a look, I'd appreciate it.

Regards,

Anthony Liguori

Quoted 5 lines

On a related note: Tried to check staging for stable. anthony-queue.git seems to be unused now though (last update a few weeks ago) Can you post a summary of which git trees are where right now and what is planned (transition to git.qemu.org?).

thanks,
Gerd

#6 lore raw

Re: [Qemu-devel] [PATCH 1/6] pc: add machine type for 0.12

Quoted 3 lines · Anthony Liguori

Can you rebase this series to stable and submit? I rebased myself but one of the rom loader patches didn't apply and I'm concerned we're missing a previous patch here. If you can take a look, I'd appreciate it.

It is a missing patch indeed. After cherry-picking commit f21a59c224a6fdf7b30c3fe551fd93043e537f6c ("loader: more ignores for rom intended to be loaded by the bios" by Aurelien Jarno) the series cleanly applies to stable as-is.

cheers,
Gerd