drm/radeon: rework ring syncing code
[deliverable/linux.git] / drivers / gpu / drm / radeon / radeon_semaphore.c
CommitLineData
15d3332f
CK
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 */
30#include "drmP.h"
31#include "drm.h"
32#include "radeon.h"
33
15d3332f
CK
34
35int radeon_semaphore_create(struct radeon_device *rdev,
36 struct radeon_semaphore **semaphore)
37{
c1341e52 38 int r;
15d3332f 39
a8c05940 40 *semaphore = kmalloc(sizeof(struct radeon_semaphore), GFP_KERNEL);
c1341e52 41 if (*semaphore == NULL) {
c1341e52
JG
42 return -ENOMEM;
43 }
c507f7ef 44 r = radeon_sa_bo_new(rdev, &rdev->ring_tmp_bo,
a8c05940
JG
45 &(*semaphore)->sa_bo, 8, 8, true);
46 if (r) {
47 kfree(*semaphore);
48 *semaphore = NULL;
49 return r;
50 }
51 (*semaphore)->waiters = 0;
52 (*semaphore)->gpu_addr = radeon_sa_bo_gpu_addr((*semaphore)->sa_bo);
53 *((uint64_t*)radeon_sa_bo_cpu_addr((*semaphore)->sa_bo)) = 0;
15d3332f
CK
54 return 0;
55}
56
57void radeon_semaphore_emit_signal(struct radeon_device *rdev, int ring,
58 struct radeon_semaphore *semaphore)
59{
a8c05940 60 --semaphore->waiters;
e32eb50d 61 radeon_semaphore_ring_emit(rdev, ring, &rdev->ring[ring], semaphore, false);
15d3332f
CK
62}
63
64void radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring,
65 struct radeon_semaphore *semaphore)
66{
a8c05940 67 ++semaphore->waiters;
e32eb50d 68 radeon_semaphore_ring_emit(rdev, ring, &rdev->ring[ring], semaphore, true);
15d3332f
CK
69}
70
220907d9 71/* caller must hold ring lock */
8f676c4c
CK
72int radeon_semaphore_sync_rings(struct radeon_device *rdev,
73 struct radeon_semaphore *semaphore,
220907d9 74 int signaler, int waiter)
8f676c4c 75{
220907d9 76 int r;
8f676c4c 77
220907d9
CK
78 /* no need to signal and wait on the same ring */
79 if (signaler == waiter) {
80 return 0;
d6999bc7 81 }
8f676c4c 82
220907d9
CK
83 /* prevent GPU deadlocks */
84 if (!rdev->ring[signaler].ready) {
85 dev_err(rdev->dev, "Trying to sync to a disabled ring!");
86 return -EINVAL;
87 }
8f676c4c 88
220907d9
CK
89 r = radeon_ring_alloc(rdev, &rdev->ring[signaler], 8);
90 if (r) {
91 return r;
8f676c4c 92 }
220907d9
CK
93 radeon_semaphore_emit_signal(rdev, signaler, semaphore);
94 radeon_ring_commit(rdev, &rdev->ring[signaler]);
8f676c4c 95
220907d9
CK
96 /* we assume caller has already allocated space on waiters ring */
97 radeon_semaphore_emit_wait(rdev, waiter, semaphore);
d6999bc7 98
8f676c4c 99 return 0;
8f676c4c
CK
100}
101
15d3332f 102void radeon_semaphore_free(struct radeon_device *rdev,
220907d9 103 struct radeon_semaphore **semaphore,
a8c05940 104 struct radeon_fence *fence)
15d3332f 105{
220907d9 106 if (semaphore == NULL || *semaphore == NULL) {
a8c05940
JG
107 return;
108 }
220907d9 109 if ((*semaphore)->waiters > 0) {
a8c05940 110 dev_err(rdev->dev, "semaphore %p has more waiters than signalers,"
220907d9 111 " hardware lockup imminent!\n", *semaphore);
15d3332f 112 }
220907d9
CK
113 radeon_sa_bo_free(rdev, &(*semaphore)->sa_bo, fence);
114 kfree(*semaphore);
115 *semaphore = NULL;
15d3332f 116}
This page took 0.079374 seconds and 5 git commands to generate.