From nobody Sun May 5 23:27:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558681538; cv=none; d=zoho.com; s=zohoarc; b=HjQ+6gswa5FpvDHDXXHc6ZjAPs/3w1WZBAxoJOhcER9hfysica+Y5ax65M9pMk4jIWlaR8EtrvKx6FNBnOOgGu03evoFO7hHa7c6eJ0pd5V/wNQ9O3/FmEQCEvIzMCGBFoXDhyLaWW33PMcHKzAqmu/v4zksg9Tscezg4qcpwIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558681538; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=MmmYiu9IZ68vhETafDOsPX8WYdclzySCxg4jOHGrBmU=; b=FsNrWz8tY3ZaHJMR9NMAJsjiciE9DWZMBB1oNokdtbypRF6vl0MZk8zgkk0mYbbEUlVRKLPSt5lOFkaJGKeYXIJpDrdRhCISzf8mz+QSePh6lHHhfnkeJQKyyqlGWXnlqhfGNQM8nACB2xiqOgoX6p9BcRKwY0ANiPcqE0GxRnE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558681538251195.2242996230965; Fri, 24 May 2019 00:05:38 -0700 (PDT) Received: from localhost ([127.0.0.1]:50091 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hU4Gh-0006qs-6c for importer@patchew.org; Fri, 24 May 2019 03:05:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hU4Ec-0005Qt-4e for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hU4Eb-0006NH-5e for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59058) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hU4Ea-0006La-QH for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFBCE307D867 for ; Fri, 24 May 2019 07:03:13 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-101.ams2.redhat.com [10.36.116.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F60B6090E; Fri, 24 May 2019 07:03:11 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id C2B0017536; Fri, 24 May 2019 09:03:10 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 24 May 2019 09:03:06 +0200 Message-Id: <20190524070310.4952-2-kraxel@redhat.com> In-Reply-To: <20190524070310.4952-1-kraxel@redhat.com> References: <20190524070310.4952-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 24 May 2019 07:03:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/5] usb-hub: tweak feature names 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: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add dashes, so they don't look like two separate things when printed. Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- hw/usb/dev-hub.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c index 7e9339b8a83d..9b04b6a6ec2d 100644 --- a/hw/usb/dev-hub.c +++ b/hw/usb/dev-hub.c @@ -287,11 +287,11 @@ static const char *feature_name(int feature) [PORT_POWER] =3D "power", [PORT_LOWSPEED] =3D "lowspeed", [PORT_HIGHSPEED] =3D "highspeed", - [PORT_C_CONNECTION] =3D "change connection", - [PORT_C_ENABLE] =3D "change enable", - [PORT_C_SUSPEND] =3D "change suspend", - [PORT_C_OVERCURRENT] =3D "change overcurrent", - [PORT_C_RESET] =3D "change reset", + [PORT_C_CONNECTION] =3D "change-connection", + [PORT_C_ENABLE] =3D "change-enable", + [PORT_C_SUSPEND] =3D "change-suspend", + [PORT_C_OVERCURRENT] =3D "change-overcurrent", + [PORT_C_RESET] =3D "change-reset", [PORT_TEST] =3D "test", [PORT_INDICATOR] =3D "indicator", }; --=20 2.18.1 From nobody Sun May 5 23:27:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558681941; cv=none; d=zoho.com; s=zohoarc; b=lC8g53L+erh28M4mH5SE4qMfYAtjflY4Z1um1wv5RO0RbFDUkNmnq0khtTW294nLnOpX+U016E6nUI04cGaHmOnwYl/LRPEoH3Lf9v4+vVHjT/RmxTEwPFj1RlD5prDYdwfUTGnkcv4bE+pprcIxtLbE4Adre148XKUt5MNUvOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558681941; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=L0MHhBymydXfhs2Z8m0E81D2VwFYJ/fc6QxkCd4jyi8=; b=M23km+TNPR7Hq880JPqWJLdKzeq2yCvaigHmZcZRq0Dkz5i8599vFr3OvPFaWSBIpLWVBLZt+gP3DsNmYURI2J7OX+Sn3BFAYiul079kzqN+k1na3tqW66xvRYs8us2EyrxqnKSNud08WaP/71pMXvOhS96znWYGvEC6udS8N+8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 15586819417371000.9285461785054; Fri, 24 May 2019 00:12:21 -0700 (PDT) Received: from localhost ([127.0.0.1]:50221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hU4ND-0004hu-EU for importer@patchew.org; Fri, 24 May 2019 03:12:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45888) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hU4Ec-0005RI-Gd for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hU4Eb-0006NO-7W for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53298) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hU4Ea-0006I4-Ot for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:21 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B2D264D87 for ; Fri, 24 May 2019 07:03:12 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-101.ams2.redhat.com [10.36.116.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8350C5C219; Fri, 24 May 2019 07:03:11 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id CB28B17538; Fri, 24 May 2019 09:03:10 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 24 May 2019 09:03:07 +0200 Message-Id: <20190524070310.4952-3-kraxel@redhat.com> In-Reply-To: <20190524070310.4952-1-kraxel@redhat.com> References: <20190524070310.4952-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 24 May 2019 07:03:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/5] usb-hub: make number of ports runtime-configurable 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: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add num_ports property which allows configure the number of downstream ports. Valid range is 1-8, default is 8. Signed-off-by: Gerd Hoffmann --- hw/usb/dev-hub.c | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c index 9b04b6a6ec2d..4f700c8f92b5 100644 --- a/hw/usb/dev-hub.c +++ b/hw/usb/dev-hub.c @@ -29,7 +29,7 @@ #include "desc.h" #include "qemu/error-report.h" =20 -#define NUM_PORTS 8 +#define MAX_PORTS 8 =20 typedef struct USBHubPort { USBPort port; @@ -40,7 +40,8 @@ typedef struct USBHubPort { typedef struct USBHubState { USBDevice dev; USBEndpoint *intr; - USBHubPort ports[NUM_PORTS]; + uint32_t num_ports; + USBHubPort ports[MAX_PORTS]; } USBHubState; =20 #define TYPE_USB_HUB "usb-hub" @@ -109,7 +110,7 @@ static const USBDescIface desc_iface_hub =3D { { .bEndpointAddress =3D USB_DIR_IN | 0x01, .bmAttributes =3D USB_ENDPOINT_XFER_INT, - .wMaxPacketSize =3D 1 + DIV_ROUND_UP(NUM_PORTS, 8), + .wMaxPacketSize =3D 1 + DIV_ROUND_UP(MAX_PORTS, 8), .bInterval =3D 0xff, }, } @@ -242,7 +243,7 @@ static USBDevice *usb_hub_find_device(USBDevice *dev, u= int8_t addr) USBDevice *downstream; int i; =20 - for (i =3D 0; i < NUM_PORTS; i++) { + for (i =3D 0; i < s->num_ports; i++) { port =3D &s->ports[i]; if (!(port->wPortStatus & PORT_STAT_ENABLE)) { continue; @@ -262,7 +263,7 @@ static void usb_hub_handle_reset(USBDevice *dev) int i; =20 trace_usb_hub_reset(s->dev.addr); - for (i =3D 0; i < NUM_PORTS; i++) { + for (i =3D 0; i < s->num_ports; i++) { port =3D s->ports + i; port->wPortStatus =3D PORT_STAT_POWER; port->wPortChange =3D 0; @@ -332,7 +333,7 @@ static void usb_hub_handle_control(USBDevice *dev, USBP= acket *p, { unsigned int n =3D index - 1; USBHubPort *port; - if (n >=3D NUM_PORTS) { + if (n >=3D s->num_ports) { goto fail; } port =3D &s->ports[n]; @@ -361,7 +362,7 @@ static void usb_hub_handle_control(USBDevice *dev, USBP= acket *p, trace_usb_hub_set_port_feature(s->dev.addr, index, feature_name(value)); =20 - if (n >=3D NUM_PORTS) { + if (n >=3D s->num_ports) { goto fail; } port =3D &s->ports[n]; @@ -394,7 +395,7 @@ static void usb_hub_handle_control(USBDevice *dev, USBP= acket *p, trace_usb_hub_clear_port_feature(s->dev.addr, index, feature_name(value)); =20 - if (n >=3D NUM_PORTS) { + if (n >=3D s->num_ports) { goto fail; } port =3D &s->ports[n]; @@ -443,17 +444,17 @@ static void usb_hub_handle_control(USBDevice *dev, US= BPacket *p, unsigned int n, limit, var_hub_size =3D 0; memcpy(data, qemu_hub_hub_descriptor, sizeof(qemu_hub_hub_descriptor)); - data[2] =3D NUM_PORTS; + data[2] =3D s->num_ports; =20 /* fill DeviceRemovable bits */ - limit =3D DIV_ROUND_UP(NUM_PORTS + 1, 8) + 7; + limit =3D DIV_ROUND_UP(s->num_ports + 1, 8) + 7; for (n =3D 7; n < limit; n++) { data[n] =3D 0x00; var_hub_size++; } =20 /* fill PortPwrCtrlMask bits */ - limit =3D limit + DIV_ROUND_UP(NUM_PORTS, 8); + limit =3D limit + DIV_ROUND_UP(s->num_ports, 8); for (;n < limit; n++) { data[n] =3D 0xff; var_hub_size++; @@ -481,7 +482,7 @@ static void usb_hub_handle_data(USBDevice *dev, USBPack= et *p) unsigned int status; uint8_t buf[4]; int i, n; - n =3D DIV_ROUND_UP(NUM_PORTS + 1, 8); + n =3D DIV_ROUND_UP(s->num_ports + 1, 8); if (p->iov.size =3D=3D 1) { /* FreeBSD workaround */ n =3D 1; } else if (n > p->iov.size) { @@ -489,7 +490,7 @@ static void usb_hub_handle_data(USBDevice *dev, USBPack= et *p) return; } status =3D 0; - for(i =3D 0; i < NUM_PORTS; i++) { + for (i =3D 0; i < s->num_ports; i++) { port =3D &s->ports[i]; if (port->wPortChange) status |=3D (1 << (i + 1)); @@ -520,7 +521,7 @@ static void usb_hub_unrealize(USBDevice *dev, Error **e= rrp) USBHubState *s =3D (USBHubState *)dev; int i; =20 - for (i =3D 0; i < NUM_PORTS; i++) { + for (i =3D 0; i < s->num_ports; i++) { usb_unregister_port(usb_bus_from_device(dev), &s->ports[i].port); } @@ -540,6 +541,12 @@ static void usb_hub_realize(USBDevice *dev, Error **er= rp) USBHubPort *port; int i; =20 + if (s->num_ports < 1 || s->num_ports > MAX_PORTS) { + error_setg(errp, "num_ports (%d) out of range (1..%d)", + s->num_ports, MAX_PORTS); + return; + } + if (dev->port->hubcount =3D=3D 5) { error_setg(errp, "usb hub chain too deep"); return; @@ -548,7 +555,7 @@ static void usb_hub_realize(USBDevice *dev, Error **err= p) usb_desc_create_serial(dev); usb_desc_init(dev); s->intr =3D usb_ep_get(dev, USB_TOKEN_IN, 1); - for (i =3D 0; i < NUM_PORTS; i++) { + for (i =3D 0; i < s->num_ports; i++) { port =3D &s->ports[i]; usb_register_port(usb_bus_from_device(dev), &port->port, s, i, &usb_hub_port_ops, @@ -575,12 +582,17 @@ static const VMStateDescription vmstate_usb_hub =3D { .minimum_version_id =3D 1, .fields =3D (VMStateField[]) { VMSTATE_USB_DEVICE(dev, USBHubState), - VMSTATE_STRUCT_ARRAY(ports, USBHubState, NUM_PORTS, 0, + VMSTATE_STRUCT_ARRAY(ports, USBHubState, MAX_PORTS, 0, vmstate_usb_hub_port, USBHubPort), VMSTATE_END_OF_LIST() } }; =20 +static Property usb_hub_properties[] =3D { + DEFINE_PROP_UINT32("ports", USBHubState, num_ports, 8), + DEFINE_PROP_END_OF_LIST(), +}; + static void usb_hub_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -597,6 +609,7 @@ static void usb_hub_class_initfn(ObjectClass *klass, vo= id *data) set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); dc->fw_name =3D "hub"; dc->vmsd =3D &vmstate_usb_hub; + dc->props =3D usb_hub_properties; } =20 static const TypeInfo hub_info =3D { --=20 2.18.1 From nobody Sun May 5 23:27:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558681714; cv=none; d=zoho.com; s=zohoarc; b=P0CWnkSZQY5X2NHIV+FTpxRWxDAAhnndrdDxt/kAYEx7dX9/8WdPRhc3VGFUNAwgg/Tyd/LTvXKxicIGBKXs6qBUbAqYVh+syZbZ5AJ+xsQe21yFrd9uerF0eeoMioxPUAuP6N56K9pw/qw8fQfWyu7ezC4uU49GQV3V2/y4/0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558681714; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=L36Oe1Kj7rBECOm4cDhNKr0WOaREtbhTTZ5f3h/Q5I0=; b=GrOU4kwJr1Kmx2iIe3xzMlJrPl6xxM7fWn1FdEAfWgM717qD9M+whgM1KTipA4HqdYpE5CGmrNk8WyVUa09/dQUdsBr0T6Flyq64THVs1Sea0N8foVAEipveaNsrEyWA4kYubUeIK6T/kzcp1LvW/XuG03OE+E4Kft5LeDdlxms= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558681714964697.9461189659271; Fri, 24 May 2019 00:08:34 -0700 (PDT) Received: from localhost ([127.0.0.1]:50143 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hU4Ja-0001Ex-SL for importer@patchew.org; Fri, 24 May 2019 03:08:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hU4Ec-0005R1-5D for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hU4Ea-0006Mr-QG for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59042) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hU4EY-0006GJ-Re for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:19 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3B8F1307D854 for ; Fri, 24 May 2019 07:03:14 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-101.ams2.redhat.com [10.36.116.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D2D71001DC0; Fri, 24 May 2019 07:03:11 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id D35AB1753A; Fri, 24 May 2019 09:03:10 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 24 May 2019 09:03:08 +0200 Message-Id: <20190524070310.4952-4-kraxel@redhat.com> In-Reply-To: <20190524070310.4952-1-kraxel@redhat.com> References: <20190524070310.4952-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 24 May 2019 07:03:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/5] usb-hub: add helpers to update port state 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: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add usb_hub_port_set() and usb_hub_port_clear() helpers which care about updating the change bits (port->wPortChange) properly, so we don't need to have that logic sprinkled all over the place ;) Signed-off-by: Gerd Hoffmann --- hw/usb/dev-hub.c | 84 ++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c index 4f700c8f92b5..1cc92a5f9abe 100644 --- a/hw/usb/dev-hub.c +++ b/hw/usb/dev-hub.c @@ -159,18 +159,46 @@ static const uint8_t qemu_hub_hub_descriptor[] =3D /* DeviceRemovable and PortPwrCtrlMask patched in later */ }; =20 +static bool usb_hub_port_change(USBHubPort *port, uint16_t status) +{ + bool notify =3D false; + + if (status & 0x1f) { + port->wPortChange |=3D status; + notify =3D true; + } + return notify; +} + +static bool usb_hub_port_set(USBHubPort *port, uint16_t status) +{ + if (port->wPortStatus & status) { + return false; + } + port->wPortStatus |=3D status; + return usb_hub_port_change(port, status); +} + +static bool usb_hub_port_clear(USBHubPort *port, uint16_t status) +{ + if (!(port->wPortStatus & status)) { + return false; + } + port->wPortStatus &=3D ~status; + return usb_hub_port_change(port, status); +} + static void usb_hub_attach(USBPort *port1) { USBHubState *s =3D port1->opaque; USBHubPort *port =3D &s->ports[port1->index]; =20 trace_usb_hub_attach(s->dev.addr, port1->index + 1); - port->wPortStatus |=3D PORT_STAT_CONNECTION; - port->wPortChange |=3D PORT_STAT_C_CONNECTION; + usb_hub_port_set(port, PORT_STAT_CONNECTION); if (port->port.dev->speed =3D=3D USB_SPEED_LOW) { - port->wPortStatus |=3D PORT_STAT_LOW_SPEED; + usb_hub_port_set(port, PORT_STAT_LOW_SPEED); } else { - port->wPortStatus &=3D ~PORT_STAT_LOW_SPEED; + usb_hub_port_clear(port, PORT_STAT_LOW_SPEED); } usb_wakeup(s->intr, 0); } @@ -186,16 +214,9 @@ static void usb_hub_detach(USBPort *port1) /* Let upstream know the device on this port is gone */ s->dev.port->ops->child_detach(s->dev.port, port1->dev); =20 - port->wPortStatus &=3D ~PORT_STAT_CONNECTION; - port->wPortChange |=3D PORT_STAT_C_CONNECTION; - if (port->wPortStatus & PORT_STAT_ENABLE) { - port->wPortStatus &=3D ~PORT_STAT_ENABLE; - port->wPortChange |=3D PORT_STAT_C_ENABLE; - } - if (port->wPortStatus & PORT_STAT_SUSPEND) { - port->wPortStatus &=3D ~PORT_STAT_SUSPEND; - port->wPortChange |=3D PORT_STAT_C_SUSPEND; - } + usb_hub_port_clear(port, PORT_STAT_CONNECTION); + usb_hub_port_clear(port, PORT_STAT_ENABLE); + usb_hub_port_clear(port, PORT_STAT_SUSPEND); usb_wakeup(s->intr, 0); } =20 @@ -212,9 +233,7 @@ static void usb_hub_wakeup(USBPort *port1) USBHubState *s =3D port1->opaque; USBHubPort *port =3D &s->ports[port1->index]; =20 - if (port->wPortStatus & PORT_STAT_SUSPEND) { - port->wPortStatus &=3D ~PORT_STAT_SUSPEND; - port->wPortChange |=3D PORT_STAT_C_SUSPEND; + if (usb_hub_port_clear(port, PORT_STAT_SUSPEND)) { usb_wakeup(s->intr, 0); } } @@ -265,13 +284,13 @@ static void usb_hub_handle_reset(USBDevice *dev) trace_usb_hub_reset(s->dev.addr); for (i =3D 0; i < s->num_ports; i++) { port =3D s->ports + i; - port->wPortStatus =3D PORT_STAT_POWER; + port->wPortStatus =3D 0; port->wPortChange =3D 0; + usb_hub_port_set(port, PORT_STAT_POWER); if (port->port.dev && port->port.dev->attached) { - port->wPortStatus |=3D PORT_STAT_CONNECTION; - port->wPortChange |=3D PORT_STAT_C_CONNECTION; + usb_hub_port_set(port, PORT_STAT_CONNECTION); if (port->port.dev->speed =3D=3D USB_SPEED_LOW) { - port->wPortStatus |=3D PORT_STAT_LOW_SPEED; + usb_hub_port_set(port, PORT_STAT_LOW_SPEED); } } } @@ -372,13 +391,13 @@ static void usb_hub_handle_control(USBDevice *dev, US= BPacket *p, port->wPortStatus |=3D PORT_STAT_SUSPEND; break; case PORT_RESET: + usb_hub_port_set(port, PORT_STAT_RESET); + usb_hub_port_clear(port, PORT_STAT_RESET); if (dev && dev->attached) { usb_device_reset(dev); - port->wPortChange |=3D PORT_STAT_C_RESET; - /* set enable bit */ - port->wPortStatus |=3D PORT_STAT_ENABLE; - usb_wakeup(s->intr, 0); + usb_hub_port_set(port, PORT_STAT_ENABLE); } + usb_wakeup(s->intr, 0); break; case PORT_POWER: break; @@ -407,20 +426,7 @@ static void usb_hub_handle_control(USBDevice *dev, USB= Packet *p, port->wPortChange &=3D ~PORT_STAT_C_ENABLE; break; case PORT_SUSPEND: - if (port->wPortStatus & PORT_STAT_SUSPEND) { - port->wPortStatus &=3D ~PORT_STAT_SUSPEND; - - /* - * USB Spec rev2.0 11.24.2.7.2.3 C_PORT_SUSPEND - * "This bit is set on the following transitions: - * - On transition from the Resuming state to the - * SendEOP [sic] state" - * - * Note that this includes both remote wake-up and - * explicit ClearPortFeature(PORT_SUSPEND). - */ - port->wPortChange |=3D PORT_STAT_C_SUSPEND; - } + usb_hub_port_clear(port, PORT_STAT_SUSPEND); break; case PORT_C_SUSPEND: port->wPortChange &=3D ~PORT_STAT_C_SUSPEND; --=20 2.18.1 From nobody Sun May 5 23:27:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558681851; cv=none; d=zoho.com; s=zohoarc; b=eYD6C46iirl0dv1saWDfdO/zv9FonIhT8mZN7jpPIqwQKUG+9jbHyYHa/8o0oQ1PhnN/SYWovnq/1ShrF8C9c/3ufcWWjMFULyN9cqbEibfofGgA21IsY/3fBlsoX6l9wlnvToWFzqV/9Ay5JyHeFSIjQpC8XQ4RD2R1pK3YTpY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558681851; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=CQECXBT+TkzLx6IilzWhlYHkZKLGt0O5u5ZViRuXazM=; b=DcPD1KZKCnGA9/v0W1cDJsDUYmmB8dIKXuGfwrMWbUnHezXzWou7BTdnSg0CCEg8zTPaNBpRpim/HlhSkuo9krJJ3U8eRwtV31YlNjw2e0BEenhEHaSU+dfZPK3GM5Nclm0PntAgNiYwYlxQEEgzhaX21E0JpIsS7HtnJTJmEek= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558681851789408.9951189823705; Fri, 24 May 2019 00:10:51 -0700 (PDT) Received: from localhost ([127.0.0.1]:50199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hU4Li-00038t-OI for importer@patchew.org; Fri, 24 May 2019 03:10:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hU4EY-0005PS-Tx for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hU4EX-0006Hq-0U for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45392) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hU4EV-0006GE-2F for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:16 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14D73308793A for ; Fri, 24 May 2019 07:03:14 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-101.ams2.redhat.com [10.36.116.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85F9817D5D; Fri, 24 May 2019 07:03:11 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id DBE311753B; Fri, 24 May 2019 09:03:10 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 24 May 2019 09:03:09 +0200 Message-Id: <20190524070310.4952-5-kraxel@redhat.com> In-Reply-To: <20190524070310.4952-1-kraxel@redhat.com> References: <20190524070310.4952-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 24 May 2019 07:03:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 4/5] usb-hub: add usb_hub_port_update() 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: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Helper function to update port status bits which depends on the connected device. We need the same logic for device attach and port reset, so factor it out. Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- hw/usb/dev-hub.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c index 1cc92a5f9abe..29f4d6723e26 100644 --- a/hw/usb/dev-hub.c +++ b/hw/usb/dev-hub.c @@ -188,18 +188,28 @@ static bool usb_hub_port_clear(USBHubPort *port, uint= 16_t status) return usb_hub_port_change(port, status); } =20 +static bool usb_hub_port_update(USBHubPort *port) +{ + bool notify =3D false; + + if (port->port.dev && port->port.dev->attached) { + notify =3D usb_hub_port_set(port, PORT_STAT_CONNECTION); + if (port->port.dev->speed =3D=3D USB_SPEED_LOW) { + usb_hub_port_set(port, PORT_STAT_LOW_SPEED); + } else { + usb_hub_port_clear(port, PORT_STAT_LOW_SPEED); + } + } + return notify; +} + static void usb_hub_attach(USBPort *port1) { USBHubState *s =3D port1->opaque; USBHubPort *port =3D &s->ports[port1->index]; =20 trace_usb_hub_attach(s->dev.addr, port1->index + 1); - usb_hub_port_set(port, PORT_STAT_CONNECTION); - if (port->port.dev->speed =3D=3D USB_SPEED_LOW) { - usb_hub_port_set(port, PORT_STAT_LOW_SPEED); - } else { - usb_hub_port_clear(port, PORT_STAT_LOW_SPEED); - } + usb_hub_port_update(port); usb_wakeup(s->intr, 0); } =20 @@ -287,12 +297,7 @@ static void usb_hub_handle_reset(USBDevice *dev) port->wPortStatus =3D 0; port->wPortChange =3D 0; usb_hub_port_set(port, PORT_STAT_POWER); - if (port->port.dev && port->port.dev->attached) { - usb_hub_port_set(port, PORT_STAT_CONNECTION); - if (port->port.dev->speed =3D=3D USB_SPEED_LOW) { - usb_hub_port_set(port, PORT_STAT_LOW_SPEED); - } - } + usb_hub_port_update(port); } } =20 --=20 2.18.1 From nobody Sun May 5 23:27:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558681675; cv=none; d=zoho.com; s=zohoarc; b=DaAOrLgC1C1i9plGSbxzST0e0lIaf8pU3XS7fVytpM+34Crw/HhYlnnjcd2QGyRvnjZKoKH4IDY2OHHB1t8wvWk8c8fg/b1Rtc3xCgGxYxvXs1+K04WkjBfl9wZo0DLud6smQqBu0LFZz/HjT+eiVvXalC/vljRtfPQn7vpWx5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558681675; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=sgJALrKenlZetA1EGfa7rYqUP1+N3gOmIDaLioMzK7I=; b=EkYaNNAkH8ibFHzqE0GvmAUE4nsMr89ZHNlYUr8SwiADTjnxTynfLxAuZP34bBs9tWAr7A/1mD4OhE+Xs2u/d9HXvEMszxSyL4sy84wW2kem/2FXpuo/1nWgFnzmmQplgLoLVVNfFQGN3Nbg+CHdCAxiOS2Owj6uc7OT4h1Cqys= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558681675344181.03712642222354; Fri, 24 May 2019 00:07:55 -0700 (PDT) Received: from localhost ([127.0.0.1]:50139 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hU4Iu-0000Wa-9G for importer@patchew.org; Fri, 24 May 2019 03:07:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hU4Ea-0005PV-ST for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hU4EY-0006LM-TV for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33670) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hU4EW-0006GO-Vy for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56238368E3 for ; Fri, 24 May 2019 07:03:14 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-101.ams2.redhat.com [10.36.116.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFE725B689; Fri, 24 May 2019 07:03:12 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id E43911753C; Fri, 24 May 2019 09:03:10 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 24 May 2019 09:03:10 +0200 Message-Id: <20190524070310.4952-6-kraxel@redhat.com> In-Reply-To: <20190524070310.4952-1-kraxel@redhat.com> References: <20190524070310.4952-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 24 May 2019 07:03:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 5/5] usb-hub: emulate per port power switching 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: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add support for per port power switching. Virtual power of course ;) Use port-power=3Don property to enable this. Signed-off-by: Gerd Hoffmann --- hw/usb/dev-hub.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c index 29f4d6723e26..2b64d6ef0349 100644 --- a/hw/usb/dev-hub.c +++ b/hw/usb/dev-hub.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu-common.h" +#include "qemu/timer.h" #include "trace.h" #include "hw/usb.h" #include "desc.h" @@ -41,6 +42,8 @@ typedef struct USBHubState { USBDevice dev; USBEndpoint *intr; uint32_t num_ports; + bool port_power; + QEMUTimer *port_timer; USBHubPort ports[MAX_PORTS]; } USBHubState; =20 @@ -203,6 +206,20 @@ static bool usb_hub_port_update(USBHubPort *port) return notify; } =20 +static void usb_hub_port_update_timer(void *opaque) +{ + USBHubState *s =3D opaque; + bool notify =3D false; + int i; + + for (i =3D 0; i < s->num_ports; i++) { + notify |=3D usb_hub_port_update(&s->ports[i]); + } + if (notify) { + usb_wakeup(s->intr, 0); + } +} + static void usb_hub_attach(USBPort *port1) { USBHubState *s =3D port1->opaque; @@ -405,6 +422,11 @@ static void usb_hub_handle_control(USBDevice *dev, USB= Packet *p, usb_wakeup(s->intr, 0); break; case PORT_POWER: + if (s->port_power) { + int64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + usb_hub_port_set(port, PORT_STAT_POWER); + timer_mod(s->port_timer, now + 5000000); /* 5 ms */ + } break; default: goto fail; @@ -445,6 +467,14 @@ static void usb_hub_handle_control(USBDevice *dev, USB= Packet *p, case PORT_C_RESET: port->wPortChange &=3D ~PORT_STAT_C_RESET; break; + case PORT_POWER: + if (s->port_power) { + usb_hub_port_clear(port, PORT_STAT_POWER); + usb_hub_port_clear(port, PORT_STAT_CONNECTION); + usb_hub_port_clear(port, PORT_STAT_ENABLE); + usb_hub_port_clear(port, PORT_STAT_SUSPEND); + port->wPortChange =3D 0; + } default: goto fail; } @@ -457,6 +487,11 @@ static void usb_hub_handle_control(USBDevice *dev, USB= Packet *p, sizeof(qemu_hub_hub_descriptor)); data[2] =3D s->num_ports; =20 + if (s->port_power) { + data[3] &=3D ~0x03; + data[3] |=3D 0x01; + } + /* fill DeviceRemovable bits */ limit =3D DIV_ROUND_UP(s->num_ports + 1, 8) + 7; for (n =3D 7; n < limit; n++) { @@ -536,6 +571,9 @@ static void usb_hub_unrealize(USBDevice *dev, Error **e= rrp) usb_unregister_port(usb_bus_from_device(dev), &s->ports[i].port); } + + timer_del(s->port_timer); + timer_free(s->port_timer); } =20 static USBPortOps usb_hub_port_ops =3D { @@ -565,6 +603,8 @@ static void usb_hub_realize(USBDevice *dev, Error **err= p) =20 usb_desc_create_serial(dev); usb_desc_init(dev); + s->port_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, + usb_hub_port_update_timer, s); s->intr =3D usb_ep_get(dev, USB_TOKEN_IN, 1); for (i =3D 0; i < s->num_ports; i++) { port =3D &s->ports[i]; @@ -587,6 +627,24 @@ static const VMStateDescription vmstate_usb_hub_port = =3D { } }; =20 +static bool usb_hub_port_timer_needed(void *opaque) +{ + USBHubState *s =3D opaque; + + return s->port_power; +} + +static const VMStateDescription vmstate_usb_hub_port_timer =3D { + .name =3D "usb-hub/port-timer", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D usb_hub_port_timer_needed, + .fields =3D (VMStateField[]) { + VMSTATE_TIMER_PTR(port_timer, USBHubState), + VMSTATE_END_OF_LIST() + }, +}; + static const VMStateDescription vmstate_usb_hub =3D { .name =3D "usb-hub", .version_id =3D 1, @@ -596,11 +654,16 @@ static const VMStateDescription vmstate_usb_hub =3D { VMSTATE_STRUCT_ARRAY(ports, USBHubState, MAX_PORTS, 0, vmstate_usb_hub_port, USBHubPort), VMSTATE_END_OF_LIST() + }, + .subsections =3D (const VMStateDescription * []) { + &vmstate_usb_hub_port_timer, + NULL } }; =20 static Property usb_hub_properties[] =3D { DEFINE_PROP_UINT32("ports", USBHubState, num_ports, 8), + DEFINE_PROP_BOOL("port-power", USBHubState, port_power, false), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.18.1