Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Christian König. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sub license, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
| 12 | * |
| 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 16 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 17 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 18 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 19 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | * |
| 21 | * The above copyright notice and this permission notice (including the |
| 22 | * next paragraph) shall be included in all copies or substantial portions |
| 23 | * of the Software. |
| 24 | * |
| 25 | */ |
| 26 | /* |
| 27 | * Authors: |
| 28 | * Christian König <deathsimple@vodafone.de> |
| 29 | */ |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 30 | #include <drm/drmP.h> |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 31 | #include "radeon.h" |
| 32 | |
Jerome Glisse | c1341e5 | 2011-12-21 12:13:47 -0500 | [diff] [blame] | 33 | |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 34 | int radeon_semaphore_create(struct radeon_device *rdev, |
| 35 | struct radeon_semaphore **semaphore) |
| 36 | { |
Jerome Glisse | c1341e5 | 2011-12-21 12:13:47 -0500 | [diff] [blame] | 37 | int r; |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 38 | |
Jerome Glisse | a8c0594 | 2012-05-09 15:34:57 +0200 | [diff] [blame] | 39 | *semaphore = kmalloc(sizeof(struct radeon_semaphore), GFP_KERNEL); |
Jerome Glisse | c1341e5 | 2011-12-21 12:13:47 -0500 | [diff] [blame] | 40 | if (*semaphore == NULL) { |
Jerome Glisse | c1341e5 | 2011-12-21 12:13:47 -0500 | [diff] [blame] | 41 | return -ENOMEM; |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 42 | } |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 43 | r = radeon_sa_bo_new(rdev, &rdev->ring_tmp_bo, |
Jerome Glisse | a8c0594 | 2012-05-09 15:34:57 +0200 | [diff] [blame] | 44 | &(*semaphore)->sa_bo, 8, 8, true); |
| 45 | if (r) { |
| 46 | kfree(*semaphore); |
| 47 | *semaphore = NULL; |
| 48 | return r; |
| 49 | } |
| 50 | (*semaphore)->waiters = 0; |
| 51 | (*semaphore)->gpu_addr = radeon_sa_bo_gpu_addr((*semaphore)->sa_bo); |
| 52 | *((uint64_t*)radeon_sa_bo_cpu_addr((*semaphore)->sa_bo)) = 0; |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | void radeon_semaphore_emit_signal(struct radeon_device *rdev, int ring, |
| 57 | struct radeon_semaphore *semaphore) |
| 58 | { |
Jerome Glisse | a8c0594 | 2012-05-09 15:34:57 +0200 | [diff] [blame] | 59 | --semaphore->waiters; |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 60 | radeon_semaphore_ring_emit(rdev, ring, &rdev->ring[ring], semaphore, false); |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring, |
| 64 | struct radeon_semaphore *semaphore) |
| 65 | { |
Jerome Glisse | a8c0594 | 2012-05-09 15:34:57 +0200 | [diff] [blame] | 66 | ++semaphore->waiters; |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 67 | radeon_semaphore_ring_emit(rdev, ring, &rdev->ring[ring], semaphore, true); |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 68 | } |
| 69 | |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 70 | /* caller must hold ring lock */ |
Christian König | 8f676c4 | 2012-05-02 15:11:18 +0200 | [diff] [blame] | 71 | int radeon_semaphore_sync_rings(struct radeon_device *rdev, |
| 72 | struct radeon_semaphore *semaphore, |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 73 | int signaler, int waiter) |
Christian König | 8f676c4 | 2012-05-02 15:11:18 +0200 | [diff] [blame] | 74 | { |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 75 | int r; |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 76 | |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 77 | /* no need to signal and wait on the same ring */ |
| 78 | if (signaler == waiter) { |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | /* prevent GPU deadlocks */ |
| 83 | if (!rdev->ring[signaler].ready) { |
| 84 | dev_err(rdev->dev, "Trying to sync to a disabled ring!"); |
| 85 | return -EINVAL; |
| 86 | } |
| 87 | |
| 88 | r = radeon_ring_alloc(rdev, &rdev->ring[signaler], 8); |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 89 | if (r) { |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 90 | return r; |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 91 | } |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 92 | radeon_semaphore_emit_signal(rdev, signaler, semaphore); |
| 93 | radeon_ring_commit(rdev, &rdev->ring[signaler]); |
Christian König | 8f676c4 | 2012-05-02 15:11:18 +0200 | [diff] [blame] | 94 | |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 95 | /* we assume caller has already allocated space on waiters ring */ |
| 96 | radeon_semaphore_emit_wait(rdev, waiter, semaphore); |
Christian König | 8f676c4 | 2012-05-02 15:11:18 +0200 | [diff] [blame] | 97 | |
| 98 | return 0; |
Christian König | 8f676c4 | 2012-05-02 15:11:18 +0200 | [diff] [blame] | 99 | } |
| 100 | |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 101 | void radeon_semaphore_free(struct radeon_device *rdev, |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 102 | struct radeon_semaphore **semaphore, |
Jerome Glisse | a8c0594 | 2012-05-09 15:34:57 +0200 | [diff] [blame] | 103 | struct radeon_fence *fence) |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 104 | { |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 105 | if (semaphore == NULL || *semaphore == NULL) { |
Jerome Glisse | a8c0594 | 2012-05-09 15:34:57 +0200 | [diff] [blame] | 106 | return; |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 107 | } |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 108 | if ((*semaphore)->waiters > 0) { |
Jerome Glisse | a8c0594 | 2012-05-09 15:34:57 +0200 | [diff] [blame] | 109 | dev_err(rdev->dev, "semaphore %p has more waiters than signalers," |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 110 | " hardware lockup imminent!\n", *semaphore); |
Jerome Glisse | a8c0594 | 2012-05-09 15:34:57 +0200 | [diff] [blame] | 111 | } |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 112 | radeon_sa_bo_free(rdev, &(*semaphore)->sa_bo, fence); |
| 113 | kfree(*semaphore); |
| 114 | *semaphore = NULL; |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 115 | } |