1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2011 Christian König.
3*4882a593Smuzhiyun * All Rights Reserved.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
6*4882a593Smuzhiyun * copy of this software and associated documentation files (the
7*4882a593Smuzhiyun * "Software"), to deal in the Software without restriction, including
8*4882a593Smuzhiyun * without limitation the rights to use, copy, modify, merge, publish,
9*4882a593Smuzhiyun * distribute, sub license, and/or sell copies of the Software, and to
10*4882a593Smuzhiyun * permit persons to whom the Software is furnished to do so, subject to
11*4882a593Smuzhiyun * the following conditions:
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
16*4882a593Smuzhiyun * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
17*4882a593Smuzhiyun * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18*4882a593Smuzhiyun * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19*4882a593Smuzhiyun * USE OR OTHER DEALINGS IN THE SOFTWARE.
20*4882a593Smuzhiyun *
21*4882a593Smuzhiyun * The above copyright notice and this permission notice (including the
22*4882a593Smuzhiyun * next paragraph) shall be included in all copies or substantial portions
23*4882a593Smuzhiyun * of the Software.
24*4882a593Smuzhiyun *
25*4882a593Smuzhiyun */
26*4882a593Smuzhiyun /*
27*4882a593Smuzhiyun * Authors:
28*4882a593Smuzhiyun * Christian König <deathsimple@vodafone.de>
29*4882a593Smuzhiyun */
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #include "radeon.h"
32*4882a593Smuzhiyun #include "radeon_trace.h"
33*4882a593Smuzhiyun
radeon_semaphore_create(struct radeon_device * rdev,struct radeon_semaphore ** semaphore)34*4882a593Smuzhiyun int radeon_semaphore_create(struct radeon_device *rdev,
35*4882a593Smuzhiyun struct radeon_semaphore **semaphore)
36*4882a593Smuzhiyun {
37*4882a593Smuzhiyun int r;
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun *semaphore = kmalloc(sizeof(struct radeon_semaphore), GFP_KERNEL);
40*4882a593Smuzhiyun if (*semaphore == NULL) {
41*4882a593Smuzhiyun return -ENOMEM;
42*4882a593Smuzhiyun }
43*4882a593Smuzhiyun r = radeon_sa_bo_new(rdev, &rdev->ring_tmp_bo,
44*4882a593Smuzhiyun &(*semaphore)->sa_bo, 8, 8);
45*4882a593Smuzhiyun if (r) {
46*4882a593Smuzhiyun kfree(*semaphore);
47*4882a593Smuzhiyun *semaphore = NULL;
48*4882a593Smuzhiyun return r;
49*4882a593Smuzhiyun }
50*4882a593Smuzhiyun (*semaphore)->waiters = 0;
51*4882a593Smuzhiyun (*semaphore)->gpu_addr = radeon_sa_bo_gpu_addr((*semaphore)->sa_bo);
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun *((uint64_t *)radeon_sa_bo_cpu_addr((*semaphore)->sa_bo)) = 0;
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun return 0;
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun
radeon_semaphore_emit_signal(struct radeon_device * rdev,int ridx,struct radeon_semaphore * semaphore)58*4882a593Smuzhiyun bool radeon_semaphore_emit_signal(struct radeon_device *rdev, int ridx,
59*4882a593Smuzhiyun struct radeon_semaphore *semaphore)
60*4882a593Smuzhiyun {
61*4882a593Smuzhiyun struct radeon_ring *ring = &rdev->ring[ridx];
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun trace_radeon_semaphore_signale(ridx, semaphore);
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun if (radeon_semaphore_ring_emit(rdev, ridx, ring, semaphore, false)) {
66*4882a593Smuzhiyun --semaphore->waiters;
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun /* for debugging lockup only, used by sysfs debug files */
69*4882a593Smuzhiyun ring->last_semaphore_signal_addr = semaphore->gpu_addr;
70*4882a593Smuzhiyun return true;
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun return false;
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun
radeon_semaphore_emit_wait(struct radeon_device * rdev,int ridx,struct radeon_semaphore * semaphore)75*4882a593Smuzhiyun bool radeon_semaphore_emit_wait(struct radeon_device *rdev, int ridx,
76*4882a593Smuzhiyun struct radeon_semaphore *semaphore)
77*4882a593Smuzhiyun {
78*4882a593Smuzhiyun struct radeon_ring *ring = &rdev->ring[ridx];
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun trace_radeon_semaphore_wait(ridx, semaphore);
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun if (radeon_semaphore_ring_emit(rdev, ridx, ring, semaphore, true)) {
83*4882a593Smuzhiyun ++semaphore->waiters;
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun /* for debugging lockup only, used by sysfs debug files */
86*4882a593Smuzhiyun ring->last_semaphore_wait_addr = semaphore->gpu_addr;
87*4882a593Smuzhiyun return true;
88*4882a593Smuzhiyun }
89*4882a593Smuzhiyun return false;
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun
radeon_semaphore_free(struct radeon_device * rdev,struct radeon_semaphore ** semaphore,struct radeon_fence * fence)92*4882a593Smuzhiyun void radeon_semaphore_free(struct radeon_device *rdev,
93*4882a593Smuzhiyun struct radeon_semaphore **semaphore,
94*4882a593Smuzhiyun struct radeon_fence *fence)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun if (semaphore == NULL || *semaphore == NULL) {
97*4882a593Smuzhiyun return;
98*4882a593Smuzhiyun }
99*4882a593Smuzhiyun if ((*semaphore)->waiters > 0) {
100*4882a593Smuzhiyun dev_err(rdev->dev, "semaphore %p has more waiters than signalers,"
101*4882a593Smuzhiyun " hardware lockup imminent!\n", *semaphore);
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun radeon_sa_bo_free(rdev, &(*semaphore)->sa_bo, fence);
104*4882a593Smuzhiyun kfree(*semaphore);
105*4882a593Smuzhiyun *semaphore = NULL;
106*4882a593Smuzhiyun }
107