Skip to contentSkip to conversation

Make pointer to fw_cfg device global.

PATCH In review Gleb Natapov 5 participants 17 messages May 20, 2012 – May 23, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Make pointer to fw_cfg device global.

There can be only one fw_cfg device, so saving global reference to it removes the need to pass its pointer around.

---
 hw/fw_cfg.c       |  110 +++++++++++++++++++++++++++--------------------------
 hw/fw_cfg.h       |   15 +++----
 hw/loader.c       |   10 +----
 hw/loader.h       |    1 -
 hw/multiboot.c    |   17 ++++----
 hw/multiboot.h    |    3 +-
 hw/pc.c           |   63 ++++++++++++++----------------
 hw/ppc_newworld.c |   43 ++++++++++-----------
 hw/ppc_oldworld.c |   43 ++++++++++-----------
 hw/sun4m.c        |   93 +++++++++++++++++++++-----------------------
 hw/sun4u.c        |   35 ++++++++---------
 11 files changed, 207 insertions(+), 226 deletions(-)
hw/fw_cfg.c +56 -54
index 7b3b576..8c50473 100644
@@ -48,7 +48,7 @@ typedef struct FWCfgEntry {
     FWCfgCallback callback;
 } FWCfgEntry;
 
-struct FWCfgState {
+static struct FWCfgState {
     SysBusDevice busdev;
     MemoryRegion ctl_iomem, data_iomem, comb_iomem;
     uint32_t ctl_iobase, data_iobase;
@@ -57,7 +57,7 @@ struct FWCfgState {
     uint16_t cur_entry;
     uint32_t cur_offset;
     Notifier machine_ready;
-};
+} *fw_cfg;
 
 #define JPG_FILE 0
 #define BMP_FILE 1
@@ -113,7 +113,7 @@ error:
     return NULL;
 }
 
-static void fw_cfg_bootsplash(FWCfgState *s)
+static void fw_cfg_bootsplash(void)
 {
     int boot_splash_time = -1;
     const char *boot_splash_filename = NULL;
@@ -148,7 +148,7 @@ static void fw_cfg_bootsplash(FWCfgState *s)
         /* use little endian format */
         qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time & 0xff);
         qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time >> 8) & 0xff);
-        fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
+        fw_cfg_add_file("etc/boot-menu-wait", qemu_extra_params_fw, 2);
     }
 
     /* insert splash file if user configurated */
@@ -173,10 +173,10 @@ static void fw_cfg_bootsplash(FWCfgState *s)
 
         /* insert data */
         if (file_type == JPG_FILE) {
-            fw_cfg_add_file(s, "bootsplash.jpg",
+            fw_cfg_add_file("bootsplash.jpg",
                     boot_splash_filedata, boot_splash_filedata_size);
         } else {
-            fw_cfg_add_file(s, "bootsplash.bmp",
+            fw_cfg_add_file("bootsplash.bmp",
                     boot_splash_filedata, boot_splash_filedata_size);
         }
         g_free(filename);
@@ -359,122 +359,126 @@ static const VMStateDescription vmstate_fw_cfg = {
     }
 };
 
-int fw_cfg_add_bytes(FWCfgState *s, uint16_t key, uint8_t *data, uint32_t len)
+int fw_cfg_add_bytes(uint16_t key, uint8_t *data, uint32_t len)
 {
     int arch = !!(key & FW_CFG_ARCH_LOCAL);
 
     key &= FW_CFG_ENTRY_MASK;
 
-    if (key >= FW_CFG_MAX_ENTRY)
+    if (key >= FW_CFG_MAX_ENTRY || !fw_cfg) {
         return 0;
+    }
 
-    s->entries[arch][key].data = data;
-    s->entries[arch][key].len = len;
+    fw_cfg->entries[arch][key].data = data;
+    fw_cfg->entries[arch][key].len = len;
 
     return 1;
 }
 
-int fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value)
+int fw_cfg_add_i16(uint16_t key, uint16_t value)
 {
     uint16_t *copy;
 
     copy = g_malloc(sizeof(value));
     *copy = cpu_to_le16(value);
-    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value)
+int fw_cfg_add_i32(uint16_t key, uint32_t value)
 {
     uint32_t *copy;
 
     copy = g_malloc(sizeof(value));
     *copy = cpu_to_le32(value);
-    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
+int fw_cfg_add_i64(uint16_t key, uint64_t value)
 {
     uint64_t *copy;
 
     copy = g_malloc(sizeof(value));
     *copy = cpu_to_le64(value);
-    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
+int fw_cfg_add_callback(uint16_t key, FWCfgCallback callback,
                         void *callback_opaque, uint8_t *data, size_t len)
 {
     int arch = !!(key & FW_CFG_ARCH_LOCAL);
 
-    if (!(key & FW_CFG_WRITE_CHANNEL))
+    if (!(key & FW_CFG_WRITE_CHANNEL) || !fw_cfg) {
         return 0;
+    }
 
     key &= FW_CFG_ENTRY_MASK;
 
     if (key >= FW_CFG_MAX_ENTRY || len > 65535)
         return 0;
 
-    s->entries[arch][key].data = data;
-    s->entries[arch][key].len = len;
-    s->entries[arch][key].callback_opaque = callback_opaque;
-    s->entries[arch][key].callback = callback;
+    fw_cfg->entries[arch][key].data = data;
+    fw_cfg->entries[arch][key].len = len;
+    fw_cfg->entries[arch][key].callback_opaque = callback_opaque;
+    fw_cfg->entries[arch][key].callback = callback;
 
     return 1;
 }
 
-int fw_cfg_add_file(FWCfgState *s,  const char *filename, uint8_t *data,
-                    uint32_t len)
+int fw_cfg_add_file(const char *filename, uint8_t *data, uint32_t len)
 {
     int i, index;
 
-    if (!s->files) {
+    if (!fw_cfg) {
+        return 0;
+    }
+
+    if (!fw_cfg->files) {
         int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;
-        s->files = g_malloc0(dsize);
-        fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, (uint8_t*)s->files, dsize);
+        fw_cfg->files = g_malloc0(dsize);
+        fw_cfg_add_bytes(FW_CFG_FILE_DIR, (uint8_t *)fw_cfg->files, dsize);
     }
 
-    index = be32_to_cpu(s->files->count);
+    index = be32_to_cpu(fw_cfg->files->count);
     if (index == FW_CFG_FILE_SLOTS) {
         fprintf(stderr, "fw_cfg: out of file slots\n");
         return 0;
     }
 
-    fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len);
+    fw_cfg_add_bytes(FW_CFG_FILE_FIRST + index, data, len);
 
-    pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name),
+    pstrcpy(fw_cfg->files->f[index].name, sizeof(fw_cfg->files->f[index].name),
             filename);
     for (i = 0; i < index; i++) {
-        if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
+        if (strcmp(fw_cfg->files->f[index].name, fw_cfg->files->f[i].name)
+                        == 0) {
             FW_CFG_DPRINTF("%s: skip duplicate: %s\n", __FUNCTION__,
-                           s->files->f[index].name);
+                           fw_cfg->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->files->f[index].size   = cpu_to_be32(len);
+    fw_cfg->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
     FW_CFG_DPRINTF("%s: #%d: %s (%d bytes)\n", __FUNCTION__,
-                   index, s->files->f[index].name, len);
+                   index, fw_cfg->files->f[index].name, len);
 
-    s->files->count = cpu_to_be32(index+1);
+    fw_cfg->files->count = cpu_to_be32(index+1);
     return 1;
 }
 
 static void fw_cfg_machine_ready(struct Notifier *n, void *data)
 {
     uint32_t len;
-    FWCfgState *s = container_of(n, FWCfgState, machine_ready);
     char *bootindex = get_boot_devices_list(&len);
 
-    fw_cfg_add_file(s, "bootorder", (uint8_t*)bootindex, len);
+    fw_cfg_add_file("bootorder", (uint8_t *)bootindex, len);
 }
 
-FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
-                        target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
+void fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
+                 target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
 {
     DeviceState *dev;
     SysBusDevice *d;
-    FWCfgState *s;
 
     dev = qdev_create(NULL, "fw_cfg");
     qdev_prop_set_uint32(dev, "ctl_iobase", ctl_port);
@@ -482,7 +486,7 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
     qdev_init_nofail(dev);
     d = sysbus_from_qdev(dev);
 
-    s = DO_UPCAST(FWCfgState, busdev.qdev, dev);
+    fw_cfg = DO_UPCAST(FWCfgState, busdev.qdev, dev);
 
     if (ctl_addr) {
         sysbus_mmio_map(d, 0, ctl_addr);
@@ -490,18 +494,16 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
     if (data_addr) {
         sysbus_mmio_map(d, 1, data_addr);
     }
-    fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
-    fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
-    fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
-    fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
-    fw_cfg_add_i16(s, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
-    fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
-    fw_cfg_bootsplash(s);
-
-    s->machine_ready.notify = fw_cfg_machine_ready;
-    qemu_add_machine_init_done_notifier(&s->machine_ready);
-
-    return s;
+    fw_cfg_add_bytes(FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
+    fw_cfg_add_bytes(FW_CFG_UUID, qemu_uuid, 16);
+    fw_cfg_add_i16(FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
+    fw_cfg_add_i16(FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
+    fw_cfg_add_i16(FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
+    fw_cfg_add_i16(FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
+    fw_cfg_bootsplash();
+
+    fw_cfg->machine_ready.notify = fw_cfg_machine_ready;
+    qemu_add_machine_init_done_notifier(&fw_cfg->machine_ready);
 }
 
 static int fw_cfg_init1(SysBusDevice *dev)
hw/fw_cfg.h +7 -8
index 856bf91..cdb239e 100644
@@ -54,15 +54,14 @@ typedef struct FWCfgFiles {
 typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
 
 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,
+int fw_cfg_add_bytes(uint16_t key, uint8_t *data, uint32_t len);
+int fw_cfg_add_i16(uint16_t key, uint16_t value);
+int fw_cfg_add_i32(uint16_t key, uint32_t value);
+int fw_cfg_add_i64(uint16_t key, uint64_t value);
+int fw_cfg_add_callback(uint16_t key, FWCfgCallback callback,
                         void *callback_opaque, uint8_t *data, size_t len);
-int fw_cfg_add_file(FWCfgState *s, const char *filename, uint8_t *data,
-                    uint32_t len);
-FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
+int fw_cfg_add_file(const char *filename, uint8_t *data, uint32_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);
 
 #endif /* NO_QEMU_PROTOS */
hw/loader.c +2 -8
index 415cdce..28464da 100644
@@ -543,7 +543,6 @@ struct Rom {
     QTAILQ_ENTRY(Rom) next;
 };
 
-static FWCfgState *fw_cfg;
 static QTAILQ_HEAD(, Rom) roms = QTAILQ_HEAD_INITIALIZER(roms);
 
 static void rom_insert(Rom *rom)
@@ -601,7 +600,7 @@ int rom_add_file(const char *file, const char *fw_dir,
     }
     close(fd);
     rom_insert(rom);
-    if (rom->fw_file && fw_cfg) {
+    if (rom->fw_file) {
         const char *basename;
         char fw_file_name[56];
 
@@ -613,7 +612,7 @@ int rom_add_file(const char *file, const char *fw_dir,
         }
         snprintf(fw_file_name, sizeof(fw_file_name), "%s/%s", rom->fw_dir,
                  basename);
-        fw_cfg_add_file(fw_cfg, fw_file_name, rom->data, rom->romsize);
+        fw_cfg_add_file(fw_file_name, rom->data, rom->romsize);
         snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);
     } else {
         snprintf(devpath, sizeof(devpath), "/rom@" TARGET_FMT_plx, addr);
@@ -704,11 +703,6 @@ int rom_load_all(void)
     return 0;
 }
 
-void rom_set_fw(void *f)
-{
-    fw_cfg = f;
-}
-
 static Rom *find_rom(target_phys_addr_t addr)
 {
     Rom *rom;
hw/loader.h +0 -1
index fbcaba9..c357ec4 100644
@@ -26,7 +26,6 @@ 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);
-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/multiboot.c +8 -9
index b4484a3..fd93e13 100644
@@ -124,8 +124,7 @@ static void mb_add_mod(MultibootState *s,
     s->mb_mods_count++;
 }
 
-int load_multiboot(void *fw_cfg,
-                   FILE *f,
+int load_multiboot(FILE *f,
                    const char *kernel_filename,
                    const char *initrd_filename,
                    const char *kernel_cmdline,
@@ -324,15 +323,15 @@ int load_multiboot(void *fw_cfg,
     memcpy(mb_bootinfo_data, bootinfo, sizeof(bootinfo));
 
     /* Pass variables to option rom */
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ENTRY, mh_entry_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, mh_load_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, mbs.mb_buf_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA,
+    fw_cfg_add_i32(FW_CFG_KERNEL_ENTRY, mh_entry_addr);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, mh_load_addr);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, mbs.mb_buf_size);
+    fw_cfg_add_bytes(FW_CFG_KERNEL_DATA,
                      mbs.mb_buf, mbs.mb_buf_size);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, ADDR_MBI);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, sizeof(bootinfo));
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, mb_bootinfo_data,
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, ADDR_MBI);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, sizeof(bootinfo));
+    fw_cfg_add_bytes(FW_CFG_INITRD_DATA, mb_bootinfo_data,
                      sizeof(bootinfo));
 
     option_rom[nb_option_roms].name = "multiboot.bin";
hw/multiboot.h +1 -2
index 98fb1b7..1302c55 100644
@@ -1,8 +1,7 @@
 #ifndef QEMU_MULTIBOOT_H
 #define QEMU_MULTIBOOT_H
 
-int load_multiboot(void *fw_cfg,
-                   FILE *f,
+int load_multiboot(FILE *f,
                    const char *kernel_filename,
                    const char *initrd_filename,
                    const char *kernel_cmdline,
hw/pc.c +29 -34

136 lines not on this page · raw message

hw/ppc_newworld.c +21 -22

77 lines not on this page · raw message

hw/ppc_oldworld.c +21 -22

77 lines not on this page · raw message

hw/sun4m.c +45 -48

154 lines not on this page · raw message

hw/sun4u.c +17 -18
index 517bdb8..094c07c 100644
@@ -125,7 +125,7 @@ void DMA_register_channel (int nchan,
 
 static int fw_cfg_boot_set(void *opaque, const char *boot_device)
 {
-    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
     return 0;
 }
 
@@ -802,7 +802,6 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
     qemu_irq *ivec_irqs, *pbm_irqs;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     DriveInfo *fd[MAX_FD];
-    void *fw_cfg;
 
     /* init CPUs */
     env = cpu_devinit(cpu_model, hwdef);
@@ -867,30 +866,30 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
                            graphic_width, graphic_height, graphic_depth,
                            (uint8_t *)&nd_table[0].macaddr);
 
-    fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_entry);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, hwdef->machine_id);
+    fw_cfg_add_i64(FW_CFG_KERNEL_ADDR, kernel_entry);
+    fw_cfg_add_i64(FW_CFG_KERNEL_SIZE, kernel_size);
     if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE,
                        strlen(kernel_cmdline) + 1);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+        fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                          (uint8_t*)strdup(kernel_cmdline),
                          strlen(kernel_cmdline) + 1);
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE, 0);
     }
-    fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_devices[0]);
+    fw_cfg_add_i64(FW_CFG_INITRD_ADDR, initrd_addr);
+    fw_cfg_add_i64(FW_CFG_INITRD_SIZE, initrd_size);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_devices[0]);
 
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_WIDTH, graphic_width);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_HEIGHT, graphic_height);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_DEPTH, graphic_depth);
+    fw_cfg_add_i16(FW_CFG_SPARC64_WIDTH, graphic_width);
+    fw_cfg_add_i16(FW_CFG_SPARC64_HEIGHT, graphic_height);
+    fw_cfg_add_i16(FW_CFG_SPARC64_DEPTH, graphic_depth);
 
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
 }
 
 enum {
Signature · 1 line
1.7.7.3
#1 lore raw

PATCH 2/2 Add PIIX4 properties to control PM system states.

This patch adds two things. First it allows QEMU to distinguish between regular powerdown and S4 powerdown. Later separate QMP notification will be added for S4 powerdown. Second it allows S3/S4 states to be disabled from QEMU command line. Some guests known to be broken with regards to power management, but allow to use it anyway. Using new properties management will be able to disable S3/S4 for such guests.

Supported system state are passed to a firmware using new fw_cfg file. The file contains 6 byte array. Each byte represents one system state. If byte at offset X has its MSB set it means that system state X is supported and to enter it guest should use the value from lowest 3 bits.

---
 hw/acpi.c       |    5 ++++-
 hw/acpi.h       |    2 +-
 hw/acpi_piix4.c |   16 +++++++++++++++-
 hw/vt82c686.c   |    2 +-
 4 files changed, 21 insertions(+), 4 deletions(-)
hw/acpi.c +4 -1
index 5d521e5..effc7ec 100644
@@ -370,7 +370,7 @@ void acpi_pm1_cnt_init(ACPIREGS *ar)
     qemu_register_wakeup_notifier(&ar->wakeup);
 }
 
-void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
+void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val, char s4)
 {
     ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
 
@@ -385,6 +385,9 @@ void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
             qemu_system_suspend_request();
             break;
         default:
+            if (sus_typ == s4) { /* S4 request */
+                qemu_system_shutdown_request();
+            }
             break;
         }
     }
hw/acpi.h +1 -1
index fe8cdb4..7337f41 100644
@@ -139,7 +139,7 @@ void acpi_pm1_evt_reset(ACPIREGS *ar);
 
 /* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
 void acpi_pm1_cnt_init(ACPIREGS *ar);
-void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val);
+void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val, char s4);
 void acpi_pm1_cnt_update(ACPIREGS *ar,
                          bool sci_enable, bool sci_disable);
 void acpi_pm1_cnt_reset(ACPIREGS *ar);
hw/acpi_piix4.c +15 -1
index 585da4e..883314d 100644
@@ -27,6 +27,7 @@
 #include "sysemu.h"
 #include "range.h"
 #include "ioport.h"
+#include "fw_cfg.h"
 
 //#define DEBUG
 
@@ -71,6 +72,10 @@ typedef struct PIIX4PMState {
     struct pci_status pci0_status;
     uint32_t pci0_hotplug_enable;
     uint32_t pci0_slot_device_present;
+
+    uint8_t disable_s3;
+    uint8_t disable_s4;
+    uint8_t s4_val;
 } PIIX4PMState;
 
 static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s);
@@ -123,7 +128,7 @@ static void pm_ioport_write(IORange *ioport, uint64_t addr, unsigned width,
         pm_update_sci(s);
         break;
     case 0x04:
-        acpi_pm1_cnt_write(&s->ar, val);
+        acpi_pm1_cnt_write(&s->ar, val, s->s4_val);
         break;
     default:
         break;
@@ -425,6 +430,7 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
 {
     PCIDevice *dev;
     PIIX4PMState *s;
+    uint8_t suspend[6] = {128, 0, 0, 129, 128, 128};
 
     dev = pci_create(bus, devfn, "PIIX4_PM");
     qdev_prop_set_uint32(&dev->qdev, "smb_io_base", smb_io_base);
@@ -437,11 +443,19 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
 
     qdev_init_nofail(&dev->qdev);
 
+    suspend[3] = 1 | ((!s->disable_s3) << 7);
+    suspend[4] = s->s4_val | ((!s->disable_s4) << 7);
+
+    fw_cfg_add_file("etc/system-states", g_memdup(suspend, 6), 6);
+
     return s->smb.smbus;
 }
 
 static Property piix4_pm_properties[] = {
     DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0),
+    DEFINE_PROP_UINT8("disable_s3", PIIX4PMState, disable_s3, 0),
+    DEFINE_PROP_UINT8("disable_s4", PIIX4PMState, disable_s4, 0),
+    DEFINE_PROP_UINT8("s4_val", PIIX4PMState, s4_val, 2),
     DEFINE_PROP_END_OF_LIST(),
 };
 
hw/vt82c686.c +1 -1
index 6fb7950..5d7c00c 100644
@@ -210,7 +210,7 @@ static void pm_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
         pm_update_sci(s);
         break;
     case 0x04:
-        acpi_pm1_cnt_write(&s->ar, val);
+        acpi_pm1_cnt_write(&s->ar, val, 0);
         break;
     default:
         break;
Signature · 1 line
1.7.7.3
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] Add PIIX4 properties to control PM system states.

Quoted 7 lines · Gleb Natapov

This patch adds two things. First it allows QEMU to distinguish between regular powerdown and S4 powerdown. Later separate QMP notification will be added for S4 powerdown. Second it allows S3/S4 states to be disabled from QEMU command line. Some guests known to be broken with regards to power management, but allow to use it anyway. Using new properties management will be able to disable S3/S4 for such guests.

Quoted 7 lines

Supported system state are passed to a firmware using new fw_cfg file. The file contains 6 byte array. Each byte represents one system state. If byte at offset X has its MSB set it means that system state X is supported and to enter it guest should use the value from lowest 3 bits.

I see nothing wrong in principle here except that you should use a PTR property to pass the fw_cfg object to the ACPI PM device.

Regards,

Anthony Liguori

Quoted 116 lines
---
  hw/acpi.c       |    5 ++++-
  hw/acpi.h       |    2 +-
  hw/acpi_piix4.c |   16 +++++++++++++++-
  hw/vt82c686.c   |    2 +-
  4 files changed, 21 insertions(+), 4 deletions(-)
hw/acpi.c +4 -1
index 5d521e5..effc7ec 100644
@@ -370,7 +370,7 @@ void acpi_pm1_cnt_init(ACPIREGS *ar)
      qemu_register_wakeup_notifier(&ar->wakeup);
  }
 
-void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
+void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val, char s4)
  {
      ar->pm1.cnt.cnt = val&  ~(ACPI_BITMASK_SLEEP_ENABLE);
 
@@ -385,6 +385,9 @@ void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
              qemu_system_suspend_request();
              break;
          default:
+            if (sus_typ == s4) { /* S4 request */
+                qemu_system_shutdown_request();
+            }
              break;
          }
      }
hw/acpi.h +1 -1
index fe8cdb4..7337f41 100644
@@ -139,7 +139,7 @@ void acpi_pm1_evt_reset(ACPIREGS *ar);
 
  /* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
  void acpi_pm1_cnt_init(ACPIREGS *ar);
-void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val);
+void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val, char s4);
  void acpi_pm1_cnt_update(ACPIREGS *ar,
                           bool sci_enable, bool sci_disable);
  void acpi_pm1_cnt_reset(ACPIREGS *ar);
hw/acpi_piix4.c +15 -1
index 585da4e..883314d 100644
@@ -27,6 +27,7 @@
  #include "sysemu.h"
  #include "range.h"
  #include "ioport.h"
+#include "fw_cfg.h"
 
  //#define DEBUG
 
@@ -71,6 +72,10 @@ typedef struct PIIX4PMState {
      struct pci_status pci0_status;
      uint32_t pci0_hotplug_enable;
      uint32_t pci0_slot_device_present;
+
+    uint8_t disable_s3;
+    uint8_t disable_s4;
+    uint8_t s4_val;
  } PIIX4PMState;
 
  static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s);
@@ -123,7 +128,7 @@ static void pm_ioport_write(IORange *ioport, uint64_t addr, unsigned width,
          pm_update_sci(s);
          break;
      case 0x04:
-        acpi_pm1_cnt_write(&s->ar, val);
+        acpi_pm1_cnt_write(&s->ar, val, s->s4_val);
          break;
      default:
          break;
@@ -425,6 +430,7 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
  {
      PCIDevice *dev;
      PIIX4PMState *s;
+    uint8_t suspend[6] = {128, 0, 0, 129, 128, 128};
 
      dev = pci_create(bus, devfn, "PIIX4_PM");
      qdev_prop_set_uint32(&dev->qdev, "smb_io_base", smb_io_base);
@@ -437,11 +443,19 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
 
      qdev_init_nofail(&dev->qdev);
 
+    suspend[3] = 1 | ((!s->disable_s3)<<  7);
+    suspend[4] = s->s4_val | ((!s->disable_s4)<<  7);
+
+    fw_cfg_add_file("etc/system-states", g_memdup(suspend, 6), 6);
+
      return s->smb.smbus;
  }
 
  static Property piix4_pm_properties[] = {
      DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0),
+    DEFINE_PROP_UINT8("disable_s3", PIIX4PMState, disable_s3, 0),
+    DEFINE_PROP_UINT8("disable_s4", PIIX4PMState, disable_s4, 0),
+    DEFINE_PROP_UINT8("s4_val", PIIX4PMState, s4_val, 2),
      DEFINE_PROP_END_OF_LIST(),
  };
 
hw/vt82c686.c +1 -1
index 6fb7950..5d7c00c 100644
@@ -210,7 +210,7 @@ static void pm_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
          pm_update_sci(s);
          break;
      case 0x04:
-        acpi_pm1_cnt_write(&s->ar, val);
+        acpi_pm1_cnt_write(&s->ar, val, 0);
          break;
      default:
          break;
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] Add PIIX4 properties to control PM system states.

Quoted 14 lines · Anthony Liguori
Quoted 13 lines · Gleb Natapov

This patch adds two things. First it allows QEMU to distinguish between regular powerdown and S4 powerdown. Later separate QMP notification will be added for S4 powerdown. Second it allows S3/S4 states to be disabled from QEMU command line. Some guests known to be broken with regards to power management, but allow to use it anyway. Using new properties management will be able to disable S3/S4 for such guests.

Supported system state are passed to a firmware using new fw_cfg file. The file contains 6 byte array. Each byte represents one system state. If byte at offset X has its MSB set it means that system state X is supported and to enter it guest should use the value from lowest 3 bits.

Quoted 5 lines
Quoted 1 line

I see nothing wrong in principle here except that you should use a PTR property to pass the fw_cfg object to the ACPI PM device.

Hmm, need to check that we have fw_cfg handy when the device is created. Or can I add it through global?

Quoted 107 lines

Regards,

Anthony Liguori

Quoted 103 lines
---
 hw/acpi.c       |    5 ++++-
 hw/acpi.h       |    2 +-
 hw/acpi_piix4.c |   16 +++++++++++++++-
 hw/vt82c686.c   |    2 +-
 4 files changed, 21 insertions(+), 4 deletions(-)
hw/acpi.c +4 -1
index 5d521e5..effc7ec 100644
@@ -370,7 +370,7 @@ void acpi_pm1_cnt_init(ACPIREGS *ar)
     qemu_register_wakeup_notifier(&ar->wakeup);
 }
 
-void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
+void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val, char s4)
 {
     ar->pm1.cnt.cnt = val&  ~(ACPI_BITMASK_SLEEP_ENABLE);
 
@@ -385,6 +385,9 @@ void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
             qemu_system_suspend_request();
             break;
         default:
+            if (sus_typ == s4) { /* S4 request */
+                qemu_system_shutdown_request();
+            }
             break;
         }
     }
hw/acpi.h +1 -1
index fe8cdb4..7337f41 100644
@@ -139,7 +139,7 @@ void acpi_pm1_evt_reset(ACPIREGS *ar);
 
 /* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
 void acpi_pm1_cnt_init(ACPIREGS *ar);
-void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val);
+void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val, char s4);
 void acpi_pm1_cnt_update(ACPIREGS *ar,
                          bool sci_enable, bool sci_disable);
 void acpi_pm1_cnt_reset(ACPIREGS *ar);
hw/acpi_piix4.c +15 -1
index 585da4e..883314d 100644
@@ -27,6 +27,7 @@
 #include "sysemu.h"
 #include "range.h"
 #include "ioport.h"
+#include "fw_cfg.h"
 
 //#define DEBUG
 
@@ -71,6 +72,10 @@ typedef struct PIIX4PMState {
     struct pci_status pci0_status;
     uint32_t pci0_hotplug_enable;
     uint32_t pci0_slot_device_present;
+
+    uint8_t disable_s3;
+    uint8_t disable_s4;
+    uint8_t s4_val;
 } PIIX4PMState;
 
 static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s);
@@ -123,7 +128,7 @@ static void pm_ioport_write(IORange *ioport, uint64_t addr, unsigned width,
         pm_update_sci(s);
         break;
     case 0x04:
-        acpi_pm1_cnt_write(&s->ar, val);
+        acpi_pm1_cnt_write(&s->ar, val, s->s4_val);
         break;
     default:
         break;
@@ -425,6 +430,7 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
 {
     PCIDevice *dev;
     PIIX4PMState *s;
+    uint8_t suspend[6] = {128, 0, 0, 129, 128, 128};
 
     dev = pci_create(bus, devfn, "PIIX4_PM");
     qdev_prop_set_uint32(&dev->qdev, "smb_io_base", smb_io_base);
@@ -437,11 +443,19 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
 
     qdev_init_nofail(&dev->qdev);
 
+    suspend[3] = 1 | ((!s->disable_s3)<<  7);
+    suspend[4] = s->s4_val | ((!s->disable_s4)<<  7);
+
+    fw_cfg_add_file("etc/system-states", g_memdup(suspend, 6), 6);
+
     return s->smb.smbus;
 }
 
 static Property piix4_pm_properties[] = {
     DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0),
+    DEFINE_PROP_UINT8("disable_s3", PIIX4PMState, disable_s3, 0),
+    DEFINE_PROP_UINT8("disable_s4", PIIX4PMState, disable_s4, 0),
+    DEFINE_PROP_UINT8("s4_val", PIIX4PMState, s4_val, 2),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Quoted 13 lines

hw/vt82c686.c static void pm_ioport_writew(void *opaque, uint32_t addr, uint32_t val) · line 216

Quoted 13 lines
hw/vt82c686.c +1 -1
index 6fb7950..5d7c00c 100644
@@ -210,7 +210,7 @@ static void pm_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
         pm_update_sci(s);
         break;
     case 0x04:
-        acpi_pm1_cnt_write(&s->ar, val);
+        acpi_pm1_cnt_write(&s->ar, val, 0);
         break;
     default:
         break;

--
Gleb.

#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] Add PIIX4 properties to control PM system states.

Quoted 15 lines · Gleb Natapov
Quoted 14 lines · Anthony Liguori
Quoted 13 lines · Gleb Natapov

This patch adds two things. First it allows QEMU to distinguish between regular powerdown and S4 powerdown. Later separate QMP notification will be added for S4 powerdown. Second it allows S3/S4 states to be disabled from QEMU command line. Some guests known to be broken with regards to power management, but allow to use it anyway. Using new properties management will be able to disable S3/S4 for such guests.

Supported system state are passed to a firmware using new fw_cfg file. The file contains 6 byte array. Each byte represents one system state. If byte at offset X has its MSB set it means that system state X is supported and to enter it guest should use the value from lowest 3 bits.

Quoted 6 lines
Quoted 5 lines
Quoted 1 line

I see nothing wrong in principle here except that you should use a PTR property to pass the fw_cfg object to the ACPI PM device.

Hmm, need to check that we have fw_cfg handy when the device is created.

Yes, the pc.c/pc_piix.c split needs to die...

For now, just add another output parameter to pc_memory_init to return fw_cfg. Then you can pass it to piix4_pm_init().

Regards,

Anthony Liguori

Quoted 126 lines

Or can I add it through global?

Quoted 107 lines

Regards,

Anthony Liguori

Quoted 103 lines
---
  hw/acpi.c       |    5 ++++-
  hw/acpi.h       |    2 +-
  hw/acpi_piix4.c |   16 +++++++++++++++-
  hw/vt82c686.c   |    2 +-
  4 files changed, 21 insertions(+), 4 deletions(-)
hw/acpi.c +4 -1
index 5d521e5..effc7ec 100644
@@ -370,7 +370,7 @@ void acpi_pm1_cnt_init(ACPIREGS *ar)
      qemu_register_wakeup_notifier(&ar->wakeup);
  }
 
-void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
+void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val, char s4)
  {
      ar->pm1.cnt.cnt = val&   ~(ACPI_BITMASK_SLEEP_ENABLE);
 
@@ -385,6 +385,9 @@ void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
              qemu_system_suspend_request();
              break;
          default:
+            if (sus_typ == s4) { /* S4 request */
+                qemu_system_shutdown_request();
+            }
              break;
          }
      }
hw/acpi.h +1 -1
index fe8cdb4..7337f41 100644
@@ -139,7 +139,7 @@ void acpi_pm1_evt_reset(ACPIREGS *ar);
 
  /* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
  void acpi_pm1_cnt_init(ACPIREGS *ar);
-void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val);
+void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val, char s4);
  void acpi_pm1_cnt_update(ACPIREGS *ar,
                           bool sci_enable, bool sci_disable);
  void acpi_pm1_cnt_reset(ACPIREGS *ar);
hw/acpi_piix4.c +15 -1
index 585da4e..883314d 100644
@@ -27,6 +27,7 @@
  #include "sysemu.h"
  #include "range.h"
  #include "ioport.h"
+#include "fw_cfg.h"
 
  //#define DEBUG
 
@@ -71,6 +72,10 @@ typedef struct PIIX4PMState {
      struct pci_status pci0_status;
      uint32_t pci0_hotplug_enable;
      uint32_t pci0_slot_device_present;
+
+    uint8_t disable_s3;
+    uint8_t disable_s4;
+    uint8_t s4_val;
  } PIIX4PMState;
 
  static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s);
@@ -123,7 +128,7 @@ static void pm_ioport_write(IORange *ioport, uint64_t addr, unsigned width,
          pm_update_sci(s);
          break;
      case 0x04:
-        acpi_pm1_cnt_write(&s->ar, val);
+        acpi_pm1_cnt_write(&s->ar, val, s->s4_val);
          break;
      default:
          break;
@@ -425,6 +430,7 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
  {
      PCIDevice *dev;
      PIIX4PMState *s;
+    uint8_t suspend[6] = {128, 0, 0, 129, 128, 128};
 
      dev = pci_create(bus, devfn, "PIIX4_PM");
      qdev_prop_set_uint32(&dev->qdev, "smb_io_base", smb_io_base);
@@ -437,11 +443,19 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
 
      qdev_init_nofail(&dev->qdev);
 
+    suspend[3] = 1 | ((!s->disable_s3)<<   7);
+    suspend[4] = s->s4_val | ((!s->disable_s4)<<   7);
+
+    fw_cfg_add_file("etc/system-states", g_memdup(suspend, 6), 6);
+
      return s->smb.smbus;
  }
 
  static Property piix4_pm_properties[] = {
      DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0),
+    DEFINE_PROP_UINT8("disable_s3", PIIX4PMState, disable_s3, 0),
+    DEFINE_PROP_UINT8("disable_s4", PIIX4PMState, disable_s4, 0),
+    DEFINE_PROP_UINT8("s4_val", PIIX4PMState, s4_val, 2),
      DEFINE_PROP_END_OF_LIST(),
  };
 
Quoted 13 lines

hw/vt82c686.c static void pm_ioport_writew(void *opaque, uint32_t addr, uint32_t val) · line 216

Quoted 13 lines
hw/vt82c686.c +1 -1
index 6fb7950..5d7c00c 100644
@@ -210,7 +210,7 @@ static void pm_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
          pm_update_sci(s);
          break;
      case 0x04:
-        acpi_pm1_cnt_write(&s->ar, val);
+        acpi_pm1_cnt_write(&s->ar, val, 0);
          break;
      default:
          break;

--
Gleb.

#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] Add PIIX4 properties to control PM system states.

In reply to Anthony Liguori

Am 23.05.2012 15:27, schrieb Anthony Liguori:

Quoted 14 lines · Gleb Natapov
Quoted 13 lines

This patch adds two things. First it allows QEMU to distinguish between regular powerdown and S4 powerdown. Later separate QMP notification will be added for S4 powerdown. Second it allows S3/S4 states to be disabled from QEMU command line. Some guests known to be broken with regards to power management, but allow to use it anyway. Using new properties management will be able to disable S3/S4 for such guests.

Supported system state are passed to a firmware using new fw_cfg file. The file contains 6 byte array. Each byte represents one system state. If byte at offset X has its MSB set it means that system state X is supported and to enter it guest should use the value from lowest 3 bits.

Quoted 4 lines
Quoted 1 line

I see nothing wrong in principle here except that you should use a PTR property to pass the fw_cfg object to the ACPI PM device.

Paolo was on a quest to eliminate the PTR properties so I don't think we should advocate adding any more. Without having reviewed the code, I would suggest to rather QOM'ify the fw_cfg object and to use a link<> property if needed.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] Add PIIX4 properties to control PM system states.

Il 23/05/2012 16:34, Andreas Färber ha scritto:

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

I see nothing wrong in principle here except that you should use a PTR property to pass the fw_cfg object to the ACPI PM device.

Paolo was on a quest to eliminate the PTR properties so I don't think we should advocate adding any more. Without having reviewed the code, I would suggest to rather QOM'ify the fw_cfg object and to use a link<> property if needed.

Perhaps it should be the other way round. fw_cfg gets links to all the devices it has to expose information about. In the future it could be changed to an FWCfgProvider interface.

Paolo

#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] Add PIIX4 properties to control PM system states.

Quoted 8 lines · Paolo Bonzini

Il 23/05/2012 16:34, Andreas Färber ha scritto:

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

I see nothing wrong in principle here except that you should use a PTR property to pass the fw_cfg object to the ACPI PM device.

Paolo was on a quest to eliminate the PTR properties so I don't think we should advocate adding any more. Without having reviewed the code, I would suggest to rather QOM'ify the fw_cfg object and to use a link<> property if needed.

fw_cfg is already a QOM object. I think there's enough in the tree already to do link<>s properly so that's definitely better than doing a PTR.

Quoted 4 lines

Perhaps it should be the other way round. fw_cfg gets links to all the devices it has to expose information about. In the future it could be changed to an FWCfgProvider interface.

Yes, that does make more sense.

Regards,

Anthony Liguori

Quoted 2 lines

Paolo

#8 lore raw

Re: [Qemu-devel] [PATCH 2/2] Add PIIX4 properties to control PM system states.

Quoted 5 lines · Anthony Liguori
Quoted 4 lines · Paolo Bonzini

Il 23/05/2012 16:34, Andreas Färber ha scritto:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I see nothing wrong in principle here except that you should use a PTR property to pass the fw_cfg object to the ACPI PM device.

Quoted 9 lines
Quoted 4 lines
Quoted 4 lines

Paolo was on a quest to eliminate the PTR properties so I don't think we should advocate adding any more. Without having reviewed the code, I would suggest to rather QOM'ify the fw_cfg object and to use a link<> property if needed.

fw_cfg is already a QOM object. I think there's enough in the tree already to do link<>s properly so that's definitely better than doing a PTR.

If I do what you suggested and return fw_cfg from pc_memory_init() to pass it to piix4_pm_init() I do not need any links since piix4_pm_init() is where it is used.

Quoted 5 lines
Quoted 4 lines

Perhaps it should be the other way round. fw_cfg gets links to all the devices it has to expose information about. In the future it could be changed to an FWCfgProvider interface.

Quoted 8 lines

Yes, that does make more sense.

Regards,

Anthony Liguori

Quoted 2 lines

Paolo

--
Gleb.

#9 lore raw
In reply to Gleb Natapov

Ping.

Quoted 957 lines · Gleb Natapov

There can be only one fw_cfg device, so saving global reference to it removes the need to pass its pointer around.

---
 hw/fw_cfg.c       |  110 +++++++++++++++++++++++++++--------------------------
 hw/fw_cfg.h       |   15 +++----
 hw/loader.c       |   10 +----
 hw/loader.h       |    1 -
 hw/multiboot.c    |   17 ++++----
 hw/multiboot.h    |    3 +-
 hw/pc.c           |   63 ++++++++++++++----------------
 hw/ppc_newworld.c |   43 ++++++++++-----------
 hw/ppc_oldworld.c |   43 ++++++++++-----------
 hw/sun4m.c        |   93 +++++++++++++++++++++-----------------------
 hw/sun4u.c        |   35 ++++++++---------
 11 files changed, 207 insertions(+), 226 deletions(-)
hw/fw_cfg.c +56 -54
index 7b3b576..8c50473 100644
@@ -48,7 +48,7 @@ typedef struct FWCfgEntry {
     FWCfgCallback callback;
 } FWCfgEntry;
 
-struct FWCfgState {
+static struct FWCfgState {
     SysBusDevice busdev;
     MemoryRegion ctl_iomem, data_iomem, comb_iomem;
     uint32_t ctl_iobase, data_iobase;
@@ -57,7 +57,7 @@ struct FWCfgState {
     uint16_t cur_entry;
     uint32_t cur_offset;
     Notifier machine_ready;
-};
+} *fw_cfg;
 
 #define JPG_FILE 0
 #define BMP_FILE 1
@@ -113,7 +113,7 @@ error:
     return NULL;
 }
 
-static void fw_cfg_bootsplash(FWCfgState *s)
+static void fw_cfg_bootsplash(void)
 {
     int boot_splash_time = -1;
     const char *boot_splash_filename = NULL;
@@ -148,7 +148,7 @@ static void fw_cfg_bootsplash(FWCfgState *s)
         /* use little endian format */
         qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time & 0xff);
         qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time >> 8) & 0xff);
-        fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
+        fw_cfg_add_file("etc/boot-menu-wait", qemu_extra_params_fw, 2);
     }
 
     /* insert splash file if user configurated */
@@ -173,10 +173,10 @@ static void fw_cfg_bootsplash(FWCfgState *s)
 
         /* insert data */
         if (file_type == JPG_FILE) {
-            fw_cfg_add_file(s, "bootsplash.jpg",
+            fw_cfg_add_file("bootsplash.jpg",
                     boot_splash_filedata, boot_splash_filedata_size);
         } else {
-            fw_cfg_add_file(s, "bootsplash.bmp",
+            fw_cfg_add_file("bootsplash.bmp",
                     boot_splash_filedata, boot_splash_filedata_size);
         }
         g_free(filename);
@@ -359,122 +359,126 @@ static const VMStateDescription vmstate_fw_cfg = {
     }
 };
 
-int fw_cfg_add_bytes(FWCfgState *s, uint16_t key, uint8_t *data, uint32_t len)
+int fw_cfg_add_bytes(uint16_t key, uint8_t *data, uint32_t len)
 {
     int arch = !!(key & FW_CFG_ARCH_LOCAL);
 
     key &= FW_CFG_ENTRY_MASK;
 
-    if (key >= FW_CFG_MAX_ENTRY)
+    if (key >= FW_CFG_MAX_ENTRY || !fw_cfg) {
         return 0;
+    }
 
-    s->entries[arch][key].data = data;
-    s->entries[arch][key].len = len;
+    fw_cfg->entries[arch][key].data = data;
+    fw_cfg->entries[arch][key].len = len;
 
     return 1;
 }
 
-int fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value)
+int fw_cfg_add_i16(uint16_t key, uint16_t value)
 {
     uint16_t *copy;
 
     copy = g_malloc(sizeof(value));
     *copy = cpu_to_le16(value);
-    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value)
+int fw_cfg_add_i32(uint16_t key, uint32_t value)
 {
     uint32_t *copy;
 
     copy = g_malloc(sizeof(value));
     *copy = cpu_to_le32(value);
-    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
+int fw_cfg_add_i64(uint16_t key, uint64_t value)
 {
     uint64_t *copy;
 
     copy = g_malloc(sizeof(value));
     *copy = cpu_to_le64(value);
-    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
+int fw_cfg_add_callback(uint16_t key, FWCfgCallback callback,
                         void *callback_opaque, uint8_t *data, size_t len)
 {
     int arch = !!(key & FW_CFG_ARCH_LOCAL);
 
-    if (!(key & FW_CFG_WRITE_CHANNEL))
+    if (!(key & FW_CFG_WRITE_CHANNEL) || !fw_cfg) {
         return 0;
+    }
 
     key &= FW_CFG_ENTRY_MASK;
 
     if (key >= FW_CFG_MAX_ENTRY || len > 65535)
         return 0;
 
-    s->entries[arch][key].data = data;
-    s->entries[arch][key].len = len;
-    s->entries[arch][key].callback_opaque = callback_opaque;
-    s->entries[arch][key].callback = callback;
+    fw_cfg->entries[arch][key].data = data;
+    fw_cfg->entries[arch][key].len = len;
+    fw_cfg->entries[arch][key].callback_opaque = callback_opaque;
+    fw_cfg->entries[arch][key].callback = callback;
 
     return 1;
 }
 
-int fw_cfg_add_file(FWCfgState *s,  const char *filename, uint8_t *data,
-                    uint32_t len)
+int fw_cfg_add_file(const char *filename, uint8_t *data, uint32_t len)
 {
     int i, index;
 
-    if (!s->files) {
+    if (!fw_cfg) {
+        return 0;
+    }
+
+    if (!fw_cfg->files) {
         int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;
-        s->files = g_malloc0(dsize);
-        fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, (uint8_t*)s->files, dsize);
+        fw_cfg->files = g_malloc0(dsize);
+        fw_cfg_add_bytes(FW_CFG_FILE_DIR, (uint8_t *)fw_cfg->files, dsize);
     }
 
-    index = be32_to_cpu(s->files->count);
+    index = be32_to_cpu(fw_cfg->files->count);
     if (index == FW_CFG_FILE_SLOTS) {
         fprintf(stderr, "fw_cfg: out of file slots\n");
         return 0;
     }
 
-    fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len);
+    fw_cfg_add_bytes(FW_CFG_FILE_FIRST + index, data, len);
 
-    pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name),
+    pstrcpy(fw_cfg->files->f[index].name, sizeof(fw_cfg->files->f[index].name),
             filename);
     for (i = 0; i < index; i++) {
-        if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
+        if (strcmp(fw_cfg->files->f[index].name, fw_cfg->files->f[i].name)
+                        == 0) {
             FW_CFG_DPRINTF("%s: skip duplicate: %s\n", __FUNCTION__,
-                           s->files->f[index].name);
+                           fw_cfg->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->files->f[index].size   = cpu_to_be32(len);
+    fw_cfg->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
     FW_CFG_DPRINTF("%s: #%d: %s (%d bytes)\n", __FUNCTION__,
-                   index, s->files->f[index].name, len);
+                   index, fw_cfg->files->f[index].name, len);
 
-    s->files->count = cpu_to_be32(index+1);
+    fw_cfg->files->count = cpu_to_be32(index+1);
     return 1;
 }
 
 static void fw_cfg_machine_ready(struct Notifier *n, void *data)
 {
     uint32_t len;
-    FWCfgState *s = container_of(n, FWCfgState, machine_ready);
     char *bootindex = get_boot_devices_list(&len);
 
-    fw_cfg_add_file(s, "bootorder", (uint8_t*)bootindex, len);
+    fw_cfg_add_file("bootorder", (uint8_t *)bootindex, len);
 }
 
-FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
-                        target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
+void fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
+                 target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
 {
     DeviceState *dev;
     SysBusDevice *d;
-    FWCfgState *s;
 
     dev = qdev_create(NULL, "fw_cfg");
     qdev_prop_set_uint32(dev, "ctl_iobase", ctl_port);
@@ -482,7 +486,7 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
     qdev_init_nofail(dev);
     d = sysbus_from_qdev(dev);
 
-    s = DO_UPCAST(FWCfgState, busdev.qdev, dev);
+    fw_cfg = DO_UPCAST(FWCfgState, busdev.qdev, dev);
 
     if (ctl_addr) {
         sysbus_mmio_map(d, 0, ctl_addr);
@@ -490,18 +494,16 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
     if (data_addr) {
         sysbus_mmio_map(d, 1, data_addr);
     }
-    fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
-    fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
-    fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
-    fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
-    fw_cfg_add_i16(s, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
-    fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
-    fw_cfg_bootsplash(s);
-
-    s->machine_ready.notify = fw_cfg_machine_ready;
-    qemu_add_machine_init_done_notifier(&s->machine_ready);
-
-    return s;
+    fw_cfg_add_bytes(FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
+    fw_cfg_add_bytes(FW_CFG_UUID, qemu_uuid, 16);
+    fw_cfg_add_i16(FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
+    fw_cfg_add_i16(FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
+    fw_cfg_add_i16(FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
+    fw_cfg_add_i16(FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
+    fw_cfg_bootsplash();
+
+    fw_cfg->machine_ready.notify = fw_cfg_machine_ready;
+    qemu_add_machine_init_done_notifier(&fw_cfg->machine_ready);
 }
 
 static int fw_cfg_init1(SysBusDevice *dev)
hw/fw_cfg.h +7 -8
index 856bf91..cdb239e 100644
@@ -54,15 +54,14 @@ typedef struct FWCfgFiles {
 typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
 
 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,
+int fw_cfg_add_bytes(uint16_t key, uint8_t *data, uint32_t len);
+int fw_cfg_add_i16(uint16_t key, uint16_t value);
+int fw_cfg_add_i32(uint16_t key, uint32_t value);
+int fw_cfg_add_i64(uint16_t key, uint64_t value);
+int fw_cfg_add_callback(uint16_t key, FWCfgCallback callback,
                         void *callback_opaque, uint8_t *data, size_t len);
-int fw_cfg_add_file(FWCfgState *s, const char *filename, uint8_t *data,
-                    uint32_t len);
-FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
+int fw_cfg_add_file(const char *filename, uint8_t *data, uint32_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);
 
 #endif /* NO_QEMU_PROTOS */
hw/loader.c +2 -8
index 415cdce..28464da 100644
@@ -543,7 +543,6 @@ struct Rom {
     QTAILQ_ENTRY(Rom) next;
 };
 
-static FWCfgState *fw_cfg;
 static QTAILQ_HEAD(, Rom) roms = QTAILQ_HEAD_INITIALIZER(roms);
 
 static void rom_insert(Rom *rom)
@@ -601,7 +600,7 @@ int rom_add_file(const char *file, const char *fw_dir,
     }
     close(fd);
     rom_insert(rom);
-    if (rom->fw_file && fw_cfg) {
+    if (rom->fw_file) {
         const char *basename;
         char fw_file_name[56];
 
@@ -613,7 +612,7 @@ int rom_add_file(const char *file, const char *fw_dir,
         }
         snprintf(fw_file_name, sizeof(fw_file_name), "%s/%s", rom->fw_dir,
                  basename);
-        fw_cfg_add_file(fw_cfg, fw_file_name, rom->data, rom->romsize);
+        fw_cfg_add_file(fw_file_name, rom->data, rom->romsize);
         snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);
     } else {
         snprintf(devpath, sizeof(devpath), "/rom@" TARGET_FMT_plx, addr);
@@ -704,11 +703,6 @@ int rom_load_all(void)
     return 0;
 }
 
-void rom_set_fw(void *f)
-{
-    fw_cfg = f;
-}
-
 static Rom *find_rom(target_phys_addr_t addr)
 {
     Rom *rom;
hw/loader.h +0 -1
index fbcaba9..c357ec4 100644
@@ -26,7 +26,6 @@ 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);
-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/multiboot.c +8 -9
index b4484a3..fd93e13 100644
@@ -124,8 +124,7 @@ static void mb_add_mod(MultibootState *s,
     s->mb_mods_count++;
 }
 
-int load_multiboot(void *fw_cfg,
-                   FILE *f,
+int load_multiboot(FILE *f,
                    const char *kernel_filename,
                    const char *initrd_filename,
                    const char *kernel_cmdline,
@@ -324,15 +323,15 @@ int load_multiboot(void *fw_cfg,
     memcpy(mb_bootinfo_data, bootinfo, sizeof(bootinfo));
 
     /* Pass variables to option rom */
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ENTRY, mh_entry_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, mh_load_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, mbs.mb_buf_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA,
+    fw_cfg_add_i32(FW_CFG_KERNEL_ENTRY, mh_entry_addr);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, mh_load_addr);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, mbs.mb_buf_size);
+    fw_cfg_add_bytes(FW_CFG_KERNEL_DATA,
                      mbs.mb_buf, mbs.mb_buf_size);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, ADDR_MBI);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, sizeof(bootinfo));
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, mb_bootinfo_data,
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, ADDR_MBI);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, sizeof(bootinfo));
+    fw_cfg_add_bytes(FW_CFG_INITRD_DATA, mb_bootinfo_data,
                      sizeof(bootinfo));
 
     option_rom[nb_option_roms].name = "multiboot.bin";
hw/multiboot.h +1 -2
index 98fb1b7..1302c55 100644
@@ -1,8 +1,7 @@
 #ifndef QEMU_MULTIBOOT_H
 #define QEMU_MULTIBOOT_H
 
-int load_multiboot(void *fw_cfg,
-                   FILE *f,
+int load_multiboot(FILE *f,
                    const char *kernel_filename,
                    const char *initrd_filename,
                    const char *kernel_cmdline,
hw/pc.c +29 -34
index 4d34a33..739e4ad 100644
@@ -593,9 +593,8 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
     return index;
 }
 
-static void *bochs_bios_init(void)
+static void bochs_bios_init(void)
 {
-    void *fw_cfg;
     uint8_t *smbios_table;
     size_t smbios_len;
     uint64_t *numa_fw_cfg;
@@ -613,22 +612,21 @@ static void *bochs_bios_init(void)
     register_ioport_write(0x500, 1, 1, bochs_bios_write, NULL);
     register_ioport_write(0x503, 1, 1, bochs_bios_write, NULL);
 
-    fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
+    fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_ACPI_TABLES, (uint8_t *)acpi_tables,
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_bytes(FW_CFG_ACPI_TABLES, (uint8_t *)acpi_tables,
                      acpi_tables_len);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_IRQ0_OVERRIDE, kvm_allows_irq0_override());
+    fw_cfg_add_i32(FW_CFG_IRQ0_OVERRIDE, kvm_allows_irq0_override());
 
     smbios_table = smbios_get_table(&smbios_len);
     if (smbios_table)
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES,
-                         smbios_table, smbios_len);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, (uint8_t *)&e820_table,
+        fw_cfg_add_bytes(FW_CFG_SMBIOS_ENTRIES, smbios_table, smbios_len);
+    fw_cfg_add_bytes(FW_CFG_E820_TABLE, (uint8_t *)&e820_table,
                      sizeof(struct e820_table));
 
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_HPET, (uint8_t *)&hpet_cfg,
+    fw_cfg_add_bytes(FW_CFG_HPET, (uint8_t *)&hpet_cfg,
                      sizeof(struct hpet_fw_config));
     /* allocate memory for the NUMA channel: one (64bit) word for the number
      * of nodes, one word for each VCPU->node and one word for each node to
@@ -647,10 +645,8 @@ static void *bochs_bios_init(void)
     for (i = 0; i < nb_numa_nodes; i++) {
         numa_fw_cfg[max_cpus + 1 + i] = cpu_to_le64(node_mem[i]);
     }
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, (uint8_t *)numa_fw_cfg,
+    fw_cfg_add_bytes(FW_CFG_NUMA, (uint8_t *)numa_fw_cfg,
                      (1 + max_cpus + nb_numa_nodes) * 8);
-
-    return fw_cfg;
 }
 
 static long get_file_size(FILE *f)
@@ -667,8 +663,7 @@ static long get_file_size(FILE *f)
     return size;
 }
 
-static void load_linux(void *fw_cfg,
-                       const char *kernel_filename,
+static void load_linux(const char *kernel_filename,
 		       const char *initrd_filename,
 		       const char *kernel_cmdline,
                        target_phys_addr_t max_ram_size)
@@ -703,9 +698,10 @@ static void load_linux(void *fw_cfg,
     else {
 	/* This looks like a multiboot kernel. If it is, let's stop
 	   treating it like a Linux kernel. */
-        if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
-                           kernel_cmdline, kernel_size, header))
+        if (load_multiboot(f, kernel_filename, initrd_filename,
+                           kernel_cmdline, kernel_size, header)) {
             return;
+        }
 	protocol = 0;
     }
 
@@ -745,9 +741,9 @@ static void load_linux(void *fw_cfg,
     if (initrd_max >= max_ram_size-ACPI_DATA_SIZE)
     	initrd_max = max_ram_size-ACPI_DATA_SIZE-1;
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline)+1);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+    fw_cfg_add_i32(FW_CFG_CMDLINE_ADDR, cmdline_addr);
+    fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline)+1);
+    fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                      (uint8_t*)strdup(kernel_cmdline),
                      strlen(kernel_cmdline)+1);
 
@@ -808,9 +804,9 @@ static void load_linux(void *fw_cfg,
         initrd_data = g_malloc(initrd_size);
         load_image(initrd_filename, initrd_data);
 
-        fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, initrd_size);
+        fw_cfg_add_i32(FW_CFG_INITRD_ADDR, initrd_addr);
+        fw_cfg_add_i32(FW_CFG_INITRD_SIZE, initrd_size);
+        fw_cfg_add_bytes(FW_CFG_INITRD_DATA, initrd_data, initrd_size);
 
 	stl_p(header+0x218, initrd_addr);
 	stl_p(header+0x21c, initrd_size);
@@ -837,13 +833,13 @@ static void load_linux(void *fw_cfg,
     fclose(f);
     memcpy(setup, header, MIN(sizeof(header), setup_size));
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, prot_addr);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_add_bytes(FW_CFG_KERNEL_DATA, kernel, kernel_size);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size);
+    fw_cfg_add_i32(FW_CFG_SETUP_ADDR, real_addr);
+    fw_cfg_add_i32(FW_CFG_SETUP_SIZE, setup_size);
+    fw_cfg_add_bytes(FW_CFG_SETUP_DATA, setup, setup_size);
 
     option_rom[nb_option_roms].name = "linuxboot.bin";
     option_rom[nb_option_roms].bootindex = 0;
@@ -987,7 +983,6 @@ void pc_memory_init(MemoryRegion *system_memory,
     int linux_boot, i;
     MemoryRegion *ram, *option_rom_mr;
     MemoryRegion *ram_below_4g, *ram_above_4g;
-    void *fw_cfg;
 
     linux_boot = (kernel_filename != NULL);
 
@@ -1024,11 +1019,11 @@ void pc_memory_init(MemoryRegion *system_memory,
                                         option_rom_mr,
                                         1);
 
-    fw_cfg = bochs_bios_init();
-    rom_set_fw(fw_cfg);
+    bochs_bios_init();
 
     if (linux_boot) {
-        load_linux(fw_cfg, kernel_filename, initrd_filename, kernel_cmdline, below_4g_mem_size);
+        load_linux(kernel_filename, initrd_filename, kernel_cmdline,
+                   below_4g_mem_size);
     }
 
     for (i = 0; i < nb_option_roms; i++) {
hw/ppc_newworld.c +21 -22
index 8796510..1f2a30e 100644
@@ -107,7 +107,7 @@ static const MemoryRegionOps unin_ops = {
 
 static int fw_cfg_boot_set(void *opaque, const char *boot_device)
 {
-    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
     return 0;
 }
 
@@ -152,7 +152,6 @@ static void ppc_core99_init (ram_addr_t ram_size,
     MemoryRegion *ide_mem[3];
     int ppc_boot_device;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
-    void *fw_cfg;
     void *dbdma;
     int machine_arch;
 
@@ -377,42 +376,42 @@ static void ppc_core99_init (ram_addr_t ram_size,
     macio_nvram_setup_bar(nvr, get_system_memory(), 0xFFF04000);
     /* No PCI init: the BIOS will do it */
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, machine_arch);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, machine_arch);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, kernel_base);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
     if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, cmdline_base);
         pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline);
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
     }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, initrd_base);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, initrd_size);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, ppc_boot_device);
 
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth);
+    fw_cfg_add_i16(FW_CFG_PPC_WIDTH, graphic_width);
+    fw_cfg_add_i16(FW_CFG_PPC_HEIGHT, graphic_height);
+    fw_cfg_add_i16(FW_CFG_PPC_DEPTH, graphic_depth);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled());
+    fw_cfg_add_i32(FW_CFG_PPC_IS_KVM, kvm_enabled());
     if (kvm_enabled()) {
 #ifdef CONFIG_KVM
         uint8_t *hypercall;
 
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq());
+        fw_cfg_add_i32(FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq());
         hypercall = g_malloc(16);
         kvmppc_get_hypercall(env, hypercall, 16);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid());
+        fw_cfg_add_bytes(FW_CFG_PPC_KVM_HC, hypercall, 16);
+        fw_cfg_add_i32(FW_CFG_PPC_KVM_PID, getpid());
 #endif
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, get_ticks_per_sec());
+        fw_cfg_add_i32(FW_CFG_PPC_TBFREQ, get_ticks_per_sec());
     }
 
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
 }
 
 static QEMUMachine core99_machine = {
hw/ppc_oldworld.c +21 -22
index 7e73d37..575fe59 100644
@@ -50,7 +50,7 @@
 
 static int fw_cfg_boot_set(void *opaque, const char *boot_device)
 {
-    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
     return 0;
 }
 
@@ -95,7 +95,6 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
     MemoryRegion *escc_mem, *escc_bar = g_new(MemoryRegion, 1), *ide_mem[2];
     uint16_t ppc_boot_device;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
-    void *fw_cfg;
     void *dbdma;
 
     linux_boot = (kernel_filename != NULL);
@@ -292,42 +291,42 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
 
     /* No PCI init: the BIOS will do it */
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, ARCH_HEATHROW);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, kernel_base);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
     if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, cmdline_base);
         pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline);
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
     }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, initrd_base);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, initrd_size);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, ppc_boot_device);
 
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth);
+    fw_cfg_add_i16(FW_CFG_PPC_WIDTH, graphic_width);
+    fw_cfg_add_i16(FW_CFG_PPC_HEIGHT, graphic_height);
+    fw_cfg_add_i16(FW_CFG_PPC_DEPTH, graphic_depth);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled());
+    fw_cfg_add_i32(FW_CFG_PPC_IS_KVM, kvm_enabled());
     if (kvm_enabled()) {
 #ifdef CONFIG_KVM
         uint8_t *hypercall;
 
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq());
+        fw_cfg_add_i32(FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq());
         hypercall = g_malloc(16);
         kvmppc_get_hypercall(env, hypercall, 16);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid());
+        fw_cfg_add_bytes(FW_CFG_PPC_KVM_HC, hypercall, 16);
+        fw_cfg_add_i32(FW_CFG_PPC_KVM_PID, getpid());
 #endif
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, get_ticks_per_sec());
+        fw_cfg_add_i32(FW_CFG_PPC_TBFREQ, get_ticks_per_sec());
     }
 
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
 }
 
 static QEMUMachine heathrow_machine = {
hw/sun4m.c +45 -48
index 34088ad..9f546d6 100644
@@ -163,7 +163,7 @@ void DMA_register_channel (int nchan,
 
 static int fw_cfg_boot_set(void *opaque, const char *boot_device)
 {
-    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
     return 0;
 }
 
@@ -843,7 +843,6 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
     qemu_irq *cpu_halt;
     unsigned long kernel_size;
     DriveInfo *fd[MAX_FD];
-    void *fw_cfg;
     unsigned int num_vsimms;
 
     /* init CPUs */
@@ -995,29 +994,29 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
         ecc_init(hwdef->ecc_base, slavio_irq[28],
                  hwdef->ecc_version);
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, hwdef->machine_id);
+    fw_cfg_add_i16(FW_CFG_SUN4M_DEPTH, graphic_depth);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
     if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
         pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+        fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                          (uint8_t*)strdup(kernel_cmdline),
                          strlen(kernel_cmdline) + 1);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE,
                        strlen(kernel_cmdline) + 1);
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE, 0);
     }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, 0); /* not used */
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
 }
 
 enum {
@@ -1525,7 +1524,6 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
         espdma_irq, ledma_irq;
     qemu_irq esp_reset, dma_enable;
     unsigned long kernel_size;
-    void *fw_cfg;
     DeviceState *dev;
 
     /* init CPUs */
@@ -1606,26 +1604,26 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
                graphic_height, graphic_depth, hwdef->nvram_machine_id,
                "Sun4d");
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, hwdef->machine_id);
+    fw_cfg_add_i16(FW_CFG_SUN4M_DEPTH, graphic_depth);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
     if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
         pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+        fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                          (uint8_t*)strdup(kernel_cmdline),
                          strlen(kernel_cmdline) + 1);
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
     }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, 0); /* not used */
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
 }
 
 /* SPARCserver 1000 hardware initialisation */
@@ -1719,7 +1717,6 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
     qemu_irq fdc_tc;
     unsigned long kernel_size;
     DriveInfo *fd[MAX_FD];
-    void *fw_cfg;
     DeviceState *dev;
     unsigned int i;
 
@@ -1798,26 +1795,26 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
                graphic_height, graphic_depth, hwdef->nvram_machine_id,
                "Sun4c");
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, hwdef->machine_id);
+    fw_cfg_add_i16(FW_CFG_SUN4M_DEPTH, graphic_depth);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
     if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
         pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+        fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                          (uint8_t*)strdup(kernel_cmdline),
                          strlen(kernel_cmdline) + 1);
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
     }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, 0); /* not used */
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
 }
 
 /* SPARCstation 2 hardware initialisation */
hw/sun4u.c +17 -18
index 517bdb8..094c07c 100644
@@ -125,7 +125,7 @@ void DMA_register_channel (int nchan,
 
 static int fw_cfg_boot_set(void *opaque, const char *boot_device)
 {
-    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
     return 0;
 }
 
@@ -802,7 +802,6 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
     qemu_irq *ivec_irqs, *pbm_irqs;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     DriveInfo *fd[MAX_FD];
-    void *fw_cfg;
 
     /* init CPUs */
     env = cpu_devinit(cpu_model, hwdef);
@@ -867,30 +866,30 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
                            graphic_width, graphic_height, graphic_depth,
                            (uint8_t *)&nd_table[0].macaddr);
 
-    fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_entry);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, hwdef->machine_id);
+    fw_cfg_add_i64(FW_CFG_KERNEL_ADDR, kernel_entry);
+    fw_cfg_add_i64(FW_CFG_KERNEL_SIZE, kernel_size);
     if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE,
                        strlen(kernel_cmdline) + 1);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+        fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                          (uint8_t*)strdup(kernel_cmdline),
                          strlen(kernel_cmdline) + 1);
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE, 0);
     }
-    fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_devices[0]);
+    fw_cfg_add_i64(FW_CFG_INITRD_ADDR, initrd_addr);
+    fw_cfg_add_i64(FW_CFG_INITRD_SIZE, initrd_size);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_devices[0]);
 
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_WIDTH, graphic_width);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_HEIGHT, graphic_height);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_DEPTH, graphic_depth);
+    fw_cfg_add_i16(FW_CFG_SPARC64_WIDTH, graphic_width);
+    fw_cfg_add_i16(FW_CFG_SPARC64_HEIGHT, graphic_height);
+    fw_cfg_add_i16(FW_CFG_SPARC64_DEPTH, graphic_depth);
 
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
 }
 
 enum {
Signature · 1 line
1.7.7.3

--
Gleb.

#10 lore raw
Quoted 1 line · Gleb Natapov

Ping.

I don't understand why you're pinging.. The patch has just been on the list for a couple of days and is definitely not a 1.1 candidate. Am I missing something?

However...

Quoted 40 lines · Gleb Natapov
Quoted 38 lines

There can be only one fw_cfg device, so saving global reference to it removes the need to pass its pointer around.

---
  hw/fw_cfg.c       |  110 +++++++++++++++++++++++++++--------------------------
  hw/fw_cfg.h       |   15 +++----
  hw/loader.c       |   10 +----
  hw/loader.h       |    1 -
  hw/multiboot.c    |   17 ++++----
  hw/multiboot.h    |    3 +-
  hw/pc.c           |   63 ++++++++++++++----------------
  hw/ppc_newworld.c |   43 ++++++++++-----------
  hw/ppc_oldworld.c |   43 ++++++++++-----------
  hw/sun4m.c        |   93 +++++++++++++++++++++-----------------------
  hw/sun4u.c        |   35 ++++++++---------
  11 files changed, 207 insertions(+), 226 deletions(-)
hw/fw_cfg.c +2 -2
index 7b3b576..8c50473 100644
@@ -48,7 +48,7 @@ typedef struct FWCfgEntry {
      FWCfgCallback callback;
  } FWCfgEntry;
 
-struct FWCfgState {
+static struct FWCfgState {
      SysBusDevice busdev;
      MemoryRegion ctl_iomem, data_iomem, comb_iomem;
      uint32_t ctl_iobase, data_iobase;
@@ -57,7 +57,7 @@ struct FWCfgState {
      uint16_t cur_entry;
      uint32_t cur_offset;
      Notifier machine_ready;
-};
+} *fw_cfg;
 
Quoted 7 lines

hw/fw_cfg.c error: · line 116

Quoted 7 lines
hw/fw_cfg.c +0 -1
  #define JPG_FILE 0
  #define BMP_FILE 1
@@ -113,7 +113,7 @@ error:
      return NULL;
  }
 
-static void fw_cfg_bootsplash(FWCfgState *s)

This is a step backwards IMHO. Relying on global state is generally a bad thing. Passing around pointers is a good thing because it forces you to think about the relationships between devices and makes it hard to do silly things (like have random interactions with fw_cfg in devices that have no business doing that).

Regards,

Anthony Liguori

Quoted 915 lines
Quoted 910 lines
hw/fw_cfg.c +54 -51
+static void fw_cfg_bootsplash(void)
  {
      int boot_splash_time = -1;
      const char *boot_splash_filename = NULL;
@@ -148,7 +148,7 @@ static void fw_cfg_bootsplash(FWCfgState *s)
          /* use little endian format */
          qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time&  0xff);
          qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time>>  8)&  0xff);
-        fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
+        fw_cfg_add_file("etc/boot-menu-wait", qemu_extra_params_fw, 2);
      }
 
      /* insert splash file if user configurated */
@@ -173,10 +173,10 @@ static void fw_cfg_bootsplash(FWCfgState *s)
 
          /* insert data */
          if (file_type == JPG_FILE) {
-            fw_cfg_add_file(s, "bootsplash.jpg",
+            fw_cfg_add_file("bootsplash.jpg",
                      boot_splash_filedata, boot_splash_filedata_size);
          } else {
-            fw_cfg_add_file(s, "bootsplash.bmp",
+            fw_cfg_add_file("bootsplash.bmp",
                      boot_splash_filedata, boot_splash_filedata_size);
          }
          g_free(filename);
@@ -359,122 +359,126 @@ static const VMStateDescription vmstate_fw_cfg = {
      }
  };
 
-int fw_cfg_add_bytes(FWCfgState *s, uint16_t key, uint8_t *data, uint32_t len)
+int fw_cfg_add_bytes(uint16_t key, uint8_t *data, uint32_t len)
  {
      int arch = !!(key&  FW_CFG_ARCH_LOCAL);
 
      key&= FW_CFG_ENTRY_MASK;
 
-    if (key>= FW_CFG_MAX_ENTRY)
+    if (key>= FW_CFG_MAX_ENTRY || !fw_cfg) {
          return 0;
+    }
 
-    s->entries[arch][key].data = data;
-    s->entries[arch][key].len = len;
+    fw_cfg->entries[arch][key].data = data;
+    fw_cfg->entries[arch][key].len = len;
 
      return 1;
  }
 
-int fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value)
+int fw_cfg_add_i16(uint16_t key, uint16_t value)
  {
      uint16_t *copy;
 
      copy = g_malloc(sizeof(value));
      *copy = cpu_to_le16(value);
-    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(key, (uint8_t *)copy, sizeof(value));
  }
 
-int fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value)
+int fw_cfg_add_i32(uint16_t key, uint32_t value)
  {
      uint32_t *copy;
 
      copy = g_malloc(sizeof(value));
      *copy = cpu_to_le32(value);
-    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(key, (uint8_t *)copy, sizeof(value));
  }
 
-int fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
+int fw_cfg_add_i64(uint16_t key, uint64_t value)
  {
      uint64_t *copy;
 
      copy = g_malloc(sizeof(value));
      *copy = cpu_to_le64(value);
-    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(key, (uint8_t *)copy, sizeof(value));
  }
 
-int fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
+int fw_cfg_add_callback(uint16_t key, FWCfgCallback callback,
                          void *callback_opaque, uint8_t *data, size_t len)
  {
      int arch = !!(key&  FW_CFG_ARCH_LOCAL);
 
-    if (!(key&  FW_CFG_WRITE_CHANNEL))
+    if (!(key&  FW_CFG_WRITE_CHANNEL) || !fw_cfg) {
          return 0;
+    }
 
      key&= FW_CFG_ENTRY_MASK;
 
      if (key>= FW_CFG_MAX_ENTRY || len>  65535)
          return 0;
 
-    s->entries[arch][key].data = data;
-    s->entries[arch][key].len = len;
-    s->entries[arch][key].callback_opaque = callback_opaque;
-    s->entries[arch][key].callback = callback;
+    fw_cfg->entries[arch][key].data = data;
+    fw_cfg->entries[arch][key].len = len;
+    fw_cfg->entries[arch][key].callback_opaque = callback_opaque;
+    fw_cfg->entries[arch][key].callback = callback;
 
      return 1;
  }
 
-int fw_cfg_add_file(FWCfgState *s,  const char *filename, uint8_t *data,
-                    uint32_t len)
+int fw_cfg_add_file(const char *filename, uint8_t *data, uint32_t len)
  {
      int i, index;
 
-    if (!s->files) {
+    if (!fw_cfg) {
+        return 0;
+    }
+
+    if (!fw_cfg->files) {
          int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;
-        s->files = g_malloc0(dsize);
-        fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, (uint8_t*)s->files, dsize);
+        fw_cfg->files = g_malloc0(dsize);
+        fw_cfg_add_bytes(FW_CFG_FILE_DIR, (uint8_t *)fw_cfg->files, dsize);
      }
 
-    index = be32_to_cpu(s->files->count);
+    index = be32_to_cpu(fw_cfg->files->count);
      if (index == FW_CFG_FILE_SLOTS) {
          fprintf(stderr, "fw_cfg: out of file slots\n");
          return 0;
      }
 
-    fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len);
+    fw_cfg_add_bytes(FW_CFG_FILE_FIRST + index, data, len);
 
-    pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name),
+    pstrcpy(fw_cfg->files->f[index].name, sizeof(fw_cfg->files->f[index].name),
              filename);
      for (i = 0; i<  index; i++) {
-        if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
+        if (strcmp(fw_cfg->files->f[index].name, fw_cfg->files->f[i].name)
+                        == 0) {
              FW_CFG_DPRINTF("%s: skip duplicate: %s\n", __FUNCTION__,
-                           s->files->f[index].name);
+                           fw_cfg->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->files->f[index].size   = cpu_to_be32(len);
+    fw_cfg->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
      FW_CFG_DPRINTF("%s: #%d: %s (%d bytes)\n", __FUNCTION__,
-                   index, s->files->f[index].name, len);
+                   index, fw_cfg->files->f[index].name, len);
 
-    s->files->count = cpu_to_be32(index+1);
+    fw_cfg->files->count = cpu_to_be32(index+1);
      return 1;
  }
 
  static void fw_cfg_machine_ready(struct Notifier *n, void *data)
  {
      uint32_t len;
-    FWCfgState *s = container_of(n, FWCfgState, machine_ready);
      char *bootindex = get_boot_devices_list(&len);
 
-    fw_cfg_add_file(s, "bootorder", (uint8_t*)bootindex, len);
+    fw_cfg_add_file("bootorder", (uint8_t *)bootindex, len);
  }
 
-FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
-                        target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
+void fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
+                 target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
  {
      DeviceState *dev;
      SysBusDevice *d;
-    FWCfgState *s;
 
      dev = qdev_create(NULL, "fw_cfg");
      qdev_prop_set_uint32(dev, "ctl_iobase", ctl_port);
@@ -482,7 +486,7 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
      qdev_init_nofail(dev);
      d = sysbus_from_qdev(dev);
 
-    s = DO_UPCAST(FWCfgState, busdev.qdev, dev);
+    fw_cfg = DO_UPCAST(FWCfgState, busdev.qdev, dev);
 
      if (ctl_addr) {
          sysbus_mmio_map(d, 0, ctl_addr);
@@ -490,18 +494,16 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
      if (data_addr) {
          sysbus_mmio_map(d, 1, data_addr);
      }
-    fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
-    fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
-    fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
-    fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
-    fw_cfg_add_i16(s, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
-    fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
-    fw_cfg_bootsplash(s);
-
-    s->machine_ready.notify = fw_cfg_machine_ready;
-    qemu_add_machine_init_done_notifier(&s->machine_ready);
-
-    return s;
+    fw_cfg_add_bytes(FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
+    fw_cfg_add_bytes(FW_CFG_UUID, qemu_uuid, 16);
+    fw_cfg_add_i16(FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
+    fw_cfg_add_i16(FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
+    fw_cfg_add_i16(FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
+    fw_cfg_add_i16(FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
+    fw_cfg_bootsplash();
+
+    fw_cfg->machine_ready.notify = fw_cfg_machine_ready;
+    qemu_add_machine_init_done_notifier(&fw_cfg->machine_ready);
  }
 
  static int fw_cfg_init1(SysBusDevice *dev)
hw/fw_cfg.h +7 -8
index 856bf91..cdb239e 100644
@@ -54,15 +54,14 @@ typedef struct FWCfgFiles {
  typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
 
  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,
+int fw_cfg_add_bytes(uint16_t key, uint8_t *data, uint32_t len);
+int fw_cfg_add_i16(uint16_t key, uint16_t value);
+int fw_cfg_add_i32(uint16_t key, uint32_t value);
+int fw_cfg_add_i64(uint16_t key, uint64_t value);
+int fw_cfg_add_callback(uint16_t key, FWCfgCallback callback,
                          void *callback_opaque, uint8_t *data, size_t len);
-int fw_cfg_add_file(FWCfgState *s, const char *filename, uint8_t *data,
-                    uint32_t len);
-FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
+int fw_cfg_add_file(const char *filename, uint8_t *data, uint32_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);
 
  #endif /* NO_QEMU_PROTOS */
hw/loader.c +2 -8
index 415cdce..28464da 100644
@@ -543,7 +543,6 @@ struct Rom {
      QTAILQ_ENTRY(Rom) next;
  };
 
-static FWCfgState *fw_cfg;
  static QTAILQ_HEAD(, Rom) roms = QTAILQ_HEAD_INITIALIZER(roms);
 
  static void rom_insert(Rom *rom)
@@ -601,7 +600,7 @@ int rom_add_file(const char *file, const char *fw_dir,
      }
      close(fd);
      rom_insert(rom);
-    if (rom->fw_file&&  fw_cfg) {
+    if (rom->fw_file) {
          const char *basename;
          char fw_file_name[56];
 
@@ -613,7 +612,7 @@ int rom_add_file(const char *file, const char *fw_dir,
          }
          snprintf(fw_file_name, sizeof(fw_file_name), "%s/%s", rom->fw_dir,
                   basename);
-        fw_cfg_add_file(fw_cfg, fw_file_name, rom->data, rom->romsize);
+        fw_cfg_add_file(fw_file_name, rom->data, rom->romsize);
          snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);
      } else {
          snprintf(devpath, sizeof(devpath), "/rom@" TARGET_FMT_plx, addr);
@@ -704,11 +703,6 @@ int rom_load_all(void)
      return 0;
  }
 
-void rom_set_fw(void *f)
-{
-    fw_cfg = f;
-}
-
  static Rom *find_rom(target_phys_addr_t addr)
  {
      Rom *rom;
hw/loader.h +0 -1
index fbcaba9..c357ec4 100644
@@ -26,7 +26,6 @@ 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);
-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/multiboot.c +8 -9
index b4484a3..fd93e13 100644
@@ -124,8 +124,7 @@ static void mb_add_mod(MultibootState *s,
      s->mb_mods_count++;
  }
 
-int load_multiboot(void *fw_cfg,
-                   FILE *f,
+int load_multiboot(FILE *f,
                     const char *kernel_filename,
                     const char *initrd_filename,
                     const char *kernel_cmdline,
@@ -324,15 +323,15 @@ int load_multiboot(void *fw_cfg,
      memcpy(mb_bootinfo_data, bootinfo, sizeof(bootinfo));
 
      /* Pass variables to option rom */
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ENTRY, mh_entry_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, mh_load_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, mbs.mb_buf_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA,
+    fw_cfg_add_i32(FW_CFG_KERNEL_ENTRY, mh_entry_addr);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, mh_load_addr);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, mbs.mb_buf_size);
+    fw_cfg_add_bytes(FW_CFG_KERNEL_DATA,
                       mbs.mb_buf, mbs.mb_buf_size);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, ADDR_MBI);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, sizeof(bootinfo));
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, mb_bootinfo_data,
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, ADDR_MBI);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, sizeof(bootinfo));
+    fw_cfg_add_bytes(FW_CFG_INITRD_DATA, mb_bootinfo_data,
                       sizeof(bootinfo));
 
      option_rom[nb_option_roms].name = "multiboot.bin";
hw/multiboot.h +1 -2
index 98fb1b7..1302c55 100644
@@ -1,8 +1,7 @@
  #ifndef QEMU_MULTIBOOT_H
  #define QEMU_MULTIBOOT_H
 
-int load_multiboot(void *fw_cfg,
-                   FILE *f,
+int load_multiboot(FILE *f,
                     const char *kernel_filename,
                     const char *initrd_filename,
                     const char *kernel_cmdline,
hw/pc.c +29 -34
index 4d34a33..739e4ad 100644
@@ -593,9 +593,8 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
      return index;
  }
 
-static void *bochs_bios_init(void)
+static void bochs_bios_init(void)
  {
-    void *fw_cfg;
      uint8_t *smbios_table;
      size_t smbios_len;
      uint64_t *numa_fw_cfg;
@@ -613,22 +612,21 @@ static void *bochs_bios_init(void)
      register_ioport_write(0x500, 1, 1, bochs_bios_write, NULL);
      register_ioport_write(0x503, 1, 1, bochs_bios_write, NULL);
 
-    fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
+    fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_ACPI_TABLES, (uint8_t *)acpi_tables,
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_bytes(FW_CFG_ACPI_TABLES, (uint8_t *)acpi_tables,
                       acpi_tables_len);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_IRQ0_OVERRIDE, kvm_allows_irq0_override());
+    fw_cfg_add_i32(FW_CFG_IRQ0_OVERRIDE, kvm_allows_irq0_override());
 
      smbios_table = smbios_get_table(&smbios_len);
      if (smbios_table)
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES,
-                         smbios_table, smbios_len);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, (uint8_t *)&e820_table,
+        fw_cfg_add_bytes(FW_CFG_SMBIOS_ENTRIES, smbios_table, smbios_len);
+    fw_cfg_add_bytes(FW_CFG_E820_TABLE, (uint8_t *)&e820_table,
                       sizeof(struct e820_table));
 
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_HPET, (uint8_t *)&hpet_cfg,
+    fw_cfg_add_bytes(FW_CFG_HPET, (uint8_t *)&hpet_cfg,
                       sizeof(struct hpet_fw_config));
      /* allocate memory for the NUMA channel: one (64bit) word for the number
       * of nodes, one word for each VCPU->node and one word for each node to
@@ -647,10 +645,8 @@ static void *bochs_bios_init(void)
      for (i = 0; i<  nb_numa_nodes; i++) {
          numa_fw_cfg[max_cpus + 1 + i] = cpu_to_le64(node_mem[i]);
      }
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, (uint8_t *)numa_fw_cfg,
+    fw_cfg_add_bytes(FW_CFG_NUMA, (uint8_t *)numa_fw_cfg,
                       (1 + max_cpus + nb_numa_nodes) * 8);
-
-    return fw_cfg;
  }
 
  static long get_file_size(FILE *f)
@@ -667,8 +663,7 @@ static long get_file_size(FILE *f)
      return size;
  }
 
-static void load_linux(void *fw_cfg,
-                       const char *kernel_filename,
+static void load_linux(const char *kernel_filename,
  		       const char *initrd_filename,
  		       const char *kernel_cmdline,
                         target_phys_addr_t max_ram_size)
@@ -703,9 +698,10 @@ static void load_linux(void *fw_cfg,
      else {
  	/* This looks like a multiboot kernel. If it is, let's stop
  	   treating it like a Linux kernel. */
-        if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
-                           kernel_cmdline, kernel_size, header))
+        if (load_multiboot(f, kernel_filename, initrd_filename,
+                           kernel_cmdline, kernel_size, header)) {
              return;
+        }
  	protocol = 0;
      }
 
@@ -745,9 +741,9 @@ static void load_linux(void *fw_cfg,
      if (initrd_max>= max_ram_size-ACPI_DATA_SIZE)
      	initrd_max = max_ram_size-ACPI_DATA_SIZE-1;
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline)+1);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+    fw_cfg_add_i32(FW_CFG_CMDLINE_ADDR, cmdline_addr);
+    fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline)+1);
+    fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                       (uint8_t*)strdup(kernel_cmdline),
                       strlen(kernel_cmdline)+1);
 
@@ -808,9 +804,9 @@ static void load_linux(void *fw_cfg,
          initrd_data = g_malloc(initrd_size);
          load_image(initrd_filename, initrd_data);
 
-        fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, initrd_size);
+        fw_cfg_add_i32(FW_CFG_INITRD_ADDR, initrd_addr);
+        fw_cfg_add_i32(FW_CFG_INITRD_SIZE, initrd_size);
+        fw_cfg_add_bytes(FW_CFG_INITRD_DATA, initrd_data, initrd_size);
 
  	stl_p(header+0x218, initrd_addr);
  	stl_p(header+0x21c, initrd_size);
@@ -837,13 +833,13 @@ static void load_linux(void *fw_cfg,
      fclose(f);
      memcpy(setup, header, MIN(sizeof(header), setup_size));
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, prot_addr);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_add_bytes(FW_CFG_KERNEL_DATA, kernel, kernel_size);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size);
+    fw_cfg_add_i32(FW_CFG_SETUP_ADDR, real_addr);
+    fw_cfg_add_i32(FW_CFG_SETUP_SIZE, setup_size);
+    fw_cfg_add_bytes(FW_CFG_SETUP_DATA, setup, setup_size);
 
      option_rom[nb_option_roms].name = "linuxboot.bin";
      option_rom[nb_option_roms].bootindex = 0;
@@ -987,7 +983,6 @@ void pc_memory_init(MemoryRegion *system_memory,
      int linux_boot, i;
      MemoryRegion *ram, *option_rom_mr;
      MemoryRegion *ram_below_4g, *ram_above_4g;
-    void *fw_cfg;
 
      linux_boot = (kernel_filename != NULL);
 
@@ -1024,11 +1019,11 @@ void pc_memory_init(MemoryRegion *system_memory,
                                          option_rom_mr,
                                          1);
 
-    fw_cfg = bochs_bios_init();
-    rom_set_fw(fw_cfg);
+    bochs_bios_init();
 
      if (linux_boot) {
-        load_linux(fw_cfg, kernel_filename, initrd_filename, kernel_cmdline, below_4g_mem_size);
+        load_linux(kernel_filename, initrd_filename, kernel_cmdline,
+                   below_4g_mem_size);
      }
 
      for (i = 0; i<  nb_option_roms; i++) {
hw/ppc_newworld.c +21 -22
index 8796510..1f2a30e 100644
@@ -107,7 +107,7 @@ static const MemoryRegionOps unin_ops = {
 
  static int fw_cfg_boot_set(void *opaque, const char *boot_device)
  {
-    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
      return 0;
  }
 
@@ -152,7 +152,6 @@ static void ppc_core99_init (ram_addr_t ram_size,
      MemoryRegion *ide_mem[3];
      int ppc_boot_device;
      DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
-    void *fw_cfg;
      void *dbdma;
      int machine_arch;
 
@@ -377,42 +376,42 @@ static void ppc_core99_init (ram_addr_t ram_size,
      macio_nvram_setup_bar(nvr, get_system_memory(), 0xFFF04000);
      /* No PCI init: the BIOS will do it */
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, machine_arch);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, machine_arch);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, kernel_base);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
      if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, cmdline_base);
          pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline);
      } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
      }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, initrd_base);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, initrd_size);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, ppc_boot_device);
 
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth);
+    fw_cfg_add_i16(FW_CFG_PPC_WIDTH, graphic_width);
+    fw_cfg_add_i16(FW_CFG_PPC_HEIGHT, graphic_height);
+    fw_cfg_add_i16(FW_CFG_PPC_DEPTH, graphic_depth);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled());
+    fw_cfg_add_i32(FW_CFG_PPC_IS_KVM, kvm_enabled());
      if (kvm_enabled()) {
  #ifdef CONFIG_KVM
          uint8_t *hypercall;
 
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq());
+        fw_cfg_add_i32(FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq());
          hypercall = g_malloc(16);
          kvmppc_get_hypercall(env, hypercall, 16);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid());
+        fw_cfg_add_bytes(FW_CFG_PPC_KVM_HC, hypercall, 16);
+        fw_cfg_add_i32(FW_CFG_PPC_KVM_PID, getpid());
  #endif
      } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, get_ticks_per_sec());
+        fw_cfg_add_i32(FW_CFG_PPC_TBFREQ, get_ticks_per_sec());
      }
 
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
  }
 
  static QEMUMachine core99_machine = {
hw/ppc_oldworld.c +21 -22
index 7e73d37..575fe59 100644
@@ -50,7 +50,7 @@
 
  static int fw_cfg_boot_set(void *opaque, const char *boot_device)
  {
-    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
      return 0;
  }
 
@@ -95,7 +95,6 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
      MemoryRegion *escc_mem, *escc_bar = g_new(MemoryRegion, 1), *ide_mem[2];
      uint16_t ppc_boot_device;
      DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
-    void *fw_cfg;
      void *dbdma;
 
      linux_boot = (kernel_filename != NULL);
@@ -292,42 +291,42 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
 
      /* No PCI init: the BIOS will do it */
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, ARCH_HEATHROW);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, kernel_base);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
      if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, cmdline_base);
          pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline);
      } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
      }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, initrd_base);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, initrd_size);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, ppc_boot_device);
 
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth);
+    fw_cfg_add_i16(FW_CFG_PPC_WIDTH, graphic_width);
+    fw_cfg_add_i16(FW_CFG_PPC_HEIGHT, graphic_height);
+    fw_cfg_add_i16(FW_CFG_PPC_DEPTH, graphic_depth);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled());
+    fw_cfg_add_i32(FW_CFG_PPC_IS_KVM, kvm_enabled());
      if (kvm_enabled()) {
  #ifdef CONFIG_KVM
          uint8_t *hypercall;
 
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq());
+        fw_cfg_add_i32(FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq());
          hypercall = g_malloc(16);
          kvmppc_get_hypercall(env, hypercall, 16);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid());
+        fw_cfg_add_bytes(FW_CFG_PPC_KVM_HC, hypercall, 16);
+        fw_cfg_add_i32(FW_CFG_PPC_KVM_PID, getpid());
  #endif
      } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, get_ticks_per_sec());
+        fw_cfg_add_i32(FW_CFG_PPC_TBFREQ, get_ticks_per_sec());
      }
 
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
  }
 
  static QEMUMachine heathrow_machine = {
hw/sun4m.c +45 -48
index 34088ad..9f546d6 100644
@@ -163,7 +163,7 @@ void DMA_register_channel (int nchan,
 
  static int fw_cfg_boot_set(void *opaque, const char *boot_device)
  {
-    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
      return 0;
  }
 
@@ -843,7 +843,6 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
      qemu_irq *cpu_halt;
      unsigned long kernel_size;
      DriveInfo *fd[MAX_FD];
-    void *fw_cfg;
      unsigned int num_vsimms;
 
      /* init CPUs */
@@ -995,29 +994,29 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
          ecc_init(hwdef->ecc_base, slavio_irq[28],
                   hwdef->ecc_version);
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, hwdef->machine_id);
+    fw_cfg_add_i16(FW_CFG_SUN4M_DEPTH, graphic_depth);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
      if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
          pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+        fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                           (uint8_t*)strdup(kernel_cmdline),
                           strlen(kernel_cmdline) + 1);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE,
                         strlen(kernel_cmdline) + 1);
      } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE, 0);
      }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, 0); /* not used */
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
  }
 
  enum {
@@ -1525,7 +1524,6 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
          espdma_irq, ledma_irq;
      qemu_irq esp_reset, dma_enable;
      unsigned long kernel_size;
-    void *fw_cfg;
      DeviceState *dev;
 
      /* init CPUs */
@@ -1606,26 +1604,26 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
                 graphic_height, graphic_depth, hwdef->nvram_machine_id,
                 "Sun4d");
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, hwdef->machine_id);
+    fw_cfg_add_i16(FW_CFG_SUN4M_DEPTH, graphic_depth);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
      if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
          pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+        fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                           (uint8_t*)strdup(kernel_cmdline),
                           strlen(kernel_cmdline) + 1);
      } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
      }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, 0); /* not used */
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
  }
 
  /* SPARCserver 1000 hardware initialisation */
@@ -1719,7 +1717,6 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
      qemu_irq fdc_tc;
      unsigned long kernel_size;
      DriveInfo *fd[MAX_FD];
-    void *fw_cfg;
      DeviceState *dev;
      unsigned int i;
 
@@ -1798,26 +1795,26 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
                 graphic_height, graphic_depth, hwdef->nvram_machine_id,
                 "Sun4c");
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, hwdef->machine_id);
+    fw_cfg_add_i16(FW_CFG_SUN4M_DEPTH, graphic_depth);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
      if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
          pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+        fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                           (uint8_t*)strdup(kernel_cmdline),
                           strlen(kernel_cmdline) + 1);
      } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
      }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, 0); /* not used */
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
  }
 
  /* SPARCstation 2 hardware initialisation */
hw/sun4u.c +17 -19
index 517bdb8..094c07c 100644
@@ -125,7 +125,7 @@ void DMA_register_channel (int nchan,
 
  static int fw_cfg_boot_set(void *opaque, const char *boot_device)
  {
-    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
      return 0;
  }
 
@@ -802,7 +802,6 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
      qemu_irq *ivec_irqs, *pbm_irqs;
      DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
      DriveInfo *fd[MAX_FD];
-    void *fw_cfg;
 
      /* init CPUs */
      env = cpu_devinit(cpu_model, hwdef);
@@ -867,30 +866,30 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
                             graphic_width, graphic_height, graphic_depth,
                             (uint8_t *)&nd_table[0].macaddr);
 
-    fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_entry);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, hwdef->machine_id);
+    fw_cfg_add_i64(FW_CFG_KERNEL_ADDR, kernel_entry);
+    fw_cfg_add_i64(FW_CFG_KERNEL_SIZE, kernel_size);
      if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE,
                         strlen(kernel_cmdline) + 1);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+        fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                           (uint8_t*)strdup(kernel_cmdline),
                           strlen(kernel_cmdline) + 1);
      } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE, 0);
      }
-    fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_devices[0]);
+    fw_cfg_add_i64(FW_CFG_INITRD_ADDR, initrd_addr);
+    fw_cfg_add_i64(FW_CFG_INITRD_SIZE, initrd_size);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_devices[0]);
 
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_WIDTH, graphic_width);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_HEIGHT, graphic_height);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_DEPTH, graphic_depth);
+    fw_cfg_add_i16(FW_CFG_SPARC64_WIDTH, graphic_width);
+    fw_cfg_add_i16(FW_CFG_SPARC64_HEIGHT, graphic_height);
+    fw_cfg_add_i16(FW_CFG_SPARC64_DEPTH, graphic_depth);
 
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
  }
 
  enum {
--
Quoted 2 lines

1.7.7.3

--
Gleb.

#11 lore raw
Quoted 7 lines · Anthony Liguori
Quoted 1 line · Gleb Natapov

Ping.

I don't understand why you're pinging.. The patch has just been on the list for a couple of days and is definitely not a 1.1 candidate. Am I missing something?

It is definitely not 1.1 candidate. Only 1.1 patches are accepted now? When master will be opened for 1.2 commits?

Quoted 1 line

However...

Well, I am pinging for review :)

Quoted 47 lines
Quoted 47 lines · Gleb Natapov
Quoted 44 lines

There can be only one fw_cfg device, so saving global reference to it removes the need to pass its pointer around.

---
 hw/fw_cfg.c       |  110 +++++++++++++++++++++++++++--------------------------
 hw/fw_cfg.h       |   15 +++----
 hw/loader.c       |   10 +----
 hw/loader.h       |    1 -
 hw/multiboot.c    |   17 ++++----
 hw/multiboot.h    |    3 +-
 hw/pc.c           |   63 ++++++++++++++----------------
 hw/ppc_newworld.c |   43 ++++++++++-----------
 hw/ppc_oldworld.c |   43 ++++++++++-----------
 hw/sun4m.c        |   93 +++++++++++++++++++++-----------------------
 hw/sun4u.c        |   35 ++++++++---------
 11 files changed, 207 insertions(+), 226 deletions(-)
hw/fw_cfg.c +2 -2
index 7b3b576..8c50473 100644
@@ -48,7 +48,7 @@ typedef struct FWCfgEntry {
     FWCfgCallback callback;
 } FWCfgEntry;
 
-struct FWCfgState {
+static struct FWCfgState {
     SysBusDevice busdev;
     MemoryRegion ctl_iomem, data_iomem, comb_iomem;
     uint32_t ctl_iobase, data_iobase;
@@ -57,7 +57,7 @@ struct FWCfgState {
     uint16_t cur_entry;
     uint32_t cur_offset;
     Notifier machine_ready;
-};
+} *fw_cfg;
 
 #define JPG_FILE 0
 #define BMP_FILE 1
@@ -113,7 +113,7 @@ error:
     return NULL;
 }
 
Quoted 8 lines
Quoted 1 line

hw/fw_cfg.c error: · line 116

Quoted 1 line
hw/fw_cfg.c +0 -1
-static void fw_cfg_bootsplash(FWCfgState *s)

This is a step backwards IMHO. Relying on global state is generally a bad thing. Passing around pointers is a good thing because it forces you to think about the relationships between devices and makes it hard to do silly things (like have random interactions with fw_cfg in devices that have no business doing that).

We are in a kind of agreement here, but fw_cfg is this rare thing that wants to be accessed by devices which, on a first glance, have no business doing that. We already saving fw_cfg globally for rom loaders to use, not nice either.

Quoted 919 lines

Regards,

Anthony Liguori

Quoted 915 lines
Quoted 910 lines
hw/fw_cfg.c +54 -51
+static void fw_cfg_bootsplash(void)
 {
     int boot_splash_time = -1;
     const char *boot_splash_filename = NULL;
@@ -148,7 +148,7 @@ static void fw_cfg_bootsplash(FWCfgState *s)
         /* use little endian format */
         qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time&  0xff);
         qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time>>  8)&  0xff);
-        fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
+        fw_cfg_add_file("etc/boot-menu-wait", qemu_extra_params_fw, 2);
     }
 
     /* insert splash file if user configurated */
@@ -173,10 +173,10 @@ static void fw_cfg_bootsplash(FWCfgState *s)
 
         /* insert data */
         if (file_type == JPG_FILE) {
-            fw_cfg_add_file(s, "bootsplash.jpg",
+            fw_cfg_add_file("bootsplash.jpg",
                     boot_splash_filedata, boot_splash_filedata_size);
         } else {
-            fw_cfg_add_file(s, "bootsplash.bmp",
+            fw_cfg_add_file("bootsplash.bmp",
                     boot_splash_filedata, boot_splash_filedata_size);
         }
         g_free(filename);
@@ -359,122 +359,126 @@ static const VMStateDescription vmstate_fw_cfg = {
     }
 };
 
-int fw_cfg_add_bytes(FWCfgState *s, uint16_t key, uint8_t *data, uint32_t len)
+int fw_cfg_add_bytes(uint16_t key, uint8_t *data, uint32_t len)
 {
     int arch = !!(key&  FW_CFG_ARCH_LOCAL);
 
     key&= FW_CFG_ENTRY_MASK;
 
-    if (key>= FW_CFG_MAX_ENTRY)
+    if (key>= FW_CFG_MAX_ENTRY || !fw_cfg) {
         return 0;
+    }
 
-    s->entries[arch][key].data = data;
-    s->entries[arch][key].len = len;
+    fw_cfg->entries[arch][key].data = data;
+    fw_cfg->entries[arch][key].len = len;
 
     return 1;
 }
 
-int fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value)
+int fw_cfg_add_i16(uint16_t key, uint16_t value)
 {
     uint16_t *copy;
 
     copy = g_malloc(sizeof(value));
     *copy = cpu_to_le16(value);
-    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value)
+int fw_cfg_add_i32(uint16_t key, uint32_t value)
 {
     uint32_t *copy;
 
     copy = g_malloc(sizeof(value));
     *copy = cpu_to_le32(value);
-    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
+int fw_cfg_add_i64(uint16_t key, uint64_t value)
 {
     uint64_t *copy;
 
     copy = g_malloc(sizeof(value));
     *copy = cpu_to_le64(value);
-    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
+int fw_cfg_add_callback(uint16_t key, FWCfgCallback callback,
                         void *callback_opaque, uint8_t *data, size_t len)
 {
     int arch = !!(key&  FW_CFG_ARCH_LOCAL);
 
-    if (!(key&  FW_CFG_WRITE_CHANNEL))
+    if (!(key&  FW_CFG_WRITE_CHANNEL) || !fw_cfg) {
         return 0;
+    }
 
     key&= FW_CFG_ENTRY_MASK;
 
     if (key>= FW_CFG_MAX_ENTRY || len>  65535)
         return 0;
 
-    s->entries[arch][key].data = data;
-    s->entries[arch][key].len = len;
-    s->entries[arch][key].callback_opaque = callback_opaque;
-    s->entries[arch][key].callback = callback;
+    fw_cfg->entries[arch][key].data = data;
+    fw_cfg->entries[arch][key].len = len;
+    fw_cfg->entries[arch][key].callback_opaque = callback_opaque;
+    fw_cfg->entries[arch][key].callback = callback;
 
     return 1;
 }
 
-int fw_cfg_add_file(FWCfgState *s,  const char *filename, uint8_t *data,
-                    uint32_t len)
+int fw_cfg_add_file(const char *filename, uint8_t *data, uint32_t len)
 {
     int i, index;
 
-    if (!s->files) {
+    if (!fw_cfg) {
+        return 0;
+    }
+
+    if (!fw_cfg->files) {
         int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;
-        s->files = g_malloc0(dsize);
-        fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, (uint8_t*)s->files, dsize);
+        fw_cfg->files = g_malloc0(dsize);
+        fw_cfg_add_bytes(FW_CFG_FILE_DIR, (uint8_t *)fw_cfg->files, dsize);
     }
 
-    index = be32_to_cpu(s->files->count);
+    index = be32_to_cpu(fw_cfg->files->count);
     if (index == FW_CFG_FILE_SLOTS) {
         fprintf(stderr, "fw_cfg: out of file slots\n");
         return 0;
     }
 
-    fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len);
+    fw_cfg_add_bytes(FW_CFG_FILE_FIRST + index, data, len);
 
-    pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name),
+    pstrcpy(fw_cfg->files->f[index].name, sizeof(fw_cfg->files->f[index].name),
             filename);
     for (i = 0; i<  index; i++) {
-        if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
+        if (strcmp(fw_cfg->files->f[index].name, fw_cfg->files->f[i].name)
+                        == 0) {
             FW_CFG_DPRINTF("%s: skip duplicate: %s\n", __FUNCTION__,
-                           s->files->f[index].name);
+                           fw_cfg->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->files->f[index].size   = cpu_to_be32(len);
+    fw_cfg->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
     FW_CFG_DPRINTF("%s: #%d: %s (%d bytes)\n", __FUNCTION__,
-                   index, s->files->f[index].name, len);
+                   index, fw_cfg->files->f[index].name, len);
 
-    s->files->count = cpu_to_be32(index+1);
+    fw_cfg->files->count = cpu_to_be32(index+1);
     return 1;
 }
 
 static void fw_cfg_machine_ready(struct Notifier *n, void *data)
 {
     uint32_t len;
-    FWCfgState *s = container_of(n, FWCfgState, machine_ready);
     char *bootindex = get_boot_devices_list(&len);
 
-    fw_cfg_add_file(s, "bootorder", (uint8_t*)bootindex, len);
+    fw_cfg_add_file("bootorder", (uint8_t *)bootindex, len);
 }
 
-FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
-                        target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
+void fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
+                 target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
 {
     DeviceState *dev;
     SysBusDevice *d;
-    FWCfgState *s;
 
     dev = qdev_create(NULL, "fw_cfg");
     qdev_prop_set_uint32(dev, "ctl_iobase", ctl_port);
@@ -482,7 +486,7 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
     qdev_init_nofail(dev);
     d = sysbus_from_qdev(dev);
 
-    s = DO_UPCAST(FWCfgState, busdev.qdev, dev);
+    fw_cfg = DO_UPCAST(FWCfgState, busdev.qdev, dev);
 
     if (ctl_addr) {
         sysbus_mmio_map(d, 0, ctl_addr);
@@ -490,18 +494,16 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
     if (data_addr) {
         sysbus_mmio_map(d, 1, data_addr);
     }
-    fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
-    fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
-    fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
-    fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
-    fw_cfg_add_i16(s, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
-    fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
-    fw_cfg_bootsplash(s);
-
-    s->machine_ready.notify = fw_cfg_machine_ready;
-    qemu_add_machine_init_done_notifier(&s->machine_ready);
-
-    return s;
+    fw_cfg_add_bytes(FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
+    fw_cfg_add_bytes(FW_CFG_UUID, qemu_uuid, 16);
+    fw_cfg_add_i16(FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
+    fw_cfg_add_i16(FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
+    fw_cfg_add_i16(FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
+    fw_cfg_add_i16(FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
+    fw_cfg_bootsplash();
+
+    fw_cfg->machine_ready.notify = fw_cfg_machine_ready;
+    qemu_add_machine_init_done_notifier(&fw_cfg->machine_ready);
 }
 
 static int fw_cfg_init1(SysBusDevice *dev)
hw/fw_cfg.h +7 -8
index 856bf91..cdb239e 100644
@@ -54,15 +54,14 @@ typedef struct FWCfgFiles {
 typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
 
 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,
+int fw_cfg_add_bytes(uint16_t key, uint8_t *data, uint32_t len);
+int fw_cfg_add_i16(uint16_t key, uint16_t value);
+int fw_cfg_add_i32(uint16_t key, uint32_t value);
+int fw_cfg_add_i64(uint16_t key, uint64_t value);
+int fw_cfg_add_callback(uint16_t key, FWCfgCallback callback,
                         void *callback_opaque, uint8_t *data, size_t len);
-int fw_cfg_add_file(FWCfgState *s, const char *filename, uint8_t *data,
-                    uint32_t len);
-FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
+int fw_cfg_add_file(const char *filename, uint8_t *data, uint32_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);
 
 #endif /* NO_QEMU_PROTOS */
hw/loader.c +2 -8
index 415cdce..28464da 100644
@@ -543,7 +543,6 @@ struct Rom {
     QTAILQ_ENTRY(Rom) next;
 };
 
-static FWCfgState *fw_cfg;
 static QTAILQ_HEAD(, Rom) roms = QTAILQ_HEAD_INITIALIZER(roms);
 
 static void rom_insert(Rom *rom)
@@ -601,7 +600,7 @@ int rom_add_file(const char *file, const char *fw_dir,
     }
     close(fd);
     rom_insert(rom);
-    if (rom->fw_file&&  fw_cfg) {
+    if (rom->fw_file) {
         const char *basename;
         char fw_file_name[56];
 
@@ -613,7 +612,7 @@ int rom_add_file(const char *file, const char *fw_dir,
         }
         snprintf(fw_file_name, sizeof(fw_file_name), "%s/%s", rom->fw_dir,
                  basename);
-        fw_cfg_add_file(fw_cfg, fw_file_name, rom->data, rom->romsize);
+        fw_cfg_add_file(fw_file_name, rom->data, rom->romsize);
         snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);
     } else {
         snprintf(devpath, sizeof(devpath), "/rom@" TARGET_FMT_plx, addr);
@@ -704,11 +703,6 @@ int rom_load_all(void)
     return 0;
 }
 
-void rom_set_fw(void *f)
-{
-    fw_cfg = f;
-}
-
 static Rom *find_rom(target_phys_addr_t addr)
 {
     Rom *rom;
hw/loader.h +0 -1
index fbcaba9..c357ec4 100644
@@ -26,7 +26,6 @@ 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);
-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/multiboot.c +8 -9
index b4484a3..fd93e13 100644
@@ -124,8 +124,7 @@ static void mb_add_mod(MultibootState *s,
     s->mb_mods_count++;
 }
 
-int load_multiboot(void *fw_cfg,
-                   FILE *f,
+int load_multiboot(FILE *f,
                    const char *kernel_filename,
                    const char *initrd_filename,
                    const char *kernel_cmdline,
@@ -324,15 +323,15 @@ int load_multiboot(void *fw_cfg,
     memcpy(mb_bootinfo_data, bootinfo, sizeof(bootinfo));
 
     /* Pass variables to option rom */
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ENTRY, mh_entry_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, mh_load_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, mbs.mb_buf_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA,
+    fw_cfg_add_i32(FW_CFG_KERNEL_ENTRY, mh_entry_addr);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, mh_load_addr);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, mbs.mb_buf_size);
+    fw_cfg_add_bytes(FW_CFG_KERNEL_DATA,
                      mbs.mb_buf, mbs.mb_buf_size);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, ADDR_MBI);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, sizeof(bootinfo));
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, mb_bootinfo_data,
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, ADDR_MBI);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, sizeof(bootinfo));
+    fw_cfg_add_bytes(FW_CFG_INITRD_DATA, mb_bootinfo_data,
                      sizeof(bootinfo));
 
     option_rom[nb_option_roms].name = "multiboot.bin";
hw/multiboot.h +1 -2
index 98fb1b7..1302c55 100644
@@ -1,8 +1,7 @@
 #ifndef QEMU_MULTIBOOT_H
 #define QEMU_MULTIBOOT_H
 
-int load_multiboot(void *fw_cfg,
-                   FILE *f,
+int load_multiboot(FILE *f,
                    const char *kernel_filename,
                    const char *initrd_filename,
                    const char *kernel_cmdline,
hw/pc.c +29 -34
index 4d34a33..739e4ad 100644
@@ -593,9 +593,8 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
     return index;
 }
 
-static void *bochs_bios_init(void)
+static void bochs_bios_init(void)
 {
-    void *fw_cfg;
     uint8_t *smbios_table;
     size_t smbios_len;
     uint64_t *numa_fw_cfg;
@@ -613,22 +612,21 @@ static void *bochs_bios_init(void)
     register_ioport_write(0x500, 1, 1, bochs_bios_write, NULL);
     register_ioport_write(0x503, 1, 1, bochs_bios_write, NULL);
 
-    fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
+    fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_ACPI_TABLES, (uint8_t *)acpi_tables,
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_bytes(FW_CFG_ACPI_TABLES, (uint8_t *)acpi_tables,
                      acpi_tables_len);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_IRQ0_OVERRIDE, kvm_allows_irq0_override());
+    fw_cfg_add_i32(FW_CFG_IRQ0_OVERRIDE, kvm_allows_irq0_override());
 
     smbios_table = smbios_get_table(&smbios_len);
     if (smbios_table)
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES,
-                         smbios_table, smbios_len);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, (uint8_t *)&e820_table,
+        fw_cfg_add_bytes(FW_CFG_SMBIOS_ENTRIES, smbios_table, smbios_len);
+    fw_cfg_add_bytes(FW_CFG_E820_TABLE, (uint8_t *)&e820_table,
                      sizeof(struct e820_table));
 
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_HPET, (uint8_t *)&hpet_cfg,
+    fw_cfg_add_bytes(FW_CFG_HPET, (uint8_t *)&hpet_cfg,
                      sizeof(struct hpet_fw_config));
     /* allocate memory for the NUMA channel: one (64bit) word for the number
      * of nodes, one word for each VCPU->node and one word for each node to
@@ -647,10 +645,8 @@ static void *bochs_bios_init(void)
     for (i = 0; i<  nb_numa_nodes; i++) {
         numa_fw_cfg[max_cpus + 1 + i] = cpu_to_le64(node_mem[i]);
     }
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, (uint8_t *)numa_fw_cfg,
+    fw_cfg_add_bytes(FW_CFG_NUMA, (uint8_t *)numa_fw_cfg,
                      (1 + max_cpus + nb_numa_nodes) * 8);
-
-    return fw_cfg;
 }
 
 static long get_file_size(FILE *f)
@@ -667,8 +663,7 @@ static long get_file_size(FILE *f)
     return size;
 }
 
-static void load_linux(void *fw_cfg,
-                       const char *kernel_filename,
+static void load_linux(const char *kernel_filename,
 		       const char *initrd_filename,
 		       const char *kernel_cmdline,
                        target_phys_addr_t max_ram_size)
@@ -703,9 +698,10 @@ static void load_linux(void *fw_cfg,
     else {
 	/* This looks like a multiboot kernel. If it is, let's stop
 	   treating it like a Linux kernel. */
-        if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
-                           kernel_cmdline, kernel_size, header))
+        if (load_multiboot(f, kernel_filename, initrd_filename,
+                           kernel_cmdline, kernel_size, header)) {
             return;
+        }
 	protocol = 0;
     }
 
@@ -745,9 +741,9 @@ static void load_linux(void *fw_cfg,
     if (initrd_max>= max_ram_size-ACPI_DATA_SIZE)
     	initrd_max = max_ram_size-ACPI_DATA_SIZE-1;
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline)+1);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+    fw_cfg_add_i32(FW_CFG_CMDLINE_ADDR, cmdline_addr);
+    fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline)+1);
+    fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                      (uint8_t*)strdup(kernel_cmdline),
                      strlen(kernel_cmdline)+1);
 
@@ -808,9 +804,9 @@ static void load_linux(void *fw_cfg,
         initrd_data = g_malloc(initrd_size);
         load_image(initrd_filename, initrd_data);
 
-        fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, initrd_size);
+        fw_cfg_add_i32(FW_CFG_INITRD_ADDR, initrd_addr);
+        fw_cfg_add_i32(FW_CFG_INITRD_SIZE, initrd_size);
+        fw_cfg_add_bytes(FW_CFG_INITRD_DATA, initrd_data, initrd_size);
 
 	stl_p(header+0x218, initrd_addr);
 	stl_p(header+0x21c, initrd_size);
@@ -837,13 +833,13 @@ static void load_linux(void *fw_cfg,
     fclose(f);
     memcpy(setup, header, MIN(sizeof(header), setup_size));
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, prot_addr);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_add_bytes(FW_CFG_KERNEL_DATA, kernel, kernel_size);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size);
+    fw_cfg_add_i32(FW_CFG_SETUP_ADDR, real_addr);
+    fw_cfg_add_i32(FW_CFG_SETUP_SIZE, setup_size);
+    fw_cfg_add_bytes(FW_CFG_SETUP_DATA, setup, setup_size);
 
     option_rom[nb_option_roms].name = "linuxboot.bin";
     option_rom[nb_option_roms].bootindex = 0;
@@ -987,7 +983,6 @@ void pc_memory_init(MemoryRegion *system_memory,
     int linux_boot, i;
     MemoryRegion *ram, *option_rom_mr;
     MemoryRegion *ram_below_4g, *ram_above_4g;
-    void *fw_cfg;
 
     linux_boot = (kernel_filename != NULL);
 
@@ -1024,11 +1019,11 @@ void pc_memory_init(MemoryRegion *system_memory,
                                         option_rom_mr,
                                         1);
 
-    fw_cfg = bochs_bios_init();
-    rom_set_fw(fw_cfg);
+    bochs_bios_init();
 
     if (linux_boot) {
-        load_linux(fw_cfg, kernel_filename, initrd_filename, kernel_cmdline, below_4g_mem_size);
+        load_linux(kernel_filename, initrd_filename, kernel_cmdline,
+                   below_4g_mem_size);
     }
 
     for (i = 0; i<  nb_option_roms; i++) {
hw/ppc_newworld.c +21 -22
index 8796510..1f2a30e 100644
@@ -107,7 +107,7 @@ static const MemoryRegionOps unin_ops = {
 
 static int fw_cfg_boot_set(void *opaque, const char *boot_device)
 {
-    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
     return 0;
 }
 
@@ -152,7 +152,6 @@ static void ppc_core99_init (ram_addr_t ram_size,
     MemoryRegion *ide_mem[3];
     int ppc_boot_device;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
-    void *fw_cfg;
     void *dbdma;
     int machine_arch;
 
@@ -377,42 +376,42 @@ static void ppc_core99_init (ram_addr_t ram_size,
     macio_nvram_setup_bar(nvr, get_system_memory(), 0xFFF04000);
     /* No PCI init: the BIOS will do it */
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, machine_arch);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, machine_arch);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, kernel_base);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
     if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, cmdline_base);
         pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline);
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
     }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, initrd_base);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, initrd_size);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, ppc_boot_device);
 
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth);
+    fw_cfg_add_i16(FW_CFG_PPC_WIDTH, graphic_width);
+    fw_cfg_add_i16(FW_CFG_PPC_HEIGHT, graphic_height);
+    fw_cfg_add_i16(FW_CFG_PPC_DEPTH, graphic_depth);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled());
+    fw_cfg_add_i32(FW_CFG_PPC_IS_KVM, kvm_enabled());
     if (kvm_enabled()) {
 #ifdef CONFIG_KVM
         uint8_t *hypercall;
 
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq());
+        fw_cfg_add_i32(FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq());
         hypercall = g_malloc(16);
         kvmppc_get_hypercall(env, hypercall, 16);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid());
+        fw_cfg_add_bytes(FW_CFG_PPC_KVM_HC, hypercall, 16);
+        fw_cfg_add_i32(FW_CFG_PPC_KVM_PID, getpid());
 #endif
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, get_ticks_per_sec());
+        fw_cfg_add_i32(FW_CFG_PPC_TBFREQ, get_ticks_per_sec());
     }
 
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
 }
 
 static QEMUMachine core99_machine = {
hw/ppc_oldworld.c +21 -22
index 7e73d37..575fe59 100644
@@ -50,7 +50,7 @@
 
 static int fw_cfg_boot_set(void *opaque, const char *boot_device)
 {
-    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
     return 0;
 }
 
@@ -95,7 +95,6 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
     MemoryRegion *escc_mem, *escc_bar = g_new(MemoryRegion, 1), *ide_mem[2];
     uint16_t ppc_boot_device;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
-    void *fw_cfg;
     void *dbdma;
 
     linux_boot = (kernel_filename != NULL);
@@ -292,42 +291,42 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
 
     /* No PCI init: the BIOS will do it */
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, ARCH_HEATHROW);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, kernel_base);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
     if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, cmdline_base);
         pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline);
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
     }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, initrd_base);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, initrd_size);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, ppc_boot_device);
 
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth);
+    fw_cfg_add_i16(FW_CFG_PPC_WIDTH, graphic_width);
+    fw_cfg_add_i16(FW_CFG_PPC_HEIGHT, graphic_height);
+    fw_cfg_add_i16(FW_CFG_PPC_DEPTH, graphic_depth);
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled());
+    fw_cfg_add_i32(FW_CFG_PPC_IS_KVM, kvm_enabled());
     if (kvm_enabled()) {
 #ifdef CONFIG_KVM
         uint8_t *hypercall;
 
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq());
+        fw_cfg_add_i32(FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq());
         hypercall = g_malloc(16);
         kvmppc_get_hypercall(env, hypercall, 16);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid());
+        fw_cfg_add_bytes(FW_CFG_PPC_KVM_HC, hypercall, 16);
+        fw_cfg_add_i32(FW_CFG_PPC_KVM_PID, getpid());
 #endif
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, get_ticks_per_sec());
+        fw_cfg_add_i32(FW_CFG_PPC_TBFREQ, get_ticks_per_sec());
     }
 
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
 }
 
 static QEMUMachine heathrow_machine = {
hw/sun4m.c +45 -48
index 34088ad..9f546d6 100644
@@ -163,7 +163,7 @@ void DMA_register_channel (int nchan,
 
 static int fw_cfg_boot_set(void *opaque, const char *boot_device)
 {
-    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
     return 0;
 }
 
@@ -843,7 +843,6 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
     qemu_irq *cpu_halt;
     unsigned long kernel_size;
     DriveInfo *fd[MAX_FD];
-    void *fw_cfg;
     unsigned int num_vsimms;
 
     /* init CPUs */
@@ -995,29 +994,29 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
         ecc_init(hwdef->ecc_base, slavio_irq[28],
                  hwdef->ecc_version);
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, hwdef->machine_id);
+    fw_cfg_add_i16(FW_CFG_SUN4M_DEPTH, graphic_depth);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
     if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
         pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+        fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                          (uint8_t*)strdup(kernel_cmdline),
                          strlen(kernel_cmdline) + 1);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE,
                        strlen(kernel_cmdline) + 1);
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE, 0);
     }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, 0); /* not used */
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
 }
 
 enum {
@@ -1525,7 +1524,6 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
         espdma_irq, ledma_irq;
     qemu_irq esp_reset, dma_enable;
     unsigned long kernel_size;
-    void *fw_cfg;
     DeviceState *dev;
 
     /* init CPUs */
@@ -1606,26 +1604,26 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
                graphic_height, graphic_depth, hwdef->nvram_machine_id,
                "Sun4d");
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, hwdef->machine_id);
+    fw_cfg_add_i16(FW_CFG_SUN4M_DEPTH, graphic_depth);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
     if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
         pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+        fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                          (uint8_t*)strdup(kernel_cmdline),
                          strlen(kernel_cmdline) + 1);
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
     }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, 0); /* not used */
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
 }
 
 /* SPARCserver 1000 hardware initialisation */
@@ -1719,7 +1717,6 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
     qemu_irq fdc_tc;
     unsigned long kernel_size;
     DriveInfo *fd[MAX_FD];
-    void *fw_cfg;
     DeviceState *dev;
     unsigned int i;
 
@@ -1798,26 +1795,26 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
                graphic_height, graphic_depth, hwdef->nvram_machine_id,
                "Sun4c");
 
-    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, hwdef->machine_id);
+    fw_cfg_add_i16(FW_CFG_SUN4M_DEPTH, graphic_depth);
+    fw_cfg_add_i32(FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_KERNEL_SIZE, kernel_size);
     if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
         pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+        fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                          (uint8_t*)strdup(kernel_cmdline),
                          strlen(kernel_cmdline) + 1);
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+        fw_cfg_add_i32(FW_CFG_KERNEL_CMDLINE, 0);
     }
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    fw_cfg_add_i32(FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
+    fw_cfg_add_i32(FW_CFG_INITRD_SIZE, 0); /* not used */
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
 }
 
 /* SPARCstation 2 hardware initialisation */
hw/sun4u.c +17 -19
index 517bdb8..094c07c 100644
@@ -125,7 +125,7 @@ void DMA_register_channel (int nchan,
 
 static int fw_cfg_boot_set(void *opaque, const char *boot_device)
 {
-    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_device[0]);
     return 0;
 }
 
@@ -802,7 +802,6 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
     qemu_irq *ivec_irqs, *pbm_irqs;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     DriveInfo *fd[MAX_FD];
-    void *fw_cfg;
 
     /* init CPUs */
     env = cpu_devinit(cpu_model, hwdef);
@@ -867,30 +866,30 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
                            graphic_width, graphic_height, graphic_depth,
                            (uint8_t *)&nd_table[0].macaddr);
 
-    fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_entry);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
+    fw_cfg_add_i32(FW_CFG_ID, 1);
+    fw_cfg_add_i64(FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i16(FW_CFG_MACHINE_ID, hwdef->machine_id);
+    fw_cfg_add_i64(FW_CFG_KERNEL_ADDR, kernel_entry);
+    fw_cfg_add_i64(FW_CFG_KERNEL_SIZE, kernel_size);
     if (kernel_cmdline) {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE,
                        strlen(kernel_cmdline) + 1);
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
+        fw_cfg_add_bytes(FW_CFG_CMDLINE_DATA,
                          (uint8_t*)strdup(kernel_cmdline),
                          strlen(kernel_cmdline) + 1);
     } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
+        fw_cfg_add_i32(FW_CFG_CMDLINE_SIZE, 0);
     }
-    fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_devices[0]);
+    fw_cfg_add_i64(FW_CFG_INITRD_ADDR, initrd_addr);
+    fw_cfg_add_i64(FW_CFG_INITRD_SIZE, initrd_size);
+    fw_cfg_add_i16(FW_CFG_BOOT_DEVICE, boot_devices[0]);
 
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_WIDTH, graphic_width);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_HEIGHT, graphic_height);
-    fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_DEPTH, graphic_depth);
+    fw_cfg_add_i16(FW_CFG_SPARC64_WIDTH, graphic_width);
+    fw_cfg_add_i16(FW_CFG_SPARC64_HEIGHT, graphic_height);
+    fw_cfg_add_i16(FW_CFG_SPARC64_DEPTH, graphic_depth);
 
-    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_register_boot_set(fw_cfg_boot_set, NULL);
 }
 
 enum {
--
Quoted 2 lines

1.7.7.3

--
Gleb.

--
Gleb.

#12 lore raw
Quoted 10 lines · Gleb Natapov
Quoted 7 lines · Anthony Liguori
Quoted 1 line · Gleb Natapov

Ping.

I don't understand why you're pinging.. The patch has just been on the list for a couple of days and is definitely not a 1.1 candidate. Am I missing something?

It is definitely not 1.1 candidate. Only 1.1 patches are accepted now? When master will be opened for 1.2 commits?

After 1.1 is released (June 1st).

Quoted 59 lines
Quoted 2 lines

However...

Well, I am pinging for review :)

Quoted 47 lines
Quoted 47 lines · Gleb Natapov
Quoted 44 lines

There can be only one fw_cfg device, so saving global reference to it removes the need to pass its pointer around.

---
  hw/fw_cfg.c       |  110 +++++++++++++++++++++++++++--------------------------
  hw/fw_cfg.h       |   15 +++----
  hw/loader.c       |   10 +----
  hw/loader.h       |    1 -
  hw/multiboot.c    |   17 ++++----
  hw/multiboot.h    |    3 +-
  hw/pc.c           |   63 ++++++++++++++----------------
  hw/ppc_newworld.c |   43 ++++++++++-----------
  hw/ppc_oldworld.c |   43 ++++++++++-----------
  hw/sun4m.c        |   93 +++++++++++++++++++++-----------------------
  hw/sun4u.c        |   35 ++++++++---------
  11 files changed, 207 insertions(+), 226 deletions(-)
hw/fw_cfg.c +2 -2
index 7b3b576..8c50473 100644
@@ -48,7 +48,7 @@ typedef struct FWCfgEntry {
      FWCfgCallback callback;
  } FWCfgEntry;
 
-struct FWCfgState {
+static struct FWCfgState {
      SysBusDevice busdev;
      MemoryRegion ctl_iomem, data_iomem, comb_iomem;
      uint32_t ctl_iobase, data_iobase;
@@ -57,7 +57,7 @@ struct FWCfgState {
      uint16_t cur_entry;
      uint32_t cur_offset;
      Notifier machine_ready;
-};
+} *fw_cfg;
 
  #define JPG_FILE 0
  #define BMP_FILE 1
@@ -113,7 +113,7 @@ error:
      return NULL;
  }
 
Quoted 8 lines
Quoted 1 line

hw/fw_cfg.c error: · line 116

Quoted 1 line
hw/fw_cfg.c +0 -1
-static void fw_cfg_bootsplash(FWCfgState *s)

This is a step backwards IMHO. Relying on global state is generally a bad thing. Passing around pointers is a good thing because it forces you to think about the relationships between devices and makes it hard to do silly things (like have random interactions with fw_cfg in devices that have no business doing that).

Quoted 4 lines

We are in a kind of agreement here, but fw_cfg is this rare thing that wants to be accessed by devices which, on a first glance, have no business doing that. We already saving fw_cfg globally for rom loaders to use, not nice either.

Rom loaders are an exception because they aren't being modeled as a device today. For devices, we want the interactions to be expressed via the QOM graph which for now means having a PTR property (although actually on qom-next, it should be possible to do a proper link property).

Since you're interacting with fw_cfg in a proper device, you really should do so through the device interface (in this case, FWcfgState).

Regards,

Anthony Liguori

#13 lore raw
In reply to Gleb Natapov
Quoted 2 lines · Gleb Natapov

There can be only one fw_cfg device, so saving global reference to it removes the need to pass its pointer around.

This seems like a backwards step to me: one of the things that prevents us supporting "two separate machines in one emulation" is that we have various things that assume there's only one instance of themselves and use globals. I don't think we should be adding any more...

-- PMM

#14 lore raw
Quoted 9 lines · Peter Maydell
Quoted 2 lines · Gleb Natapov

There can be only one fw_cfg device, so saving global reference to it removes the need to pass its pointer around.

This seems like a backwards step to me: one of the things that prevents us supporting "two separate machines in one emulation" is that we have various things that assume there's only one instance of themselves and use globals. I don't think we should be adding any more...

So you do it usual way. Have "struct Machine" and put pointer to fw_cfg there. Current code already saves global pointer to fw_cfg, the patch just makes it official.

--
Gleb.

#15 lore raw
In reply to Peter Maydell

Am 23.05.2012 14:44, schrieb Peter Maydell:

Quoted 8 lines · Gleb Natapov
Quoted 2 lines

There can be only one fw_cfg device, so saving global reference to it removes the need to pass its pointer around.

This seems like a backwards step to me: one of the things that prevents us supporting "two separate machines in one emulation" is that we have various things that assume there's only one instance of themselves and use globals. I don't think we should be adding any more...

While I concur with the design sentiment of avoiding globals where possible, I can understand having multiple CPU types in one machine, but multiple machines in one emulation? Do you have a specific example that cannot easily be modeled as multiple socket-connected executables?

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#16 lore raw
Quoted 10 lines · Andreas Färber

Am 23.05.2012 14:44, schrieb Peter Maydell:

Quoted 8 lines · Gleb Natapov
Quoted 2 lines

There can be only one fw_cfg device, so saving global reference to it removes the need to pass its pointer around.

This seems like a backwards step to me: one of the things that prevents us supporting "two separate machines in one emulation" is that we have various things that assume there's only one instance of themselves and use globals. I don't think we should be adding any more...

Quoted 4 lines

While I concur with the design sentiment of avoiding globals where possible, I can understand having multiple CPU types in one machine, but multiple machines in one emulation? Do you have a specific example that cannot easily be modeled as multiple socket-connected executables?

I mostly meant the "two different CPUs" case, but there's not a great deal of difference between them. You're just instantiating a set of QOM objects and wiring them up appropriately in either
case: if you can support different CPUs then you can trivially support multiple machines, because that's just a special case of two separate CPUs which happen to not share any memory.

We don't have any support for running QOM interface links over sockets anyway, so that seems like a red herring.

-- PMM