iommu/tegra-smmu: Use non-secure register for flushing
Subsystems (3)
PATCH 1/3 iommu/tegra-smmu: Use non-secure register for flushing
From: Navneet Kumar <[email protected]>
Use PTB_ASID instead of SMMU_CONFIG to flush smmu.PTB_ASID can be accessed from non-secure mode, SMMU_CONFIG cannot be. Using SMMU_CONFIG could pose a problem when kernel doesn't have secure mode access enabled from boot.
--- drivers/iommu/tegra-smmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/tegra-smmu.c +1 -1
@@ -240,7 +240,7 @@ static inline void smmu_flush_tlb_group(struct tegra_smmu *smmu,static inline void smmu_flush (struct tegra_smmu *smmu) { -smmu_readl (smmu,SMMU_CONFIG ); +smmu_readl (smmu,SMMU_PTB_ASID ); }static int tegra_smmu_alloc_asid (struct tegra_smmu *smmu,unsigned int *idp)
Signature · 1 line
2.23.0
PATCH 2/3 iommu/tegra-smmu: Fix client enablement order
From: Navneet Kumar <[email protected]>
Enable clients' translation only after setting up the swgroups.
--- drivers/iommu/tegra-smmu.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/iommu/tegra-smmu.c +14 -9
@@ -351,6 +351,20 @@ static void tegra_smmu_enable(struct tegra_smmu *smmu, unsigned int swgroup,unsigned int i;u32 value; + group =tegra_smmu_find_swgroup (smmu, swgroup); +if (group) { + value =smmu_readl (smmu, group->reg); + value &= ~SMMU_ASID_MASK ; + value |=SMMU_ASID_VALUE (asid); + value |=SMMU_ASID_ENABLE ; +smmu_writel (smmu, value, group->reg); + }else { +pr_warn ("%s group from swgroup %u not found\n" , __func__, + swgroup); +/* No point moving ahead if group was not found */ +return ; + } +for (i =0 ; i < smmu->soc->num_clients; i++) {const struct tegra_mc_client *client = &smmu->soc->clients[i];
@@ -361,15 +375,6 @@ static void tegra_smmu_enable(struct tegra_smmu *smmu, unsigned int swgroup, value |=BIT (client->smmu.bit);smmu_writel (smmu, value, client->smmu.reg); } - - group =tegra_smmu_find_swgroup (smmu, swgroup); -if (group) { - value =smmu_readl (smmu, group->reg); - value &= ~SMMU_ASID_MASK ; - value |=SMMU_ASID_VALUE (asid); - value |=SMMU_ASID_ENABLE ; -smmu_writel (smmu, value, group->reg); - } } static void tegra_smmu_disable(struct tegra_smmu *smmu, unsigned int swgroup,
Signature · 1 line
2.23.0
PATCH 3/3 iommu/tegra-smmu: Fix page tables in > 4 GiB memory
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Page tables that reside in physical memory beyond the 4 GiB boundary are currently not working properly. The reason is that when the physical address for page directory entries is read, it gets truncated at 32 bits and can cause crashes when passing that address to the DMA API.
Fix this by first casting the PDE value to a dma_addr_t and then using the page frame number mask for the SMMU instance to mask out the invalid bits, which are typically used for mapping attributes, etc.
--- drivers/iommu/tegra-smmu.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/iommu/tegra-smmu.c +6 -5
@@ -159,9 +159,9 @@ static bool smmu_dma_addr_valid(struct tegra_smmu *smmu, dma_addr_t addr)return (addr & smmu->pfn_mask) == addr; } -static dma_addr_t smmu_pde_to_dma (u32 pde) +static dma_addr_t smmu_pde_to_dma (struct tegra_smmu *smmu,u32 pde) { -return pde <<12 ; +return (dma_addr_t)(pde & smmu->pfn_mask) <<12 ; }static void smmu_flush_ptc_all (struct tegra_smmu *smmu)
@@ -554,6 +554,7 @@ static u32 *tegra_smmu_pte_lookup(struct tegra_smmu_as *as, unsigned long iova, dma_addr_t *dmap) {unsigned int pd_index =iova_pd_index (iova); +struct tegra_smmu *smmu = as->smmu;struct page *pt_page;u32 *pd;
@@ -562,7 +563,7 @@ static u32 *tegra_smmu_pte_lookup(struct tegra_smmu_as *as, unsigned long iova,return NULL ; pd =page_address (as->pd); - *dmap =smmu_pde_to_dma (pd[pd_index]); + *dmap =smmu_pde_to_dma (smmu, pd[pd_index]);return tegra_smmu_pte_offset (pt_page, iova); }
@@ -604,7 +605,7 @@ static u32 *as_get_pte(struct tegra_smmu_as *as, dma_addr_t iova, }else {u32 *pd =page_address (as->pd); - *dmap =smmu_pde_to_dma (pd[pde]); + *dmap =smmu_pde_to_dma (smmu, pd[pde]); }return tegra_smmu_pte_offset (as->pts[pde], iova);
@@ -629,7 +630,7 @@ static void tegra_smmu_pte_put_use(struct tegra_smmu_as *as, unsigned long iova)if (--as->count[pde] ==0 ) {struct tegra_smmu *smmu = as->smmu;u32 *pd =page_address (as->pd); -dma_addr_t pte_dma =smmu_pde_to_dma (pd[pde]); +dma_addr_t pte_dma =smmu_pde_to_dma (smmu, pd[pde]);tegra_smmu_set_pde (as, iova,0 );
Signature · 1 line
2.23.0
Quoted 7 lines · Thierry Reding
From: Navneet Kumar <[email protected]>
Use
PTB_ASIDinstead ofSMMU_CONFIGto flush smmu.PTB_ASIDcan be accessed from non-secure mode,SMMU_CONFIGcannot be. UsingSMMU_CONFIGcould pose a problem when kernel doesn't have secure mode access enabled from boot.
Quoted 7 lines
Signed-off-by Navneet Kumar <[email protected]>Reviewed-by Dmitry Osipenko <[email protected]>Tested-by Dmitry Osipenko <[email protected]>Signed-off-by Thierry Reding <[email protected]>--- drivers/iommu/tegra-smmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied all, thanks.