From nobody Sat May 07 09:21:50 2022 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 230341AB98A7; Sat, 7 May 2022 09:21:51 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KwMQ70VDsz4fdS; Sat, 7 May 2022 09:21:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651915311; 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=4dmixC3DvWrx5r8lC9yYuH3ub01aVJX5hfotIW3ctgw=; b=AcTJx8lkd4ZADZREB6f9L9qZMAdGR0/QJKr4/nLvTAyKHtGe7p68dz9WNXe+M074imnIs0 d5KqZFW42i6WDlDkAUUWsVZWXFOcTPKyZnxEJrO6TUJJ3/Um72ThJeofIChQxVB7hnXfRW 0jrrU/SJ/EpZNatNmHfqK4XqDHuJ4uTNA98QoydY6tWGNB/1sXdU9q38VF19iocNTwIf+4 gsy6IF+9Hb4BxEnca+29tFysHDytyQ8tEPAEWLVsqd+dpknvystKwoDlo0zBfJyHYxu0rN nlCLjfHDTnSzowiWUe9A6XiAxIvZfRdXA9PH/d+7iEITlNcopgx5v+7PqYB1yw== 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 E4C905D29; Sat, 7 May 2022 09:21:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2479LoW4085152; Sat, 7 May 2022 09:21:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2479LoAB085136; Sat, 7 May 2022 09:21:50 GMT (envelope-from git) Date: Sat, 7 May 2022 09:21:50 GMT Message-Id: <202205070921.2479LoAB085136@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ruslan Bukin Subject: git: b7672a70256b - main - Add OFW_IOMMU id type for pci_get_id() so we can ask parent IOMMU controller to map PCI RID to an IOMMU specifier. 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: br X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b7672a70256b9a0d21a8f8d2c8a43d00700b95a7 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651915311; 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=4dmixC3DvWrx5r8lC9yYuH3ub01aVJX5hfotIW3ctgw=; b=B9nU5HmyVnF7HrOEqXsGpWBEpePo9iCcumUmzAZApamQfSHIY+jkJOMcm5eGAkwK285hFW L8I7MYI5wujk7OmJPS5fHJxJZ74AV7Od4Zsmltz63pB0hmUpcUQ+LbjjXArtQf6I2jArsa ZrSqR06p31fBerBCyv3D0lHo7w7yBFUFwIc6/s28Y2+StIOLWufTLTGWo5FkdS7uicnAkm HnTE2Xzd4+O/s2PoLUpRQkRve4Mh7WSk1WczvINP8983blYJDO1Su+8T0MI838EaUg0OXV zDnmHM2Vt9FxaTo2IXsb90/FEOdVxFravHNrUaT+sMpYv6Z0+vJr0Zub6Bq6TA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651915311; a=rsa-sha256; cv=none; b=jTZkjGRdRr94baQavoWNl2L/hCJfV7h1WicH/+5TCQ8suG2xXu3SrZfDVvuzMXERzLoSfa dviJ8OGeZCiU8Rr0eAguG82c0dckCADFqH0Shp1c9SumX5Ubdji1lR8gCNtdHkKgncszJq 3QK2OiLxkxrEtMnWBheJ6Aqe9wmtcBFfxDvKR9mLSPw+h3ZD2g+bdJX9562eLfFcQN6qJ4 +yI/gLnv9VFkugKRZY3QzBzkBqR7B5FYecUXUf2o/gvm1gAMGVTe2yfgQ3elHBZXksWzQr MytCUyBUS5hhH7yhh5sUsAm5x8WnbbbV/w+JLQANUKjNN19qCbdCloCnXEkvFw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by br: URL: https://cgit.FreeBSD.org/src/commit/?id=b7672a70256b9a0d21a8f8d2c8a43d00700b95a7 commit b7672a70256b9a0d21a8f8d2c8a43d00700b95a7 Author: Ruslan Bukin AuthorDate: 2022-05-07 09:17:43 +0000 Commit: Ruslan Bukin CommitDate: 2022-05-07 09:21:09 +0000 Add OFW_IOMMU id type for pci_get_id() so we can ask parent IOMMU controller to map PCI RID to an IOMMU specifier. Sponsored by: UKRI Discussed with: jhb Differential Revision: https://reviews.freebsd.org/D35129 --- sys/dev/pci/pci_host_generic_fdt.c | 27 +++++++++++++++++++++++++++ sys/dev/pci/pci_if.m | 1 + sys/dev/pci/pcib_support.c | 3 +++ sys/dev/pci/pcivar.h | 5 +++++ 4 files changed, 36 insertions(+) diff --git a/sys/dev/pci/pci_host_generic_fdt.c b/sys/dev/pci/pci_host_generic_fdt.c index ef0851afb76c..57ce03d0b94d 100644 --- a/sys/dev/pci/pci_host_generic_fdt.c +++ b/sys/dev/pci/pci_host_generic_fdt.c @@ -373,6 +373,30 @@ generic_pcie_fdt_release_msix(device_t pci, device_t child, int irq) #endif } +static int +generic_pcie_get_iommu(device_t pci, device_t child, uintptr_t *id) +{ + struct pci_id_ofw_iommu *iommu; + uint32_t iommu_rid; + uint32_t iommu_xref; + uint16_t pci_rid; + phandle_t node; + int err; + + node = ofw_bus_get_node(pci); + pci_rid = pci_get_rid(child); + + iommu = (struct pci_id_ofw_iommu *)id; + + err = ofw_bus_iommu_map(node, pci_rid, &iommu_xref, &iommu_rid); + if (err == 0) { + iommu->id = iommu_rid; + iommu->xref = iommu_xref; + } + + return (err); +} + int generic_pcie_get_id(device_t pci, device_t child, enum pci_id_type type, uintptr_t *id) @@ -382,6 +406,9 @@ generic_pcie_get_id(device_t pci, device_t child, enum pci_id_type type, uint32_t rid; uint16_t pci_rid; + if (type == PCI_ID_OFW_IOMMU) + return (generic_pcie_get_iommu(pci, child, id)); + if (type != PCI_ID_MSI) return (pcib_get_id(pci, child, type, id)); diff --git a/sys/dev/pci/pci_if.m b/sys/dev/pci/pci_if.m index a7a2af7bb4a9..36e2172172a8 100644 --- a/sys/dev/pci/pci_if.m +++ b/sys/dev/pci/pci_if.m @@ -59,6 +59,7 @@ HEADER { enum pci_id_type { PCI_ID_RID, PCI_ID_MSI, + PCI_ID_OFW_IOMMU, }; enum pci_feature { diff --git a/sys/dev/pci/pcib_support.c b/sys/dev/pci/pcib_support.c index dcf8275e566d..a0563c58a99b 100644 --- a/sys/dev/pci/pcib_support.c +++ b/sys/dev/pci/pcib_support.c @@ -59,6 +59,9 @@ pcib_get_id(device_t pcib, device_t dev, enum pci_id_type type, uintptr_t *id) { uint8_t bus, slot, func; + if (type == PCI_ID_OFW_IOMMU) + return (PCI_GET_ID(device_get_parent(pcib), dev, type, id)); + if (type != PCI_ID_RID) return (ENXIO); diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h index 74aa704635f7..2454b05b9acc 100644 --- a/sys/dev/pci/pcivar.h +++ b/sys/dev/pci/pcivar.h @@ -127,6 +127,11 @@ struct pcicfg_msix { struct resource *msix_pba_res; /* Resource containing PBA. */ }; +struct pci_id_ofw_iommu { + uint32_t id; + uint32_t xref; +}; + /* Interesting values for HyperTransport */ struct pcicfg_ht { uint8_t ht_slave; /* Non-zero if device is an HT slave. */