[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] xen/arm: smmuv1: Add a stream map entry iterator



commit e1d96fa2832d458ec6405b41a7202063421f5dc3
Author:     Rahul Singh <rahul.singh@xxxxxxx>
AuthorDate: Mon Mar 22 16:11:38 2021 +0000
Commit:     Julien Grall <jgrall@xxxxxxxxxx>
CommitDate: Thu Apr 1 17:12:05 2021 +0100

    xen/arm: smmuv1: Add a stream map entry iterator
    
    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 <lorenzo.pieralisi@xxxxxxx>
        Signed-off-by: Robin Murphy <robin.murphy@xxxxxxx>
        Signed-off-by: Will Deacon <will.deacon@xxxxxxx>
    
    Signed-off-by: Rahul Singh <rahul.singh@xxxxxxx>
    Acked-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>
    Acked-by: Julien Grall <jgrall@xxxxxxxxxx>
---
 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/arm/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 = 0; idx = cfg->smendx[i], i < cfg->num_streamids; ++i)
 
 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;
 
        /* Allocate the SMRs on the SMMU */
-       for (i = 0; i < cfg->num_streamids; ++i) {
-               if (cfg->smendx[i] != INVALID_SMENDX)
+       for_each_cfg_sme(cfg, i, idx) {
+               if (idx != INVALID_SMENDX)
                        return -EEXIST;
 
                /* ...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;
 
        /* It worked! Now, poke the actual hardware */
-       for (i = 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);
 
        return 0;
 
@@ -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;
 
        /*
         * We *must* clear the S2CR first, because freeing the SMR means
         * that it can be re-allocated immediately.
         */
-       for (i = 0; i < cfg->num_streamids; ++i) {
-               int idx = 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 == INVALID_SMENDX)
                        return;
@@ -1518,9 +1518,9 @@ static void arm_smmu_master_free_smes(struct 
arm_smmu_device *smmu,
        __iowmb();
 
        /* Invalidate the SMRs before freeing back to the allocator */
-       for (i = 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);
 
                cfg->smendx[i] = 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 = 0;
+       int i, idx, ret = 0;
        struct arm_smmu_device *smmu = smmu_domain->smmu;
        struct arm_smmu_s2cr *s2cr = smmu->s2crs;
        enum arm_smmu_s2cr_type type = S2CR_TYPE_TRANS;
@@ -1540,9 +1540,7 @@ static int arm_smmu_domain_add_master(struct 
arm_smmu_domain *smmu_domain,
        if (ret)
                return ret;
 
-       for (i = 0; i < cfg->num_streamids; ++i) {
-               int idx = cfg->smendx[i];
-
+       for_each_cfg_sme(cfg, i, idx) {
                /* Devices in an IOMMU group may already be configured */
                if (type == s2cr[idx].type && cbndx == s2cr[idx].cbndx)
                        break;
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.