Skip to contentSkip to conversation

FW_CFG_EMULATOR

PATCH In review Jes Sorensen 2 participants 3 messages Aug 3, 2009 – Aug 5, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 FW_CFG_EMULATOR

Hi,

Here's a patch for QEMU which tells the BIOS it is running on QEMU/KQEMU/KVM.

I have a set if patches for Seabios using this to runtime select KVM and QEMU settings, eliminating the need for a specially compiled BIOS binary.

If we can agree on the interface, I would look into doing something similar for BOCHS as well.

I will be posting the Seabios patches in a minute.

Cheers,
Jes

Provide FW_CFG_EMULATOR info to the BIOS

This option provides info to the BIOS informing it which emulator it is running on top of.

The emulator version is designed as a master rev, for the upper 8 bits, and a minor version for the lower 8 bits. This allows one to specify QEMU_KVM vs QEMU_KQEMU for example. It should leave space for other emulators to register themselves too.

If the BIOS' probe for FW_CFG fails, it is expected it sets it's emulator version to the same as CFG_EMU_NONE.

I have a set of patches for Seabios using this to determine it is running on top of QEMU and KVM. This allows setting certain KVM specific bits, and also determining at runtime that Seabios is running on top of QEMU, eliminating the #define CONFIG_KVM.

Signed-off-by Jes Sorensen
---
 hw/fw_cfg.c |    3 +++
 hw/fw_cfg.h |   11 ++++++++++-
 vl.c        |    6 ++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
hw/fw_cfg.c +3 -0
Index: qemu/hw/fw_cfg.c
===================================================================
@@ -38,6 +38,8 @@
 
 #define FW_CFG_SIZE 2
 
+extern uint16_t emu_type;
+
 typedef struct _FWCfgEntry {
     uint16_t len;
     uint8_t *data;
@@ -281,6 +283,7 @@ void *fw_cfg_init(uint32_t ctl_port, uin
     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_add_i16(s, FW_CFG_EMULATOR, emu_type);
 
     register_savevm("fw_cfg", -1, 1, fw_cfg_save, fw_cfg_load, s);
     qemu_register_reset(fw_cfg_reset, s);
hw/fw_cfg.h +10 -1
Index: qemu/hw/fw_cfg.h
===================================================================
@@ -17,7 +17,8 @@
 #define FW_CFG_NUMA             0x0d
 #define FW_CFG_BOOT_MENU        0x0e
 #define FW_CFG_MAX_CPUS         0x0f
-#define FW_CFG_MAX_ENTRY        0x10
+#define FW_CFG_EMULATOR         0x10
+#define FW_CFG_MAX_ENTRY        0x11
 
 #define FW_CFG_WRITE_CHANNEL    0x4000
 #define FW_CFG_ARCH_LOCAL       0x8000
@@ -25,6 +26,14 @@
 
 #define FW_CFG_INVALID          0xffff
 
+/*
+ * Values for FW_CFG_EMULATOR
+ */
+#define CFG_EMU_NONE            0x0000
+#define CFG_EMU_QEMU            0x0100
+#define CFG_EMU_QEMU_KVM        0x0101
+#define CFG_EMU_QEMU_KQEMU      0x0102
+
 #ifndef NO_QEMU_PROTOS
 typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
 
vl.c +6 -0
Index: qemu/vl.c
===================================================================
@@ -142,6 +142,7 @@ int main(int argc, char **argv)
 #include "hw/smbios.h"
 #include "hw/xen.h"
 #include "hw/qdev.h"
+#include "hw/fw_cfg.h"
 #include "bt-host.h"
 #include "net.h"
 #include "monitor.h"
@@ -270,6 +271,8 @@ uint8_t qemu_uuid[16];
 static QEMUBootSetHandler *boot_set_handler;
 static void *boot_set_opaque;
 
+uint16_t emu_type = CFG_EMU_QEMU;
+
 /***********************************************************/
 /* x86 ISA bus support */
 
@@ -5426,14 +5429,17 @@ int main(int argc, char **argv, char **e
 #ifdef CONFIG_KQEMU
             case QEMU_OPTION_enable_kqemu:
                 kqemu_allowed = 1;
+                emu_type = CFG_EMU_QEMU_KQEMU;
                 break;
             case QEMU_OPTION_kernel_kqemu:
                 kqemu_allowed = 2;
+                emu_type = CFG_EMU_QEMU_KQEMU;
                 break;
 #endif
 #ifdef CONFIG_KVM
             case QEMU_OPTION_enable_kvm:
                 kvm_allowed = 1;
+                emu_type = CFG_EMU_QEMU_KVM;
 #ifdef CONFIG_KQEMU
                 kqemu_allowed = 0;
 #endif
#1 lore raw
Quoted 5 lines · Jes Sorensen

Hi,

Here's a patch for QEMU which tells the BIOS it is running on QEMU/KQEMU/KVM.

Quoted 8 lines

I have a set if patches for Seabios using this to runtime select KVM and QEMU settings, eliminating the need for a specially compiled BIOS binary.

If we can agree on the interface, I would look into doing something similar for BOCHS as well.

I will be posting the Seabios patches in a minute.

The guest never runs on kvm or kqemu. It always runs on qemu, which may use kvm or kqemu for cpu virtualization.

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 3 lines · Avi Kivity

The guest never runs on kvm or kqemu. It always runs on qemu, which may use kvm or kqemu for cpu virtualization.

That is exactly why I designed it to have QEMU as the master emu version and then KVM/KQEMU etc. as the minor version.

However given our conversation yesterday, I am going to respin it as fw cfg features instead of the blank 'you are running on KVM' thing.

Cheers,
Jes