hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/gpu/drm/radeon/radeon_object.c
....@@ -29,14 +29,17 @@
2929 * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
3030 * Dave Airlie
3131 */
32
+
33
+#include <linux/io.h>
3234 #include <linux/list.h>
3335 #include <linux/slab.h>
34
-#include <drm/drmP.h>
35
-#include <drm/radeon_drm.h>
36
+
3637 #include <drm/drm_cache.h>
38
+#include <drm/drm_prime.h>
39
+#include <drm/radeon_drm.h>
40
+
3741 #include "radeon.h"
3842 #include "radeon_trace.h"
39
-
4043
4144 int radeon_ttm_init(struct radeon_device *rdev);
4245 void radeon_ttm_fini(struct radeon_device *rdev);
....@@ -82,9 +85,9 @@
8285 mutex_unlock(&bo->rdev->gem.mutex);
8386 radeon_bo_clear_surface_reg(bo);
8487 WARN_ON_ONCE(!list_empty(&bo->va));
85
- if (bo->gem_base.import_attach)
86
- drm_prime_gem_destroy(&bo->gem_base, bo->tbo.sg);
87
- drm_gem_object_release(&bo->gem_base);
88
+ if (bo->tbo.base.import_attach)
89
+ drm_prime_gem_destroy(&bo->tbo.base, bo->tbo.sg);
90
+ drm_gem_object_release(&bo->tbo.base);
8891 kfree(bo);
8992 }
9093
....@@ -109,58 +112,58 @@
109112 rbo->rdev->mc.visible_vram_size < rbo->rdev->mc.real_vram_size) {
110113 rbo->placements[c].fpfn =
111114 rbo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
115
+ rbo->placements[c].mem_type = TTM_PL_VRAM;
112116 rbo->placements[c++].flags = TTM_PL_FLAG_WC |
113
- TTM_PL_FLAG_UNCACHED |
114
- TTM_PL_FLAG_VRAM;
117
+ TTM_PL_FLAG_UNCACHED;
115118 }
116119
117120 rbo->placements[c].fpfn = 0;
121
+ rbo->placements[c].mem_type = TTM_PL_VRAM;
118122 rbo->placements[c++].flags = TTM_PL_FLAG_WC |
119
- TTM_PL_FLAG_UNCACHED |
120
- TTM_PL_FLAG_VRAM;
123
+ TTM_PL_FLAG_UNCACHED;
121124 }
122125
123126 if (domain & RADEON_GEM_DOMAIN_GTT) {
124127 if (rbo->flags & RADEON_GEM_GTT_UC) {
125128 rbo->placements[c].fpfn = 0;
126
- rbo->placements[c++].flags = TTM_PL_FLAG_UNCACHED |
127
- TTM_PL_FLAG_TT;
129
+ rbo->placements[c].mem_type = TTM_PL_TT;
130
+ rbo->placements[c++].flags = TTM_PL_FLAG_UNCACHED;
128131
129132 } else if ((rbo->flags & RADEON_GEM_GTT_WC) ||
130133 (rbo->rdev->flags & RADEON_IS_AGP)) {
131134 rbo->placements[c].fpfn = 0;
135
+ rbo->placements[c].mem_type = TTM_PL_TT;
132136 rbo->placements[c++].flags = TTM_PL_FLAG_WC |
133
- TTM_PL_FLAG_UNCACHED |
134
- TTM_PL_FLAG_TT;
137
+ TTM_PL_FLAG_UNCACHED;
135138 } else {
136139 rbo->placements[c].fpfn = 0;
137
- rbo->placements[c++].flags = TTM_PL_FLAG_CACHED |
138
- TTM_PL_FLAG_TT;
140
+ rbo->placements[c].mem_type = TTM_PL_TT;
141
+ rbo->placements[c++].flags = TTM_PL_FLAG_CACHED;
139142 }
140143 }
141144
142145 if (domain & RADEON_GEM_DOMAIN_CPU) {
143146 if (rbo->flags & RADEON_GEM_GTT_UC) {
144147 rbo->placements[c].fpfn = 0;
145
- rbo->placements[c++].flags = TTM_PL_FLAG_UNCACHED |
146
- TTM_PL_FLAG_SYSTEM;
148
+ rbo->placements[c].mem_type = TTM_PL_SYSTEM;
149
+ rbo->placements[c++].flags = TTM_PL_FLAG_UNCACHED;
147150
148151 } else if ((rbo->flags & RADEON_GEM_GTT_WC) ||
149152 rbo->rdev->flags & RADEON_IS_AGP) {
150153 rbo->placements[c].fpfn = 0;
154
+ rbo->placements[c].mem_type = TTM_PL_SYSTEM;
151155 rbo->placements[c++].flags = TTM_PL_FLAG_WC |
152
- TTM_PL_FLAG_UNCACHED |
153
- TTM_PL_FLAG_SYSTEM;
156
+ TTM_PL_FLAG_UNCACHED;
154157 } else {
155158 rbo->placements[c].fpfn = 0;
156
- rbo->placements[c++].flags = TTM_PL_FLAG_CACHED |
157
- TTM_PL_FLAG_SYSTEM;
159
+ rbo->placements[c].mem_type = TTM_PL_SYSTEM;
160
+ rbo->placements[c++].flags = TTM_PL_FLAG_CACHED;
158161 }
159162 }
160163 if (!c) {
161164 rbo->placements[c].fpfn = 0;
162
- rbo->placements[c++].flags = TTM_PL_MASK_CACHING |
163
- TTM_PL_FLAG_SYSTEM;
165
+ rbo->placements[c].mem_type = TTM_PL_SYSTEM;
166
+ rbo->placements[c++].flags = TTM_PL_MASK_CACHING;
164167 }
165168
166169 rbo->placement.num_placement = c;
....@@ -168,7 +171,7 @@
168171
169172 for (i = 0; i < c; ++i) {
170173 if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&
171
- (rbo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
174
+ (rbo->placements[i].mem_type == TTM_PL_VRAM) &&
172175 !rbo->placements[i].fpfn)
173176 rbo->placements[i].lpfn =
174177 rbo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
....@@ -180,7 +183,7 @@
180183 int radeon_bo_create(struct radeon_device *rdev,
181184 unsigned long size, int byte_align, bool kernel,
182185 u32 domain, u32 flags, struct sg_table *sg,
183
- struct reservation_object *resv,
186
+ struct dma_resv *resv,
184187 struct radeon_bo **bo_ptr)
185188 {
186189 struct radeon_bo *bo;
....@@ -206,7 +209,7 @@
206209 bo = kzalloc(sizeof(struct radeon_bo), GFP_KERNEL);
207210 if (bo == NULL)
208211 return -ENOMEM;
209
- drm_gem_private_object_init(rdev->ddev, &bo->gem_base, size);
212
+ drm_gem_private_object_init(rdev->ddev, &bo->tbo.base, size);
210213 bo->rdev = rdev;
211214 bo->surface_reg = -1;
212215 INIT_LIST_HEAD(&bo->list);
....@@ -314,11 +317,9 @@
314317 void radeon_bo_unref(struct radeon_bo **bo)
315318 {
316319 struct ttm_buffer_object *tbo;
317
- struct radeon_device *rdev;
318320
319321 if ((*bo) == NULL)
320322 return;
321
- rdev = (*bo)->rdev;
322323 tbo = &((*bo)->tbo);
323324 ttm_bo_put(tbo);
324325 *bo = NULL;
....@@ -330,7 +331,7 @@
330331 struct ttm_operation_ctx ctx = { false, false };
331332 int r, i;
332333
333
- if (radeon_ttm_tt_has_userptr(bo->tbo.ttm))
334
+ if (radeon_ttm_tt_has_userptr(bo->rdev, bo->tbo.ttm))
334335 return -EPERM;
335336
336337 if (bo->pin_count) {
....@@ -359,7 +360,7 @@
359360 radeon_ttm_placement_from_domain(bo, domain);
360361 for (i = 0; i < bo->placement.num_placement; i++) {
361362 /* force to pin into visible video ram */
362
- if ((bo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
363
+ if ((bo->placements[i].mem_type == TTM_PL_VRAM) &&
363364 !(bo->flags & RADEON_GEM_NO_CPU_ACCESS) &&
364365 (!max_offset || max_offset > bo->rdev->mc.visible_vram_size))
365366 bo->placements[i].lpfn =
....@@ -421,11 +422,13 @@
421422 int radeon_bo_evict_vram(struct radeon_device *rdev)
422423 {
423424 /* late 2.6.33 fix IGP hibernate - we need pm ops to do this correct */
424
- if (0 && (rdev->flags & RADEON_IS_IGP)) {
425
+#ifndef CONFIG_HIBERNATION
426
+ if (rdev->flags & RADEON_IS_IGP) {
425427 if (rdev->mc.igp_sideport_enabled == false)
426428 /* Useless to evict on IGP chips */
427429 return 0;
428430 }
431
+#endif
429432 return ttm_bo_evict_mm(&rdev->mman.bdev, TTM_PL_VRAM);
430433 }
431434
....@@ -439,13 +442,13 @@
439442 dev_err(rdev->dev, "Userspace still has active objects !\n");
440443 list_for_each_entry_safe(bo, n, &rdev->gem.objects, list) {
441444 dev_err(rdev->dev, "%p %p %lu %lu force free\n",
442
- &bo->gem_base, bo, (unsigned long)bo->gem_base.size,
443
- *((unsigned long *)&bo->gem_base.refcount));
445
+ &bo->tbo.base, bo, (unsigned long)bo->tbo.base.size,
446
+ *((unsigned long *)&bo->tbo.base.refcount));
444447 mutex_lock(&bo->rdev->gem.mutex);
445448 list_del_init(&bo->list);
446449 mutex_unlock(&bo->rdev->gem.mutex);
447450 /* this should unref the ttm bo */
448
- drm_gem_object_put_unlocked(&bo->gem_base);
451
+ drm_gem_object_put(&bo->tbo.base);
449452 }
450453 }
451454
....@@ -607,7 +610,7 @@
607610 int steal;
608611 int i;
609612
610
- lockdep_assert_held(&bo->tbo.resv->lock.base);
613
+ dma_resv_assert_held(bo->tbo.base.resv);
611614
612615 if (!bo->tiling_flags)
613616 return 0;
....@@ -733,7 +736,7 @@
733736 uint32_t *tiling_flags,
734737 uint32_t *pitch)
735738 {
736
- lockdep_assert_held(&bo->tbo.resv->lock.base);
739
+ dma_resv_assert_held(bo->tbo.base.resv);
737740
738741 if (tiling_flags)
739742 *tiling_flags = bo->tiling_flags;
....@@ -745,7 +748,7 @@
745748 bool force_drop)
746749 {
747750 if (!force_drop)
748
- lockdep_assert_held(&bo->tbo.resv->lock.base);
751
+ dma_resv_assert_held(bo->tbo.base.resv);
749752
750753 if (!(bo->tiling_flags & RADEON_TILING_SURFACE))
751754 return 0;
....@@ -772,7 +775,7 @@
772775
773776 void radeon_bo_move_notify(struct ttm_buffer_object *bo,
774777 bool evict,
775
- struct ttm_mem_reg *new_mem)
778
+ struct ttm_resource *new_mem)
776779 {
777780 struct radeon_bo *rbo;
778781
....@@ -821,7 +824,7 @@
821824 lpfn = rdev->mc.visible_vram_size >> PAGE_SHIFT;
822825 for (i = 0; i < rbo->placement.num_placement; i++) {
823826 /* Force into visible VRAM */
824
- if ((rbo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
827
+ if ((rbo->placements[i].mem_type == TTM_PL_VRAM) &&
825828 (!rbo->placements[i].lpfn || rbo->placements[i].lpfn > lpfn))
826829 rbo->placements[i].lpfn = lpfn;
827830 }
....@@ -867,10 +870,10 @@
867870 void radeon_bo_fence(struct radeon_bo *bo, struct radeon_fence *fence,
868871 bool shared)
869872 {
870
- struct reservation_object *resv = bo->tbo.resv;
873
+ struct dma_resv *resv = bo->tbo.base.resv;
871874
872875 if (shared)
873
- reservation_object_add_shared_fence(resv, &fence->base);
876
+ dma_resv_add_shared_fence(resv, &fence->base);
874877 else
875
- reservation_object_add_excl_fence(resv, &fence->base);
878
+ dma_resv_add_excl_fence(resv, &fence->base);
876879 }