Skip to content

Commit 1f85888

Browse files
shavitmichaelwilldeacon
authored andcommitted
iommu/arm-smmu-v3: Replace s1_cfg with cdtab_cfg
Remove struct arm_smmu_s1_cfg. This is really just a CD table with a bit of extra information. Move other attributes of the CD table that were held there into the existing CD table structure, struct arm_smmu_ctx_desc_cfg, and replace all usages of arm_smmu_s1_cfg with arm_smmu_ctx_desc_cfg. For clarity, use the name "cd_table" for the variables pointing to arm_smmu_ctx_desc_cfg in the new code instead of cdcfg. A later patch will make this fully consistent. Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Michael Shavit <mshavit@google.com> Tested-by: Nicolin Chen <nicolinc@nvidia.com> Link: https://lore.kernel.org/r/20230915211705.v8.2.I1ef1ed19d7786c8176a0d05820c869e650c8d68f@changeid Signed-off-by: Will Deacon <will@kernel.org>
1 parent 987a878 commit 1f85888

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,9 +1033,9 @@ static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_domain *smmu_domain,
10331033
unsigned int idx;
10341034
struct arm_smmu_l1_ctx_desc *l1_desc;
10351035
struct arm_smmu_device *smmu = smmu_domain->smmu;
1036-
struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->s1_cfg.cdcfg;
1036+
struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
10371037

1038-
if (smmu_domain->s1_cfg.s1fmt == STRTAB_STE_0_S1FMT_LINEAR)
1038+
if (cdcfg->s1fmt == STRTAB_STE_0_S1FMT_LINEAR)
10391039
return cdcfg->cdtab + ssid * CTXDESC_CD_DWORDS;
10401040

10411041
idx = ssid >> CTXDESC_SPLIT;
@@ -1071,7 +1071,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid,
10711071
bool cd_live;
10721072
__le64 *cdptr;
10731073

1074-
if (WARN_ON(ssid >= (1 << smmu_domain->s1_cfg.s1cdmax)))
1074+
if (WARN_ON(ssid >= (1 << smmu_domain->cd_table.s1cdmax)))
10751075
return -E2BIG;
10761076

10771077
cdptr = arm_smmu_get_cd_ptr(smmu_domain, ssid);
@@ -1138,19 +1138,18 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain)
11381138
size_t l1size;
11391139
size_t max_contexts;
11401140
struct arm_smmu_device *smmu = smmu_domain->smmu;
1141-
struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg;
1142-
struct arm_smmu_ctx_desc_cfg *cdcfg = &cfg->cdcfg;
1141+
struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
11431142

1144-
max_contexts = 1 << cfg->s1cdmax;
1143+
max_contexts = 1 << cdcfg->s1cdmax;
11451144

11461145
if (!(smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB) ||
11471146
max_contexts <= CTXDESC_L2_ENTRIES) {
1148-
cfg->s1fmt = STRTAB_STE_0_S1FMT_LINEAR;
1147+
cdcfg->s1fmt = STRTAB_STE_0_S1FMT_LINEAR;
11491148
cdcfg->num_l1_ents = max_contexts;
11501149

11511150
l1size = max_contexts * (CTXDESC_CD_DWORDS << 3);
11521151
} else {
1153-
cfg->s1fmt = STRTAB_STE_0_S1FMT_64K_L2;
1152+
cdcfg->s1fmt = STRTAB_STE_0_S1FMT_64K_L2;
11541153
cdcfg->num_l1_ents = DIV_ROUND_UP(max_contexts,
11551154
CTXDESC_L2_ENTRIES);
11561155

@@ -1186,7 +1185,7 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_domain *smmu_domain)
11861185
int i;
11871186
size_t size, l1size;
11881187
struct arm_smmu_device *smmu = smmu_domain->smmu;
1189-
struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->s1_cfg.cdcfg;
1188+
struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
11901189

11911190
if (cdcfg->l1_desc) {
11921191
size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3);
@@ -1276,7 +1275,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
12761275
u64 val = le64_to_cpu(dst[0]);
12771276
bool ste_live = false;
12781277
struct arm_smmu_device *smmu = NULL;
1279-
struct arm_smmu_s1_cfg *s1_cfg = NULL;
1278+
struct arm_smmu_ctx_desc_cfg *cd_table = NULL;
12801279
struct arm_smmu_s2_cfg *s2_cfg = NULL;
12811280
struct arm_smmu_domain *smmu_domain = NULL;
12821281
struct arm_smmu_cmdq_ent prefetch_cmd = {
@@ -1294,7 +1293,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
12941293
if (smmu_domain) {
12951294
switch (smmu_domain->stage) {
12961295
case ARM_SMMU_DOMAIN_S1:
1297-
s1_cfg = &smmu_domain->s1_cfg;
1296+
cd_table = &smmu_domain->cd_table;
12981297
break;
12991298
case ARM_SMMU_DOMAIN_S2:
13001299
case ARM_SMMU_DOMAIN_NESTED:
@@ -1325,7 +1324,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
13251324
val = STRTAB_STE_0_V;
13261325

13271326
/* Bypass/fault */
1328-
if (!smmu_domain || !(s1_cfg || s2_cfg)) {
1327+
if (!smmu_domain || !(cd_table || s2_cfg)) {
13291328
if (!smmu_domain && disable_bypass)
13301329
val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT);
13311330
else
@@ -1344,7 +1343,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
13441343
return;
13451344
}
13461345

1347-
if (s1_cfg) {
1346+
if (cd_table) {
13481347
u64 strw = smmu->features & ARM_SMMU_FEAT_E2H ?
13491348
STRTAB_STE_1_STRW_EL2 : STRTAB_STE_1_STRW_NSEL1;
13501349

@@ -1360,10 +1359,10 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
13601359
!master->stall_enabled)
13611360
dst[1] |= cpu_to_le64(STRTAB_STE_1_S1STALLD);
13621361

1363-
val |= (s1_cfg->cdcfg.cdtab_dma & STRTAB_STE_0_S1CTXPTR_MASK) |
1362+
val |= (cd_table->cdtab_dma & STRTAB_STE_0_S1CTXPTR_MASK) |
13641363
FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS) |
1365-
FIELD_PREP(STRTAB_STE_0_S1CDMAX, s1_cfg->s1cdmax) |
1366-
FIELD_PREP(STRTAB_STE_0_S1FMT, s1_cfg->s1fmt);
1364+
FIELD_PREP(STRTAB_STE_0_S1CDMAX, cd_table->s1cdmax) |
1365+
FIELD_PREP(STRTAB_STE_0_S1FMT, cd_table->s1fmt);
13671366
}
13681367

13691368
if (s2_cfg) {
@@ -2069,11 +2068,11 @@ static void arm_smmu_domain_free(struct iommu_domain *domain)
20692068

20702069
/* Free the CD and ASID, if we allocated them */
20712070
if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) {
2072-
struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg;
2071+
struct arm_smmu_ctx_desc_cfg *cd_table = &smmu_domain->cd_table;
20732072

20742073
/* Prevent SVA from touching the CD while we're freeing it */
20752074
mutex_lock(&arm_smmu_asid_lock);
2076-
if (cfg->cdcfg.cdtab)
2075+
if (cd_table->cdtab)
20772076
arm_smmu_free_cd_tables(smmu_domain);
20782077
arm_smmu_free_asid(&smmu_domain->cd);
20792078
mutex_unlock(&arm_smmu_asid_lock);
@@ -2093,7 +2092,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
20932092
int ret;
20942093
u32 asid;
20952094
struct arm_smmu_device *smmu = smmu_domain->smmu;
2096-
struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg;
2095+
struct arm_smmu_ctx_desc_cfg *cd_table = &smmu_domain->cd_table;
20972096
struct arm_smmu_ctx_desc *cd = &smmu_domain->cd;
20982097
typeof(&pgtbl_cfg->arm_lpae_s1_cfg.tcr) tcr = &pgtbl_cfg->arm_lpae_s1_cfg.tcr;
20992098

@@ -2106,7 +2105,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
21062105
if (ret)
21072106
goto out_unlock;
21082107

2109-
cfg->s1cdmax = master->ssid_bits;
2108+
cd_table->s1cdmax = master->ssid_bits;
21102109

21112110
smmu_domain->stall_enabled = master->stall_enabled;
21122111

@@ -2446,7 +2445,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
24462445
ret = -EINVAL;
24472446
goto out_unlock;
24482447
} else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 &&
2449-
master->ssid_bits != smmu_domain->s1_cfg.s1cdmax) {
2448+
master->ssid_bits != smmu_domain->cd_table.s1cdmax) {
24502449
ret = -EINVAL;
24512450
goto out_unlock;
24522451
} else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 &&

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,8 @@ struct arm_smmu_ctx_desc_cfg {
595595
dma_addr_t cdtab_dma;
596596
struct arm_smmu_l1_ctx_desc *l1_desc;
597597
unsigned int num_l1_ents;
598-
};
599-
600-
struct arm_smmu_s1_cfg {
601-
struct arm_smmu_ctx_desc_cfg cdcfg;
602598
u8 s1fmt;
599+
/* log2 of the maximum number of CDs supported by this table */
603600
u8 s1cdmax;
604601
};
605602

@@ -725,7 +722,7 @@ struct arm_smmu_domain {
725722
union {
726723
struct {
727724
struct arm_smmu_ctx_desc cd;
728-
struct arm_smmu_s1_cfg s1_cfg;
725+
struct arm_smmu_ctx_desc_cfg cd_table;
729726
};
730727
struct arm_smmu_s2_cfg s2_cfg;
731728
};

0 commit comments

Comments
 (0)