qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Li Zhang <zhlcindy@gmail.com>
To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org
Cc: aliguori@us.ibm.com, agraf@suse.de,
	Li Zhang <zhlcindy@linux.vnet.ibm.com>,
	afaerber@suse.de, david@gibson.dropbear.id.au
Subject: [Qemu-devel] [Qemu-ppc][PATCH v6 1/5] Add USB option in machine options
Date: Sat,  4 Aug 2012 20:05:53 +0800	[thread overview]
Message-ID: <1344081957-4717-2-git-send-email-zhlcindy@linux.vnet.ibm.com> (raw)
In-Reply-To: <1344081957-4717-1-git-send-email-zhlcindy@linux.vnet.ibm.com>

When -usb option is used, global varible usb_enabled is set.
And all the plafrom will create one USB controller according
to this variable. In fact, global varibles make code hard
to read.

So this patch is to remove global variable usb_enabled and
add USB option in machine options. All the plaforms will
get USB option value from machine options.

USB option of machine options will be set by either by:
  * -usb
  * -machine type=pseries,usb=on

Both these ways can work now. They both set USB option in
machine options. In the future, the first way will be removed.

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
---
 qemu-config.c |    4 ++++
 sysemu.h      |    1 -
 vl.c          |   29 +++++++++++++++++++++++------
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/qemu-config.c b/qemu-config.c
index 5c3296b..b86ee36 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -595,6 +595,10 @@ static QemuOptsList qemu_machine_opts = {
             .name = "dt_compatible",
             .type = QEMU_OPT_STRING,
             .help = "Overrides the \"compatible\" property of the dt root node",
+        },{
+            .name = "usb",
+            .type = QEMU_OPT_BOOL,
+            .help = "Set on/off to enable/disable usb",
         },
         { /* End of list */ }
     },
diff --git a/sysemu.h b/sysemu.h
index 6540c79..09f97fb 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -118,7 +118,6 @@ extern const char *keyboard_layout;
 extern int win2k_install_hack;
 extern int alt_grab;
 extern int ctrl_grab;
-extern int usb_enabled;
 extern int smp_cpus;
 extern int max_cpus;
 extern int cursor_hide;
diff --git a/vl.c b/vl.c
index 9fea320..db8b080 100644
--- a/vl.c
+++ b/vl.c
@@ -196,7 +196,6 @@ CharDriverState *serial_hds[MAX_SERIAL_PORTS];
 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
 int win2k_install_hack = 0;
-int usb_enabled = 0;
 int singlestep = 0;
 int smp_cpus = 1;
 int max_cpus = 0;
@@ -1044,13 +1043,24 @@ static void smp_parse(const char *optarg)
 /***********************************************************/
 /* USB devices */
 
+static inline bool usb_enabled(bool default_usb)
+{
+    QemuOpts *mach_opts;
+    mach_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
+    if (mach_opts) {
+        return qemu_opt_get_bool(mach_opts, "usb", default_usb);
+    }
+    return default_usb;
+}
+
 static int usb_device_add(const char *devname)
 {
     const char *p;
     USBDevice *dev = NULL;
 
-    if (!usb_enabled)
+    if (!usb_enabled(false)) {
         return -1;
+    }
 
     /* drivers with .usbdevice_name entry in USBDeviceInfo */
     dev = usbdevice_create(devname);
@@ -1086,8 +1096,9 @@ static int usb_device_del(const char *devname)
     if (strstart(devname, "host:", &p))
         return usb_host_device_close(p);
 
-    if (!usb_enabled)
+    if (!usb_enabled(false)) {
         return -1;
+    }
 
     p = strchr(devname, '.');
     if (!p)
@@ -2978,10 +2989,16 @@ int main(int argc, char **argv, char **envp)
                 }
                 break;
             case QEMU_OPTION_usb:
-                usb_enabled = 1;
+                machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
+                if (machine_opts) {
+                    qemu_opt_set_bool(machine_opts, "usb", true);
+                }
                 break;
             case QEMU_OPTION_usbdevice:
-                usb_enabled = 1;
+                machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
+                if (machine_opts) {
+                    qemu_opt_set_bool(machine_opts, "usb", true);
+                }
                 add_device_config(DEV_USB, optarg);
                 break;
             case QEMU_OPTION_device:
@@ -3526,7 +3543,7 @@ int main(int argc, char **argv, char **envp)
     current_machine = machine;
 
     /* init USB devices */
-    if (usb_enabled) {
+    if (usb_enabled(false)) {
         if (foreach_device_config(DEV_USB, usb_parse) < 0)
             exit(1);
     }
-- 
1.7.7.6

  reply	other threads:[~2012-08-04 12:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-04 12:05 [Qemu-devel] [Qemu-ppc][PATCH v6 0/5] Add USB enablement and VGA enablement on sPAPR Li Zhang
2012-08-04 12:05 ` Li Zhang [this message]
2012-08-04 12:05 ` [Qemu-devel] [Qemu-ppc][PATCH v6 2/5] Get USB option by machine options on all platforms Li Zhang
2012-08-04 12:05 ` [Qemu-devel] [Qemu-ppc][PATCH v6 3/5] Add one new file vga-pci.h Li Zhang
2012-08-04 12:43   ` [Qemu-devel] [Qemu-ppc] [PATCH " Blue Swirl
2012-08-04 12:49     ` Li Zhang
2012-08-04 12:56       ` Blue Swirl
2012-08-04 12:05 ` [Qemu-devel] [Qemu-ppc][PATCH v6 4/5] Cleanup pc.h on other platforms Li Zhang
2012-08-04 12:05 ` [Qemu-devel] [Qemu-ppc][PATCH v6 5/5] spapr: Add support for -vga option Li Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1344081957-4717-2-git-send-email-zhlcindy@linux.vnet.ibm.com \
    --to=zhlcindy@gmail.com \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=zhlcindy@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).