Skip to content

Commit 237d623

Browse files
Timur Kristófalexdeucher
authored andcommitted
drm/amdgpu/gart: Add helper to bind VRAM pages (v2)
Binds pages that located in VRAM to the GART page table. Useful when a kernel BO is located in VRAM but needs to be accessed from the GART address space, for example to give a kernel BO a 32-bit address when GART is placed in LOW address space. v2: - Refactor function to be more reusable Signed-off-by: Timur Kristóf <timur.kristof@gmail.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 3a4132e commit 237d623

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,42 @@ void amdgpu_gart_map(struct amdgpu_device *adev, uint64_t offset,
367367
drm_dev_exit(idx);
368368
}
369369

370+
/**
371+
* amdgpu_gart_map_vram_range - map VRAM pages into the GART page table
372+
*
373+
* @adev: amdgpu_device pointer
374+
* @pa: physical address of the first page to be mapped
375+
* @start_page: first page to map in the GART aperture
376+
* @num_pages: number of pages to be mapped
377+
* @flags: page table entry flags
378+
* @dst: CPU address of the GART table
379+
*
380+
* Binds a BO that is allocated in VRAM to the GART page table
381+
* (all ASICs).
382+
*
383+
* Useful when a kernel BO is located in VRAM but
384+
* needs to be accessed from the GART address space.
385+
*/
386+
void amdgpu_gart_map_vram_range(struct amdgpu_device *adev, uint64_t pa,
387+
uint64_t start_page, uint64_t num_pages,
388+
uint64_t flags, void *dst)
389+
{
390+
u32 i, idx;
391+
392+
/* The SYSTEM flag indicates the pages aren't in VRAM. */
393+
WARN_ON_ONCE(flags & AMDGPU_PTE_SYSTEM);
394+
395+
if (!drm_dev_enter(adev_to_drm(adev), &idx))
396+
return;
397+
398+
for (i = 0; i < num_pages; ++i) {
399+
amdgpu_gmc_set_pte_pde(adev, adev->gart.ptr,
400+
start_page + i, pa + AMDGPU_GPU_PAGE_SIZE * i, flags);
401+
}
402+
403+
drm_dev_exit(idx);
404+
}
405+
370406
/**
371407
* amdgpu_gart_bind - bind pages into the gart page table
372408
*

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,8 @@ void amdgpu_gart_map(struct amdgpu_device *adev, uint64_t offset,
6464
void *dst);
6565
void amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,
6666
int pages, dma_addr_t *dma_addr, uint64_t flags);
67+
void amdgpu_gart_map_vram_range(struct amdgpu_device *adev, uint64_t pa,
68+
uint64_t start_page, uint64_t num_pages,
69+
uint64_t flags, void *dst);
6770
void amdgpu_gart_invalidate_tlb(struct amdgpu_device *adev);
6871
#endif

0 commit comments

Comments
 (0)