From a23e7a88bcf2471704db1b4948a39916886cc899 Mon Sep 17 00:00:00 2001 From: Oleksandr Tyshchenko Date: Mon, 20 Dec 2021 23:15:50 +0200 Subject: [PATCH] iommu/ipmmu-vmsa: Add helper functions for "uTLB" registers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is a non-verbatim port of corresponding Linux upsteam commit: 3667c9978b2911dc1ded77f5971df477885409c4 Original commit message: commit 3667c9978b2911dc1ded77f5971df477885409c4 Author: Yoshihiro Shimoda Date: Wed Nov 6 11:35:49 2019 +0900 iommu/ipmmu-vmsa: Add helper functions for "uTLB" registers Since we will have changed memory mapping of the IPMMU in the future, This patch adds helper functions ipmmu_utlb_reg() and ipmmu_imu{asid,ctr}_write() for "uTLB" registers. No behavior change. Signed-off-by: Yoshihiro Shimoda Reviewed-by: Geert Uytterhoeven Reviewed-by: Niklas Söderlund Signed-off-by: Joerg Roedel ********** This is a prereq work needed to add support for S4 series easily in the future. Besides changes done in the original commit, we also need to introduce ipmmu_imuctr_read() since Xen driver contains an additional logic in ipmmu_utlb_enable() to prevent the use cases where devices which use the same micro-TLB are assigned to different Xen domains. No change in behavior. Signed-off-by: Oleksandr Tyshchenko Reviewed-by: Yoshihiro Shimoda Acked-by: Julien Grall --- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 33 ++++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c b/xen/drivers/passthrough/arm/ipmmu-vmsa.c index ce5c3bc1e0..1b94af245f 100644 --- a/xen/drivers/passthrough/arm/ipmmu-vmsa.c +++ b/xen/drivers/passthrough/arm/ipmmu-vmsa.c @@ -366,6 +366,29 @@ static void ipmmu_ctx_write_all(struct ipmmu_vmsa_domain *domain, ipmmu_ctx_write_root(domain, reg, data); } +static uint32_t ipmmu_utlb_reg(struct ipmmu_vmsa_device *mmu, uint32_t reg) +{ + return reg; +} + +static void ipmmu_imuasid_write(struct ipmmu_vmsa_device *mmu, + unsigned int utlb, uint32_t data) +{ + ipmmu_write(mmu, ipmmu_utlb_reg(mmu, IMUASID(utlb)), data); +} + +static void ipmmu_imuctr_write(struct ipmmu_vmsa_device *mmu, + unsigned int utlb, uint32_t data) +{ + ipmmu_write(mmu, ipmmu_utlb_reg(mmu, IMUCTR(utlb)), data); +} + +static uint32_t ipmmu_imuctr_read(struct ipmmu_vmsa_device *mmu, + unsigned int utlb) +{ + return ipmmu_read(mmu, ipmmu_utlb_reg(mmu, IMUCTR(utlb))); +} + /* TLB and micro-TLB Management */ /* Wait for any pending TLB invalidations to complete. */ @@ -413,7 +436,7 @@ static int ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain, * context_id for already enabled micro-TLB and prevent different context * bank from being set. */ - imuctr = ipmmu_read(mmu, IMUCTR(utlb)); + imuctr = ipmmu_imuctr_read(mmu, utlb); if ( imuctr & IMUCTR_MMUEN ) { unsigned int context_id; @@ -431,9 +454,9 @@ static int ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain, * TODO: Reference-count the micro-TLB as several bus masters can be * connected to the same micro-TLB. */ - ipmmu_write(mmu, IMUASID(utlb), 0); - ipmmu_write(mmu, IMUCTR(utlb), imuctr | - IMUCTR_TTSEL_MMU(domain->context_id) | IMUCTR_MMUEN); + ipmmu_imuasid_write(mmu, utlb, 0); + ipmmu_imuctr_write(mmu, utlb, imuctr | + IMUCTR_TTSEL_MMU(domain->context_id) | IMUCTR_MMUEN); return 0; } @@ -444,7 +467,7 @@ static void ipmmu_utlb_disable(struct ipmmu_vmsa_domain *domain, { struct ipmmu_vmsa_device *mmu = domain->mmu; - ipmmu_write(mmu, IMUCTR(utlb), 0); + ipmmu_imuctr_write(mmu, utlb, 0); } /* Domain/Context Management */ -- 2.30.2