From nobody Sun Aug 10 03:16:17 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4c02wd5VkGz63YPc; Sun, 10 Aug 2025 03:16:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4c02wd2z4Vz42MC; Sun, 10 Aug 2025 03:16:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754795777; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TQDa9vMneotL7UAQRvRY2+5av3upLwKQqJUsRclT77k=; b=Z3squOzkWu+B+2v7Y5dSBbrOR3Eq700w3etsj8l3ZruW9n2HFfzJHRUAzXecidoaEpHEjb +xx6VOVnJWsW37ZPI3Nd3x2oz/rPzac0IgXYNeNA7kF3bcbDmznRMSDFFM68LDCJT4MWZ5 ztWL8hDxfia0sbh/EMYCIJDaufCRPy4BtA83LdBL4y5DpOGKUdWeupVux+rdJoreL6/Pn0 CzU/+zVAh/wqArkiTIPkSrExcPsBK/mfOe4RIayVvf3BOh6pNB5l5Ra4pJWUYuw3XXS9mG G6SvM34zEswvkDRHRlB1z5De+DW3ZJzHIJS4QLgjgOB5xIebB6nxXZ7AImD+NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754795777; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TQDa9vMneotL7UAQRvRY2+5av3upLwKQqJUsRclT77k=; b=Klwu9hSF4QBc/c4T1BXm/dUEgpxWZ+RGYneWjz02vt4kTEln99MYRt2tpd39jVZ7Qlu2DL yPxb3al+2FikgwSWyJT28z6ZV+Nbse0pwE92Vr68y2eJbvA+XEsqCrHZPxHsJtE6hFGobD HX6T/UW4nFCrDxDpSyrEpp1U6LMDJgPzdR1kaqBWTqGpxN1Tapyv3hYmJbkpsA8cXf2j0O 8+cCVGhnqHpMlJDwmW46r8PWebC4e4eUelYMaRNksuTnr2ZhF7txovzK1X2ekI6ijXITBI kNe9jYakR7+46Vj7DlBCfggVZoaiO0kFY0WKtNBFvFlHVuZai/etvEJVrtNTeA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1754795777; a=rsa-sha256; cv=none; b=kv6aXepzKcqAs/jmKq3HYjWNHnORQnYrroPLabGyirC0wPIWAmvBIvFz6WfnbFXegp0j1k Y2s4s+7rqR1gBiB6YJo5QbCjuNpUAjz4UolzmdMpiMxxFy45xtVnLAwSZpcZvKIz77MHi9 c5T9TGHnWd/cyaFkboPx9dAgx1DlqM1gEVG6CBygMJQy0nbcHNds5Yajpa1nBHK+0mhcNV I0YFQG7+S34pzBH9nIS9W+oKc5SiPJ2qv3tyz9Rs1pdZQ2gx7ykaRjB2aOq2kP6dpBPnmm TOneJTpSw1odT3OwxUYk6h5QdhfTHLy5TfUDHoVY54oB/Ash/NItedruGqRTqg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4c02wd2Ygxzq3Q; Sun, 10 Aug 2025 03:16:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 57A3GHxO074795; Sun, 10 Aug 2025 03:16:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 57A3GHYk074792; Sun, 10 Aug 2025 03:16:17 GMT (envelope-from git) Date: Sun, 10 Aug 2025 03:16:17 GMT Message-Id: <202508100316.57A3GHYk074792@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: ShengYi Hung Subject: git: ec99803ad70a - main - bhyve: Populate the device version from the backend List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: aokblast X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ec99803ad70a757cc104334f745a2985cf60e948 Auto-Submitted: auto-generated The branch main has been updated by aokblast: URL: https://cgit.FreeBSD.org/src/commit/?id=ec99803ad70a757cc104334f745a2985cf60e948 commit ec99803ad70a757cc104334f745a2985cf60e948 Author: ShengYi Hung AuthorDate: 2025-07-23 16:19:40 +0000 Commit: ShengYi Hung CommitDate: 2025-08-10 03:15:41 +0000 bhyve: Populate the device version from the backend The pci_xhci driver requires the USB device version to be known before allocating a hub port. To support this, we split the original xHCI initialization into two phases: 1. Probe: Parse the nvlist and determine the device version. 2. Init: Complete initialization and set up the softc details. This change ensures proper hub port allocation based on accurate device version. Approved by: markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51478 --- usr.sbin/bhyve/pci_xhci.c | 35 +++++++++++++++++++++++++---------- usr.sbin/bhyve/usb_emul.h | 4 +++- usr.sbin/bhyve/usb_mouse.c | 13 +++++++++++-- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/usr.sbin/bhyve/pci_xhci.c b/usr.sbin/bhyve/pci_xhci.c index 0871bbb87fe5..ff12e40359e2 100644 --- a/usr.sbin/bhyve/pci_xhci.c +++ b/usr.sbin/bhyve/pci_xhci.c @@ -406,7 +406,7 @@ pci_xhci_usbcmd_write(struct pci_xhci_softc *sc, uint32_t cmd) * XHCI 4.19.3 USB2 RxDetect->Polling, * USB3 Polling->U0 */ - if (dev->dev_ue->ue_usbver == 2) + if (dev->hci.hci_usbver == 2) port->portsc |= XHCI_PS_PLS_SET(UPS_PORT_LS_POLL); else @@ -2590,7 +2590,7 @@ pci_xhci_reset_port(struct pci_xhci_softc *sc, int portn, int warm) port->portsc |= XHCI_PS_PED | XHCI_PS_SPEED_SET(dev->hci.hci_speed); - if (warm && dev->dev_ue->ue_usbver == 3) { + if (warm && dev->hci.hci_usbver == 3) { port->portsc |= XHCI_PS_WRC; } @@ -2620,7 +2620,7 @@ pci_xhci_init_port(struct pci_xhci_softc *sc, int portn) port->portsc = XHCI_PS_CCS | /* connected */ XHCI_PS_PP; /* port power */ - if (dev->dev_ue->ue_usbver == 2) { + if (dev->hci.hci_usbver == 2) { port->portsc |= XHCI_PS_PLS_SET(UPS_PORT_LS_POLL) | XHCI_PS_SPEED_SET(dev->hci.hci_speed); } else { @@ -2785,8 +2785,8 @@ pci_xhci_parse_devices(struct pci_xhci_softc *sc, nvlist_t *nvl) cookie = NULL; while ((name = nvlist_next(slots_nvl, &type, &cookie)) != NULL) { - if (usb2_port == ((sc->usb2_port_start) + XHCI_MAX_DEVS/2) || - usb3_port == ((sc->usb3_port_start) + XHCI_MAX_DEVS/2)) { + if (usb2_port == ((sc->usb2_port_start) + XHCI_MAX_DEVS / 2) || + usb3_port == ((sc->usb3_port_start) + XHCI_MAX_DEVS / 2)) { WPRINTF(("pci_xhci max number of USB 2 or 3 " "devices reached, max %d", XHCI_MAX_DEVS/2)); goto bad; @@ -2834,12 +2834,25 @@ pci_xhci_parse_devices(struct pci_xhci_softc *sc, nvlist_t *nvl) dev->hci.hci_intr = pci_xhci_dev_intr; dev->hci.hci_event = pci_xhci_dev_event; dev->hci.hci_speed = USB_SPEED_MAX; + dev->hci.hci_usbver = -1; - if (ue->ue_usbver == 2) { + devsc = ue->ue_probe(&dev->hci, nvl); + if (devsc == NULL) { + free(dev); + goto bad; + } + dev->dev_sc = devsc; + + if (dev->hci.hci_usbver == -1) + dev->hci.hci_usbver = ue->ue_usbver; + + if (dev->hci.hci_usbver == 2) { if (usb2_port == sc->usb2_port_start + XHCI_MAX_DEVS / 2) { WPRINTF(("pci_xhci max number of USB 2 devices " "reached, max %d", XHCI_MAX_DEVS / 2)); + free(dev->dev_sc); + free(dev); goto bad; } dev->hci.hci_port = usb2_port; @@ -2849,6 +2862,8 @@ pci_xhci_parse_devices(struct pci_xhci_softc *sc, nvlist_t *nvl) XHCI_MAX_DEVS / 2) { WPRINTF(("pci_xhci max number of USB 3 devices " "reached, max %d", XHCI_MAX_DEVS / 2)); + free(dev->dev_sc); + free(dev); goto bad; } dev->hci.hci_port = usb3_port; @@ -2857,13 +2872,10 @@ pci_xhci_parse_devices(struct pci_xhci_softc *sc, nvlist_t *nvl) XHCI_DEVINST_PTR(sc, dev->hci.hci_port) = dev; dev->hci.hci_address = 0; - devsc = ue->ue_init(&dev->hci, nvl); - if (devsc == NULL) { + if (ue->ue_init(dev->dev_sc)) goto bad; - } dev->dev_ue = ue; - dev->dev_sc = devsc; if (dev->hci.hci_speed == USB_SPEED_MAX) dev->hci.hci_speed = ue->ue_usbspeed; @@ -2885,6 +2897,8 @@ portsfinal: bad: for (i = 1; i <= XHCI_MAX_DEVS; i++) { + if (XHCI_DEVINST_PTR(sc, i) != NULL) + free(XHCI_DEVINST_PTR(sc, i)->dev_sc); free(XHCI_DEVINST_PTR(sc, i)); } @@ -3232,6 +3246,7 @@ pci_xhci_snapshot(struct vm_snapshot_meta *meta) SNAPSHOT_VAR_OR_LEAVE(dev->hci.hci_address, meta, ret, done); SNAPSHOT_VAR_OR_LEAVE(dev->hci.hci_port, meta, ret, done); SNAPSHOT_VAR_OR_LEAVE(dev->hci.hci_speed, meta, ret, done); + SNAPSHOT_VAR_OR_LEAVE(dev->hci.hci_usbver, meta, ret, done); } SNAPSHOT_VAR_OR_LEAVE(sc->usb2_port_start, meta, ret, done); diff --git a/usr.sbin/bhyve/usb_emul.h b/usr.sbin/bhyve/usb_emul.h index 85dedfeacd3b..43b6b53b5205 100644 --- a/usr.sbin/bhyve/usb_emul.h +++ b/usr.sbin/bhyve/usb_emul.h @@ -52,7 +52,8 @@ struct usb_devemu { int ue_usbspeed; /* usb device speed */ /* instance creation */ - void *(*ue_init)(struct usb_hci *hci, nvlist_t *nvl); + void *(*ue_probe)(struct usb_hci *hci, nvlist_t *nvl); + int (*ue_init)(void *sc); /* handlers */ int (*ue_request)(void *sc, struct usb_data_xfer *xfer); @@ -86,6 +87,7 @@ struct usb_hci { int hci_address; int hci_port; int hci_speed; + int hci_usbver; }; /* diff --git a/usr.sbin/bhyve/usb_mouse.c b/usr.sbin/bhyve/usb_mouse.c index a37941c0cd9d..82b1159d5f61 100644 --- a/usr.sbin/bhyve/usb_mouse.c +++ b/usr.sbin/bhyve/usb_mouse.c @@ -295,20 +295,28 @@ umouse_event(uint8_t button, int x, int y, void *arg) } static void * -umouse_init(struct usb_hci *hci, nvlist_t *nvl __unused) +umouse_probe(struct usb_hci *hci, nvlist_t *nvl __unused) { struct umouse_softc *sc; sc = calloc(1, sizeof(struct umouse_softc)); sc->hci = hci; + return (sc); +} + +static int +umouse_init(void *scarg) +{ + struct umouse_softc *sc = (struct umouse_softc *)scarg; + sc->hid.protocol = 1; /* REPORT protocol */ pthread_mutex_init(&sc->mtx, NULL); pthread_mutex_init(&sc->ev_mtx, NULL); console_ptr_register(umouse_event, sc, 10); - return (sc); + return (0); } #define UREQ(x,y) ((x) | ((y) << 8)) @@ -811,6 +819,7 @@ static struct usb_devemu ue_mouse = { .ue_emu = "tablet", .ue_usbver = 3, .ue_usbspeed = USB_SPEED_HIGH, + .ue_probe = umouse_probe, .ue_init = umouse_init, .ue_request = umouse_request, .ue_data = umouse_data_handler,