Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc
[linux-2.6-block.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 */
760285e7 30#include <drm/drmP.h>
15d3332f 31#include "radeon.h"
bd80c8ba 32#include "radeon_trace.h"
15d3332f
CK
33
34int radeon_semaphore_create(struct radeon_device *rdev,
35 struct radeon_semaphore **semaphore)
36{
975700d2 37 int r;
15d3332f 38
a8c05940 39 *semaphore = kmalloc(sizeof(struct radeon_semaphore), GFP_KERNEL);
c1341e52 40 if (*semaphore == NULL) {
c1341e52
JG
41 return -ENOMEM;
42 }
975700d2
CK
43 r = radeon_sa_bo_new(rdev, &rdev->ring_tmp_bo,
44 &(*semaphore)->sa_bo, 8, 8);
a8c05940
JG
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);
8f53492f 52
975700d2 53 *((uint64_t *)radeon_sa_bo_cpu_addr((*semaphore)->sa_bo)) = 0;
1654b817 54
15d3332f
CK
55 return 0;
56}
57
1654b817 58bool radeon_semaphore_emit_signal(struct radeon_device *rdev, int ridx,
3cf8bb1a 59 struct radeon_semaphore *semaphore)
15d3332f 60{
1654b817
CK
61 struct radeon_ring *ring = &rdev->ring[ridx];
62
63 trace_radeon_semaphore_signale(ridx, semaphore);
64
65 if (radeon_semaphore_ring_emit(rdev, ridx, ring, semaphore, false)) {
66 --semaphore->waiters;
bd80c8ba 67
1654b817
CK
68 /* for debugging lockup only, used by sysfs debug files */
69 ring->last_semaphore_signal_addr = semaphore->gpu_addr;
70 return true;
71 }
72 return false;
15d3332f
CK
73}
74
1654b817 75bool radeon_semaphore_emit_wait(struct radeon_device *rdev, int ridx,
3cf8bb1a 76 struct radeon_semaphore *semaphore)
15d3332f 77{
1654b817
CK
78 struct radeon_ring *ring = &rdev->ring[ridx];
79
80 trace_radeon_semaphore_wait(ridx, semaphore);
81
82 if (radeon_semaphore_ring_emit(rdev, ridx, ring, semaphore, true)) {
83 ++semaphore->waiters;
bd80c8ba 84
1654b817
CK
85 /* for debugging lockup only, used by sysfs debug files */
86 ring->last_semaphore_wait_addr = semaphore->gpu_addr;
87 return true;
88 }
89 return false;
15d3332f
CK
90}
91
92void radeon_semaphore_free(struct radeon_device *rdev,
220907d9 93 struct radeon_semaphore **semaphore,
a8c05940 94 struct radeon_fence *fence)
15d3332f 95{
220907d9 96 if (semaphore == NULL || *semaphore == NULL) {
a8c05940
JG
97 return;
98 }
220907d9 99 if ((*semaphore)->waiters > 0) {
a8c05940 100 dev_err(rdev->dev, "semaphore %p has more waiters than signalers,"
220907d9 101 " hardware lockup imminent!\n", *semaphore);
15d3332f 102 }
220907d9
CK
103 radeon_sa_bo_free(rdev, &(*semaphore)->sa_bo, fence);
104 kfree(*semaphore);
105 *semaphore = NULL;
15d3332f 106}