aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/mediatek/sync/mtk_sync.c
blob: e9fe3173a31dd04df37edda74391132f84e330df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright (C) 2011-2014 MediaTek Inc.
*
* 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/debugfs.h>
#include <linux/export.h>
#include <linux/seq_file.h>
#include <linux/file.h>
#include <linux/kthread.h>
#include <linux/xlog.h>
#include <linux/delay.h>

#include "mtk_sync.h"

/* -------------------------------------------------------------------------- */

struct sw_sync_timeline *timeline_create(const char *name)
{
	return sw_sync_timeline_create(name);
}
EXPORT_SYMBOL(timeline_create);

void timeline_destroy(struct sw_sync_timeline *obj)
{
	sync_timeline_destroy(&obj->obj);
}
EXPORT_SYMBOL(timeline_destroy);

void timeline_inc(struct sw_sync_timeline *obj, u32 value)
{
	sw_sync_timeline_inc(obj, value);
}
EXPORT_SYMBOL(timeline_inc);

int fence_create(struct sw_sync_timeline *obj, struct fence_data *data)
{
	int fd = get_unused_fd();
	int err;
	struct sync_pt *pt;
	struct sync_fence *fence;

	if (fd < 0)
		return fd;

	pt = sw_sync_pt_create(obj, data->value);
	if (pt == NULL) {
		err = -ENOMEM;
		goto err;
	}

	data->name[sizeof(data->name) - 1] = '\0';
	fence = sync_fence_create(data->name, pt);
	if (fence == NULL) {
		sync_pt_free(pt);
		err = -ENOMEM;
		goto err;
	}

	data->fence = fd;

	sync_fence_install(fence, fd);

	return 0;

 err:
	put_unused_fd(fd);
	return err;
}
EXPORT_SYMBOL(fence_create);

int fence_merge(char *const name, int fd1, int fd2)
{
	int fd = get_unused_fd();
	int err;
	struct sync_fence *fence1, *fence2, *fence3;

	if (fd < 0)
		return fd;

	fence1 = sync_fence_fdget(fd1);
	if (NULL == fence1) {
		err = -ENOENT;
		goto err_put_fd;
	}

	fence2 = sync_fence_fdget(fd2);
	if (NULL == fence2) {
		err = -ENOENT;
		goto err_put_fence1;
	}

	name[sizeof(name) - 1] = '\0';
	fence3 = sync_fence_merge(name, fence1, fence2);
	if (fence3 == NULL) {
		err = -ENOMEM;
		goto err_put_fence2;
	}

	sync_fence_install(fence3, fd);
	sync_fence_put(fence2);
	sync_fence_put(fence1);

	return fd;

 err_put_fence2:
	sync_fence_put(fence2);

 err_put_fence1:
	sync_fence_put(fence1);

 err_put_fd:
	put_unused_fd(fd);
	return err;
}
EXPORT_SYMBOL(fence_merge);

inline int fence_wait(struct sync_fence *fence, int timeout)
{
	return sync_fence_wait(fence, timeout);
}
EXPORT_SYMBOL(fence_wait);