Patchwork [v17,5/6] pvpanic: create pvpanic device by default

login
register
mail settings
Submitter Hu Tao
Date April 5, 2013, 6:36 a.m.
Message ID <a8f8ee9b0baaea4cc36055d70bd928a9c77392ab.1365143012.git.hutao@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/234054/
State New
Headers show

Comments

Hu Tao - April 5, 2013, 6:36 a.m.
Also parse command line options for ioport and set
it accordingly.

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 hw/i386/pc_piix.c |  2 ++
 hw/i386/pc_q35.c  |  1 +
 hw/pc.h           |  4 ++++
 hw/pvpanic.c      | 42 ++++++++++++++++++++++++++++++++++++++++++
 vl.c              |  2 ++
 5 files changed, 51 insertions(+)
Paolo Bonzini - April 5, 2013, 11:14 a.m.
Il 05/04/2013 08:36, Hu Tao ha scritto:
> Also parse command line options for ioport and set
> it accordingly.

This does not do the correct thing for versioned machine types like "-M
pc-1.4".  Also, adding stuff to vl.c is really something you cannot do.
 Please don't be afraid to ask!

See the attached patch, untested.  Feel free to take it with my S-o-b line.

Patches 1-4 and 6 are okay.

Paolo

> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> ---
>  hw/i386/pc_piix.c |  2 ++
>  hw/i386/pc_q35.c  |  1 +
>  hw/pc.h           |  4 ++++
>  hw/pvpanic.c      | 42 ++++++++++++++++++++++++++++++++++++++++++
>  vl.c              |  2 ++
>  5 files changed, 51 insertions(+)
> 
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 0abc9f1..897254a 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -217,6 +217,8 @@ static void pc_init1(MemoryRegion *system_memory,
>      if (pci_enabled) {
>          pc_pci_device_init(pci_bus);
>      }
> +
> +    pvpanic_init(isa_bus);
>  }
>  
>  static void pc_init_pci(QEMUMachineInitArgs *args)
> diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
> index 4f5f347..fd9ab01 100644
> --- a/hw/i386/pc_q35.c
> +++ b/hw/i386/pc_q35.c
> @@ -204,6 +204,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
>      pc_vga_init(isa_bus, host_bus);
>      audio_init(isa_bus, host_bus);
>      pc_nic_init(isa_bus, host_bus);
> +    pvpanic_init(isa_bus);
>      if (pci_enabled) {
>          pc_pci_device_init(host_bus);
>      }
> diff --git a/hw/pc.h b/hw/pc.h
> index 8e1dd4c..1311037 100644
> --- a/hw/pc.h
> +++ b/hw/pc.h
> @@ -178,6 +178,10 @@ static inline bool isa_ne2000_init(ISABus *bus, int base, int irq, NICInfo *nd)
>  /* pc_sysfw.c */
>  void pc_system_firmware_init(MemoryRegion *rom_memory);
>  
> +/* pvpanic.c */
> +int pvpanic_init(ISABus *bus);
> +int pvpanic_ioport(QemuOpts *opts, void *opaque);
> +
>  /* e820 types */
>  #define E820_RAM        1
>  #define E820_RESERVED   2
> diff --git a/hw/pvpanic.c b/hw/pvpanic.c
> index b3d10e2..2e237a4 100644
> --- a/hw/pvpanic.c
> +++ b/hw/pvpanic.c
> @@ -19,6 +19,8 @@
>  #include <sysemu/kvm.h>
>  
>  #include "hw/fw_cfg.h"
> +#include "hw/pc.h"
> +#include "qapi/string-input-visitor.h"
>  
>  /* The bit of supported pv event */
>  #define PVPANIC_F_PANICKED      0
> @@ -57,6 +59,36 @@ typedef struct PVPanicState {
>      uint16_t ioport;
>  } PVPanicState;
>  
> +static uint16_t ioport;
> +
> +static int set_ioport(const char *name, const char *value, void *opaque)
> +{
> +    StringInputVisitor *mi;
> +
> +    if (strcmp(name, "ioport") == 0) {
> +        mi = string_input_visitor_new(value);
> +        visit_type_uint16(string_input_get_visitor(mi), &ioport, "ioport",
> +                          NULL);
> +        string_input_visitor_cleanup(mi);
> +    }
> +
> +    return 0;
> +}
> +
> +int pvpanic_ioport(QemuOpts *opts, void *opaque)
> +{
> +    const char *driver;
> +
> +    driver = qemu_opt_get(opts, "driver");
> +    if (!driver || strcmp(driver, "pvpanic")) {
> +        return 0;
> +    }
> +
> +    qemu_opt_foreach(opts, set_ioport, NULL, 0);
> +
> +    return 0;
> +}
> +
>  /* return supported events on read */
>  static uint64_t pvpanic_ioport_read(void *opaque, hwaddr addr, unsigned size)
>  {
> @@ -84,6 +116,10 @@ static int pvpanic_isa_initfn(ISADevice *dev)
>      static bool port_configured;
>      void *fw_cfg;
>  
> +    if (ioport) {
> +        s->ioport = ioport;
> +    }
> +
>      memory_region_init_io(&s->io, &pvpanic_ops, s, "pvpanic", 1);
>      isa_register_ioport(dev, &s->io, s->ioport);
>  
> @@ -115,6 +151,12 @@ static void pvpanic_isa_class_init(ObjectClass *klass, void *data)
>      dc->props = pvpanic_isa_properties;
>  }
>  
> +int pvpanic_init(ISABus *bus)
> +{
> +    isa_create_simple(bus, TYPE_ISA_PVPANIC_DEVICE);
> +    return 0;
> +}
> +
>  static TypeInfo pvpanic_isa_info = {
>      .name          = TYPE_ISA_PVPANIC_DEVICE,
>      .parent        = TYPE_ISA_DEVICE,
> diff --git a/vl.c b/vl.c
> index c91fd4e..1a3ffa2 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -4302,6 +4302,8 @@ int main(int argc, char **argv, char **envp)
>              exit (i == 1 ? 1 : 0);
>      }
>  
> +    qemu_opts_foreach(qemu_find_opts("device"), pvpanic_ioport, NULL, 0);
> +
>      if (machine->compat_props) {
>          qdev_prop_register_global_list(machine->compat_props);
>      }
>
Hu Tao - April 8, 2013, 2:50 a.m.
On Fri, Apr 05, 2013 at 01:14:16PM +0200, Paolo Bonzini wrote:
> Il 05/04/2013 08:36, Hu Tao ha scritto:
> > Also parse command line options for ioport and set
> > it accordingly.
> 
> This does not do the correct thing for versioned machine types like "-M
> pc-1.4".  Also, adding stuff to vl.c is really something you cannot do.
>  Please don't be afraid to ask!
> 
> See the attached patch, untested.  Feel free to take it with my S-o-b line.

Thanks. But you forgot the attachment?

> 
> Patches 1-4 and 6 are okay.
> 
> Paolo
> 
> > Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> > ---
> >  hw/i386/pc_piix.c |  2 ++
> >  hw/i386/pc_q35.c  |  1 +
> >  hw/pc.h           |  4 ++++
> >  hw/pvpanic.c      | 42 ++++++++++++++++++++++++++++++++++++++++++
> >  vl.c              |  2 ++
> >  5 files changed, 51 insertions(+)
> > 
> > diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> > index 0abc9f1..897254a 100644
> > --- a/hw/i386/pc_piix.c
> > +++ b/hw/i386/pc_piix.c
> > @@ -217,6 +217,8 @@ static void pc_init1(MemoryRegion *system_memory,
> >      if (pci_enabled) {
> >          pc_pci_device_init(pci_bus);
> >      }
> > +
> > +    pvpanic_init(isa_bus);
> >  }
> >  
> >  static void pc_init_pci(QEMUMachineInitArgs *args)
> > diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
> > index 4f5f347..fd9ab01 100644
> > --- a/hw/i386/pc_q35.c
> > +++ b/hw/i386/pc_q35.c
> > @@ -204,6 +204,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
> >      pc_vga_init(isa_bus, host_bus);
> >      audio_init(isa_bus, host_bus);
> >      pc_nic_init(isa_bus, host_bus);
> > +    pvpanic_init(isa_bus);
> >      if (pci_enabled) {
> >          pc_pci_device_init(host_bus);
> >      }
> > diff --git a/hw/pc.h b/hw/pc.h
> > index 8e1dd4c..1311037 100644
> > --- a/hw/pc.h
> > +++ b/hw/pc.h
> > @@ -178,6 +178,10 @@ static inline bool isa_ne2000_init(ISABus *bus, int base, int irq, NICInfo *nd)
> >  /* pc_sysfw.c */
> >  void pc_system_firmware_init(MemoryRegion *rom_memory);
> >  
> > +/* pvpanic.c */
> > +int pvpanic_init(ISABus *bus);
> > +int pvpanic_ioport(QemuOpts *opts, void *opaque);
> > +
> >  /* e820 types */
> >  #define E820_RAM        1
> >  #define E820_RESERVED   2
> > diff --git a/hw/pvpanic.c b/hw/pvpanic.c
> > index b3d10e2..2e237a4 100644
> > --- a/hw/pvpanic.c
> > +++ b/hw/pvpanic.c
> > @@ -19,6 +19,8 @@
> >  #include <sysemu/kvm.h>
> >  
> >  #include "hw/fw_cfg.h"
> > +#include "hw/pc.h"
> > +#include "qapi/string-input-visitor.h"
> >  
> >  /* The bit of supported pv event */
> >  #define PVPANIC_F_PANICKED      0
> > @@ -57,6 +59,36 @@ typedef struct PVPanicState {
> >      uint16_t ioport;
> >  } PVPanicState;
> >  
> > +static uint16_t ioport;
> > +
> > +static int set_ioport(const char *name, const char *value, void *opaque)
> > +{
> > +    StringInputVisitor *mi;
> > +
> > +    if (strcmp(name, "ioport") == 0) {
> > +        mi = string_input_visitor_new(value);
> > +        visit_type_uint16(string_input_get_visitor(mi), &ioport, "ioport",
> > +                          NULL);
> > +        string_input_visitor_cleanup(mi);
> > +    }
> > +
> > +    return 0;
> > +}
> > +
> > +int pvpanic_ioport(QemuOpts *opts, void *opaque)
> > +{
> > +    const char *driver;
> > +
> > +    driver = qemu_opt_get(opts, "driver");
> > +    if (!driver || strcmp(driver, "pvpanic")) {
> > +        return 0;
> > +    }
> > +
> > +    qemu_opt_foreach(opts, set_ioport, NULL, 0);
> > +
> > +    return 0;
> > +}
> > +
> >  /* return supported events on read */
> >  static uint64_t pvpanic_ioport_read(void *opaque, hwaddr addr, unsigned size)
> >  {
> > @@ -84,6 +116,10 @@ static int pvpanic_isa_initfn(ISADevice *dev)
> >      static bool port_configured;
> >      void *fw_cfg;
> >  
> > +    if (ioport) {
> > +        s->ioport = ioport;
> > +    }
> > +
> >      memory_region_init_io(&s->io, &pvpanic_ops, s, "pvpanic", 1);
> >      isa_register_ioport(dev, &s->io, s->ioport);
> >  
> > @@ -115,6 +151,12 @@ static void pvpanic_isa_class_init(ObjectClass *klass, void *data)
> >      dc->props = pvpanic_isa_properties;
> >  }
> >  
> > +int pvpanic_init(ISABus *bus)
> > +{
> > +    isa_create_simple(bus, TYPE_ISA_PVPANIC_DEVICE);
> > +    return 0;
> > +}
> > +
> >  static TypeInfo pvpanic_isa_info = {
> >      .name          = TYPE_ISA_PVPANIC_DEVICE,
> >      .parent        = TYPE_ISA_DEVICE,
> > diff --git a/vl.c b/vl.c
> > index c91fd4e..1a3ffa2 100644
> > --- a/vl.c
> > +++ b/vl.c
> > @@ -4302,6 +4302,8 @@ int main(int argc, char **argv, char **envp)
> >              exit (i == 1 ? 1 : 0);
> >      }
> >  
> > +    qemu_opts_foreach(qemu_find_opts("device"), pvpanic_ioport, NULL, 0);
> > +
> >      if (machine->compat_props) {
> >          qdev_prop_register_global_list(machine->compat_props);
> >      }
> >

Patch

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 0abc9f1..897254a 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -217,6 +217,8 @@  static void pc_init1(MemoryRegion *system_memory,
     if (pci_enabled) {
         pc_pci_device_init(pci_bus);
     }
+
+    pvpanic_init(isa_bus);
 }
 
 static void pc_init_pci(QEMUMachineInitArgs *args)
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 4f5f347..fd9ab01 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -204,6 +204,7 @@  static void pc_q35_init(QEMUMachineInitArgs *args)
     pc_vga_init(isa_bus, host_bus);
     audio_init(isa_bus, host_bus);
     pc_nic_init(isa_bus, host_bus);
+    pvpanic_init(isa_bus);
     if (pci_enabled) {
         pc_pci_device_init(host_bus);
     }
diff --git a/hw/pc.h b/hw/pc.h
index 8e1dd4c..1311037 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -178,6 +178,10 @@  static inline bool isa_ne2000_init(ISABus *bus, int base, int irq, NICInfo *nd)
 /* pc_sysfw.c */
 void pc_system_firmware_init(MemoryRegion *rom_memory);
 
+/* pvpanic.c */
+int pvpanic_init(ISABus *bus);
+int pvpanic_ioport(QemuOpts *opts, void *opaque);
+
 /* e820 types */
 #define E820_RAM        1
 #define E820_RESERVED   2
diff --git a/hw/pvpanic.c b/hw/pvpanic.c
index b3d10e2..2e237a4 100644
--- a/hw/pvpanic.c
+++ b/hw/pvpanic.c
@@ -19,6 +19,8 @@ 
 #include <sysemu/kvm.h>
 
 #include "hw/fw_cfg.h"
+#include "hw/pc.h"
+#include "qapi/string-input-visitor.h"
 
 /* The bit of supported pv event */
 #define PVPANIC_F_PANICKED      0
@@ -57,6 +59,36 @@  typedef struct PVPanicState {
     uint16_t ioport;
 } PVPanicState;
 
+static uint16_t ioport;
+
+static int set_ioport(const char *name, const char *value, void *opaque)
+{
+    StringInputVisitor *mi;
+
+    if (strcmp(name, "ioport") == 0) {
+        mi = string_input_visitor_new(value);
+        visit_type_uint16(string_input_get_visitor(mi), &ioport, "ioport",
+                          NULL);
+        string_input_visitor_cleanup(mi);
+    }
+
+    return 0;
+}
+
+int pvpanic_ioport(QemuOpts *opts, void *opaque)
+{
+    const char *driver;
+
+    driver = qemu_opt_get(opts, "driver");
+    if (!driver || strcmp(driver, "pvpanic")) {
+        return 0;
+    }
+
+    qemu_opt_foreach(opts, set_ioport, NULL, 0);
+
+    return 0;
+}
+
 /* return supported events on read */
 static uint64_t pvpanic_ioport_read(void *opaque, hwaddr addr, unsigned size)
 {
@@ -84,6 +116,10 @@  static int pvpanic_isa_initfn(ISADevice *dev)
     static bool port_configured;
     void *fw_cfg;
 
+    if (ioport) {
+        s->ioport = ioport;
+    }
+
     memory_region_init_io(&s->io, &pvpanic_ops, s, "pvpanic", 1);
     isa_register_ioport(dev, &s->io, s->ioport);
 
@@ -115,6 +151,12 @@  static void pvpanic_isa_class_init(ObjectClass *klass, void *data)
     dc->props = pvpanic_isa_properties;
 }
 
+int pvpanic_init(ISABus *bus)
+{
+    isa_create_simple(bus, TYPE_ISA_PVPANIC_DEVICE);
+    return 0;
+}
+
 static TypeInfo pvpanic_isa_info = {
     .name          = TYPE_ISA_PVPANIC_DEVICE,
     .parent        = TYPE_ISA_DEVICE,
diff --git a/vl.c b/vl.c
index c91fd4e..1a3ffa2 100644
--- a/vl.c
+++ b/vl.c
@@ -4302,6 +4302,8 @@  int main(int argc, char **argv, char **envp)
             exit (i == 1 ? 1 : 0);
     }
 
+    qemu_opts_foreach(qemu_find_opts("device"), pvpanic_ioport, NULL, 0);
+
     if (machine->compat_props) {
         qdev_prop_register_global_list(machine->compat_props);
     }