From patchwork Sat Aug 4 12:05:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zhang X-Patchwork-Id: 175084 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B8D102C008E for ; Sat, 4 Aug 2012 22:06:54 +1000 (EST) Received: from localhost ([::1]:41377 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sxd88-0006Wk-L1 for incoming@patchwork.ozlabs.org; Sat, 04 Aug 2012 08:06:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sxd7z-0006WU-6s for qemu-devel@nongnu.org; Sat, 04 Aug 2012 08:06:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sxd7x-0003Kc-Rz for qemu-devel@nongnu.org; Sat, 04 Aug 2012 08:06:43 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:35131) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sxd7x-0002vX-NX; Sat, 04 Aug 2012 08:06:41 -0400 Received: by mail-ob0-f173.google.com with SMTP id ta14so2476455obb.4 for ; Sat, 04 Aug 2012 05:06:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=Pb1ser+jbLAfa1mrmTFfuD+oIYLEkyiTIhSKw64LJP4=; b=Wxn5Q9F4QWD0l6DQZnhv63wSdh1C+RfMqd4eWswOSWg18FjWqjJKAK7QNDMolDQQut PuNobXUJ7ejr7CMS1i8zLmCe53Z9lJq5A8GB8Yt0iU6pCWgoroknEzJKMplsQWWjs1Kh kR2V2HhnmzmWdwsyVKJey9euURI7uBeWQY28nEBIfCXzAzII+70KFXeNL8l+gU+ZZd6g oYO//koI2djsT/SGuK7EobsnU9seu8UqbQGjxLD+i7qJFNY857Ri8EuXSsk/Y31dc5r8 5fd6uJbXM1wvwDODpCbZK6NaQpubtI4ogyyIdHRwqWjFCKvRlJVIuhpscCmBJzPC6RlC CWOA== Received: by 10.60.6.195 with SMTP id d3mr10548636oea.42.1344082001406; Sat, 04 Aug 2012 05:06:41 -0700 (PDT) Received: from localhost.localdomain ([175.25.242.10]) by mx.google.com with ESMTPS id th3sm12393434obb.6.2012.08.04.05.06.36 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 04 Aug 2012 05:06:40 -0700 (PDT) From: Li Zhang To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Date: Sat, 4 Aug 2012 20:05:53 +0800 Message-Id: <1344081957-4717-2-git-send-email-zhlcindy@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1344081957-4717-1-git-send-email-zhlcindy@linux.vnet.ibm.com> References: <1344081957-4717-1-git-send-email-zhlcindy@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.173 Cc: aliguori@us.ibm.com, agraf@suse.de, Li Zhang , afaerber@suse.de, david@gibson.dropbear.id.au Subject: [Qemu-devel] [Qemu-ppc][PATCH v6 1/5] Add USB option in machine options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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); }