diff options
author | Alex Deucher <alexander.deucher@amd.com> | 2017-12-14 16:39:02 -0500 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2017-12-18 10:59:35 -0500 |
commit | f5ec697e37023ce60dc1c38bf6b2bf32de767376 (patch) | |
tree | a0c41f14d3a0939c3fb8ddd721f35ceb6345dd2f | |
parent | 2543e28a81b8d687880315475ba1203ca2f7496a (diff) |
drm/amdgpu: move fw_reserve functions to amdgpu_ttm.c
It's the only place they are used.
Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 95 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 99 |
3 files changed, 97 insertions, 100 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index ac21addcde7d..a8390abe13a6 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h | |||
@@ -1387,9 +1387,6 @@ struct amdgpu_fw_vram_usage { | |||
1387 | void *va; | 1387 | void *va; |
1388 | }; | 1388 | }; |
1389 | 1389 | ||
1390 | int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev); | ||
1391 | void amdgpu_fw_reserve_vram_fini(struct amdgpu_device *adev); | ||
1392 | |||
1393 | /* | 1390 | /* |
1394 | * CGS | 1391 | * CGS |
1395 | */ | 1392 | */ |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 09ffa9fbcd92..3135287c0f5b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | |||
@@ -597,101 +597,6 @@ void amdgpu_device_gart_location(struct amdgpu_device *adev, | |||
597 | mc->gart_size >> 20, mc->gart_start, mc->gart_end); | 597 | mc->gart_size >> 20, mc->gart_start, mc->gart_end); |
598 | } | 598 | } |
599 | 599 | ||
600 | /* | ||
601 | * Firmware Reservation functions | ||
602 | */ | ||
603 | /** | ||
604 | * amdgpu_fw_reserve_vram_fini - free fw reserved vram | ||
605 | * | ||
606 | * @adev: amdgpu_device pointer | ||
607 | * | ||
608 | * free fw reserved vram if it has been reserved. | ||
609 | */ | ||
610 | void amdgpu_fw_reserve_vram_fini(struct amdgpu_device *adev) | ||
611 | { | ||
612 | amdgpu_bo_free_kernel(&adev->fw_vram_usage.reserved_bo, | ||
613 | NULL, &adev->fw_vram_usage.va); | ||
614 | } | ||
615 | |||
616 | /** | ||
617 | * amdgpu_fw_reserve_vram_init - create bo vram reservation from fw | ||
618 | * | ||
619 | * @adev: amdgpu_device pointer | ||
620 | * | ||
621 | * create bo vram reservation from fw. | ||
622 | */ | ||
623 | int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev) | ||
624 | { | ||
625 | struct ttm_operation_ctx ctx = { false, false }; | ||
626 | int r = 0; | ||
627 | int i; | ||
628 | u64 vram_size = adev->mc.visible_vram_size; | ||
629 | u64 offset = adev->fw_vram_usage.start_offset; | ||
630 | u64 size = adev->fw_vram_usage.size; | ||
631 | struct amdgpu_bo *bo; | ||
632 | |||
633 | adev->fw_vram_usage.va = NULL; | ||
634 | adev->fw_vram_usage.reserved_bo = NULL; | ||
635 | |||
636 | if (adev->fw_vram_usage.size > 0 && | ||
637 | adev->fw_vram_usage.size <= vram_size) { | ||
638 | |||
639 | r = amdgpu_bo_create(adev, adev->fw_vram_usage.size, | ||
640 | PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_VRAM, | ||
641 | AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED | | ||
642 | AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS, NULL, NULL, 0, | ||
643 | &adev->fw_vram_usage.reserved_bo); | ||
644 | if (r) | ||
645 | goto error_create; | ||
646 | |||
647 | r = amdgpu_bo_reserve(adev->fw_vram_usage.reserved_bo, false); | ||
648 | if (r) | ||
649 | goto error_reserve; | ||
650 | |||
651 | /* remove the original mem node and create a new one at the | ||
652 | * request position | ||
653 | */ | ||
654 | bo = adev->fw_vram_usage.reserved_bo; | ||
655 | offset = ALIGN(offset, PAGE_SIZE); | ||
656 | for (i = 0; i < bo->placement.num_placement; ++i) { | ||
657 | bo->placements[i].fpfn = offset >> PAGE_SHIFT; | ||
658 | bo->placements[i].lpfn = (offset + size) >> PAGE_SHIFT; | ||
659 | } | ||
660 | |||
661 | ttm_bo_mem_put(&bo->tbo, &bo->tbo.mem); | ||
662 | r = ttm_bo_mem_space(&bo->tbo, &bo->placement, | ||
663 | &bo->tbo.mem, &ctx); | ||
664 | if (r) | ||
665 | goto error_pin; | ||
666 | |||
667 | r = amdgpu_bo_pin_restricted(adev->fw_vram_usage.reserved_bo, | ||
668 | AMDGPU_GEM_DOMAIN_VRAM, | ||
669 | adev->fw_vram_usage.start_offset, | ||
670 | (adev->fw_vram_usage.start_offset + | ||
671 | adev->fw_vram_usage.size), NULL); | ||
672 | if (r) | ||
673 | goto error_pin; | ||
674 | r = amdgpu_bo_kmap(adev->fw_vram_usage.reserved_bo, | ||
675 | &adev->fw_vram_usage.va); | ||
676 | if (r) | ||
677 | goto error_kmap; | ||
678 | |||
679 | amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo); | ||
680 | } | ||
681 | return r; | ||
682 | |||
683 | error_kmap: | ||
684 | amdgpu_bo_unpin(adev->fw_vram_usage.reserved_bo); | ||
685 | error_pin: | ||
686 | amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo); | ||
687 | error_reserve: | ||
688 | amdgpu_bo_unref(&adev->fw_vram_usage.reserved_bo); | ||
689 | error_create: | ||
690 | adev->fw_vram_usage.va = NULL; | ||
691 | adev->fw_vram_usage.reserved_bo = NULL; | ||
692 | return r; | ||
693 | } | ||
694 | |||
695 | /** | 600 | /** |
696 | * amdgpu_device_resize_fb_bar - try to resize FB BAR | 601 | * amdgpu_device_resize_fb_bar - try to resize FB BAR |
697 | * | 602 | * |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index c307a7d2cf16..5b5554cba35f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | |||
@@ -1269,6 +1269,101 @@ static struct ttm_bo_driver amdgpu_bo_driver = { | |||
1269 | .access_memory = &amdgpu_ttm_access_memory | 1269 | .access_memory = &amdgpu_ttm_access_memory |
1270 | }; | 1270 | }; |
1271 | 1271 | ||
1272 | /* | ||
1273 | * Firmware Reservation functions | ||
1274 | */ | ||
1275 | /** | ||
1276 | * amdgpu_ttm_fw_reserve_vram_fini - free fw reserved vram | ||
1277 | * | ||
1278 | * @adev: amdgpu_device pointer | ||
1279 | * | ||
1280 | * free fw reserved vram if it has been reserved. | ||
1281 | */ | ||
1282 | static void amdgpu_ttm_fw_reserve_vram_fini(struct amdgpu_device *adev) | ||
1283 | { | ||
1284 | amdgpu_bo_free_kernel(&adev->fw_vram_usage.reserved_bo, | ||
1285 | NULL, &adev->fw_vram_usage.va); | ||
1286 | } | ||
1287 | |||
1288 | /** | ||
1289 | * amdgpu_ttm_fw_reserve_vram_init - create bo vram reservation from fw | ||
1290 | * | ||
1291 | * @adev: amdgpu_device pointer | ||
1292 | * | ||
1293 | * create bo vram reservation from fw. | ||
1294 | */ | ||
1295 | static int amdgpu_ttm_fw_reserve_vram_init(struct amdgpu_device *adev) | ||
1296 | { | ||
1297 | struct ttm_operation_ctx ctx = { false, false }; | ||
1298 | int r = 0; | ||
1299 | int i; | ||
1300 | u64 vram_size = adev->mc.visible_vram_size; | ||
1301 | u64 offset = adev->fw_vram_usage.start_offset; | ||
1302 | u64 size = adev->fw_vram_usage.size; | ||
1303 | struct amdgpu_bo *bo; | ||
1304 | |||
1305 | adev->fw_vram_usage.va = NULL; | ||
1306 | adev->fw_vram_usage.reserved_bo = NULL; | ||
1307 | |||
1308 | if (adev->fw_vram_usage.size > 0 && | ||
1309 | adev->fw_vram_usage.size <= vram_size) { | ||
1310 | |||
1311 | r = amdgpu_bo_create(adev, adev->fw_vram_usage.size, | ||
1312 | PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_VRAM, | ||
1313 | AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED | | ||
1314 | AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS, NULL, NULL, 0, | ||
1315 | &adev->fw_vram_usage.reserved_bo); | ||
1316 | if (r) | ||
1317 | goto error_create; | ||
1318 | |||
1319 | r = amdgpu_bo_reserve(adev->fw_vram_usage.reserved_bo, false); | ||
1320 | if (r) | ||
1321 | goto error_reserve; | ||
1322 | |||
1323 | /* remove the original mem node and create a new one at the | ||
1324 | * request position | ||
1325 | */ | ||
1326 | bo = adev->fw_vram_usage.reserved_bo; | ||
1327 | offset = ALIGN(offset, PAGE_SIZE); | ||
1328 | for (i = 0; i < bo->placement.num_placement; ++i) { | ||
1329 | bo->placements[i].fpfn = offset >> PAGE_SHIFT; | ||
1330 | bo->placements[i].lpfn = (offset + size) >> PAGE_SHIFT; | ||
1331 | } | ||
1332 | |||
1333 | ttm_bo_mem_put(&bo->tbo, &bo->tbo.mem); | ||
1334 | r = ttm_bo_mem_space(&bo->tbo, &bo->placement, | ||
1335 | &bo->tbo.mem, &ctx); | ||
1336 | if (r) | ||
1337 | goto error_pin; | ||
1338 | |||
1339 | r = amdgpu_bo_pin_restricted(adev->fw_vram_usage.reserved_bo, | ||
1340 | AMDGPU_GEM_DOMAIN_VRAM, | ||
1341 | adev->fw_vram_usage.start_offset, | ||
1342 | (adev->fw_vram_usage.start_offset + | ||
1343 | adev->fw_vram_usage.size), NULL); | ||
1344 | if (r) | ||
1345 | goto error_pin; | ||
1346 | r = amdgpu_bo_kmap(adev->fw_vram_usage.reserved_bo, | ||
1347 | &adev->fw_vram_usage.va); | ||
1348 | if (r) | ||
1349 | goto error_kmap; | ||
1350 | |||
1351 | amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo); | ||
1352 | } | ||
1353 | return r; | ||
1354 | |||
1355 | error_kmap: | ||
1356 | amdgpu_bo_unpin(adev->fw_vram_usage.reserved_bo); | ||
1357 | error_pin: | ||
1358 | amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo); | ||
1359 | error_reserve: | ||
1360 | amdgpu_bo_unref(&adev->fw_vram_usage.reserved_bo); | ||
1361 | error_create: | ||
1362 | adev->fw_vram_usage.va = NULL; | ||
1363 | adev->fw_vram_usage.reserved_bo = NULL; | ||
1364 | return r; | ||
1365 | } | ||
1366 | |||
1272 | int amdgpu_ttm_init(struct amdgpu_device *adev) | 1367 | int amdgpu_ttm_init(struct amdgpu_device *adev) |
1273 | { | 1368 | { |
1274 | uint64_t gtt_size; | 1369 | uint64_t gtt_size; |
@@ -1311,7 +1406,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) | |||
1311 | *The reserved vram for firmware must be pinned to the specified | 1406 | *The reserved vram for firmware must be pinned to the specified |
1312 | *place on the VRAM, so reserve it early. | 1407 | *place on the VRAM, so reserve it early. |
1313 | */ | 1408 | */ |
1314 | r = amdgpu_fw_reserve_vram_init(adev); | 1409 | r = amdgpu_ttm_fw_reserve_vram_init(adev); |
1315 | if (r) { | 1410 | if (r) { |
1316 | return r; | 1411 | return r; |
1317 | } | 1412 | } |
@@ -1395,7 +1490,7 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev) | |||
1395 | 1490 | ||
1396 | amdgpu_ttm_debugfs_fini(adev); | 1491 | amdgpu_ttm_debugfs_fini(adev); |
1397 | amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL); | 1492 | amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL); |
1398 | amdgpu_fw_reserve_vram_fini(adev); | 1493 | amdgpu_ttm_fw_reserve_vram_fini(adev); |
1399 | 1494 | ||
1400 | ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_VRAM); | 1495 | ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_VRAM); |
1401 | ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_TT); | 1496 | ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_TT); |