From nobody Sun May 19 14:32:52 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=1558518571; cv=none; d=zoho.com; s=zohoarc; b=Lp4Mbl4wG6ucsS7cI9K5mbGsGaNtXweh1l3QBY26qhVWoU57f83JLC1hoFDtE/7InhjWOPJE+Vd1P2q9C2h77B/Km6D4pWYCor1HwJRpN+MsmrrTrgZWlnd4ToyIalPAqbeQawWPaRdRz4iSD70lLXACOxi5gmrOvwjkvWnBz3A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558518571; 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=fuq0oowbsvX3RxvKRbROa3r88/q7mMkQNomad5dn1hpcujILahHjob2qLPiNJuS1ITBgnLz9E7yW2n163u4SRwA1BbwfVpvBC08tJJp1h3gjDlHCxj/i9GfiOM8tRm4I4ZvaMVN/eLQqovwpb337X2pC3dWCbAfEkfADjTmtMK8= 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 1558518571414418.5688680456734; Wed, 22 May 2019 02:49:31 -0700 (PDT) Received: from localhost ([127.0.0.1]:39100 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTNVB-0001Pw-Pd for importer@patchew.org; Wed, 22 May 2019 05:25:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43767) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTNTY-0000Yq-BV for qemu-devel@nongnu.org; Wed, 22 May 2019 05:23:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTNTX-00016o-Gb for qemu-devel@nongnu.org; Wed, 22 May 2019 05:23:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47652) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTNTX-00015g-Ar for qemu-devel@nongnu.org; Wed, 22 May 2019 05:23:55 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 704B386673 for ; Wed, 22 May 2019 09:23:54 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-74.ams2.redhat.com [10.36.117.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAEE8282D8; Wed, 22 May 2019 09:23:51 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 12029A200; Wed, 22 May 2019 11:23:51 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 11:23:47 +0200 Message-Id: <20190522092351.17920-2-kraxel@redhat.com> In-Reply-To: <20190522092351.17920-1-kraxel@redhat.com> References: <20190522092351.17920-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 22 May 2019 09:23:54 +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 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 --- 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 19 14:32:52 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=1558517293; cv=none; d=zoho.com; s=zohoarc; b=YirKXn1beDUBBtPII25llr+8N3O5SvTT1mwA3aanipLrBLF1gMwduCVipx4tlt07+WnFbyQKFPbR6EIBXyRk81yGMunc6RXebdW/bbdWu7TmiNhH3RyNV2zc7jSval1mY5s7TYwx5LRtLVqksWRfaTNqT6EZ7kKCwA/rAvwE4Rg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558517293; 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=fE9EJGqBeG3esBx4gg+oetn/pq+IkOj6/6N+ekkOYnA=; b=El27/wZeGFCYSQB8dU843HCbdUS8c9BM7vcG9eB2RkXk623BNHsWBP/fD/WyTlmTWXbN5+nb8Rr7+56u1H3jurF43fs/QqqLxBB9xicO4Z7W5WBZPv/L0sW2OK6wCK9fvQREFMvdJ0Xt9H4S8SWbhTIsmhOUg6r07TGLvtp5BSk= 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 1558517293240199.24660822376165; Wed, 22 May 2019 02:28:13 -0700 (PDT) Received: from localhost ([127.0.0.1]:39138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTNXb-0003I6-7A for importer@patchew.org; Wed, 22 May 2019 05:28:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTNTY-0000Ys-RX for qemu-devel@nongnu.org; Wed, 22 May 2019 05:23:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTNTX-00016z-Ix for qemu-devel@nongnu.org; Wed, 22 May 2019 05:23:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42146) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTNTX-00015q-BJ for qemu-devel@nongnu.org; Wed, 22 May 2019 05:23:55 -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 A897981E04 for ; Wed, 22 May 2019 09:23:54 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-74.ams2.redhat.com [10.36.117.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAC9162660; Wed, 22 May 2019 09:23:51 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 1A815A205; Wed, 22 May 2019 11:23:51 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 11:23:48 +0200 Message-Id: <20190522092351.17920-3-kraxel@redhat.com> In-Reply-To: <20190522092351.17920-1-kraxel@redhat.com> References: <20190522092351.17920-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.25]); Wed, 22 May 2019 09:23:54 +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 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..d25ac1817995 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 19 14:32:52 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=1558517152; cv=none; d=zoho.com; s=zohoarc; b=b3Of6pQzBiN1gXUeEP5oK52CApEcqpA9o1VcCchwWnOGh8Ut0wjjqfOTq6pV7O0xrAjv3u7o5hfMeAunizZC0GgA8+ebR33jOWxaPqMFqDfBAFID1z6fOrb0qUNs0h95OZvJ2pTonCtcQEh4IbJnMaTSYJRRWALGdYGjx9ouCYo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558517152; 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=8iJC8wRoNbcAANNkUtx4rkZrQHtwRpJ8sxdjUgOPzd4=; b=TKs8m0eUSHTR3tOEIySjkcQxTCl+DWB3ssJq1fv+w0GYgBF7fSkuSbCQe0qqdui5W+q6p3ozdPspSFaz8HHqDvfMiXNE8Z9qeZwUU7dK2EMyLGrpmvPIQ8kG8DdM+RrL69SWAa15v8w3s0qamDXr+XfzeJa4+RlWaPgFrzsRZ+s= 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 1558517152262254.3852666006719; Wed, 22 May 2019 02:25:52 -0700 (PDT) Received: from localhost ([127.0.0.1]:39114 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTNVM-0001X2-6X for importer@patchew.org; Wed, 22 May 2019 05:25:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43867) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTNTi-0000dO-FC for qemu-devel@nongnu.org; Wed, 22 May 2019 05:24:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTNTh-0001KT-9y for qemu-devel@nongnu.org; Wed, 22 May 2019 05:24:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42184) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTNTh-0001J2-2V for qemu-devel@nongnu.org; Wed, 22 May 2019 05:24:05 -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 CF33E81E0B for ; Wed, 22 May 2019 09:23:54 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-74.ams2.redhat.com [10.36.117.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AD431001E81; Wed, 22 May 2019 09:23:51 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 22D5CA206; Wed, 22 May 2019 11:23:51 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 11:23:49 +0200 Message-Id: <20190522092351.17920-4-kraxel@redhat.com> In-Reply-To: <20190522092351.17920-1-kraxel@redhat.com> References: <20190522092351.17920-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.25]); Wed, 22 May 2019 09:23:54 +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 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 d25ac1817995..4940280264b4 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 19 14:32:52 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=1558517150; cv=none; d=zoho.com; s=zohoarc; b=oY3X2AnOCXaC3rGBgEypWV2iF9cfKrYa/DLZlmTgfGO0bcVHvul3G8PtiUKGfgjhLncRS+SbPNPE00QcBmKLEP9bsYYguOhLe25Cz2FYHvaZ08hDXg+a0AlX8DkAaXGwaTEJEUpHIaSuUcdRAlDAIgY6t/Li3iKSG4Y7k2IHsdw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558517150; 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=YSO9TYGp5nug/ms6mkMbHk+hvGWAV3JU1wcDhWyKXVk=; b=mK5h3HXxmASuGhvFb7ltMbuJxx+v4ehYJKcHusBkUIwO8WHBiLaNdR3hQpdTHey4MJXGbQq3utq6hihoSFU5PtI0uUoZJ7KOok2e9XiDMVALXIpa+VUUoj7U2H0mbfmdxl3mF7QoMS7H5BAIjM7JAWsWDtnRi721Kxh8ftl3jSc= 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 1558517150005468.8817026979549; Wed, 22 May 2019 02:25:50 -0700 (PDT) Received: from localhost ([127.0.0.1]:39103 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTNVC-0001QI-75 for importer@patchew.org; Wed, 22 May 2019 05:25:38 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTNTY-0000Yr-Cv for qemu-devel@nongnu.org; Wed, 22 May 2019 05:23:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTNTX-00016b-FY for qemu-devel@nongnu.org; Wed, 22 May 2019 05:23:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48226) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTNTX-00015f-9v for qemu-devel@nongnu.org; Wed, 22 May 2019 05:23:55 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E07D307D847 for ; Wed, 22 May 2019 09:23:54 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-74.ams2.redhat.com [10.36.117.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id F081860478; Wed, 22 May 2019 09:23:51 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 2AFFAA207; Wed, 22 May 2019 11:23:51 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 11:23:50 +0200 Message-Id: <20190522092351.17920-5-kraxel@redhat.com> In-Reply-To: <20190522092351.17920-1-kraxel@redhat.com> References: <20190522092351.17920-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 22 May 2019 09:23:54 +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 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. --- 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 4940280264b4..c1bc9785878c 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 19 14:32:52 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=1558517425; cv=none; d=zoho.com; s=zohoarc; b=JUuwsEpM2g651Y1BJ3+eQPie4D2zDiJuElIJMOleCjxUv15/99Y+u/9qEtwblUBM2kr2UF/xd1r1Xp0Nra6xYroZVGVCQliLE1D31FbtnLzDZvfPymgkIUtgLPgmFv2AJl/YR4UdtCkDlJm4ppdqh/K9V7FU8ALASbHWdipWdE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558517425; 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=UYd3lxjfmVKVjec2XyvSDRlZkZcf7IPfLqj4sjUe3zM=; b=DyKAdqkeqYamFsNBMuCqZGYUTPt7KhV0M4THq6w8Fx9Y4gUBOnFy2uJawWj89zb37MtEPjzA7gy5Lff1zqpazSkoChkw2Bunic7yb1eY2f1sYfFFO8I2oIw92fY+pt8ktKV/76cYG4AsBxaBnVutieheQW2vnAwi6nrlc9M/z/I= 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 155851742587395.17495013792643; Wed, 22 May 2019 02:30:25 -0700 (PDT) Received: from localhost ([127.0.0.1]:39162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTNZk-0005bT-0m for importer@patchew.org; Wed, 22 May 2019 05:30:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTNTe-0000dK-Vm for qemu-devel@nongnu.org; Wed, 22 May 2019 05:24:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTNTd-0001Fi-RV for qemu-devel@nongnu.org; Wed, 22 May 2019 05:24:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47856) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTNTd-0001Ec-JW for qemu-devel@nongnu.org; Wed, 22 May 2019 05:24:01 -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 E1FA930821B3 for ; Wed, 22 May 2019 09:23:55 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-74.ams2.redhat.com [10.36.117.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C20A1001F41; Wed, 22 May 2019 09:23:55 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 3377D9D85; Wed, 22 May 2019 11:23:51 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 11:23:51 +0200 Message-Id: <20190522092351.17920-6-kraxel@redhat.com> In-Reply-To: <20190522092351.17920-1-kraxel@redhat.com> References: <20190522092351.17920-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.47]); Wed, 22 May 2019 09:24:00 +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 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 c1bc9785878c..13c376e2e0f8 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