aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c95
1 files changed, 78 insertions, 17 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index e7dfb7b44b4b..21adb1b6e5cb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -22,7 +22,21 @@
22 */ 22 */
23 23
24#include "amdgpu.h" 24#include "amdgpu.h"
25#define MAX_KIQ_REG_WAIT 100000000 /* in usecs */ 25#define MAX_KIQ_REG_WAIT 5000 /* in usecs, 5ms */
26#define MAX_KIQ_REG_BAILOUT_INTERVAL 5 /* in msecs, 5ms */
27#define MAX_KIQ_REG_TRY 20
28
29uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev)
30{
31 uint64_t addr = adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT;
32
33 addr -= AMDGPU_VA_RESERVED_SIZE;
34
35 if (addr >= AMDGPU_VA_HOLE_START)
36 addr |= AMDGPU_VA_HOLE_END;
37
38 return addr;
39}
26 40
27bool amdgpu_virt_mmio_blocked(struct amdgpu_device *adev) 41bool amdgpu_virt_mmio_blocked(struct amdgpu_device *adev)
28{ 42{
@@ -55,14 +69,14 @@ void amdgpu_free_static_csa(struct amdgpu_device *adev) {
55 69
56/* 70/*
57 * amdgpu_map_static_csa should be called during amdgpu_vm_init 71 * amdgpu_map_static_csa should be called during amdgpu_vm_init
58 * it maps virtual address "AMDGPU_VA_RESERVED_SIZE - AMDGPU_CSA_SIZE" 72 * it maps virtual address amdgpu_csa_vaddr() to this VM, and each command
59 * to this VM, and each command submission of GFX should use this virtual 73 * submission of GFX should use this virtual address within META_DATA init
60 * address within META_DATA init package to support SRIOV gfx preemption. 74 * package to support SRIOV gfx preemption.
61 */ 75 */
62
63int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm, 76int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,
64 struct amdgpu_bo_va **bo_va) 77 struct amdgpu_bo_va **bo_va)
65{ 78{
79 uint64_t csa_addr = amdgpu_csa_vaddr(adev) & AMDGPU_VA_HOLE_MASK;
66 struct ww_acquire_ctx ticket; 80 struct ww_acquire_ctx ticket;
67 struct list_head list; 81 struct list_head list;
68 struct amdgpu_bo_list_entry pd; 82 struct amdgpu_bo_list_entry pd;
@@ -90,7 +104,7 @@ int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,
90 return -ENOMEM; 104 return -ENOMEM;
91 } 105 }
92 106
93 r = amdgpu_vm_alloc_pts(adev, (*bo_va)->base.vm, AMDGPU_CSA_VADDR, 107 r = amdgpu_vm_alloc_pts(adev, (*bo_va)->base.vm, csa_addr,
94 AMDGPU_CSA_SIZE); 108 AMDGPU_CSA_SIZE);
95 if (r) { 109 if (r) {
96 DRM_ERROR("failed to allocate pts for static CSA, err=%d\n", r); 110 DRM_ERROR("failed to allocate pts for static CSA, err=%d\n", r);
@@ -99,7 +113,7 @@ int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,
99 return r; 113 return r;
100 } 114 }
101 115
102 r = amdgpu_vm_bo_map(adev, *bo_va, AMDGPU_CSA_VADDR, 0, AMDGPU_CSA_SIZE, 116 r = amdgpu_vm_bo_map(adev, *bo_va, csa_addr, 0, AMDGPU_CSA_SIZE,
103 AMDGPU_PTE_READABLE | AMDGPU_PTE_WRITEABLE | 117 AMDGPU_PTE_READABLE | AMDGPU_PTE_WRITEABLE |
104 AMDGPU_PTE_EXECUTABLE); 118 AMDGPU_PTE_EXECUTABLE);
105 119
@@ -125,9 +139,9 @@ void amdgpu_virt_init_setting(struct amdgpu_device *adev)
125 139
126uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) 140uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg)
127{ 141{
128 signed long r; 142 signed long r, cnt = 0;
129 unsigned long flags; 143 unsigned long flags;
130 uint32_t val, seq; 144 uint32_t seq;
131 struct amdgpu_kiq *kiq = &adev->gfx.kiq; 145 struct amdgpu_kiq *kiq = &adev->gfx.kiq;
132 struct amdgpu_ring *ring = &kiq->ring; 146 struct amdgpu_ring *ring = &kiq->ring;
133 147
@@ -141,18 +155,39 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg)
141 spin_unlock_irqrestore(&kiq->ring_lock, flags); 155 spin_unlock_irqrestore(&kiq->ring_lock, flags);
142 156
143 r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT); 157 r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
144 if (r < 1) { 158
145 DRM_ERROR("wait for kiq fence error: %ld\n", r); 159 /* don't wait anymore for gpu reset case because this way may
146 return ~0; 160 * block gpu_recover() routine forever, e.g. this virt_kiq_rreg
161 * is triggered in TTM and ttm_bo_lock_delayed_workqueue() will
162 * never return if we keep waiting in virt_kiq_rreg, which cause
163 * gpu_recover() hang there.
164 *
165 * also don't wait anymore for IRQ context
166 * */
167 if (r < 1 && (adev->in_gpu_reset || in_interrupt()))
168 goto failed_kiq_read;
169
170 if (in_interrupt())
171 might_sleep();
172
173 while (r < 1 && cnt++ < MAX_KIQ_REG_TRY) {
174 msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
175 r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
147 } 176 }
148 val = adev->wb.wb[adev->virt.reg_val_offs];
149 177
150 return val; 178 if (cnt > MAX_KIQ_REG_TRY)
179 goto failed_kiq_read;
180
181 return adev->wb.wb[adev->virt.reg_val_offs];
182
183failed_kiq_read:
184 pr_err("failed to read reg:%x\n", reg);
185 return ~0;
151} 186}
152 187
153void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) 188void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
154{ 189{
155 signed long r; 190 signed long r, cnt = 0;
156 unsigned long flags; 191 unsigned long flags;
157 uint32_t seq; 192 uint32_t seq;
158 struct amdgpu_kiq *kiq = &adev->gfx.kiq; 193 struct amdgpu_kiq *kiq = &adev->gfx.kiq;
@@ -168,8 +203,34 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
168 spin_unlock_irqrestore(&kiq->ring_lock, flags); 203 spin_unlock_irqrestore(&kiq->ring_lock, flags);
169 204
170 r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT); 205 r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
171 if (r < 1) 206
172 DRM_ERROR("wait for kiq fence error: %ld\n", r); 207 /* don't wait anymore for gpu reset case because this way may
208 * block gpu_recover() routine forever, e.g. this virt_kiq_rreg
209 * is triggered in TTM and ttm_bo_lock_delayed_workqueue() will
210 * never return if we keep waiting in virt_kiq_rreg, which cause
211 * gpu_recover() hang there.
212 *
213 * also don't wait anymore for IRQ context
214 * */
215 if (r < 1 && (adev->in_gpu_reset || in_interrupt()))
216 goto failed_kiq_write;
217
218 if (in_interrupt())
219 might_sleep();
220
221 while (r < 1 && cnt++ < MAX_KIQ_REG_TRY) {
222
223 msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
224 r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
225 }
226
227 if (cnt > MAX_KIQ_REG_TRY)
228 goto failed_kiq_write;
229
230 return;
231
232failed_kiq_write:
233 pr_err("failed to write reg:%x\n", reg);
173} 234}
174 235
175/** 236/**