From: Nicolin Chen nicolinc@nvidia.com
Add a queue_ncmds() to return the number of pending commands in the queue. This will be used in the following patch to kcalloc memory for user CMDQ.
This helper was partially the existing queue_has_space(), so simplify it.
Signed-off-by: Nicolin Chen nicolinc@nvidia.com Signed-off-by: Kunkun Jiang jiangkunkun@huawei.com --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 00c2654f3253..0c858ab70d30 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -162,17 +162,22 @@ static void parse_driver_options(struct arm_smmu_device *smmu) }
/* Low-level queue manipulation functions */ -static bool queue_has_space(struct arm_smmu_ll_queue *q, u32 n) +static int queue_ncmds(struct arm_smmu_ll_queue *q) { - u32 space, prod, cons; + u32 prod, cons;
prod = Q_IDX(q, q->prod); cons = Q_IDX(q, q->cons);
if (Q_WRP(q, q->prod) == Q_WRP(q, q->cons)) - space = (1 << q->max_n_shift) - (prod - cons); + return prod - cons; else - space = cons - prod; + return (1 << q->max_n_shift) - cons + prod; +} + +static bool queue_has_space(struct arm_smmu_ll_queue *q, u32 n) +{ + u32 space = (1 << q->max_n_shift) - queue_ncmds(q);
return space >= n; }