blob: bfe14e94c488196de8ec81230f527770bad83f93 [file] [log] [blame]
Thomas Gleixner1802d0b2019-05-27 08:55:21 +02001// SPDX-License-Identifier: GPL-2.0-only
Maarten Lankhorst606b23a2014-07-01 12:57:20 +02002/*
3 * seqno-fence, using a dma-buf to synchronize fencing
4 *
5 * Copyright (C) 2012 Texas Instruments
6 * Copyright (C) 2012-2014 Canonical Ltd
7 * Authors:
8 * Rob Clark <robdclark@gmail.com>
9 * Maarten Lankhorst <maarten.lankhorst@canonical.com>
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020010 */
11
12#include <linux/slab.h>
13#include <linux/export.h>
14#include <linux/seqno-fence.h>
15
Chris Wilsonf54d1862016-10-25 13:00:45 +010016static const char *seqno_fence_get_driver_name(struct dma_fence *fence)
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020017{
18 struct seqno_fence *seqno_fence = to_seqno_fence(fence);
Jagan Teki51366292015-05-21 01:09:31 +053019
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020020 return seqno_fence->ops->get_driver_name(fence);
21}
22
Chris Wilsonf54d1862016-10-25 13:00:45 +010023static const char *seqno_fence_get_timeline_name(struct dma_fence *fence)
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020024{
25 struct seqno_fence *seqno_fence = to_seqno_fence(fence);
Jagan Teki51366292015-05-21 01:09:31 +053026
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020027 return seqno_fence->ops->get_timeline_name(fence);
28}
29
Chris Wilsonf54d1862016-10-25 13:00:45 +010030static bool seqno_enable_signaling(struct dma_fence *fence)
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020031{
32 struct seqno_fence *seqno_fence = to_seqno_fence(fence);
Jagan Teki51366292015-05-21 01:09:31 +053033
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020034 return seqno_fence->ops->enable_signaling(fence);
35}
36
Chris Wilsonf54d1862016-10-25 13:00:45 +010037static bool seqno_signaled(struct dma_fence *fence)
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020038{
39 struct seqno_fence *seqno_fence = to_seqno_fence(fence);
Jagan Teki51366292015-05-21 01:09:31 +053040
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020041 return seqno_fence->ops->signaled && seqno_fence->ops->signaled(fence);
42}
43
Chris Wilsonf54d1862016-10-25 13:00:45 +010044static void seqno_release(struct dma_fence *fence)
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020045{
46 struct seqno_fence *f = to_seqno_fence(fence);
47
48 dma_buf_put(f->sync_buf);
49 if (f->ops->release)
50 f->ops->release(fence);
51 else
Chris Wilsonf54d1862016-10-25 13:00:45 +010052 dma_fence_free(&f->base);
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020053}
54
Chris Wilsonf54d1862016-10-25 13:00:45 +010055static signed long seqno_wait(struct dma_fence *fence, bool intr,
56 signed long timeout)
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020057{
58 struct seqno_fence *f = to_seqno_fence(fence);
Jagan Teki51366292015-05-21 01:09:31 +053059
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020060 return f->ops->wait(fence, intr, timeout);
61}
62
Chris Wilsonf54d1862016-10-25 13:00:45 +010063const struct dma_fence_ops seqno_fence_ops = {
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020064 .get_driver_name = seqno_fence_get_driver_name,
65 .get_timeline_name = seqno_fence_get_timeline_name,
66 .enable_signaling = seqno_enable_signaling,
67 .signaled = seqno_signaled,
68 .wait = seqno_wait,
69 .release = seqno_release,
70};
71EXPORT_SYMBOL(seqno_fence_ops);