From nobody Sat Nov 30 21:24:38 2024 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 4Y133C0qcHz5fh83; Sat, 30 Nov 2024 21:24:39 +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 4Y133B5n7Gz4bBK; Sat, 30 Nov 2024 21:24:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733001878; 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=JZ1sFWLgb2U6/HFGfBRbisbPN4SlF1hbnSAmthCoUNU=; b=e2661QMUvdNmaeKuyJ5H6ZtlCFJ/s3+JjE+Hu09978OZRv6kQxy4L4vDhCDAh0Bwu5ldiA SOA46h2FHbFkpchod4dWgMqetPZ0L2nxe4K96xsmOhKeqtnVq4cZxd6vOvfvoELc++lL5z 5bhEWwGjlLSTGcSEu2laSXlLgX83kbrMbr8DzpzGDcWc1euxa2m9/NxE/wRTQ+0bGxgVkR MvmppHUX/j3bBa2rJG6AEDQdyXfQrhHMswa0IT1AR/OW9hGebYGnDOV18T3JtVJ/Qqd6FC RnlcHYsFaHFFMBnqFfNv/GECYxTDMAg9fhktBoSqvWckv2m0DF16RGscGMmVPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733001878; 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=JZ1sFWLgb2U6/HFGfBRbisbPN4SlF1hbnSAmthCoUNU=; b=v8UeWgNppg7+mvRTGyKGleGvTJxDbePMxQhL3HB1fXoOiuetw7NlQoAzNbBWGMAURby7Up hBKIOaG1BNKZh2VyQ0SnLFRwp2xuruNDanejU9w4BvUytBxcZ9da+/Frtip9ibwmuLlLkn DYd7FAc/0dhLNKn0fNkE1nW5IaCAfXxZg8zlgbcptHek002OzqrnV4PbqAx/exN0SPqdlk y0hTSKKxC/MD6mDl/YhhD79Fh8b5Qy1j03zuwhme7G/nt2uEvIBl7TTpsOUSMOHhUpROzS TVK2iF3rnzsi+RkqVjH40EJvMEmxI1IZgk2KByHGnaSx/PyjUU/2rGq/CKZRUw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733001878; a=rsa-sha256; cv=none; b=Ce16R5OphG6l3F/DOY/pOSedRNAzxhFO1sFTSqt6c9Vn7sXvD3fEcuM1mey4jOL95tf2ZX nX82/lmeuGg8RjTB+kjfn0j/GHiftcyDOzCLJ88nRiIr/QQH1jJVLEG1YHdtaXuDr81Lfp KMFH4zTpAbNo20svPn2rQVLK1CLCCjHeICeFiif5RUHrsb/zHzDkCU7swpm+dEijJuLOOh 86iuP8czSP6iRxO+NJx1PM/EBTjl3NnJJ+A3mIzJ88wIaYzt83K2xVpteQPpl92OJvPA5H 8q46IcrkZOrCJt/KTZY41UHsomDvlNgc2F2QnXlbDjaLwl1CikyZZQ3NVRUINg== 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 4Y133B5PWczPl0; Sat, 30 Nov 2024 21:24:38 +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 4AULOc78057611; Sat, 30 Nov 2024 21:24:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AULOcD2057608; Sat, 30 Nov 2024 21:24:38 GMT (envelope-from git) Date: Sat, 30 Nov 2024 21:24:38 GMT Message-Id: <202411302124.4AULOcD2057608@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 0b2f891f3bda - stable/14 - vmm ppt: Enable busmastering and BAR decoding while a device is assigned 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 0b2f891f3bda8cffdbcfbc9efaa819a9b3a01b8f Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=0b2f891f3bda8cffdbcfbc9efaa819a9b3a01b8f commit 0b2f891f3bda8cffdbcfbc9efaa819a9b3a01b8f Author: John Baldwin AuthorDate: 2024-08-22 18:40:48 +0000 Commit: John Baldwin CommitDate: 2024-11-30 20:42:15 +0000 vmm ppt: Enable busmastering and BAR decoding while a device is assigned Reviewed by: corvink, markj Fixes: f44ff2aba2d6 bhyve: Treat the COMMAND register for PCI passthru devices as emulated Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D46245 (cherry picked from commit 776cd02b891ccd984963c9ec26f9748d213f0b9b) --- sys/amd64/vmm/io/ppt.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/sys/amd64/vmm/io/ppt.c b/sys/amd64/vmm/io/ppt.c index 27cbb3ac2986..7643ba0c2973 100644 --- a/sys/amd64/vmm/io/ppt.c +++ b/sys/amd64/vmm/io/ppt.c @@ -152,9 +152,13 @@ static int ppt_attach(device_t dev) { struct pptdev *ppt; + uint16_t cmd; ppt = device_get_softc(dev); + cmd = pci_read_config(dev, PCIR_COMMAND, 2); + cmd &= ~(PCIM_CMD_PORTEN | PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN); + pci_write_config(dev, PCIR_COMMAND, cmd, 2); iommu_remove_device(iommu_host_domain(), pci_get_rid(dev)); num_pptdevs++; TAILQ_INSERT_TAIL(&pptdev_list, ppt, next); @@ -177,7 +181,6 @@ ppt_detach(device_t dev) return (EBUSY); num_pptdevs--; TAILQ_REMOVE(&pptdev_list, ppt, next); - pci_disable_busmaster(dev); if (iommu_host_domain() != NULL) iommu_add_device(iommu_host_domain(), pci_get_rid(dev)); @@ -377,11 +380,28 @@ ppt_pci_reset(device_t dev) pci_power_reset(dev); } +static uint16_t +ppt_bar_enables(struct pptdev *ppt) +{ + struct pci_map *pm; + uint16_t cmd; + + cmd = 0; + for (pm = pci_first_bar(ppt->dev); pm != NULL; pm = pci_next_bar(pm)) { + if (PCI_BAR_IO(pm->pm_value)) + cmd |= PCIM_CMD_PORTEN; + if (PCI_BAR_MEM(pm->pm_value)) + cmd |= PCIM_CMD_MEMEN; + } + return (cmd); +} + int ppt_assign_device(struct vm *vm, int bus, int slot, int func) { struct pptdev *ppt; int error; + uint16_t cmd; /* Passing NULL requires the device to be unowned. */ error = ppt_find(NULL, bus, slot, func, &ppt); @@ -393,6 +413,9 @@ ppt_assign_device(struct vm *vm, int bus, int slot, int func) pci_restore_state(ppt->dev); ppt->vm = vm; iommu_add_device(vm_iommu_domain(vm), pci_get_rid(ppt->dev)); + cmd = pci_read_config(ppt->dev, PCIR_COMMAND, 2); + cmd |= PCIM_CMD_BUSMASTEREN | ppt_bar_enables(ppt); + pci_write_config(ppt->dev, PCIR_COMMAND, cmd, 2); return (0); } @@ -401,11 +424,15 @@ ppt_unassign_device(struct vm *vm, int bus, int slot, int func) { struct pptdev *ppt; int error; + uint16_t cmd; error = ppt_find(vm, bus, slot, func, &ppt); if (error) return (error); + cmd = pci_read_config(ppt->dev, PCIR_COMMAND, 2); + cmd &= ~(PCIM_CMD_PORTEN | PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN); + pci_write_config(ppt->dev, PCIR_COMMAND, cmd, 2); pci_save_state(ppt->dev); ppt_pci_reset(ppt->dev); pci_restore_state(ppt->dev);