Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/panthor: Simplify mmu_hw_do_operation_locked

The only callers to mmu_hw_do_operation_locked() pass an 'op' of either
AS_COMAND_FLUSH_MEM or AS_COMMAND_FLUSH_PT. This means the code paths
after that are dead. Removing those paths means the
mmu_hw_do_flush_on_gpu_ctrl() function might has well be inlined.

Simplify everything by having a switch statement for the type of 'op'
(warning if we get an unexpected value) and removing the dead cases.

Suggested-by: Daniel Stone <daniel@fooishbar.org>
Signed-off-by: Steven Price <steven.price@arm.com>
Reviewed-by: Karunika Choo <karunika.choo@arm.com>
Link: https://lore.kernel.org/r/20250815134226.57703-1-steven.price@arm.com

+26 -31
+26 -31
drivers/gpu/drm/panthor/panthor_mmu.c
··· 569 569 write_cmd(ptdev, as_nr, AS_COMMAND_LOCK); 570 570 } 571 571 572 - static int mmu_hw_do_flush_on_gpu_ctrl(struct panthor_device *ptdev, int as_nr, 573 - u32 op) 572 + static int mmu_hw_do_operation_locked(struct panthor_device *ptdev, int as_nr, 573 + u64 iova, u64 size, u32 op) 574 574 { 575 575 const u32 l2_flush_op = CACHE_CLEAN | CACHE_INV; 576 - u32 lsc_flush_op = 0; 576 + u32 lsc_flush_op; 577 577 int ret; 578 578 579 - if (op == AS_COMMAND_FLUSH_MEM) 579 + lockdep_assert_held(&ptdev->mmu->as.slots_lock); 580 + 581 + switch (op) { 582 + case AS_COMMAND_FLUSH_MEM: 580 583 lsc_flush_op = CACHE_CLEAN | CACHE_INV; 584 + break; 585 + case AS_COMMAND_FLUSH_PT: 586 + lsc_flush_op = 0; 587 + break; 588 + default: 589 + drm_WARN(&ptdev->base, 1, "Unexpected AS_COMMAND: %d", op); 590 + return -EINVAL; 591 + } 592 + 593 + if (as_nr < 0) 594 + return 0; 595 + 596 + /* 597 + * If the AS number is greater than zero, then we can be sure 598 + * the device is up and running, so we don't need to explicitly 599 + * power it up 600 + */ 601 + 602 + lock_region(ptdev, as_nr, iova, size); 581 603 582 604 ret = wait_ready(ptdev, as_nr); 583 605 if (ret) ··· 617 595 write_cmd(ptdev, as_nr, AS_COMMAND_UNLOCK); 618 596 619 597 /* Wait for the unlock command to complete */ 620 - return wait_ready(ptdev, as_nr); 621 - } 622 - 623 - static int mmu_hw_do_operation_locked(struct panthor_device *ptdev, int as_nr, 624 - u64 iova, u64 size, u32 op) 625 - { 626 - lockdep_assert_held(&ptdev->mmu->as.slots_lock); 627 - 628 - if (as_nr < 0) 629 - return 0; 630 - 631 - /* 632 - * If the AS number is greater than zero, then we can be sure 633 - * the device is up and running, so we don't need to explicitly 634 - * power it up 635 - */ 636 - 637 - if (op != AS_COMMAND_UNLOCK) 638 - lock_region(ptdev, as_nr, iova, size); 639 - 640 - if (op == AS_COMMAND_FLUSH_MEM || op == AS_COMMAND_FLUSH_PT) 641 - return mmu_hw_do_flush_on_gpu_ctrl(ptdev, as_nr, op); 642 - 643 - /* Run the MMU operation */ 644 - write_cmd(ptdev, as_nr, op); 645 - 646 - /* Wait for the flush to complete */ 647 598 return wait_ready(ptdev, as_nr); 648 599 } 649 600