Skip to content

Commit abb4f9d

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/arm-smmu-v3: Add types for each level of the 2 level stream table
Add types struct arm_smmu_strtab_l1 and l2 to represent the HW layout of the descriptors, and use them in most places, following patches will get the remaing places. The size of the l1 and l2 HW allocations are sizeof(struct arm_smmu_strtab_l1/2). This provides some more clarity than having raw __le64 *'s and sizes computed via macros. Remove STRTAB_L1_DESC_DWORDS. Tested-by: Nicolin Chen <[email protected]> Reviewed-by: Nicolin Chen <[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 ce41041 commit abb4f9d

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,15 +1496,16 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master)
14961496
}
14971497

14981498
/* Stream table manipulation functions */
1499-
static void arm_smmu_write_strtab_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma)
1499+
static void arm_smmu_write_strtab_l1_desc(struct arm_smmu_strtab_l1 *dst,
1500+
dma_addr_t l2ptr_dma)
15001501
{
15011502
u64 val = 0;
15021503

15031504
val |= FIELD_PREP(STRTAB_L1_DESC_SPAN, STRTAB_SPLIT + 1);
15041505
val |= l2ptr_dma & STRTAB_L1_DESC_L2PTR_MASK;
15051506

15061507
/* The HW has 64 bit atomicity with stores to the L2 STE table */
1507-
WRITE_ONCE(*dst, cpu_to_le64(val));
1508+
WRITE_ONCE(dst->l2ptr, cpu_to_le64(val));
15081509
}
15091510

15101511
struct arm_smmu_ste_writer {
@@ -1709,27 +1710,27 @@ static void arm_smmu_init_initial_stes(struct arm_smmu_ste *strtab,
17091710

17101711
static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid)
17111712
{
1712-
size_t size;
17131713
dma_addr_t l2ptr_dma;
17141714
struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg;
17151715
struct arm_smmu_strtab_l1_desc *desc;
1716+
__le64 *dst;
17161717

17171718
desc = &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)];
17181719
if (desc->l2ptr)
17191720
return 0;
17201721

1721-
size = STRTAB_NUM_L2_STES * sizeof(struct arm_smmu_ste);
1722-
desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &l2ptr_dma,
1723-
GFP_KERNEL);
1722+
desc->l2ptr = dmam_alloc_coherent(smmu->dev, sizeof(*desc->l2ptr),
1723+
&l2ptr_dma, GFP_KERNEL);
17241724
if (!desc->l2ptr) {
17251725
dev_err(smmu->dev,
17261726
"failed to allocate l2 stream table for SID %u\n",
17271727
sid);
17281728
return -ENOMEM;
17291729
}
17301730

1731-
arm_smmu_init_initial_stes(desc->l2ptr, STRTAB_NUM_L2_STES);
1732-
arm_smmu_write_strtab_l1_desc(&cfg->strtab[arm_smmu_strtab_l1_idx(sid)],
1731+
arm_smmu_init_initial_stes(desc->l2ptr->stes, STRTAB_NUM_L2_STES);
1732+
dst = &cfg->strtab[arm_smmu_strtab_l1_idx(sid)];
1733+
arm_smmu_write_strtab_l1_desc((struct arm_smmu_strtab_l1 *)dst,
17331734
l2ptr_dma);
17341735
return 0;
17351736
}
@@ -2487,7 +2488,7 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid)
24872488
if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) {
24882489
/* Two-level walk */
24892490
return &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)]
2490-
.l2ptr[arm_smmu_strtab_l2_idx(sid)];
2491+
.l2ptr->stes[arm_smmu_strtab_l2_idx(sid)];
24912492
} else {
24922493
/* Simple linear lookup */
24932494
return (struct arm_smmu_ste *)&cfg
@@ -3643,7 +3644,7 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu)
36433644
ilog2(cfg->num_l1_ents * STRTAB_NUM_L2_STES),
36443645
smmu->sid_bits);
36453646

3646-
l1size = cfg->num_l1_ents * (STRTAB_L1_DESC_DWORDS << 3);
3647+
l1size = cfg->num_l1_ents * sizeof(struct arm_smmu_strtab_l1);
36473648
strtab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->strtab_dma,
36483649
GFP_KERNEL);
36493650
if (!strtab) {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ struct arm_smmu_device;
206206
*/
207207
#define STRTAB_SPLIT 8
208208

209-
#define STRTAB_L1_DESC_DWORDS 1
210209
#define STRTAB_L1_DESC_SPAN GENMASK_ULL(4, 0)
211210
#define STRTAB_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 6)
212211

@@ -217,6 +216,13 @@ struct arm_smmu_ste {
217216
};
218217

219218
#define STRTAB_NUM_L2_STES (1 << STRTAB_SPLIT)
219+
struct arm_smmu_strtab_l2 {
220+
struct arm_smmu_ste stes[STRTAB_NUM_L2_STES];
221+
};
222+
223+
struct arm_smmu_strtab_l1 {
224+
__le64 l2ptr;
225+
};
220226
#define STRTAB_MAX_L1_ENTRIES (1 << 17)
221227

222228
static inline u32 arm_smmu_strtab_l1_idx(u32 sid)
@@ -608,7 +614,7 @@ struct arm_smmu_priq {
608614

609615
/* High-level stream table and context descriptor structures */
610616
struct arm_smmu_strtab_l1_desc {
611-
struct arm_smmu_ste *l2ptr;
617+
struct arm_smmu_strtab_l2 *l2ptr;
612618
};
613619

614620
struct arm_smmu_ctx_desc {

0 commit comments

Comments
 (0)