Commit dce34bfd authored by Christian König's avatar Christian König Committed by Alex Deucher

drm/radeon: refactor set_page chipset interface v5

Cleanup the interface in preparation for hierarchical page tables.

v2: add incr parameter to set_page for simple scattered PTs uptates
    added PDE-specific flags to r600_flags and radeon_drm.h
    removed superfluous value masking with 0xffffffff

v3: removed superfluous bo_va->valid checking
    changed R600_PTE_VALID to R600_ENTRY_VALID to handle PDE too

v4 (ck): fix indention style, rework and fix typos in commit message,
         add documentation for incr parameter, also use incr
         parameter for system pages

v5 (agd5f): use upper_32_bits() and minor white space fixes
Signed-off-by: default avatarChristian König <deathsimple@vodafone.de>
Signed-off-by: default avatarDmitry Cherkassov <Dmitrii.Cherkasov@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent af026c5b
...@@ -1497,7 +1497,7 @@ void cayman_vm_fini(struct radeon_device *rdev) ...@@ -1497,7 +1497,7 @@ void cayman_vm_fini(struct radeon_device *rdev)
{ {
} }
#define R600_PTE_VALID (1 << 0) #define R600_ENTRY_VALID (1 << 0)
#define R600_PTE_SYSTEM (1 << 1) #define R600_PTE_SYSTEM (1 << 1)
#define R600_PTE_SNOOPED (1 << 2) #define R600_PTE_SNOOPED (1 << 2)
#define R600_PTE_READABLE (1 << 5) #define R600_PTE_READABLE (1 << 5)
...@@ -1506,8 +1506,7 @@ void cayman_vm_fini(struct radeon_device *rdev) ...@@ -1506,8 +1506,7 @@ void cayman_vm_fini(struct radeon_device *rdev)
uint32_t cayman_vm_page_flags(struct radeon_device *rdev, uint32_t flags) uint32_t cayman_vm_page_flags(struct radeon_device *rdev, uint32_t flags)
{ {
uint32_t r600_flags = 0; uint32_t r600_flags = 0;
r600_flags |= (flags & RADEON_VM_PAGE_VALID) ? R600_ENTRY_VALID : 0;
r600_flags |= (flags & RADEON_VM_PAGE_VALID) ? R600_PTE_VALID : 0;
r600_flags |= (flags & RADEON_VM_PAGE_READABLE) ? R600_PTE_READABLE : 0; r600_flags |= (flags & RADEON_VM_PAGE_READABLE) ? R600_PTE_READABLE : 0;
r600_flags |= (flags & RADEON_VM_PAGE_WRITEABLE) ? R600_PTE_WRITEABLE : 0; r600_flags |= (flags & RADEON_VM_PAGE_WRITEABLE) ? R600_PTE_WRITEABLE : 0;
if (flags & RADEON_VM_PAGE_SYSTEM) { if (flags & RADEON_VM_PAGE_SYSTEM) {
...@@ -1521,30 +1520,40 @@ uint32_t cayman_vm_page_flags(struct radeon_device *rdev, uint32_t flags) ...@@ -1521,30 +1520,40 @@ uint32_t cayman_vm_page_flags(struct radeon_device *rdev, uint32_t flags)
* cayman_vm_set_page - update the page tables using the CP * cayman_vm_set_page - update the page tables using the CP
* *
* @rdev: radeon_device pointer * @rdev: radeon_device pointer
* @pe: addr of the page entry
* @addr: dst addr to write into pe
* @count: number of page entries to update
* @incr: increase next addr by incr bytes
* @flags: access flags
* *
* Update the page tables using the CP (cayman-si). * Update the page tables using the CP (cayman-si).
*/ */
void cayman_vm_set_page(struct radeon_device *rdev, struct radeon_vm *vm, void cayman_vm_set_page(struct radeon_device *rdev, uint64_t pe,
unsigned pfn, struct ttm_mem_reg *mem, uint64_t addr, unsigned count,
unsigned npages, uint32_t flags) uint32_t incr, uint32_t flags)
{ {
struct radeon_ring *ring = &rdev->ring[rdev->asic->vm.pt_ring_index]; struct radeon_ring *ring = &rdev->ring[rdev->asic->vm.pt_ring_index];
uint64_t addr, pt = vm->pt_gpu_addr + pfn * 8; uint32_t r600_flags = cayman_vm_page_flags(rdev, flags);
int i; int i;
addr = flags = cayman_vm_page_flags(rdev, flags); radeon_ring_write(ring, PACKET3(PACKET3_ME_WRITE, 1 + count * 2));
radeon_ring_write(ring, pe);
radeon_ring_write(ring, PACKET3(PACKET3_ME_WRITE, 1 + npages * 2)); radeon_ring_write(ring, upper_32_bits(pe) & 0xff);
radeon_ring_write(ring, pt & 0xffffffff); for (i = 0; i < count; ++i) {
radeon_ring_write(ring, (pt >> 32) & 0xff); uint64_t value = 0;
for (i = 0; i < npages; ++i) { if (flags & RADEON_VM_PAGE_SYSTEM) {
if (mem) { value = radeon_vm_map_gart(rdev, addr);
addr = radeon_vm_get_addr(rdev, mem, i); value &= 0xFFFFFFFFFFFFF000ULL;
addr = addr & 0xFFFFFFFFFFFFF000ULL; addr += incr;
addr |= flags;
} else if (flags & RADEON_VM_PAGE_VALID) {
value = addr;
addr += incr;
} }
radeon_ring_write(ring, addr & 0xffffffff);
radeon_ring_write(ring, (addr >> 32) & 0xffffffff); value |= r600_flags;
radeon_ring_write(ring, value);
radeon_ring_write(ring, upper_32_bits(value));
} }
} }
......
...@@ -1141,9 +1141,9 @@ struct radeon_asic { ...@@ -1141,9 +1141,9 @@ struct radeon_asic {
void (*fini)(struct radeon_device *rdev); void (*fini)(struct radeon_device *rdev);
u32 pt_ring_index; u32 pt_ring_index;
void (*set_page)(struct radeon_device *rdev, struct radeon_vm *vm, void (*set_page)(struct radeon_device *rdev, uint64_t pe,
unsigned pfn, struct ttm_mem_reg *mem, uint64_t addr, unsigned count,
unsigned npages, uint32_t flags); uint32_t incr, uint32_t flags);
} vm; } vm;
/* ring specific callbacks */ /* ring specific callbacks */
struct { struct {
...@@ -1757,7 +1757,7 @@ void radeon_ring_write(struct radeon_ring *ring, uint32_t v); ...@@ -1757,7 +1757,7 @@ void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
#define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart.set_page((rdev), (i), (p)) #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart.set_page((rdev), (i), (p))
#define radeon_asic_vm_init(rdev) (rdev)->asic->vm.init((rdev)) #define radeon_asic_vm_init(rdev) (rdev)->asic->vm.init((rdev))
#define radeon_asic_vm_fini(rdev) (rdev)->asic->vm.fini((rdev)) #define radeon_asic_vm_fini(rdev) (rdev)->asic->vm.fini((rdev))
#define radeon_asic_vm_set_page(rdev, v, pfn, mem, npages, flags) (rdev)->asic->vm.set_page((rdev), (v), (pfn), (mem), (npages), (flags)) #define radeon_asic_vm_set_page(rdev, pe, addr, count, incr, flags) ((rdev)->asic->vm.set_page((rdev), (pe), (addr), (count), (incr), (flags)))
#define radeon_ring_start(rdev, r, cp) (rdev)->asic->ring[(r)].ring_start((rdev), (cp)) #define radeon_ring_start(rdev, r, cp) (rdev)->asic->ring[(r)].ring_start((rdev), (cp))
#define radeon_ring_test(rdev, r, cp) (rdev)->asic->ring[(r)].ring_test((rdev), (cp)) #define radeon_ring_test(rdev, r, cp) (rdev)->asic->ring[(r)].ring_test((rdev), (cp))
#define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)].ib_test((rdev), (cp)) #define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)].ib_test((rdev), (cp))
...@@ -1843,9 +1843,7 @@ struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev, ...@@ -1843,9 +1843,7 @@ struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev,
void radeon_vm_fence(struct radeon_device *rdev, void radeon_vm_fence(struct radeon_device *rdev,
struct radeon_vm *vm, struct radeon_vm *vm,
struct radeon_fence *fence); struct radeon_fence *fence);
u64 radeon_vm_get_addr(struct radeon_device *rdev, uint64_t radeon_vm_map_gart(struct radeon_device *rdev, uint64_t addr);
struct ttm_mem_reg *mem,
unsigned pfn);
int radeon_vm_bo_update_pte(struct radeon_device *rdev, int radeon_vm_bo_update_pte(struct radeon_device *rdev,
struct radeon_vm *vm, struct radeon_vm *vm,
struct radeon_bo *bo, struct radeon_bo *bo,
......
...@@ -444,9 +444,9 @@ int cayman_vm_init(struct radeon_device *rdev); ...@@ -444,9 +444,9 @@ int cayman_vm_init(struct radeon_device *rdev);
void cayman_vm_fini(struct radeon_device *rdev); void cayman_vm_fini(struct radeon_device *rdev);
void cayman_vm_flush(struct radeon_device *rdev, struct radeon_ib *ib); void cayman_vm_flush(struct radeon_device *rdev, struct radeon_ib *ib);
uint32_t cayman_vm_page_flags(struct radeon_device *rdev, uint32_t flags); uint32_t cayman_vm_page_flags(struct radeon_device *rdev, uint32_t flags);
void cayman_vm_set_page(struct radeon_device *rdev, struct radeon_vm *vm, void cayman_vm_set_page(struct radeon_device *rdev, uint64_t pe,
unsigned pfn, struct ttm_mem_reg *mem, uint64_t addr, unsigned count,
unsigned npages, uint32_t flags); uint32_t incr, uint32_t flags);
int evergreen_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib); int evergreen_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib);
/* DCE6 - SI */ /* DCE6 - SI */
......
...@@ -822,42 +822,26 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev, ...@@ -822,42 +822,26 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
} }
/** /**
* radeon_vm_get_addr - get the physical address of the page * radeon_vm_map_gart - get the physical address of a gart page
* *
* @rdev: radeon_device pointer * @rdev: radeon_device pointer
* @mem: ttm mem * @addr: the unmapped addr
* @pfn: pfn
* *
* Look up the physical address of the page that the pte resolves * Look up the physical address of the page that the pte resolves
* to (cayman+). * to (cayman+).
* Returns the physical address of the page. * Returns the physical address of the page.
*/ */
u64 radeon_vm_get_addr(struct radeon_device *rdev, uint64_t radeon_vm_map_gart(struct radeon_device *rdev, uint64_t addr)
struct ttm_mem_reg *mem,
unsigned pfn)
{ {
u64 addr = 0; uint64_t result;
switch (mem->mem_type) { /* page table offset */
case TTM_PL_VRAM: result = rdev->gart.pages_addr[addr >> PAGE_SHIFT];
addr = (mem->start << PAGE_SHIFT);
addr += pfn * RADEON_GPU_PAGE_SIZE; /* in case cpu page size != gpu page size*/
addr += rdev->vm_manager.vram_base_offset; result |= addr & (~PAGE_MASK);
break;
case TTM_PL_TT: return result;
/* offset inside page table */
addr = mem->start << PAGE_SHIFT;
addr += pfn * RADEON_GPU_PAGE_SIZE;
addr = addr >> PAGE_SHIFT;
/* page table offset */
addr = rdev->gart.pages_addr[addr];
/* in case cpu page size != gpu page size*/
addr += (pfn * RADEON_GPU_PAGE_SIZE) & (~PAGE_MASK);
break;
default:
break;
}
return addr;
} }
/** /**
...@@ -883,7 +867,7 @@ int radeon_vm_bo_update_pte(struct radeon_device *rdev, ...@@ -883,7 +867,7 @@ int radeon_vm_bo_update_pte(struct radeon_device *rdev,
struct radeon_semaphore *sem = NULL; struct radeon_semaphore *sem = NULL;
struct radeon_bo_va *bo_va; struct radeon_bo_va *bo_va;
unsigned ngpu_pages, ndw; unsigned ngpu_pages, ndw;
uint64_t pfn; uint64_t pfn, addr;
int r; int r;
/* nothing to do if vm isn't bound */ /* nothing to do if vm isn't bound */
...@@ -908,21 +892,22 @@ int radeon_vm_bo_update_pte(struct radeon_device *rdev, ...@@ -908,21 +892,22 @@ int radeon_vm_bo_update_pte(struct radeon_device *rdev,
ngpu_pages = radeon_bo_ngpu_pages(bo); ngpu_pages = radeon_bo_ngpu_pages(bo);
bo_va->flags &= ~RADEON_VM_PAGE_VALID; bo_va->flags &= ~RADEON_VM_PAGE_VALID;
bo_va->flags &= ~RADEON_VM_PAGE_SYSTEM; bo_va->flags &= ~RADEON_VM_PAGE_SYSTEM;
pfn = bo_va->soffset / RADEON_GPU_PAGE_SIZE;
if (mem) { if (mem) {
addr = mem->start << PAGE_SHIFT;
if (mem->mem_type != TTM_PL_SYSTEM) { if (mem->mem_type != TTM_PL_SYSTEM) {
bo_va->flags |= RADEON_VM_PAGE_VALID; bo_va->flags |= RADEON_VM_PAGE_VALID;
bo_va->valid = true; bo_va->valid = true;
} }
if (mem->mem_type == TTM_PL_TT) { if (mem->mem_type == TTM_PL_TT) {
bo_va->flags |= RADEON_VM_PAGE_SYSTEM; bo_va->flags |= RADEON_VM_PAGE_SYSTEM;
} } else {
if (!bo_va->valid) { addr += rdev->vm_manager.vram_base_offset;
mem = NULL;
} }
} else { } else {
addr = 0;
bo_va->valid = false; bo_va->valid = false;
} }
pfn = bo_va->soffset / RADEON_GPU_PAGE_SIZE;
if (vm->fence && radeon_fence_signaled(vm->fence)) { if (vm->fence && radeon_fence_signaled(vm->fence)) {
radeon_fence_unref(&vm->fence); radeon_fence_unref(&vm->fence);
...@@ -950,7 +935,8 @@ int radeon_vm_bo_update_pte(struct radeon_device *rdev, ...@@ -950,7 +935,8 @@ int radeon_vm_bo_update_pte(struct radeon_device *rdev,
radeon_fence_note_sync(vm->fence, ridx); radeon_fence_note_sync(vm->fence, ridx);
} }
radeon_asic_vm_set_page(rdev, vm, pfn, mem, ngpu_pages, bo_va->flags); radeon_asic_vm_set_page(rdev, vm->pt_gpu_addr + pfn * 8, addr,
ngpu_pages, RADEON_GPU_PAGE_SIZE, bo_va->flags);
radeon_fence_unref(&vm->fence); radeon_fence_unref(&vm->fence);
r = radeon_fence_emit(rdev, &vm->fence, ridx); r = radeon_fence_emit(rdev, &vm->fence, ridx);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment