diff options
| author | Meizu OpenSource <patchwork@meizu.com> | 2016-08-15 10:19:42 +0800 |
|---|---|---|
| committer | Meizu OpenSource <patchwork@meizu.com> | 2016-08-15 10:19:42 +0800 |
| commit | d2e1446d81725c351dc73a03b397ce043fb18452 (patch) | |
| tree | 4dbc616b7f92aea39cd697a9084205ddb805e344 /drivers/misc/mediatek/sync | |
| download | android_kernel_m2note-d2e1446d81725c351dc73a03b397ce043fb18452.tar.gz | |
first commit
Diffstat (limited to 'drivers/misc/mediatek/sync')
| -rw-r--r-- | drivers/misc/mediatek/sync/Makefile | 6 | ||||
| -rw-r--r-- | drivers/misc/mediatek/sync/mtk_sync.c | 131 | ||||
| -rw-r--r-- | drivers/misc/mediatek/sync/mtk_sync.h | 120 |
3 files changed, 257 insertions, 0 deletions
diff --git a/drivers/misc/mediatek/sync/Makefile b/drivers/misc/mediatek/sync/Makefile new file mode 100644 index 000000000..a6270f8ba --- /dev/null +++ b/drivers/misc/mediatek/sync/Makefile @@ -0,0 +1,6 @@ +# +# Makefile for the MTK sync driver +# + +# MTK sync driver interface +obj-y += mtk_sync.o diff --git a/drivers/misc/mediatek/sync/mtk_sync.c b/drivers/misc/mediatek/sync/mtk_sync.c new file mode 100644 index 000000000..e9fe3173a --- /dev/null +++ b/drivers/misc/mediatek/sync/mtk_sync.c @@ -0,0 +1,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); diff --git a/drivers/misc/mediatek/sync/mtk_sync.h b/drivers/misc/mediatek/sync/mtk_sync.h new file mode 100644 index 000000000..1bcedc408 --- /dev/null +++ b/drivers/misc/mediatek/sync/mtk_sync.h @@ -0,0 +1,120 @@ +/* +* 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/>. +*/ + +#ifndef _MTK_SYNC_H +#define _MTK_SYNC_H + +/* + * TIMEOUT_NEVER may be passed to the wait method to indicate that it + * should wait indefinitely for the fence to signal. + */ +#define TIMEOUT_NEVER -1 + +/* --------------------------------------------------------------------------- */ + +#ifdef __KERNEL__ + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)) +#include <linux/sw_sync.h> +#else +#include <../drivers/staging/android/sw_sync.h> +#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)) */ + +/* + * sync_timeline, sync_fence data structure + */ + +struct fence_data { + __u32 value; + char name[32]; + __s32 fence; /* fd of new fence */ +}; + + +/* + * sync_timeline, sync_fence API + */ + +/** + * timeline_create() - creates a sync object + * @name: sync_timeline name + * + * The timeline_create() function creates a sync object named @name, + * which represents a 32-bit monotonically increasing counter. + */ +struct sw_sync_timeline *timeline_create(const char *name); + +/** + * timeline_destroy() - releases a sync object + * @obj: sync_timeline obj + * + * The timeline_destroy() function releases a sync object. + * The remaining active points would be put into signaled list, + * and their statuses are set to ˇVENOENT. + */ +void timeline_destroy(struct sw_sync_timeline *obj); + +/** + * timeline_inc() - increases timeline + * @obj: sync_timeline obj + * @value: the increment to a sync object + * + * The timeline_inc() function increase the counter of @obj by @value + * Each sync point contains a value. A sync point on a parent timeline transits + * from active to signaled status when the counter of a timeline reaches + * to that of a sync point. + */ +void timeline_inc(struct sw_sync_timeline *obj, u32 value); + +/** + * fence_create() - create a fence + * @obj: sync_timeline obj + * @data: fence struct with its name and the number a sync point bears + * + * The fence_create() function creates a new sync point with @data->value, + * and assign the sync point to a newly created fence named @data->name. + * A file descriptor binded with the fence is stored in @data->fence. + */ +int fence_create(struct sw_sync_timeline *obj, struct fence_data *data); + +/** + * fence_merge() - merge two fences into a new one + * @name: fence name + * @fd1: file descriptor of the first fence + * @fd2: file descriptor of the second fence + * + * The fence_merge() function creates a new fence which contains copies of all + * the sync_pts in both @fd1 and @fd2. + * @fd1 and @fd2 remain valid, independent fences. + * On success, the newly created fd is returned; Otherwise, a -errno is returned. + */ +int fence_merge(char *const name, int fd1, int fd2); + +/** + * fence_wait() - wait for a fence + * @fence: fence pointer to a fence obj + * @timeout: how much time we wait at most + * + * The fence_wait() function waits for up to @timeout milliseconds + * for the fence to signal. + * A timeout of TIMEOUT_NEVER may be used to indicate that + * the call should wait indefinitely for the fence to signal. + */ +inline int fence_wait(struct sync_fence *fence, int timeout); + +#endif /* __KERNEL __ */ + +#endif /* _MTK_SYNC_H */ |
