diff options
author | Alex Deucher <alexander.deucher@amd.com> | 2015-10-08 11:31:58 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2015-10-14 16:16:34 -0400 |
commit | 72b400675a900e80a75cad57db6aa726c68ffb3f (patch) | |
tree | 9b6329372647692a43347ec4adcc344120558f64 | |
parent | c4e0dfadb2d4c054ca06641da77294fd5c61725a (diff) |
drm/amdgpu/dce8: Clean up reference counting and pinning of the cursor BOs
Take a GEM reference for and pin the new cursor BO, unpin and drop the
GEM reference for the old cursor BO in dce8 crtc_cursor_set2, and use
amdgpu_crtc->cursor_addr in dce8 set_cursor.
This fixes dce8 cursor_reset accidentally incrementing the cursor BO
pin count, and cleans up the code a little.
Port of radeon commit:
cd404af0c930104462aa91344f07d002cf8248ed
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/dce_v8_0.c | 61 |
1 files changed, 24 insertions, 37 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c index aac998010128..aebfe3cd6c2d 100644 --- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c +++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c | |||
@@ -2449,34 +2449,15 @@ static int dce_v8_0_cursor_move_locked(struct drm_crtc *crtc, | |||
2449 | return 0; | 2449 | return 0; |
2450 | } | 2450 | } |
2451 | 2451 | ||
2452 | static int dce_v8_0_set_cursor(struct drm_crtc *crtc, struct drm_gem_object *obj) | 2452 | static void dce_v8_0_set_cursor(struct drm_crtc *crtc) |
2453 | { | 2453 | { |
2454 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); | 2454 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
2455 | struct amdgpu_device *adev = crtc->dev->dev_private; | 2455 | struct amdgpu_device *adev = crtc->dev->dev_private; |
2456 | struct amdgpu_bo *aobj = gem_to_amdgpu_bo(obj); | ||
2457 | uint64_t gpu_addr; | ||
2458 | int ret; | ||
2459 | |||
2460 | ret = amdgpu_bo_reserve(aobj, false); | ||
2461 | if (unlikely(ret != 0)) | ||
2462 | goto fail; | ||
2463 | |||
2464 | ret = amdgpu_bo_pin(aobj, AMDGPU_GEM_DOMAIN_VRAM, &gpu_addr); | ||
2465 | amdgpu_bo_unreserve(aobj); | ||
2466 | if (ret) | ||
2467 | goto fail; | ||
2468 | 2456 | ||
2469 | WREG32(mmCUR_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset, | 2457 | WREG32(mmCUR_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset, |
2470 | upper_32_bits(gpu_addr)); | 2458 | upper_32_bits(amdgpu_crtc->cursor_addr)); |
2471 | WREG32(mmCUR_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset, | 2459 | WREG32(mmCUR_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset, |
2472 | lower_32_bits(gpu_addr)); | 2460 | lower_32_bits(amdgpu_crtc->cursor_addr)); |
2473 | |||
2474 | return 0; | ||
2475 | |||
2476 | fail: | ||
2477 | drm_gem_object_unreference_unlocked(obj); | ||
2478 | |||
2479 | return ret; | ||
2480 | } | 2461 | } |
2481 | 2462 | ||
2482 | static int dce_v8_0_crtc_cursor_move(struct drm_crtc *crtc, | 2463 | static int dce_v8_0_crtc_cursor_move(struct drm_crtc *crtc, |
@@ -2501,6 +2482,7 @@ static int dce_v8_0_crtc_cursor_set2(struct drm_crtc *crtc, | |||
2501 | { | 2482 | { |
2502 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); | 2483 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
2503 | struct drm_gem_object *obj; | 2484 | struct drm_gem_object *obj; |
2485 | struct amdgpu_bo *aobj; | ||
2504 | int ret; | 2486 | int ret; |
2505 | 2487 | ||
2506 | if (!handle) { | 2488 | if (!handle) { |
@@ -2522,6 +2504,21 @@ static int dce_v8_0_crtc_cursor_set2(struct drm_crtc *crtc, | |||
2522 | return -ENOENT; | 2504 | return -ENOENT; |
2523 | } | 2505 | } |
2524 | 2506 | ||
2507 | aobj = gem_to_amdgpu_bo(obj); | ||
2508 | ret = amdgpu_bo_reserve(aobj, false); | ||
2509 | if (ret != 0) { | ||
2510 | drm_gem_object_unreference_unlocked(obj); | ||
2511 | return ret; | ||
2512 | } | ||
2513 | |||
2514 | ret = amdgpu_bo_pin(aobj, AMDGPU_GEM_DOMAIN_VRAM, &amdgpu_crtc->cursor_addr); | ||
2515 | amdgpu_bo_unreserve(aobj); | ||
2516 | if (ret) { | ||
2517 | DRM_ERROR("Failed to pin new cursor BO (%d)\n", ret); | ||
2518 | drm_gem_object_unreference_unlocked(obj); | ||
2519 | return ret; | ||
2520 | } | ||
2521 | |||
2525 | amdgpu_crtc->cursor_width = width; | 2522 | amdgpu_crtc->cursor_width = width; |
2526 | amdgpu_crtc->cursor_height = height; | 2523 | amdgpu_crtc->cursor_height = height; |
2527 | 2524 | ||
@@ -2540,12 +2537,8 @@ static int dce_v8_0_crtc_cursor_set2(struct drm_crtc *crtc, | |||
2540 | amdgpu_crtc->cursor_hot_y = hot_y; | 2537 | amdgpu_crtc->cursor_hot_y = hot_y; |
2541 | } | 2538 | } |
2542 | 2539 | ||
2543 | ret = dce_v8_0_set_cursor(crtc, obj); | 2540 | dce_v8_0_set_cursor(crtc); |
2544 | if (ret) | 2541 | dce_v8_0_show_cursor(crtc); |
2545 | DRM_ERROR("dce_v8_0_set_cursor returned %d, not changing cursor\n", | ||
2546 | ret); | ||
2547 | else | ||
2548 | dce_v8_0_show_cursor(crtc); | ||
2549 | dce_v8_0_lock_cursor(crtc, false); | 2542 | dce_v8_0_lock_cursor(crtc, false); |
2550 | 2543 | ||
2551 | unpin: | 2544 | unpin: |
@@ -2556,8 +2549,7 @@ unpin: | |||
2556 | amdgpu_bo_unpin(aobj); | 2549 | amdgpu_bo_unpin(aobj); |
2557 | amdgpu_bo_unreserve(aobj); | 2550 | amdgpu_bo_unreserve(aobj); |
2558 | } | 2551 | } |
2559 | if (amdgpu_crtc->cursor_bo != obj) | 2552 | drm_gem_object_unreference_unlocked(amdgpu_crtc->cursor_bo); |
2560 | drm_gem_object_unreference_unlocked(amdgpu_crtc->cursor_bo); | ||
2561 | } | 2553 | } |
2562 | 2554 | ||
2563 | amdgpu_crtc->cursor_bo = obj; | 2555 | amdgpu_crtc->cursor_bo = obj; |
@@ -2567,7 +2559,6 @@ unpin: | |||
2567 | static void dce_v8_0_cursor_reset(struct drm_crtc *crtc) | 2559 | static void dce_v8_0_cursor_reset(struct drm_crtc *crtc) |
2568 | { | 2560 | { |
2569 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); | 2561 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
2570 | int ret; | ||
2571 | 2562 | ||
2572 | if (amdgpu_crtc->cursor_bo) { | 2563 | if (amdgpu_crtc->cursor_bo) { |
2573 | dce_v8_0_lock_cursor(crtc, true); | 2564 | dce_v8_0_lock_cursor(crtc, true); |
@@ -2575,12 +2566,8 @@ static void dce_v8_0_cursor_reset(struct drm_crtc *crtc) | |||
2575 | dce_v8_0_cursor_move_locked(crtc, amdgpu_crtc->cursor_x, | 2566 | dce_v8_0_cursor_move_locked(crtc, amdgpu_crtc->cursor_x, |
2576 | amdgpu_crtc->cursor_y); | 2567 | amdgpu_crtc->cursor_y); |
2577 | 2568 | ||
2578 | ret = dce_v8_0_set_cursor(crtc, amdgpu_crtc->cursor_bo); | 2569 | dce_v8_0_set_cursor(crtc); |
2579 | if (ret) | 2570 | dce_v8_0_show_cursor(crtc); |
2580 | DRM_ERROR("dce_v8_0_set_cursor returned %d, not showing " | ||
2581 | "cursor\n", ret); | ||
2582 | else | ||
2583 | dce_v8_0_show_cursor(crtc); | ||
2584 | 2571 | ||
2585 | dce_v8_0_lock_cursor(crtc, false); | 2572 | dce_v8_0_lock_cursor(crtc, false); |
2586 | } | 2573 | } |