aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2015-11-04 19:57:25 -0500
committerDave Airlie <airlied@redhat.com>2015-11-04 19:57:25 -0500
commit793423ffcb229ae5654b382a1356906f81da2018 (patch)
treec95dcf05246a9c44d9ce15f4d9fb1c4012598fe5 /drivers/gpu/drm/amd/amdgpu
parentbf248ca1f5c7ba1e535ba4bd517a15a1ae965c69 (diff)
parenta95e264254dca5b6bfb331d5902930d0787bd7e1 (diff)
Merge branch 'drm-next-4.4' of git://people.freedesktop.org/~agd5f/linux into drm-next
- Updated register headers for GFX 8.1 for Stoney - Add some new CZ revisions - minor pageflip optimizations - Fencing clean up - Warning fix - More fence cleanup - oops fix - Fiji fixes * 'drm-next-4.4' of git://people.freedesktop.org/~agd5f/linux: (29 commits) drm/amdgpu: group together common fence implementation drm/amdgpu: remove AMDGPU_FENCE_OWNER_MOVE drm/amdgpu: remove now unused fence functions drm/amdgpu: fix fence fallback check drm/amdgpu: fix stoping the scheduler timeout drm/amdgpu: cleanup on error in amdgpu_cs_ioctl() drm/amdgpu: update Fiji's Golden setting drm/amdgpu: update Fiji's rev id drm/amdgpu: extract common code in vi_common_early_init drm/amd/scheduler: don't oops on failure to load drm/amdgpu: don't oops on failure to load (v2) drm/amdgpu: don't VT switch on suspend drm/amdgpu: Make amdgpu_mn functions inline drm/amdgpu: remove amdgpu_fence_ref/unref drm/amdgpu: use common fence for sync drm/amdgpu: use the new fence_is_later drm/amdgpu: use common fences for VMID management v2 drm/amdgpu: move ring_from_fence to common code drm/amdgpu: switch to common fence_wait_any_timeout v2 drm/amdgpu: remove unneeded fence functions ...
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu.h58
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c6
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c3
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c1
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c345
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c3
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c24
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c43
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c3
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c55
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c27
-rw-r--r--drivers/gpu/drm/amd/amdgpu/dce_v10_0.c36
-rw-r--r--drivers/gpu/drm/amd/amdgpu/dce_v11_0.c34
-rw-r--r--drivers/gpu/drm/amd/amdgpu/dce_v8_0.c38
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c29
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c4
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c4
-rw-r--r--drivers/gpu/drm/amd/amdgpu/vi.c14
19 files changed, 261 insertions, 468 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 5c400f4b87fd..de9312c02185 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -405,7 +405,6 @@ struct amdgpu_fence_driver {
405/* some special values for the owner field */ 405/* some special values for the owner field */
406#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul) 406#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
407#define AMDGPU_FENCE_OWNER_VM ((void*)1ul) 407#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
408#define AMDGPU_FENCE_OWNER_MOVE ((void*)2ul)
409 408
410#define AMDGPU_FENCE_FLAG_64BIT (1 << 0) 409#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
411#define AMDGPU_FENCE_FLAG_INT (1 << 1) 410#define AMDGPU_FENCE_FLAG_INT (1 << 1)
@@ -447,57 +446,11 @@ int amdgpu_fence_wait_next(struct amdgpu_ring *ring);
447int amdgpu_fence_wait_empty(struct amdgpu_ring *ring); 446int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
448unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring); 447unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
449 448
450signed long amdgpu_fence_wait_any(struct fence **array,
451 uint32_t count,
452 bool intr,
453 signed long t);
454struct amdgpu_fence *amdgpu_fence_ref(struct amdgpu_fence *fence);
455void amdgpu_fence_unref(struct amdgpu_fence **fence);
456
457bool amdgpu_fence_need_sync(struct amdgpu_fence *fence, 449bool amdgpu_fence_need_sync(struct amdgpu_fence *fence,
458 struct amdgpu_ring *ring); 450 struct amdgpu_ring *ring);
459void amdgpu_fence_note_sync(struct amdgpu_fence *fence, 451void amdgpu_fence_note_sync(struct amdgpu_fence *fence,
460 struct amdgpu_ring *ring); 452 struct amdgpu_ring *ring);
461 453
462static inline struct amdgpu_fence *amdgpu_fence_later(struct amdgpu_fence *a,
463 struct amdgpu_fence *b)
464{
465 if (!a) {
466 return b;
467 }
468
469 if (!b) {
470 return a;
471 }
472
473 BUG_ON(a->ring != b->ring);
474
475 if (a->seq > b->seq) {
476 return a;
477 } else {
478 return b;
479 }
480}
481
482static inline bool amdgpu_fence_is_earlier(struct amdgpu_fence *a,
483 struct amdgpu_fence *b)
484{
485 if (!a) {
486 return false;
487 }
488
489 if (!b) {
490 return true;
491 }
492
493 BUG_ON(a->ring != b->ring);
494
495 return a->seq < b->seq;
496}
497
498int amdgpu_user_fence_emit(struct amdgpu_ring *ring, struct amdgpu_user_fence *user,
499 void *owner, struct amdgpu_fence **fence);
500
501/* 454/*
502 * TTM. 455 * TTM.
503 */ 456 */
@@ -708,7 +661,7 @@ void amdgpu_semaphore_free(struct amdgpu_device *adev,
708 */ 661 */
709struct amdgpu_sync { 662struct amdgpu_sync {
710 struct amdgpu_semaphore *semaphores[AMDGPU_NUM_SYNCS]; 663 struct amdgpu_semaphore *semaphores[AMDGPU_NUM_SYNCS];
711 struct amdgpu_fence *sync_to[AMDGPU_MAX_RINGS]; 664 struct fence *sync_to[AMDGPU_MAX_RINGS];
712 DECLARE_HASHTABLE(fences, 4); 665 DECLARE_HASHTABLE(fences, 4);
713 struct fence *last_vm_update; 666 struct fence *last_vm_update;
714}; 667};
@@ -974,7 +927,7 @@ struct amdgpu_vm_id {
974 /* last flushed PD/PT update */ 927 /* last flushed PD/PT update */
975 struct fence *flushed_updates; 928 struct fence *flushed_updates;
976 /* last use of vmid */ 929 /* last use of vmid */
977 struct amdgpu_fence *last_id_use; 930 struct fence *last_id_use;
978}; 931};
979 932
980struct amdgpu_vm { 933struct amdgpu_vm {
@@ -1007,7 +960,7 @@ struct amdgpu_vm {
1007}; 960};
1008 961
1009struct amdgpu_vm_manager { 962struct amdgpu_vm_manager {
1010 struct amdgpu_fence *active[AMDGPU_NUM_VM]; 963 struct fence *active[AMDGPU_NUM_VM];
1011 uint32_t max_pfn; 964 uint32_t max_pfn;
1012 /* number of VMIDs */ 965 /* number of VMIDs */
1013 unsigned nvm; 966 unsigned nvm;
@@ -1235,6 +1188,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
1235 struct amdgpu_irq_src *irq_src, unsigned irq_type, 1188 struct amdgpu_irq_src *irq_src, unsigned irq_type,
1236 enum amdgpu_ring_type ring_type); 1189 enum amdgpu_ring_type ring_type);
1237void amdgpu_ring_fini(struct amdgpu_ring *ring); 1190void amdgpu_ring_fini(struct amdgpu_ring *ring);
1191struct amdgpu_ring *amdgpu_ring_from_fence(struct fence *f);
1238 1192
1239/* 1193/*
1240 * CS. 1194 * CS.
@@ -1758,11 +1712,11 @@ void amdgpu_test_syncing(struct amdgpu_device *adev);
1758int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr); 1712int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1759void amdgpu_mn_unregister(struct amdgpu_bo *bo); 1713void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1760#else 1714#else
1761static int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr) 1715static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
1762{ 1716{
1763 return -ENODEV; 1717 return -ENODEV;
1764} 1718}
1765static void amdgpu_mn_unregister(struct amdgpu_bo *bo) {} 1719static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
1766#endif 1720#endif
1767 1721
1768/* 1722/*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 27ef52847e6d..dfc4d02c7a38 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -876,8 +876,10 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
876 struct amdgpu_job *job; 876 struct amdgpu_job *job;
877 struct amdgpu_ring * ring = parser->ibs->ring; 877 struct amdgpu_ring * ring = parser->ibs->ring;
878 job = kzalloc(sizeof(struct amdgpu_job), GFP_KERNEL); 878 job = kzalloc(sizeof(struct amdgpu_job), GFP_KERNEL);
879 if (!job) 879 if (!job) {
880 return -ENOMEM; 880 r = -ENOMEM;
881 goto out;
882 }
881 job->base.sched = &ring->sched; 883 job->base.sched = &ring->sched;
882 job->base.s_entity = &parser->ctx->rings[ring->idx].entity; 884 job->base.s_entity = &parser->ctx->rings[ring->idx].entity;
883 job->adev = parser->adev; 885 job->adev = parser->adev;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index e0b80ccdfe8a..fec65f01c031 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -69,6 +69,9 @@ void amdgpu_ctx_fini(struct amdgpu_ctx *ctx)
69 struct amdgpu_device *adev = ctx->adev; 69 struct amdgpu_device *adev = ctx->adev;
70 unsigned i, j; 70 unsigned i, j;
71 71
72 if (!adev)
73 return;
74
72 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) 75 for (i = 0; i < AMDGPU_MAX_RINGS; ++i)
73 for (j = 0; j < AMDGPU_CTX_MAX_CS_PENDING; ++j) 76 for (j = 0; j < AMDGPU_CTX_MAX_CS_PENDING; ++j)
74 fence_put(ctx->rings[i].fences[j]); 77 fence_put(ctx->rings[i].fences[j]);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
index 96290d9cddca..093a8c618931 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
@@ -207,6 +207,7 @@ static int amdgpufb_create(struct drm_fb_helper *helper,
207 } 207 }
208 208
209 info->par = rfbdev; 209 info->par = rfbdev;
210 info->skip_vt_switch = true;
210 211
211 ret = amdgpu_framebuffer_init(adev->ddev, &rfbdev->rfb, &mode_cmd, gobj); 212 ret = amdgpu_framebuffer_init(adev->ddev, &rfbdev->rfb, &mode_cmd, gobj);
212 if (ret) { 213 if (ret) {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
index 003a219943f1..257d72205bb5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
@@ -137,42 +137,6 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, void *owner,
137} 137}
138 138
139/** 139/**
140 * amdgpu_fence_check_signaled - callback from fence_queue
141 *
142 * this function is called with fence_queue lock held, which is also used
143 * for the fence locking itself, so unlocked variants are used for
144 * fence_signal, and remove_wait_queue.
145 */
146static int amdgpu_fence_check_signaled(wait_queue_t *wait, unsigned mode, int flags, void *key)
147{
148 struct amdgpu_fence *fence;
149 struct amdgpu_device *adev;
150 u64 seq;
151 int ret;
152
153 fence = container_of(wait, struct amdgpu_fence, fence_wake);
154 adev = fence->ring->adev;
155
156 /*
157 * We cannot use amdgpu_fence_process here because we're already
158 * in the waitqueue, in a call from wake_up_all.
159 */
160 seq = atomic64_read(&fence->ring->fence_drv.last_seq);
161 if (seq >= fence->seq) {
162 ret = fence_signal_locked(&fence->base);
163 if (!ret)
164 FENCE_TRACE(&fence->base, "signaled from irq context\n");
165 else
166 FENCE_TRACE(&fence->base, "was already signaled\n");
167
168 __remove_wait_queue(&fence->ring->fence_drv.fence_queue, &fence->fence_wake);
169 fence_put(&fence->base);
170 } else
171 FENCE_TRACE(&fence->base, "pending\n");
172 return 0;
173}
174
175/**
176 * amdgpu_fence_activity - check for fence activity 140 * amdgpu_fence_activity - check for fence activity
177 * 141 *
178 * @ring: pointer to struct amdgpu_ring 142 * @ring: pointer to struct amdgpu_ring
@@ -305,47 +269,6 @@ static bool amdgpu_fence_seq_signaled(struct amdgpu_ring *ring, u64 seq)
305 return false; 269 return false;
306} 270}
307 271
308static bool amdgpu_fence_is_signaled(struct fence *f)
309{
310 struct amdgpu_fence *fence = to_amdgpu_fence(f);
311 struct amdgpu_ring *ring = fence->ring;
312
313 if (atomic64_read(&ring->fence_drv.last_seq) >= fence->seq)
314 return true;
315
316 amdgpu_fence_process(ring);
317
318 if (atomic64_read(&ring->fence_drv.last_seq) >= fence->seq)
319 return true;
320
321 return false;
322}
323
324/**
325 * amdgpu_fence_enable_signaling - enable signalling on fence
326 * @fence: fence
327 *
328 * This function is called with fence_queue lock held, and adds a callback
329 * to fence_queue that checks if this fence is signaled, and if so it
330 * signals the fence and removes itself.
331 */
332static bool amdgpu_fence_enable_signaling(struct fence *f)
333{
334 struct amdgpu_fence *fence = to_amdgpu_fence(f);
335 struct amdgpu_ring *ring = fence->ring;
336
337 if (atomic64_read(&ring->fence_drv.last_seq) >= fence->seq)
338 return false;
339
340 fence->fence_wake.flags = 0;
341 fence->fence_wake.private = NULL;
342 fence->fence_wake.func = amdgpu_fence_check_signaled;
343 __add_wait_queue(&ring->fence_drv.fence_queue, &fence->fence_wake);
344 fence_get(f);
345 FENCE_TRACE(&fence->base, "armed on ring %i!\n", ring->idx);
346 return true;
347}
348
349/* 272/*
350 * amdgpu_ring_wait_seq_timeout - wait for seq of the specific ring to signal 273 * amdgpu_ring_wait_seq_timeout - wait for seq of the specific ring to signal
351 * @ring: ring to wait on for the seq number 274 * @ring: ring to wait on for the seq number
@@ -367,6 +290,7 @@ static int amdgpu_fence_ring_wait_seq(struct amdgpu_ring *ring, uint64_t seq)
367 if (atomic64_read(&ring->fence_drv.last_seq) >= seq) 290 if (atomic64_read(&ring->fence_drv.last_seq) >= seq)
368 return 0; 291 return 0;
369 292
293 amdgpu_fence_schedule_check(ring);
370 wait_event(ring->fence_drv.fence_queue, ( 294 wait_event(ring->fence_drv.fence_queue, (
371 (signaled = amdgpu_fence_seq_signaled(ring, seq)))); 295 (signaled = amdgpu_fence_seq_signaled(ring, seq))));
372 296
@@ -417,36 +341,6 @@ int amdgpu_fence_wait_empty(struct amdgpu_ring *ring)
417} 341}
418 342
419/** 343/**
420 * amdgpu_fence_ref - take a ref on a fence
421 *
422 * @fence: amdgpu fence object
423 *
424 * Take a reference on a fence (all asics).
425 * Returns the fence.
426 */
427struct amdgpu_fence *amdgpu_fence_ref(struct amdgpu_fence *fence)
428{
429 fence_get(&fence->base);
430 return fence;
431}
432
433/**
434 * amdgpu_fence_unref - remove a ref on a fence
435 *
436 * @fence: amdgpu fence object
437 *
438 * Remove a reference on a fence (all asics).
439 */
440void amdgpu_fence_unref(struct amdgpu_fence **fence)
441{
442 struct amdgpu_fence *tmp = *fence;
443
444 *fence = NULL;
445 if (tmp)
446 fence_put(&tmp->base);
447}
448
449/**
450 * amdgpu_fence_count_emitted - get the count of emitted fences 344 * amdgpu_fence_count_emitted - get the count of emitted fences
451 * 345 *
452 * @ring: ring the fence is associated with 346 * @ring: ring the fence is associated with
@@ -761,6 +655,115 @@ void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev)
761 } 655 }
762} 656}
763 657
658/*
659 * Common fence implementation
660 */
661
662static const char *amdgpu_fence_get_driver_name(struct fence *fence)
663{
664 return "amdgpu";
665}
666
667static const char *amdgpu_fence_get_timeline_name(struct fence *f)
668{
669 struct amdgpu_fence *fence = to_amdgpu_fence(f);
670 return (const char *)fence->ring->name;
671}
672
673/**
674 * amdgpu_fence_is_signaled - test if fence is signaled
675 *
676 * @f: fence to test
677 *
678 * Test the fence sequence number if it is already signaled. If it isn't
679 * signaled start fence processing. Returns True if the fence is signaled.
680 */
681static bool amdgpu_fence_is_signaled(struct fence *f)
682{
683 struct amdgpu_fence *fence = to_amdgpu_fence(f);
684 struct amdgpu_ring *ring = fence->ring;
685
686 if (atomic64_read(&ring->fence_drv.last_seq) >= fence->seq)
687 return true;
688
689 amdgpu_fence_process(ring);
690
691 if (atomic64_read(&ring->fence_drv.last_seq) >= fence->seq)
692 return true;
693
694 return false;
695}
696
697/**
698 * amdgpu_fence_check_signaled - callback from fence_queue
699 *
700 * this function is called with fence_queue lock held, which is also used
701 * for the fence locking itself, so unlocked variants are used for
702 * fence_signal, and remove_wait_queue.
703 */
704static int amdgpu_fence_check_signaled(wait_queue_t *wait, unsigned mode, int flags, void *key)
705{
706 struct amdgpu_fence *fence;
707 struct amdgpu_device *adev;
708 u64 seq;
709 int ret;
710
711 fence = container_of(wait, struct amdgpu_fence, fence_wake);
712 adev = fence->ring->adev;
713
714 /*
715 * We cannot use amdgpu_fence_process here because we're already
716 * in the waitqueue, in a call from wake_up_all.
717 */
718 seq = atomic64_read(&fence->ring->fence_drv.last_seq);
719 if (seq >= fence->seq) {
720 ret = fence_signal_locked(&fence->base);
721 if (!ret)
722 FENCE_TRACE(&fence->base, "signaled from irq context\n");
723 else
724 FENCE_TRACE(&fence->base, "was already signaled\n");
725
726 __remove_wait_queue(&fence->ring->fence_drv.fence_queue, &fence->fence_wake);
727 fence_put(&fence->base);
728 } else
729 FENCE_TRACE(&fence->base, "pending\n");
730 return 0;
731}
732
733/**
734 * amdgpu_fence_enable_signaling - enable signalling on fence
735 * @fence: fence
736 *
737 * This function is called with fence_queue lock held, and adds a callback
738 * to fence_queue that checks if this fence is signaled, and if so it
739 * signals the fence and removes itself.
740 */
741static bool amdgpu_fence_enable_signaling(struct fence *f)
742{
743 struct amdgpu_fence *fence = to_amdgpu_fence(f);
744 struct amdgpu_ring *ring = fence->ring;
745
746 if (atomic64_read(&ring->fence_drv.last_seq) >= fence->seq)
747 return false;
748
749 fence->fence_wake.flags = 0;
750 fence->fence_wake.private = NULL;
751 fence->fence_wake.func = amdgpu_fence_check_signaled;
752 __add_wait_queue(&ring->fence_drv.fence_queue, &fence->fence_wake);
753 fence_get(f);
754 amdgpu_fence_schedule_check(ring);
755 FENCE_TRACE(&fence->base, "armed on ring %i!\n", ring->idx);
756 return true;
757}
758
759const struct fence_ops amdgpu_fence_ops = {
760 .get_driver_name = amdgpu_fence_get_driver_name,
761 .get_timeline_name = amdgpu_fence_get_timeline_name,
762 .enable_signaling = amdgpu_fence_enable_signaling,
763 .signaled = amdgpu_fence_is_signaled,
764 .wait = fence_default_wait,
765 .release = NULL,
766};
764 767
765/* 768/*
766 * Fence debugfs 769 * Fence debugfs
@@ -811,131 +814,3 @@ int amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
811#endif 814#endif
812} 815}
813 816
814static const char *amdgpu_fence_get_driver_name(struct fence *fence)
815{
816 return "amdgpu";
817}
818
819static const char *amdgpu_fence_get_timeline_name(struct fence *f)
820{
821 struct amdgpu_fence *fence = to_amdgpu_fence(f);
822 return (const char *)fence->ring->name;
823}
824
825static inline bool amdgpu_test_signaled(struct amdgpu_fence *fence)
826{
827 return test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->base.flags);
828}
829
830static bool amdgpu_test_signaled_any(struct fence **fences, uint32_t count)
831{
832 int idx;
833 struct fence *fence;
834
835 for (idx = 0; idx < count; ++idx) {
836 fence = fences[idx];
837 if (fence) {
838 if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags))
839 return true;
840 }
841 }
842 return false;
843}
844
845struct amdgpu_wait_cb {
846 struct fence_cb base;
847 struct task_struct *task;
848};
849
850static void amdgpu_fence_wait_cb(struct fence *fence, struct fence_cb *cb)
851{
852 struct amdgpu_wait_cb *wait =
853 container_of(cb, struct amdgpu_wait_cb, base);
854 wake_up_process(wait->task);
855}
856
857static signed long amdgpu_fence_default_wait(struct fence *f, bool intr,
858 signed long t)
859{
860 return amdgpu_fence_wait_any(&f, 1, intr, t);
861}
862
863/**
864 * Wait the fence array with timeout
865 *
866 * @array: the fence array with amdgpu fence pointer
867 * @count: the number of the fence array
868 * @intr: when sleep, set the current task interruptable or not
869 * @t: timeout to wait
870 *
871 * It will return when any fence is signaled or timeout.
872 */
873signed long amdgpu_fence_wait_any(struct fence **array, uint32_t count,
874 bool intr, signed long t)
875{
876 struct amdgpu_wait_cb *cb;
877 struct fence *fence;
878 unsigned idx;
879
880 BUG_ON(!array);
881
882 cb = kcalloc(count, sizeof(struct amdgpu_wait_cb), GFP_KERNEL);
883 if (cb == NULL) {
884 t = -ENOMEM;
885 goto err_free_cb;
886 }
887
888 for (idx = 0; idx < count; ++idx) {
889 fence = array[idx];
890 if (fence) {
891 cb[idx].task = current;
892 if (fence_add_callback(fence,
893 &cb[idx].base, amdgpu_fence_wait_cb)) {
894 /* The fence is already signaled */
895 goto fence_rm_cb;
896 }
897 }
898 }
899
900 while (t > 0) {
901 if (intr)
902 set_current_state(TASK_INTERRUPTIBLE);
903 else
904 set_current_state(TASK_UNINTERRUPTIBLE);
905
906 /*
907 * amdgpu_test_signaled_any must be called after
908 * set_current_state to prevent a race with wake_up_process
909 */
910 if (amdgpu_test_signaled_any(array, count))
911 break;
912
913 t = schedule_timeout(t);
914
915 if (t > 0 && intr && signal_pending(current))
916 t = -ERESTARTSYS;
917 }
918
919 __set_current_state(TASK_RUNNING);
920
921fence_rm_cb:
922 for (idx = 0; idx < count; ++idx) {
923 fence = array[idx];
924 if (fence && cb[idx].base.func)
925 fence_remove_callback(fence, &cb[idx].base);
926 }
927
928err_free_cb:
929 kfree(cb);
930
931 return t;
932}
933
934const struct fence_ops amdgpu_fence_ops = {
935 .get_driver_name = amdgpu_fence_get_driver_name,
936 .get_timeline_name = amdgpu_fence_get_timeline_name,
937 .enable_signaling = amdgpu_fence_enable_signaling,
938 .signaled = amdgpu_fence_is_signaled,
939 .wait = amdgpu_fence_default_wait,
940 .release = NULL,
941};
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
index aad4c1c69448..e65987743871 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
@@ -95,7 +95,8 @@ void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib)
95{ 95{
96 amdgpu_sync_free(adev, &ib->sync, &ib->fence->base); 96 amdgpu_sync_free(adev, &ib->sync, &ib->fence->base);
97 amdgpu_sa_bo_free(adev, &ib->sa_bo, &ib->fence->base); 97 amdgpu_sa_bo_free(adev, &ib->sa_bo, &ib->fence->base);
98 amdgpu_fence_unref(&ib->fence); 98 if (ib->fence)
99 fence_put(&ib->fence->base);
99} 100}
100 101
101/** 102/**
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
index b2df348aa223..78e9b0f14661 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
@@ -436,6 +436,30 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)
436 } 436 }
437} 437}
438 438
439/**
440 * amdgpu_ring_from_fence - get ring from fence
441 *
442 * @f: fence structure
443 *
444 * Extract the ring a fence belongs to. Handles both scheduler as
445 * well as hardware fences.
446 */
447struct amdgpu_ring *amdgpu_ring_from_fence(struct fence *f)
448{
449 struct amdgpu_fence *a_fence;
450 struct amd_sched_fence *s_fence;
451
452 s_fence = to_amd_sched_fence(f);
453 if (s_fence)
454 return container_of(s_fence->sched, struct amdgpu_ring, sched);
455
456 a_fence = to_amdgpu_fence(f);
457 if (a_fence)
458 return a_fence->ring;
459
460 return NULL;
461}
462
439/* 463/*
440 * Debugfs info 464 * Debugfs info
441 */ 465 */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c
index 5cb27d525e43..0212b31dc194 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c
@@ -139,25 +139,6 @@ int amdgpu_sa_bo_manager_suspend(struct amdgpu_device *adev,
139 return r; 139 return r;
140} 140}
141 141
142static uint32_t amdgpu_sa_get_ring_from_fence(struct fence *f)
143{
144 struct amdgpu_fence *a_fence;
145 struct amd_sched_fence *s_fence;
146
147 s_fence = to_amd_sched_fence(f);
148 if (s_fence) {
149 struct amdgpu_ring *ring;
150
151 ring = container_of(s_fence->sched, struct amdgpu_ring, sched);
152 return ring->idx;
153 }
154
155 a_fence = to_amdgpu_fence(f);
156 if (a_fence)
157 return a_fence->ring->idx;
158 return 0;
159}
160
161static void amdgpu_sa_bo_remove_locked(struct amdgpu_sa_bo *sa_bo) 142static void amdgpu_sa_bo_remove_locked(struct amdgpu_sa_bo *sa_bo)
162{ 143{
163 struct amdgpu_sa_manager *sa_manager = sa_bo->manager; 144 struct amdgpu_sa_manager *sa_manager = sa_bo->manager;
@@ -318,7 +299,7 @@ static bool amdgpu_sa_bo_next_hole(struct amdgpu_sa_manager *sa_manager,
318 } 299 }
319 300
320 if (best_bo) { 301 if (best_bo) {
321 uint32_t idx = amdgpu_sa_get_ring_from_fence(best_bo->fence); 302 uint32_t idx = amdgpu_ring_from_fence(best_bo->fence)->idx;
322 ++tries[idx]; 303 ++tries[idx];
323 sa_manager->hole = best_bo->olist.prev; 304 sa_manager->hole = best_bo->olist.prev;
324 305
@@ -337,6 +318,7 @@ int amdgpu_sa_bo_new(struct amdgpu_device *adev,
337{ 318{
338 struct fence *fences[AMDGPU_MAX_RINGS]; 319 struct fence *fences[AMDGPU_MAX_RINGS];
339 unsigned tries[AMDGPU_MAX_RINGS]; 320 unsigned tries[AMDGPU_MAX_RINGS];
321 unsigned count;
340 int i, r; 322 int i, r;
341 signed long t; 323 signed long t;
342 324
@@ -371,13 +353,18 @@ int amdgpu_sa_bo_new(struct amdgpu_device *adev,
371 /* see if we can skip over some allocations */ 353 /* see if we can skip over some allocations */
372 } while (amdgpu_sa_bo_next_hole(sa_manager, fences, tries)); 354 } while (amdgpu_sa_bo_next_hole(sa_manager, fences, tries));
373 355
374 spin_unlock(&sa_manager->wq.lock); 356 for (i = 0, count = 0; i < AMDGPU_MAX_RINGS; ++i)
375 t = amdgpu_fence_wait_any(fences, AMDGPU_MAX_RINGS, 357 if (fences[i])
376 false, MAX_SCHEDULE_TIMEOUT); 358 fences[count++] = fences[i];
377 r = (t > 0) ? 0 : t; 359
378 spin_lock(&sa_manager->wq.lock); 360 if (count) {
379 /* if we have nothing to wait for block */ 361 spin_unlock(&sa_manager->wq.lock);
380 if (r == -ENOENT) { 362 t = fence_wait_any_timeout(fences, count, false,
363 MAX_SCHEDULE_TIMEOUT);
364 r = (t > 0) ? 0 : t;
365 spin_lock(&sa_manager->wq.lock);
366 } else {
367 /* if we have nothing to wait for block */
381 r = wait_event_interruptible_locked( 368 r = wait_event_interruptible_locked(
382 sa_manager->wq, 369 sa_manager->wq,
383 amdgpu_sa_event(sa_manager, size, align) 370 amdgpu_sa_event(sa_manager, size, align)
@@ -406,7 +393,7 @@ void amdgpu_sa_bo_free(struct amdgpu_device *adev, struct amdgpu_sa_bo **sa_bo,
406 if (fence && !fence_is_signaled(fence)) { 393 if (fence && !fence_is_signaled(fence)) {
407 uint32_t idx; 394 uint32_t idx;
408 (*sa_bo)->fence = fence_get(fence); 395 (*sa_bo)->fence = fence_get(fence);
409 idx = amdgpu_sa_get_ring_from_fence(fence); 396 idx = amdgpu_ring_from_fence(fence)->idx;
410 list_add_tail(&(*sa_bo)->flist, &sa_manager->flist[idx]); 397 list_add_tail(&(*sa_bo)->flist, &sa_manager->flist[idx]);
411 } else { 398 } else {
412 amdgpu_sa_bo_remove_locked(*sa_bo); 399 amdgpu_sa_bo_remove_locked(*sa_bo);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c
index 2e946b2cad88..dcf4a8aca680 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c
@@ -54,7 +54,8 @@ static struct fence *amdgpu_sched_run_job(struct amd_sched_job *sched_job)
54 goto err; 54 goto err;
55 } 55 }
56 56
57 fence = amdgpu_fence_ref(job->ibs[job->num_ibs - 1].fence); 57 fence = job->ibs[job->num_ibs - 1].fence;
58 fence_get(&fence->base);
58 59
59err: 60err:
60 if (job->free_job) 61 if (job->free_job)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
index 4921de15b451..a6697fd05217 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
@@ -87,6 +87,15 @@ static bool amdgpu_sync_test_owner(struct fence *f, void *owner)
87 return false; 87 return false;
88} 88}
89 89
90static void amdgpu_sync_keep_later(struct fence **keep, struct fence *fence)
91{
92 if (*keep && fence_is_later(*keep, fence))
93 return;
94
95 fence_put(*keep);
96 *keep = fence_get(fence);
97}
98
90/** 99/**
91 * amdgpu_sync_fence - remember to sync to this fence 100 * amdgpu_sync_fence - remember to sync to this fence
92 * 101 *
@@ -99,35 +108,21 @@ int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
99{ 108{
100 struct amdgpu_sync_entry *e; 109 struct amdgpu_sync_entry *e;
101 struct amdgpu_fence *fence; 110 struct amdgpu_fence *fence;
102 struct amdgpu_fence *other;
103 struct fence *tmp, *later;
104 111
105 if (!f) 112 if (!f)
106 return 0; 113 return 0;
107 114
108 if (amdgpu_sync_same_dev(adev, f) && 115 if (amdgpu_sync_same_dev(adev, f) &&
109 amdgpu_sync_test_owner(f, AMDGPU_FENCE_OWNER_VM)) { 116 amdgpu_sync_test_owner(f, AMDGPU_FENCE_OWNER_VM))
110 if (sync->last_vm_update) { 117 amdgpu_sync_keep_later(&sync->last_vm_update, f);
111 tmp = sync->last_vm_update;
112 BUG_ON(f->context != tmp->context);
113 later = (f->seqno - tmp->seqno <= INT_MAX) ? f : tmp;
114 sync->last_vm_update = fence_get(later);
115 fence_put(tmp);
116 } else
117 sync->last_vm_update = fence_get(f);
118 }
119 118
120 fence = to_amdgpu_fence(f); 119 fence = to_amdgpu_fence(f);
121 if (!fence || fence->ring->adev != adev) { 120 if (!fence || fence->ring->adev != adev) {
122 hash_for_each_possible(sync->fences, e, node, f->context) { 121 hash_for_each_possible(sync->fences, e, node, f->context) {
123 struct fence *new;
124 if (unlikely(e->fence->context != f->context)) 122 if (unlikely(e->fence->context != f->context))
125 continue; 123 continue;
126 new = fence_get(fence_later(e->fence, f)); 124
127 if (new) { 125 amdgpu_sync_keep_later(&e->fence, f);
128 fence_put(e->fence);
129 e->fence = new;
130 }
131 return 0; 126 return 0;
132 } 127 }
133 128
@@ -140,10 +135,7 @@ int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
140 return 0; 135 return 0;
141 } 136 }
142 137
143 other = sync->sync_to[fence->ring->idx]; 138 amdgpu_sync_keep_later(&sync->sync_to[fence->ring->idx], f);
144 sync->sync_to[fence->ring->idx] = amdgpu_fence_ref(
145 amdgpu_fence_later(fence, other));
146 amdgpu_fence_unref(&other);
147 139
148 return 0; 140 return 0;
149} 141}
@@ -199,8 +191,8 @@ int amdgpu_sync_resv(struct amdgpu_device *adev,
199 * for other VM updates and moves. 191 * for other VM updates and moves.
200 */ 192 */
201 fence_owner = amdgpu_sync_get_owner(f); 193 fence_owner = amdgpu_sync_get_owner(f);
202 if ((owner != AMDGPU_FENCE_OWNER_MOVE) && 194 if ((owner != AMDGPU_FENCE_OWNER_UNDEFINED) &&
203 (fence_owner != AMDGPU_FENCE_OWNER_MOVE) && 195 (fence_owner != AMDGPU_FENCE_OWNER_UNDEFINED) &&
204 ((owner == AMDGPU_FENCE_OWNER_VM) != 196 ((owner == AMDGPU_FENCE_OWNER_VM) !=
205 (fence_owner == AMDGPU_FENCE_OWNER_VM))) 197 (fence_owner == AMDGPU_FENCE_OWNER_VM)))
206 continue; 198 continue;
@@ -262,11 +254,11 @@ int amdgpu_sync_wait(struct amdgpu_sync *sync)
262 return 0; 254 return 0;
263 255
264 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { 256 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
265 struct amdgpu_fence *fence = sync->sync_to[i]; 257 struct fence *fence = sync->sync_to[i];
266 if (!fence) 258 if (!fence)
267 continue; 259 continue;
268 260
269 r = fence_wait(&fence->base, false); 261 r = fence_wait(fence, false);
270 if (r) 262 if (r)
271 return r; 263 return r;
272 } 264 }
@@ -291,9 +283,14 @@ int amdgpu_sync_rings(struct amdgpu_sync *sync,
291 int i, r; 283 int i, r;
292 284
293 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { 285 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
294 struct amdgpu_fence *fence = sync->sync_to[i];
295 struct amdgpu_semaphore *semaphore;
296 struct amdgpu_ring *other = adev->rings[i]; 286 struct amdgpu_ring *other = adev->rings[i];
287 struct amdgpu_semaphore *semaphore;
288 struct amdgpu_fence *fence;
289
290 if (!sync->sync_to[i])
291 continue;
292
293 fence = to_amdgpu_fence(sync->sync_to[i]);
297 294
298 /* check if we really need to sync */ 295 /* check if we really need to sync */
299 if (!amdgpu_fence_need_sync(fence, ring)) 296 if (!amdgpu_fence_need_sync(fence, ring))
@@ -378,7 +375,7 @@ void amdgpu_sync_free(struct amdgpu_device *adev,
378 amdgpu_semaphore_free(adev, &sync->semaphores[i], fence); 375 amdgpu_semaphore_free(adev, &sync->semaphores[i], fence);
379 376
380 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) 377 for (i = 0; i < AMDGPU_MAX_RINGS; ++i)
381 amdgpu_fence_unref(&sync->sync_to[i]); 378 fence_put(sync->sync_to[i]);
382 379
383 fence_put(sync->last_vm_update); 380 fence_put(sync->last_vm_update);
384} 381}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index a089e69e9927..81bb8e9fc26d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1041,7 +1041,7 @@ int amdgpu_copy_buffer(struct amdgpu_ring *ring,
1041 WARN_ON(ib->length_dw > num_dw); 1041 WARN_ON(ib->length_dw > num_dw);
1042 r = amdgpu_sched_ib_submit_kernel_helper(adev, ring, ib, 1, 1042 r = amdgpu_sched_ib_submit_kernel_helper(adev, ring, ib, 1,
1043 &amdgpu_vm_free_job, 1043 &amdgpu_vm_free_job,
1044 AMDGPU_FENCE_OWNER_MOVE, 1044 AMDGPU_FENCE_OWNER_UNDEFINED,
1045 fence); 1045 fence);
1046 if (r) 1046 if (r)
1047 goto error_free; 1047 goto error_free;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index ff26e330ccd6..633a32a48560 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -135,7 +135,7 @@ struct amdgpu_bo_list_entry *amdgpu_vm_get_bos(struct amdgpu_device *adev,
135int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, 135int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
136 struct amdgpu_sync *sync) 136 struct amdgpu_sync *sync)
137{ 137{
138 struct amdgpu_fence *best[AMDGPU_MAX_RINGS] = {}; 138 struct fence *best[AMDGPU_MAX_RINGS] = {};
139 struct amdgpu_vm_id *vm_id = &vm->ids[ring->idx]; 139 struct amdgpu_vm_id *vm_id = &vm->ids[ring->idx];
140 struct amdgpu_device *adev = ring->adev; 140 struct amdgpu_device *adev = ring->adev;
141 141
@@ -154,7 +154,8 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
154 154
155 /* skip over VMID 0, since it is the system VM */ 155 /* skip over VMID 0, since it is the system VM */
156 for (i = 1; i < adev->vm_manager.nvm; ++i) { 156 for (i = 1; i < adev->vm_manager.nvm; ++i) {
157 struct amdgpu_fence *fence = adev->vm_manager.active[i]; 157 struct fence *fence = adev->vm_manager.active[i];
158 struct amdgpu_ring *fring;
158 159
159 if (fence == NULL) { 160 if (fence == NULL) {
160 /* found a free one */ 161 /* found a free one */
@@ -163,21 +164,23 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
163 return 0; 164 return 0;
164 } 165 }
165 166
166 if (amdgpu_fence_is_earlier(fence, best[fence->ring->idx])) { 167 fring = amdgpu_ring_from_fence(fence);
167 best[fence->ring->idx] = fence; 168 if (best[fring->idx] == NULL ||
168 choices[fence->ring == ring ? 0 : 1] = i; 169 fence_is_later(best[fring->idx], fence)) {
170 best[fring->idx] = fence;
171 choices[fring == ring ? 0 : 1] = i;
169 } 172 }
170 } 173 }
171 174
172 for (i = 0; i < 2; ++i) { 175 for (i = 0; i < 2; ++i) {
173 if (choices[i]) { 176 if (choices[i]) {
174 struct amdgpu_fence *fence; 177 struct fence *fence;
175 178
176 fence = adev->vm_manager.active[choices[i]]; 179 fence = adev->vm_manager.active[choices[i]];
177 vm_id->id = choices[i]; 180 vm_id->id = choices[i];
178 181
179 trace_amdgpu_vm_grab_id(choices[i], ring->idx); 182 trace_amdgpu_vm_grab_id(choices[i], ring->idx);
180 return amdgpu_sync_fence(ring->adev, sync, &fence->base); 183 return amdgpu_sync_fence(ring->adev, sync, fence);
181 } 184 }
182 } 185 }
183 186
@@ -246,11 +249,11 @@ void amdgpu_vm_fence(struct amdgpu_device *adev,
246 unsigned ridx = fence->ring->idx; 249 unsigned ridx = fence->ring->idx;
247 unsigned vm_id = vm->ids[ridx].id; 250 unsigned vm_id = vm->ids[ridx].id;
248 251
249 amdgpu_fence_unref(&adev->vm_manager.active[vm_id]); 252 fence_put(adev->vm_manager.active[vm_id]);
250 adev->vm_manager.active[vm_id] = amdgpu_fence_ref(fence); 253 adev->vm_manager.active[vm_id] = fence_get(&fence->base);
251 254
252 amdgpu_fence_unref(&vm->ids[ridx].last_id_use); 255 fence_put(vm->ids[ridx].last_id_use);
253 vm->ids[ridx].last_id_use = amdgpu_fence_ref(fence); 256 vm->ids[ridx].last_id_use = fence_get(&fence->base);
254} 257}
255 258
256/** 259/**
@@ -1313,7 +1316,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
1313 1316
1314 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { 1317 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
1315 fence_put(vm->ids[i].flushed_updates); 1318 fence_put(vm->ids[i].flushed_updates);
1316 amdgpu_fence_unref(&vm->ids[i].last_id_use); 1319 fence_put(vm->ids[i].last_id_use);
1317 } 1320 }
1318 1321
1319 mutex_destroy(&vm->mutex); 1322 mutex_destroy(&vm->mutex);
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
index a6ea2d8e85df..61320511c479 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
@@ -262,46 +262,22 @@ static u32 dce_v10_0_vblank_get_counter(struct amdgpu_device *adev, int crtc)
262 * @crtc_id: crtc to cleanup pageflip on 262 * @crtc_id: crtc to cleanup pageflip on
263 * @crtc_base: new address of the crtc (GPU MC address) 263 * @crtc_base: new address of the crtc (GPU MC address)
264 * 264 *
265 * Does the actual pageflip (evergreen+). 265 * Triggers the actual pageflip by updating the primary
266 * During vblank we take the crtc lock and wait for the update_pending 266 * surface base address.
267 * bit to go high, when it does, we release the lock, and allow the
268 * double buffered update to take place.
269 * Returns the current update pending status.
270 */ 267 */
271static void dce_v10_0_page_flip(struct amdgpu_device *adev, 268static void dce_v10_0_page_flip(struct amdgpu_device *adev,
272 int crtc_id, u64 crtc_base) 269 int crtc_id, u64 crtc_base)
273{ 270{
274 struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[crtc_id]; 271 struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
275 u32 tmp = RREG32(mmGRPH_UPDATE + amdgpu_crtc->crtc_offset);
276 int i;
277
278 /* Lock the graphics update lock */
279 tmp = REG_SET_FIELD(tmp, GRPH_UPDATE, GRPH_UPDATE_LOCK, 1);
280 WREG32(mmGRPH_UPDATE + amdgpu_crtc->crtc_offset, tmp);
281
282 /* update the scanout addresses */
283 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
284 upper_32_bits(crtc_base));
285 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
286 lower_32_bits(crtc_base));
287 272
273 /* update the primary scanout address */
288 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset, 274 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
289 upper_32_bits(crtc_base)); 275 upper_32_bits(crtc_base));
276 /* writing to the low address triggers the update */
290 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset, 277 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
291 lower_32_bits(crtc_base)); 278 lower_32_bits(crtc_base));
292 279 /* post the write */
293 /* Wait for update_pending to go high. */ 280 RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset);
294 for (i = 0; i < adev->usec_timeout; i++) {
295 if (RREG32(mmGRPH_UPDATE + amdgpu_crtc->crtc_offset) &
296 GRPH_UPDATE__GRPH_SURFACE_UPDATE_PENDING_MASK)
297 break;
298 udelay(1);
299 }
300 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
301
302 /* Unlock the lock, so double-buffering can take place inside vblank */
303 tmp = REG_SET_FIELD(tmp, GRPH_UPDATE, GRPH_UPDATE_LOCK, 0);
304 WREG32(mmGRPH_UPDATE + amdgpu_crtc->crtc_offset, tmp);
305} 281}
306 282
307static int dce_v10_0_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc, 283static int dce_v10_0_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
index 784afb5978ac..3506c5b42106 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
@@ -252,46 +252,22 @@ static u32 dce_v11_0_vblank_get_counter(struct amdgpu_device *adev, int crtc)
252 * @crtc_id: crtc to cleanup pageflip on 252 * @crtc_id: crtc to cleanup pageflip on
253 * @crtc_base: new address of the crtc (GPU MC address) 253 * @crtc_base: new address of the crtc (GPU MC address)
254 * 254 *
255 * Does the actual pageflip (evergreen+). 255 * Triggers the actual pageflip by updating the primary
256 * During vblank we take the crtc lock and wait for the update_pending 256 * surface base address.
257 * bit to go high, when it does, we release the lock, and allow the
258 * double buffered update to take place.
259 * Returns the current update pending status.
260 */ 257 */
261static void dce_v11_0_page_flip(struct amdgpu_device *adev, 258static void dce_v11_0_page_flip(struct amdgpu_device *adev,
262 int crtc_id, u64 crtc_base) 259 int crtc_id, u64 crtc_base)
263{ 260{
264 struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[crtc_id]; 261 struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
265 u32 tmp = RREG32(mmGRPH_UPDATE + amdgpu_crtc->crtc_offset);
266 int i;
267
268 /* Lock the graphics update lock */
269 tmp = REG_SET_FIELD(tmp, GRPH_UPDATE, GRPH_UPDATE_LOCK, 1);
270 WREG32(mmGRPH_UPDATE + amdgpu_crtc->crtc_offset, tmp);
271 262
272 /* update the scanout addresses */ 263 /* update the scanout addresses */
273 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
274 upper_32_bits(crtc_base));
275 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
276 lower_32_bits(crtc_base));
277
278 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset, 264 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
279 upper_32_bits(crtc_base)); 265 upper_32_bits(crtc_base));
266 /* writing to the low address triggers the update */
280 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset, 267 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
281 lower_32_bits(crtc_base)); 268 lower_32_bits(crtc_base));
282 269 /* post the write */
283 /* Wait for update_pending to go high. */ 270 RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset);
284 for (i = 0; i < adev->usec_timeout; i++) {
285 if (RREG32(mmGRPH_UPDATE + amdgpu_crtc->crtc_offset) &
286 GRPH_UPDATE__GRPH_SURFACE_UPDATE_PENDING_MASK)
287 break;
288 udelay(1);
289 }
290 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
291
292 /* Unlock the lock, so double-buffering can take place inside vblank */
293 tmp = REG_SET_FIELD(tmp, GRPH_UPDATE, GRPH_UPDATE_LOCK, 0);
294 WREG32(mmGRPH_UPDATE + amdgpu_crtc->crtc_offset, tmp);
295} 271}
296 272
297static int dce_v11_0_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc, 273static int dce_v11_0_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
index 00c34f87ac20..b17abbe1be99 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
@@ -211,46 +211,22 @@ static u32 dce_v8_0_vblank_get_counter(struct amdgpu_device *adev, int crtc)
211 * @crtc_id: crtc to cleanup pageflip on 211 * @crtc_id: crtc to cleanup pageflip on
212 * @crtc_base: new address of the crtc (GPU MC address) 212 * @crtc_base: new address of the crtc (GPU MC address)
213 * 213 *
214 * Does the actual pageflip (evergreen+). 214 * Triggers the actual pageflip by updating the primary
215 * During vblank we take the crtc lock and wait for the update_pending 215 * surface base address.
216 * bit to go high, when it does, we release the lock, and allow the
217 * double buffered update to take place.
218 * Returns the current update pending status.
219 */ 216 */
220static void dce_v8_0_page_flip(struct amdgpu_device *adev, 217static void dce_v8_0_page_flip(struct amdgpu_device *adev,
221 int crtc_id, u64 crtc_base) 218 int crtc_id, u64 crtc_base)
222{ 219{
223 struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[crtc_id]; 220 struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
224 u32 tmp = RREG32(mmGRPH_UPDATE + amdgpu_crtc->crtc_offset);
225 int i;
226
227 /* Lock the graphics update lock */
228 tmp |= GRPH_UPDATE__GRPH_UPDATE_LOCK_MASK;
229 WREG32(mmGRPH_UPDATE + amdgpu_crtc->crtc_offset, tmp);
230
231 /* update the scanout addresses */
232 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
233 upper_32_bits(crtc_base));
234 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
235 (u32)crtc_base);
236 221
222 /* update the primary scanout addresses */
237 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset, 223 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
238 upper_32_bits(crtc_base)); 224 upper_32_bits(crtc_base));
225 /* writing to the low address triggers the update */
239 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset, 226 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
240 (u32)crtc_base); 227 lower_32_bits(crtc_base));
241 228 /* post the write */
242 /* Wait for update_pending to go high. */ 229 RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset);
243 for (i = 0; i < adev->usec_timeout; i++) {
244 if (RREG32(mmGRPH_UPDATE + amdgpu_crtc->crtc_offset) &
245 GRPH_UPDATE__GRPH_SURFACE_UPDATE_PENDING_MASK)
246 break;
247 udelay(1);
248 }
249 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
250
251 /* Unlock the lock, so double-buffering can take place inside vblank */
252 tmp &= ~GRPH_UPDATE__GRPH_UPDATE_LOCK_MASK;
253 WREG32(mmGRPH_UPDATE + amdgpu_crtc->crtc_offset, tmp);
254} 230}
255 231
256static int dce_v8_0_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc, 232static int dce_v8_0_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index cbc46a34987c..6776cf756d40 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -235,11 +235,13 @@ static const u32 fiji_golden_common_all[] =
235 mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000, 235 mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
236 mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x3a00161a, 236 mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x3a00161a,
237 mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002e, 237 mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002e,
238 mmGB_ADDR_CONFIG, 0xffffffff, 0x12011003, 238 mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
239 mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800, 239 mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
240 mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800, 240 mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
241 mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00007FBF, 241 mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00007FBF,
242 mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00007FAF 242 mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00007FAF,
243 mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
244 mmSPI_CONFIG_CNTL_1, 0x0000000f, 0x00000009,
243}; 245};
244 246
245static const u32 golden_settings_fiji_a10[] = 247static const u32 golden_settings_fiji_a10[] =
@@ -247,24 +249,26 @@ static const u32 golden_settings_fiji_a10[] =
247 mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040, 249 mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
248 mmDB_DEBUG2, 0xf00fffff, 0x00000400, 250 mmDB_DEBUG2, 0xf00fffff, 0x00000400,
249 mmPA_SC_ENHANCE, 0xffffffff, 0x20000001, 251 mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
250 mmPA_SC_FIFO_DEPTH_CNTL, 0x000003ff, 0x00000100,
251 mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000, 252 mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
253 mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
254 mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
252 mmTA_CNTL_AUX, 0x000f000f, 0x000b0000, 255 mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
253 mmTCC_CTRL, 0x00100000, 0xf30fff7f, 256 mmTCC_CTRL, 0x00100000, 0xf31fff7f,
257 mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
254 mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000ff, 258 mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000ff,
255 mmTCP_CHAN_STEER_HI, 0xffffffff, 0x7d6cf5e4, 259 mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
256 mmTCP_CHAN_STEER_LO, 0xffffffff, 0x3928b1a0,
257}; 260};
258 261
259static const u32 fiji_mgcg_cgcg_init[] = 262static const u32 fiji_mgcg_cgcg_init[] =
260{ 263{
261 mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffc0, 264 mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
262 mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000, 265 mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
263 mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100, 266 mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
264 mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100, 267 mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
265 mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100, 268 mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100,
266 mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100, 269 mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100,
267 mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x40000100, 270 mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x40000100,
271 mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
268 mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100, 272 mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
269 mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100, 273 mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
270 mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100, 274 mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
@@ -292,6 +296,10 @@ static const u32 fiji_mgcg_cgcg_init[] =
292 mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200, 296 mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
293 mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100, 297 mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
294 mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c, 298 mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c,
299 mmPCIE_INDEX, 0xffffffff, 0x0140001c,
300 mmPCIE_DATA, 0x000f0000, 0x00000000,
301 mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
302 mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
295 mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001, 303 mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
296}; 304};
297 305
@@ -1031,6 +1039,8 @@ static void gfx_v8_0_gpu_early_init(struct amdgpu_device *adev)
1031 case 0x84: 1039 case 0x84:
1032 case 0xc8: 1040 case 0xc8:
1033 case 0xcc: 1041 case 0xcc:
1042 case 0xe1:
1043 case 0xe3:
1034 /* B10 */ 1044 /* B10 */
1035 adev->gfx.config.max_cu_per_sh = 8; 1045 adev->gfx.config.max_cu_per_sh = 8;
1036 break; 1046 break;
@@ -1039,18 +1049,23 @@ static void gfx_v8_0_gpu_early_init(struct amdgpu_device *adev)
1039 case 0x85: 1049 case 0x85:
1040 case 0xc9: 1050 case 0xc9:
1041 case 0xcd: 1051 case 0xcd:
1052 case 0xe2:
1053 case 0xe4:
1042 /* B8 */ 1054 /* B8 */
1043 adev->gfx.config.max_cu_per_sh = 6; 1055 adev->gfx.config.max_cu_per_sh = 6;
1044 break; 1056 break;
1045 case 0xc6: 1057 case 0xc6:
1046 case 0xca: 1058 case 0xca:
1047 case 0xce: 1059 case 0xce:
1060 case 0x88:
1048 /* B6 */ 1061 /* B6 */
1049 adev->gfx.config.max_cu_per_sh = 6; 1062 adev->gfx.config.max_cu_per_sh = 6;
1050 break; 1063 break;
1051 case 0xc7: 1064 case 0xc7:
1052 case 0x87: 1065 case 0x87:
1053 case 0xcb: 1066 case 0xcb:
1067 case 0xe5:
1068 case 0x89:
1054 default: 1069 default:
1055 /* B4 */ 1070 /* B4 */
1056 adev->gfx.config.max_cu_per_sh = 4; 1071 adev->gfx.config.max_cu_per_sh = 4;
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 488348272c4d..85bbcdc73fff 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -965,7 +965,7 @@ static int gmc_v7_0_sw_fini(void *handle)
965 965
966 if (adev->vm_manager.enabled) { 966 if (adev->vm_manager.enabled) {
967 for (i = 0; i < AMDGPU_NUM_VM; ++i) 967 for (i = 0; i < AMDGPU_NUM_VM; ++i)
968 amdgpu_fence_unref(&adev->vm_manager.active[i]); 968 fence_put(adev->vm_manager.active[i]);
969 gmc_v7_0_vm_fini(adev); 969 gmc_v7_0_vm_fini(adev);
970 adev->vm_manager.enabled = false; 970 adev->vm_manager.enabled = false;
971 } 971 }
@@ -1015,7 +1015,7 @@ static int gmc_v7_0_suspend(void *handle)
1015 1015
1016 if (adev->vm_manager.enabled) { 1016 if (adev->vm_manager.enabled) {
1017 for (i = 0; i < AMDGPU_NUM_VM; ++i) 1017 for (i = 0; i < AMDGPU_NUM_VM; ++i)
1018 amdgpu_fence_unref(&adev->vm_manager.active[i]); 1018 fence_put(adev->vm_manager.active[i]);
1019 gmc_v7_0_vm_fini(adev); 1019 gmc_v7_0_vm_fini(adev);
1020 adev->vm_manager.enabled = false; 1020 adev->vm_manager.enabled = false;
1021 } 1021 }
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
index 72e977b1685d..1bcc4e74e3b4 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
@@ -984,7 +984,7 @@ static int gmc_v8_0_sw_fini(void *handle)
984 984
985 if (adev->vm_manager.enabled) { 985 if (adev->vm_manager.enabled) {
986 for (i = 0; i < AMDGPU_NUM_VM; ++i) 986 for (i = 0; i < AMDGPU_NUM_VM; ++i)
987 amdgpu_fence_unref(&adev->vm_manager.active[i]); 987 fence_put(adev->vm_manager.active[i]);
988 gmc_v8_0_vm_fini(adev); 988 gmc_v8_0_vm_fini(adev);
989 adev->vm_manager.enabled = false; 989 adev->vm_manager.enabled = false;
990 } 990 }
@@ -1036,7 +1036,7 @@ static int gmc_v8_0_suspend(void *handle)
1036 1036
1037 if (adev->vm_manager.enabled) { 1037 if (adev->vm_manager.enabled) {
1038 for (i = 0; i < AMDGPU_NUM_VM; ++i) 1038 for (i = 0; i < AMDGPU_NUM_VM; ++i)
1039 amdgpu_fence_unref(&adev->vm_manager.active[i]); 1039 fence_put(adev->vm_manager.active[i]);
1040 gmc_v8_0_vm_fini(adev); 1040 gmc_v8_0_vm_fini(adev);
1041 adev->vm_manager.enabled = false; 1041 adev->vm_manager.enabled = false;
1042 } 1042 }
diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c
index d8c93f14c3b5..2adc1c855e85 100644
--- a/drivers/gpu/drm/amd/amdgpu/vi.c
+++ b/drivers/gpu/drm/amd/amdgpu/vi.c
@@ -1413,17 +1413,18 @@ static int vi_common_early_init(void *handle)
1413 adev->cg_flags = 0; 1413 adev->cg_flags = 0;
1414 adev->pg_flags = 0; 1414 adev->pg_flags = 0;
1415 adev->external_rev_id = 0x1; 1415 adev->external_rev_id = 0x1;
1416 if (amdgpu_smc_load_fw && smc_enabled)
1417 adev->firmware.smu_load = true;
1418 break; 1416 break;
1419 case CHIP_FIJI: 1417 case CHIP_FIJI:
1418 adev->has_uvd = true;
1419 adev->cg_flags = 0;
1420 adev->pg_flags = 0;
1421 adev->external_rev_id = adev->rev_id + 0x3c;
1422 break;
1420 case CHIP_TONGA: 1423 case CHIP_TONGA:
1421 adev->has_uvd = true; 1424 adev->has_uvd = true;
1422 adev->cg_flags = 0; 1425 adev->cg_flags = 0;
1423 adev->pg_flags = 0; 1426 adev->pg_flags = 0;
1424 adev->external_rev_id = adev->rev_id + 0x14; 1427 adev->external_rev_id = adev->rev_id + 0x14;
1425 if (amdgpu_smc_load_fw && smc_enabled)
1426 adev->firmware.smu_load = true;
1427 break; 1428 break;
1428 case CHIP_CARRIZO: 1429 case CHIP_CARRIZO:
1429 case CHIP_STONEY: 1430 case CHIP_STONEY:
@@ -1432,14 +1433,15 @@ static int vi_common_early_init(void *handle)
1432 /* Disable UVD pg */ 1433 /* Disable UVD pg */
1433 adev->pg_flags = /* AMDGPU_PG_SUPPORT_UVD | */AMDGPU_PG_SUPPORT_VCE; 1434 adev->pg_flags = /* AMDGPU_PG_SUPPORT_UVD | */AMDGPU_PG_SUPPORT_VCE;
1434 adev->external_rev_id = adev->rev_id + 0x1; 1435 adev->external_rev_id = adev->rev_id + 0x1;
1435 if (amdgpu_smc_load_fw && smc_enabled)
1436 adev->firmware.smu_load = true;
1437 break; 1436 break;
1438 default: 1437 default:
1439 /* FIXME: not supported yet */ 1438 /* FIXME: not supported yet */
1440 return -EINVAL; 1439 return -EINVAL;
1441 } 1440 }
1442 1441
1442 if (amdgpu_smc_load_fw && smc_enabled)
1443 adev->firmware.smu_load = true;
1444
1443 return 0; 1445 return 0;
1444} 1446}
1445 1447