@@ -98,12 +98,10 @@ struct arm_smmu_master_cfg {
98
98
s16 smendx [];
99
99
};
100
100
#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)
107
105
108
106
static bool using_legacy_binding , using_generic_binding ;
109
107
@@ -1069,7 +1067,7 @@ static int arm_smmu_master_alloc_smes(struct device *dev)
1069
1067
1070
1068
mutex_lock (& smmu -> stream_map_mutex );
1071
1069
/* 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 ) {
1073
1071
u16 sid = FIELD_GET (ARM_SMMU_SMR_ID , fwspec -> ids [i ]);
1074
1072
u16 mask = FIELD_GET (ARM_SMMU_SMR_MASK , fwspec -> ids [i ]);
1075
1073
@@ -1100,7 +1098,7 @@ static int arm_smmu_master_alloc_smes(struct device *dev)
1100
1098
iommu_group_put (group );
1101
1099
1102
1100
/* It worked! Now, poke the actual hardware */
1103
- for_each_cfg_sme (fwspec , i , idx ) {
1101
+ for_each_cfg_sme (cfg , fwspec , i , idx ) {
1104
1102
arm_smmu_write_sme (smmu , idx );
1105
1103
smmu -> s2crs [idx ].group = group ;
1106
1104
}
@@ -1117,14 +1115,14 @@ static int arm_smmu_master_alloc_smes(struct device *dev)
1117
1115
return ret ;
1118
1116
}
1119
1117
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 )
1121
1120
{
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 ;
1124
1122
int i , idx ;
1125
1123
1126
1124
mutex_lock (& smmu -> stream_map_mutex );
1127
- for_each_cfg_sme (fwspec , i , idx ) {
1125
+ for_each_cfg_sme (cfg , fwspec , i , idx ) {
1128
1126
if (arm_smmu_free_sme (smmu , idx ))
1129
1127
arm_smmu_write_sme (smmu , idx );
1130
1128
cfg -> smendx [i ] = INVALID_SMENDX ;
@@ -1133,6 +1131,7 @@ static void arm_smmu_master_free_smes(struct iommu_fwspec *fwspec)
1133
1131
}
1134
1132
1135
1133
static int arm_smmu_domain_add_master (struct arm_smmu_domain * smmu_domain ,
1134
+ struct arm_smmu_master_cfg * cfg ,
1136
1135
struct iommu_fwspec * fwspec )
1137
1136
{
1138
1137
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,
1146
1145
else
1147
1146
type = S2CR_TYPE_TRANS ;
1148
1147
1149
- for_each_cfg_sme (fwspec , i , idx ) {
1148
+ for_each_cfg_sme (cfg , fwspec , i , idx ) {
1150
1149
if (type == s2cr [idx ].type && cbndx == s2cr [idx ].cbndx )
1151
1150
continue ;
1152
1151
@@ -1162,8 +1161,9 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
1162
1161
{
1163
1162
int ret ;
1164
1163
struct iommu_fwspec * fwspec = dev_iommu_fwspec_get (dev );
1165
- struct arm_smmu_device * smmu ;
1166
1164
struct arm_smmu_domain * smmu_domain = to_smmu_domain (domain );
1165
+ struct arm_smmu_master_cfg * cfg ;
1166
+ struct arm_smmu_device * smmu ;
1167
1167
1168
1168
if (!fwspec || fwspec -> ops != & arm_smmu_ops ) {
1169
1169
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)
1177
1177
* domains, just say no (but more politely than by dereferencing NULL).
1178
1178
* This should be at least a WARN_ON once that's sorted.
1179
1179
*/
1180
- if (!fwspec -> iommu_priv )
1180
+ cfg = fwspec -> iommu_priv ;
1181
+ if (!cfg )
1181
1182
return - ENODEV ;
1182
1183
1183
- smmu = fwspec_smmu ( fwspec ) ;
1184
+ smmu = cfg -> smmu ;
1184
1185
1185
1186
ret = arm_smmu_rpm_get (smmu );
1186
1187
if (ret < 0 )
@@ -1204,7 +1205,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
1204
1205
}
1205
1206
1206
1207
/* 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 );
1208
1209
1209
1210
/*
1210
1211
* Setup an autosuspend delay to avoid bouncing runpm state.
@@ -1475,7 +1476,7 @@ static void arm_smmu_remove_device(struct device *dev)
1475
1476
return ;
1476
1477
1477
1478
iommu_device_unlink (& smmu -> iommu , dev );
1478
- arm_smmu_master_free_smes (fwspec );
1479
+ arm_smmu_master_free_smes (cfg , fwspec );
1479
1480
1480
1481
arm_smmu_rpm_put (smmu );
1481
1482
@@ -1487,11 +1488,12 @@ static void arm_smmu_remove_device(struct device *dev)
1487
1488
static struct iommu_group * arm_smmu_device_group (struct device * dev )
1488
1489
{
1489
1490
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 ;
1491
1493
struct iommu_group * group = NULL ;
1492
1494
int i , idx ;
1493
1495
1494
- for_each_cfg_sme (fwspec , i , idx ) {
1496
+ for_each_cfg_sme (cfg , fwspec , i , idx ) {
1495
1497
if (group && smmu -> s2crs [idx ].group &&
1496
1498
group != smmu -> s2crs [idx ].group )
1497
1499
return ERR_PTR (- EINVAL );
0 commit comments