From nobody Wed Dec 17 06:04:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1616429673; cv=none; d=zohomail.com; s=zohoarc; b=Cn1yT+y3w1uiq3QJ7dNYjW5eAULnuBDRFwyWv/z/kFTPL1nB8++UeiciTuHKtLcUYlZqVznCx1ipMfflcgavD/SkjD5imYWciSYJ0Z1KbduMsvpy7yxXEwZf4pU/bJR2OJdoH0j3eM01hsuC/ZlLmTkXmerDXZf1DbZO0uGi1aU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616429673; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Ev3hdrkUHxOEAwpv6m5uIkJzNvP28c1RLrILOdFvG3g=; b=Z3bgkJQGIe/wgAgwwx5xt7ev8MT7knlNbj0lR2GmBtnfERgovSNCm7aPq8ceCPFtlL5+ONT0LV+UsqusgvvZvZAUXAR0FZXxYg2ZExG+gNpOKafZeRvlq/yJ89ISguTHlL8S4Jq+zMMAjyIHw7ALOIB+R4APpgBg9CLW7Utd01A= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 161642967388392.4475051842386; Mon, 22 Mar 2021 09:14:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.100340.191123 (Exim 4.92) (envelope-from ) id 1lONC9-0002TJ-Vr; Mon, 22 Mar 2021 16:14:21 +0000 Received: by outflank-mailman (output) from mailman id 100340.191123; Mon, 22 Mar 2021 16:14:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lONC9-0002TC-SP; Mon, 22 Mar 2021 16:14:21 +0000 Received: by outflank-mailman (input) for mailman id 100340; Mon, 22 Mar 2021 16:14:20 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lONC8-0002T0-OZ for xen-devel@lists.xenproject.org; Mon, 22 Mar 2021 16:14:20 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 39779ff6-3add-4511-85a4-8d84bfeba642; Mon, 22 Mar 2021 16:14:19 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2168D1042; Mon, 22 Mar 2021 09:14:19 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3986D3F719; Mon, 22 Mar 2021 09:14:18 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 39779ff6-3add-4511-85a4-8d84bfeba642 From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH v2 4/5] xen/arm: smmuv1: Add a stream map entry iterator Date: Mon, 22 Mar 2021 16:11:38 +0000 Message-Id: <662c4a4872e471df1d185002988700cd738080a0.1616428314.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Backport commit d3097e39302083d58922a3d1032d7d59a63d263d "iommu/arm-smmu: Add a stream map entry iterator" from the Linux kernel. This patch is the preparatory work to fix the stream match conflict when two devices have the same stream-id. Original commit message: iommu/arm-smmu: Add a stream map entry iterator We iterate over the SMEs associated with a master config quite a lot in various places, and are about to do so even more. Let's wrap the idiom in a handy iterator macro before the repetition gets out of hand. Tested-by: Lorenzo Pieralisi Signed-off-by: Robin Murphy Signed-off-by: Will Deacon Signed-off-by: Rahul Singh Acked-by: Stefano Stabellini Reviewed-by: Bertrand Marquis --- xen/drivers/passthrough/arm/smmu.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/a= rm/smmu.c index e1b937bd4b..2c1ea8e6ff 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -618,6 +618,8 @@ struct arm_smmu_master_cfg { s16 smendx[MAX_MASTER_STREAMIDS]; }; #define INVALID_SMENDX -1 +#define for_each_cfg_sme(cfg, i, idx) \ + for (i =3D 0; idx =3D cfg->smendx[i], i < cfg->num_streamids; ++i) =20 struct arm_smmu_master { struct device_node *of_node; @@ -1457,8 +1459,8 @@ static int arm_smmu_master_alloc_smes(struct arm_smmu= _device *smmu, int i, idx; =20 /* Allocate the SMRs on the SMMU */ - for (i =3D 0; i < cfg->num_streamids; ++i) { - if (cfg->smendx[i] !=3D INVALID_SMENDX) + for_each_cfg_sme(cfg, i, idx) { + if (idx !=3D INVALID_SMENDX) return -EEXIST; =20 /* ...except on stream indexing hardware, of course */ @@ -1482,8 +1484,8 @@ static int arm_smmu_master_alloc_smes(struct arm_smmu= _device *smmu, return 0; =20 /* It worked! Now, poke the actual hardware */ - for (i =3D 0; i < cfg->num_streamids; ++i) - arm_smmu_write_smr(smmu, cfg->smendx[i]); + for_each_cfg_sme(cfg, i, idx) + arm_smmu_write_smr(smmu, idx); =20 return 0; =20 @@ -1498,15 +1500,13 @@ err_free_smrs: static void arm_smmu_master_free_smes(struct arm_smmu_device *smmu, struct arm_smmu_master_cfg *cfg) { - int i; + int i, idx; =20 /* * We *must* clear the S2CR first, because freeing the SMR means * that it can be re-allocated immediately. */ - for (i =3D 0; i < cfg->num_streamids; ++i) { - int idx =3D cfg->smendx[i]; - + for_each_cfg_sme(cfg, i, idx) { /* An IOMMU group is torn down by the first device to be removed */ if (idx =3D=3D INVALID_SMENDX) return; @@ -1518,9 +1518,9 @@ static void arm_smmu_master_free_smes(struct arm_smmu= _device *smmu, __iowmb(); =20 /* Invalidate the SMRs before freeing back to the allocator */ - for (i =3D 0; i < cfg->num_streamids; ++i) { + for_each_cfg_sme(cfg, i, idx) { if (smmu->smrs) - arm_smmu_free_smr(smmu, cfg->smendx[i]); + arm_smmu_free_smr(smmu, idx); =20 cfg->smendx[i] =3D INVALID_SMENDX; } @@ -1529,7 +1529,7 @@ static void arm_smmu_master_free_smes(struct arm_smmu= _device *smmu, static int arm_smmu_domain_add_master(struct arm_smmu_domain *smmu_domain, struct arm_smmu_master_cfg *cfg) { - int i, ret =3D 0; + int i, idx, ret =3D 0; struct arm_smmu_device *smmu =3D smmu_domain->smmu; struct arm_smmu_s2cr *s2cr =3D smmu->s2crs; enum arm_smmu_s2cr_type type =3D S2CR_TYPE_TRANS; @@ -1540,9 +1540,7 @@ static int arm_smmu_domain_add_master(struct arm_smmu= _domain *smmu_domain, if (ret) return ret; =20 - for (i =3D 0; i < cfg->num_streamids; ++i) { - int idx =3D cfg->smendx[i]; - + for_each_cfg_sme(cfg, i, idx) { /* Devices in an IOMMU group may already be configured */ if (type =3D=3D s2cr[idx].type && cbndx =3D=3D s2cr[idx].cbndx) break; --=20 2.17.1