From nobody Tue May 10 15:21:02 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 BDEEA1AE293B; Tue, 10 May 2022 15:21:02 +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 4KyMFB504Dz3rN8; Tue, 10 May 2022 15:21:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652196062; 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=BtBwCXVZ4OeLS/YivD0ZMByjo79iv/WJ+hQcHri08nk=; b=JdXuys9SVzX1i9GQnihfI+gv0bPm2FeG+KE+w8ed9SMua/AaalQAbN4vJcvRvGZKg0Vq+h 3ykfbcHyA+Ojy6yKfCnIPTxbjdGbK16OTN8HTpI1SmW16xqWL0P+zmZO2SeifeXlnmyGlk wmQxkWG50CgKFwCekITzrwZIWOrHE9yaGJb4jea95KLtSnkpMtygiLz1u/EyMGYjrKjxiN 2yl4opVp4+eNyiJWrkWy4qcYRSKq1C5XU0Io4Tf1gw84zNb7Y3brs5uNCmyEtKRFm+58H8 ACn1O/wlOmhvMgUfEiQrpcb8cb4OwIWyXFublJhqkd2xS4IYktfQLx5P5mantg== 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 8C34D27AA3; Tue, 10 May 2022 15:21:02 +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 24AFL2D6021281; Tue, 10 May 2022 15:21:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24AFL2bd021280; Tue, 10 May 2022 15:21:02 GMT (envelope-from git) Date: Tue, 10 May 2022 15:21:02 GMT Message-Id: <202205101521.24AFL2bd021280@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: 1cb8e38e4b39 - main - Code deduplication: use SID-getting functions in smmu_find(). 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: 1cb8e38e4b39cd5de0db843ec303ecfd5c6cef0e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652196062; 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=BtBwCXVZ4OeLS/YivD0ZMByjo79iv/WJ+hQcHri08nk=; b=A+eb66Jmatf1D/I7imkyZI47qli85n/Qiq+n4xk7VeS7VnOglu/rjdKqJ0qu9vxr6HpSYe 1LrbvvYpYK8rKiggv3AG6vMaH6tiqIWvpqNQWkeeplam+oVMInQrUVPKZItOd2EJL2RhEf IX9EPU5+A4DMFyP6SfBcqqoJfBBQlUFTQm8/PCprsl7+FQlH4/KQsOooq8O4sgiPSHQgZM lBOe/KpQL9hYiS7kGJhR2c6wZJ9YuDjDJ7ELs8Ww8HZ5srQhMOyyRRu2O/r5PH1/F311gn z73+82cvVv8DPxG4q0m+wep127AJxLg+WnCjBtLEB7jQbU2p3lrOacJefKuIxA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652196062; a=rsa-sha256; cv=none; b=dAd1en2AhMAP0vnPnwI+NKPIucBU8274M3J13EFVrUYVYDVvKYa24Grfmfc41ntJfeJ882 ClCuNA71Tw34hQK6OvVu/XCBMctybHvSDxGRjLxfYOKhLrnVmFqChd8TKnZOdRdVtl2dCJ +H6w5UpJnODlb6/a68AJ3tuWFxCYD8i13zc8CjlUJE5wWCJFgVE9uUBsIcsD+JTnadthLM SJYbYrEoVmWZ8kdrrr7pcyadm0g/B2CPkw7NXQIABeu4PEf/DmOQE56Laog6PFQr5ZRKxw QoiJOCeRJvx9mbOPZOYqwed/+D5d0kyBPm+ATathwf3xt50vx8/N5jbeEnsMSQ== 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=1cb8e38e4b39cd5de0db843ec303ecfd5c6cef0e commit 1cb8e38e4b39cd5de0db843ec303ecfd5c6cef0e Author: Ruslan Bukin AuthorDate: 2022-05-10 15:18:42 +0000 Commit: Ruslan Bukin CommitDate: 2022-05-10 15:20:15 +0000 Code deduplication: use SID-getting functions in smmu_find(). Sponsored by: UKRI --- sys/arm64/iommu/smmu.c | 70 +++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/sys/arm64/iommu/smmu.c b/sys/arm64/iommu/smmu.c index 20971a2d7e41..ef1f96599789 100644 --- a/sys/arm64/iommu/smmu.c +++ b/sys/arm64/iommu/smmu.c @@ -1762,7 +1762,7 @@ smmu_set_buswide(device_t dev, struct smmu_domain *domain, #ifdef DEV_ACPI static int -smmu_pci_get_sid_acpi(device_t child, u_int *sid0) +smmu_pci_get_sid_acpi(device_t child, u_int *xref0, u_int *sid0) { uint16_t rid; u_int xref; @@ -1774,8 +1774,12 @@ smmu_pci_get_sid_acpi(device_t child, u_int *sid0) rid = pci_get_rid(child); err = acpi_iort_map_pci_smmuv3(seg, rid, &xref, &sid); - if (err == 0) - *sid0 = sid; + if (err == 0) { + if (sid0) + *sid0 = sid; + if (xref0) + *xref0 = xref; + } return (err); } @@ -1783,14 +1787,26 @@ smmu_pci_get_sid_acpi(device_t child, u_int *sid0) #ifdef FDT static int -smmu_pci_get_sid_fdt(device_t child, u_int *sid0) +smmu_pci_get_sid_fdt(device_t child, u_int *xref0, u_int *sid0) { struct pci_id_ofw_iommu pi; + uint64_t base, size; + phandle_t node; + u_int xref; int err; err = pci_get_id(child, PCI_ID_OFW_IOMMU, (uintptr_t *)&pi); - if (err == 0) - *sid0 = pi.id; + if (err == 0) { + /* Our xref is memory base address. */ + node = OF_node_from_xref(pi.xref); + fdt_regsize(node, &base, &size); + xref = base; + + if (sid0) + *sid0 = pi.id; + if (xref0) + *xref0 = xref; + } return (err); } @@ -1815,9 +1831,9 @@ smmu_ctx_alloc(device_t dev, struct iommu_domain *iodom, device_t child, return (NULL); #ifdef DEV_ACPI - err = smmu_pci_get_sid_acpi(child, &sid); + err = smmu_pci_get_sid_acpi(child, NULL, &sid); #else - err = smmu_pci_get_sid_fdt(child, &sid); + err = smmu_pci_get_sid_fdt(child, NULL, &sid); #endif if (err) return (NULL); @@ -1931,45 +1947,17 @@ smmu_find(device_t dev, device_t child) { struct smmu_softc *sc; u_int xref; - int error; -#ifdef DEV_ACPI - uint16_t rid; - int seg; - u_int sid; -#else - phandle_t node; - uint64_t base, size; - struct pci_id_ofw_iommu pi; -#endif + int err; sc = device_get_softc(dev); #ifdef DEV_ACPI - rid = pci_get_rid(child); - seg = pci_get_domain(child); -#endif - - /* - * Find an xref of an IOMMU controller that serves traffic for dev. - */ -#ifdef DEV_ACPI - error = acpi_iort_map_pci_smmuv3(seg, rid, &xref, &sid); - if (error) { - /* Could not find reference to an SMMU device. */ - return (ENOENT); - } + err = smmu_pci_get_sid_acpi(child, &xref, NULL); #else - error = pci_get_id(child, PCI_ID_OFW_IOMMU, (uintptr_t *)&pi); - if (error) { - /* Could not find reference to an SMMU device. */ - return (ENOENT); - } - - /* Our xref is memory base address. */ - node = OF_node_from_xref(pi.xref); - fdt_regsize(node, &base, &size); - xref = base; + err = smmu_pci_get_sid_fdt(child, &xref, NULL); #endif + if (err) + return (ENOENT); /* Check if xref is ours. */ if (xref != sc->xref)