Skip to content

Commit 2465170

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu/arm-smmu: Refactor master_cfg/fwspec usage
In preparation for restructuring iommu_fwspec, refactor the way we access the arm_smmu_master_cfg private data to be less dependent on the current layout. Signed-off-by: Robin Murphy <[email protected]> Signed-off-by: Joerg Roedel <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b7a9662 commit 2465170

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

drivers/iommu/arm-smmu.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,10 @@ struct arm_smmu_master_cfg {
9898
s16 smendx[];
9999
};
100100
#define INVALID_SMENDX -1
101-
#define __fwspec_cfg(fw) ((struct arm_smmu_master_cfg *)fw->iommu_priv)
102-
#define fwspec_smmu(fw) (__fwspec_cfg(fw)->smmu)
103-
#define fwspec_smendx(fw, i) \
104-
(i >= fw->num_ids ? INVALID_SMENDX : __fwspec_cfg(fw)->smendx[i])
105-
#define for_each_cfg_sme(fw, i, idx) \
106-
for (i = 0; idx = fwspec_smendx(fw, i), i < fw->num_ids; ++i)
101+
#define cfg_smendx(cfg, fw, i) \
102+
(i >= fw->num_ids ? INVALID_SMENDX : cfg->smendx[i])
103+
#define for_each_cfg_sme(cfg, fw, i, idx) \
104+
for (i = 0; idx = cfg_smendx(cfg, fw, i), i < fw->num_ids; ++i)
107105

108106
static bool using_legacy_binding, using_generic_binding;
109107

@@ -1069,7 +1067,7 @@ static int arm_smmu_master_alloc_smes(struct device *dev)
10691067

10701068
mutex_lock(&smmu->stream_map_mutex);
10711069
/* Figure out a viable stream map entry allocation */
1072-
for_each_cfg_sme(fwspec, i, idx) {
1070+
for_each_cfg_sme(cfg, fwspec, i, idx) {
10731071
u16 sid = FIELD_GET(ARM_SMMU_SMR_ID, fwspec->ids[i]);
10741072
u16 mask = FIELD_GET(ARM_SMMU_SMR_MASK, fwspec->ids[i]);
10751073

@@ -1100,7 +1098,7 @@ static int arm_smmu_master_alloc_smes(struct device *dev)
11001098
iommu_group_put(group);
11011099

11021100
/* It worked! Now, poke the actual hardware */
1103-
for_each_cfg_sme(fwspec, i, idx) {
1101+
for_each_cfg_sme(cfg, fwspec, i, idx) {
11041102
arm_smmu_write_sme(smmu, idx);
11051103
smmu->s2crs[idx].group = group;
11061104
}
@@ -1117,14 +1115,14 @@ static int arm_smmu_master_alloc_smes(struct device *dev)
11171115
return ret;
11181116
}
11191117

1120-
static void arm_smmu_master_free_smes(struct iommu_fwspec *fwspec)
1118+
static void arm_smmu_master_free_smes(struct arm_smmu_master_cfg *cfg,
1119+
struct iommu_fwspec *fwspec)
11211120
{
1122-
struct arm_smmu_device *smmu = fwspec_smmu(fwspec);
1123-
struct arm_smmu_master_cfg *cfg = fwspec->iommu_priv;
1121+
struct arm_smmu_device *smmu = cfg->smmu;
11241122
int i, idx;
11251123

11261124
mutex_lock(&smmu->stream_map_mutex);
1127-
for_each_cfg_sme(fwspec, i, idx) {
1125+
for_each_cfg_sme(cfg, fwspec, i, idx) {
11281126
if (arm_smmu_free_sme(smmu, idx))
11291127
arm_smmu_write_sme(smmu, idx);
11301128
cfg->smendx[i] = INVALID_SMENDX;
@@ -1133,6 +1131,7 @@ static void arm_smmu_master_free_smes(struct iommu_fwspec *fwspec)
11331131
}
11341132

11351133
static int arm_smmu_domain_add_master(struct arm_smmu_domain *smmu_domain,
1134+
struct arm_smmu_master_cfg *cfg,
11361135
struct iommu_fwspec *fwspec)
11371136
{
11381137
struct arm_smmu_device *smmu = smmu_domain->smmu;
@@ -1146,7 +1145,7 @@ static int arm_smmu_domain_add_master(struct arm_smmu_domain *smmu_domain,
11461145
else
11471146
type = S2CR_TYPE_TRANS;
11481147

1149-
for_each_cfg_sme(fwspec, i, idx) {
1148+
for_each_cfg_sme(cfg, fwspec, i, idx) {
11501149
if (type == s2cr[idx].type && cbndx == s2cr[idx].cbndx)
11511150
continue;
11521151

@@ -1162,8 +1161,9 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
11621161
{
11631162
int ret;
11641163
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
1165-
struct arm_smmu_device *smmu;
11661164
struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
1165+
struct arm_smmu_master_cfg *cfg;
1166+
struct arm_smmu_device *smmu;
11671167

11681168
if (!fwspec || fwspec->ops != &arm_smmu_ops) {
11691169
dev_err(dev, "cannot attach to SMMU, is it on the same bus?\n");
@@ -1177,10 +1177,11 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
11771177
* domains, just say no (but more politely than by dereferencing NULL).
11781178
* This should be at least a WARN_ON once that's sorted.
11791179
*/
1180-
if (!fwspec->iommu_priv)
1180+
cfg = fwspec->iommu_priv;
1181+
if (!cfg)
11811182
return -ENODEV;
11821183

1183-
smmu = fwspec_smmu(fwspec);
1184+
smmu = cfg->smmu;
11841185

11851186
ret = arm_smmu_rpm_get(smmu);
11861187
if (ret < 0)
@@ -1204,7 +1205,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
12041205
}
12051206

12061207
/* Looks ok, so add the device to the domain */
1207-
ret = arm_smmu_domain_add_master(smmu_domain, fwspec);
1208+
ret = arm_smmu_domain_add_master(smmu_domain, cfg, fwspec);
12081209

12091210
/*
12101211
* Setup an autosuspend delay to avoid bouncing runpm state.
@@ -1475,7 +1476,7 @@ static void arm_smmu_remove_device(struct device *dev)
14751476
return;
14761477

14771478
iommu_device_unlink(&smmu->iommu, dev);
1478-
arm_smmu_master_free_smes(fwspec);
1479+
arm_smmu_master_free_smes(cfg, fwspec);
14791480

14801481
arm_smmu_rpm_put(smmu);
14811482

@@ -1487,11 +1488,12 @@ static void arm_smmu_remove_device(struct device *dev)
14871488
static struct iommu_group *arm_smmu_device_group(struct device *dev)
14881489
{
14891490
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
1490-
struct arm_smmu_device *smmu = fwspec_smmu(fwspec);
1491+
struct arm_smmu_master_cfg *cfg = fwspec->iommu_priv;
1492+
struct arm_smmu_device *smmu = cfg->smmu;
14911493
struct iommu_group *group = NULL;
14921494
int i, idx;
14931495

1494-
for_each_cfg_sme(fwspec, i, idx) {
1496+
for_each_cfg_sme(cfg, fwspec, i, idx) {
14951497
if (group && smmu->s2crs[idx].group &&
14961498
group != smmu->s2crs[idx].group)
14971499
return ERR_PTR(-EINVAL);

0 commit comments

Comments
 (0)