Merge branch 'misc' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
[deliverable/linux.git] / drivers / staging / android / sw_sync.c
CommitLineData
9d1906e6
EG
1/*
2 * drivers/base/sw_sync.c
3 *
4 * Copyright (C) 2012 Google, Inc.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/kernel.h>
db1ad33b 18#include <linux/init.h>
6e91f719 19#include <linux/export.h>
9d1906e6
EG
20#include <linux/file.h>
21#include <linux/fs.h>
22#include <linux/miscdevice.h>
9d1906e6
EG
23#include <linux/syscalls.h>
24#include <linux/uaccess.h>
25
26#include "sw_sync.h"
27
b55b54b5 28struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value)
9d1906e6
EG
29{
30 struct sw_sync_pt *pt;
31
32 pt = (struct sw_sync_pt *)
33 sync_pt_create(&obj->obj, sizeof(struct sw_sync_pt));
34
35 pt->value = value;
36
b55b54b5 37 return (struct fence *)pt;
9d1906e6 38}
6e91f719 39EXPORT_SYMBOL(sw_sync_pt_create);
9d1906e6 40
b55b54b5 41static int sw_sync_fence_has_signaled(struct fence *fence)
9d1906e6 42{
b55b54b5 43 struct sw_sync_pt *pt = (struct sw_sync_pt *)fence;
9d1906e6 44 struct sw_sync_timeline *obj =
b55b54b5 45 (struct sw_sync_timeline *)fence_parent(fence);
9d1906e6 46
27e3917a 47 return (pt->value > obj->value) ? 0 : 1;
9d1906e6
EG
48}
49
135114a5
EG
50static void sw_sync_timeline_value_str(struct sync_timeline *sync_timeline,
51 char *str, int size)
52{
53 struct sw_sync_timeline *timeline =
54 (struct sw_sync_timeline *)sync_timeline;
55 snprintf(str, size, "%d", timeline->value);
56}
57
b55b54b5 58static void sw_sync_fence_value_str(struct fence *fence, char *str, int size)
135114a5 59{
b55b54b5 60 struct sw_sync_pt *pt = (struct sw_sync_pt *)fence;
a5b4e003 61
135114a5
EG
62 snprintf(str, size, "%d", pt->value);
63}
64
451fb766 65static struct sync_timeline_ops sw_sync_timeline_ops = {
9d1906e6 66 .driver_name = "sw_sync",
b55b54b5 67 .has_signaled = sw_sync_fence_has_signaled,
135114a5 68 .timeline_value_str = sw_sync_timeline_value_str,
b55b54b5 69 .fence_value_str = sw_sync_fence_value_str,
9d1906e6
EG
70};
71
9d1906e6
EG
72struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
73{
74 struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
75 sync_timeline_create(&sw_sync_timeline_ops,
76 sizeof(struct sw_sync_timeline),
77 name);
78
79 return obj;
80}
6e91f719 81EXPORT_SYMBOL(sw_sync_timeline_create);
9d1906e6
EG
82
83void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
84{
85 obj->value += inc;
86
87 sync_timeline_signal(&obj->obj);
88}
6e91f719 89EXPORT_SYMBOL(sw_sync_timeline_inc);
This page took 0.45746 seconds and 5 git commands to generate.