aboutsummaryrefslogtreecommitdiffstats
path: root/common/recipes-kernel/linux/files/0031-drm-amdgpu-split-VM-PD-and-PT-handling-during-CS.patch
blob: 4f646fee14c511075633ea040e93dc74e86ebe67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
From e80b9ea2005233764ff7bac3ed1ef49732bdaa05 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20K=C3=B6nig?= <christian.koenig@amd.com>
Date: Fri, 11 Dec 2015 15:16:32 +0100
Subject: [PATCH 0031/1110] drm/amdgpu: split VM PD and PT handling during CS
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This way we avoid the extra allocation for the page directory entry.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Kalyan Alle <kalyan.alle@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  6 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |  9 ++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 16 +++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  | 39 ++++++++++++++++++++++++---------
 4 files changed, 52 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 1447a5e..638b089 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -986,6 +986,11 @@ struct amdgpu_bo_list_entry *amdgpu_vm_get_bos(struct amdgpu_device *adev,
                                                struct amdgpu_vm *vm,
                                                struct list_head *validated,
                                                struct list_head *duplicates);
+void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
+                         struct list_head *validated,
+                         struct amdgpu_bo_list_entry *entry);
+struct amdgpu_bo_list_entry *amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm,
+                                                  struct list_head *duplicates);
 int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
 		      struct amdgpu_sync *sync);
 void amdgpu_vm_flush(struct amdgpu_ring *ring,
@@ -1255,6 +1260,7 @@ struct amdgpu_cs_parser {
 	unsigned		nchunks;
 	struct amdgpu_cs_chunk	*chunks;
 	/* relocations */
+        struct amdgpu_bo_list_entry     vm_pd;
 	struct amdgpu_bo_list_entry	*vm_bos;
 	struct list_head	validated;
 	struct fence		*fence;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 1d52144..1ff138e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -407,8 +407,7 @@ static int amdgpu_cs_parser_relocs(struct amdgpu_cs_parser *p)
 	}
 
         INIT_LIST_HEAD(&duplicates);
-	p->vm_bos = amdgpu_vm_get_bos(p->adev, &fpriv->vm,
-                                      &p->validated, &duplicates);
+        amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd);
 
 	if (p->uf.bo)
 		list_add(&p->uf_entry.tv.head, &p->validated);
@@ -420,6 +419,12 @@ static int amdgpu_cs_parser_relocs(struct amdgpu_cs_parser *p)
 	if (unlikely(r != 0))
 		goto error_reserve;
 
+        p->vm_bos = amdgpu_vm_get_pt_bos(&fpriv->vm, &duplicates);
+        if (!p->vm_bos) {
+                r = -ENOMEM;
+                goto error_validate;
+        }
+
 	r = amdgpu_cs_list_validate(p->adev, &fpriv->vm, &p->validated);
 	if (r)
 		goto error_validate;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index df0444f..b1d44ce 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -449,6 +449,7 @@ static void amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
 {
 	struct ttm_validate_buffer tv, *entry;
 	struct amdgpu_bo_list_entry *vm_bos;
+        struct amdgpu_bo_list_entry vm_pd;
 	struct ww_acquire_ctx ticket;
 	struct list_head list, duplicates;
 	unsigned domain;
@@ -461,14 +462,18 @@ static void amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
 	tv.shared = true;
 	list_add(&tv.head, &list);
 
-        vm_bos = amdgpu_vm_get_bos(adev, bo_va->vm, &list, &duplicates);
-	if (!vm_bos)
-		return;
+        amdgpu_vm_get_pd_bo(bo_va->vm, &list, &vm_pd);
 
 	/* Provide duplicates to avoid -EALREADY */
 	r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates);
 	if (r)
-		goto error_free;
+                goto error_print;
+ 
+        vm_bos = amdgpu_vm_get_pt_bos(bo_va->vm, &duplicates);
+        if (!vm_bos) {
+                r = -ENOMEM;
+                goto error_unreserve;
+        }
 
 	list_for_each_entry(entry, &list, head) {
 		domain = amdgpu_mem_type_to_domain(entry->bo->mem.mem_type);
@@ -498,10 +503,9 @@ static void amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
 
 error_unreserve:
 	ttm_eu_backoff_reservation(&ticket, &list);
-
-error_free:
 	drm_free_large(vm_bos);
 
+error_print:
 	if (r && r != -ERESTARTSYS)
 		DRM_ERROR("Couldn't update BO_VA (%d)\n", r);
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 3c3404f..396ab85 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -75,27 +75,46 @@ static unsigned amdgpu_vm_directory_size(struct amdgpu_device *adev)
 }
 
 /**
- * amdgpu_vm_get_bos - add the vm BOs to a validation list
- *
+ * amdgpu_vm_get_pd_bo - add the VM PD to a validation list
  * @vm: vm providing the BOs
  * @validated: head of validation list
+ * @entry: entry to add
+ *
+ * Add the page directory to the list of BOs to
+ * validate for command submission.
+ */
+void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
+                        struct list_head *validated,
+                        struct amdgpu_bo_list_entry *entry)
+{
+        entry->robj = vm->page_directory;
+        entry->prefered_domains = AMDGPU_GEM_DOMAIN_VRAM;
+        entry->allowed_domains = AMDGPU_GEM_DOMAIN_VRAM;
+        entry->priority = 0;
+        entry->tv.bo = &vm->page_directory->tbo;
+        entry->tv.shared = true;
+        list_add(&entry->tv.head, validated);
+}
+
+/**
++ * amdgpu_vm_get_bos - add the vm BOs to a validation list
++ *
++ * @vm: vm providing the BOs
  * @duplicates: head of duplicates list
 
- *
  * Add the page directory to the list of BOs to
  * validate for command submission (cayman+).
  */
-struct amdgpu_bo_list_entry *amdgpu_vm_get_bos(struct amdgpu_device *adev,
-                                               struct amdgpu_vm *vm,
-                                               struct list_head *validated,
-                                               struct list_head *duplicates)
+struct amdgpu_bo_list_entry *amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm,
+                                                  struct list_head *duplicates)
+
 {
 	struct amdgpu_bo_list_entry *list;
 	unsigned i, idx;
 
-	list = drm_malloc_ab(vm->max_pde_used + 2,
+        list = drm_malloc_ab(vm->max_pde_used + 1,
 			     sizeof(struct amdgpu_bo_list_entry));
-	if (!list) {
+        if (!list)
 		return NULL;
 	}
 
@@ -108,7 +127,7 @@ struct amdgpu_bo_list_entry *amdgpu_vm_get_bos(struct amdgpu_device *adev,
 	list[0].tv.shared = true;
         list_add(&list[0].tv.head, validated);
 
-	for (i = 0, idx = 1; i <= vm->max_pde_used; i++) {
+        for (i = 0, idx = 0; i <= vm->max_pde_used; i++) {
 		if (!vm->page_tables[i].bo)
 			continue;
 
-- 
2.7.4