From nobody Fri May 06 15:51:24 2022
X-Original-To: dev-commits-src-main@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 D2B1B1ACB1BF;
Fri, 6 May 2022 15:51:24 +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 4Kvw645YdVz3nnR;
Fri, 6 May 2022 15:51:24 +0000 (UTC)
(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
t=1651852284;
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=u8Dyu+J+zF4oB+EiFcbpuJEi3OyCSiv+1YaNjXFTjPA=;
b=NZsGByvHj/yp/l9zYMfZFbBIwCwRTDfKkLR++R8SkkJ2VEYwG68S14y6pTFnuVcoeqE3tz
Wyjxwi9C8/gAwrDncjxQ5rCpXiIVtyg01sohJUkqaWacUXwtYFMGuBLopIeAif+hXvvFaH
7DbWfs2BZDSAtuWZ1jmh+RpbW8sRjAw3W0uMuou7Uv8LkA0tCoWcnl4/zrqmPVpbc9d+0c
D4ZeIht5x/s8JFo/nL6Pf2RbKOdzktTuyX6kC7HXYJMLZqV+N0E1ubdvY9ALrbvjlXBBlO
viQsFndRpGyv37K7LFPu69ofA0rglRTK/twHE5j+ivKEl9yMAZr5ZE/FACO4yg==
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 955DB1E957;
Fri, 6 May 2022 15:51:24 +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 246FpO6O060061;
Fri, 6 May 2022 15:51:24 GMT
(envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 246FpO6o060060;
Fri, 6 May 2022 15:51:24 GMT
(envelope-from git)
Date: Fri, 6 May 2022 15:51:24 GMT
Message-Id: <202205061551.246FpO6o060060@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: 0b6bacc7874f - main - Add ofw_bus_iommu_map() that maps PCI requester ID to an IOMMU specifier based on "iommu-map" DTS property.
List-Id: Commit messages for the main branch of the src repository
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main
List-Help:
List-Post:
List-Subscribe:
List-Unsubscribe:
Sender: owner-dev-commits-src-main@freebsd.org
X-BeenThere: dev-commits-src-main@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: 0b6bacc7874f9c68ad35b06f1a7614171eb9ab10
Auto-Submitted: auto-generated
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
s=dkim; t=1651852284;
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=u8Dyu+J+zF4oB+EiFcbpuJEi3OyCSiv+1YaNjXFTjPA=;
b=ZSSQTtvErZpIm55/LDXU6vL2kaPmp1NOkPnVMh1dh808sBRgC7B2qjkG5+IfDIAxEiobh1
1aufZ7CzP9nryZ7O5LFtST582k1/VxTJ6T5jNtSankB3aZ7Yz1PH1RYGF5b31WVtLFBdSZ
2vhYMjLe4p80BaDCELLaiCIJgyayuGSw8BfoJ0UW8rz6TkHAD1us7yYUXX6EqlWo80+M7t
aXqUFD5zgCNJJtwPWm+Be2oi+tSxVv72BIR5u4VOrRoWCstEoZr9KtVjKrQtYsLnC1JWJr
fXH0SLvBaleYfeNR6M5sfxzL8agi/e39/KD4VRACtuO5lfJkW6bEd/QZOUdphw==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651852284; a=rsa-sha256; cv=none;
b=c/Q2zSSOZ737zHS4ic5urb0QL1F25JjR6qCqDhwGrhvBCYMnZ2T2GLt6Zig+Wg3WOqgvQ1
9saD8AFIynO23Z0Nkr8NUcw960RlDkABSeq2BE6KCC95lqOeZjEJXhZlal0rXFn8JLIFOi
J2kb9PTy9GsKYet7pq5SaaO17cgRFiTkZINu35b5aG6/4B/EXjA/NnwdlT0w6HVU9WEzqC
orSVqfOZI6WMfW7jN8Ozn+qLmz+B3LLZ17WcItKC7UasyA64800tXzDA4BX0AXoB78jcF7
y7lckE4uLh4F3EeIB3jf1XlxgZH80+y07MOXg2XJfDVhoSIvSB2uMbzDnJlkVA==
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=0b6bacc7874f9c68ad35b06f1a7614171eb9ab10
commit 0b6bacc7874f9c68ad35b06f1a7614171eb9ab10
Author: Ruslan Bukin
AuthorDate: 2022-05-06 15:41:11 +0000
Commit: Ruslan Bukin
CommitDate: 2022-05-06 15:48:04 +0000
Add ofw_bus_iommu_map() that maps PCI requester ID to an IOMMU
specifier based on "iommu-map" DTS property.
Sponsored by: UKRI
---
sys/dev/ofw/ofw_bus_subr.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
sys/dev/ofw/ofw_bus_subr.h | 3 ++-
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c
index ea57d1086779..408d554b3c7f 100644
--- a/sys/dev/ofw/ofw_bus_subr.c
+++ b/sys/dev/ofw/ofw_bus_subr.c
@@ -491,6 +491,50 @@ ofw_bus_msimap(phandle_t node, uint16_t pci_rid, phandle_t *msi_parent,
return (err);
}
+int
+ofw_bus_iommu_map(phandle_t node, uint16_t pci_rid, phandle_t *iommu_parent,
+ uint32_t *iommu_rid)
+{
+ pcell_t mask, iommu_base, rid_base, rid_length;
+ uint32_t masked_rid;
+ pcell_t map[4];
+ ssize_t len;
+ int err, i;
+
+ len = OF_getproplen(node, "iommu-map");
+ if (len <= 0)
+ return (ENOENT);
+ if (len > sizeof(map))
+ return (ENOMEM);
+
+ len = OF_getencprop(node, "iommu-map", map, 16);
+
+ err = ENOENT;
+ mask = 0xffffffff;
+ OF_getencprop(node, "iommu-map-mask", &mask, sizeof(mask));
+
+ masked_rid = pci_rid & mask;
+ for (i = 0; i < len; i += 4) {
+ rid_base = map[i + 0];
+ rid_length = map[i + 3];
+
+ if (masked_rid < rid_base ||
+ masked_rid >= (rid_base + rid_length))
+ continue;
+
+ iommu_base = map[i + 2];
+
+ if (iommu_parent != NULL)
+ *iommu_parent = map[i + 1];
+ if (iommu_rid != NULL)
+ *iommu_rid = masked_rid - rid_base + iommu_base;
+ err = 0;
+ break;
+ }
+
+ return (err);
+}
+
static int
ofw_bus_reg_to_rl_helper(device_t dev, phandle_t node, pcell_t acells, pcell_t scells,
struct resource_list *rl, const char *reg_source)
diff --git a/sys/dev/ofw/ofw_bus_subr.h b/sys/dev/ofw/ofw_bus_subr.h
index 45709c92c1f7..89f291f92373 100644
--- a/sys/dev/ofw/ofw_bus_subr.h
+++ b/sys/dev/ofw/ofw_bus_subr.h
@@ -92,8 +92,9 @@ int ofw_bus_lookup_imap(phandle_t, struct ofw_bus_iinfo *, void *, int,
int ofw_bus_search_intrmap(void *, int, void *, int, void *, int, void *,
void *, void *, int, phandle_t *);
-/* Routines for processing msi maps */
+/* Routines for processing msi and iommu maps. */
int ofw_bus_msimap(phandle_t, uint16_t, phandle_t *, uint32_t *);
+int ofw_bus_iommu_map(phandle_t, uint16_t, phandle_t *, uint32_t *);
/* Routines for parsing device-tree data into resource lists. */
int ofw_bus_reg_to_rl(device_t, phandle_t, pcell_t, pcell_t,