Skip to content

Commit c0a25a9

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/arm-smmu-v3: Shrink the cdtab l1_desc array
The top of the 2 level CD table is (at most) 1024 entries big, and two high order allocations are required. One of __le64 which is programmed into the HW (8k) and one of struct arm_smmu_l1_ctx_desc which holds the CPU pointer (16k). There are two copies of the l2ptr_dma, one is stored in the struct arm_smmu_l1_ctx_desc, and another is encoded in the __le64 for the HW to use. Instead of storing two copies just decode the value from the __le64. 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 47b2de3 commit c0a25a9

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

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

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,29 +1217,17 @@ static void arm_smmu_sync_cd(struct arm_smmu_master *master,
12171217
arm_smmu_cmdq_batch_submit(smmu, &cmds);
12181218
}
12191219

1220-
static int arm_smmu_alloc_cd_leaf_table(struct arm_smmu_device *smmu,
1221-
struct arm_smmu_l1_ctx_desc *l1_desc)
1220+
static void arm_smmu_write_cd_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma)
12221221
{
1223-
size_t size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3);
1222+
u64 val = (l2ptr_dma & CTXDESC_L1_DESC_L2PTR_MASK) | CTXDESC_L1_DESC_V;
12241223

1225-
l1_desc->l2ptr = dma_alloc_coherent(smmu->dev, size,
1226-
&l1_desc->l2ptr_dma, GFP_KERNEL);
1227-
if (!l1_desc->l2ptr) {
1228-
dev_warn(smmu->dev,
1229-
"failed to allocate context descriptor table\n");
1230-
return -ENOMEM;
1231-
}
1232-
return 0;
1224+
/* The HW has 64 bit atomicity with stores to the L2 CD table */
1225+
WRITE_ONCE(*dst, cpu_to_le64(val));
12331226
}
12341227

1235-
static void arm_smmu_write_cd_l1_desc(__le64 *dst,
1236-
struct arm_smmu_l1_ctx_desc *l1_desc)
1228+
static dma_addr_t arm_smmu_cd_l1_get_desc(const __le64 *src)
12371229
{
1238-
u64 val = (l1_desc->l2ptr_dma & CTXDESC_L1_DESC_L2PTR_MASK) |
1239-
CTXDESC_L1_DESC_V;
1240-
1241-
/* The HW has 64 bit atomicity with stores to the L2 CD table */
1242-
WRITE_ONCE(*dst, cpu_to_le64(val));
1230+
return le64_to_cpu(*src) & CTXDESC_L1_DESC_L2PTR_MASK;
12431231
}
12441232

12451233
struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master,
@@ -1281,13 +1269,18 @@ static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master,
12811269

12821270
l1_desc = &cd_table->l1_desc[idx];
12831271
if (!l1_desc->l2ptr) {
1284-
__le64 *l1ptr;
1285-
1286-
if (arm_smmu_alloc_cd_leaf_table(smmu, l1_desc))
1272+
dma_addr_t l2ptr_dma;
1273+
size_t size;
1274+
1275+
size = CTXDESC_L2_ENTRIES * sizeof(struct arm_smmu_cd);
1276+
l1_desc->l2ptr = dma_alloc_coherent(smmu->dev, size,
1277+
&l2ptr_dma,
1278+
GFP_KERNEL);
1279+
if (!l1_desc->l2ptr)
12871280
return NULL;
12881281

1289-
l1ptr = cd_table->cdtab + idx * CTXDESC_L1_DESC_DWORDS;
1290-
arm_smmu_write_cd_l1_desc(l1ptr, l1_desc);
1282+
arm_smmu_write_cd_l1_desc(&cd_table->cdtab[idx],
1283+
l2ptr_dma);
12911284
/* An invalid L1CD can be cached */
12921285
arm_smmu_sync_cd(master, ssid, false);
12931286
}
@@ -1480,7 +1473,8 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master)
14801473

14811474
dma_free_coherent(smmu->dev, size,
14821475
cd_table->l1_desc[i].l2ptr,
1483-
cd_table->l1_desc[i].l2ptr_dma);
1476+
arm_smmu_cd_l1_get_desc(
1477+
&cd_table->cdtab[i]));
14841478
}
14851479
kfree(cd_table->l1_desc);
14861480

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,6 @@ struct arm_smmu_ctx_desc {
619619

620620
struct arm_smmu_l1_ctx_desc {
621621
struct arm_smmu_cd *l2ptr;
622-
dma_addr_t l2ptr_dma;
623622
};
624623

625624
struct arm_smmu_ctx_desc_cfg {

0 commit comments

Comments
 (0)