forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/gpu/drm/ttm/ttm_tt.c
....@@ -48,7 +48,10 @@
4848 struct ttm_bo_device *bdev = bo->bdev;
4949 uint32_t page_flags = 0;
5050
51
- reservation_object_assert_held(bo->resv);
51
+ dma_resv_assert_held(bo->base.resv);
52
+
53
+ if (bo->ttm)
54
+ return 0;
5255
5356 if (bdev->need_dma32)
5457 page_flags |= TTM_PAGE_FLAG_DMA32;
....@@ -67,7 +70,6 @@
6770 page_flags |= TTM_PAGE_FLAG_SG;
6871 break;
6972 default:
70
- bo->ttm = NULL;
7173 pr_err("Illegal buffer object type\n");
7274 return -EINVAL;
7375 }
....@@ -154,7 +156,7 @@
154156 if (ttm->caching_state == c_state)
155157 return 0;
156158
157
- if (ttm->state == tt_unpopulated) {
159
+ if (!ttm_tt_is_populated(ttm)) {
158160 /* Change caching but don't populate */
159161 ttm->caching_state = c_state;
160162 return 0;
....@@ -205,32 +207,31 @@
205207 }
206208 EXPORT_SYMBOL(ttm_tt_set_placement_caching);
207209
208
-void ttm_tt_destroy(struct ttm_tt *ttm)
210
+void ttm_tt_destroy_common(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
209211 {
210
- if (ttm == NULL)
211
- return;
212
-
213
- ttm_tt_unbind(ttm);
214
-
215
- if (ttm->state == tt_unbound)
216
- ttm_tt_unpopulate(ttm);
212
+ ttm_tt_unpopulate(bdev, ttm);
217213
218214 if (!(ttm->page_flags & TTM_PAGE_FLAG_PERSISTENT_SWAP) &&
219215 ttm->swap_storage)
220216 fput(ttm->swap_storage);
221217
222218 ttm->swap_storage = NULL;
223
- ttm->func->destroy(ttm);
219
+}
220
+EXPORT_SYMBOL(ttm_tt_destroy_common);
221
+
222
+void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
223
+{
224
+ bdev->driver->ttm_tt_destroy(bdev, ttm);
224225 }
225226
226
-void ttm_tt_init_fields(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
227
- uint32_t page_flags)
227
+static void ttm_tt_init_fields(struct ttm_tt *ttm,
228
+ struct ttm_buffer_object *bo,
229
+ uint32_t page_flags)
228230 {
229
- ttm->bdev = bo->bdev;
230231 ttm->num_pages = bo->num_pages;
231232 ttm->caching_state = tt_cached;
232233 ttm->page_flags = page_flags;
233
- ttm->state = tt_unpopulated;
234
+ ttm_tt_set_unpopulated(ttm);
234235 ttm->swap_storage = NULL;
235236 ttm->sg = bo->sg;
236237 }
....@@ -305,42 +306,6 @@
305306 }
306307 EXPORT_SYMBOL(ttm_dma_tt_fini);
307308
308
-void ttm_tt_unbind(struct ttm_tt *ttm)
309
-{
310
- int ret;
311
-
312
- if (ttm->state == tt_bound) {
313
- ret = ttm->func->unbind(ttm);
314
- BUG_ON(ret);
315
- ttm->state = tt_unbound;
316
- }
317
-}
318
-
319
-int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem,
320
- struct ttm_operation_ctx *ctx)
321
-{
322
- int ret = 0;
323
-
324
- if (!ttm)
325
- return -EINVAL;
326
-
327
- if (ttm->state == tt_bound)
328
- return 0;
329
-
330
- ret = ttm_tt_populate(ttm, ctx);
331
- if (ret)
332
- return ret;
333
-
334
- ret = ttm->func->bind(ttm, bo_mem);
335
- if (unlikely(ret != 0))
336
- return ret;
337
-
338
- ttm->state = tt_bound;
339
-
340
- return 0;
341
-}
342
-EXPORT_SYMBOL(ttm_tt_bind);
343
-
344309 int ttm_tt_swapin(struct ttm_tt *ttm)
345310 {
346311 struct address_space *swap_space;
....@@ -383,7 +348,8 @@
383348 return ret;
384349 }
385350
386
-int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
351
+int ttm_tt_swapout(struct ttm_bo_device *bdev,
352
+ struct ttm_tt *ttm, struct file *persistent_swap_storage)
387353 {
388354 struct address_space *swap_space;
389355 struct file *swap_storage;
....@@ -392,7 +358,6 @@
392358 int i;
393359 int ret = -ENOMEM;
394360
395
- BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated);
396361 BUG_ON(ttm->caching_state != tt_cached);
397362
398363 if (!persistent_swap_storage) {
....@@ -429,7 +394,7 @@
429394 put_page(to_page);
430395 }
431396
432
- ttm_tt_unpopulate(ttm);
397
+ ttm_tt_unpopulate(bdev, ttm);
433398 ttm->swap_storage = swap_storage;
434399 ttm->page_flags |= TTM_PAGE_FLAG_SWAPPED;
435400 if (persistent_swap_storage)
....@@ -443,7 +408,7 @@
443408 return ret;
444409 }
445410
446
-static void ttm_tt_add_mapping(struct ttm_tt *ttm)
411
+static void ttm_tt_add_mapping(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
447412 {
448413 pgoff_t i;
449414
....@@ -451,24 +416,29 @@
451416 return;
452417
453418 for (i = 0; i < ttm->num_pages; ++i)
454
- ttm->pages[i]->mapping = ttm->bdev->dev_mapping;
419
+ ttm->pages[i]->mapping = bdev->dev_mapping;
455420 }
456421
457
-int ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
422
+int ttm_tt_populate(struct ttm_bo_device *bdev,
423
+ struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
458424 {
459425 int ret;
460426
461
- if (ttm->state != tt_unpopulated)
427
+ if (!ttm)
428
+ return -EINVAL;
429
+
430
+ if (ttm_tt_is_populated(ttm))
462431 return 0;
463432
464
- if (ttm->bdev->driver->ttm_tt_populate)
465
- ret = ttm->bdev->driver->ttm_tt_populate(ttm, ctx);
433
+ if (bdev->driver->ttm_tt_populate)
434
+ ret = bdev->driver->ttm_tt_populate(bdev, ttm, ctx);
466435 else
467436 ret = ttm_pool_populate(ttm, ctx);
468437 if (!ret)
469
- ttm_tt_add_mapping(ttm);
438
+ ttm_tt_add_mapping(bdev, ttm);
470439 return ret;
471440 }
441
+EXPORT_SYMBOL(ttm_tt_populate);
472442
473443 static void ttm_tt_clear_mapping(struct ttm_tt *ttm)
474444 {
....@@ -484,14 +454,16 @@
484454 }
485455 }
486456
487
-void ttm_tt_unpopulate(struct ttm_tt *ttm)
457
+void ttm_tt_unpopulate(struct ttm_bo_device *bdev,
458
+ struct ttm_tt *ttm)
488459 {
489
- if (ttm->state == tt_unpopulated)
460
+ if (!ttm_tt_is_populated(ttm))
490461 return;
491462
492463 ttm_tt_clear_mapping(ttm);
493
- if (ttm->bdev->driver->ttm_tt_unpopulate)
494
- ttm->bdev->driver->ttm_tt_unpopulate(ttm);
464
+ if (bdev->driver->ttm_tt_unpopulate)
465
+ bdev->driver->ttm_tt_unpopulate(bdev, ttm);
495466 else
496467 ttm_pool_unpopulate(ttm);
497468 }
469
+EXPORT_SYMBOL(ttm_tt_unpopulate);