Skip to content

Commit 0633bbc

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Refactor fetch_pte to use struct amd_io_pgtable
To simplify the fetch_pte function. There is no functional change. Signed-off-by: Suravee Suthikulpanit <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 33aef97 commit 0633bbc

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

drivers/iommu/amd/amd_iommu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ extern int iommu_map_page(struct protection_domain *dom,
143143
extern unsigned long iommu_unmap_page(struct protection_domain *dom,
144144
unsigned long bus_addr,
145145
unsigned long page_size);
146-
extern u64 *fetch_pte(struct protection_domain *domain,
146+
extern u64 *fetch_pte(struct amd_io_pgtable *pgtable,
147147
unsigned long address,
148148
unsigned long *page_size);
149149
extern void amd_iommu_domain_set_pgtable(struct protection_domain *domain,

drivers/iommu/amd/io_pgtable.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ static u64 *alloc_pte(struct protection_domain *domain,
311311
* This function checks if there is a PTE for a given dma address. If
312312
* there is one, it returns the pointer to it.
313313
*/
314-
u64 *fetch_pte(struct protection_domain *domain,
314+
u64 *fetch_pte(struct amd_io_pgtable *pgtable,
315315
unsigned long address,
316316
unsigned long *page_size)
317317
{
@@ -320,11 +320,11 @@ u64 *fetch_pte(struct protection_domain *domain,
320320

321321
*page_size = 0;
322322

323-
if (address > PM_LEVEL_SIZE(domain->iop.mode))
323+
if (address > PM_LEVEL_SIZE(pgtable->mode))
324324
return NULL;
325325

326-
level = domain->iop.mode - 1;
327-
pte = &domain->iop.root[PM_LEVEL_INDEX(level, address)];
326+
level = pgtable->mode - 1;
327+
pte = &pgtable->root[PM_LEVEL_INDEX(level, address)];
328328
*page_size = PTE_LEVEL_PAGE_SIZE(level);
329329

330330
while (level > 0) {
@@ -459,6 +459,8 @@ unsigned long iommu_unmap_page(struct protection_domain *dom,
459459
unsigned long iova,
460460
unsigned long size)
461461
{
462+
struct io_pgtable_ops *ops = &dom->iop.iop.ops;
463+
struct amd_io_pgtable *pgtable = io_pgtable_ops_to_data(ops);
462464
unsigned long long unmapped;
463465
unsigned long unmap_size;
464466
u64 *pte;
@@ -468,8 +470,7 @@ unsigned long iommu_unmap_page(struct protection_domain *dom,
468470
unmapped = 0;
469471

470472
while (unmapped < size) {
471-
pte = fetch_pte(dom, iova, &unmap_size);
472-
473+
pte = fetch_pte(pgtable, iova, &unmap_size);
473474
if (pte) {
474475
int i, count;
475476

drivers/iommu/amd/iommu.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2099,13 +2099,15 @@ static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,
20992099
dma_addr_t iova)
21002100
{
21012101
struct protection_domain *domain = to_pdomain(dom);
2102+
struct io_pgtable_ops *ops = &domain->iop.iop.ops;
2103+
struct amd_io_pgtable *pgtable = io_pgtable_ops_to_data(ops);
21022104
unsigned long offset_mask, pte_pgsize;
21032105
u64 *pte, __pte;
21042106

21052107
if (domain->iop.mode == PAGE_MODE_NONE)
21062108
return iova;
21072109

2108-
pte = fetch_pte(domain, iova, &pte_pgsize);
2110+
pte = fetch_pte(pgtable, iova, &pte_pgsize);
21092111

21102112
if (!pte || !IOMMU_PTE_PRESENT(*pte))
21112113
return 0;

0 commit comments

Comments
 (0)