Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Timur Kristóf and committed by
Alex Deucher
237d623a 3a4132e6

+39
+36
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
··· 368 368 } 369 369 370 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 + 406 + /** 371 407 * amdgpu_gart_bind - bind pages into the gart page table 372 408 * 373 409 * @adev: amdgpu_device pointer
+3
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.h
··· 64 64 void *dst); 65 65 void amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset, 66 66 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); 67 70 void amdgpu_gart_invalidate_tlb(struct amdgpu_device *adev); 68 71 #endif