Skip to contentSkip to conversation

smbios: Add a function to directly add an entry

PATCH In review [email protected] 5 participants 23 messages Jul 15, 2012 – Jul 17, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/16 smbios: Add a function to directly add an entry

From: Corey Minyard <[email protected]>

There was no way to directly add a table entry to the SMBIOS table, even though the BIOS supports this. So add a function to do this. This is in preparation for the IPMI handler adding it's SMBIOS table entry.

---
 hw/smbios.c |   27 +++++++++++++++++++++++++++
 hw/smbios.h |   15 ++++++++-------
 2 files changed, 35 insertions(+), 7 deletions(-)
hw/smbios.c +27 -0
index c57237d..98c7f99 100644
@@ -178,6 +178,33 @@ static void smbios_build_type_1_fields(const char *t)
                          strlen(buf) + 1, buf);
 }
 
+int smbios_table_entry_add(struct smbios_structure_header *entry)
+{
+    struct smbios_table *table;
+    struct smbios_structure_header *header;
+    unsigned int size = entry->length;
+
+    if (!smbios_entries) {
+        smbios_entries_len = sizeof(uint16_t);
+        smbios_entries = g_malloc0(smbios_entries_len);
+    }
+    smbios_entries = g_realloc(smbios_entries, smbios_entries_len +
+			       sizeof(*table) + size);
+    table = (struct smbios_table *)(smbios_entries + smbios_entries_len);
+    table->header.type = SMBIOS_TABLE_ENTRY;
+    table->header.length = cpu_to_le16(sizeof(*table) + size);
+
+    header = (struct smbios_structure_header *)(table->data);
+    memcpy(header, entry, size);
+
+    smbios_check_collision(header->type, SMBIOS_TABLE_ENTRY);
+
+    smbios_entries_len += sizeof(*table) + size;
+    (*(uint16_t *)smbios_entries) =
+	cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries) + 1);
+    return 0;
+}
+
 int smbios_entry_add(const char *t)
 {
     char buf[1024];
hw/smbios.h +8 -7
index 94e3641..6431a15 100644
@@ -13,21 +13,22 @@
  *
  */
 
+/* This goes at the beginning of every SMBIOS structure. */
+struct smbios_structure_header {
+    uint8_t type;
+    uint8_t length;
+    uint16_t handle;
+} QEMU_PACKED;
+
 int smbios_entry_add(const char *t);
 void smbios_add_field(int type, int offset, int len, void *data);
 uint8_t *smbios_get_table(size_t *length);
+int smbios_table_entry_add(struct smbios_structure_header *entry);
 
 /*
  * SMBIOS spec defined tables
  */
 
-/* This goes at the beginning of every SMBIOS structure. */
-struct smbios_structure_header {
-    uint8_t type;
-    uint8_t length;
-    uint16_t handle;
-} QEMU_PACKED;
-
 /* SMBIOS type 0 - BIOS Information */
 struct smbios_type_0 {
     struct smbios_structure_header header;
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 2/16 pc: move SMBIOS setup to after device init

From: Corey Minyard <[email protected]>

Setting up the firmware interface for the SMBIOS table needs to be done later in the process, after device initialization, so that devices can add entries to the table.

---
 hw/pc.c      |   24 ++++++++++++++----------
 hw/pc.h      |   11 ++++++-----
 hw/pc_piix.c |   12 ++++++++----
 3 files changed, 28 insertions(+), 19 deletions(-)
hw/pc.c +14 -10
index fb1ad5b..bc753c0 100644
@@ -970,21 +970,13 @@ void pc_cpus_init(const char *cpu_model)
     }
 }
 
-void *pc_memory_init(MemoryRegion *system_memory,
-                    const char *kernel_filename,
-                    const char *kernel_cmdline,
-                    const char *initrd_filename,
+void pc_memory_init(MemoryRegion *system_memory,
                     ram_addr_t below_4g_mem_size,
                     ram_addr_t above_4g_mem_size,
-                    MemoryRegion *rom_memory,
                     MemoryRegion **ram_memory)
 {
-    int linux_boot, i;
-    MemoryRegion *ram, *option_rom_mr;
+    MemoryRegion *ram;
     MemoryRegion *ram_below_4g, *ram_above_4g;
-    void *fw_cfg;
-
-    linux_boot = (kernel_filename != NULL);
 
     /* Allocate RAM.  We allocate it as a single memory region and use
      * aliases to address portions of it, mostly for backwards compatibility
@@ -1006,7 +998,17 @@ void *pc_memory_init(MemoryRegion *system_memory,
         memory_region_add_subregion(system_memory, 0x100000000ULL,
                                     ram_above_4g);
     }
+}
 
+void *pc_bios_init(const char *kernel_filename,
+		   const char *kernel_cmdline,
+		   const char *initrd_filename,
+		   ram_addr_t below_4g_mem_size,
+		   MemoryRegion *rom_memory)
+{
+    MemoryRegion *option_rom_mr;
+    void *fw_cfg;
+    int linux_boot, i;
 
     /* Initialize PC system firmware */
     pc_system_firmware_init(rom_memory);
@@ -1019,6 +1021,8 @@ void *pc_memory_init(MemoryRegion *system_memory,
                                         option_rom_mr,
                                         1);
 
+    linux_boot = (kernel_filename != NULL);
+
     fw_cfg = bochs_bios_init();
     rom_set_fw(fw_cfg);
 
hw/pc.h +6 -5
index a662090..d727dfb 100644
@@ -106,14 +106,15 @@ void pc_register_ferr_irq(qemu_irq irq);
 void pc_acpi_smi_interrupt(void *opaque, int irq, int level);
 
 void pc_cpus_init(const char *cpu_model);
-void *pc_memory_init(MemoryRegion *system_memory,
-                    const char *kernel_filename,
-                    const char *kernel_cmdline,
-                    const char *initrd_filename,
+void pc_memory_init(MemoryRegion *system_memory,
                     ram_addr_t below_4g_mem_size,
                     ram_addr_t above_4g_mem_size,
-                    MemoryRegion *rom_memory,
                     MemoryRegion **ram_memory);
+void *pc_bios_init(const char *kernel_filename,
+		   const char *kernel_cmdline,
+		   const char *initrd_filename,
+		   ram_addr_t below_4g_mem_size,
+		   MemoryRegion *rom_memory);
 qemu_irq *pc_allocate_cpu_irq(void);
 DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus);
 void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
hw/pc_piix.c +8 -4
index 98a06fa..2c3feaa 100644
@@ -178,10 +178,8 @@ static void pc_init1(MemoryRegion *system_memory,
 
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
-        fw_cfg = pc_memory_init(system_memory,
-                       kernel_filename, kernel_cmdline, initrd_filename,
-                       below_4g_mem_size, above_4g_mem_size,
-                       pci_enabled ? rom_memory : system_memory, &ram_memory);
+        pc_memory_init(system_memory, below_4g_mem_size,
+		       above_4g_mem_size, &ram_memory);
     }
 
     gsi_state = g_malloc0(sizeof(*gsi_state));
@@ -275,6 +273,12 @@ static void pc_init1(MemoryRegion *system_memory,
         pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
     }
 
+    if (!xen_enabled()) {
+	fw_cfg = pc_bios_init(kernel_filename, kernel_cmdline,
+			      initrd_filename, below_4g_mem_size,
+			      pci_enabled ? rom_memory : system_memory);
+    }
+
     if (pci_enabled && acpi_enabled) {
         i2c_bus *smbus;
 
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 3/16 vl: Move init_timer_alarm() earlier

In reply to [email protected]

From: Corey Minyard <[email protected]>

The timers may be used in initialization, so move them earlier so they are ready. A reconnect options will be added to qemu-char, and it uses a timer, but the timer alarm wasn't initialized yet.

---
 vl.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
vl.c +5 -5
index 52b6588..0f0bcd9 100644
@@ -3245,6 +3245,11 @@ int main(int argc, char **argv, char **envp)
         qemu_set_version(machine->hw_version);
     }
 
+    if (init_timer_alarm() < 0) {
+        fprintf(stderr, "could not initialize alarm timer\n");
+        exit(1);
+    }
+
     /* Init CPU def lists, based on config
      * - Must be called after all the qemu_read_config_file() calls
      * - Must be called before list_cpus()
@@ -3422,11 +3427,6 @@ int main(int argc, char **argv, char **envp)
 
     os_set_line_buffering();
 
-    if (init_timer_alarm() < 0) {
-        fprintf(stderr, "could not initialize alarm timer\n");
-        exit(1);
-    }
-
 #ifdef CONFIG_SPICE
     /* spice needs the timers to be initialized by this point */
     qemu_spice_init();
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH 4/16 qemu-char: Allocate CharDriverState in qemu_chr_new_from_opts

In reply to [email protected]

From: Corey Minyard <[email protected]>

This allocates the CharDriverState structure in a more logical place. It reduces code size and it allows a coming option to automatically attempt to reconnect a chardev if the connection fails.

---
 console.c         |    9 +----
 console.h         |    2 +-
 hw/baum.c         |    6 +--
 hw/baum.h         |    2 +-
 hw/msmouse.c      |    5 +--
 hw/msmouse.h      |    2 +-
 qemu-char.c       |   93 +++++++++++++++++++++-------------------------------
 spice-qemu-char.c |    4 +--
 ui/qemu-spice.h   |    2 +-
 9 files changed, 48 insertions(+), 77 deletions(-)
console.c +2 -7
index 6a463f5..f27e5dc 100644
@@ -1513,15 +1513,12 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds)
         chr->init(chr);
 }
 
-CharDriverState *text_console_init(QemuOpts *opts)
+CharDriverState *text_console_init(CharDriverState *chr, QemuOpts *opts)
 {
-    CharDriverState *chr;
     TextConsole *s;
     unsigned width;
     unsigned height;
 
-    chr = g_malloc0(sizeof(CharDriverState));
-
     width = qemu_opt_get_number(opts, "width", 0);
     if (width == 0)
         width = qemu_opt_get_number(opts, "cols", 0) * FONT_WIDTH;
@@ -1536,10 +1533,8 @@ CharDriverState *text_console_init(QemuOpts *opts)
         s = new_console(NULL, TEXT_CONSOLE_FIXED_SIZE);
     }
 
-    if (!s) {
-        g_free(chr);
+    if (!s)
         return NULL;
-    }
 
     s->chr = chr;
     s->g_width = width;
console.h +1 -1
index 4334db5..d4b930d 100644
@@ -359,7 +359,7 @@ void vga_hw_text_update(console_ch_t *chardata);
 
 int is_graphic_console(void);
 int is_fixedsize_console(void);
-CharDriverState *text_console_init(QemuOpts *opts);
+CharDriverState *text_console_init(CharDriverState *chr, QemuOpts *opts);
 void text_consoles_set_display(DisplayState *ds);
 void console_select(unsigned int index);
 void console_color_init(DisplayState *ds);
hw/baum.c +2 -4
index 3e94f84..b5df8a6 100644
@@ -562,10 +562,9 @@ static void baum_close(struct CharDriverState *chr)
     g_free(baum);
 }
 
-CharDriverState *chr_baum_init(QemuOpts *opts)
+CharDriverState *chr_baum_init(CharDriverState *chr, QemuOpts *opts)
 {
     BaumDriverState *baum;
-    CharDriverState *chr;
     brlapi_handle_t *handle;
 #ifdef CONFIG_SDL
     SDL_SysWMinfo info;
@@ -573,7 +572,7 @@ CharDriverState *chr_baum_init(QemuOpts *opts)
     int tty;
 
     baum = g_malloc0(sizeof(BaumDriverState));
-    baum->chr = chr = g_malloc0(sizeof(CharDriverState));
+    baum->chr = chr;
 
     chr->opaque = baum;
     chr->chr_write = baum_write;
@@ -621,7 +620,6 @@ fail:
     brlapi__closeConnection(handle);
 fail_handle:
     g_free(handle);
-    g_free(chr);
     g_free(baum);
     return NULL;
 }
hw/baum.h +1 -1
index 8af710f..599d48b 100644
@@ -23,4 +23,4 @@
  */
 
 /* char device */
-CharDriverState *chr_baum_init(QemuOpts *opts);
+CharDriverState *chr_baum_init(CharDriverState *chr, QemuOpts *opts);
hw/msmouse.c +1 -4
index 9c492a4..8a8a1d3 100644
@@ -64,11 +64,8 @@ static void msmouse_chr_close (struct CharDriverState *chr)
     g_free (chr);
 }
 
-CharDriverState *qemu_chr_open_msmouse(QemuOpts *opts)
+CharDriverState *qemu_chr_open_msmouse(CharDriverState *chr, QemuOpts *opts)
 {
-    CharDriverState *chr;
-
-    chr = g_malloc0(sizeof(CharDriverState));
     chr->chr_write = msmouse_chr_write;
     chr->chr_close = msmouse_chr_close;
 
hw/msmouse.h +1 -1
index 456cb21..925af1a 100644
@@ -1,2 +1,2 @@
 /* msmouse.c */
-CharDriverState *qemu_chr_open_msmouse(QemuOpts *opts);
+CharDriverState *qemu_chr_open_msmouse(CharDriverState *chr, QemuOpts *opts);
qemu-char.c +38 -55

305 lines not on this page · raw message

spice-qemu-char.c +1 -3
index 09aa22d..2fb8a10 100644
@@ -188,9 +188,8 @@ static void print_allowed_subtypes(void)
     fprintf(stderr, "\n");
 }
 
-CharDriverState *qemu_chr_open_spice(QemuOpts *opts)
+CharDriverState *qemu_chr_open_spice(CharDriverState *chr, QemuOpts *opts)
 {
-    CharDriverState *chr;
     SpiceCharDriver *s;
     const char* name = qemu_opt_get(opts, "name");
     uint32_t debug = qemu_opt_get_number(opts, "debug", 0);
@@ -214,7 +213,6 @@ CharDriverState *qemu_chr_open_spice(QemuOpts *opts)
         return NULL;
     }
 
-    chr = g_malloc0(sizeof(CharDriverState));
     s = g_malloc0(sizeof(SpiceCharDriver));
     s->chr = chr;
     s->debug = debug;
ui/qemu-spice.h +1 -1
index 3299da8..fb582c5 100644
@@ -45,7 +45,7 @@ int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,
 void do_info_spice_print(Monitor *mon, const QObject *data);
 void do_info_spice(Monitor *mon, QObject **ret_data);
 
-CharDriverState *qemu_chr_open_spice(QemuOpts *opts);
+CharDriverState *qemu_chr_open_spice(CharDriverState *chr, QemuOpts *opts);
 
 #else  /* CONFIG_SPICE */
 #include "monitor.h"
Signature · 1 line
1.7.4.1
#4 lore raw

PATCH 5/16 qemu-char: Allow a chardev to reconnect if disconnected

In reply to [email protected]

From: Corey Minyard <[email protected]>

Allow a socket that connects to reconnect on a periodic basis if it fails to connect at startup or if the connection drops while in use.

---
 qemu-char.c     |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 qemu-char.h     |    4 ++++
 qemu-config.c   |    3 +++
 qemu-options.hx |   11 ++++++++---
 4 files changed, 65 insertions(+), 7 deletions(-)
qemu-char.c +50 -4
index c9348fa..76d4deb 100644
@@ -111,9 +111,15 @@ void qemu_chr_be_event(CharDriverState *s, int event)
     /* Keep track if the char device is open */
     switch (event) {
         case CHR_EVENT_OPENED:
+	    if (s->recon_timer)
+		qemu_del_timer(s->recon_timer);
             s->opened = 1;
             break;
         case CHR_EVENT_CLOSED:
+	    if (s->recon_timer)
+		qemu_mod_timer(s->recon_timer,
+			       (qemu_get_clock_ns(vm_clock) +
+				(s->recon_time * 1000000000ULL)));
             s->opened = 0;
             break;
     }
@@ -2726,6 +2732,19 @@ static const struct {
 #endif
 };
 
+static void recon_timeout(void *opaque)
+{
+    CharDriverState *chr = opaque;
+
+    if (chr->opened)
+	return;
+
+    qemu_mod_timer(chr->recon_timer,
+		   (qemu_get_clock_ns(vm_clock) +
+		    (chr->recon_time * 1000000000ULL)));
+    backend_table[chr->backend].open(chr, chr->opts);
+}
+
 CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
                                     void (*init)(struct CharDriverState *s))
 {
@@ -2753,11 +2772,36 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
     }
 
     chr = g_malloc0(sizeof(CharDriverState));
+
+    chr->backend = i;
+    if ((chr->recon_time = qemu_opt_get_number(opts, "reconnect", 0))) {
+	if (strcmp(qemu_opt_get(opts, "backend"), "socket") != 0) {
+	    g_free(chr);
+	    fprintf(stderr, "chardev: reconnect only supported on sockets\n");
+	    return NULL;
+	}
+	if (qemu_opt_get_bool(opts, "server", 0)) {
+	    g_free(chr);
+	    fprintf(stderr, "chardev: server device cannot reconnect\n");
+	    return NULL;
+	}
+	chr->opts = opts;
+	chr->recon_timer = qemu_new_timer_ns(vm_clock, recon_timeout, chr);
+
+	/* Make sure it connects in time. */
+	qemu_mod_timer(chr->recon_timer,
+		       (qemu_get_clock_ns(vm_clock) +
+			(chr->recon_time * 1000000000ULL)));
+    }
+
     if (!backend_table[i].open(chr, opts)) {
-	g_free(chr);
-        fprintf(stderr, "chardev: opening backend \"%s\" failed\n",
-                qemu_opt_get(opts, "backend"));
-        return NULL;
+	if (!chr->recon_time) {
+	    /* Reconnect is not enabled, give up */
+	    g_free(chr);
+	    fprintf(stderr, "chardev: opening backend \"%s\" failed\n",
+		    qemu_opt_get(opts, "backend"));
+	    return NULL;
+	}
     }
 
     if (!chr->filename)
@@ -2829,6 +2873,8 @@ void qemu_chr_delete(CharDriverState *chr)
     QTAILQ_REMOVE(&chardevs, chr, next);
     if (chr->chr_close)
         chr->chr_close(chr);
+    if (chr->recon_timer)
+	qemu_free_timer(chr->recon_timer);
     g_free(chr->filename);
     g_free(chr->label);
     g_free(chr);
qemu-char.h +4 -0
index 486644b..d21ae39 100644
@@ -75,6 +75,10 @@ struct CharDriverState {
     int opened;
     int avail_connections;
     QTAILQ_ENTRY(CharDriverState) next;
+    int backend;
+    QemuOpts *opts;
+    QEMUTimer *recon_timer;
+    uint64_t recon_time;
 };
 
 /**
qemu-config.c +3 -0
index 54694cc..9ebe432 100644
@@ -209,6 +209,9 @@ static QemuOptsList qemu_chardev_opts = {
             .name = "mux",
             .type = QEMU_OPT_BOOL,
         },{
+            .name = "reconnect",
+            .type = QEMU_OPT_NUMBER,
+        },{
             .name = "signal",
             .type = QEMU_OPT_BOOL,
         },{
qemu-options.hx +8 -3
index 72aace6..c5f592c 100644
@@ -1620,8 +1620,9 @@ DEFHEADING(Character device options:)
 DEF("chardev", HAS_ARG, QEMU_OPTION_chardev,
     "-chardev null,id=id[,mux=on|off]\n"
     "-chardev socket,id=id[,host=host],port=host[,to=to][,ipv4][,ipv6][,nodelay]\n"
-    "         [,server][,nowait][,telnet][,mux=on|off] (tcp)\n"
-    "-chardev socket,id=id,path=path[,server][,nowait][,telnet],[mux=on|off] (unix)\n"
+    "         [,server][,nowait][,telnet][,mux=on|off][,reconnect=seconds] (tcp)\n"
+    "-chardev socket,id=id,path=path[,server][,nowait][,telnet][,mux=on|off]\n"
+    "         [,reconnect=seconds] (unix)\n"
     "-chardev udp,id=id[,host=host],port=port[,localaddr=localaddr]\n"
     "         [,localport=localport][,ipv4][,ipv6][,mux=on|off]\n"
     "-chardev msmouse,id=id[,mux=on|off]\n"
@@ -1690,7 +1691,7 @@ Options to each backend are described below.
 A void device. This device will not emit any data, and will drop any data it
 receives. The null backend does not take any options.
 
-@item -chardev socket ,id=@var{id} [@var{TCP options} or @var{unix options}] [,server] [,nowait] [,telnet]
+@item -chardev socket ,id=@var{id} [@var{TCP options} or @var{unix options}] [,server] [,nowait] [,telnet] [,reconnect=@var{seconds}]
 
 Create a two-way stream socket, which can be either a TCP or a unix socket. A
 unix socket will be created if @option{path} is specified. Behaviour is
@@ -1704,6 +1705,10 @@ connect to a listening socket.
 @option{telnet} specifies that traffic on the socket should interpret telnet
 escape sequences.
 
+@option{reconnect} specifies that if the socket does not come up at startup,
+or if the socket is closed for some reason (like the other end exited),
+wait the given number of seconds and attempt to reconnect.
+
 TCP and unix socket options are given below:
 
 @table @option
Signature · 1 line
1.7.4.1
#5 lore raw

PATCH 6/16 qemu-char: Fix a race reporting opens and closes

In reply to [email protected]

From: Corey Minyard <[email protected]>

When an open event is reported, it is done through a bh. But close events are reported immediately. So if an open event is in the bh and a close occurs, an extraneous open happens, which can confuse a user.

To fix this, this patch sets the "opened" flag immediately instead of in the bh handler and checks to make sure the opened flag is set before reporting an open event.

This also modifies the spice code to call qemu_chr_generic_open to report an open, to keep things consistent.

---
 qemu-char.c       |   17 +++++++++++++++--
 spice-qemu-char.c |    6 ++++--
 2 files changed, 19 insertions(+), 4 deletions(-)
qemu-char.c +15 -2
index 76d4deb..3d4302d 100644
@@ -111,9 +111,12 @@ void qemu_chr_be_event(CharDriverState *s, int event)
     /* Keep track if the char device is open */
     switch (event) {
         case CHR_EVENT_OPENED:
+	    /*
+	     * See the comment in qemu_chr_generic_open_bh() for why
+	     * 's->opened = 1' is not here.
+	     */
 	    if (s->recon_timer)
 		qemu_del_timer(s->recon_timer);
-            s->opened = 1;
             break;
         case CHR_EVENT_CLOSED:
 	    if (s->recon_timer)
@@ -132,13 +135,23 @@ void qemu_chr_be_event(CharDriverState *s, int event)
 static void qemu_chr_generic_open_bh(void *opaque)
 {
     CharDriverState *s = opaque;
-    qemu_chr_be_event(s, CHR_EVENT_OPENED);
+    /*
+     * Since the "close" event doesn't go through a bh, there is a
+     * possible race condition if a close comes in after an open, but
+     * the open is in the bh queue.  So we double-check here, and we
+     * set opened in qemu_chr_generic_open() instead of
+     * qemu_chr_be_event().
+     */
+    if (s->opened)
+	qemu_chr_be_event(s, CHR_EVENT_OPENED);
     qemu_bh_delete(s->bh);
     s->bh = NULL;
 }
 
 void qemu_chr_generic_open(CharDriverState *s)
 {
+    /* See the comment in qemu_chr_generic_open_bh() for why this is here */
+    s->opened = 1;
     if (s->bh == NULL) {
 	s->bh = qemu_bh_new(qemu_chr_generic_open_bh, s);
 	qemu_bh_schedule(s->bh);
spice-qemu-char.c +4 -2
index 2fb8a10..7c6d989 100644
@@ -93,8 +93,10 @@ static void vmc_state(SpiceCharDeviceInstance *sin, int connected)
         return;
     }
 
-    qemu_chr_be_event(scd->chr,
-                      connected ? CHR_EVENT_OPENED : CHR_EVENT_CLOSED);
+    if (connected)
+	qemu_chr_generic_open(scd->chr);
+    else
+	qemu_chr_be_event(scd->chr, CHR_EVENT_CLOSED);
 }
 
 static SpiceCharDeviceInterface vmc_interface = {
Signature · 1 line
1.7.4.1
#6 lore raw

PATCH 7/16 qemu-char: remove free of chr from win_stdio_close

In reply to [email protected]

From: Corey Minyard <[email protected]>

This will result in a double free on close, because it's freed in qemu_chr_delete() right after calling the close function.

---
 qemu-char.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
qemu-char.c +0 -1
index 3d4302d..8fbc704 100644
@@ -1946,7 +1946,6 @@ static void win_stdio_close(CharDriverState *chr)
     }
 
     g_free(chr->opaque);
-    g_free(chr);
     stdio_nb_clients--;
 }
 
Signature · 1 line
1.7.4.1
#7 lore raw

PATCH 8/16 qemu-char: Close fd at end of file

In reply to [email protected]

From: Corey Minyard <[email protected]>

The chardev backends that used qemu_chr_open_fd did not get their file descriptors closed at end of file or when the chardev was closed. This could result in a file descriptor leak.

---
 qemu-char.c |   29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)
qemu-char.c +23 -6
index 8fbc704..9cbc8c0 100644
@@ -563,6 +563,7 @@ static int stdio_nb_clients;
 typedef struct {
     int fd_in, fd_out;
     int max_size;
+    int close_fds_on_close;
 } FDCharDriver;
 
 
@@ -581,6 +582,18 @@ static int fd_chr_read_poll(void *opaque)
     return s->max_size;
 }
 
+static void fd_close_fds(FDCharDriver *s)
+{
+    if (!s->close_fds_on_close)
+	return;
+
+    if ((s->fd_out != s->fd_in) && (s->fd_out != -1))
+	close(s->fd_out);
+    s->fd_out = -1;
+    close(s->fd_in);
+    s->fd_in = -1;
+}
+
 static void fd_chr_read(void *opaque)
 {
     CharDriverState *chr = opaque;
@@ -597,6 +610,7 @@ static void fd_chr_read(void *opaque)
     if (size == 0) {
         /* FD has been closed. Remove it from the active list.  */
         qemu_set_fd_handler2(s->fd_in, NULL, NULL, NULL, NULL);
+	fd_close_fds(s);
         qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
         return;
     }
@@ -626,6 +640,7 @@ static void fd_chr_close(struct CharDriverState *chr)
         if (display_type == DT_NOGRAPHIC && s->fd_in == 0) {
         } else {
             qemu_set_fd_handler2(s->fd_in, NULL, NULL, NULL, NULL);
+	    fd_close_fds(s);
         }
     }
 
@@ -635,13 +650,15 @@ static void fd_chr_close(struct CharDriverState *chr)
 
 /* open a character device to a unix fd */
 static CharDriverState *qemu_chr_open_fd(CharDriverState *chr,
-					 int fd_in, int fd_out)
+					 int fd_in, int fd_out,
+					 int close_fds_on_close)
 {
     FDCharDriver *s;
 
     s = g_malloc0(sizeof(FDCharDriver));
     s->fd_in = fd_in;
     s->fd_out = fd_out;
+    s->close_fds_on_close = close_fds_on_close;
     chr->opaque = s;
     chr->chr_write = fd_chr_write;
     chr->chr_update_read_handler = fd_chr_update_read_handler;
@@ -662,7 +679,7 @@ static CharDriverState *qemu_chr_open_file_out(CharDriverState *chr,
     if (fd_out < 0) {
         return NULL;
     }
-    return qemu_chr_open_fd(chr, -1, fd_out);
+    return qemu_chr_open_fd(chr, -1, fd_out, 1);
 }
 
 static CharDriverState *qemu_chr_open_pipe(CharDriverState *chr, QemuOpts *opts)
@@ -690,7 +707,7 @@ static CharDriverState *qemu_chr_open_pipe(CharDriverState *chr, QemuOpts *opts)
             return NULL;
         }
     }
-    return qemu_chr_open_fd(chr, fd_in, fd_out);
+    return qemu_chr_open_fd(chr, fd_in, fd_out, 1);
 }
 
 
@@ -794,7 +811,7 @@ static CharDriverState *qemu_chr_open_stdio(CharDriverState *chr,
         atexit(term_exit);
     }
 
-    qemu_chr_open_fd(chr, 0, 1);
+    qemu_chr_open_fd(chr, 0, 1, 0);
     chr->chr_close = qemu_chr_close_stdio;
     chr->chr_set_echo = qemu_chr_set_echo_stdio;
     qemu_set_fd_handler2(0, stdio_read_poll, stdio_read, NULL, chr);
@@ -1239,7 +1256,7 @@ static CharDriverState *qemu_chr_open_tty(CharDriverState *chr, QemuOpts *opts)
         return NULL;
     }
     tty_serial_init(fd, 115200, 'N', 8, 1);
-    qemu_chr_open_fd(chr, fd, fd);
+    qemu_chr_open_fd(chr, fd, fd, 1);
     chr->chr_ioctl = tty_serial_ioctl;
     chr->chr_close = qemu_chr_close_tty;
     return chr;
@@ -2313,7 +2330,7 @@ static void tcp_chr_read(void *opaque)
 CharDriverState *qemu_chr_open_eventfd(int eventfd)
 {
     CharDriverState *chr = g_malloc0(sizeof(CharDriverState));
-    return qemu_chr_open_fd(chr, eventfd, eventfd);
+    return qemu_chr_open_fd(chr, eventfd, eventfd, 0);
 }
 #endif
 
Signature · 1 line
1.7.4.1
#8 lore raw

PATCH 9/16 qdev: Add a pre-firmware init capability

In reply to [email protected]

From: Corey Minyard <[email protected]>

Some devices may need to do some firmware-type initialization before the firmware itself is initialized. For instance, any device that adds SMBIOS table entries (like IPMI) will need to do that before the BIOS is initialized.

So add a list of devices that get initialized before the firmware initialization. Since those devices get removed from the list so they don't get initialized twice, convert the qemu_opt_foreach() to use the safe list traversal.

---
 hw/pc.c           |    2 ++
 hw/qdev-monitor.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev.h         |    3 +++
 qemu-option.c     |    4 ++--
 4 files changed, 57 insertions(+), 2 deletions(-)
hw/pc.c +2 -0
index bc753c0..a0e8824 100644
@@ -1010,6 +1010,8 @@ void *pc_bios_init(const char *kernel_filename,
     void *fw_cfg;
     int linux_boot, i;
 
+    qdev_prefw_init_check();
+
     /* Initialize PC system firmware */
     pc_system_firmware_init(rom_memory);
 
hw/qdev-monitor.c +50 -0

56 lines not on this page · raw message

hw/qdev.h +3 -0
index f4683dc..2be4c95 100644
@@ -167,6 +167,9 @@ int qdev_simple_unplug_cb(DeviceState *dev);
 void qdev_machine_creation_done(void);
 bool qdev_machine_modified(void);
 
+void qdev_add_prefw_init(const char *name);
+void qdev_prefw_init_check(void);
+
 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
 void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
 
qemu-option.c +2 -2
index bb3886c..1d000f8 100644
@@ -709,10 +709,10 @@ int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
 int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
                      int abort_on_failure)
 {
-    QemuOpt *opt;
+    QemuOpt *opt, *next_opt;
     int rc = 0;
 
-    QTAILQ_FOREACH(opt, &opts->head, next) {
+    QTAILQ_FOREACH_SAFE(opt, &opts->head, next, next_opt) {
         rc = func(opt->name, opt->str, opaque);
         if (abort_on_failure  &&  rc != 0)
             break;
Signature · 1 line
1.7.4.1
#9 lore raw

PATCH 10/16 qom: release previous object when setting

In reply to [email protected]

From: Corey Minyard <[email protected]>

When setting an object, if you don't release the previous object that was there, it may become unusable. This change allows a chardev to be removed from one object's properties and added to another's.

---
 qom/object.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
qom/object.c +2 -0
index 00bb3b0..484dc77 100644
@@ -731,6 +731,8 @@ void object_property_set(Object *obj, Visitor *v, const char *name,
     if (!prop->set) {
         error_set(errp, QERR_PERMISSION_DENIED);
     } else {
+	if (prop->release)
+	    prop->release(obj, name, prop->opaque);
         prop->set(obj, v, prop->opaque, name, errp);
     }
 }
Signature · 1 line
1.7.4.1
Acked-by on v1 10/16
#10 lore raw

Re: [Qemu-devel] [PATCH 10/16] qom: release previous object when setting

Il 15/07/2012 22:25, [email protected] ha scritto:

Quoted 16 lines

From: Corey Minyard <[email protected]>

When setting an object, if you don't release the previous object that was there, it may become unusable. This change allows a chardev to be removed from one object's properties and added to another's.

---
 qom/object.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
qom/object.c +0 -0
index 00bb3b0..484dc77 100644

qom/object.c void object_property_set(Object *obj, Visitor *v, const char *name, · line 738

Quoted 8 lines
qom/object.c +2 -0
@@ -731,6 +731,8 @@ void object_property_set(Object *obj, Visitor *v, const char *name,
     if (!prop->set) {
         error_set(errp, QERR_PERMISSION_DENIED);
     } else {
+	if (prop->release)
+	    prop->release(obj, name, prop->opaque);
         prop->set(obj, v, prop->opaque, name, errp);
     }
 }

... but you need to run scripts/checkpatch.pl on your patches to conform to coding style.

Thanks!

Paolo

#11 lore raw

Re: [Qemu-devel] [PATCH 10/16] qom: release previous object when setting

Quoted 27 lines · Paolo Bonzini

Il 15/07/2012 22:25, [email protected] ha scritto:

Quoted 16 lines

From: Corey Minyard <[email protected]>

When setting an object, if you don't release the previous object that was there, it may become unusable. This change allows a chardev to be removed from one object's properties and added to another's.

---
  qom/object.c |    2 ++
  1 files changed, 2 insertions(+), 0 deletions(-)
qom/object.c +0 -0
index 00bb3b0..484dc77 100644

qom/object.c void object_property_set(Object *obj, Visitor *v, const char *name, · line 738

Quoted 8 lines
qom/object.c +2 -0
@@ -731,6 +731,8 @@ void object_property_set(Object *obj, Visitor *v, const char *name,
      if (!prop->set) {
          error_set(errp, QERR_PERMISSION_DENIED);
      } else {
+	if (prop->release)
+	    prop->release(obj, name, prop->opaque);
          prop->set(obj, v, prop->opaque, name, errp);
      }
  }
Quoted 2 lines

... but you need to run scripts/checkpatch.pl on your patches to conform to coding style.

Ok. I'm running everything through the script. I didn't realize the coding standard was that different from Linux.

Thanks,

-corey

#12 lore raw

PATCH 11/16 Add a base IPMI interface

In reply to [email protected]

From: Corey Minyard <[email protected]>

Add the basic IPMI types and infrastructure to QEMU. Low-level interfaces and simulation interfaces will register with this; it's kind of the go-between to tie them together.

---
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 hw/Makefile.objs                   |    2 +
 hw/ipmi.c                          |  182 ++++++++++++++++++++++++++++
 hw/ipmi.h                          |  228 ++++++++++++++++++++++++++++++++++++
 qemu-doc.texi                      |    2 +
 6 files changed, 416 insertions(+), 0 deletions(-)
 create mode 100644 hw/ipmi.c
 create mode 100644 hw/ipmi.h
default-configs/i386-softmmu.mak +1 -0
index 2c78175..eb17afc 100644
@@ -7,6 +7,7 @@ CONFIG_VGA_ISA=y
 CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
 CONFIG_VMMOUSE=y
+CONFIG_IPMI=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index 233a856..e4e3e4f 100644
@@ -7,6 +7,7 @@ CONFIG_VGA_ISA=y
 CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
 CONFIG_VMMOUSE=y
+CONFIG_IPMI=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/Makefile.objs +2 -0
index 27e362a..256cfae 100644
@@ -20,6 +20,8 @@ hw-obj-$(CONFIG_M48T59) += m48t59.o
 hw-obj-$(CONFIG_ESCC) += escc.o
 hw-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
 
+hw-obj-$(CONFIG_IPMI) += ipmi.o
+
 hw-obj-$(CONFIG_SERIAL) += serial.o
 hw-obj-$(CONFIG_PARALLEL) += parallel.o
 hw-obj-$(CONFIG_I8254) += i8254_common.o i8254.o
hw/ipmi.c new file +182 -0

182 lines not on this page · raw message

hw/ipmi.h new file +228 -0

228 lines not on this page · raw message

qemu-doc.texi +2 -0
index 0af0ff4..effa2da 100644
@@ -195,6 +195,8 @@ PCI and ISA network adapters
 @item
 Serial ports
 @item
+IPMI BMC, either and internal or external one
+@item
 Creative SoundBlaster 16 sound card
 @item
 ENSONIQ AudioPCI ES1370 sound card
Signature · 1 line
1.7.4.1
#13 lore raw

PATCH 12/16 IPMI: Add a PC ISA type structure

In reply to [email protected]

From: Corey Minyard <[email protected]>

This provides the base infrastructure to tie IPMI low-level interfaces into a PC ISA bus.

---
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 hw/Makefile.objs                   |    1 +
 hw/isa_ipmi.c                      |  156 ++++++++++++++++++++++++++++++++++++
 hw/smbios.h                        |   12 +++
 5 files changed, 171 insertions(+), 0 deletions(-)
 create mode 100644 hw/isa_ipmi.c
default-configs/i386-softmmu.mak +1 -0
index eb17afc..c0aff0d 100644
@@ -8,6 +8,7 @@ CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
+CONFIG_ISA_IPMI=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index e4e3e4f..615e4f2 100644
@@ -8,6 +8,7 @@ CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
+CONFIG_ISA_IPMI=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/Makefile.objs +1 -0
index 256cfae..928870b 100644
@@ -21,6 +21,7 @@ hw-obj-$(CONFIG_ESCC) += escc.o
 hw-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
 
 hw-obj-$(CONFIG_IPMI) += ipmi.o
+hw-obj-$(CONFIG_ISA_IPMI) += isa_ipmi.o
 
 hw-obj-$(CONFIG_SERIAL) += serial.o
 hw-obj-$(CONFIG_PARALLEL) += parallel.o
hw/isa_ipmi.c new file +156 -0

156 lines not on this page · raw message

hw/smbios.h +12 -0
index 6431a15..b9e4a61 100644
@@ -155,6 +155,18 @@ struct smbios_type_32 {
     uint8_t boot_status;
 } QEMU_PACKED;
 
+/* SMBIOS type 38 - IPMI Device Information */
+struct smbios_type_38 {
+    struct smbios_structure_header header;
+    uint8_t interface_type;
+    uint8_t ipmi_version;
+    uint8_t i2c_slave_addr;
+    uint8_t nv_storage_dev_addr;
+    uint64_t base_addr;
+    uint8_t base_addr_mod_and_irq_info;
+    uint8_t interrupt_number;
+} QEMU_PACKED;
+
 /* SMBIOS type 127 -- End-of-table */
 struct smbios_type_127 {
     struct smbios_structure_header header;
Signature · 1 line
1.7.4.1
#14 lore raw

Re: [Qemu-devel] [PATCH 12/16] IPMI: Add a PC ISA type structure

Il 15/07/2012 22:25, [email protected] ha scritto:

Quoted 7 lines
hw/isa_ipmi.c new file +7 -0
+    /* Clear the property from this device so we can put it elsewhere */
+    chr = isa->chr;
+    qdev_prop_set_chr(&dev->qdev, "chardev", NULL);
+
+    if (chr) {
+	bdev = qdev_create(NULL, "ipmi-bmc-extern");
+	qdev_prop_set_chr(bdev, "chardev", chr);

hw/isa_ipmi.c line 75

Quoted 10 lines
hw/isa_ipmi.c new file +10 -0
+    } else {
+	bdev = qdev_create(NULL, "ipmi-bmc-sim");
+    }
+    snprintf(typename, sizeof(typename), "ipmi-interface-%s", isa->interface);
+    idev = qdev_create(&isa_bus->qbus, typename);
+    qdev_prop_set_ptr(bdev, "ipmiif", idev);
+    qdev_prop_set_uint64(idev, "iobase", isa->iobase);
+    qdev_prop_set_ptr(idev, "bmc", bdev);
+    qdev_prop_set_uint8(idev, "slave-addr", isa->slave_addr);
+    rc = qdev_init(idev);

I think this is adding a bit of extra complication. You do not need to add explicit devices for this.

If you want to make ipmi-bmc-* and ipmi-interface-* objects, you can create them with object_new, set the properties manually with the returned pointer and add the object to the parent with object_property_add_child.

Otherwise, it should also be fine if you just add them as function pointers.

Either way also lets you keep the ownership of the chardev in the ISA IPMI device, and avoids that "info qtree" looks strange and does not show the chardev you assigned.

Paolo

#15 lore raw

Re: [Qemu-devel] [PATCH 12/16] IPMI: Add a PC ISA type structure

Quoted 12 lines · Paolo Bonzini

Il 15/07/2012 22:25, [email protected] ha scritto:

Quoted 11 lines
hw/isa_ipmi.c new file +11 -0
+    /* Clear the property from this device so we can put it elsewhere */
+    chr = isa->chr;
+    qdev_prop_set_chr(&dev->qdev, "chardev", NULL);
+
+    if (chr) {
+	bdev = qdev_create(NULL, "ipmi-bmc-extern");
+	qdev_prop_set_chr(bdev, "chardev", chr);
+    } else {
+	bdev = qdev_create(NULL, "ipmi-bmc-sim");
+    }
+    snprintf(typename, sizeof(typename), "ipmi-interface-%s", isa->interface);
Quoted 8 lines

hw/isa_ipmi.c line 75

Quoted 6 lines
hw/isa_ipmi.c new file +6 -0
+    idev = qdev_create(&isa_bus->qbus, typename);
+    qdev_prop_set_ptr(bdev, "ipmiif", idev);
+    qdev_prop_set_uint64(idev, "iobase", isa->iobase);
+    qdev_prop_set_ptr(idev, "bmc", bdev);
+    qdev_prop_set_uint8(idev, "slave-addr", isa->slave_addr);
+    rc = qdev_init(idev);

I think this is adding a bit of extra complication. You do not need to add explicit devices for this.

Yeah, but the qdevs did a lot of nice things for me :). But I understand.

Quoted 5 lines

If you want to make ipmi-bmc-* and ipmi-interface-* objects, you can create them with object_new, set the properties manually with the returned pointer and add the object to the parent with object_property_add_child.

The main reason I went with qdevs originally was because all the properties are defined for qdevs. I'd have to do all my own properties otherwise.

However, I think all the properties are represented by what is already there in isa-ipmi, so just having pointers to the interface and bmc objects is ok, I think.

Quoted 6 lines

Otherwise, it should also be fine if you just add them as function pointers.

Either way also lets you keep the ownership of the chardev in the ISA IPMI device, and avoids that "info qtree" looks strange and does not show the chardev you assigned.

Yeah, I see that now. Makes sense.

BTW, where do you want me to document this? I didn't see an obvious place in qemu-options.hx.

I'm working on tests, too. I didn't find much there already, but I'll see what I can add.

Thanks,

-corey

#16 lore raw

PATCH 13/16 IPMI: Add a KCS low-level interface

In reply to [email protected]

From: Corey Minyard <[email protected]>

This provides the simulation of the KCS hardware interface.

---
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 hw/Makefile.objs                   |    1 +
 hw/ipmi_kcs.c                      |  329 ++++++++++++++++++++++++++++++++++++
 4 files changed, 332 insertions(+), 0 deletions(-)
 create mode 100644 hw/ipmi_kcs.c
default-configs/i386-softmmu.mak +1 -0
index c0aff0d..b549389 100644
@@ -9,6 +9,7 @@ CONFIG_VMWARE_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
 CONFIG_ISA_IPMI=y
+CONFIG_IPMI_KCS=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index 615e4f2..af7d2a9 100644
@@ -9,6 +9,7 @@ CONFIG_VMWARE_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
 CONFIG_ISA_IPMI=y
+CONFIG_IPMI_KCS=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/Makefile.objs +1 -0
index 928870b..12cc9a2 100644
@@ -22,6 +22,7 @@ hw-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
 
 hw-obj-$(CONFIG_IPMI) += ipmi.o
 hw-obj-$(CONFIG_ISA_IPMI) += isa_ipmi.o
+hw-obj-$(CONFIG_IPMI_KCS) += ipmi_kcs.o
 
 hw-obj-$(CONFIG_SERIAL) += serial.o
 hw-obj-$(CONFIG_PARALLEL) += parallel.o
hw/ipmi_kcs.c new file +329 -0

329 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#17 lore raw

PATCH 14/16 IPMI: Add a BT low-level interface

In reply to [email protected]

From: Corey Minyard <[email protected]>

This provides the simulation of the BT hardware interface for IPMI.

---
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 hw/Makefile.objs                   |    1 +
 hw/ipmi_bt.c                       |  354 ++++++++++++++++++++++++++++++++++++
 4 files changed, 357 insertions(+), 0 deletions(-)
 create mode 100644 hw/ipmi_bt.c
default-configs/i386-softmmu.mak +1 -0
index b549389..f8f8e6d 100644
@@ -10,6 +10,7 @@ CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
 CONFIG_ISA_IPMI=y
 CONFIG_IPMI_KCS=y
+CONFIG_IPMI_BT=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index af7d2a9..8c1177d 100644
@@ -10,6 +10,7 @@ CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
 CONFIG_ISA_IPMI=y
 CONFIG_IPMI_KCS=y
+CONFIG_IPMI_BT=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/Makefile.objs +1 -0
index 12cc9a2..c6f54fb 100644
@@ -23,6 +23,7 @@ hw-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
 hw-obj-$(CONFIG_IPMI) += ipmi.o
 hw-obj-$(CONFIG_ISA_IPMI) += isa_ipmi.o
 hw-obj-$(CONFIG_IPMI_KCS) += ipmi_kcs.o
+hw-obj-$(CONFIG_IPMI_BT) += ipmi_bt.o
 
 hw-obj-$(CONFIG_SERIAL) += serial.o
 hw-obj-$(CONFIG_PARALLEL) += parallel.o
hw/ipmi_bt.c new file +354 -0

354 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#18 lore raw

PATCH 15/16 IPMI: Add a local BMC simulation

In reply to [email protected]

From: Corey Minyard <[email protected]>

This provides a minimal local BMC, basically enough to comply with the spec and provide a complete watchdog timer (including a sensor, SDR, and event).

---
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 hw/Makefile.objs                   |    1 +
 hw/ipmi_sim.c                      | 1528 ++++++++++++++++++++++++++++++++++++
 4 files changed, 1531 insertions(+), 0 deletions(-)
 create mode 100644 hw/ipmi_sim.c
default-configs/i386-softmmu.mak +1 -0
index f8f8e6d..8c99d5d 100644
@@ -11,6 +11,7 @@ CONFIG_IPMI=y
 CONFIG_ISA_IPMI=y
 CONFIG_IPMI_KCS=y
 CONFIG_IPMI_BT=y
+CONFIG_IPMI_LOCAL=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index 8c1177d..4d01883 100644
@@ -11,6 +11,7 @@ CONFIG_IPMI=y
 CONFIG_ISA_IPMI=y
 CONFIG_IPMI_KCS=y
 CONFIG_IPMI_BT=y
+CONFIG_IPMI_LOCAL=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/Makefile.objs +1 -0
index c6f54fb..1b707d7 100644
@@ -24,6 +24,7 @@ hw-obj-$(CONFIG_IPMI) += ipmi.o
 hw-obj-$(CONFIG_ISA_IPMI) += isa_ipmi.o
 hw-obj-$(CONFIG_IPMI_KCS) += ipmi_kcs.o
 hw-obj-$(CONFIG_IPMI_BT) += ipmi_bt.o
+hw-obj-$(CONFIG_IPMI_LOCAL) += ipmi_sim.o
 
 hw-obj-$(CONFIG_SERIAL) += serial.o
 hw-obj-$(CONFIG_PARALLEL) += parallel.o
hw/ipmi_sim.c new file +1528 -0

1,528 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#19 lore raw

PATCH 16/16 IPMI: Add an external connection simulation interface

In reply to [email protected]

From: Corey Minyard <[email protected]>

This adds an interface for IPMI that connects to a remote BMC over a chardev (generally a TCP socket). The OpenIPMI lanserv simulator describes this interface, see that for interface details.

---
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 hw/Makefile.objs                   |    1 +
 hw/ipmi_extern.c                   |  479 ++++++++++++++++++++++++++++++++++++
 4 files changed, 482 insertions(+), 0 deletions(-)
 create mode 100644 hw/ipmi_extern.c
default-configs/i386-softmmu.mak +1 -0
index 8c99d5d..325f92e 100644
@@ -12,6 +12,7 @@ CONFIG_ISA_IPMI=y
 CONFIG_IPMI_KCS=y
 CONFIG_IPMI_BT=y
 CONFIG_IPMI_LOCAL=y
+CONFIG_IPMI_EXTERN=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index 4d01883..2ac9177 100644
@@ -12,6 +12,7 @@ CONFIG_ISA_IPMI=y
 CONFIG_IPMI_KCS=y
 CONFIG_IPMI_BT=y
 CONFIG_IPMI_LOCAL=y
+CONFIG_IPMI_EXTERN=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/Makefile.objs +1 -0
index 1b707d7..b87de2c 100644
@@ -25,6 +25,7 @@ hw-obj-$(CONFIG_ISA_IPMI) += isa_ipmi.o
 hw-obj-$(CONFIG_IPMI_KCS) += ipmi_kcs.o
 hw-obj-$(CONFIG_IPMI_BT) += ipmi_bt.o
 hw-obj-$(CONFIG_IPMI_LOCAL) += ipmi_sim.o
+hw-obj-$(CONFIG_IPMI_EXTERN) += ipmi_extern.o
 
 hw-obj-$(CONFIG_SERIAL) += serial.o
 hw-obj-$(CONFIG_PARALLEL) += parallel.o
hw/ipmi_extern.c new file +479 -0

479 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#20 lore raw
In reply to [email protected]

I messed up and didn't get an introduction for these patches. So here goes.

These patches are for adding an IPMI interface to QEMU. It adds a KCS and BT interface; it should be easy to add a SMIC interface if anyone wants that, but it's not often used. For simulation of an IPMI management controller, it is a basic one that is built in to KVM, and it can make a connection to an external simulator.

I think I got all the previous comments handled. Once I realized how the class stuff worked, things made a lot more sense to me.

The OpenIPMI library (openipmi.sf.net) has a simulator that will work as an external simulator in the latest release candidate.

This patch fixes up a few things that the IPMI driver needs:

Allow a driver to add entries to the SMBIOS table.

Add the ability for a chardev that makes an external connection to reconnect if the initial connection fails or if it fails while in use.

In order to move the chardev to the external interface simulator, it had to be released or the add to the external interface failed.

Patches 7 and 8 in the series are not really related, they are things that I saw that seemed to be issues. I meant to pull them out but I forgot. These patches really got accidentally sent, but since they are out, well, they are out.

There are two things that I know of that are still missing:

Documentation. I'm planning to write docs for this, but I don't really see a place to do this. I don't see many other docs for devices. Where should I put them? If it's in qemu-options.hx, where in that file should they be?

Tests. I looked at the test infrastructure, and I don't really see many tests, so not much to go on for examples. I think I have it figured out, but I'll basically have to write a driver to be able to really test this. It would be nice if I could use the Linux driver, but I guess that's not really feasible.

-corey

#21 lore raw
In reply to [email protected]
Quoted 7 lines · On 07/15/2012 02:24 PM, [email protected] wrote:

From: Corey Minyard <[email protected]>

There was no way to directly add a table entry to the SMBIOS table, even though the BIOS supports this. So add a function to do this. This is in preparation for the IPMI handler adding it's SMBIOS table entry.

Quoted 5 lines
---
 hw/smbios.c |   27 +++++++++++++++++++++++++++
 hw/smbios.h |   15 ++++++++-------
 2 files changed, 35 insertions(+), 7 deletions(-)

Are you planning to expose this via the command line? Libvirt would like the ability to set arbitrary name/value pairs in SMBIOS (such as asset tag in the type 3 page), rather than the current limitation of only being able to set pre-defined names in just type 0 and 1 sections.

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#22 lore raw
Quoted 13 lines · Eric Blake
Quoted 7 lines · On 07/15/2012 02:24 PM, [email protected] wrote:

From: Corey Minyard <[email protected]>

There was no way to directly add a table entry to the SMBIOS table, even though the BIOS supports this. So add a function to do this. This is in preparation for the IPMI handler adding it's SMBIOS table entry.

Quoted 5 lines
---
  hw/smbios.c |   27 +++++++++++++++++++++++++++
  hw/smbios.h |   15 ++++++++-------
  2 files changed, 35 insertions(+), 7 deletions(-)
Quoted 5 lines

Are you planning to expose this via the command line? Libvirt would like the ability to set arbitrary name/value pairs in SMBIOS (such as asset tag in the type 3 page), rather than the current limitation of only being able to set pre-defined names in just type 0 and 1 sections.

Well, I wan't planning on it, I only did what I needed for IPMI. Adding a command line interface would be more learning that I can probably afford right now.

-corey