2009-12-11 09:24:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Ben Skeggs.
|
|
|
|
* 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, sublicense, 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 above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* 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 NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-10-02 17:01:07 +00:00
|
|
|
#include <drm/drmP.h>
|
2009-12-11 09:24:15 +00:00
|
|
|
|
2011-03-09 13:22:19 +00:00
|
|
|
#include <linux/ktime.h>
|
|
|
|
#include <linux/hrtimer.h>
|
2014-01-09 10:03:11 +00:00
|
|
|
#include <trace/events/fence.h>
|
2011-03-09 13:22:19 +00:00
|
|
|
|
2014-08-09 18:10:25 +00:00
|
|
|
#include <nvif/notify.h>
|
|
|
|
#include <nvif/event.h>
|
|
|
|
|
2012-07-19 22:17:34 +00:00
|
|
|
#include "nouveau_drm.h"
|
2009-12-11 09:24:15 +00:00
|
|
|
#include "nouveau_dma.h"
|
2012-07-19 22:17:34 +00:00
|
|
|
#include "nouveau_fence.h"
|
2009-12-11 09:24:15 +00:00
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
static const struct fence_ops nouveau_fence_ops_uevent;
|
|
|
|
static const struct fence_ops nouveau_fence_ops_legacy;
|
|
|
|
|
|
|
|
static inline struct nouveau_fence *
|
|
|
|
from_fence(struct fence *fence)
|
|
|
|
{
|
|
|
|
return container_of(fence, struct nouveau_fence, base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct nouveau_fence_chan *
|
|
|
|
nouveau_fctx(struct nouveau_fence *fence)
|
|
|
|
{
|
|
|
|
return container_of(fence->base.lock, struct nouveau_fence_chan, lock);
|
|
|
|
}
|
2013-05-06 23:48:30 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
nouveau_fence_signal(struct nouveau_fence *fence)
|
|
|
|
{
|
2014-01-09 10:03:11 +00:00
|
|
|
fence_signal_locked(&fence->base);
|
|
|
|
list_del(&fence->head);
|
|
|
|
|
|
|
|
if (test_bit(FENCE_FLAG_USER_BITS, &fence->base.flags)) {
|
|
|
|
struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
|
2013-05-06 23:48:30 +00:00
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
if (!--fctx->notify_ref)
|
|
|
|
nvif_notify_put(&fctx->notify);
|
2013-05-06 23:48:30 +00:00
|
|
|
}
|
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
fence_put(&fence->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct nouveau_fence *
|
|
|
|
nouveau_local_fence(struct fence *fence, struct nouveau_drm *drm) {
|
|
|
|
struct nouveau_fence_priv *priv = (void*)drm->fence;
|
|
|
|
|
|
|
|
if (fence->ops != &nouveau_fence_ops_legacy &&
|
|
|
|
fence->ops != &nouveau_fence_ops_uevent)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (fence->context < priv->context_base ||
|
|
|
|
fence->context >= priv->context_base + priv->contexts)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return from_fence(fence);
|
2013-05-06 23:48:30 +00:00
|
|
|
}
|
|
|
|
|
2012-04-30 03:55:29 +00:00
|
|
|
void
|
|
|
|
nouveau_fence_context_del(struct nouveau_fence_chan *fctx)
|
|
|
|
{
|
2014-01-09 10:03:11 +00:00
|
|
|
struct nouveau_fence *fence;
|
|
|
|
|
|
|
|
nvif_notify_fini(&fctx->notify);
|
|
|
|
|
|
|
|
spin_lock_irq(&fctx->lock);
|
|
|
|
while (!list_empty(&fctx->pending)) {
|
|
|
|
fence = list_entry(fctx->pending.next, typeof(*fence), head);
|
|
|
|
|
2013-05-06 23:48:30 +00:00
|
|
|
nouveau_fence_signal(fence);
|
2014-01-09 10:03:11 +00:00
|
|
|
fence->channel = NULL;
|
2012-04-30 03:55:29 +00:00
|
|
|
}
|
2014-01-09 10:03:11 +00:00
|
|
|
spin_unlock_irq(&fctx->lock);
|
|
|
|
}
|
|
|
|
|
2014-09-29 08:06:18 +00:00
|
|
|
static void
|
|
|
|
nouveau_fence_context_put(struct kref *fence_ref)
|
|
|
|
{
|
|
|
|
kfree(container_of(fence_ref, struct nouveau_fence_chan, fence_ref));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nouveau_fence_context_free(struct nouveau_fence_chan *fctx)
|
|
|
|
{
|
|
|
|
kref_put(&fctx->fence_ref, nouveau_fence_context_put);
|
|
|
|
}
|
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
static void
|
|
|
|
nouveau_fence_update(struct nouveau_channel *chan, struct nouveau_fence_chan *fctx)
|
|
|
|
{
|
|
|
|
struct nouveau_fence *fence;
|
|
|
|
|
|
|
|
u32 seq = fctx->read(chan);
|
|
|
|
|
|
|
|
while (!list_empty(&fctx->pending)) {
|
|
|
|
fence = list_entry(fctx->pending.next, typeof(*fence), head);
|
|
|
|
|
|
|
|
if ((int)(seq - fence->base.seqno) < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nouveau_fence_signal(fence);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nouveau_fence_wait_uevent_handler(struct nvif_notify *notify)
|
|
|
|
{
|
|
|
|
struct nouveau_fence_chan *fctx =
|
|
|
|
container_of(notify, typeof(*fctx), notify);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&fctx->lock, flags);
|
|
|
|
if (!list_empty(&fctx->pending)) {
|
|
|
|
struct nouveau_fence *fence;
|
|
|
|
|
|
|
|
fence = list_entry(fctx->pending.next, typeof(*fence), head);
|
|
|
|
nouveau_fence_update(fence->channel, fctx);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&fctx->lock, flags);
|
|
|
|
|
|
|
|
/* Always return keep here. NVIF refcount is handled with nouveau_fence_update */
|
|
|
|
return NVIF_NOTIFY_KEEP;
|
2012-04-30 03:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-09 10:03:11 +00:00
|
|
|
nouveau_fence_context_new(struct nouveau_channel *chan, struct nouveau_fence_chan *fctx)
|
2012-04-30 03:55:29 +00:00
|
|
|
{
|
2014-01-09 10:03:11 +00:00
|
|
|
struct nouveau_fence_priv *priv = (void*)chan->drm->fence;
|
2014-09-29 08:06:18 +00:00
|
|
|
struct nouveau_cli *cli = (void *)nvif_client(chan->object);
|
2014-01-09 10:03:11 +00:00
|
|
|
int ret;
|
|
|
|
|
2012-07-22 01:55:54 +00:00
|
|
|
INIT_LIST_HEAD(&fctx->flip);
|
2012-04-30 03:55:29 +00:00
|
|
|
INIT_LIST_HEAD(&fctx->pending);
|
|
|
|
spin_lock_init(&fctx->lock);
|
2014-01-09 10:03:11 +00:00
|
|
|
fctx->context = priv->context_base + chan->chid;
|
|
|
|
|
2014-09-29 08:06:18 +00:00
|
|
|
if (chan == chan->drm->cechan)
|
|
|
|
strcpy(fctx->name, "copy engine channel");
|
|
|
|
else if (chan == chan->drm->channel)
|
|
|
|
strcpy(fctx->name, "generic kernel channel");
|
|
|
|
else
|
|
|
|
strcpy(fctx->name, nvkm_client(&cli->base)->name);
|
|
|
|
|
|
|
|
kref_init(&fctx->fence_ref);
|
2014-01-09 10:03:11 +00:00
|
|
|
if (!priv->uevent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ret = nvif_notify_init(chan->object, NULL,
|
|
|
|
nouveau_fence_wait_uevent_handler, false,
|
|
|
|
G82_CHANNEL_DMA_V0_NTFY_UEVENT,
|
|
|
|
&(struct nvif_notify_uevent_req) { },
|
|
|
|
sizeof(struct nvif_notify_uevent_req),
|
|
|
|
sizeof(struct nvif_notify_uevent_rep),
|
|
|
|
&fctx->notify);
|
|
|
|
|
|
|
|
WARN_ON(ret);
|
2012-04-30 03:55:29 +00:00
|
|
|
}
|
2009-12-11 09:24:15 +00:00
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
struct nouveau_fence_work {
|
|
|
|
struct work_struct work;
|
|
|
|
struct fence_cb cb;
|
|
|
|
void (*func)(void *);
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
2013-05-06 23:48:30 +00:00
|
|
|
static void
|
|
|
|
nouveau_fence_work_handler(struct work_struct *kwork)
|
|
|
|
{
|
2014-01-09 10:03:11 +00:00
|
|
|
struct nouveau_fence_work *work = container_of(kwork, typeof(*work), work);
|
2013-05-06 23:48:30 +00:00
|
|
|
work->func(work->data);
|
|
|
|
kfree(work);
|
|
|
|
}
|
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
static void nouveau_fence_work_cb(struct fence *fence, struct fence_cb *cb)
|
|
|
|
{
|
|
|
|
struct nouveau_fence_work *work = container_of(cb, typeof(*work), cb);
|
|
|
|
|
|
|
|
schedule_work(&work->work);
|
|
|
|
}
|
|
|
|
|
2013-05-06 23:48:30 +00:00
|
|
|
void
|
2014-04-02 15:14:48 +00:00
|
|
|
nouveau_fence_work(struct fence *fence,
|
2013-05-06 23:48:30 +00:00
|
|
|
void (*func)(void *), void *data)
|
|
|
|
{
|
2014-01-09 10:03:11 +00:00
|
|
|
struct nouveau_fence_work *work;
|
2013-05-06 23:48:30 +00:00
|
|
|
|
2014-04-02 15:14:48 +00:00
|
|
|
if (fence_is_signaled(fence))
|
2014-01-09 10:03:11 +00:00
|
|
|
goto err;
|
2013-05-06 23:48:30 +00:00
|
|
|
|
|
|
|
work = kmalloc(sizeof(*work), GFP_KERNEL);
|
|
|
|
if (!work) {
|
2014-01-09 10:03:15 +00:00
|
|
|
/*
|
|
|
|
* this might not be a nouveau fence any more,
|
|
|
|
* so force a lazy wait here
|
|
|
|
*/
|
2014-04-02 15:14:48 +00:00
|
|
|
WARN_ON(nouveau_fence_wait((struct nouveau_fence *)fence,
|
2014-01-09 10:03:15 +00:00
|
|
|
true, false));
|
2014-01-09 10:03:11 +00:00
|
|
|
goto err;
|
2013-05-06 23:48:30 +00:00
|
|
|
}
|
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
INIT_WORK(&work->work, nouveau_fence_work_handler);
|
2013-05-06 23:48:30 +00:00
|
|
|
work->func = func;
|
|
|
|
work->data = data;
|
2009-12-11 09:24:15 +00:00
|
|
|
|
2014-04-02 15:14:48 +00:00
|
|
|
if (fence_add_callback(fence, &work->cb, nouveau_fence_work_cb) < 0)
|
2014-01-09 10:03:11 +00:00
|
|
|
goto err_free;
|
|
|
|
return;
|
2012-03-21 03:51:03 +00:00
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
err_free:
|
|
|
|
kfree(work);
|
|
|
|
err:
|
|
|
|
func(data);
|
2009-12-11 09:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-04-30 03:30:00 +00:00
|
|
|
nouveau_fence_emit(struct nouveau_fence *fence, struct nouveau_channel *chan)
|
2009-12-11 09:24:15 +00:00
|
|
|
{
|
2012-07-19 00:51:42 +00:00
|
|
|
struct nouveau_fence_chan *fctx = chan->fence;
|
2014-01-09 10:03:11 +00:00
|
|
|
struct nouveau_fence_priv *priv = (void*)chan->drm->fence;
|
2009-12-11 09:24:15 +00:00
|
|
|
int ret;
|
|
|
|
|
2012-04-30 03:55:29 +00:00
|
|
|
fence->channel = chan;
|
2013-12-11 10:34:41 +00:00
|
|
|
fence->timeout = jiffies + (15 * HZ);
|
2009-12-11 09:24:15 +00:00
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
if (priv->uevent)
|
|
|
|
fence_init(&fence->base, &nouveau_fence_ops_uevent,
|
2014-09-16 09:15:07 +00:00
|
|
|
&fctx->lock, fctx->context, ++fctx->sequence);
|
2014-01-09 10:03:11 +00:00
|
|
|
else
|
|
|
|
fence_init(&fence->base, &nouveau_fence_ops_legacy,
|
2014-09-16 09:15:07 +00:00
|
|
|
&fctx->lock, fctx->context, ++fctx->sequence);
|
2014-09-29 08:06:18 +00:00
|
|
|
kref_get(&fctx->fence_ref);
|
2014-01-09 10:03:11 +00:00
|
|
|
|
|
|
|
trace_fence_emit(&fence->base);
|
2013-02-14 03:20:17 +00:00
|
|
|
ret = fctx->emit(fence);
|
2012-04-30 03:55:29 +00:00
|
|
|
if (!ret) {
|
2014-01-09 10:03:11 +00:00
|
|
|
fence_get(&fence->base);
|
|
|
|
spin_lock_irq(&fctx->lock);
|
|
|
|
nouveau_fence_update(chan, fctx);
|
2012-04-30 03:55:29 +00:00
|
|
|
list_add_tail(&fence->head, &fctx->pending);
|
2014-01-09 10:03:11 +00:00
|
|
|
spin_unlock_irq(&fctx->lock);
|
2010-11-24 00:30:22 +00:00
|
|
|
}
|
2009-12-11 09:24:15 +00:00
|
|
|
|
2012-04-30 03:55:29 +00:00
|
|
|
return ret;
|
2009-12-11 09:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-04-30 03:30:00 +00:00
|
|
|
nouveau_fence_done(struct nouveau_fence *fence)
|
2009-12-11 09:24:15 +00:00
|
|
|
{
|
2014-01-09 10:03:11 +00:00
|
|
|
if (fence->base.ops == &nouveau_fence_ops_legacy ||
|
|
|
|
fence->base.ops == &nouveau_fence_ops_uevent) {
|
|
|
|
struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
|
|
|
|
unsigned long flags;
|
2009-12-11 09:24:15 +00:00
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->base.flags))
|
|
|
|
return true;
|
2014-08-09 18:10:20 +00:00
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
spin_lock_irqsave(&fctx->lock, flags);
|
|
|
|
nouveau_fence_update(fence->channel, fctx);
|
|
|
|
spin_unlock_irqrestore(&fctx->lock, flags);
|
|
|
|
}
|
|
|
|
return fence_is_signaled(&fence->base);
|
2013-01-31 04:57:33 +00:00
|
|
|
}
|
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
static long
|
|
|
|
nouveau_fence_wait_legacy(struct fence *f, bool intr, long wait)
|
2013-01-31 04:57:33 +00:00
|
|
|
{
|
2014-01-09 10:03:11 +00:00
|
|
|
struct nouveau_fence *fence = from_fence(f);
|
|
|
|
unsigned long sleep_time = NSEC_PER_MSEC / 1000;
|
|
|
|
unsigned long t = jiffies, timeout = t + wait;
|
2013-01-31 04:57:33 +00:00
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
while (!nouveau_fence_done(fence)) {
|
|
|
|
ktime_t kt;
|
2013-10-02 21:02:29 +00:00
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
t = jiffies;
|
2013-01-31 04:57:33 +00:00
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
if (wait != MAX_SCHEDULE_TIMEOUT && time_after_eq(t, timeout)) {
|
|
|
|
__set_current_state(TASK_RUNNING);
|
|
|
|
return 0;
|
2013-01-31 04:57:33 +00:00
|
|
|
}
|
2014-01-09 10:03:11 +00:00
|
|
|
|
|
|
|
__set_current_state(intr ? TASK_INTERRUPTIBLE :
|
|
|
|
TASK_UNINTERRUPTIBLE);
|
|
|
|
|
|
|
|
kt = ktime_set(0, sleep_time);
|
|
|
|
schedule_hrtimeout(&kt, HRTIMER_MODE_REL);
|
|
|
|
sleep_time *= 2;
|
|
|
|
if (sleep_time > NSEC_PER_MSEC)
|
|
|
|
sleep_time = NSEC_PER_MSEC;
|
|
|
|
|
|
|
|
if (intr && signal_pending(current))
|
|
|
|
return -ERESTARTSYS;
|
2013-01-31 04:57:33 +00:00
|
|
|
}
|
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
__set_current_state(TASK_RUNNING);
|
2013-01-31 04:57:33 +00:00
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
return timeout - t;
|
2013-01-31 04:57:33 +00:00
|
|
|
}
|
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
static int
|
|
|
|
nouveau_fence_wait_busy(struct nouveau_fence *fence, bool intr)
|
2009-12-11 09:24:15 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2012-04-30 03:30:00 +00:00
|
|
|
while (!nouveau_fence_done(fence)) {
|
2014-01-09 10:03:11 +00:00
|
|
|
if (time_after_eq(jiffies, fence->timeout)) {
|
2009-12-11 09:24:15 +00:00
|
|
|
ret = -EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
__set_current_state(intr ?
|
|
|
|
TASK_INTERRUPTIBLE :
|
|
|
|
TASK_UNINTERRUPTIBLE);
|
2009-12-11 09:24:15 +00:00
|
|
|
|
|
|
|
if (intr && signal_pending(current)) {
|
2009-12-15 01:04:25 +00:00
|
|
|
ret = -ERESTARTSYS;
|
2009-12-11 09:24:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__set_current_state(TASK_RUNNING);
|
2012-04-30 03:30:00 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-04-30 03:55:29 +00:00
|
|
|
int
|
2014-01-09 10:03:11 +00:00
|
|
|
nouveau_fence_wait(struct nouveau_fence *fence, bool lazy, bool intr)
|
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
|
|
|
|
if (!lazy)
|
|
|
|
return nouveau_fence_wait_busy(fence, intr);
|
|
|
|
|
|
|
|
ret = fence_wait_timeout(&fence->base, intr, 15 * HZ);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
else if (!ret)
|
|
|
|
return -EBUSY;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-09-16 09:15:07 +00:00
|
|
|
nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool exclusive, bool intr)
|
2012-04-30 03:55:29 +00:00
|
|
|
{
|
2013-02-14 03:20:17 +00:00
|
|
|
struct nouveau_fence_chan *fctx = chan->fence;
|
2014-04-09 14:19:30 +00:00
|
|
|
struct fence *fence;
|
2014-01-09 10:03:11 +00:00
|
|
|
struct reservation_object *resv = nvbo->bo.resv;
|
|
|
|
struct reservation_object_list *fobj;
|
2014-04-09 14:19:30 +00:00
|
|
|
struct nouveau_fence *f;
|
2014-01-09 10:03:11 +00:00
|
|
|
int ret = 0, i;
|
|
|
|
|
2014-04-09 14:19:30 +00:00
|
|
|
if (!exclusive) {
|
|
|
|
ret = reservation_object_reserve_shared(resv);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
fobj = reservation_object_get_list(resv);
|
2014-04-02 15:14:48 +00:00
|
|
|
fence = reservation_object_get_excl(resv);
|
2014-01-09 10:03:11 +00:00
|
|
|
|
2014-04-09 14:19:30 +00:00
|
|
|
if (fence && (!exclusive || !fobj || !fobj->shared_count)) {
|
|
|
|
struct nouveau_channel *prev = NULL;
|
2012-04-30 03:55:29 +00:00
|
|
|
|
2014-04-09 14:19:30 +00:00
|
|
|
f = nouveau_local_fence(fence, chan->drm);
|
|
|
|
if (f)
|
|
|
|
prev = f->channel;
|
|
|
|
|
|
|
|
if (!prev || (prev != chan && (ret = fctx->sync(f, prev, chan))))
|
2014-09-16 09:15:07 +00:00
|
|
|
ret = fence_wait(fence, intr);
|
2012-04-30 03:55:29 +00:00
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
return ret;
|
2014-04-09 14:19:30 +00:00
|
|
|
}
|
2012-04-30 03:55:29 +00:00
|
|
|
|
2014-04-09 14:19:30 +00:00
|
|
|
if (!exclusive || !fobj)
|
2014-01-09 10:03:11 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
for (i = 0; i < fobj->shared_count && !ret; ++i) {
|
2014-04-09 14:19:30 +00:00
|
|
|
struct nouveau_channel *prev = NULL;
|
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
fence = rcu_dereference_protected(fobj->shared[i],
|
|
|
|
reservation_object_held(resv));
|
|
|
|
|
2014-04-09 14:19:30 +00:00
|
|
|
f = nouveau_local_fence(fence, chan->drm);
|
|
|
|
if (f)
|
|
|
|
prev = f->channel;
|
|
|
|
|
2014-09-16 09:15:07 +00:00
|
|
|
if (!prev || (prev != chan && (ret = fctx->sync(f, prev, chan))))
|
|
|
|
ret = fence_wait(fence, intr);
|
2014-04-09 14:19:30 +00:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
break;
|
2014-01-09 10:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2012-04-30 03:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nouveau_fence_unref(struct nouveau_fence **pfence)
|
|
|
|
{
|
|
|
|
if (*pfence)
|
2014-01-09 10:03:11 +00:00
|
|
|
fence_put(&(*pfence)->base);
|
2012-04-30 03:30:00 +00:00
|
|
|
*pfence = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-02-14 03:43:21 +00:00
|
|
|
nouveau_fence_new(struct nouveau_channel *chan, bool sysmem,
|
|
|
|
struct nouveau_fence **pfence)
|
2012-04-30 03:30:00 +00:00
|
|
|
{
|
|
|
|
struct nouveau_fence *fence;
|
|
|
|
int ret = 0;
|
2009-12-11 09:24:15 +00:00
|
|
|
|
2012-07-19 00:51:42 +00:00
|
|
|
if (unlikely(!chan->fence))
|
2012-04-30 03:55:29 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
2012-04-30 03:30:00 +00:00
|
|
|
fence = kzalloc(sizeof(*fence), GFP_KERNEL);
|
|
|
|
if (!fence)
|
|
|
|
return -ENOMEM;
|
2013-02-14 03:43:21 +00:00
|
|
|
|
|
|
|
fence->sysmem = sysmem;
|
2012-04-30 03:30:00 +00:00
|
|
|
|
2013-01-15 17:19:49 +00:00
|
|
|
ret = nouveau_fence_emit(fence, chan);
|
|
|
|
if (ret)
|
|
|
|
nouveau_fence_unref(&fence);
|
2012-04-30 03:30:00 +00:00
|
|
|
|
|
|
|
*pfence = fence;
|
2009-12-11 09:24:15 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2014-01-09 10:03:11 +00:00
|
|
|
|
|
|
|
static const char *nouveau_fence_get_get_driver_name(struct fence *fence)
|
|
|
|
{
|
|
|
|
return "nouveau";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *nouveau_fence_get_timeline_name(struct fence *f)
|
|
|
|
{
|
|
|
|
struct nouveau_fence *fence = from_fence(f);
|
|
|
|
struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
|
|
|
|
|
|
|
|
return fence->channel ? fctx->name : "dead channel";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In an ideal world, read would not assume the channel context is still alive.
|
|
|
|
* This function may be called from another device, running into free memory as a
|
|
|
|
* result. The drm node should still be there, so we can derive the index from
|
|
|
|
* the fence context.
|
|
|
|
*/
|
|
|
|
static bool nouveau_fence_is_signaled(struct fence *f)
|
|
|
|
{
|
|
|
|
struct nouveau_fence *fence = from_fence(f);
|
|
|
|
struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
|
|
|
|
struct nouveau_channel *chan = fence->channel;
|
|
|
|
|
|
|
|
return (int)(fctx->read(chan) - fence->base.seqno) >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool nouveau_fence_no_signaling(struct fence *f)
|
|
|
|
{
|
|
|
|
struct nouveau_fence *fence = from_fence(f);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* caller should have a reference on the fence,
|
|
|
|
* else fence could get freed here
|
|
|
|
*/
|
|
|
|
WARN_ON(atomic_read(&fence->base.refcount.refcount) <= 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This needs uevents to work correctly, but fence_add_callback relies on
|
|
|
|
* being able to enable signaling. It will still get signaled eventually,
|
|
|
|
* just not right away.
|
|
|
|
*/
|
|
|
|
if (nouveau_fence_is_signaled(f)) {
|
|
|
|
list_del(&fence->head);
|
|
|
|
|
|
|
|
fence_put(&fence->base);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-29 08:06:18 +00:00
|
|
|
static void nouveau_fence_release(struct fence *f)
|
|
|
|
{
|
|
|
|
struct nouveau_fence *fence = from_fence(f);
|
|
|
|
struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
|
|
|
|
|
|
|
|
kref_put(&fctx->fence_ref, nouveau_fence_context_put);
|
|
|
|
fence_free(&fence->base);
|
|
|
|
}
|
|
|
|
|
2014-01-09 10:03:11 +00:00
|
|
|
static const struct fence_ops nouveau_fence_ops_legacy = {
|
|
|
|
.get_driver_name = nouveau_fence_get_get_driver_name,
|
|
|
|
.get_timeline_name = nouveau_fence_get_timeline_name,
|
|
|
|
.enable_signaling = nouveau_fence_no_signaling,
|
|
|
|
.signaled = nouveau_fence_is_signaled,
|
|
|
|
.wait = nouveau_fence_wait_legacy,
|
2014-09-29 08:06:18 +00:00
|
|
|
.release = nouveau_fence_release
|
2014-01-09 10:03:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool nouveau_fence_enable_signaling(struct fence *f)
|
|
|
|
{
|
|
|
|
struct nouveau_fence *fence = from_fence(f);
|
|
|
|
struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
if (!fctx->notify_ref++)
|
|
|
|
nvif_notify_get(&fctx->notify);
|
|
|
|
|
|
|
|
ret = nouveau_fence_no_signaling(f);
|
|
|
|
if (ret)
|
|
|
|
set_bit(FENCE_FLAG_USER_BITS, &fence->base.flags);
|
|
|
|
else if (!--fctx->notify_ref)
|
|
|
|
nvif_notify_put(&fctx->notify);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct fence_ops nouveau_fence_ops_uevent = {
|
|
|
|
.get_driver_name = nouveau_fence_get_get_driver_name,
|
|
|
|
.get_timeline_name = nouveau_fence_get_timeline_name,
|
|
|
|
.enable_signaling = nouveau_fence_enable_signaling,
|
|
|
|
.signaled = nouveau_fence_is_signaled,
|
|
|
|
.wait = fence_default_wait,
|
|
|
|
.release = NULL
|
|
|
|
};
|