diff mbox

[v2] libxl: usb2 and usb3 controller support for upstream qemu

Message ID 1373538837-4811-1-git-send-email-fabio.fantoni@m2r.biz
State New
Headers show

Commit Message

Fabio Fantoni July 11, 2013, 10:33 a.m. UTC
Usage: usbversion=1|2|3 (default=2)
Specifies the type of an emulated USB bus in the guest. 1 for usb1,
2 for usb2 and 3 for usb3, it is available only with upstream qemu.
Default is 2.

Signed-off-by: Fabio Fantoni <fabio.fantoni@m2r.biz>
---
 docs/man/xl.cfg.pod.5       |    6 ++++++
 tools/libxl/libxl_create.c  |    3 +++
 tools/libxl/libxl_dm.c      |   24 +++++++++++++++++++++++-
 tools/libxl/libxl_types.idl |    1 +
 tools/libxl/xl_cmdimpl.c    |    2 ++
 tools/libxl/xl_sxp.c        |    1 +
 6 files changed, 36 insertions(+), 1 deletion(-)

Comments

Dario Faggioli July 11, 2013, 3:56 p.m. UTC | #1
On gio, 2013-07-11 at 12:33 +0200, Fabio Fantoni wrote:
> Usage: usbversion=1|2|3 (default=2)
> Specifies the type of an emulated USB bus in the guest. 1 for usb1,
> 2 for usb2 and 3 for usb3, it is available only with upstream qemu.
> Default is 2.
> 
> Signed-off-by: Fabio Fantoni <fabio.fantoni@m2r.biz>
>
> diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
> index d218a2d..b4c6921 100644
> --- a/tools/libxl/libxl_types.idl
> +++ b/tools/libxl/libxl_types.idl
> @@ -325,6 +325,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
>                                         ("serial",           string),
>                                         ("boot",             string),
>                                         ("usb",              libxl_defbool),
> +                                       ("usbversion",              integer),
>                                         # usbdevice:
>                                         # - "tablet" for absolute mouse,
>                                         # - "mouse" for PS/2 protocol relative mouse
>
I believe this calls for a `#define LIBXL_HAVE_USBVERSION' (or something
like that) in libxl.h, doesn't it?

See the comment about "libxl API compatibility" in libxl.h itself for
more details.

Regards,
Dario
Fabio Fantoni July 12, 2013, 8:43 a.m. UTC | #2
Il 11/07/2013 17:56, Dario Faggioli ha scritto:
> On gio, 2013-07-11 at 12:33 +0200, Fabio Fantoni wrote:
>> Usage: usbversion=1|2|3 (default=2)
>> Specifies the type of an emulated USB bus in the guest. 1 for usb1,
>> 2 for usb2 and 3 for usb3, it is available only with upstream qemu.
>> Default is 2.
>>
>> Signed-off-by: Fabio Fantoni <fabio.fantoni@m2r.biz>
>>
>> diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
>> index d218a2d..b4c6921 100644
>> --- a/tools/libxl/libxl_types.idl
>> +++ b/tools/libxl/libxl_types.idl
>> @@ -325,6 +325,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
>>                                          ("serial",           string),
>>                                          ("boot",             string),
>>                                          ("usb",              libxl_defbool),
>> +                                       ("usbversion",              integer),
>>                                          # usbdevice:
>>                                          # - "tablet" for absolute mouse,
>>                                          # - "mouse" for PS/2 protocol relative mouse
>>
> I believe this calls for a `#define LIBXL_HAVE_USBVERSION' (or something
> like that) in libxl.h, doesn't it?
>
> See the comment about "libxl API compatibility" in libxl.h itself for
> more details.
>
> Regards,
> Dario
>
Is it necessary even if I just want to apply it to xen 4.4 (as a new 
features) and not backport it to older versions?
Or probably I don't understand exactly what is the function of LIBXL_HAVE_*.
I tried to grep all code for LIBXL_HAVE_* to see an example of use but I 
found only one an I don't understand.
Wei Liu July 12, 2013, 9:08 a.m. UTC | #3
On Thu, Jul 11, 2013 at 12:33:57PM +0200, Fabio Fantoni wrote:
> Usage: usbversion=1|2|3 (default=2)
> Specifies the type of an emulated USB bus in the guest. 1 for usb1,
> 2 for usb2 and 3 for usb3, it is available only with upstream qemu.
> Default is 2.
> 
> Signed-off-by: Fabio Fantoni <fabio.fantoni@m2r.biz>
> ---
>  docs/man/xl.cfg.pod.5       |    6 ++++++
>  tools/libxl/libxl_create.c  |    3 +++
>  tools/libxl/libxl_dm.c      |   24 +++++++++++++++++++++++-
>  tools/libxl/libxl_types.idl |    1 +
>  tools/libxl/xl_cmdimpl.c    |    2 ++
>  tools/libxl/xl_sxp.c        |    1 +
>  6 files changed, 36 insertions(+), 1 deletion(-)
> 
> diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5
> index 069b73f..602d428 100644
> --- a/docs/man/xl.cfg.pod.5
> +++ b/docs/man/xl.cfg.pod.5
> @@ -1154,6 +1154,12 @@ device.
>  
>  Enables or disables an emulated USB bus in the guest.
>  
> +=item B<usbversion=NUMBER>
> + 
> +Specifies the type of an emulated USB bus in the guest. 1 for usb1,
> +2 for usb2 and 3 for usb3, it is available only with upstream qemu.
> +Default is 2.
> +
>  =item B<usbdevice=[ "DEVICE", "DEVICE", ...]>
>  
>  Adds B<DEVICE>s to the emulated USB bus. The USB bus must also be
> diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
> index 0c32d0b..9683740 100644
> --- a/tools/libxl/libxl_create.c
> +++ b/tools/libxl/libxl_create.c
> @@ -229,6 +229,9 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
>              return ERROR_INVAL;
>          }
>  
> +        if (!b_info->u.hvm.usbversion)
> +            b_info->u.hvm.usbversion = 2;
> +
>          if (b_info->u.hvm.timer_mode == LIBXL_TIMER_MODE_DEFAULT)
>              b_info->u.hvm.timer_mode =
>                  LIBXL_TIMER_MODE_NO_DELAY_FOR_MISSED_TICKS;
> diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
> index 7e54c02..52a546b 100644
> --- a/tools/libxl/libxl_dm.c
> +++ b/tools/libxl/libxl_dm.c
> @@ -492,7 +492,29 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,
>                      __func__);
>                  return NULL;
>              }
> -            flexarray_append(dm_args, "-usb");
> +
> +            switch (b_info->u.hvm.usbversion) {
> +            case 1:
> +                flexarray_vappend(dm_args,
> +                    "-device", "piix3-usb-uhci,id=usb", NULL);
> +                break;
> +            case 2:
> +                flexarray_vappend(dm_args, "-device","ich9-usb-ehci1,id=usb,"
> +                    "bus=pci.0,addr=0x1d.0x7", "-device","ich9-usb-uhci1,"
> +                    "masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,"
> +                    "addr=0x1d.0x0","-device","ich9-usb-uhci2,masterbus=usb.0,"
> +                    "firstport=2,bus=pci.0,addr=0x1d.0x1", "-device",
> +                    "ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,"
> +                    "addr=0x1d.0x2", NULL);
> +                break;
> +            case 3:
> +                flexarray_vappend(dm_args,
> +                    "-device", "nec-usb-xhci,id=usb", NULL);
> +                break;
> +            default:
> +                LIBXL__LOG(CTX, LIBXL__LOG_ERROR,
> +                    "usbversion parameter is invalid must be between 1 and 3");
> +            }
>              if (b_info->u.hvm.usbdevice) {
>                  flexarray_vappend(dm_args,
>                                    "-usbdevice", b_info->u.hvm.usbdevice, NULL);
> diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
> index d218a2d..b4c6921 100644
> --- a/tools/libxl/libxl_types.idl
> +++ b/tools/libxl/libxl_types.idl
> @@ -325,6 +325,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
>                                         ("serial",           string),
>                                         ("boot",             string),
>                                         ("usb",              libxl_defbool),
> +                                       ("usbversion",              integer),

Indentation.

>                                         # usbdevice:
>                                         # - "tablet" for absolute mouse,
>                                         # - "mouse" for PS/2 protocol relative mouse
> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> index 8a478ba..a618ede 100644
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -1495,6 +1495,8 @@ skip_vfb:
>          xlu_cfg_replace_string (config, "serial", &b_info->u.hvm.serial, 0);
>          xlu_cfg_replace_string (config, "boot", &b_info->u.hvm.boot, 0);
>          xlu_cfg_get_defbool(config, "usb", &b_info->u.hvm.usb, 0);
> +        if (!xlu_cfg_get_long (config, "usbversion", &l, 0))
> +            b_info->u.hvm.usbversion = l;
>          switch (xlu_cfg_get_list_as_string_list(config, "usbdevice",
>                                                  &b_info->u.hvm.usbdevice_list,
>                                                  1))
> diff --git a/tools/libxl/xl_sxp.c b/tools/libxl/xl_sxp.c
> index a16a025..2dc3a86 100644
> --- a/tools/libxl/xl_sxp.c
> +++ b/tools/libxl/xl_sxp.c
> @@ -142,6 +142,7 @@ void printf_info_sexp(int domid, libxl_domain_config *d_config)
>          printf("\t\t\t(serial %s)\n", b_info->u.hvm.serial);
>          printf("\t\t\t(boot %s)\n", b_info->u.hvm.boot);
>          printf("\t\t\t(usb %s)\n", libxl_defbool_to_string(b_info->u.hvm.usb));
> +        printf("\t\t\t(usb %d)\n", b_info->u.hvm.usbversion);

Should be "usbversion".

>          printf("\t\t\t(usbdevice %s)\n", b_info->u.hvm.usbdevice);
>          printf("\t\t)\n");
>          break;
> -- 
> 1.7.9.5
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
Ian Campbell July 12, 2013, 9:17 a.m. UTC | #4
On Fri, 2013-07-12 at 10:08 +0100, Wei Liu wrote:
> On Thu, Jul 11, 2013 at 12:33:57PM +0200, Fabio Fantoni wrote:
> > diff --git a/tools/libxl/xl_sxp.c b/tools/libxl/xl_sxp.c
> > index a16a025..2dc3a86 100644
> > --- a/tools/libxl/xl_sxp.c
> > +++ b/tools/libxl/xl_sxp.c
> > @@ -142,6 +142,7 @@ void printf_info_sexp(int domid, libxl_domain_config *d_config)
> >          printf("\t\t\t(serial %s)\n", b_info->u.hvm.serial);
> >          printf("\t\t\t(boot %s)\n", b_info->u.hvm.boot);
> >          printf("\t\t\t(usb %s)\n", libxl_defbool_to_string(b_info->u.hvm.usb));
> > +        printf("\t\t\t(usb %d)\n", b_info->u.hvm.usbversion);
> 
> Should be "usbversion".

Actually this file shouldn't be patched at all. The sxp output exists
solely for compatibility with existing scripts which expect xend and so
does not need to reflect the status of new features.

Ian.
Dario Faggioli July 12, 2013, 12:13 p.m. UTC | #5
On ven, 2013-07-12 at 10:43 +0200, Fabio Fantoni wrote:
> Il 11/07/2013 17:56, Dario Faggioli ha scritto:
> >> Signed-off-by: Fabio Fantoni <fabio.fantoni@m2r.biz>
> >>
> >> diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
> >> index d218a2d..b4c6921 100644
> >> --- a/tools/libxl/libxl_types.idl
> >> +++ b/tools/libxl/libxl_types.idl
> >> @@ -325,6 +325,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
> >>                                          ("serial",           string),
> >>                                          ("boot",             string),
> >>                                          ("usb",              libxl_defbool),
> >> +                                       ("usbversion",              integer),
> >>                                          # usbdevice:
> >>                                          # - "tablet" for absolute mouse,
> >>                                          # - "mouse" for PS/2 protocol relative mouse
> >>
> > I believe this calls for a `#define LIBXL_HAVE_USBVERSION' (or something
> > like that) in libxl.h, doesn't it?
>
> Is it necessary even if I just want to apply it to xen 4.4 (as a new 
> features) and not backport it to older versions?
>
Although API stability is something I'm not sure I fully master, I would
say, yes it is necessary. :-)

> Or probably I don't understand exactly what is the function of LIBXL_HAVE_*.
>
The point is to allow people to write code suitable for _all_ versions
of libxl. So, imagine, in the super cool toolstack I'm writing on top of
libxl, I want to use your new parameter, if it's there, i.e., if
compiling on top of 4.4, but I also want the code to compile against
libxl 4.3.

With the LIBXL_HAVE_*, I can do something like this:

    ...
    binfo.usb = true;
    #ifdef LIBXL_HAVE_BUILDINFO_USBVERSION
    binfo.usbversion = 3;
    #endif
    ...

Does that make sense?

> I tried to grep all code for LIBXL_HAVE_* to see an example of use but I 
> found only one an I don't understand.
>
Try harder! :-)

http://xenbits.xen.org/gitweb/?p=xen.git&a=search&h=refs%2Fheads%2Fstaging&st=commit&s=LIBXL_HAVE_
http://xenbits.xen.org/gitweb/?p=xen.git&a=search&h=HEAD&st=grep&s=LIBXL_HAVE_

Actually, while at it, given LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST is
added in ac16730d0339d41fd7d1, I'd go for
LIBXL_HAVE_BUILDINFO_USBVERSION for yours, it looks more consistent.

Regards,
Dario
diff mbox

Patch

diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5
index 069b73f..602d428 100644
--- a/docs/man/xl.cfg.pod.5
+++ b/docs/man/xl.cfg.pod.5
@@ -1154,6 +1154,12 @@  device.
 
 Enables or disables an emulated USB bus in the guest.
 
+=item B<usbversion=NUMBER>
+ 
+Specifies the type of an emulated USB bus in the guest. 1 for usb1,
+2 for usb2 and 3 for usb3, it is available only with upstream qemu.
+Default is 2.
+
 =item B<usbdevice=[ "DEVICE", "DEVICE", ...]>
 
 Adds B<DEVICE>s to the emulated USB bus. The USB bus must also be
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 0c32d0b..9683740 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -229,6 +229,9 @@  int libxl__domain_build_info_setdefault(libxl__gc *gc,
             return ERROR_INVAL;
         }
 
+        if (!b_info->u.hvm.usbversion)
+            b_info->u.hvm.usbversion = 2;
+
         if (b_info->u.hvm.timer_mode == LIBXL_TIMER_MODE_DEFAULT)
             b_info->u.hvm.timer_mode =
                 LIBXL_TIMER_MODE_NO_DELAY_FOR_MISSED_TICKS;
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 7e54c02..52a546b 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -492,7 +492,29 @@  static char ** libxl__build_device_model_args_new(libxl__gc *gc,
                     __func__);
                 return NULL;
             }
-            flexarray_append(dm_args, "-usb");
+
+            switch (b_info->u.hvm.usbversion) {
+            case 1:
+                flexarray_vappend(dm_args,
+                    "-device", "piix3-usb-uhci,id=usb", NULL);
+                break;
+            case 2:
+                flexarray_vappend(dm_args, "-device","ich9-usb-ehci1,id=usb,"
+                    "bus=pci.0,addr=0x1d.0x7", "-device","ich9-usb-uhci1,"
+                    "masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,"
+                    "addr=0x1d.0x0","-device","ich9-usb-uhci2,masterbus=usb.0,"
+                    "firstport=2,bus=pci.0,addr=0x1d.0x1", "-device",
+                    "ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,"
+                    "addr=0x1d.0x2", NULL);
+                break;
+            case 3:
+                flexarray_vappend(dm_args,
+                    "-device", "nec-usb-xhci,id=usb", NULL);
+                break;
+            default:
+                LIBXL__LOG(CTX, LIBXL__LOG_ERROR,
+                    "usbversion parameter is invalid must be between 1 and 3");
+            }
             if (b_info->u.hvm.usbdevice) {
                 flexarray_vappend(dm_args,
                                   "-usbdevice", b_info->u.hvm.usbdevice, NULL);
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index d218a2d..b4c6921 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -325,6 +325,7 @@  libxl_domain_build_info = Struct("domain_build_info",[
                                        ("serial",           string),
                                        ("boot",             string),
                                        ("usb",              libxl_defbool),
+                                       ("usbversion",              integer),
                                        # usbdevice:
                                        # - "tablet" for absolute mouse,
                                        # - "mouse" for PS/2 protocol relative mouse
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 8a478ba..a618ede 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -1495,6 +1495,8 @@  skip_vfb:
         xlu_cfg_replace_string (config, "serial", &b_info->u.hvm.serial, 0);
         xlu_cfg_replace_string (config, "boot", &b_info->u.hvm.boot, 0);
         xlu_cfg_get_defbool(config, "usb", &b_info->u.hvm.usb, 0);
+        if (!xlu_cfg_get_long (config, "usbversion", &l, 0))
+            b_info->u.hvm.usbversion = l;
         switch (xlu_cfg_get_list_as_string_list(config, "usbdevice",
                                                 &b_info->u.hvm.usbdevice_list,
                                                 1))
diff --git a/tools/libxl/xl_sxp.c b/tools/libxl/xl_sxp.c
index a16a025..2dc3a86 100644
--- a/tools/libxl/xl_sxp.c
+++ b/tools/libxl/xl_sxp.c
@@ -142,6 +142,7 @@  void printf_info_sexp(int domid, libxl_domain_config *d_config)
         printf("\t\t\t(serial %s)\n", b_info->u.hvm.serial);
         printf("\t\t\t(boot %s)\n", b_info->u.hvm.boot);
         printf("\t\t\t(usb %s)\n", libxl_defbool_to_string(b_info->u.hvm.usb));
+        printf("\t\t\t(usb %d)\n", b_info->u.hvm.usbversion);
         printf("\t\t\t(usbdevice %s)\n", b_info->u.hvm.usbdevice);
         printf("\t\t)\n");
         break;