From nobody Thu Aug 22 18:41:18 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 4WqX8v4qRBz5TQj4; Thu, 22 Aug 2024 18:41:19 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WqX8t5nMJz4GNJ; Thu, 22 Aug 2024 18:41:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724352078; 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=vrjxvmvLK9SrPDffoCds0moqTfpnBmKlJ0vQH9C2X4M=; b=yr/cZl0ZBAvhOVJtCmEdBD7dx7b973A0SZLynM8lxCZ5Dx29a1AB2Qr5guaSCUijfUDF1c 2dXcKjSmfd1Hqj/v+Ieh/HmfU1SRT/v/hduSuic3Y08xPby3l6WRvHRq6ADdELKkAQ0bCp Jh7KYE1fNnpcQNrvqPLgFMCNEXlOY7gLmrlIY85ehVahH2GQxsz6GxicoEuLA0k11ZEmNs VFyq+7nK0tBJ5Cp7ITOwXK1ytubAbdwkNfy4EuHJM3GV08ZVRI1ZbbBvSOgiWLY0g2gufX gLeytUZGtDs2/he1/QzIzvH+fmhpCt1DKUdix+SIpV3OwWKVpSUPUz288G9wiw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724352078; a=rsa-sha256; cv=none; b=C5/FXsaE6vo77yzXtQ7nQbE8B4mOr+Pnye5UWK9CErNDzW0gMXze2J+Nea6Ph69cHQNiri pg7KZiwUSuBPbAIdwz6cymVwLAtvnbdae3JC0q+LwprANjGybuhYy70ypHos41NHboOkd5 /kmy0+ITE9HdReXX8DgpwfsA4ks/ui8tek7lX/gxFibyh71/g7TuB/tHcYn4NgdxRwMtu9 7g3Gbf9+1ckut5XyPQMgd27bz75MPmLd0/ysTAZjEpAptDFxlMzkBrM598g4Tvntrz8ce3 FII82tV+pfl6+5r2aNEkU0eYsjPqdVyU13Tpa/tlaaM9E/7z3E05hZDhdoMWeQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724352078; 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=vrjxvmvLK9SrPDffoCds0moqTfpnBmKlJ0vQH9C2X4M=; b=AmwyxuAiqxqaDHmY79aD3ZofT+TU2khsmvdWn/xM+XItUNsC7ZD8HeE54ZHNwRAaAkDPe7 jIZcBClyk13Pb59lN7bln1e80dy0zbFZm3TnqTBYKOfvRoOoHbdXp29YlV9NiEBqB8zXlt E2pIs7AvxOElbGjFvfJuvXD6bTpUqroPB03qN5I9EPIqUoim2A6BzuNvYpCoMZAWjs40NQ dFHw6ayjpOIcSZ08JNSnwHx7bl9ZUAOGk+K5jI9Lr8A8k3a7Y8zQ7fIc7U8HsjgyKQiYyj ugVFFwDhaZ7UsgilbuDEsbrr8pQP0PKNDkUlqpV1cnK29pPtD11ojqfP9nvptA== 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 4WqX8t5NdszfZy; Thu, 22 Aug 2024 18:41:18 +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 47MIfICk045604; Thu, 22 Aug 2024 18:41:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47MIfIvr045601; Thu, 22 Aug 2024 18:41:18 GMT (envelope-from git) Date: Thu, 22 Aug 2024 18:41:18 GMT Message-Id: <202408221841.47MIfIvr045601@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 776cd02b891c - main - 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/main X-Git-Reftype: branch X-Git-Commit: 776cd02b891ccd984963c9ec26f9748d213f0b9b Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=776cd02b891ccd984963c9ec26f9748d213f0b9b commit 776cd02b891ccd984963c9ec26f9748d213f0b9b Author: John Baldwin AuthorDate: 2024-08-22 18:40:48 +0000 Commit: John Baldwin CommitDate: 2024-08-22 18:40:48 +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 --- 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 3451e91d9de1..9fcfdc7cb441 100644 --- a/sys/amd64/vmm/io/ppt.c +++ b/sys/amd64/vmm/io/ppt.c @@ -151,9 +151,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); @@ -176,7 +180,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)); @@ -376,11 +379,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); @@ -392,6 +412,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); } @@ -400,11 +423,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);