From patchwork Tue Nov 22 18:46:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9441941 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 944A0600BA for ; Tue, 22 Nov 2016 18:51:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87934281A7 for ; Tue, 22 Nov 2016 18:51:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78F33285CE; Tue, 22 Nov 2016 18:51:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EC909281A7 for ; Tue, 22 Nov 2016 18:51:34 +0000 (UTC) Received: from localhost ([::1]:57515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c9GAH-0004eY-Pf for patchwork-qemu-devel@patchwork.kernel.org; Tue, 22 Nov 2016 13:51:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49241) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c9G5J-0000eB-TV for qemu-devel@nongnu.org; Tue, 22 Nov 2016 13:46:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c9G5I-0001RT-Ua for qemu-devel@nongnu.org; Tue, 22 Nov 2016 13:46:25 -0500 Received: from mail.kernel.org ([198.145.29.136]:46886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c9G5I-0001R4-L8 for qemu-devel@nongnu.org; Tue, 22 Nov 2016 13:46:24 -0500 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D4E0B20259; Tue, 22 Nov 2016 18:46:22 +0000 (UTC) Received: from sstabellini-ThinkPad-X260.hsd1.ca.comcast.net (96-82-76-110-static.hfc.comcastbusiness.net [96.82.76.110]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6C7F620268; Tue, 22 Nov 2016 18:46:21 +0000 (UTC) From: Stefano Stabellini To: stefanha@gmail.com Date: Tue, 22 Nov 2016 10:46:09 -0800 Message-Id: <1479840369-19503-5-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1479840369-19503-1-git-send-email-sstabellini@kernel.org> References: <1479840369-19503-1-git-send-email-sstabellini@kernel.org> X-Virus-Scanned: ClamAV using ClamSMTP X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 198.145.29.136 Subject: [Qemu-devel] [PULL 5/5] xen: attach pvusb usb bus to backend qdev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , peter.maydell@linaro.org, sstabellini@kernel.org, qemu-devel@nongnu.org, stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Juergen Gross Attach the usb bus of a new pvusb controller to the qdev associated with the Xen backend. Any device connected to that controller can now specify the bus and port directly via its properties. Signed-off-by: Juergen Gross Reviewed-by: Stefano Stabellini Signed-off-by: Stefano Stabellini --- hw/usb/xen-usb.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c index 1b3c2fb..8e676e6 100644 --- a/hw/usb/xen-usb.c +++ b/hw/usb/xen-usb.c @@ -712,15 +712,10 @@ static void usbback_portid_detach(struct usbback_info *usbif, unsigned port) static void usbback_portid_remove(struct usbback_info *usbif, unsigned port) { - USBPort *p; - if (!usbif->ports[port - 1].dev) { return; } - p = &(usbif->ports[port - 1].port); - snprintf(p->path, sizeof(p->path), "%d", 99); - object_unparent(OBJECT(usbif->ports[port - 1].dev)); usbif->ports[port - 1].dev = NULL; usbback_portid_detach(usbif, port); @@ -733,10 +728,10 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port, { unsigned speed; char *portname; - USBPort *p; Error *local_err = NULL; QDict *qdict; QemuOpts *opts; + char *tmp; if (usbif->ports[port - 1].dev) { return; @@ -749,11 +744,16 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port, return; } portname++; - p = &(usbif->ports[port - 1].port); - snprintf(p->path, sizeof(p->path), "%s", portname); qdict = qdict_new(); qdict_put(qdict, "driver", qstring_from_str("usb-host")); + tmp = g_strdup_printf("%s.0", usbif->xendev.qdev.id); + qdict_put(qdict, "bus", qstring_from_str(tmp)); + g_free(tmp); + tmp = g_strdup_printf("%s-%u", usbif->xendev.qdev.id, port); + qdict_put(qdict, "id", qstring_from_str(tmp)); + g_free(tmp); + qdict_put(qdict, "port", qint_from_int(port)); qdict_put(qdict, "hostbus", qint_from_int(atoi(busid))); qdict_put(qdict, "hostport", qstring_from_str(portname)); opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err); @@ -765,7 +765,6 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port, goto err; } QDECREF(qdict); - snprintf(p->path, sizeof(p->path), "%d", port); speed = usbif->ports[port - 1].dev->speed; switch (speed) { case USB_SPEED_LOW: @@ -799,7 +798,6 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port, err: QDECREF(qdict); - snprintf(p->path, sizeof(p->path), "%d", 99); xen_pv_printf(&usbif->xendev, 0, "device %s could not be opened\n", busid); } @@ -1012,13 +1010,13 @@ static void usbback_alloc(struct XenDevice *xendev) usbif = container_of(xendev, struct usbback_info, xendev); - usb_bus_new(&usbif->bus, sizeof(usbif->bus), &xen_usb_bus_ops, xen_sysdev); + usb_bus_new(&usbif->bus, sizeof(usbif->bus), &xen_usb_bus_ops, + DEVICE(&xendev->qdev)); for (i = 0; i < USBBACK_MAXPORTS; i++) { p = &(usbif->ports[i].port); usb_register_port(&usbif->bus, p, usbif, i, &xen_usb_port_ops, USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL | USB_SPEED_MASK_HIGH); - snprintf(p->path, sizeof(p->path), "%d", 99); } QTAILQ_INIT(&usbif->req_free_q); @@ -1066,7 +1064,6 @@ static int usbback_free(struct XenDevice *xendev) } usb_bus_release(&usbif->bus); - object_unparent(OBJECT(&usbif->bus)); TR_BUS(xendev, "finished\n");