Add an IPMI device to QEMU
cover Add an IPMI device to QEMU
I have finally gotten some time to work on this, this series of patches adds an IPMI interface to qemu. The changes are roughly:
patches 01-05 - Add the capability to have a chardev reconnect if the connections fails. This way, if using an external BMC, qemu will detect the failure and periodically attempt to reconnect. This also adds ways for the device code to get an event on a disconnect and connect so it can handle it properly. This is probably useful for things besides IPMI. There are also a few small bugfixes in this.
patches 06-14 - Add the IPMI device itself, with an ISA interface for now (PCI and others can also be added easily).
patches 15-18 - Add a way to dynamically add content to the ACPI tables, and add the capability to add the IPMI information to the table.
Patches 19-20 - Add a way to dynamically add content to the SMBIOS tables, and add an IPMI entry to the table.
PATCH 1/20 qemu-char: Allocate CharDriverState in qemu_chr_new_from_opts
From: Corey Minyard <[email protected]>
This allocates the CharDriverState structure and passes it in to the open routine. This allows a coming option to automatically attempt to reconnect a chardev if the connection fails. The chardev has to be kept around so a reconnect can be done on it.
--- backends/baum.c | 6 +- backends/msmouse.c | 5 +- hw/misc/ivshmem.c | 11 ++- include/sysemu/char.h | 9 +-- include/ui/console.h | 4 +- include/ui/qemu-spice.h | 6 +- qemu-char.c | 180 +++++++++++++++++++++-------------------------- spice-qemu-char.c | 14 ++-- ui/console.c | 10 +-- 9 files changed, 113 insertions(+), 132 deletions(-)
backends/baum.c +2 -4
@@ -561,10 +561,9 @@ static void baum_close(struct CharDriverState *chr)g_free (baum); } -CharDriverState *chr_baum_init (void ) +CharDriverState *chr_baum_init (CharDriverState *chr) {BaumDriverState *baum; -CharDriverState *chr;brlapi_handle_t *handle;#ifdef CONFIG_SDL SDL_SysWMinfo info;
@@ -572,7 +571,7 @@ CharDriverState *chr_baum_init(void)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;
@@ -620,7 +619,6 @@ fail:brlapi__closeConnection (handle); fail_handle:g_free (handle); -g_free (chr);g_free (baum);return NULL ; }
backends/msmouse.c +1 -4
@@ -63,11 +63,8 @@ static void msmouse_chr_close (struct CharDriverState *chr)g_free (chr); } -CharDriverState *qemu_chr_open_msmouse (void ) +CharDriverState *qemu_chr_open_msmouse (CharDriverState *chr) { -CharDriverState *chr; - - chr =g_malloc0 (sizeof (CharDriverState)); chr->chr_write = msmouse_chr_write; chr->chr_close = msmouse_chr_close;
hw/misc/ivshmem.c +8 -3
@@ -283,12 +283,17 @@ static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier * {/* create a event character device based on the passed eventfd */ IVShmemState *s = opaque; -CharDriverState * chr; +CharDriverState *chr, *newchr;int eventfd =event_notifier_get_fd (n); - chr =qemu_chr_open_eventfd (eventfd); - + newchr =g_malloc0 (sizeof (*chr)); +if (newchr ==NULL ) { +fprintf (stderr,"creating eventfd for eventfd %d failed\n" , eventfd); +exit (-1 ); + } + chr =qemu_chr_open_eventfd (newchr, eventfd);if (chr ==NULL ) { +g_free (newchr);fprintf (stderr,"creating eventfd for eventfd %d failed\n" , eventfd);exit (-1 ); }
include/sysemu/char.h +5 -4
@@ -280,21 +280,22 @@ CharDriverState *qemu_chr_find(const char *name);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); -void register_char_driver (const char *name,CharDriverState *(*open)(QemuOpts *)); +void register_char_driver (const char *name, +CharDriverState *(*open)(CharDriverState *,QemuOpts *));void register_char_driver_qapi (const char *name,int kind,void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp));/* add an eventfd to the qemu devices that are polled */ -CharDriverState *qemu_chr_open_eventfd (int eventfd); +CharDriverState *qemu_chr_open_eventfd (CharDriverState *chr,int eventfd);extern int term_escape_char;CharDriverState *qemu_char_get_next_serial (void );/* msmouse */ -CharDriverState *qemu_chr_open_msmouse (void ); +CharDriverState *qemu_chr_open_msmouse (CharDriverState *chr);/* baum.c */ -CharDriverState *chr_baum_init (void ); +CharDriverState *chr_baum_init (CharDriverState *chr);#endif
include/ui/console.h +2 -2
@@ -300,9 +300,9 @@ void qemu_console_copy(QemuConsole *con, int src_x, int src_y,DisplaySurface *qemu_console_surface (QemuConsole *con);DisplayState *qemu_console_displaystate (QemuConsole *console); -typedef CharDriverState *(VcHandler )(ChardevVC *vc); +typedef CharDriverState *(VcHandler )(CharDriverState *chr,ChardevVC *vc); -CharDriverState *vc_init (ChardevVC *vc); +CharDriverState *vc_init (CharDriverState *chr,ChardevVC *vc);void register_vc_handler (VcHandler *handler);/* sdl.c */
include/ui/qemu-spice.h +4 -2
@@ -44,9 +44,11 @@ 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_vmc (const char *type); +CharDriverState *qemu_chr_open_spice_vmc (CharDriverState *chr, +const char *type);#if SPICE_SERVER_VERSION >=0x000c02 -CharDriverState *qemu_chr_open_spice_port (const char *name); +CharDriverState *qemu_chr_open_spice_port (CharDriverSTate *chr, +const char *name);void qemu_spice_register_ports (void );#else static inline CharDriverState *qemu_chr_open_spice_port (const char *name)
qemu-char.c +82 -98
550 lines not on this page · raw message
spice-qemu-char.c +6 -8
@@ -240,12 +240,10 @@ static void print_allowed_subtypes(void)fprintf (stderr,"\n" ); } -static CharDriverState *chr_open (const char *subtype) +static CharDriverState *chr_open (CharDriverState *chr,const char *subtype) { -CharDriverState *chr;SpiceCharDriver *s; - chr =g_malloc0 (sizeof (CharDriverState)); s =g_malloc0 (sizeof (SpiceCharDriver)); s->chr = chr; s->active = false;
@@ -261,7 +259,7 @@ static CharDriverState *chr_open(const char *subtype)return chr; } -CharDriverState *qemu_chr_open_spice_vmc (const char *type) +CharDriverState *qemu_chr_open_spice_vmc (CharDriverState *chr,const char *type) {const char **psubtype =spice_server_char_device_recognized_subtypes ();
@@ -281,13 +279,13 @@ CharDriverState *qemu_chr_open_spice_vmc(const char *type)return NULL ; } -return chr_open (type); +return chr_open (chr, type); }#if SPICE_SERVER_VERSION >=0x000c02 -CharDriverState *qemu_chr_open_spice_port (const char *name) +CharDriverState *qemu_chr_open_spice_port (CharDriverState *chr, +const char *name) { -CharDriverState *chr;SpiceCharDriver *s;if (name ==NULL ) {
@@ -295,7 +293,7 @@ CharDriverState *qemu_chr_open_spice_port(const char *name)return NULL ; } - chr =chr_open ("port" ); +chr_open (chr,"port" ); s = chr->opaque; s->sin.portname =g_strdup (name);
ui/console.c +3 -7
@@ -1751,15 +1751,12 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds) chr->init (chr); } -static CharDriverState *text_console_init (ChardevVC *vc) +static CharDriverState *text_console_init (CharDriverState *chr,ChardevVC *vc) { -CharDriverState *chr;QemuConsole *s;unsigned width =0 ;unsigned height =0 ; - chr =g_malloc0 (sizeof (CharDriverState)); -if (vc->has_width) { width = vc->width; }else if (vc->has_cols) {
@@ -1781,7 +1778,6 @@ static CharDriverState *text_console_init(ChardevVC *vc) }if (!s) { -g_free (chr);return NULL ; }
@@ -1797,9 +1793,9 @@ static CharDriverState *text_console_init(ChardevVC *vc)static VcHandler *vc_handler = text_console_init; -CharDriverState *vc_init (ChardevVC *vc) +CharDriverState *vc_init (CharDriverState *chr,ChardevVC *vc) { -return vc_handler (vc); +return vc_handler (chr, vc); }void register_vc_handler (VcHandler *handler)
Signature · 1 line
1.7.9.5
PATCH 2/20 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.
--- include/sysemu/char.h | 3 ++ qemu-char.c | 84 +++++++++++++++++++++++++++++++++++++++++++------ qemu-options.hx | 11 +++++-- 3 files changed, 85 insertions(+), 13 deletions(-)
include/sysemu/char.h +3 -0
@@ -79,6 +79,9 @@ struct CharDriverState {int avail_connections;QemuOpts *opts;QTAILQ_ENTRY (CharDriverState) next; +GSList *backend; +QEMUTimer *recon_timer; +uint64_t recon_time; };/**
qemu-char.c +74 -10
143 lines not on this page · raw message
qemu-options.hx +8 -3
@@ -1772,8 +1772,9 @@ ETEXI 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"
@@ -1845,7 +1846,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
@@ -1859,6 +1860,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.9.5
PATCH 3/20 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 | 18 ++++++++++++++++-- spice-qemu-char.c | 7 +++++-- 2 files changed, 21 insertions(+), 4 deletions(-)
qemu-char.c +16 -2
@@ -98,10 +98,13 @@ 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->be_open =1 ;break ;case CHR_EVENT_CLOSED :if (s->recon_timer) {
@@ -126,13 +129,24 @@ void qemu_chr_be_event(CharDriverState *s, int event)static gboolean qemu_chr_be_generic_open_bh (gpointer 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->be_open) { +qemu_chr_be_event (s,CHR_EVENT_OPENED ); + } s->idle_tag =0 ;return FALSE; }void qemu_chr_be_generic_open (CharDriverState *s) { +/* See the comment in qemu_chr_generic_open_bh() for why this is here */ + s->be_open =1 ;if (s->idle_tag ==0 ) { s->idle_tag =g_idle_add (qemu_chr_be_generic_open_bh, s); }
spice-qemu-char.c +5 -2
@@ -97,8 +97,11 @@ 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.9.5
PATCH 4/20 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 file changed, 1 deletion(-)
qemu-char.c +0 -1
@@ -2145,7 +2145,6 @@ static void win_stdio_close(CharDriverState *chr) }g_free (chr->opaque); -g_free (chr); } static CharDriverState *qemu_chr_open_stdio(CharDriverState *chr,
Signature · 1 line
1.7.9.5
PATCH 5/20 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 | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-)
qemu-char.c +29 -6
@@ -796,6 +796,8 @@ typedef struct FDCharDriver {guint fd_in_tag;int max_size;QTAILQ_ENTRY (FDCharDriver) node; +int close_fdin; +int close_fdout; } FDCharDriver;static int fd_chr_write (CharDriverState *chr,const uint8_t *buf,int len)
@@ -805,6 +807,18 @@ static int fd_chr_write(CharDriverState *chr, const uint8_t *buf, int len)return io_channel_send (s->fd_out, buf, len); } +static void fd_close_fds (FDCharDriver *s) +{ +if ((s->close_fdin != s->close_fdout) && (s->close_fdout !=-1 )) { +close (s->close_fdout); + } + s->close_fdout =-1 ; +if (s->close_fdin !=-1 ) { +close (s->close_fdin); + } + s->close_fdin =-1 ; +} +static gboolean fd_chr_read (GIOChannel *chan,GIOCondition cond,void *opaque) {CharDriverState *chr = opaque;
@@ -829,6 +843,7 @@ static gboolean fd_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)io_remove_watch_poll (s->fd_in_tag); s->fd_in_tag =0 ; } +fd_close_fds (s);qemu_chr_be_event (chr,CHR_EVENT_CLOSED );return FALSE; }
@@ -884,19 +899,27 @@ static void fd_chr_close(struct CharDriverState *chr)g_io_channel_unref (s->fd_out); } +fd_close_fds (s);g_free (s);qemu_chr_be_event (chr,CHR_EVENT_CLOSED ); }/* 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 =io_channel_from_fd (fd_in); s->fd_out =io_channel_from_fd (fd_out); +if (close_fds_on_close) { + s->close_fdin = fd_in; + s->close_fdout = fd_out; + }else { + s->close_fdin = s->close_fdout =-1 ; + }fcntl (fd_out,F_SETFL ,O_NONBLOCK ); s->chr = chr; chr->opaque = s;
@@ -936,7 +959,7 @@ static CharDriverState *qemu_chr_open_pipe(CharDriverState *chr,return NULL ; } } -return qemu_chr_open_fd (chr, fd_in, fd_out); +return qemu_chr_open_fd (chr, fd_in, fd_out, TRUE); }/* init terminal so that we can grab keys */
@@ -990,7 +1013,7 @@ static CharDriverState *qemu_chr_open_stdio(CharDriverState *chr,fcntl (0 ,F_SETFL ,O_NONBLOCK );atexit (term_exit); -qemu_chr_open_fd (chr,0 ,1 ); +qemu_chr_open_fd (chr,0 ,1 , FALSE); chr->chr_close = qemu_chr_close_stdio; chr->chr_set_echo = qemu_chr_set_echo_stdio; stdio_allow_signal = display_type !=DT_NOGRAPHIC ;
@@ -1473,7 +1496,7 @@ static void qemu_chr_close_tty(CharDriverState *chr)static CharDriverState *qemu_chr_open_tty_fd (CharDriverState *chr,int fd) {tty_serial_init (fd,115200 ,'N' ,8 ,1 ); -qemu_chr_open_fd (chr, fd, fd); +qemu_chr_open_fd (chr, fd, fd, TRUE); chr->chr_ioctl = tty_serial_ioctl; chr->chr_close = qemu_chr_close_tty;return chr;
@@ -2561,7 +2584,7 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)#ifndef _WIN32CharDriverState *qemu_chr_open_eventfd (CharDriverState *chr,int eventfd) { -return qemu_chr_open_fd (chr, eventfd, eventfd); +return qemu_chr_open_fd (chr, eventfd, eventfd, FALSE); }#endif
@@ -3692,7 +3715,7 @@ static CharDriverState *qmp_chardev_open_file(CharDriverState *chr, } } -return qemu_chr_open_fd (chr, in, out); +return qemu_chr_open_fd (chr, in, out, TRUE); } static CharDriverState *qmp_chardev_open_serial(CharDriverState *chr,
Signature · 1 line
1.7.9.5
PATCH 6/20 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 | 1 + hw/ipmi/Makefile.objs | 1 + hw/ipmi/ipmi.c | 167 +++++++++++++++++++++++++ hw/ipmi/ipmi.h | 241 ++++++++++++++++++++++++++++++++++++ qemu-doc.texi | 2 + 7 files changed, 414 insertions(+) create mode 100644 hw/ipmi/Makefile.objs create mode 100644 hw/ipmi/ipmi.c create mode 100644 hw/ipmi/ipmi.h
default-configs/i386-softmmu.mak +1 -0
@@ -10,6 +10,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
@@ -10,6 +10,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 +1 -0
@@ -12,6 +12,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += i2c/ devices-dirs-$(CONFIG_SOFTMMU) += ide/ devices-dirs-$(CONFIG_SOFTMMU) += input/ devices-dirs-$(CONFIG_SOFTMMU) += intc/ +devices-dirs-$(CONFIG_SOFTMMU) += ipmi/ devices-dirs-$(CONFIG_SOFTMMU) += isa/ devices-dirs-$(CONFIG_SOFTMMU) += misc/ devices-dirs-$(CONFIG_SOFTMMU) += net/
hw/ipmi/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +common-obj-$(CONFIG_IPMI) += ipmi.o
hw/ipmi/ipmi.c new file +167 -0
167 lines not on this page · raw message
hw/ipmi/ipmi.h new file +241 -0
241 lines not on this page · raw message
qemu-doc.texi +2 -0
@@ -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.9.5
PATCH 7/20 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/ipmi/Makefile.objs | 1 + hw/ipmi/isa_ipmi.c | 150 ++++++++++++++++++++++++++++++++++++ include/hw/nvram/fw_cfg.h | 11 ++- 5 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 hw/ipmi/isa_ipmi.c
default-configs/i386-softmmu.mak +1 -0
@@ -11,6 +11,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
@@ -11,6 +11,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/ipmi/Makefile.objs +1 -0
@@ -1 +1,2 @@ common-obj-$(CONFIG_IPMI) += ipmi.o +common-obj-$(CONFIG_ISA_IPMI) += isa_ipmi.o
hw/ipmi/isa_ipmi.c new file +150 -0
150 lines not on this page · raw message
include/hw/nvram/fw_cfg.h +10 -1
@@ -37,7 +37,16 @@#define FW_CFG_FILE_FIRST 0x20#define FW_CFG_FILE_SLOTS 0x10 -#define FW_CFG_MAX_ENTRY (FW_CFG_FILE_FIRST+FW_CFG_FILE_SLOTS) + +#define FW_CFG_IPMI_INTERFACE 0x30 +#define FW_CFG_IPMI_BASE_ADDR 0x31 +#define FW_CFG_IPMI_REG_SPACE 0x32 +#define FW_CFG_IPMI_REG_SPACING 0x33 +#define FW_CFG_IPMI_SLAVE_ADDR 0x34 +#define FW_CFG_IPMI_IRQ 0x35 +#define FW_CFG_IPMI_VERSION 0x36 + +#define FW_CFG_MAX_ENTRY (FW_CFG_IPMI_VERSION + 1)#define FW_CFG_WRITE_CHANNEL 0x4000#define FW_CFG_ARCH_LOCAL 0x8000
Signature · 1 line
1.7.9.5
PATCH 8/20 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/ipmi/Makefile.objs | 1 + hw/ipmi/ipmi_kcs.c | 342 ++++++++++++++++++++++++++++++++++++ 4 files changed, 345 insertions(+) create mode 100644 hw/ipmi/ipmi_kcs.c
default-configs/i386-softmmu.mak +1 -0
@@ -12,6 +12,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
@@ -12,6 +12,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/ipmi/Makefile.objs +1 -0
@@ -1,2 +1,3 @@ common-obj-$(CONFIG_IPMI) += ipmi.o common-obj-$(CONFIG_ISA_IPMI) += isa_ipmi.o +common-obj-$(CONFIG_IPMI_KCS) += ipmi_kcs.o
hw/ipmi/ipmi_kcs.c new file +342 -0
342 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 9/20 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/ipmi/Makefile.objs | 1 + hw/ipmi/ipmi_bt.c | 365 ++++++++++++++++++++++++++++++++++++ 4 files changed, 368 insertions(+) create mode 100644 hw/ipmi/ipmi_bt.c
default-configs/i386-softmmu.mak +1 -0
@@ -13,6 +13,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
@@ -13,6 +13,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/ipmi/Makefile.objs +1 -0
@@ -1,3 +1,4 @@ common-obj-$(CONFIG_IPMI) += ipmi.o common-obj-$(CONFIG_ISA_IPMI) += isa_ipmi.o common-obj-$(CONFIG_IPMI_KCS) += ipmi_kcs.o +common-obj-$(CONFIG_IPMI_BT) += ipmi_bt.o
hw/ipmi/ipmi_bt.c new file +365 -0
365 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 10/20 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/ipmi/Makefile.objs | 1 + hw/ipmi/ipmi_sim.c | 1551 ++++++++++++++++++++++++++++++++++++ 4 files changed, 1554 insertions(+) create mode 100644 hw/ipmi/ipmi_sim.c
default-configs/i386-softmmu.mak +1 -0
@@ -14,6 +14,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
@@ -14,6 +14,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/ipmi/Makefile.objs +1 -0
@@ -2,3 +2,4 @@ common-obj-$(CONFIG_IPMI) += ipmi.o common-obj-$(CONFIG_ISA_IPMI) += isa_ipmi.o common-obj-$(CONFIG_IPMI_KCS) += ipmi_kcs.o common-obj-$(CONFIG_IPMI_BT) += ipmi_bt.o +common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_sim.o
hw/ipmi/ipmi_sim.c new file +1551 -0
1,551 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 11/20 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/ipmi/Makefile.objs | 1 + hw/ipmi/ipmi_extern.c | 475 ++++++++++++++++++++++++++++++++++++ 4 files changed, 478 insertions(+) create mode 100644 hw/ipmi/ipmi_extern.c
default-configs/i386-softmmu.mak +1 -0
@@ -15,6 +15,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
@@ -15,6 +15,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/ipmi/Makefile.objs +1 -0
@@ -3,3 +3,4 @@ common-obj-$(CONFIG_ISA_IPMI) += isa_ipmi.o common-obj-$(CONFIG_IPMI_KCS) += ipmi_kcs.o common-obj-$(CONFIG_IPMI_BT) += ipmi_bt.o common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_sim.o +common-obj-$(CONFIG_IPMI_EXTERN) += ipmi_extern.o
hw/ipmi/ipmi_extern.c new file +475 -0
475 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 12/20 ipmi: Add tests
In reply to [email protected]From: Corey Minyard <[email protected]>
Test the KCS interface with a local BMC and a BT interface with an external BMC.
--- tests/Makefile | 4 + tests/ipmi-bt-test.c | 444 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/ipmi-kcs-test.c | 294 ++++++++++++++++++++++++++++++++ 3 files changed, 742 insertions(+) create mode 100644 tests/ipmi-bt-test.c create mode 100644 tests/ipmi-kcs-test.c
tests/Makefile +4 -0
@@ -55,6 +55,8 @@ check-qtest-i386-y += tests/ide-test$(EXESUF) check-qtest-i386-y += tests/hd-geo-test$(EXESUF) gcov-files-i386-y += hw/hd-geometry.c check-qtest-i386-y += tests/rtc-test$(EXESUF) +check-qtest-i386-y += tests/ipmi-kcs-test$(EXESUF) +check-qtest-i386-y += tests/ipmi-bt-test$(EXESUF) check-qtest-i386-y += tests/i440fx-test$(EXESUF) check-qtest-i386-y += tests/fw_cfg-test$(EXESUF) check-qtest-x86_64-y = $(check-qtest-i386-y)
@@ -129,6 +131,8 @@ tests/rtc-test$(EXESUF): tests/rtc-test.o tests/m48t59-test$(EXESUF): tests/m48t59-test.o tests/fdc-test$(EXESUF): tests/fdc-test.o tests/ide-test$(EXESUF): tests/ide-test.o $(libqos-pc-obj-y) +tests/ipmi-kcs-test$(EXESUF): tests/ipmi-kcs-test.o +tests/ipmi-bt-test$(EXESUF): tests/ipmi-bt-test.o tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y)
tests/ipmi-bt-test.c new file +444 -0
444 lines not on this page · raw message
tests/ipmi-kcs-test.c new file +294 -0
294 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 13/20 ipmi: Add documentation
In reply to [email protected]From: Corey Minyard <[email protected]>
Add some basic documentation for the IPMI device.
--- qemu-options.hx | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
qemu-options.hx +35 -0
@@ -327,6 +327,41 @@ Add device @var{driver}. @var{prop}=@var{value} sets driver properties. Valid properties depend on the driver. To get help on possible drivers and properties, use @code{-device help} and @code{-device @var{driver},help}. + +Some drivers are: +@item -device isa-ipmi[,interface=kcs|bt][,iobase=@var{val}][,irq=@var{val}][,slave_addr=@var{val}][,chardev=name] + +Add an IPMI device. This also adds a corresponding SMBIOS entry to the +SMBIOS tables for x86. The following options are handled: +@table @option +@item interface=kcs|bt +Define the interface type to use. Currently the IPMI-defined KCS and +BT interfaces are handled. The default is KCS. +@item iobase=@var{val} +Define the I/O address of the interface. The default is 0xca0 for KCS +and 0xe4 for BT. +@item irq=@var{val} +Define the interrupt to use. The default is 5. To disable interrupts, +set this to 0. +@item slave_addr=@var{val} +The IPMI slave address to use for the BMC. The default is 0x20. +@item chardev=name +If a chardev is not specified, the IPMI driver uses a built-in baseboard +management controller (BMC) simulator. It provides a basic BMC with a +watchdog timer and associated sensor. + +If a chardev is specified, A connection is made to an external BMC +simulator. If you do this, it is strongly recommended that you use +the "reconnect=" chardev option to reconnect to the simulator if the +connection is lost. Note that if this is not used carefully, it can +be a security issue, as the interface has the ability to send resets, +NMIs, and power off the VM. It's best if QEMU makes a connection to +an external simulator running on a secure port on localhost, so +neither the simulator nor QEMU is exposed to any outside network. + +See the "lanserv/README.vm" file in the OpenIPMI library for more +details on the external interface. +@end table ETEXI DEF("name", HAS_ARG, QEMU_OPTION_name,
Signature · 1 line
1.7.9.5
PATCH 14/20 ipmi: Add migration capability to the IPMI device.
In reply to [email protected]From: Corey Minyard <[email protected]>
--- hw/ipmi/ipmi.c | 17 +++++++++++++++++ hw/ipmi/ipmi.h | 2 ++ hw/ipmi/ipmi_bt.c | 14 ++++++++++++++ hw/ipmi/ipmi_extern.c | 42 ++++++++++++++++++++++++++++++++++++++---- hw/ipmi/ipmi_kcs.c | 15 +++++++++++++++ hw/ipmi/ipmi_sim.c | 31 +++++++++++++++++++++++++++++++ hw/ipmi/isa_ipmi.c | 12 ++++++++++++ 7 files changed, 129 insertions(+), 4 deletions(-)
hw/ipmi/ipmi.c +17 -0
@@ -150,6 +150,23 @@ int ipmi_bmc_init(IPMIBmc *s)return 0 ; } +const VMStateDescription vmstate_IPMIInterface = { + .name =TYPE_IPMI_INTERFACE , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_BOOL (obf_irq_set, IPMIInterface), +VMSTATE_BOOL (atn_irq_set, IPMIInterface), +VMSTATE_BOOL (use_irq, IPMIInterface), +VMSTATE_BOOL (irqs_enabled, IPMIInterface), +VMSTATE_UINT32 (outpos, IPMIInterface), +VMSTATE_UINT32 (outlen, IPMIInterface), +VMSTATE_VBUFFER_UINT32 (inmsg, IPMIInterface,1 ,NULL ,0 , inlen), +VMSTATE_BOOL (write_end, IPMIInterface), +VMSTATE_END_OF_LIST () + } +}; +static TypeInfo ipmi_bmc_type_info = { .name =TYPE_IPMI_BMC , .parent =TYPE_OBJECT ,
hw/ipmi/ipmi.h +2 -0
@@ -187,6 +187,8 @@ typedef struct IPMIInterfaceClass { unsigned char *rsp, unsigned int rsp_len); } IPMIInterfaceClass; +extern const VMStateDescription vmstate_IPMIInterface; +int ipmi_interface_init (IPMIInterface *s);void ipmi_interface_reset (IPMIInterface *s);
hw/ipmi/ipmi_bt.c +14 -0
@@ -325,6 +325,19 @@ static void ipmi_bt_set_atn(IPMIInterface *s, int val, int irq) } } +static const VMStateDescription vmstate_ipmi_bt = { + .name =TYPE_IPMI_INTERFACE_BT , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT8 (control_reg, IPMIBtInterface), +VMSTATE_UINT8 (mask_reg, IPMIBtInterface), +VMSTATE_UINT8 (waiting_rsp, IPMIBtInterface), +VMSTATE_UINT8 (waiting_seq, IPMIBtInterface), +VMSTATE_END_OF_LIST () + } +}; +static int ipmi_bt_init (IPMIInterface *s) {IPMIBtInterface *bt =IPMI_INTERFACE_BT (s);
@@ -335,6 +348,7 @@ static int ipmi_bt_init(IPMIInterface *s) s->io_length =3 ;memory_region_init_io (&s->io, &ipmi_bt_io_ops, bt,"ipmi-bt" ,3 ); +vmstate_register (NULL ,0 , &vmstate_ipmi_bt, bt);return 0 ; }
hw/ipmi/ipmi_extern.c +38 -4
60 lines not on this page · raw message
hw/ipmi/ipmi_kcs.c +15 -0
@@ -302,6 +302,20 @@ static void ipmi_kcs_set_atn(IPMIInterface *s, int val, int irq) } } +static const VMStateDescription vmstate_ipmi_kcs = { + .name =TYPE_IPMI_INTERFACE_KCS , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT8 (status_reg, IPMIKcsInterface), +VMSTATE_UINT8 (data_out_reg, IPMIKcsInterface), +VMSTATE_INT16 (data_in_reg, IPMIKcsInterface), +VMSTATE_INT16 (cmd_reg, IPMIKcsInterface), +VMSTATE_UINT8 (waiting_rsp, IPMIKcsInterface), +VMSTATE_END_OF_LIST () + } +}; +static int ipmi_kcs_init (IPMIInterface *s) {IPMIKcsInterface *kcs =IPMI_INTERFACE_KCS (s);
@@ -312,6 +326,7 @@ static int ipmi_kcs_init(IPMIInterface *s) s->io_length =2 ;memory_region_init_io (&s->io, &ipmi_kcs_io_ops, kcs,"ipmi-kcs" ,2 ); +vmstate_register (NULL ,0 , &vmstate_ipmi_kcs, kcs);return 0 ; }
hw/ipmi/ipmi_sim.c +31 -0
@@ -1481,6 +1481,34 @@ static const uint8_t init_sdrs[] = {0xff ,0xff ,0x00 ,0x00 ,0x00 }; +static const VMStateDescription vmstate_ipmi_sim = { + .name =TYPE_IPMI_BMC_SIMULATOR , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT8 (bmc_global_enables, IPMISimBmc), +VMSTATE_UINT8 (msg_flags, IPMISimBmc), +VMSTATE_BOOL (watchdog_initialized, IPMISimBmc), +VMSTATE_UINT8 (watchdog_use, IPMISimBmc), +VMSTATE_UINT8 (watchdog_action, IPMISimBmc), +VMSTATE_UINT8 (watchdog_pretimeout, IPMISimBmc), +VMSTATE_BOOL (watchdog_expired, IPMISimBmc), +VMSTATE_UINT16 (watchdog_timeout, IPMISimBmc), +VMSTATE_BOOL (watchdog_running, IPMISimBmc), +VMSTATE_BOOL (watchdog_preaction_ran, IPMISimBmc), +VMSTATE_INT64 (watchdog_expiry, IPMISimBmc), +VMSTATE_UINT8_ARRAY (evtbuf, IPMISimBmc,16 ), +VMSTATE_UINT8 (sensors[IPMI_WATCHDOG_SENSOR ].status, IPMISimBmc), +VMSTATE_UINT8 (sensors[IPMI_WATCHDOG_SENSOR ].reading, IPMISimBmc), +VMSTATE_UINT16 (sensors[IPMI_WATCHDOG_SENSOR ].states, IPMISimBmc), +VMSTATE_UINT16 (sensors[IPMI_WATCHDOG_SENSOR ].assert_states, IPMISimBmc), +VMSTATE_UINT16 (sensors[IPMI_WATCHDOG_SENSOR ].deassert_states, + IPMISimBmc), +VMSTATE_UINT16 (sensors[IPMI_WATCHDOG_SENSOR ].assert_enable, IPMISimBmc), +VMSTATE_END_OF_LIST () + } +}; +static int ipmi_sim_init (IPMIBmc *b) {unsigned int i;
@@ -1525,6 +1553,9 @@ static int ipmi_sim_init(IPMIBmc *b)register_cmds (ss); ss->timer =qemu_new_timer_ns (vm_clock, ipmi_timeout, ss); + +vmstate_register (NULL ,0 , &vmstate_ipmi_sim, ss); +return 0 ; }
hw/ipmi/isa_ipmi.c +12 -0
@@ -126,12 +126,24 @@ static Property ipmi_isa_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static const VMStateDescription vmstate_isa_ipmi = { + .name =TYPE_ISA_IPMI , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_STRUCT_POINTER (intf, ISAIPMIDevice, vmstate_IPMIInterface, + IPMIInterface *), +VMSTATE_END_OF_LIST () + } +}; +static void ipmi_isa_class_initfn (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);ISADeviceClass *ic =ISA_DEVICE_CLASS (klass); ic->init = ipmi_isa_initfn; dc->reset = ipmi_isa_reset; + dc->vmsd = &vmstate_isa_ipmi; dc->props = ipmi_isa_properties; }
Signature · 1 line
1.7.9.5
PATCH 15/20 acpi: Add a way to extend tables
In reply to [email protected]From: Corey Minyard <[email protected]>
Add a function that can extend the contents of a given ACPI table to add on new entries. This way devices that have ACPI entries can add them.
--- hw/acpi/core.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/acpi.h | 2 ++ 2 files changed, 49 insertions(+)
hw/acpi/core.c +47 -0
@@ -229,6 +229,53 @@ static void acpi_table_install(const char unsigned *blob, size_t bloblen, ACPI_TABLE_PFX_SIZE, acpi_payload_size); } +void acpi_append_to_table (const char *sig,void *blob,size_t bloblen, +Error **errp) +{ +struct acpi_table_header *ext_hdr; +unsigned int ntables, i; +size_t acpi_payload_size; +size_t pos, pos2; + +if (!acpi_tables) +return ; + + ntables =le16_to_cpupu ((uint16_t *)acpi_tables); + pos =sizeof (uint16_t ); +for (i =0 ; i < ntables; i++) { + ext_hdr = (void *) (((char *) acpi_tables) + pos); +if (memcmp (sig, ext_hdr->sig,4 ) ==0 ) +break ; + pos +=le16_to_cpupu (&ext_hdr->_length) +ACPI_TABLE_PFX_SIZE ; + } +if (i == ntables) +return ; + + acpi_payload_size =le16_to_cpupu (&ext_hdr->_length); +if (acpi_payload_size + bloblen >UINT16_MAX ) { +error_setg (errp,"ACPI table overflow adding field" ); +return ; + } + + acpi_tables =g_realloc (acpi_tables, acpi_tables_len + bloblen); + + pos2 = pos + acpi_payload_size +ACPI_TABLE_PFX_SIZE ; +memcpy (acpi_tables + pos2 + bloblen, acpi_tables + pos2, + acpi_tables_len - pos2); +memcpy (acpi_tables + pos2, blob, bloblen); + + acpi_payload_size += bloblen; + + ext_hdr = (void *) (((char *) acpi_tables) + pos); + ext_hdr->_length =cpu_to_le16 (acpi_payload_size); + ext_hdr->length =cpu_to_le32 (acpi_payload_size); + + ext_hdr->checksum =0 ; + ext_hdr->checksum =acpi_checksum ((const char unsigned *)ext_hdr + +ACPI_TABLE_PFX_SIZE , acpi_payload_size); + acpi_tables_len += bloblen; +} +void acpi_table_add (const QemuOpts *opts,Error **errp) {AcpiTableOptions *hdrs =NULL ;
include/hw/acpi/acpi.h +2 -0
@@ -166,5 +166,7 @@ extern char unsigned *acpi_tables;extern size_t acpi_tables_len;void acpi_table_add (const QemuOpts *opts,Error **errp); +void acpi_append_to_table (const char *sig,void *blob,size_t bloblen, +Error **errp);#endif /* !QEMU_HW_ACPI_H */
Signature · 1 line
1.7.9.5
PATCH 16/20 acpi: Add table construction tools
In reply to [email protected]From: Corey Minyard <[email protected]>
Add a set of functions to allow construction of ACPI elements dynamically.
--- hw/acpi/Makefile.objs | 2 +- hw/acpi/acpi-elements.c | 351 +++++++++++++++++++++++++++++++++++++++ include/hw/acpi/acpi-elements.h | 77 +++++++++ 3 files changed, 429 insertions(+), 1 deletion(-) create mode 100644 hw/acpi/acpi-elements.c create mode 100644 include/hw/acpi/acpi-elements.h
hw/acpi/Makefile.objs +1 -1
@@ -1,2 +1,2 @@ -common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o +common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o acpi-elements.o
hw/acpi/acpi-elements.c new file +351 -0
351 lines not on this page · raw message
include/hw/acpi/acpi-elements.h new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 17/20 pc: Postpone adding ACPI and SMBIOS to fw_cfg
In reply to [email protected]From: Corey Minyard <[email protected]>
Postpone the addition of the ACPI and SMBIOS tables until after device initialization. This allows devices to add entries to these tables.
--- hw/i386/pc.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-)
hw/i386/pc.c +30 -8
@@ -598,8 +598,6 @@ static unsigned int pc_apic_id_limit(unsigned int max_cpus)static void *bochs_bios_init (void ) {void *fw_cfg; -uint8_t *smbios_table; -size_t smbios_len;uint64_t *numa_fw_cfg;int i, j;unsigned int apic_id_limit =pc_apic_id_limit (max_cpus);
@@ -622,14 +620,8 @@ static void *bochs_bios_init(void)fw_cfg_add_i16 (fw_cfg,FW_CFG_MAX_CPUS , (uint16_t )apic_id_limit);fw_cfg_add_i32 (fw_cfg,FW_CFG_ID ,1 );fw_cfg_add_i64 (fw_cfg,FW_CFG_RAM_SIZE , (uint64_t )ram_size); -fw_cfg_add_bytes (fw_cfg,FW_CFG_ACPI_TABLES , - acpi_tables, acpi_tables_len);fw_cfg_add_i32 (fw_cfg,FW_CFG_IRQ0_OVERRIDE ,kvm_allows_irq0_override ()); - smbios_table =smbios_get_table (&smbios_len); -if (smbios_table) -fw_cfg_add_bytes (fw_cfg,FW_CFG_SMBIOS_ENTRIES , - smbios_table, smbios_len);fw_cfg_add_bytes (fw_cfg,FW_CFG_E820_TABLE , &e820_table,sizeof (e820_table));
@@ -1012,6 +1004,31 @@ void pc_acpi_init(const char *default_dsdt) } } +struct pc_bios_post_init { +Notifier post_init; +void *fw_cfg; +}; + +/* Add the ACPI and SMBIOS tables after all the hardware has been initialized. +* This gives devices a chance to add to those tables. +*/ +static void pc_bios_post_initfn (Notifier *n,void *opaque) +{ + struct pc_bios_post_init *p = container_of(n, struct pc_bios_post_init, + post_init); +uint8_t *smbios_table; +size_t smbios_len; + +fw_cfg_add_bytes (p->fw_cfg,FW_CFG_ACPI_TABLES , + acpi_tables, acpi_tables_len); + smbios_table =smbios_get_table (&smbios_len); +if (smbios_table) +fw_cfg_add_bytes (p->fw_cfg,FW_CFG_SMBIOS_ENTRIES , + smbios_table, smbios_len); +} + +static struct pc_bios_post_init post_init; + void *pc_memory_init(MemoryRegion *system_memory, const char *kernel_filename, const char *kernel_cmdline,
@@ -1071,6 +1088,11 @@ void *pc_memory_init(MemoryRegion *system_memory,for (i =0 ; i < nb_option_roms; i++) {rom_add_option (option_rom[i].name, option_rom[i].bootindex); } + + post_init.fw_cfg = fw_cfg; + post_init.post_init.notify = pc_bios_post_initfn; +qemu_add_machine_init_done_notifier (&post_init.post_init); +return fw_cfg; }
Signature · 1 line
1.7.9.5
PATCH 18/20 ipmi: Add ACPI table entries for BMCs
In reply to [email protected]From: Corey Minyard <[email protected]>
Use the new ACPI table construction tools to create an ACPI entry for IPMI.
--- hw/ipmi/isa_ipmi.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+)
hw/ipmi/isa_ipmi.c +127 -0
@@ -23,6 +23,8 @@*/ #include "hw/hw.h" #include "hw/isa/isa.h" +#include "hw/acpi/acpi-elements.h" +#include "hw/acpi/acpi.h" #include "hw/i386/pc.h" #include "qemu/timer.h" #include "sysemu/char.h"
@@ -36,16 +38,134 @@typedef struct ISAIPMIDevice {ISADevice dev;char *interface; +int intftype;uint32_t iobase; +uint32_t endaddr;uint32_t isairq; +uint8_t regspacing;uint8_t slave_addr; +uint8_t version;CharDriverState *chr;IPMIInterface *intf; }ISAIPMIDevice ; +static int +acpi_ipmi_crs_ops (char **data,int dlen,void *opaque) +{ +ISAIPMIDevice *info = opaque; +int len, rv; +uint8_t regspacing = info->regspacing; + +if (regspacing ==1 ) + regspacing =0 ; +/* IO(Decode16, x, y, z, c) */ + len =acpi_add_IO16 (data, dlen, info->iobase, info->endaddr, + regspacing, info->endaddr - info->iobase +1 ); +if (len <0 ) +return len; +if (info->isairq) { +/* Interrupt(ResourceConsumer,Level,ActiveHigh,Exclusive) {n} */ + rv =acpi_add_Interrupt (data, dlen, info->isairq, +ACPI_RESOURCE_CONSUMER , +ACPI_INTERRUPT_MODE_LEVEL , +ACPI_INTERRUPT_POLARITY_ACTIVE_HIGH , +ACPI_INTERRUPT_EXCLUSIVE ); +if (rv <0 ) +return rv; + len += rv; + } + rv =acpi_add_EndResource (data, dlen); +if (rv <0 ) +return rv; + len += rv; +return len; +} + +static int +acpi_ipmi_crs (char **data,int dlen,void *opaque) +{ +ISAIPMIDevice *info = opaque; +int len; + + len =acpi_add_BufferOp (NULL ,0 , acpi_ipmi_crs_ops, info); +if (len <0 ) +return len; +if (len <= dlen) { +acpi_add_BufferOp (data, dlen, acpi_ipmi_crs_ops, info); + } +return len; +} + +static int +acpi_ipmi_dev (char **data,int dlen,void *opaque) +{ +ISAIPMIDevice *info = opaque; +int len, rv; +char *name; +uint64_t val; + + name =g_strdup_printf ("ipmi_%s" , info->interface); + +/* Name(_HID, EISAID("IPI0001")) */ + len =acpi_add_Name (data, dlen,"_HID" , acpi_add_EISAID, + (void *)"IPI0001" ); +if (len <0 ) +return len; +/* Name(_STR, Unicode("ipmi_xxx")) */ + rv =acpi_add_Name (data, dlen,"_STR" , acpi_add_Unicode, name); +if (rv <0 ) +return rv; + len += rv; + val =0 ; +/* Name(_UID, 0) */ + rv =acpi_add_Name (data, dlen,"_UID" , acpi_add_Integer, &val); +if (rv <0 ) +return rv; + len += rv; +/* Name(_CRS, ResourceTemplate() { */ + rv =acpi_add_Name (data, dlen,"_CRS" , acpi_ipmi_crs, info); +if (rv <0 ) +return rv; + len += rv; + val = info->intftype; +/* Method(_IFT) { Return(i) } */ + rv =acpi_add_Method (data, dlen,"_IFT" ,0 , acpi_add_Return, &val); +if (rv <0 ) +return rv; + len += rv; + val = ((info->version &0xf0 ) <<4 ) | (info->version &0x0f ); +/* Method(_SRV) { Return(version) } */ + rv =acpi_add_Method (data, dlen,"_SRV" ,0 , acpi_add_Return, &val); +if (rv <0 ) +return rv; + len += rv; +return len; +} + +static void +ipmi_encode_acpi (ISAIPMIDevice *info) +{ +char ipmitable[200 ]; +char *tblptr = ipmitable; +int rc; +Error *err =NULL ; + +/* Device(MI0) { */ + rc =acpi_add_Device (&tblptr,sizeof (ipmitable),"MI0" , + acpi_ipmi_dev, info); +/* } */ +if (rc <0 ) { +fprintf (stderr,"Unable to format IPMI ACPI table entry\n" ); +return ; + } + +acpi_append_to_table ("DSDT" , ipmitable, rc, &err); +} +static int ipmi_isa_initfn (ISADevice *dev) {ISAIPMIDevice *isa =ISA_IPMI (dev); +IPMIInterfaceClass *intfk;char typename[20 ];Object *intfobj;IPMIInterface *intf;
@@ -69,6 +189,7 @@ static int ipmi_isa_initfn(ISADevice *dev) TYPE_IPMI_INTERFACE_PREFIX "%s", isa->interface); intfobj =object_new (typename); intf =IPMI_INTERFACE (intfobj); + intfk =IPMI_INTERFACE_GET_CLASS (intf); bmc->intf = intf; intf->bmc = bmc; intf->io_base = isa->iobase;
@@ -85,6 +206,10 @@ static int ipmi_isa_initfn(ISADevice *dev)/* These may be set by the interface. */ isa->iobase = intf->io_base; isa->slave_addr = intf->slave_addr; + isa->regspacing =1 ; + isa->endaddr =cpu_to_le64 (intf->io_base + intf->io_length -1 ); + isa->intftype = intfk->smbios_type; + isa->version =0x20 ;/* Version 2.0 */ if (isa->isairq !=0 ) {isa_init_irq (dev, &intf->irq, isa->isairq);
@@ -107,6 +232,8 @@ static int ipmi_isa_initfn(ISADevice *dev)isa_register_ioport (dev, &intf->io, intf->io_base); +ipmi_encode_acpi (isa); +return 0 ; }
Signature · 1 line
1.7.9.5
PATCH 19/20 smbios: Add a function to directly add an entry
In reply to [email protected]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/i386/smbios.c | 27 +++++++++++++++++++++++++++ include/hw/i386/smbios.h | 2 ++ 2 files changed, 29 insertions(+)
hw/i386/smbios.c +27 -0
@@ -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 ];
include/hw/i386/smbios.h +2 -0
@@ -28,6 +28,8 @@ struct smbios_structure_header {uint16_t handle; }QEMU_PACKED ; +int smbios_table_entry_add (struct smbios_structure_header *entry); +/* SMBIOS type 0 - BIOS Information */ struct smbios_type_0 {struct smbios_structure_header header;
Signature · 1 line
1.7.9.5
PATCH 20/20 ipmi: Add SMBIOS table entry
In reply to [email protected]From: Corey Minyard <[email protected]>
Add an IPMI table entry to the SMBIOS.
--- hw/ipmi/isa_ipmi.c | 23 +++++++++++++++++++++++ include/hw/i386/smbios.h | 12 ++++++++++++ 2 files changed, 35 insertions(+)
hw/ipmi/isa_ipmi.c +23 -0
@@ -29,6 +29,7 @@#include "qemu/timer.h" #include "sysemu/char.h" #include "sysemu/sysemu.h" +#include "hw/i386/smbios.h" #include "ipmi.h" /* This is the type the user specifies on the -device command line */
@@ -162,6 +163,27 @@ ipmi_encode_acpi(ISAIPMIDevice *info)acpi_append_to_table ("DSDT" , ipmitable, rc, &err); } +static void ipmi_encode_smbios (ISAIPMIDevice *info) +{ +struct smbios_type_38 smb38; + + smb38.header.type =38 ; + smb38.header.length =sizeof (smb38); + smb38.header.handle =cpu_to_le16 (0x3000 ); + smb38.interface_type = info->intftype; + smb38.ipmi_spec_revision =0x20 ; + smb38.i2c_slave_address = info->slave_addr; + smb38.nv_storage_device_address =0 ; + +/* or 1 to set it to I/O space */ + smb38.base_address =cpu_to_le64 (info->iobase |1 ); + +/* 1-byte boundaries, addr bit0=0, level triggered irq */ + smb38.base_address_modifier =1 ; + smb38.interrupt_number = info->isairq; +smbios_table_entry_add ((struct smbios_structure_header *) &smb38); +} +static int ipmi_isa_initfn (ISADevice *dev) {ISAIPMIDevice *isa =ISA_IPMI (dev);
@@ -233,6 +255,7 @@ static int ipmi_isa_initfn(ISADevice *dev)isa_register_ioport (dev, &intf->io, intf->io_base);ipmi_encode_acpi (isa); +ipmi_encode_smbios (isa);return 0 ; }
include/hw/i386/smbios.h +12 -0
@@ -156,6 +156,18 @@ struct smbios_type_32 {uint8_t boot_status; }QEMU_PACKED ; +/* SMBIOS type 38 - IPMI */ +struct smbios_type_38 { +struct smbios_structure_header header; +uint8_t interface_type; +uint8_t ipmi_spec_revision; +uint8_t i2c_slave_address; +uint8_t nv_storage_device_address; +uint64_t base_address; +uint8_t base_address_modifier; +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.9.5
Quoted 14 lines · On Wed, May 29, 2013 at 05:07:56PM -0500, [email protected] wrote:
I have finally gotten some time to work on this, this series of patches adds an IPMI interface to qemu. The changes are roughly:
patches 01-05 - Add the capability to have a chardev reconnect if the connections fails. This way, if using an external BMC, qemu will detect the failure and periodically attempt to reconnect. This also adds ways for the device code to get an event on a disconnect and connect so it can handle it properly. This is probably useful for things besides IPMI. There are also a few small bugfixes in this.
patches 06-14 - Add the IPMI device itself, with an ISA interface for now (PCI and others can also be added easily).
Quoted 7 lines
patches 15-18 - Add a way to dynamically add content to the ACPI tables, and add the capability to add the IPMI information to the table.
Patches 19-20 - Add a way to dynamically add content to the SMBIOS tables, and add an IPMI entry to the table.
I was pointed at these patches as an example of useful functionality that's out of qemu merely for lack of review resources. I'd like to help.
Now that we have code to generate ACPI tables directly in qemu, this series can be rebased on top of that, with no need for new FW CFG entries or bios changes.
If you have the time, pls Cc me on patches and I'll try to help shepherd them upstream.
Signature · 1 line
MST
Quoted 26 lines · Michael S. Tsirkin
Quoted 14 lines · On Wed, May 29, 2013 at 05:07:56PM -0500, [email protected] wrote:
I have finally gotten some time to work on this, this series of patches adds an IPMI interface to qemu. The changes are roughly:
patches 01-05 - Add the capability to have a chardev reconnect if the connections fails. This way, if using an external BMC, qemu will detect the failure and periodically attempt to reconnect. This also adds ways for the device code to get an event on a disconnect and connect so it can handle it properly. This is probably useful for things besides IPMI. There are also a few small bugfixes in this.
patches 06-14 - Add the IPMI device itself, with an ISA interface for now (PCI and others can also be added easily).
Quoted 7 lines
patches 15-18 - Add a way to dynamically add content to the ACPI tables, and add the capability to add the IPMI information to the table.
Patches 19-20 - Add a way to dynamically add content to the SMBIOS tables, and add an IPMI entry to the table.
I was pointed at these patches as an example of useful functionality that's out of qemu merely for lack of review resources. I'd like to help.
Quoted 7 lines
Now that we have code to generate ACPI tables directly in qemu, this series can be rebased on top of that, with no need for new FW CFG entries or bios changes.
If you have the time, pls Cc me on patches and I'll try to help shepherd them upstream.
Ok, thanks. I will make some time this week to get the patches updated to the current git tree.
-corey
Hi,
Am 05.11.2013 14:56, schrieb Michael S. Tsirkin:
Quoted 27 lines · On Wed, May 29, 2013 at 05:07:56PM -0500, [email protected] wrote:
Quoted 14 lines
I have finally gotten some time to work on this, this series of patches adds an IPMI interface to qemu. The changes are roughly:
patches 01-05 - Add the capability to have a chardev reconnect if the connections fails. This way, if using an external BMC, qemu will detect the failure and periodically attempt to reconnect. This also adds ways for the device code to get an event on a disconnect and connect so it can handle it properly. This is probably useful for things besides IPMI. There are also a few small bugfixes in this.
patches 06-14 - Add the IPMI device itself, with an ISA interface for now (PCI and others can also be added easily).
Quoted 7 lines
patches 15-18 - Add a way to dynamically add content to the ACPI tables, and add the capability to add the IPMI information to the table.
Patches 19-20 - Add a way to dynamically add content to the SMBIOS tables, and add an IPMI entry to the table.
I was pointed at these patches as an example of useful functionality that's out of qemu merely for lack of review resources. I'd like to help.
Quoted 6 lines
Now that we have code to generate ACPI tables directly in qemu, this series can be rebased on top of that, with no need for new FW CFG entries or bios changes.
If you have the time, pls Cc me on patches and I'll try to help shepherd them upstream.
Me too, I have IPMI on my radar for 1.8/2.0.
Our use case would be using IPMI tools to boot/reboot/shutdown a guest and to access its serial console as done for the physical hosts; we had discussed in the past where to locate such a TCP server component, whether in QEMU or libvirt - am I interpreting correctly that patch 11 is preparing an interface to have that as external process now? Or is it hidden somewhere in patch 10 or is this unimplemented in this version?
Also, some of the IPMI acronyms in the commit messages (KCS, BT, ...) could use some explanation in the next version. ;)
Regards,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Quoted 35 lines · Andreas Färber
Hi,
Am 05.11.2013 14:56, schrieb Michael S. Tsirkin:
Quoted 26 lines · On Wed, May 29, 2013 at 05:07:56PM -0500, [email protected] wrote:
Quoted 14 lines
I have finally gotten some time to work on this, this series of patches adds an IPMI interface to qemu. The changes are roughly:
patches 01-05 - Add the capability to have a chardev reconnect if the connections fails. This way, if using an external BMC, qemu will detect the failure and periodically attempt to reconnect. This also adds ways for the device code to get an event on a disconnect and connect so it can handle it properly. This is probably useful for things besides IPMI. There are also a few small bugfixes in this.
patches 06-14 - Add the IPMI device itself, with an ISA interface for now (PCI and others can also be added easily).
Quoted 7 lines
patches 15-18 - Add a way to dynamically add content to the ACPI tables, and add the capability to add the IPMI information to the table.
Patches 19-20 - Add a way to dynamically add content to the SMBIOS tables, and add an IPMI entry to the table.
I was pointed at these patches as an example of useful functionality that's out of qemu merely for lack of review resources. I'd like to help.
Quoted 6 lines
Now that we have code to generate ACPI tables directly in qemu, this series can be rebased on top of that, with no need for new FW CFG entries or bios changes.
If you have the time, pls Cc me on patches and I'll try to help shepherd them upstream.
Quoted 8 lines
Me too, I have IPMI on my radar for 1.8/2.0.
Our use case would be using IPMI tools to boot/reboot/shutdown a guest and to access its serial console as done for the physical hosts; we had discussed in the past where to locate such a TCP server component, whether in QEMU or libvirt - am I interpreting correctly that patch 11 is preparing an interface to have that as external process now? Or is it hidden somewhere in patch 10 or is this unimplemented in this version?
Patch 11 does that, it gives an external interface. The OpenIPMI library has a
simulator that will plug in to this interface to provide BMC functions and an
IPMI LAN interface.
You can do the boot/reboot/shutdown via the normal mechanisms with the external simulator. The internal simulator doesn't have an IPMI LAN interface,
though, so you would need the external interface.
I also have not provided a serial over LAN interface through this interface. If
that's what you are looking for, more work would need to be done.
Thanks,
-corey
Quoted 7 lines
Also, some of the IPMI acronyms in the commit messages (KCS, BT, ...) could use some explanation in the next version. ;)
Regards,
Andreas