Skip to content

Commit 71b0aa1

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/arm-smmu-v3: Build the whole STE in arm_smmu_make_s2_domain_ste()
Half the code was living in arm_smmu_domain_finalise_s2(), just move it here and take the values directly from the pgtbl_ops instead of storing copies. Reviewed-by: Michael Shavit <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Reviewed-by: Mostafa Saleh <[email protected]> Tested-by: Shameer Kolothum <[email protected]> Tested-by: Nicolin Chen <[email protected]> Tested-by: Moritz Fischer <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent efe15df commit 71b0aa1

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,11 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target,
15201520
struct arm_smmu_domain *smmu_domain)
15211521
{
15221522
struct arm_smmu_s2_cfg *s2_cfg = &smmu_domain->s2_cfg;
1523+
const struct io_pgtable_cfg *pgtbl_cfg =
1524+
&io_pgtable_ops_to_pgtable(smmu_domain->pgtbl_ops)->cfg;
1525+
typeof(&pgtbl_cfg->arm_lpae_s2_cfg.vtcr) vtcr =
1526+
&pgtbl_cfg->arm_lpae_s2_cfg.vtcr;
1527+
u64 vtcr_val;
15231528

15241529
memset(target, 0, sizeof(*target));
15251530
target->data[0] = cpu_to_le64(
@@ -1532,17 +1537,25 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target,
15321537
FIELD_PREP(STRTAB_STE_1_SHCFG,
15331538
STRTAB_STE_1_SHCFG_INCOMING));
15341539

1540+
vtcr_val = FIELD_PREP(STRTAB_STE_2_VTCR_S2T0SZ, vtcr->tsz) |
1541+
FIELD_PREP(STRTAB_STE_2_VTCR_S2SL0, vtcr->sl) |
1542+
FIELD_PREP(STRTAB_STE_2_VTCR_S2IR0, vtcr->irgn) |
1543+
FIELD_PREP(STRTAB_STE_2_VTCR_S2OR0, vtcr->orgn) |
1544+
FIELD_PREP(STRTAB_STE_2_VTCR_S2SH0, vtcr->sh) |
1545+
FIELD_PREP(STRTAB_STE_2_VTCR_S2TG, vtcr->tg) |
1546+
FIELD_PREP(STRTAB_STE_2_VTCR_S2PS, vtcr->ps);
15351547
target->data[2] = cpu_to_le64(
15361548
FIELD_PREP(STRTAB_STE_2_S2VMID, s2_cfg->vmid) |
1537-
FIELD_PREP(STRTAB_STE_2_VTCR, s2_cfg->vtcr) |
1549+
FIELD_PREP(STRTAB_STE_2_VTCR, vtcr_val) |
15381550
STRTAB_STE_2_S2AA64 |
15391551
#ifdef __BIG_ENDIAN
15401552
STRTAB_STE_2_S2ENDI |
15411553
#endif
15421554
STRTAB_STE_2_S2PTW |
15431555
STRTAB_STE_2_S2R);
15441556

1545-
target->data[3] = cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK);
1557+
target->data[3] = cpu_to_le64(pgtbl_cfg->arm_lpae_s2_cfg.vttbr &
1558+
STRTAB_STE_3_S2TTB_MASK);
15461559
}
15471560

15481561
static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
@@ -2302,24 +2315,14 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain,
23022315
int vmid;
23032316
struct arm_smmu_device *smmu = smmu_domain->smmu;
23042317
struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg;
2305-
typeof(&pgtbl_cfg->arm_lpae_s2_cfg.vtcr) vtcr;
23062318

23072319
/* Reserve VMID 0 for stage-2 bypass STEs */
23082320
vmid = ida_alloc_range(&smmu->vmid_map, 1, (1 << smmu->vmid_bits) - 1,
23092321
GFP_KERNEL);
23102322
if (vmid < 0)
23112323
return vmid;
23122324

2313-
vtcr = &pgtbl_cfg->arm_lpae_s2_cfg.vtcr;
23142325
cfg->vmid = (u16)vmid;
2315-
cfg->vttbr = pgtbl_cfg->arm_lpae_s2_cfg.vttbr;
2316-
cfg->vtcr = FIELD_PREP(STRTAB_STE_2_VTCR_S2T0SZ, vtcr->tsz) |
2317-
FIELD_PREP(STRTAB_STE_2_VTCR_S2SL0, vtcr->sl) |
2318-
FIELD_PREP(STRTAB_STE_2_VTCR_S2IR0, vtcr->irgn) |
2319-
FIELD_PREP(STRTAB_STE_2_VTCR_S2OR0, vtcr->orgn) |
2320-
FIELD_PREP(STRTAB_STE_2_VTCR_S2SH0, vtcr->sh) |
2321-
FIELD_PREP(STRTAB_STE_2_VTCR_S2TG, vtcr->tg) |
2322-
FIELD_PREP(STRTAB_STE_2_VTCR_S2PS, vtcr->ps);
23232326
return 0;
23242327
}
23252328

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,6 @@ struct arm_smmu_ctx_desc_cfg {
609609

610610
struct arm_smmu_s2_cfg {
611611
u16 vmid;
612-
u64 vttbr;
613-
u64 vtcr;
614612
};
615613

616614
struct arm_smmu_strtab_cfg {

0 commit comments

Comments
 (0)