Simplify flush op to a bool to control whether LSC is flushed/invalidated. Remove mmu_hw_do_operation helper.
Signed-off-by: Chia-I Wu <olva...@gmail.com> --- drivers/gpu/drm/panthor/panthor_mmu.c | 42 ++++++--------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c index 743e9342eece7..5418f079444ce 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.c +++ b/drivers/gpu/drm/panthor/panthor_mmu.c @@ -613,33 +613,20 @@ static void mmu_hw_cmd_unlock(struct panthor_device *ptdev, u32 as_nr) * @as_nr: AS to issue command to. * @iova: Start of the region. * @size: Size of the region. - * @op: AS_COMMAND_FLUSH_* + * @flush_lsc: True if LSC should be flushed/invalidated. * * Issue LOCK/GPU_FLUSH_CACHES/UNLOCK commands in order to flush and * invalidate L2/MMU/LSC caches for a region. * * Return: 0 on success, a negative error code otherwise. */ -static int mmu_hw_flush_caches(struct panthor_device *ptdev, int as_nr, u64 iova, u64 size, u32 op) +static int mmu_hw_flush_caches(struct panthor_device *ptdev, int as_nr, u64 iova, u64 size, + bool flush_lsc) { const u32 l2_flush_op = CACHE_CLEAN | CACHE_INV; - u32 lsc_flush_op; + const u32 lsc_flush_op = flush_lsc ? l2_flush_op : 0; int ret; - lockdep_assert_held(&ptdev->mmu->as.slots_lock); - - switch (op) { - case AS_COMMAND_FLUSH_MEM: - lsc_flush_op = CACHE_CLEAN | CACHE_INV; - break; - case AS_COMMAND_FLUSH_PT: - lsc_flush_op = 0; - break; - default: - drm_WARN(&ptdev->base, 1, "Unexpected AS_COMMAND: %d", op); - return -EINVAL; - } - if (as_nr < 0 || !size) return 0; @@ -671,25 +658,12 @@ static int mmu_hw_flush_caches(struct panthor_device *ptdev, int as_nr, u64 iova return ret; } -static int mmu_hw_do_operation(struct panthor_vm *vm, - u64 iova, u64 size, u32 op) -{ - struct panthor_device *ptdev = vm->ptdev; - int ret; - - mutex_lock(&ptdev->mmu->as.slots_lock); - ret = mmu_hw_flush_caches(ptdev, vm->as.id, iova, size, op); - mutex_unlock(&ptdev->mmu->as.slots_lock); - - return ret; -} - static int panthor_mmu_as_enable(struct panthor_device *ptdev, u32 as_nr, u64 transtab, u64 transcfg, u64 memattr) { int ret; - ret = mmu_hw_flush_caches(ptdev, as_nr, 0, ~0ULL, AS_COMMAND_FLUSH_MEM); + ret = mmu_hw_flush_caches(ptdev, as_nr, 0, ~0ULL, true); if (ret) return ret; @@ -706,7 +680,7 @@ static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr) { int ret; - ret = mmu_hw_flush_caches(ptdev, as_nr, 0, ~0ULL, AS_COMMAND_FLUSH_MEM); + ret = mmu_hw_flush_caches(ptdev, as_nr, 0, ~0ULL, true); if (ret) return ret; @@ -962,7 +936,9 @@ static int panthor_vm_flush_range(struct panthor_vm *vm, u64 iova, u64 size) if (!drm_dev_enter(&ptdev->base, &cookie)) return 0; - ret = mmu_hw_do_operation(vm, iova, size, AS_COMMAND_FLUSH_PT); + mutex_lock(&ptdev->mmu->as.slots_lock); + ret = mmu_hw_flush_caches(ptdev, vm->as.id, iova, size, false); + mutex_unlock(&ptdev->mmu->as.slots_lock); drm_dev_exit(cookie); return ret; -- 2.51.0.384.g4c02a37b29-goog