mirror of
https://github.com/torvalds/linux.git
synced 2024-12-31 23:31:29 +00:00
ca762a8ae7
Better encapsulate the per-timeline stuff into fence-context. For now there is just a single fence-context, but eventually we'll also have one per-CRTC to enable fully explicit fencing. Signed-off-by: Rob Clark <robdclark@gmail.com>
140 lines
3.3 KiB
C
140 lines
3.3 KiB
C
/*
|
|
* Copyright (C) 2013-2016 Red Hat
|
|
* Author: Rob Clark <robdclark@gmail.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
* the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <linux/fence.h>
|
|
|
|
#include "msm_drv.h"
|
|
#include "msm_fence.h"
|
|
|
|
|
|
struct msm_fence_context *
|
|
msm_fence_context_alloc(struct drm_device *dev, const char *name)
|
|
{
|
|
struct msm_fence_context *fctx;
|
|
|
|
fctx = kzalloc(sizeof(*fctx), GFP_KERNEL);
|
|
if (!fctx)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
fctx->dev = dev;
|
|
fctx->name = name;
|
|
init_waitqueue_head(&fctx->event);
|
|
INIT_LIST_HEAD(&fctx->fence_cbs);
|
|
|
|
return fctx;
|
|
}
|
|
|
|
void msm_fence_context_free(struct msm_fence_context *fctx)
|
|
{
|
|
kfree(fctx);
|
|
}
|
|
|
|
static inline bool fence_completed(struct msm_fence_context *fctx, uint32_t fence)
|
|
{
|
|
return (int32_t)(fctx->completed_fence - fence) >= 0;
|
|
}
|
|
|
|
int msm_wait_fence(struct msm_fence_context *fctx, uint32_t fence,
|
|
ktime_t *timeout, bool interruptible)
|
|
{
|
|
int ret;
|
|
|
|
if (fence > fctx->last_fence) {
|
|
DRM_ERROR("%s: waiting on invalid fence: %u (of %u)\n",
|
|
fctx->name, fence, fctx->last_fence);
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (!timeout) {
|
|
/* no-wait: */
|
|
ret = fence_completed(fctx, fence) ? 0 : -EBUSY;
|
|
} else {
|
|
unsigned long remaining_jiffies = timeout_to_jiffies(timeout);
|
|
|
|
if (interruptible)
|
|
ret = wait_event_interruptible_timeout(fctx->event,
|
|
fence_completed(fctx, fence),
|
|
remaining_jiffies);
|
|
else
|
|
ret = wait_event_timeout(fctx->event,
|
|
fence_completed(fctx, fence),
|
|
remaining_jiffies);
|
|
|
|
if (ret == 0) {
|
|
DBG("timeout waiting for fence: %u (completed: %u)",
|
|
fence, fctx->completed_fence);
|
|
ret = -ETIMEDOUT;
|
|
} else if (ret != -ERESTARTSYS) {
|
|
ret = 0;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
int msm_queue_fence_cb(struct msm_fence_context *fctx,
|
|
struct msm_fence_cb *cb, uint32_t fence)
|
|
{
|
|
struct msm_drm_private *priv = fctx->dev->dev_private;
|
|
int ret = 0;
|
|
|
|
mutex_lock(&fctx->dev->struct_mutex);
|
|
if (!list_empty(&cb->work.entry)) {
|
|
ret = -EINVAL;
|
|
} else if (fence > fctx->completed_fence) {
|
|
cb->fence = fence;
|
|
list_add_tail(&cb->work.entry, &fctx->fence_cbs);
|
|
} else {
|
|
queue_work(priv->wq, &cb->work);
|
|
}
|
|
mutex_unlock(&fctx->dev->struct_mutex);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/* called from workqueue */
|
|
void msm_update_fence(struct msm_fence_context *fctx, uint32_t fence)
|
|
{
|
|
struct msm_drm_private *priv = fctx->dev->dev_private;
|
|
|
|
mutex_lock(&fctx->dev->struct_mutex);
|
|
fctx->completed_fence = max(fence, fctx->completed_fence);
|
|
|
|
while (!list_empty(&fctx->fence_cbs)) {
|
|
struct msm_fence_cb *cb;
|
|
|
|
cb = list_first_entry(&fctx->fence_cbs,
|
|
struct msm_fence_cb, work.entry);
|
|
|
|
if (cb->fence > fctx->completed_fence)
|
|
break;
|
|
|
|
list_del_init(&cb->work.entry);
|
|
queue_work(priv->wq, &cb->work);
|
|
}
|
|
|
|
mutex_unlock(&fctx->dev->struct_mutex);
|
|
|
|
wake_up_all(&fctx->event);
|
|
}
|
|
|
|
void __msm_fence_worker(struct work_struct *work)
|
|
{
|
|
struct msm_fence_cb *cb = container_of(work, struct msm_fence_cb, work);
|
|
cb->func(cb);
|
|
}
|