2009-06-05 20:42:42 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Jerome Glisse.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Authors:
|
|
|
|
* Jerome Glisse <glisse@freedesktop.org>
|
|
|
|
* Dave Airlie
|
|
|
|
*/
|
|
|
|
#include <linux/seq_file.h>
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2009-06-05 20:42:42 +08:00
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/kref.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-06-05 20:42:42 +08:00
|
|
|
#include "drmP.h"
|
|
|
|
#include "drm.h"
|
|
|
|
#include "radeon_reg.h"
|
|
|
|
#include "radeon.h"
|
2010-11-23 09:47:49 +08:00
|
|
|
#include "radeon_trace.h"
|
2009-06-05 20:42:42 +08:00
|
|
|
|
2011-08-26 01:39:48 +08:00
|
|
|
static void radeon_fence_write(struct radeon_device *rdev, u32 seq, int ring)
|
2011-06-14 05:39:06 +08:00
|
|
|
{
|
|
|
|
if (rdev->wb.enabled) {
|
2011-11-21 04:45:34 +08:00
|
|
|
*rdev->fence_drv[ring].cpu_addr = cpu_to_le32(seq);
|
|
|
|
} else {
|
2011-08-26 01:39:48 +08:00
|
|
|
WREG32(rdev->fence_drv[ring].scratch_reg, seq);
|
2011-11-21 04:45:34 +08:00
|
|
|
}
|
2011-06-14 05:39:06 +08:00
|
|
|
}
|
|
|
|
|
2011-08-26 01:39:48 +08:00
|
|
|
static u32 radeon_fence_read(struct radeon_device *rdev, int ring)
|
2011-06-14 05:39:06 +08:00
|
|
|
{
|
2011-08-26 01:39:48 +08:00
|
|
|
u32 seq = 0;
|
2011-06-14 05:39:06 +08:00
|
|
|
|
|
|
|
if (rdev->wb.enabled) {
|
2011-11-21 04:45:34 +08:00
|
|
|
seq = le32_to_cpu(*rdev->fence_drv[ring].cpu_addr);
|
|
|
|
} else {
|
2011-08-26 01:39:48 +08:00
|
|
|
seq = RREG32(rdev->fence_drv[ring].scratch_reg);
|
2011-11-21 04:45:34 +08:00
|
|
|
}
|
2011-06-14 05:39:06 +08:00
|
|
|
return seq;
|
|
|
|
}
|
|
|
|
|
2009-06-05 20:42:42 +08:00
|
|
|
int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
|
|
|
|
{
|
|
|
|
unsigned long irq_flags;
|
|
|
|
|
2011-08-26 01:39:48 +08:00
|
|
|
write_lock_irqsave(&rdev->fence_lock, irq_flags);
|
2012-05-09 21:34:46 +08:00
|
|
|
if (fence->seq && fence->seq < RADEON_FENCE_NOTEMITED_SEQ) {
|
2011-08-26 01:39:48 +08:00
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
2009-06-05 20:42:42 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2012-05-09 21:34:46 +08:00
|
|
|
/* we are protected by the ring emission mutex */
|
|
|
|
fence->seq = ++rdev->fence_drv[fence->ring].seq;
|
2012-05-02 21:11:10 +08:00
|
|
|
radeon_fence_ring_emit(rdev, fence->ring, fence);
|
2010-11-23 09:47:49 +08:00
|
|
|
trace_radeon_fence_emit(rdev->ddev, fence->seq);
|
2012-05-02 21:11:13 +08:00
|
|
|
/* are we the first fence on a previusly idle ring? */
|
|
|
|
if (list_empty(&rdev->fence_drv[fence->ring].emitted)) {
|
|
|
|
rdev->fence_drv[fence->ring].last_activity = jiffies;
|
|
|
|
}
|
2011-08-26 01:39:48 +08:00
|
|
|
list_move_tail(&fence->list, &rdev->fence_drv[fence->ring].emitted);
|
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
2009-06-05 20:42:42 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-26 01:39:48 +08:00
|
|
|
static bool radeon_fence_poll_locked(struct radeon_device *rdev, int ring)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
|
|
|
struct radeon_fence *fence;
|
|
|
|
struct list_head *i, *n;
|
2012-05-09 21:34:46 +08:00
|
|
|
uint64_t seq, last_seq;
|
|
|
|
unsigned count_loop = 0;
|
2009-06-05 20:42:42 +08:00
|
|
|
bool wake = false;
|
|
|
|
|
2012-05-09 21:34:46 +08:00
|
|
|
/* Note there is a scenario here for an infinite loop but it's
|
|
|
|
* very unlikely to happen. For it to happen, the current polling
|
|
|
|
* process need to be interrupted by another process and another
|
|
|
|
* process needs to update the last_seq btw the atomic read and
|
|
|
|
* xchg of the current process.
|
|
|
|
*
|
|
|
|
* More over for this to go in infinite loop there need to be
|
|
|
|
* continuously new fence signaled ie radeon_fence_read needs
|
|
|
|
* to return a different value each time for both the currently
|
|
|
|
* polling process and the other process that xchg the last_seq
|
|
|
|
* btw atomic read and xchg of the current process. And the
|
|
|
|
* value the other process set as last seq must be higher than
|
|
|
|
* the seq value we just read. Which means that current process
|
|
|
|
* need to be interrupted after radeon_fence_read and before
|
|
|
|
* atomic xchg.
|
|
|
|
*
|
|
|
|
* To be even more safe we count the number of time we loop and
|
|
|
|
* we bail after 10 loop just accepting the fact that we might
|
|
|
|
* have temporarly set the last_seq not to the true real last
|
|
|
|
* seq but to an older one.
|
|
|
|
*/
|
|
|
|
last_seq = atomic64_read(&rdev->fence_drv[ring].last_seq);
|
|
|
|
do {
|
|
|
|
seq = radeon_fence_read(rdev, ring);
|
|
|
|
seq |= last_seq & 0xffffffff00000000LL;
|
|
|
|
if (seq < last_seq) {
|
|
|
|
seq += 0x100000000LL;
|
|
|
|
}
|
2012-05-02 21:11:13 +08:00
|
|
|
|
2012-05-09 21:34:46 +08:00
|
|
|
if (!wake && seq == last_seq) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/* If we loop over we don't want to return without
|
|
|
|
* checking if a fence is signaled as it means that the
|
|
|
|
* seq we just read is different from the previous on.
|
|
|
|
*/
|
|
|
|
wake = true;
|
|
|
|
if ((count_loop++) > 10) {
|
|
|
|
/* We looped over too many time leave with the
|
|
|
|
* fact that we might have set an older fence
|
|
|
|
* seq then the current real last seq as signaled
|
|
|
|
* by the hw.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
last_seq = seq;
|
|
|
|
} while (atomic64_xchg(&rdev->fence_drv[ring].last_seq, seq) > seq);
|
|
|
|
|
|
|
|
/* reset wake to false */
|
|
|
|
wake = false;
|
2012-05-02 21:11:13 +08:00
|
|
|
rdev->fence_drv[ring].last_activity = jiffies;
|
|
|
|
|
2009-06-05 20:42:42 +08:00
|
|
|
n = NULL;
|
2011-08-26 01:39:48 +08:00
|
|
|
list_for_each(i, &rdev->fence_drv[ring].emitted) {
|
2009-06-05 20:42:42 +08:00
|
|
|
fence = list_entry(i, struct radeon_fence, list);
|
|
|
|
if (fence->seq == seq) {
|
|
|
|
n = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* all fence previous to this one are considered as signaled */
|
|
|
|
if (n) {
|
|
|
|
i = n;
|
|
|
|
do {
|
|
|
|
n = i->prev;
|
2011-08-26 01:39:48 +08:00
|
|
|
list_move_tail(i, &rdev->fence_drv[ring].signaled);
|
2009-06-05 20:42:42 +08:00
|
|
|
fence = list_entry(i, struct radeon_fence, list);
|
2012-05-09 21:34:46 +08:00
|
|
|
fence->seq = RADEON_FENCE_SIGNALED_SEQ;
|
2009-06-05 20:42:42 +08:00
|
|
|
i = n;
|
2011-08-26 01:39:48 +08:00
|
|
|
} while (i != &rdev->fence_drv[ring].emitted);
|
2009-06-05 20:42:42 +08:00
|
|
|
wake = true;
|
|
|
|
}
|
|
|
|
return wake;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void radeon_fence_destroy(struct kref *kref)
|
|
|
|
{
|
|
|
|
unsigned long irq_flags;
|
|
|
|
struct radeon_fence *fence;
|
|
|
|
|
|
|
|
fence = container_of(kref, struct radeon_fence, kref);
|
2011-08-26 01:39:48 +08:00
|
|
|
write_lock_irqsave(&fence->rdev->fence_lock, irq_flags);
|
2009-06-05 20:42:42 +08:00
|
|
|
list_del(&fence->list);
|
2012-05-09 21:34:46 +08:00
|
|
|
fence->seq = RADEON_FENCE_NOTEMITED_SEQ;
|
2011-08-26 01:39:48 +08:00
|
|
|
write_unlock_irqrestore(&fence->rdev->fence_lock, irq_flags);
|
2012-01-06 11:11:06 +08:00
|
|
|
if (fence->semaphore)
|
|
|
|
radeon_semaphore_free(fence->rdev, fence->semaphore);
|
2009-06-05 20:42:42 +08:00
|
|
|
kfree(fence);
|
|
|
|
}
|
|
|
|
|
2011-08-26 01:39:48 +08:00
|
|
|
int radeon_fence_create(struct radeon_device *rdev,
|
|
|
|
struct radeon_fence **fence,
|
|
|
|
int ring)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
|
|
|
*fence = kmalloc(sizeof(struct radeon_fence), GFP_KERNEL);
|
|
|
|
if ((*fence) == NULL) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
kref_init(&((*fence)->kref));
|
|
|
|
(*fence)->rdev = rdev;
|
2012-05-09 21:34:46 +08:00
|
|
|
(*fence)->seq = RADEON_FENCE_NOTEMITED_SEQ;
|
2011-08-26 01:39:48 +08:00
|
|
|
(*fence)->ring = ring;
|
2012-01-06 11:11:06 +08:00
|
|
|
(*fence)->semaphore = NULL;
|
2009-06-05 20:42:42 +08:00
|
|
|
INIT_LIST_HEAD(&(*fence)->list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool radeon_fence_signaled(struct radeon_fence *fence)
|
|
|
|
{
|
|
|
|
unsigned long irq_flags;
|
|
|
|
bool signaled = false;
|
|
|
|
|
2009-12-30 09:20:05 +08:00
|
|
|
if (!fence)
|
2009-06-05 20:42:42 +08:00
|
|
|
return true;
|
2009-12-30 09:20:05 +08:00
|
|
|
|
2011-08-26 01:39:48 +08:00
|
|
|
write_lock_irqsave(&fence->rdev->fence_lock, irq_flags);
|
2012-05-09 21:34:46 +08:00
|
|
|
signaled = (fence->seq == RADEON_FENCE_SIGNALED_SEQ);
|
2009-06-05 20:42:42 +08:00
|
|
|
/* if we are shuting down report all fence as signaled */
|
|
|
|
if (fence->rdev->shutdown) {
|
|
|
|
signaled = true;
|
|
|
|
}
|
2012-05-09 21:34:46 +08:00
|
|
|
if (fence->seq == RADEON_FENCE_NOTEMITED_SEQ) {
|
2011-10-24 21:05:29 +08:00
|
|
|
WARN(1, "Querying an unemitted fence : %p !\n", fence);
|
2009-06-05 20:42:42 +08:00
|
|
|
signaled = true;
|
|
|
|
}
|
|
|
|
if (!signaled) {
|
2011-08-26 01:39:48 +08:00
|
|
|
radeon_fence_poll_locked(fence->rdev, fence->ring);
|
2012-05-09 21:34:46 +08:00
|
|
|
signaled = (fence->seq == RADEON_FENCE_SIGNALED_SEQ);
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
2011-08-26 01:39:48 +08:00
|
|
|
write_unlock_irqrestore(&fence->rdev->fence_lock, irq_flags);
|
2009-06-05 20:42:42 +08:00
|
|
|
return signaled;
|
|
|
|
}
|
|
|
|
|
2009-09-08 08:10:24 +08:00
|
|
|
int radeon_fence_wait(struct radeon_fence *fence, bool intr)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
|
|
|
struct radeon_device *rdev;
|
2012-05-09 21:34:46 +08:00
|
|
|
unsigned long irq_flags, timeout, last_activity;
|
|
|
|
uint64_t seq;
|
2012-05-02 21:11:13 +08:00
|
|
|
int i, r;
|
|
|
|
bool signaled;
|
2009-06-05 20:42:42 +08:00
|
|
|
|
|
|
|
if (fence == NULL) {
|
|
|
|
WARN(1, "Querying an invalid fence : %p !\n", fence);
|
2012-05-02 21:11:13 +08:00
|
|
|
return -EINVAL;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
2012-05-02 21:11:13 +08:00
|
|
|
|
2009-06-05 20:42:42 +08:00
|
|
|
rdev = fence->rdev;
|
2012-05-02 21:11:13 +08:00
|
|
|
signaled = radeon_fence_signaled(fence);
|
|
|
|
while (!signaled) {
|
|
|
|
read_lock_irqsave(&rdev->fence_lock, irq_flags);
|
|
|
|
timeout = jiffies - RADEON_FENCE_JIFFIES_TIMEOUT;
|
|
|
|
if (time_after(rdev->fence_drv[fence->ring].last_activity, timeout)) {
|
|
|
|
/* the normal case, timeout is somewhere before last_activity */
|
|
|
|
timeout = rdev->fence_drv[fence->ring].last_activity - timeout;
|
|
|
|
} else {
|
|
|
|
/* either jiffies wrapped around, or no fence was signaled in the last 500ms
|
|
|
|
* anyway we will just wait for the minimum amount and then check for a lockup */
|
|
|
|
timeout = 1;
|
|
|
|
}
|
|
|
|
/* save current sequence value used to check for GPU lockups */
|
2012-05-09 21:34:46 +08:00
|
|
|
seq = atomic64_read(&rdev->fence_drv[fence->ring].last_seq);
|
|
|
|
/* Save current last activity valuee, used to check for GPU lockups */
|
|
|
|
last_activity = rdev->fence_drv[fence->ring].last_activity;
|
2012-05-02 21:11:13 +08:00
|
|
|
read_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
|
|
|
|
|
|
|
trace_radeon_fence_wait_begin(rdev->ddev, seq);
|
2011-11-18 09:13:28 +08:00
|
|
|
radeon_irq_kms_sw_irq_get(rdev, fence->ring);
|
2012-05-02 21:11:13 +08:00
|
|
|
if (intr) {
|
|
|
|
r = wait_event_interruptible_timeout(
|
|
|
|
rdev->fence_drv[fence->ring].queue,
|
|
|
|
(signaled = radeon_fence_signaled(fence)), timeout);
|
|
|
|
} else {
|
|
|
|
r = wait_event_timeout(
|
|
|
|
rdev->fence_drv[fence->ring].queue,
|
|
|
|
(signaled = radeon_fence_signaled(fence)), timeout);
|
|
|
|
}
|
2011-11-18 09:13:28 +08:00
|
|
|
radeon_irq_kms_sw_irq_put(rdev, fence->ring);
|
2010-03-09 22:45:12 +08:00
|
|
|
if (unlikely(r < 0)) {
|
2009-12-08 01:36:19 +08:00
|
|
|
return r;
|
2010-03-09 22:45:12 +08:00
|
|
|
}
|
2012-05-02 21:11:13 +08:00
|
|
|
trace_radeon_fence_wait_end(rdev->ddev, seq);
|
2012-05-02 21:11:10 +08:00
|
|
|
|
2012-05-02 21:11:13 +08:00
|
|
|
if (unlikely(!signaled)) {
|
|
|
|
/* we were interrupted for some reason and fence
|
|
|
|
* isn't signaled yet, resume waiting */
|
|
|
|
if (r) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-05-02 21:11:10 +08:00
|
|
|
|
2012-05-02 21:11:13 +08:00
|
|
|
write_lock_irqsave(&rdev->fence_lock, irq_flags);
|
2012-05-09 21:34:46 +08:00
|
|
|
/* test if somebody else has already decided that this is a lockup */
|
|
|
|
if (last_activity != rdev->fence_drv[fence->ring].last_activity) {
|
2012-05-02 21:11:13 +08:00
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
|
|
|
|
|
|
|
if (radeon_ring_is_lockup(rdev, fence->ring, &rdev->ring[fence->ring])) {
|
|
|
|
/* good news we believe it's a lockup */
|
2012-05-09 21:34:46 +08:00
|
|
|
dev_warn(rdev->dev, "GPU lockup (waiting for 0x%016llx last fence id 0x%016llx)\n",
|
|
|
|
fence->seq, seq);
|
|
|
|
|
|
|
|
/* change last activity so nobody else think there is a lockup */
|
|
|
|
for (i = 0; i < RADEON_NUM_RINGS; ++i) {
|
|
|
|
rdev->fence_drv[i].last_activity = jiffies;
|
|
|
|
}
|
2012-05-02 21:11:13 +08:00
|
|
|
|
|
|
|
/* mark the ring as not ready any more */
|
|
|
|
rdev->ring[fence->ring].ready = false;
|
2012-05-02 21:11:19 +08:00
|
|
|
return -EDEADLK;
|
2012-05-02 21:11:13 +08:00
|
|
|
}
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-26 01:39:48 +08:00
|
|
|
int radeon_fence_wait_next(struct radeon_device *rdev, int ring)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
|
|
|
unsigned long irq_flags;
|
|
|
|
struct radeon_fence *fence;
|
|
|
|
int r;
|
|
|
|
|
2011-08-26 01:39:48 +08:00
|
|
|
write_lock_irqsave(&rdev->fence_lock, irq_flags);
|
2012-05-02 21:11:10 +08:00
|
|
|
if (!rdev->ring[ring].ready) {
|
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
2011-08-26 01:39:48 +08:00
|
|
|
if (list_empty(&rdev->fence_drv[ring].emitted)) {
|
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
2012-05-02 21:11:15 +08:00
|
|
|
return -ENOENT;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
2011-08-26 01:39:48 +08:00
|
|
|
fence = list_entry(rdev->fence_drv[ring].emitted.next,
|
2009-06-05 20:42:42 +08:00
|
|
|
struct radeon_fence, list);
|
|
|
|
radeon_fence_ref(fence);
|
2011-08-26 01:39:48 +08:00
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
2009-06-05 20:42:42 +08:00
|
|
|
r = radeon_fence_wait(fence, false);
|
|
|
|
radeon_fence_unref(&fence);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-05-02 21:11:16 +08:00
|
|
|
int radeon_fence_wait_empty(struct radeon_device *rdev, int ring)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
|
|
|
unsigned long irq_flags;
|
|
|
|
struct radeon_fence *fence;
|
|
|
|
int r;
|
|
|
|
|
2011-08-26 01:39:48 +08:00
|
|
|
write_lock_irqsave(&rdev->fence_lock, irq_flags);
|
2012-05-02 21:11:10 +08:00
|
|
|
if (!rdev->ring[ring].ready) {
|
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
2011-08-26 01:39:48 +08:00
|
|
|
if (list_empty(&rdev->fence_drv[ring].emitted)) {
|
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
2009-06-05 20:42:42 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2011-08-26 01:39:48 +08:00
|
|
|
fence = list_entry(rdev->fence_drv[ring].emitted.prev,
|
2009-06-05 20:42:42 +08:00
|
|
|
struct radeon_fence, list);
|
|
|
|
radeon_fence_ref(fence);
|
2011-08-26 01:39:48 +08:00
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
2009-06-05 20:42:42 +08:00
|
|
|
r = radeon_fence_wait(fence, false);
|
|
|
|
radeon_fence_unref(&fence);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence)
|
|
|
|
{
|
|
|
|
kref_get(&fence->kref);
|
|
|
|
return fence;
|
|
|
|
}
|
|
|
|
|
|
|
|
void radeon_fence_unref(struct radeon_fence **fence)
|
|
|
|
{
|
|
|
|
struct radeon_fence *tmp = *fence;
|
|
|
|
|
|
|
|
*fence = NULL;
|
|
|
|
if (tmp) {
|
2011-02-27 08:34:08 +08:00
|
|
|
kref_put(&tmp->kref, radeon_fence_destroy);
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-26 01:39:48 +08:00
|
|
|
void radeon_fence_process(struct radeon_device *rdev, int ring)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
|
|
|
unsigned long irq_flags;
|
|
|
|
bool wake;
|
|
|
|
|
2011-08-26 01:39:48 +08:00
|
|
|
write_lock_irqsave(&rdev->fence_lock, irq_flags);
|
|
|
|
wake = radeon_fence_poll_locked(rdev, ring);
|
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
2009-06-05 20:42:42 +08:00
|
|
|
if (wake) {
|
2011-08-26 01:39:48 +08:00
|
|
|
wake_up_all(&rdev->fence_drv[ring].queue);
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-20 18:38:09 +08:00
|
|
|
int radeon_fence_count_emitted(struct radeon_device *rdev, int ring)
|
|
|
|
{
|
|
|
|
unsigned long irq_flags;
|
|
|
|
int not_processed = 0;
|
|
|
|
|
|
|
|
read_lock_irqsave(&rdev->fence_lock, irq_flags);
|
2012-02-13 20:18:37 +08:00
|
|
|
if (!rdev->fence_drv[ring].initialized) {
|
|
|
|
read_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
2011-10-20 18:38:09 +08:00
|
|
|
return 0;
|
2012-02-13 20:18:37 +08:00
|
|
|
}
|
2011-10-20 18:38:09 +08:00
|
|
|
|
|
|
|
if (!list_empty(&rdev->fence_drv[ring].emitted)) {
|
|
|
|
struct list_head *ptr;
|
|
|
|
list_for_each(ptr, &rdev->fence_drv[ring].emitted) {
|
|
|
|
/* count up to 3, that's enought info */
|
|
|
|
if (++not_processed >= 3)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
read_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
|
|
|
return not_processed;
|
|
|
|
}
|
|
|
|
|
2011-11-21 04:45:34 +08:00
|
|
|
int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
|
|
|
unsigned long irq_flags;
|
2011-11-21 04:45:34 +08:00
|
|
|
uint64_t index;
|
|
|
|
int r;
|
2009-06-05 20:42:42 +08:00
|
|
|
|
2011-11-21 04:45:34 +08:00
|
|
|
write_lock_irqsave(&rdev->fence_lock, irq_flags);
|
|
|
|
radeon_scratch_free(rdev, rdev->fence_drv[ring].scratch_reg);
|
|
|
|
if (rdev->wb.use_event) {
|
|
|
|
rdev->fence_drv[ring].scratch_reg = 0;
|
|
|
|
index = R600_WB_EVENT_OFFSET + ring * 4;
|
|
|
|
} else {
|
2011-08-26 01:39:48 +08:00
|
|
|
r = radeon_scratch_get(rdev, &rdev->fence_drv[ring].scratch_reg);
|
|
|
|
if (r) {
|
|
|
|
dev_err(rdev->dev, "fence failed to get scratch register\n");
|
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
|
|
|
return r;
|
|
|
|
}
|
2011-11-21 04:45:34 +08:00
|
|
|
index = RADEON_WB_SCRATCH_OFFSET +
|
|
|
|
rdev->fence_drv[ring].scratch_reg -
|
|
|
|
rdev->scratch.reg_base;
|
2011-08-26 01:39:48 +08:00
|
|
|
}
|
2011-11-21 04:45:34 +08:00
|
|
|
rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
|
|
|
|
rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
|
2012-05-09 21:34:46 +08:00
|
|
|
radeon_fence_write(rdev, rdev->fence_drv[ring].seq, ring);
|
2011-11-21 04:45:34 +08:00
|
|
|
rdev->fence_drv[ring].initialized = true;
|
2012-05-09 21:34:46 +08:00
|
|
|
DRM_INFO("fence driver on ring %d use gpu addr 0x%016llx and cpu addr 0x%p\n",
|
2011-11-21 04:45:34 +08:00
|
|
|
ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
|
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
|
|
|
|
{
|
|
|
|
rdev->fence_drv[ring].scratch_reg = -1;
|
|
|
|
rdev->fence_drv[ring].cpu_addr = NULL;
|
|
|
|
rdev->fence_drv[ring].gpu_addr = 0;
|
2012-05-09 21:34:46 +08:00
|
|
|
rdev->fence_drv[ring].seq = 0;
|
|
|
|
atomic64_set(&rdev->fence_drv[ring].last_seq, 0);
|
2011-11-21 04:45:34 +08:00
|
|
|
INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
|
|
|
|
INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
|
|
|
|
init_waitqueue_head(&rdev->fence_drv[ring].queue);
|
|
|
|
rdev->fence_drv[ring].initialized = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int radeon_fence_driver_init(struct radeon_device *rdev)
|
|
|
|
{
|
|
|
|
unsigned long irq_flags;
|
|
|
|
int ring;
|
|
|
|
|
|
|
|
write_lock_irqsave(&rdev->fence_lock, irq_flags);
|
|
|
|
for (ring = 0; ring < RADEON_NUM_RINGS; ring++) {
|
|
|
|
radeon_fence_driver_init_ring(rdev, ring);
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
2011-11-21 04:45:34 +08:00
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
2009-06-05 20:42:42 +08:00
|
|
|
if (radeon_debugfs_fence_init(rdev)) {
|
2009-12-12 03:36:19 +08:00
|
|
|
dev_err(rdev->dev, "fence debugfs file creation failed\n");
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void radeon_fence_driver_fini(struct radeon_device *rdev)
|
|
|
|
{
|
|
|
|
unsigned long irq_flags;
|
2011-08-26 01:39:48 +08:00
|
|
|
int ring;
|
|
|
|
|
|
|
|
for (ring = 0; ring < RADEON_NUM_RINGS; ring++) {
|
|
|
|
if (!rdev->fence_drv[ring].initialized)
|
|
|
|
continue;
|
2012-05-02 21:11:16 +08:00
|
|
|
radeon_fence_wait_empty(rdev, ring);
|
2011-08-26 01:39:48 +08:00
|
|
|
wake_up_all(&rdev->fence_drv[ring].queue);
|
|
|
|
write_lock_irqsave(&rdev->fence_lock, irq_flags);
|
|
|
|
radeon_scratch_free(rdev, rdev->fence_drv[ring].scratch_reg);
|
|
|
|
write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
|
|
|
|
rdev->fence_drv[ring].initialized = false;
|
|
|
|
}
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fence debugfs
|
|
|
|
*/
|
|
|
|
#if defined(CONFIG_DEBUG_FS)
|
|
|
|
static int radeon_debugfs_fence_info(struct seq_file *m, void *data)
|
|
|
|
{
|
|
|
|
struct drm_info_node *node = (struct drm_info_node *)m->private;
|
|
|
|
struct drm_device *dev = node->minor->dev;
|
|
|
|
struct radeon_device *rdev = dev->dev_private;
|
|
|
|
struct radeon_fence *fence;
|
2011-08-26 01:39:48 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < RADEON_NUM_RINGS; ++i) {
|
|
|
|
if (!rdev->fence_drv[i].initialized)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
seq_printf(m, "--- ring %d ---\n", i);
|
2012-05-09 21:34:46 +08:00
|
|
|
seq_printf(m, "Last signaled fence 0x%016lx\n",
|
|
|
|
atomic64_read(&rdev->fence_drv[i].last_seq));
|
2011-08-26 01:39:48 +08:00
|
|
|
if (!list_empty(&rdev->fence_drv[i].emitted)) {
|
|
|
|
fence = list_entry(rdev->fence_drv[i].emitted.prev,
|
|
|
|
struct radeon_fence, list);
|
2012-05-09 21:34:46 +08:00
|
|
|
seq_printf(m, "Last emitted fence %p with 0x%016llx\n",
|
2011-08-26 01:39:48 +08:00
|
|
|
fence, fence->seq);
|
|
|
|
}
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct drm_info_list radeon_debugfs_fence_list[] = {
|
|
|
|
{"radeon_fence_info", &radeon_debugfs_fence_info, 0, NULL},
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int radeon_debugfs_fence_init(struct radeon_device *rdev)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_DEBUG_FS)
|
|
|
|
return radeon_debugfs_add_files(rdev, radeon_debugfs_fence_list, 1);
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|