qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 0/6] Add UUID command-line option
@ 2008-08-28 16:52 Gleb Natapov
  2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication Gleb Natapov
                   ` (5 more replies)
  0 siblings, 6 replies; 20+ messages in thread
From: Gleb Natapov @ 2008-08-28 16:52 UTC (permalink / raw)
  To: qemu-devel

This patch series implements simple qemu<->bios communication channel
using IO port in patch 1. Patches 2-5 implement UUID support. Patch 6
implements CPU speed detection needed by SMBIOS.

---

Gleb Natapov (6):
      Pass cpu speed into SM BIOS.
      Add UUID to firmware configuration info.
      Use libuuid if available.
      Add "info uuid" command to monitor.
      Add -uuid command line option.
      Use IO port for qemu<->guest BIOS communication.


 Makefile.target |    5 +
 configure       |   21 ++++++
 hw/fw_cfg.c     |  201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/fw_cfg.h     |   16 ++++
 hw/pc.c         |   99 +++++++++++++++++++++++++++
 hw/sun4m.c      |   20 +++++
 hw/sun4u.c      |    7 ++
 monitor.c       |   11 +++
 sysemu.h        |    2 +
 vl.c            |   45 ++++++++++++
 10 files changed, 427 insertions(+), 0 deletions(-)
 create mode 100644 hw/fw_cfg.c
 create mode 100644 hw/fw_cfg.h

-- 
        Gleb.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-28 16:52 [Qemu-devel] [PATCH v3 0/6] Add UUID command-line option Gleb Natapov
@ 2008-08-28 16:52 ` Gleb Natapov
  2008-08-28 17:57   ` Blue Swirl
  2008-08-28 18:04   ` Blue Swirl
  2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 2/6] Add -uuid command line option Gleb Natapov
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 20+ messages in thread
From: Gleb Natapov @ 2008-08-28 16:52 UTC (permalink / raw)
  To: qemu-devel

Use PIO to get configuration info between qemu process and guest BIOS.

Signed-off-by: Gleb Natapov <gleb@qumranet.com>
---

 Makefile.target |    1 
 hw/fw_cfg.c     |  199 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/fw_cfg.h     |   15 ++++
 hw/pc.c         |    9 ++
 hw/sun4m.c      |   20 ++++++
 hw/sun4u.c      |    7 ++
 6 files changed, 251 insertions(+), 0 deletions(-)
 create mode 100644 hw/fw_cfg.c
 create mode 100644 hw/fw_cfg.h

diff --git a/Makefile.target b/Makefile.target
index 2464484..02bb553 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -473,6 +473,7 @@ endif #CONFIG_DARWIN_USER
 ifndef CONFIG_USER_ONLY
 
 OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o net-checksum.o
+OBJS+=fw_cfg.o
 ifdef CONFIG_WIN32
 OBJS+=block-raw-win32.o
 else
diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
new file mode 100644
index 0000000..e36224e
--- /dev/null
+++ b/hw/fw_cfg.c
@@ -0,0 +1,199 @@
+/*
+ * QEMU Firmware configuration device emulation
+ *
+ * Copyright (c) 2008 Gleb Natapov
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "hw.h"
+#include "isa.h"
+#include "fw_cfg.h"
+
+/* debug firmware config */
+//#define DEBUG_FW_CFG
+
+#ifdef DEBUG_FW_CFG
+#define FW_CFG_DPRINTF(fmt, args...)                     \
+    do { printf("FW_CFG: " fmt , ##args); } while (0)
+#else
+#define FW_CFG_DPRINTF(fmt, args...)
+#endif
+
+#define FW_CFG_SIZE 2
+
+typedef struct _FWCfgEntry {
+    uint16_t len;
+    uint8_t *data;
+} FWCfgEntry;
+
+typedef struct _FWCfgState {
+    FWCfgEntry entries[2][FW_CFG_MAX_ENTRY];
+    uint16_t cur_entry;
+    uint16_t cur_offset;
+} FWCfgState;
+
+static int fw_cfg_select(FWCfgState *s, uint16_t key)
+{
+    int ret;
+
+    s->cur_offset = 0;
+    if ((key & ~FW_CFG_ARCH_LOCAL) >= FW_CFG_MAX_ENTRY) {
+        s->cur_entry = 0xffff;
+        ret = 0;
+    } else {
+        s->cur_entry = key;
+        ret = 1;
+    }
+
+    FW_CFG_DPRINTF("select key %d (%sfound)\n", key, ret ? "" : "not ");
+
+    return ret;
+}
+
+static uint8_t fw_cfg_read(FWCfgState *s)
+{
+    int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
+    FWCfgEntry *e = &s->entries[arch][s->cur_entry & ~FW_CFG_ARCH_LOCAL];
+    uint8_t ret;
+
+    if (s->cur_entry == 0xffff || !e->data || s->cur_offset >= e->len)
+        ret = 0;
+    else
+        ret = e->data[s->cur_offset++];
+
+    FW_CFG_DPRINTF("read %d\n", ret);
+
+    return ret;
+}
+
+static uint32_t fw_cfg_io_readb(void *opaque, uint32_t addr)
+{
+    return fw_cfg_read(opaque);
+}
+
+static void fw_cfg_io_writew(void *opaque, uint32_t addr, uint32_t value)
+{
+    fw_cfg_select(opaque, (uint16_t)value);
+}
+
+static uint32_t fw_cfg_mem_readb(void *opaque, target_phys_addr_t addr)
+{
+    return fw_cfg_read(opaque);
+}
+
+static void fw_cfg_mem_writew(void *opaque, target_phys_addr_t addr,
+                              uint32_t value)
+{
+    fw_cfg_select(opaque, (uint16_t)value);
+}
+
+static CPUReadMemoryFunc *fw_cfg_mem_read[3] = {
+    fw_cfg_mem_readb,
+    NULL,
+    NULL,
+};
+
+static CPUWriteMemoryFunc *fw_cfg_mem_write[3] = {
+    NULL,
+    fw_cfg_mem_writew,
+    NULL,
+};
+
+static void fw_cfg_reset(void *opaque)
+{
+    FWCfgState *s = opaque;
+
+    fw_cfg_select(s, 0);
+}
+
+static void fw_cfg_save(QEMUFile *f, void *opaque)
+{
+    FWCfgState *s = opaque;
+    unsigned int i;
+
+    for (i = 0; i < FW_CFG_MAX_ENTRY; i++) {
+        qemu_put_be16s(f, &s->entries[0][i].len);
+        qemu_put_buffer(f, s->entries[0][i].data, s->entries[0][i].len);
+
+        qemu_put_be16s(f, &s->entries[1][i].len);
+        qemu_put_buffer(f, s->entries[1][i].data, s->entries[1][i].len);
+    }
+}
+
+static int fw_cfg_load(QEMUFile *f, void *opaque, int version_id)
+{
+    FWCfgState *s = opaque;
+    unsigned int i;
+
+    if (version_id > 1)
+        return -EINVAL;
+
+    for (i = 0; i < FW_CFG_MAX_ENTRY; i++) {
+        qemu_get_be16s(f, &s->entries[0][i].len);
+        qemu_get_buffer(f, s->entries[0][i].data, s->entries[0][i].len);
+
+        qemu_get_be16s(f, &s->entries[1][i].len);
+        qemu_get_buffer(f, s->entries[1][i].data, s->entries[1][i].len);
+    }
+
+    return 0;
+}
+
+int fw_cfg_add(void *opaque, uint16_t key, uint8_t *data, uint16_t len)
+{
+    FWCfgState *s = opaque;
+    int arch = !!(key & FW_CFG_ARCH_LOCAL);
+
+    key &= (~FW_CFG_ARCH_LOCAL);
+
+    if (key >= FW_CFG_MAX_ENTRY)
+        return 0;
+
+    s->entries[arch][key].data = data;
+    s->entries[arch][key].len = len;
+
+    return 1;
+}
+
+void *fw_cfg_init(uint32_t port, target_phys_addr_t addr)
+{
+    FWCfgState *s;
+    int io_memory;
+
+    s = qemu_mallocz(sizeof(FWCfgState));
+    if (!s)
+        return NULL;
+
+    if (port) {
+        register_ioport_read(port, 1, 1, fw_cfg_io_readb, s);
+        register_ioport_write(port, 2, 2, fw_cfg_io_writew, s);
+    }
+    if (addr) {
+        io_memory = cpu_register_io_memory(0, fw_cfg_mem_read,
+                                           fw_cfg_mem_write, s);
+        cpu_register_physical_memory(addr, FW_CFG_SIZE, io_memory);
+
+    }
+    fw_cfg_add(s, FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
+    register_savevm("fw_cfg", -1, 1, fw_cfg_save, fw_cfg_load, s);
+    qemu_register_reset(fw_cfg_reset, s);
+    fw_cfg_reset(s);
+
+    return s;
+}
diff --git a/hw/fw_cfg.h b/hw/fw_cfg.h
new file mode 100644
index 0000000..aa8ebe7
--- /dev/null
+++ b/hw/fw_cfg.h
@@ -0,0 +1,15 @@
+#ifndef FW_CFG_H
+#define FW_CFG_H
+
+#define FW_CFG_SIGNATURE        0x00
+#define FW_CFG_ID               0x01
+#define FW_CFG_MAX_ENTRY        0x10
+
+#define FW_CFG_ARCH_LOCAL       0x8000
+
+#ifndef __ASSEMBLY__
+int fw_cfg_add(void *opaque, uint16_t key, uint8_t *data, uint16_t len);
+void *fw_cfg_init(uint32_t port, target_phys_addr_t addr);
+#endif /* __ASSEMBLY__ */
+
+#endif
diff --git a/hw/pc.c b/hw/pc.c
index 213ead8..938c449 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -32,6 +32,7 @@
 #include "smbus.h"
 #include "boards.h"
 #include "console.h"
+#include "fw_cfg.h"
 
 /* output Bochs bios info messages */
 //#define DEBUG_BIOS
@@ -44,6 +45,7 @@
 
 /* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables.  */
 #define ACPI_DATA_SIZE       0x10000
+#define BIOS_CFG_IOPORT 0x510
 
 #define MAX_IDE_BUS 2
 
@@ -416,6 +418,9 @@ static void bochs_bios_write(void *opaque, uint32_t addr, uint32_t val)
 
 static void bochs_bios_init(void)
 {
+    static const uint32_t bios_cfg_id = 1;
+    void *fw_cfg;
+
     register_ioport_write(0x400, 1, 2, bochs_bios_write, NULL);
     register_ioport_write(0x401, 1, 2, bochs_bios_write, NULL);
     register_ioport_write(0x402, 1, 1, bochs_bios_write, NULL);
@@ -426,6 +431,10 @@ static void bochs_bios_init(void)
     register_ioport_write(0x502, 1, 2, bochs_bios_write, NULL);
     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, 0);
+    fw_cfg_add(fw_cfg, FW_CFG_ID, (uint8_t *)&bios_cfg_id,
+               sizeof(bios_cfg_id));
 }
 
 /* Generate an initial boot sector which sets state and jump to
diff --git a/hw/sun4m.c b/hw/sun4m.c
index 21f8899..861e604 100644
--- a/hw/sun4m.c
+++ b/hw/sun4m.c
@@ -34,6 +34,7 @@
 #include "scsi.h"
 #include "pc.h"
 #include "isa.h"
+#include "fw_cfg.h"
 
 //#define DEBUG_IRQ
 
@@ -78,6 +79,7 @@
 #define PROM_SIZE_MAX        (512 * 1024)
 #define PROM_VADDR           0xffd00000
 #define PROM_FILENAME        "openbios-sparc32"
+#define CFG_ADDR             0xd00001234ULL
 
 // Control plane, 8-bit and 24-bit planes
 #define TCX_SIZE             (9 * 1024 * 1024)
@@ -410,6 +412,8 @@ static void sun4m_hw_init(const struct hwdef *hwdef, ram_addr_t RAM_size,
     char buf[1024];
     BlockDriverState *fd[MAX_FD];
     int drive_index;
+    static const uint32_t bios_cfg_id = 1;
+    void *fw_cfg;
 
     /* init CPUs */
     if (!cpu_model)
@@ -570,6 +574,10 @@ static void sun4m_hw_init(const struct hwdef *hwdef, ram_addr_t RAM_size,
     if (hwdef->ecc_base != (target_phys_addr_t)-1)
         ecc_init(hwdef->ecc_base, slavio_irq[hwdef->ecc_irq],
                  hwdef->ecc_version);
+
+    fw_cfg = fw_cfg_init(0, CFG_ADDR);
+    fw_cfg_add(fw_cfg, FW_CFG_ID, (uint8_t *)&bios_cfg_id,
+               sizeof(bios_cfg_id));
 }
 
 static void sun4c_hw_init(const struct hwdef *hwdef, ram_addr_t RAM_size,
@@ -589,6 +597,8 @@ static void sun4c_hw_init(const struct hwdef *hwdef, ram_addr_t RAM_size,
     char buf[1024];
     BlockDriverState *fd[MAX_FD];
     int drive_index;
+    static const uint32_t bios_cfg_id = 1;
+    void *fw_cfg;
 
     /* init CPU */
     if (!cpu_model)
@@ -715,6 +725,10 @@ static void sun4c_hw_init(const struct hwdef *hwdef, ram_addr_t RAM_size,
     nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
                boot_device, RAM_size, kernel_size, graphic_width,
                graphic_height, graphic_depth, hwdef->machine_id, "Sun4c");
+
+    fw_cfg = fw_cfg_init(0, CFG_ADDR);
+    fw_cfg_add(fw_cfg, FW_CFG_ID, (uint8_t *)&bios_cfg_id,
+               sizeof(bios_cfg_id));
 }
 
 static const struct hwdef hwdefs[] = {
@@ -1405,6 +1419,8 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
     int ret;
     char buf[1024];
     int drive_index;
+    static const uint32_t bios_cfg_id = 1;
+    void *fw_cfg;
 
     /* init CPUs */
     if (!cpu_model)
@@ -1528,6 +1544,10 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
     nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
                boot_device, RAM_size, kernel_size, graphic_width,
                graphic_height, graphic_depth, hwdef->machine_id, "Sun4d");
+
+    fw_cfg = fw_cfg_init(0, CFG_ADDR);
+    fw_cfg_add(fw_cfg, FW_CFG_ID, (uint8_t *)&bios_cfg_id,
+               sizeof(bios_cfg_id));
 }
 
 /* SPARCserver 1000 hardware initialisation */
diff --git a/hw/sun4u.c b/hw/sun4u.c
index 42a765d..42b784c 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -31,6 +31,7 @@
 #include "sysemu.h"
 #include "boards.h"
 #include "firmware_abi.h"
+#include "fw_cfg.h"
 
 #define KERNEL_LOAD_ADDR     0x00404000
 #define CMDLINE_ADDR         0x003ff000
@@ -44,6 +45,7 @@
 #define PROM_FILENAME        "openbios-sparc64"
 #define NVRAM_SIZE           0x2000
 #define MAX_IDE_BUS          2
+#define CFG_ADDR             0x1fe004001234ULL
 
 struct hwdef {
     const char * const default_cpu_model;
@@ -270,6 +272,8 @@ static void sun4uv_init(ram_addr_t RAM_size, int vga_ram_size,
     int drive_index;
     BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     BlockDriverState *fd[MAX_FD];
+    static const uint32_t bios_cfg_id = 1;
+    void *fw_cfg;
 
     linux_boot = (kernel_filename != NULL);
 
@@ -415,6 +419,9 @@ static void sun4uv_init(ram_addr_t RAM_size, int vga_ram_size,
                            graphic_width, graphic_height, graphic_depth,
                            (uint8_t *)&nd_table[0].macaddr);
 
+    fw_cfg = fw_cfg_init(0, CFG_ADDR);
+    fw_cfg_add(fw_cfg, FW_CFG_ID, (uint8_t *)&bios_cfg_id,
+               sizeof(bios_cfg_id));
 }
 
 static const struct hwdef hwdefs[] = {

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v3 2/6] Add -uuid command line option.
  2008-08-28 16:52 [Qemu-devel] [PATCH v3 0/6] Add UUID command-line option Gleb Natapov
  2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication Gleb Natapov
@ 2008-08-28 16:52 ` Gleb Natapov
  2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 3/6] Add "info uuid" command to monitor Gleb Natapov
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 20+ messages in thread
From: Gleb Natapov @ 2008-08-28 16:52 UTC (permalink / raw)
  To: qemu-devel

Let user specify UUID of the virtual machine.

Signed-off-by: Gleb Natapov <gleb@qumranet.com>
---

 sysemu.h |    2 ++
 vl.c     |   29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/sysemu.h b/sysemu.h
index b12fae0..931ac3a 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -8,6 +8,8 @@ extern const char *bios_dir;
 
 extern int vm_running;
 extern const char *qemu_name;
+extern uint8_t qemu_uuid[];
+#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
 
 typedef struct vm_change_state_entry VMChangeStateEntry;
 typedef void VMChangeStateHandler(void *opaque, int running);
diff --git a/vl.c b/vl.c
index 245177a..30fef2a 100644
--- a/vl.c
+++ b/vl.c
@@ -257,6 +257,8 @@ static int64_t qemu_icount_bias;
 QEMUTimer *icount_rt_timer;
 QEMUTimer *icount_vm_timer;
 
+uint8_t qemu_uuid[16];
+
 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
 
 /***********************************************************/
@@ -7710,6 +7712,7 @@ static void help(int exitcode)
            "-g WxH[xDEPTH]  Set the initial graphical resolution and depth\n"
 #endif
            "-name string    set the name of the guest\n"
+           "-uuid %%08x-%%04x-%%04x-%%04x-%%012x specify machine UUID\n"
            "\n"
            "Network options:\n"
            "-net nic[,vlan=n][,macaddr=addr][,model=type]\n"
@@ -7904,6 +7907,7 @@ enum {
     QEMU_OPTION_startdate,
     QEMU_OPTION_tb_size,
     QEMU_OPTION_icount,
+    QEMU_OPTION_uuid,
 };
 
 typedef struct QEMUOption {
@@ -7992,6 +7996,7 @@ const QEMUOption qemu_options[] = {
 #ifdef CONFIG_CURSES
     { "curses", 0, QEMU_OPTION_curses },
 #endif
+    { "uuid", HAS_ARG, QEMU_OPTION_uuid },
 
     /* temporary options */
     { "usb", 0, QEMU_OPTION_usb },
@@ -8202,6 +8207,23 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
 }
 #endif
 
+static int qemu_uuid_parse(const char *str, uint8_t *uuid)
+{
+    int ret;
+
+    if(strlen(str) != 36)
+        return -1;
+
+    ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3],
+            &uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9],
+            &uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14], &uuid[15]);
+
+    if(ret != 16)
+        return -1;
+
+    return 0;
+}
+
 #define MAX_NET_CLIENTS 32
 
 #ifndef _WIN32
@@ -8780,6 +8802,13 @@ int main(int argc, char **argv)
             case QEMU_OPTION_show_cursor:
                 cursor_hide = 0;
                 break;
+            case QEMU_OPTION_uuid:
+                if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
+                    fprintf(stderr, "Fail to parse UUID string."
+                            " Wrong format.\n");
+                    exit(1);
+                }
+                break;
 	    case QEMU_OPTION_daemonize:
 		daemonize = 1;
 		break;

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v3 3/6] Add "info uuid" command to monitor.
  2008-08-28 16:52 [Qemu-devel] [PATCH v3 0/6] Add UUID command-line option Gleb Natapov
  2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication Gleb Natapov
  2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 2/6] Add -uuid command line option Gleb Natapov
@ 2008-08-28 16:52 ` Gleb Natapov
  2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 4/6] Use libuuid if available Gleb Natapov
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 20+ messages in thread
From: Gleb Natapov @ 2008-08-28 16:52 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Gleb Natapov <gleb@qumranet.com>
---

 monitor.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/monitor.c b/monitor.c
index e71f49e..314c71e 100644
--- a/monitor.c
+++ b/monitor.c
@@ -253,6 +253,15 @@ static void do_info_name(void)
         term_printf("%s\n", qemu_name);
 }
 
+static void do_info_uuid(void)
+{
+    term_printf(UUID_FMT "\n", qemu_uuid[0], qemu_uuid[1], qemu_uuid[2],
+            qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], qemu_uuid[6],
+            qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], qemu_uuid[10],
+            qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], qemu_uuid[14],
+            qemu_uuid[15]);
+}
+
 static void do_info_block(void)
 {
     bdrv_info();
@@ -1501,6 +1510,8 @@ static term_cmd_t info_cmds[] = {
       "", "show the vnc server status"},
     { "name", "", do_info_name,
       "", "show the current VM name" },
+    { "uuid", "", do_info_uuid,
+      "", "show the current VM UUID" },
 #if defined(TARGET_PPC)
     { "cpustats", "", do_info_cpu_stats,
       "", "show CPU statistics", },

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v3 4/6] Use libuuid if available.
  2008-08-28 16:52 [Qemu-devel] [PATCH v3 0/6] Add UUID command-line option Gleb Natapov
                   ` (2 preceding siblings ...)
  2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 3/6] Add "info uuid" command to monitor Gleb Natapov
@ 2008-08-28 16:52 ` Gleb Natapov
  2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 5/6] Add UUID to firmware configuration info Gleb Natapov
  2008-08-28 16:53 ` [Qemu-devel] [PATCH v3 6/6] Pass cpu speed into SM BIOS Gleb Natapov
  5 siblings, 0 replies; 20+ messages in thread
From: Gleb Natapov @ 2008-08-28 16:52 UTC (permalink / raw)
  To: qemu-devel

If libuuid is available use it for UUID generation in case a user asks for it.

Signed-off-by: Gleb Natapov <gleb@qumranet.com>
---

 Makefile.target |    4 ++++
 configure       |   21 +++++++++++++++++++++
 vl.c            |   16 ++++++++++++++++
 3 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index 02bb553..681073d 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -519,6 +519,10 @@ CPPFLAGS += $(CONFIG_VNC_TLS_CFLAGS)
 LIBS += $(CONFIG_VNC_TLS_LIBS)
 endif
 
+ifdef CONFIG_UUID
+LIBS += -luuid
+endif
+
 # SCSI layer
 OBJS+= lsi53c895a.o esp.o
 
diff --git a/configure b/configure
index acb4a4a..fa46a64 100755
--- a/configure
+++ b/configure
@@ -110,6 +110,7 @@ curses="yes"
 aio="yes"
 nptl="yes"
 mixemu="no"
+uuid="yes"
 
 # OS specific
 targetos=`uname -s`
@@ -316,6 +317,8 @@ for opt do
   ;;
   --enable-uname-release=*) uname_release="$optarg"
   ;;
+  --disable-uuid) uuid="no"
+  ;;
   --sparc_cpu=*)
       sparc_cpu="$optarg"
       case $sparc_cpu in
@@ -780,6 +783,19 @@ EOF
 fi
 
 ##########################################
+# uuid library
+if test "$uuid" = "yes" ; then
+  uuid=no
+  cat > $TMPC << EOF
+#include <uuid/uuid.h>
+int main(void) { uuid_t u; return 0; }
+EOF
+  if $cc -o $TMPE $TMPC -luuid 2> /dev/null ; then
+    uuid=yes
+  fi
+fi
+
+##########################################
 # Sound support libraries probe
 
 audio_drv_probe()
@@ -961,6 +977,7 @@ echo "uname -r          $uname_release"
 echo "NPTL support      $nptl"
 echo "vde support       $vde"
 echo "AIO support       $aio"
+echo "UUID support      $uuid"
 
 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -1168,6 +1185,10 @@ if test "$vnc_tls" = "yes" ; then
   echo "CONFIG_VNC_TLS_LIBS=$vnc_tls_libs" >> $config_mak
   echo "#define CONFIG_VNC_TLS 1" >> $config_h
 fi
+if test "$uuid" = "yes" ; then
+  echo "CONFIG_UUID=yes" >> $config_mak
+  echo "#define CONFIG_UUID 1" >> $config_h
+fi
 qemu_version=`head $source_path/VERSION`
 echo "VERSION=$qemu_version" >>$config_mak
 echo "#define QEMU_VERSION \"$qemu_version\"" >> $config_h
diff --git a/vl.c b/vl.c
index 30fef2a..655dd3c 100644
--- a/vl.c
+++ b/vl.c
@@ -142,6 +142,11 @@ int inet_aton(const char *cp, struct in_addr *ia);
 
 #include "exec-all.h"
 
+#ifdef CONFIG_UUID
+#include <uuid/uuid.h>
+static int generate_uuid;
+#endif
+
 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
 #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
 #ifdef __sun__
@@ -8803,6 +8808,12 @@ int main(int argc, char **argv)
                 cursor_hide = 0;
                 break;
             case QEMU_OPTION_uuid:
+#ifdef CONFIG_UUID
+                if (strcmp(optarg, "gen") == 0) {
+                    generate_uuid = 1;
+                    break;
+                }
+#endif
                 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
                     fprintf(stderr, "Fail to parse UUID string."
                             " Wrong format.\n");
@@ -8908,6 +8919,11 @@ int main(int argc, char **argv)
            monitor_device = "stdio";
     }
 
+#if CONFIG_UUID
+    if (generate_uuid)
+        uuid_generate(qemu_uuid);
+#endif
+
 #ifndef _WIN32
     if (daemonize) {
 	pid_t pid;

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v3 5/6] Add UUID to firmware configuration info.
  2008-08-28 16:52 [Qemu-devel] [PATCH v3 0/6] Add UUID command-line option Gleb Natapov
                   ` (3 preceding siblings ...)
  2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 4/6] Use libuuid if available Gleb Natapov
@ 2008-08-28 16:52 ` Gleb Natapov
  2008-08-28 16:53 ` [Qemu-devel] [PATCH v3 6/6] Pass cpu speed into SM BIOS Gleb Natapov
  5 siblings, 0 replies; 20+ messages in thread
From: Gleb Natapov @ 2008-08-28 16:52 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Gleb Natapov <gleb@qumranet.com>
---

 hw/fw_cfg.c |    2 ++
 hw/fw_cfg.h |    1 +
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index e36224e..614a4a6 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "hw.h"
+#include "sysemu.h"
 #include "isa.h"
 #include "fw_cfg.h"
 
@@ -191,6 +192,7 @@ void *fw_cfg_init(uint32_t port, target_phys_addr_t addr)
 
     }
     fw_cfg_add(s, FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
+    fw_cfg_add(s, FW_CFG_UUID, qemu_uuid, 16);
     register_savevm("fw_cfg", -1, 1, fw_cfg_save, fw_cfg_load, s);
     qemu_register_reset(fw_cfg_reset, s);
     fw_cfg_reset(s);
diff --git a/hw/fw_cfg.h b/hw/fw_cfg.h
index aa8ebe7..baa445d 100644
--- a/hw/fw_cfg.h
+++ b/hw/fw_cfg.h
@@ -3,6 +3,7 @@
 
 #define FW_CFG_SIGNATURE        0x00
 #define FW_CFG_ID               0x01
+#define FW_CFG_UUID             0x02
 #define FW_CFG_MAX_ENTRY        0x10
 
 #define FW_CFG_ARCH_LOCAL       0x8000

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v3 6/6] Pass cpu speed into SM BIOS.
  2008-08-28 16:52 [Qemu-devel] [PATCH v3 0/6] Add UUID command-line option Gleb Natapov
                   ` (4 preceding siblings ...)
  2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 5/6] Add UUID to firmware configuration info Gleb Natapov
@ 2008-08-28 16:53 ` Gleb Natapov
  5 siblings, 0 replies; 20+ messages in thread
From: Gleb Natapov @ 2008-08-28 16:53 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Gleb Natapov <gleb@qumranet.com>
---

 hw/pc.c |   90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 90 insertions(+), 0 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index 938c449..8df71c4 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -49,6 +49,8 @@
 
 #define MAX_IDE_BUS 2
 
+#define FW_CFG_PC_CPUSPEED (FW_CFG_ARCH_LOCAL + 0x00)
+
 static fdctrl_t *floppy_controller;
 static RTCState *rtc_state;
 static PITState *pit;
@@ -369,6 +371,89 @@ static uint32_t ioport92_read(void *opaque, uint32_t addr)
     return ioport_get_a20() << 1;
 }
 
+#ifdef __linux__
+/* get_freq () function is taken from conky source code */
+#define CPUFREQ_PREFIX "/sys/devices/system/cpu"
+#define CPUFREQ_POSTFIX "cpufreq/scaling_cur_freq"
+
+/* return system frequency in MHz (use divisor=1) or GHz (use divisor=1000) */
+static double get_freq(int divisor, unsigned int cpu)
+{
+	FILE *f;
+	char frequency[32];
+	char s[256];
+	double freq = 0;
+
+	if (divisor <= 0)
+		return 0;
+
+	snprintf(s, 256, "%s/cpu%d/%s", CPUFREQ_PREFIX, cpu - 1, CPUFREQ_POSTFIX);
+	f = fopen(s, "r");
+	if (f) {
+		/* if there's a cpufreq /sys node, read the current frequency from
+		 * this node and divide by 1000 to get Mhz. */
+		if (fgets(s, sizeof(s), f)) {
+			s[strlen(s) - 1] = '\0';
+			freq = strtod(s, NULL);
+		}
+		fclose(f);
+		return (freq / 1000) / divisor;
+	}
+
+	// open the CPU information file
+	f = fopen("/proc/cpuinfo", "r");
+	if (!f) {
+		perror("Failed to access '/proc/cpuinfo' at get_freq()");
+		return 0;
+	}
+
+	// read the file
+	while (fgets(s, sizeof(s), f) != NULL) {
+
+#if defined(__i386) || defined(__x86_64)
+		// and search for the cpu mhz
+		if (strncmp(s, "cpu MHz", 7) == 0 && cpu == 0) {
+#else
+#if defined(__alpha)
+		// different on alpha
+		if (strncmp(s, "cycle frequency [Hz]", 20) == 0 && cpu == 0) {
+#else
+		// this is different on ppc for some reason
+		if (strncmp(s, "clock", 5) == 0 && cpu == 0) {
+#endif // defined(__alpha)
+#endif // defined(__i386) || defined(__x86_64)
+
+			// copy just the number
+			strcpy(frequency, strchr(s, ':') + 2);
+#if defined(__alpha)
+			// strip " est.\n"
+			frequency[strlen(frequency) - 6] = '\0';
+			// kernel reports in Hz
+			freq = strtod(frequency, NULL) / 1000000;
+#else
+			// strip \n
+			frequency[strlen(frequency) - 1] = '\0';
+			freq = strtod(frequency, NULL);
+#endif
+			break;
+		}
+		if (strncmp(s, "processor", 9) == 0) {
+			cpu--;
+			continue;
+		}
+	}
+
+	fclose(f);
+	return freq / divisor;
+}
+#else
+static double get_freq(int divisor, unsigned int cpu)
+{
+    return 0;
+}
+#endif
+
+
 /***********************************************************/
 /* Bochs BIOS debug ports */
 
@@ -419,6 +504,7 @@ static void bochs_bios_write(void *opaque, uint32_t addr, uint32_t val)
 static void bochs_bios_init(void)
 {
     static const uint32_t bios_cfg_id = 1;
+    static uint16_t cpu_speed;
     void *fw_cfg;
 
     register_ioport_write(0x400, 1, 2, bochs_bios_write, NULL);
@@ -432,9 +518,13 @@ 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);
 
+    cpu_speed = (uint16_t)get_freq(1, 1);
+
     fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, 0);
     fw_cfg_add(fw_cfg, FW_CFG_ID, (uint8_t *)&bios_cfg_id,
                sizeof(bios_cfg_id));
+    fw_cfg_add(fw_cfg, FW_CFG_PC_CPUSPEED, (uint8_t*)&cpu_speed,
+               sizeof(cpu_speed));
 }
 
 /* Generate an initial boot sector which sets state and jump to

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication Gleb Natapov
@ 2008-08-28 17:57   ` Blue Swirl
  2008-08-28 18:04   ` Blue Swirl
  1 sibling, 0 replies; 20+ messages in thread
From: Blue Swirl @ 2008-08-28 17:57 UTC (permalink / raw)
  To: qemu-devel

On 8/28/08, Gleb Natapov <gleb@qumranet.com> wrote:
> Use PIO to get configuration info between qemu process and guest BIOS.

Looking good ;-)

Sparc targets need these firmware_abi.h fields, and probably other targets too:
    uint64_t RAM0_size;
    uint64_t kernel_image;
    uint64_t kernel_size;
    uint64_t cmdline;
    uint64_t cmdline_size;
    uint16_t graphic_flags;
    uint8_t  nb_cpus;
    uint8_t  nboot_devices;
    uint8_t  boot_devices[0x10];

Maybe not all targets want these:
    uint16_t width;
    uint16_t height;
    uint16_t depth;

But before keys for these are added, it's not possible to migrate
Sparc targets to the new system. So should these be global?

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication Gleb Natapov
  2008-08-28 17:57   ` Blue Swirl
@ 2008-08-28 18:04   ` Blue Swirl
  2008-08-29 19:00     ` Gleb Natapov
  1 sibling, 1 reply; 20+ messages in thread
From: Blue Swirl @ 2008-08-28 18:04 UTC (permalink / raw)
  To: qemu-devel

On 8/28/08, Gleb Natapov <gleb@qumranet.com> wrote:
>  +    fw_cfg_add(fw_cfg, FW_CFG_ID, (uint8_t *)&bios_cfg_id,
>  +               sizeof(bios_cfg_id));

On second thought, this is in host byte order, which is not a good idea.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-28 18:04   ` Blue Swirl
@ 2008-08-29 19:00     ` Gleb Natapov
  2008-08-29 19:26       ` Blue Swirl
  2008-08-30 19:57       ` Blue Swirl
  0 siblings, 2 replies; 20+ messages in thread
From: Gleb Natapov @ 2008-08-29 19:00 UTC (permalink / raw)
  To: qemu-devel

On Thu, Aug 28, 2008 at 09:04:11PM +0300, Blue Swirl wrote:
> On 8/28/08, Gleb Natapov <gleb@qumranet.com> wrote:
> >  +    fw_cfg_add(fw_cfg, FW_CFG_ID, (uint8_t *)&bios_cfg_id,
> >  +               sizeof(bios_cfg_id));
> 
> On second thought, this is in host byte order, which is not a good idea.
> 
Is there some function to convert from host byte order to target byte
order?

--
			Gleb.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-29 19:00     ` Gleb Natapov
@ 2008-08-29 19:26       ` Blue Swirl
  2008-08-30 19:57       ` Blue Swirl
  1 sibling, 0 replies; 20+ messages in thread
From: Blue Swirl @ 2008-08-29 19:26 UTC (permalink / raw)
  To: qemu-devel

On 8/29/08, Gleb Natapov <gleb@qumranet.com> wrote:
> On Thu, Aug 28, 2008 at 09:04:11PM +0300, Blue Swirl wrote:
>  > On 8/28/08, Gleb Natapov <gleb@qumranet.com> wrote:
>  > >  +    fw_cfg_add(fw_cfg, FW_CFG_ID, (uint8_t *)&bios_cfg_id,
>  > >  +               sizeof(bios_cfg_id));
>  >
>  > On second thought, this is in host byte order, which is not a good idea.
>  >
>
> Is there some function to convert from host byte order to target byte
>  order?

Nothing generic like cpu_to_target.

Because the only read access method is byte by byte, we could use
little endian order and as a side benefit, the numbers would be
automatically zero extended as needed.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-29 19:00     ` Gleb Natapov
  2008-08-29 19:26       ` Blue Swirl
@ 2008-08-30 19:57       ` Blue Swirl
  2008-08-31 11:12         ` Gleb Natapov
  1 sibling, 1 reply; 20+ messages in thread
From: Blue Swirl @ 2008-08-30 19:57 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 2708 bytes --]

On 8/29/08, Gleb Natapov <gleb@qumranet.com> wrote:
> On Thu, Aug 28, 2008 at 09:04:11PM +0300, Blue Swirl wrote:
>  > On 8/28/08, Gleb Natapov <gleb@qumranet.com> wrote:
>  > >  +    fw_cfg_add(fw_cfg, FW_CFG_ID, (uint8_t *)&bios_cfg_id,
>  > >  +               sizeof(bios_cfg_id));
>  >
>  > On second thought, this is in host byte order, which is not a good idea.
>  >
>
> Is there some function to convert from host byte order to target byte
>  order?

I made an updated version of the patch 1/6, with explicit little
endian conversions. I'm not very happy with that. Another way would be
to add functions just to put different size numbers into device and
they would hide the conversion.

The second patch (after 6/6) adds keys for ram size, nographic flag,
number of CPUs and machine ID. I noticed that the other fields like
preloaded kernel location, initrd and command line should not be in
read-only storage so that BIOS can clear them and they will not be
valid after next reset. We could add a writable part to the
configuration device or a way to delete some entries but I think NVRAM
variables could be used instead.

Then I made a patch that takes the new device into use on
OpenBIOS/Sparc64. I found some bugs in the implementation, save and
load were wrong and FWCfgEntry.data should be const. The prototypes
with target_phys_addr_t cause compile failure on OpenBIOS, so
protecting them with something else than __ASSEMBLY__ should be added.
Maybe a PCI bridge or something between CPU and the device should do
byte swapping for outw.

But all in all, it seems to work. Sparc64 boots, UUID gets printed
correctly and added to OF tree:

OpenBIOS for Sparc64
Initializing PCI devices...
ide0: [io ports 0x1f0-0x1f7,0x3f6]
ide1: [io ports 0x170-0x177,0x376]
    drive0 [ATAPI cdrom]: QEMU DVD-ROM
floppy_init
FDC is a S82078B
floppy_reset
floppy_motor_off
SENSEI 20 00
status = 80, reply_buffer= 20 0
fdc_specify
FD_SPECIFY(c1, 11)
set_drive status = 80, new_dor = 10
floppy_recalibrate
fdc_state.version = 0062
Configuration device id QEMU version 1
kernel addr 404000 size 0
CPUs: 1 x SUNW,UltraSPARC-II
UUID: 10000000-2000-3000-4000-500000000000

No disk found.
Welcome to OpenBIOS v1.0RC1 built on Aug 30 2008 15:58
  Type 'help' for detailed information

[sparc64] Booting file 'disk' with parameters ''

0 > cd /  ok
0 > .properties
name                      "OpenBiosTeam,OpenBIOS"
#address-cells            2
#size-cells               2
compatible                "sun4u"
uuid                      -- 10 : 10 0 0 0 20 0 30 0 40 0 50 0 0 0 0 0
idprom                    -- 20 : 1 80 52 54 0 12 34 56 0 0 0 0 0 0 0
f7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
clock-frequency           1dcd6500
 ok

[-- Attachment #2: new_fw_abi.diff --]
[-- Type: plain/text, Size: 11966 bytes --]

[-- Attachment #3: fw_cfg_add_common_keys.diff --]
[-- Type: plain/text, Size: 12188 bytes --]

[-- Attachment #4: openbios_new_fw_abi.diff --]
[-- Type: plain/text, Size: 8896 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-30 19:57       ` Blue Swirl
@ 2008-08-31 11:12         ` Gleb Natapov
  2008-08-31 11:40           ` Blue Swirl
  2008-08-31 12:45           ` Blue Swirl
  0 siblings, 2 replies; 20+ messages in thread
From: Gleb Natapov @ 2008-08-31 11:12 UTC (permalink / raw)
  To: qemu-devel

On Sat, Aug 30, 2008 at 10:57:34PM +0300, Blue Swirl wrote:
> On 8/29/08, Gleb Natapov <gleb@qumranet.com> wrote:
> > On Thu, Aug 28, 2008 at 09:04:11PM +0300, Blue Swirl wrote:
> >  > On 8/28/08, Gleb Natapov <gleb@qumranet.com> wrote:
> >  > >  +    fw_cfg_add(fw_cfg, FW_CFG_ID, (uint8_t *)&bios_cfg_id,
> >  > >  +               sizeof(bios_cfg_id));
> >  >
> >  > On second thought, this is in host byte order, which is not a good idea.
> >  >
> >
> > Is there some function to convert from host byte order to target byte
> >  order?
> 
> I made an updated version of the patch 1/6, with explicit little
> endian conversions. I'm not very happy with that. Another way would be
> to add functions just to put different size numbers into device and
> they would hide the conversion.
> 
So what approach we should go with? We can go with the second one (add
functions for each type) and extend interface as needed.

--
			Gleb.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-31 11:12         ` Gleb Natapov
@ 2008-08-31 11:40           ` Blue Swirl
  2008-08-31 12:45           ` Blue Swirl
  1 sibling, 0 replies; 20+ messages in thread
From: Blue Swirl @ 2008-08-31 11:40 UTC (permalink / raw)
  To: qemu-devel

On 8/31/08, Gleb Natapov <gleb@qumranet.com> wrote:
> On Sat, Aug 30, 2008 at 10:57:34PM +0300, Blue Swirl wrote:
>  > On 8/29/08, Gleb Natapov <gleb@qumranet.com> wrote:
>  > > On Thu, Aug 28, 2008 at 09:04:11PM +0300, Blue Swirl wrote:
>  > >  > On 8/28/08, Gleb Natapov <gleb@qumranet.com> wrote:
>  > >  > >  +    fw_cfg_add(fw_cfg, FW_CFG_ID, (uint8_t *)&bios_cfg_id,
>  > >  > >  +               sizeof(bios_cfg_id));
>  > >  >
>  > >  > On second thought, this is in host byte order, which is not a good idea.
>  > >  >
>  > >
>  > > Is there some function to convert from host byte order to target byte
>  > >  order?
>  >
>  > I made an updated version of the patch 1/6, with explicit little
>  > endian conversions. I'm not very happy with that. Another way would be
>  > to add functions just to put different size numbers into device and
>  > they would hide the conversion.
>  >
>
> So what approach we should go with? We can go with the second one (add
>  functions for each type) and extend interface as needed.

Okay, I'll make a new version.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-31 11:12         ` Gleb Natapov
  2008-08-31 11:40           ` Blue Swirl
@ 2008-08-31 12:45           ` Blue Swirl
  2008-08-31 13:02             ` Gleb Natapov
  1 sibling, 1 reply; 20+ messages in thread
From: Blue Swirl @ 2008-08-31 12:45 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1128 bytes --]

On 8/31/08, Gleb Natapov <gleb@qumranet.com> wrote:
> On Sat, Aug 30, 2008 at 10:57:34PM +0300, Blue Swirl wrote:
>  > On 8/29/08, Gleb Natapov <gleb@qumranet.com> wrote:
>  > > On Thu, Aug 28, 2008 at 09:04:11PM +0300, Blue Swirl wrote:
>  > >  > On 8/28/08, Gleb Natapov <gleb@qumranet.com> wrote:
>  > >  > >  +    fw_cfg_add(fw_cfg, FW_CFG_ID, (uint8_t *)&bios_cfg_id,
>  > >  > >  +               sizeof(bios_cfg_id));
>  > >  >
>  > >  > On second thought, this is in host byte order, which is not a good idea.
>  > >  >
>  > >
>  > > Is there some function to convert from host byte order to target byte
>  > >  order?
>  >
>  > I made an updated version of the patch 1/6, with explicit little
>  > endian conversions. I'm not very happy with that. Another way would be
>  > to add functions just to put different size numbers into device and
>  > they would hide the conversion.
>  >
>
> So what approach we should go with? We can go with the second one (add
>  functions for each type) and extend interface as needed.

This version adds the functions, now the interface is much better. I
updated the other patches too.

[-- Attachment #2: new_fw_abi.diff --]
[-- Type: plain/text, Size: 11859 bytes --]

[-- Attachment #3: uuid_02_gn.diff --]
[-- Type: plain/text, Size: 6671 bytes --]

[-- Attachment #4: uuid_03_gn.diff --]
[-- Type: plain/text, Size: 4921 bytes --]

[-- Attachment #5: uuid_04_gn.diff --]
[-- Type: plain/text, Size: 7233 bytes --]

[-- Attachment #6: uuid_05_gn.diff --]
[-- Type: plain/text, Size: 4975 bytes --]

[-- Attachment #7: uuid_06_gn.diff --]
[-- Type: plain/text, Size: 7002 bytes --]

[-- Attachment #8: fw_cfg_add_common_keys.diff --]
[-- Type: plain/text, Size: 10508 bytes --]

[-- Attachment #9: openbios_new_fw_abi.diff --]
[-- Type: plain/text, Size: 9040 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-31 12:45           ` Blue Swirl
@ 2008-08-31 13:02             ` Gleb Natapov
  2008-08-31 13:39               ` Blue Swirl
  0 siblings, 1 reply; 20+ messages in thread
From: Gleb Natapov @ 2008-08-31 13:02 UTC (permalink / raw)
  To: qemu-devel

On Sun, Aug 31, 2008 at 03:45:36PM +0300, Blue Swirl wrote:
> >  > I made an updated version of the patch 1/6, with explicit little
> >  > endian conversions. I'm not very happy with that. Another way would be
> >  > to add functions just to put different size numbers into device and
> >  > they would hide the conversion.
> >  >
> >
> > So what approach we should go with? We can go with the second one (add
> >  functions for each type) and extend interface as needed.
> 
> This version adds the functions, now the interface is much better. I
> updated the other patches too.

> +static int fw_cfg_select(FWCfgState *s, uint16_t key)
> +{
> +    int ret;
> +
> +    s->cur_offset = 0;
> +    if ((key & ~FW_CFG_ARCH_LOCAL) >= FW_CFG_MAX_ENTRY) {
> +        s->cur_entry = 0;
Here we select valid entry on incorrect input. Perhaps set 0xffff here
and return 0 on read if cur_entry == 0xffff ?

> +static uint8_t fw_cfg_read(FWCfgState *s)
> +{
> +    int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
> +    FWCfgEntry *e = &s->entries[arch][s->cur_entry];
This should be:
	FWCfgEntry *e = &s->entries[arch][s->cur_entry & ~FW_CFG_ARCH_LOCAL];

> +    uint8_t ret;
> +
> +    if (!e || !e->data || s->cur_offset >= e->len)
Like this:
       if (s->cur_entry == 0xffff || !e->data || s->cur_offset >= e->len)

> +        ret = 0;
> +    else
> +        ret = e->data[s->cur_offset++];
> +
> +    FW_CFG_DPRINTF("read %d\n", ret);
> +
> +    return ret;
> +}
> +

Other then that looks great to me.

--
			Gleb.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-31 13:02             ` Gleb Natapov
@ 2008-08-31 13:39               ` Blue Swirl
  2008-08-31 14:18                 ` Gleb Natapov
  0 siblings, 1 reply; 20+ messages in thread
From: Blue Swirl @ 2008-08-31 13:39 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1686 bytes --]

On 8/31/08, Gleb Natapov <gleb@qumranet.com> wrote:
> On Sun, Aug 31, 2008 at 03:45:36PM +0300, Blue Swirl wrote:
>  > >  > I made an updated version of the patch 1/6, with explicit little
>  > >  > endian conversions. I'm not very happy with that. Another way would be
>  > >  > to add functions just to put different size numbers into device and
>  > >  > they would hide the conversion.
>  > >  >
>  > >
>  > > So what approach we should go with? We can go with the second one (add
>  > >  functions for each type) and extend interface as needed.
>  >
>  > This version adds the functions, now the interface is much better. I
>  > updated the other patches too.
>
>
> > +static int fw_cfg_select(FWCfgState *s, uint16_t key)
>  > +{
>  > +    int ret;
>  > +
>  > +    s->cur_offset = 0;
>  > +    if ((key & ~FW_CFG_ARCH_LOCAL) >= FW_CFG_MAX_ENTRY) {
>
> > +        s->cur_entry = 0;
>  Here we select valid entry on incorrect input. Perhaps set 0xffff here
>  and return 0 on read if cur_entry == 0xffff ?
>
>
>  > +static uint8_t fw_cfg_read(FWCfgState *s)
>  > +{
>  > +    int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
>
> > +    FWCfgEntry *e = &s->entries[arch][s->cur_entry];
>  This should be:
>
>         FWCfgEntry *e = &s->entries[arch][s->cur_entry & ~FW_CFG_ARCH_LOCAL];
>
>  > +    uint8_t ret;
>  > +
>
> > +    if (!e || !e->data || s->cur_offset >= e->len)
>  Like this:
>
>        if (s->cur_entry == 0xffff || !e->data || s->cur_offset >= e->len)
>
>  > +        ret = 0;
>  > +    else
>  > +        ret = e->data[s->cur_offset++];
>  > +
>  > +    FW_CFG_DPRINTF("read %d\n", ret);
>  > +
>  > +    return ret;
>  > +}
>  > +

Right, here's a fixed version.

[-- Attachment #2: new_fw_abi.diff --]
[-- Type: plain/text, Size: 11963 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-31 13:39               ` Blue Swirl
@ 2008-08-31 14:18                 ` Gleb Natapov
  2008-08-31 18:41                   ` Blue Swirl
  0 siblings, 1 reply; 20+ messages in thread
From: Gleb Natapov @ 2008-08-31 14:18 UTC (permalink / raw)
  To: qemu-devel

With the fix below this patch series works for me.

On Sun, Aug 31, 2008 at 04:39:34PM +0300, Blue Swirl wrote:
> +static uint8_t fw_cfg_read(FWCfgState *s)
> +{
> +    int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
> +    FWCfgEntry *e = &s->entries[arch][s->cur_entry & ~FW_CFG_ARCH_LOCAL];
> +    uint8_t ret;
> +
> +    if (s->cur_entry != FW_CFG_INVALID || !e->data || s->cur_offset >= e->len)
This should be "=="     ^^^

> +        ret = 0;
> +    else
> +        ret = e->data[s->cur_offset++];
> +
> +    FW_CFG_DPRINTF("read %d\n", ret);
> +
> +    return ret;
> +}
> +


--
			Gleb.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-31 14:18                 ` Gleb Natapov
@ 2008-08-31 18:41                   ` Blue Swirl
  2008-08-31 19:24                     ` Gleb Natapov
  0 siblings, 1 reply; 20+ messages in thread
From: Blue Swirl @ 2008-08-31 18:41 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 796 bytes --]

On 8/31/08, Gleb Natapov <gleb@qumranet.com> wrote:
> With the fix below this patch series works for me.

Do you already have a patch for Bochs BIOS, or how do you test it?

I've fixed the bug in the version attached, updated the common patch
and added a Sparc32 specific patch to add the graphic depth. I added
support to Sparc32 version of OpenBIOS, it can also boot using the new
device:

Configuration device id QEMU version 1 machine id 32
CPUs: 1 x FMI,MB86904
Welcome to OpenBIOS v1.0RC1 built on Aug 31 2008 15:30
  Type 'help' for detailed information

[sparc] Booting file 'cdrom' with parameters ''
Not a bootable ELF image
Not a Linux kernel image
Loading a.out image...
Loaded 7680 bytes
entry point is 0x4000
Jumping to entry point...

So I would be ready to switch to this system.

[-- Attachment #2: new_fw_abi.diff --]
[-- Type: plain/text, Size: 11963 bytes --]

[-- Attachment #3: fw_cfg_add_common_keys.diff --]
[-- Type: plain/text, Size: 10513 bytes --]

[-- Attachment #4: fw_cfg_add_sparc_keys.diff --]
[-- Type: plain/text, Size: 851 bytes --]

[-- Attachment #5: openbios_new_fw_abi.diff --]
[-- Type: plain/text, Size: 26673 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication.
  2008-08-31 18:41                   ` Blue Swirl
@ 2008-08-31 19:24                     ` Gleb Natapov
  0 siblings, 0 replies; 20+ messages in thread
From: Gleb Natapov @ 2008-08-31 19:24 UTC (permalink / raw)
  To: qemu-devel

On Sun, Aug 31, 2008 at 09:41:20PM +0300, Blue Swirl wrote:
> On 8/31/08, Gleb Natapov <gleb@qumranet.com> wrote:
> > With the fix below this patch series works for me.
> 
> Do you already have a patch for Bochs BIOS, or how do you test it?
> 
Yes I have. The patch is against Bochs BIOS from KVM repository. But it
is easy to make one for original version too.

--
			Gleb.

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2008-08-31 19:24 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-28 16:52 [Qemu-devel] [PATCH v3 0/6] Add UUID command-line option Gleb Natapov
2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 1/6] Use IO port for qemu<->guest BIOS communication Gleb Natapov
2008-08-28 17:57   ` Blue Swirl
2008-08-28 18:04   ` Blue Swirl
2008-08-29 19:00     ` Gleb Natapov
2008-08-29 19:26       ` Blue Swirl
2008-08-30 19:57       ` Blue Swirl
2008-08-31 11:12         ` Gleb Natapov
2008-08-31 11:40           ` Blue Swirl
2008-08-31 12:45           ` Blue Swirl
2008-08-31 13:02             ` Gleb Natapov
2008-08-31 13:39               ` Blue Swirl
2008-08-31 14:18                 ` Gleb Natapov
2008-08-31 18:41                   ` Blue Swirl
2008-08-31 19:24                     ` Gleb Natapov
2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 2/6] Add -uuid command line option Gleb Natapov
2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 3/6] Add "info uuid" command to monitor Gleb Natapov
2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 4/6] Use libuuid if available Gleb Natapov
2008-08-28 16:52 ` [Qemu-devel] [PATCH v3 5/6] Add UUID to firmware configuration info Gleb Natapov
2008-08-28 16:53 ` [Qemu-devel] [PATCH v3 6/6] Pass cpu speed into SM BIOS Gleb Natapov

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