Patchwork FW_CFG_EMULATOR

login
register
mail settings
Submitter Jes Sorensen
Date Aug. 3, 2009, 3:05 p.m.
Message ID <4A76FCC5.2020803@sgi.com>
Download mbox | patch
Permalink /patch/30599/
State Superseded
Headers show

Comments

Jes Sorensen - Aug. 3, 2009, 3:05 p.m.
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
Avi Kivity - Aug. 5, 2009, 10:59 a.m.
On 08/03/2009 06:05 PM, Jes Sorensen wrote:
> 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.

The guest never runs on kvm or kqemu.  It always runs on qemu, which may 
use kvm or kqemu for cpu virtualization.
Jes Sorensen - Aug. 5, 2009, 12:26 p.m.
On 08/05/2009 12:59 PM, Avi Kivity wrote:
> 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

Patch

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(-)

Index: qemu/hw/fw_cfg.c
===================================================================
--- qemu.orig/hw/fw_cfg.c
+++ 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);
Index: qemu/hw/fw_cfg.h
===================================================================
--- qemu.orig/hw/fw_cfg.h
+++ 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);
 
Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c
+++ 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