Re: [PATCH 2/2] drm/amdgpu: Support IOMMU on Raven

2017-07-28 Thread Christian König

Am 27.07.2017 um 21:48 schrieb Yong Zhao:

We achieved that by setting S(SYSTEM) and P(PDE as PTE) bit to 1 for
PDEs and setting S bit to 1 for PTEs when the corresponding addresses
are not occupied by gpu driver allocated buffers.

Change-Id: I52e41b6e93243dbbd08d97781da1c9a60ce1f9a4
Signed-off-by: Yong Zhao 


Reviewed-by: Christian König 


---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 29 -
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  3 +++
  2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 9325f39..d152724 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -288,6 +288,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device 
*adev,
unsigned pt_idx, from, to;
int r;
u64 flags;
+   uint64_t init_value = 0;
  
  	if (!parent->entries) {

unsigned num_entries = amdgpu_vm_num_entries(adev, level);
@@ -320,6 +321,12 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device 
*adev,
flags |= (AMDGPU_GEM_CREATE_NO_CPU_ACCESS |
AMDGPU_GEM_CREATE_SHADOW);
  
+	if (vm->pte_support_ats) {

+   init_value = AMDGPU_PTE_SYSTEM;
+   if (level != adev->vm_manager.num_level - 1)
+   init_value |= AMDGPU_PDE_PTE;
+   }
+
/* walk over the address space and allocate the page tables */
for (pt_idx = from; pt_idx <= to; ++pt_idx) {
struct reservation_object *resv = vm->root.bo->tbo.resv;
@@ -332,7 +339,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device 
*adev,
 AMDGPU_GPU_PAGE_SIZE, true,
 AMDGPU_GEM_DOMAIN_VRAM,
 flags,
-NULL, resv, 0, );
+NULL, resv, init_value, );
if (r)
return r;
  
@@ -1994,15 +2001,19 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev,

struct amdgpu_bo_va_mapping *mapping;
struct dma_fence *f = NULL;
int r;
+   uint64_t init_pte_value = 0;
  
  	while (!list_empty(>freed)) {

mapping = list_first_entry(>freed,
struct amdgpu_bo_va_mapping, list);
list_del(>list);
  
+		if (vm->pte_support_ats)

+   init_pte_value = AMDGPU_PTE_SYSTEM;
+
r = amdgpu_vm_bo_update_mapping(adev, NULL, 0, NULL, vm,
mapping->start, mapping->last,
-   0, 0, );
+   init_pte_value, 0, );
amdgpu_vm_free_mapping(adev, vm, mapping, f);
if (r) {
dma_fence_put(f);
@@ -2493,6 +2504,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct 
amdgpu_vm *vm,
struct amd_sched_rq *rq;
int r, i;
u64 flags;
+   uint64_t init_pde_value = 0;
  
  	vm->va = RB_ROOT;

vm->client_id = atomic64_inc_return(>vm_manager.client_counter);
@@ -2514,10 +2526,17 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct 
amdgpu_vm *vm,
if (r)
return r;
  
-	if (vm_context == AMDGPU_VM_CONTEXT_COMPUTE)

+   vm->pte_support_ats = false;
+
+   if (vm_context == AMDGPU_VM_CONTEXT_COMPUTE) {
vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode &
AMDGPU_VM_USE_CPU_FOR_COMPUTE);
-   else
+
+   if (adev->asic_type == CHIP_RAVEN) {
+   vm->pte_support_ats = true;
+   init_pde_value = AMDGPU_PTE_SYSTEM | AMDGPU_PDE_PTE;
+   }
+   } else
vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode &
AMDGPU_VM_USE_CPU_FOR_GFX);
DRM_DEBUG_DRIVER("VM update mode is %s\n",
@@ -2537,7 +2556,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct 
amdgpu_vm *vm,
r = amdgpu_bo_create(adev, amdgpu_vm_bo_size(adev, 0), align, true,
 AMDGPU_GEM_DOMAIN_VRAM,
 flags,
-NULL, NULL, 0, >root.bo);
+NULL, NULL, init_pde_value, >root.bo);
if (r)
goto error_free_sched_entity;
  
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

index 34d9174..217ecba 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -146,6 +146,9 @@ struct amdgpu_vm {
  
  	/* Flag to indicate if VM tables are updated by CPU 

Re: [PATCH 2/2] drm/amdgpu: Support IOMMU on Raven

2017-07-27 Thread Christian König

Am 26.07.2017 um 22:46 schrieb Yong Zhao:

We achieved that by setting the PTEs to 2 (the SYSTEM bit is set) when
the corresponding addresses are not occupied by gpu driver allocated
buffers.

Change-Id: I995c11c7a25bdaf7a16700d9e08a8fe287d49417
Signed-off-by: Yong Zhao 


[SNIP]


diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 833b172..4271243 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -132,14 +132,16 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
bool kernel, u32 domain, u64 flags,
struct sg_table *sg,
struct reservation_object *resv,
-   struct amdgpu_bo **bo_ptr);
+   struct amdgpu_bo **bo_ptr,
+   uint64_t init_value);
Two comments here: The new parameter init_value should come before 
bo_ptr, cause bo_ptr is the result of the function. And please split up 
that change into a separate patch.


Apart from that the change looks good to me,
Christian.
___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 2/2] drm/amdgpu: Support IOMMU on Raven

2017-07-26 Thread Yong Zhao
We achieved that by setting the PTEs to 2 (the SYSTEM bit is set) when
the corresponding addresses are not occupied by gpu driver allocated
buffers.

Change-Id: I995c11c7a25bdaf7a16700d9e08a8fe287d49417
Signed-off-by: Yong Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c|  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c|  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c| 18 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h|  6 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c|  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_test.c  |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c   |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c   |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c| 27 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h|  3 +++
 drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c |  4 ++--
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 10 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c |  6 +++---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c |  4 ++--
 21 files changed, 70 insertions(+), 42 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index 2292c77..fce2fa5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -185,7 +185,7 @@ int alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
return -ENOMEM;
 
r = amdgpu_bo_create(adev, size, PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_GTT,
-AMDGPU_GEM_CREATE_CPU_GTT_USWC, NULL, NULL, 
&(*mem)->bo);
+AMDGPU_GEM_CREATE_CPU_GTT_USWC, NULL, NULL, 
&(*mem)->bo, 0);
if (r) {
dev_err(adev->dev,
"failed to allocate BO for amdkfd (%d)\n", r);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
index 2fb299a..56445ec 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
@@ -81,7 +81,7 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, 
unsigned size,
 
n = AMDGPU_BENCHMARK_ITERATIONS;
r = amdgpu_bo_create(adev, size, PAGE_SIZE, true, sdomain, 0, NULL,
-NULL, );
+NULL, , 0);
if (r) {
goto out_cleanup;
}
@@ -94,7 +94,7 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, 
unsigned size,
goto out_cleanup;
}
r = amdgpu_bo_create(adev, size, PAGE_SIZE, true, ddomain, 0, NULL,
-NULL, );
+NULL, , 0);
if (r) {
goto out_cleanup;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
index 3d41cd4..ce19419 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
@@ -124,7 +124,7 @@ static int amdgpu_cgs_alloc_gpu_mem(struct cgs_device 
*cgs_device,
ret = amdgpu_bo_create_restricted(adev, size, PAGE_SIZE,
  true, domain, flags,
  NULL, , NULL,
- );
+ , 0);
if (ret) {
DRM_ERROR("(%d) bo create failed\n", ret);
return ret;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index fe6783e..d8cd14f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -344,7 +344,7 @@ static int amdgpu_vram_scratch_init(struct amdgpu_device 
*adev)
 PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_VRAM,
 AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
 AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-NULL, NULL, >vram_scratch.robj);
+NULL, NULL, >vram_scratch.robj, 0);
if (r) {
return r;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
index 124b237..a6d7f55 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
@@ -141,7 +141,7 @@ int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev)