blob: f47112a647634c5c16b64add1b8e9a68b5d99c85 [file] [log] [blame]
Maarten Lankhorst606b23a2014-07-01 12:57:20 +02001/*
2 * seqno-fence, using a dma-buf to synchronize fencing
3 *
4 * Copyright (C) 2012 Texas Instruments
5 * Copyright (C) 2012-2014 Canonical Ltd
6 * Authors:
7 * Rob Clark <robdclark@gmail.com>
8 * Maarten Lankhorst <maarten.lankhorst@canonical.com>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 */
19
20#include <linux/slab.h>
21#include <linux/export.h>
22#include <linux/seqno-fence.h>
23
Chris Wilsonf54d1862016-10-25 13:00:45 +010024static const char *seqno_fence_get_driver_name(struct dma_fence *fence)
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020025{
26 struct seqno_fence *seqno_fence = to_seqno_fence(fence);
Jagan Teki51366292015-05-21 01:09:31 +053027
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020028 return seqno_fence->ops->get_driver_name(fence);
29}
30
Chris Wilsonf54d1862016-10-25 13:00:45 +010031static const char *seqno_fence_get_timeline_name(struct dma_fence *fence)
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020032{
33 struct seqno_fence *seqno_fence = to_seqno_fence(fence);
Jagan Teki51366292015-05-21 01:09:31 +053034
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020035 return seqno_fence->ops->get_timeline_name(fence);
36}
37
Chris Wilsonf54d1862016-10-25 13:00:45 +010038static bool seqno_enable_signaling(struct dma_fence *fence)
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020039{
40 struct seqno_fence *seqno_fence = to_seqno_fence(fence);
Jagan Teki51366292015-05-21 01:09:31 +053041
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020042 return seqno_fence->ops->enable_signaling(fence);
43}
44
Chris Wilsonf54d1862016-10-25 13:00:45 +010045static bool seqno_signaled(struct dma_fence *fence)
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020046{
47 struct seqno_fence *seqno_fence = to_seqno_fence(fence);
Jagan Teki51366292015-05-21 01:09:31 +053048
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020049 return seqno_fence->ops->signaled && seqno_fence->ops->signaled(fence);
50}
51
Chris Wilsonf54d1862016-10-25 13:00:45 +010052static void seqno_release(struct dma_fence *fence)
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020053{
54 struct seqno_fence *f = to_seqno_fence(fence);
55
56 dma_buf_put(f->sync_buf);
57 if (f->ops->release)
58 f->ops->release(fence);
59 else
Chris Wilsonf54d1862016-10-25 13:00:45 +010060 dma_fence_free(&f->base);
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020061}
62
Chris Wilsonf54d1862016-10-25 13:00:45 +010063static signed long seqno_wait(struct dma_fence *fence, bool intr,
64 signed long timeout)
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020065{
66 struct seqno_fence *f = to_seqno_fence(fence);
Jagan Teki51366292015-05-21 01:09:31 +053067
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020068 return f->ops->wait(fence, intr, timeout);
69}
70
Chris Wilsonf54d1862016-10-25 13:00:45 +010071const struct dma_fence_ops seqno_fence_ops = {
Maarten Lankhorst606b23a2014-07-01 12:57:20 +020072 .get_driver_name = seqno_fence_get_driver_name,
73 .get_timeline_name = seqno_fence_get_timeline_name,
74 .enable_signaling = seqno_enable_signaling,
75 .signaled = seqno_signaled,
76 .wait = seqno_wait,
77 .release = seqno_release,
78};
79EXPORT_SYMBOL(seqno_fence_ops);