mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 09:19:51 +00:00
![Matthew Brost](/assets/img/avatar_default.png)
Rather than stealing bits from i915_sw_fence function pointer use separate fields for function pointer and flags. If using two different fields, the 4 byte alignment for the i915_sw_fence function pointer can also be dropped. v2: (CI) - Set new function field rather than flags in __i915_sw_fence_init v3: (Tvrtko) - Remove BUG_ON(!fence->flags) in reinit as that will now blow up - Only define fence->flags if CONFIG_DRM_I915_SW_FENCE_CHECK_DAG is defined v4: - Rebase, resend for CI Signed-off-by: Matthew Brost <matthew.brost@intel.com> Acked-by: Jani Nikula <jani.nikula@intel.com> Reviewed-by: Alan Previn <alan.previn.teres.alexis@intel.com> Signed-off-by: John Harrison <John.C.Harrison@Intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20211116194929.10211-1-matthew.brost@intel.com
99 lines
2 KiB
C
99 lines
2 KiB
C
// SPDX-License-Identifier: MIT
|
|
|
|
/*
|
|
* Copyright © 2019 Intel Corporation
|
|
*/
|
|
|
|
#include "i915_sw_fence_work.h"
|
|
|
|
static void fence_complete(struct dma_fence_work *f)
|
|
{
|
|
if (f->ops->release)
|
|
f->ops->release(f);
|
|
dma_fence_signal(&f->dma);
|
|
}
|
|
|
|
static void fence_work(struct work_struct *work)
|
|
{
|
|
struct dma_fence_work *f = container_of(work, typeof(*f), work);
|
|
|
|
f->ops->work(f);
|
|
|
|
fence_complete(f);
|
|
dma_fence_put(&f->dma);
|
|
}
|
|
|
|
static int
|
|
fence_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
|
|
{
|
|
struct dma_fence_work *f = container_of(fence, typeof(*f), chain);
|
|
|
|
switch (state) {
|
|
case FENCE_COMPLETE:
|
|
if (fence->error)
|
|
dma_fence_set_error(&f->dma, fence->error);
|
|
|
|
if (!f->dma.error) {
|
|
dma_fence_get(&f->dma);
|
|
if (test_bit(DMA_FENCE_WORK_IMM, &f->dma.flags))
|
|
fence_work(&f->work);
|
|
else
|
|
queue_work(system_unbound_wq, &f->work);
|
|
} else {
|
|
fence_complete(f);
|
|
}
|
|
break;
|
|
|
|
case FENCE_FREE:
|
|
dma_fence_put(&f->dma);
|
|
break;
|
|
}
|
|
|
|
return NOTIFY_DONE;
|
|
}
|
|
|
|
static const char *get_driver_name(struct dma_fence *fence)
|
|
{
|
|
return "dma-fence";
|
|
}
|
|
|
|
static const char *get_timeline_name(struct dma_fence *fence)
|
|
{
|
|
struct dma_fence_work *f = container_of(fence, typeof(*f), dma);
|
|
|
|
return f->ops->name ?: "work";
|
|
}
|
|
|
|
static void fence_release(struct dma_fence *fence)
|
|
{
|
|
struct dma_fence_work *f = container_of(fence, typeof(*f), dma);
|
|
|
|
i915_sw_fence_fini(&f->chain);
|
|
|
|
BUILD_BUG_ON(offsetof(typeof(*f), dma));
|
|
dma_fence_free(&f->dma);
|
|
}
|
|
|
|
static const struct dma_fence_ops fence_ops = {
|
|
.get_driver_name = get_driver_name,
|
|
.get_timeline_name = get_timeline_name,
|
|
.release = fence_release,
|
|
};
|
|
|
|
void dma_fence_work_init(struct dma_fence_work *f,
|
|
const struct dma_fence_work_ops *ops)
|
|
{
|
|
f->ops = ops;
|
|
spin_lock_init(&f->lock);
|
|
dma_fence_init(&f->dma, &fence_ops, &f->lock, 0, 0);
|
|
i915_sw_fence_init(&f->chain, fence_notify);
|
|
INIT_WORK(&f->work, fence_work);
|
|
}
|
|
|
|
int dma_fence_work_chain(struct dma_fence_work *f, struct dma_fence *signal)
|
|
{
|
|
if (!signal)
|
|
return 0;
|
|
|
|
return __i915_sw_fence_await_dma_fence(&f->chain, signal, &f->cb);
|
|
}
|