Skip to content

Commit 4ce8da4

Browse files
jpbruckerwilldeacon
authored andcommitted
iommu/arm-smmu-v3: Add command queue batching helpers
As more functions will implement command queue batching, add two helpers to simplify building a command list. Signed-off-by: Jean-Philippe Brucker <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 87e5fe5 commit 4ce8da4

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

drivers/iommu/arm-smmu-v3.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,11 @@ struct arm_smmu_cmdq {
548548
atomic_t lock;
549549
};
550550

551+
struct arm_smmu_cmdq_batch {
552+
u64 cmds[CMDQ_BATCH_ENTRIES * CMDQ_ENT_DWORDS];
553+
int num;
554+
};
555+
551556
struct arm_smmu_evtq {
552557
struct arm_smmu_queue q;
553558
u32 max_stalls;
@@ -1482,6 +1487,24 @@ static int arm_smmu_cmdq_issue_sync(struct arm_smmu_device *smmu)
14821487
return arm_smmu_cmdq_issue_cmdlist(smmu, NULL, 0, true);
14831488
}
14841489

1490+
static void arm_smmu_cmdq_batch_add(struct arm_smmu_device *smmu,
1491+
struct arm_smmu_cmdq_batch *cmds,
1492+
struct arm_smmu_cmdq_ent *cmd)
1493+
{
1494+
if (cmds->num == CMDQ_BATCH_ENTRIES) {
1495+
arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmds, cmds->num, false);
1496+
cmds->num = 0;
1497+
}
1498+
arm_smmu_cmdq_build_cmd(&cmds->cmds[cmds->num * CMDQ_ENT_DWORDS], cmd);
1499+
cmds->num++;
1500+
}
1501+
1502+
static int arm_smmu_cmdq_batch_submit(struct arm_smmu_device *smmu,
1503+
struct arm_smmu_cmdq_batch *cmds)
1504+
{
1505+
return arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmds, cmds->num, true);
1506+
}
1507+
14851508
/* Context descriptor manipulation functions */
14861509
static void arm_smmu_sync_cd(struct arm_smmu_domain *smmu_domain,
14871510
int ssid, bool leaf)
@@ -2220,10 +2243,9 @@ static void arm_smmu_tlb_inv_range(unsigned long iova, size_t size,
22202243
size_t granule, bool leaf,
22212244
struct arm_smmu_domain *smmu_domain)
22222245
{
2223-
u64 cmds[CMDQ_BATCH_ENTRIES * CMDQ_ENT_DWORDS];
22242246
struct arm_smmu_device *smmu = smmu_domain->smmu;
22252247
unsigned long start = iova, end = iova + size;
2226-
int i = 0;
2248+
struct arm_smmu_cmdq_batch cmds = {};
22272249
struct arm_smmu_cmdq_ent cmd = {
22282250
.tlbi = {
22292251
.leaf = leaf,
@@ -2242,18 +2264,11 @@ static void arm_smmu_tlb_inv_range(unsigned long iova, size_t size,
22422264
}
22432265

22442266
while (iova < end) {
2245-
if (i == CMDQ_BATCH_ENTRIES) {
2246-
arm_smmu_cmdq_issue_cmdlist(smmu, cmds, i, false);
2247-
i = 0;
2248-
}
2249-
22502267
cmd.tlbi.addr = iova;
2251-
arm_smmu_cmdq_build_cmd(&cmds[i * CMDQ_ENT_DWORDS], &cmd);
2268+
arm_smmu_cmdq_batch_add(smmu, &cmds, &cmd);
22522269
iova += granule;
2253-
i++;
22542270
}
2255-
2256-
arm_smmu_cmdq_issue_cmdlist(smmu, cmds, i, true);
2271+
arm_smmu_cmdq_batch_submit(smmu, &cmds);
22572272

22582273
/*
22592274
* Unfortunately, this can't be leaf-only since we may have

0 commit comments

Comments
 (0)