qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: kevin@koconnor.net
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH][SEABIOS] Move qemu config port access functions into separate file.
Date: Mon, 14 Sep 2009 15:51:41 +0300	[thread overview]
Message-ID: <20090914125141.GB30746@redhat.com> (raw)

Move qemu config code from smbios.c to its own files. Add support for
-boot menu=on|off qemu option.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
diff --git a/Makefile b/Makefile
index ec30f39..a7dd8c8 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ OUT=out/
 # Source files
 SRCBOTH=output.c util.c block.c floppy.c ata.c misc.c mouse.c kbd.c pci.c \
         serial.c clock.c pic.c cdrom.c ps2port.c smp.c resume.c \
-        pnpbios.c pirtable.c vgahooks.c pmm.c ramdisk.c
+        pnpbios.c pirtable.c vgahooks.c pmm.c ramdisk.c pv.c
 SRC16=$(SRCBOTH) system.c disk.c apm.c pcibios.c font.c
 SRC32=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \
       acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
diff --git a/src/boot.c b/src/boot.c
index b70d49c..083d5b9 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -12,6 +12,7 @@
 #include "bregs.h" // struct bregs
 #include "boot.h" // struct ipl_s
 #include "cmos.h" // inb_cmos
+#include "pv.h"
 
 struct ipl_s IPL;
 
@@ -297,7 +298,8 @@ boot_prep()
         return;
 
     // Allow user to modify BCV/IPL order.
-    interactive_bootmenu();
+    if (qemu_cfg_show_boot_menu())
+        interactive_bootmenu();
 
     // Setup floppy boot order
     int override = IPL.bev[0].subchoice;
diff --git a/src/post.c b/src/post.c
index e2569b0..bd638f8 100644
--- a/src/post.c
+++ b/src/post.c
@@ -19,6 +19,7 @@
 #include "bregs.h" // struct bregs
 #include "mptable.h" // mptable_init
 #include "boot.h" // IPL
+#include "pv.h"
 
 void
 __set_irq(int vector, void *loc)
@@ -182,6 +183,8 @@ post()
     serial_setup();
     mouse_setup();
 
+    qemu_cfg_port_probe();
+
     init_bios_tables();
 
     boot_setup();
diff --git a/src/pv.c b/src/pv.c
new file mode 100644
index 0000000..1e2033c
--- /dev/null
+++ b/src/pv.c
@@ -0,0 +1,62 @@
+#include "config.h"
+#include "ioport.h"
+#include "pv.h"
+
+int qemu_cfg_present;
+
+static void
+qemu_cfg_select(u16 f)
+{
+    outw(f, QEMU_CFG_CTL_PORT);
+}
+
+static void
+qemu_cfg_read(u8 *buf, int len)
+{
+    while (len--)
+        *(buf++) = inb(PORT_QEMU_CFG_DATA);
+}
+
+static void
+qemu_cfg_read_entry(void *buf, int e, int len)
+{
+    qemu_cfg_select(e);
+    qemu_cfg_read(buf, len);
+}
+
+void qemu_cfg_port_probe(void)
+{
+    char *sig = "QEMU";
+    int i;
+
+    qemu_cfg_present = 1;
+
+    qemu_cfg_select(QEMU_CFG_SIGNATURE);
+
+    for (i = 0; i < 4; i++)
+        if (inb(QEMU_CFG_DATA_PORT) != sig[i]) {
+            qemu_cfg_present = 0;
+            break;
+        }
+    dprintf(4, "qemu_cfg_present=%d\n", qemu_cfg_present);
+}
+
+void qemu_cfg_get_uuid(u8 *uuid)
+{
+    if (!qemu_cfg_present)
+        return;
+
+    qemu_cfg_read_entry(uuid, QEMU_CFG_UUID, 16);
+}
+
+int qemu_cfg_show_boot_menu(void)
+{
+    u16 v;
+    if (!qemu_cfg_present)
+        return 1;
+
+    qemu_cfg_read_entry(&v, QEMU_CFG_BOOT_MENU, sizeof(v));
+
+    return v;
+}
+
diff --git a/src/pv.h b/src/pv.h
new file mode 100644
index 0000000..d4bca80
--- /dev/null
+++ b/src/pv.h
@@ -0,0 +1,46 @@
+#ifndef __PV_H
+#define __PV_H
+
+#include "util.h"
+
+/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx.  It
+ * should be used to determine that a VM is running under KVM.
+ */
+#define KVM_CPUID_SIGNATURE     0x40000000
+
+static inline int kvm_para_available(void)
+{
+    unsigned int eax, ebx, ecx, edx;
+    char signature[13];
+
+    cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
+    memcpy(signature + 0, &ebx, 4);
+    memcpy(signature + 4, &ecx, 4);
+    memcpy(signature + 8, &edx, 4);
+    signature[12] = 0;
+
+    if (strcmp(signature, "KVMKVMKVM") == 0)
+        return 1;
+
+    return 0;
+}
+
+#define QEMU_CFG_CTL_PORT		0x510
+#define QEMU_CFG_DATA_PORT		0x511
+#define QEMU_CFG_SIGNATURE		0x00
+#define QEMU_CFG_ID			0x01
+#define QEMU_CFG_UUID			0x02
+#define QEMU_CFG_NUMA			0x0d
+#define QEMU_CFG_BOOT_MENU		0x0e
+#define QEMU_CFG_MAX_CPUS		0x0f
+#define QEMU_CFG_ARCH_LOCAL		0x8000
+#define QEMU_CFG_ACPI_TABLES		(QEMU_CFG_ARCH_LOCAL + 0)
+#define QEMU_CFG_SMBIOS_ENTRIES		(QEMU_CFG_ARCH_LOCAL + 1)
+
+extern int qemu_cfg_present;
+
+void qemu_cfg_port_probe(void);
+int qemu_cfg_show_boot_menu(void);
+void qemu_cfg_get_uuid(u8 *uuid);
+
+#endif
diff --git a/src/smbios.c b/src/smbios.c
index 6fbddd9..3223b80 100644
--- a/src/smbios.c
+++ b/src/smbios.c
@@ -7,7 +7,7 @@
 
 #include "util.h" // dprintf
 #include "biosvar.h" // GET_EBDA
-
+#include "pv.h"
 
 /****************************************************************
  * UUID probe
@@ -18,23 +18,6 @@
 #define QEMU_CFG_UUID       0x02
 
 static void
-qemu_cfg_read(u8 *buf, u16 f, int len)
-{
-    outw(f, PORT_QEMU_CFG_CTL);
-    while (len--)
-        *(buf++) = inb(PORT_QEMU_CFG_DATA);
-}
-
-static int
-qemu_cfg_port_probe()
-{
-    u8 sig[4] = "QEMU";
-    u8 buf[4];
-    qemu_cfg_read(buf, QEMU_CFG_SIGNATURE, 4);
-    return *(u32*)buf == *(u32*)sig;
-}
-
-static void
 uuid_probe(u8 *bios_uuid)
 {
     // Default to UUID not set
@@ -44,11 +27,8 @@ uuid_probe(u8 *bios_uuid)
         return;
     if (CONFIG_COREBOOT)
         return;
-    if (! qemu_cfg_port_probe())
-        // Feature not available
-        return;
 
-    qemu_cfg_read(bios_uuid, QEMU_CFG_UUID, 16);
+    qemu_cfg_get_uuid(bios_uuid);
 }
 
 
--
			Gleb.

             reply	other threads:[~2009-09-14 12:51 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-14 12:51 Gleb Natapov [this message]
2009-09-15  0:08 ` [Qemu-devel] Re: [PATCH][SEABIOS] Move qemu config port access functions into separate file Kevin O'Connor
2009-09-15  5:43   ` Gleb Natapov
2009-09-16  2:02     ` Kevin O'Connor
2009-09-17  9:57       ` Gleb Natapov
2009-09-18  1:24         ` Kevin O'Connor
2009-09-18 10:01           ` Gleb Natapov
2009-09-19 15:16             ` Kevin O'Connor
2009-09-19 17:56               ` Gleb Natapov
2009-09-30  1:09                 ` Kevin O'Connor
2009-09-30  6:35                   ` Gleb Natapov
2009-09-30 17:17                     ` Blue Swirl
2009-09-30 17:31                       ` Gleb Natapov
2009-10-02  1:08                       ` Kevin O'Connor
2009-10-01 16:35   ` Gleb Natapov
2009-10-02  0:51     ` Kevin O'Connor
2009-10-02 14:03       ` Gleb Natapov
2009-10-02 16:52         ` Kevin O'Connor
2009-10-02 18:10           ` Gleb Natapov
2009-10-02 19:31             ` Kevin O'Connor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090914125141.GB30746@redhat.com \
    --to=gleb@redhat.com \
    --cc=kevin@koconnor.net \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).