Skip to content

Commit fd86c95

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Introduce iommu_v1_map_page and iommu_v1_unmap_page
These implement map and unmap for AMD IOMMU v1 pagetable, which will be used by the IO pagetable framework. Also clean up unused extern function declarations. Signed-off-by: Suravee Suthikulpanit <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 441555c commit fd86c95

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

drivers/iommu/amd/amd_iommu.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,6 @@ void amd_iommu_apply_ivrs_quirks(void);
133133
static inline void amd_iommu_apply_ivrs_quirks(void) { }
134134
#endif
135135

136-
/* TODO: These are temporary and will be removed once fully transition */
137-
extern int iommu_map_page(struct protection_domain *dom,
138-
unsigned long bus_addr,
139-
unsigned long phys_addr,
140-
unsigned long page_size,
141-
int prot,
142-
gfp_t gfp);
143-
extern unsigned long iommu_unmap_page(struct protection_domain *dom,
144-
unsigned long bus_addr,
145-
unsigned long page_size);
146-
extern u64 *fetch_pte(struct amd_io_pgtable *pgtable,
147-
unsigned long address,
148-
unsigned long *page_size);
149136
extern void amd_iommu_domain_set_pgtable(struct protection_domain *domain,
150137
u64 *root, int mode);
151138
#endif

drivers/iommu/amd/io_pgtable.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,9 @@ 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 amd_io_pgtable *pgtable,
315-
unsigned long address,
316-
unsigned long *page_size)
314+
static u64 *fetch_pte(struct amd_io_pgtable *pgtable,
315+
unsigned long address,
316+
unsigned long *page_size)
317317
{
318318
int level;
319319
u64 *pte;
@@ -386,13 +386,10 @@ static struct page *free_clear_pte(u64 *pte, u64 pteval, struct page *freelist)
386386
* supporting all features of AMD IOMMU page tables like level skipping
387387
* and full 64 bit address spaces.
388388
*/
389-
int iommu_map_page(struct protection_domain *dom,
390-
unsigned long iova,
391-
unsigned long paddr,
392-
unsigned long size,
393-
int prot,
394-
gfp_t gfp)
389+
static int iommu_v1_map_page(struct io_pgtable_ops *ops, unsigned long iova,
390+
phys_addr_t paddr, size_t size, int prot, gfp_t gfp)
395391
{
392+
struct protection_domain *dom = io_pgtable_ops_to_domain(ops);
396393
struct page *freelist = NULL;
397394
bool updated = false;
398395
u64 __pte, *pte;
@@ -455,11 +452,11 @@ int iommu_map_page(struct protection_domain *dom,
455452
return ret;
456453
}
457454

458-
unsigned long iommu_unmap_page(struct protection_domain *dom,
459-
unsigned long iova,
460-
unsigned long size)
455+
static unsigned long iommu_v1_unmap_page(struct io_pgtable_ops *ops,
456+
unsigned long iova,
457+
size_t size,
458+
struct iommu_iotlb_gather *gather)
461459
{
462-
struct io_pgtable_ops *ops = &dom->iop.iop.ops;
463460
struct amd_io_pgtable *pgtable = io_pgtable_ops_to_data(ops);
464461
unsigned long long unmapped;
465462
unsigned long unmap_size;
@@ -548,6 +545,8 @@ static struct io_pgtable *v1_alloc_pgtable(struct io_pgtable_cfg *cfg, void *coo
548545
cfg->oas = IOMMU_OUT_ADDR_BIT_SIZE,
549546
cfg->tlb = &v1_flush_ops;
550547

548+
pgtable->iop.ops.map = iommu_v1_map_page;
549+
pgtable->iop.ops.unmap = iommu_v1_unmap_page;
551550
pgtable->iop.ops.iova_to_phys = iommu_v1_iova_to_phys;
552551

553552
return &pgtable->iop;

drivers/iommu/amd/iommu.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,8 +2065,9 @@ static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova,
20652065
gfp_t gfp)
20662066
{
20672067
struct protection_domain *domain = to_pdomain(dom);
2068+
struct io_pgtable_ops *ops = &domain->iop.iop.ops;
20682069
int prot = 0;
2069-
int ret;
2070+
int ret = -EINVAL;
20702071

20712072
if (domain->iop.mode == PAGE_MODE_NONE)
20722073
return -EINVAL;
@@ -2076,9 +2077,10 @@ static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova,
20762077
if (iommu_prot & IOMMU_WRITE)
20772078
prot |= IOMMU_PROT_IW;
20782079

2079-
ret = iommu_map_page(domain, iova, paddr, page_size, prot, gfp);
2080-
2081-
domain_flush_np_cache(domain, iova, page_size);
2080+
if (ops->map) {
2081+
ret = ops->map(ops, iova, paddr, page_size, prot, gfp);
2082+
domain_flush_np_cache(domain, iova, page_size);
2083+
}
20822084

20832085
return ret;
20842086
}
@@ -2088,11 +2090,12 @@ static size_t amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova,
20882090
struct iommu_iotlb_gather *gather)
20892091
{
20902092
struct protection_domain *domain = to_pdomain(dom);
2093+
struct io_pgtable_ops *ops = &domain->iop.iop.ops;
20912094

20922095
if (domain->iop.mode == PAGE_MODE_NONE)
20932096
return 0;
20942097

2095-
return iommu_unmap_page(domain, iova, page_size);
2098+
return (ops->unmap) ? ops->unmap(ops, iova, page_size, gather) : 0;
20962099
}
20972100

20982101
static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,

0 commit comments

Comments
 (0)