]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_sync.c
gpu: vivante: Update driver from Freescale 3.10.53-1.1-ga BSP
[karo-tx-linux.git] / drivers / mxc / gpu-viv / hal / os / linux / kernel / gc_hal_kernel_sync.c
1 /****************************************************************************
2 *
3 *    Copyright (C) 2005 - 2014 by Vivante Corp.
4 *
5 *    This program is free software; you can redistribute it and/or modify
6 *    it under the terms of the GNU General Public License as published by
7 *    the Free Software Foundation; either version 2 of the license, or
8 *    (at your option) any later version.
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 *    You should have received a copy of the GNU General Public License
16 *    along with this program; if not write to the Free Software
17 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 *****************************************************************************/
20
21
22 #include <gc_hal.h>
23 #include <gc_hal_base.h>
24
25 #if gcdANDROID_NATIVE_FENCE_SYNC
26
27 #include <linux/kernel.h>
28 #include <linux/file.h>
29 #include <linux/fs.h>
30 #include <linux/miscdevice.h>
31 #include <linux/module.h>
32 #include <linux/syscalls.h>
33 #include <linux/uaccess.h>
34
35 #include "gc_hal_kernel_sync.h"
36
37 static struct sync_pt *
38 viv_sync_pt_dup(
39     struct sync_pt * sync_pt
40     )
41 {
42     gceSTATUS status;
43     struct viv_sync_pt *pt;
44     struct viv_sync_pt *src;
45     struct viv_sync_timeline *obj;
46
47     src = (struct viv_sync_pt *) sync_pt;
48     obj = (struct viv_sync_timeline *) sync_pt->parent;
49
50     /* Create the new sync_pt. */
51     pt = (struct viv_sync_pt *)
52         sync_pt_create(&obj->obj, sizeof(struct viv_sync_pt));
53
54     pt->stamp = src->stamp;
55     pt->sync = src->sync;
56
57     /* Reference sync point. */
58     status = gckOS_ReferenceSyncPoint(obj->os, pt->sync);
59
60     if (gcmIS_ERROR(status))
61     {
62         sync_pt_free((struct sync_pt *)pt);
63         return NULL;
64     }
65
66     return (struct sync_pt *)pt;
67 }
68
69 static int
70 viv_sync_pt_has_signaled(
71     struct sync_pt * sync_pt
72     )
73 {
74     gceSTATUS status;
75     gctBOOL state;
76     struct viv_sync_pt * pt;
77     struct viv_sync_timeline * obj;
78
79     pt  = (struct viv_sync_pt *)sync_pt;
80     obj = (struct viv_sync_timeline *)sync_pt->parent;
81
82     status = gckOS_QuerySyncPoint(obj->os, pt->sync, &state);
83
84     if (gcmIS_ERROR(status))
85     {
86         /* Error. */
87         return -1;
88     }
89
90     return state;
91 }
92
93 static int
94 viv_sync_pt_compare(
95     struct sync_pt * a,
96     struct sync_pt * b
97     )
98 {
99     int ret;
100     struct viv_sync_pt * pt1 = (struct viv_sync_pt *) a;
101     struct viv_sync_pt * pt2 = (struct viv_sync_pt *) b;
102
103     ret = (pt1->stamp <  pt2->stamp) ? -1
104         : (pt1->stamp == pt2->stamp) ?  0
105         : 1;
106
107     return ret;
108 }
109
110 static void
111 viv_sync_pt_free(
112     struct sync_pt * sync_pt
113     )
114 {
115     struct viv_sync_pt * pt;
116     struct viv_sync_timeline * obj;
117
118     pt  = (struct viv_sync_pt *) sync_pt;
119     obj = (struct viv_sync_timeline *) sync_pt->parent;
120
121     gckOS_DestroySyncPoint(obj->os, pt->sync);
122 }
123
124 static struct sync_timeline_ops viv_timeline_ops =
125 {
126     .driver_name = "viv_sync",
127     .dup = viv_sync_pt_dup,
128     .has_signaled = viv_sync_pt_has_signaled,
129     .compare = viv_sync_pt_compare,
130     .free_pt = viv_sync_pt_free,
131 };
132
133 struct viv_sync_timeline *
134 viv_sync_timeline_create(
135     const char * name,
136     gckOS os
137     )
138 {
139     struct viv_sync_timeline * obj;
140
141     obj = (struct viv_sync_timeline *)
142         sync_timeline_create(&viv_timeline_ops, sizeof(struct viv_sync_timeline), name);
143
144     obj->os    = os;
145     obj->stamp = 0;
146
147     return obj;
148 }
149
150 struct sync_pt *
151 viv_sync_pt_create(
152     struct viv_sync_timeline * obj,
153     gctSYNC_POINT SyncPoint
154     )
155 {
156     gceSTATUS status;
157     struct viv_sync_pt * pt;
158
159     pt = (struct viv_sync_pt *)
160         sync_pt_create(&obj->obj, sizeof(struct viv_sync_pt));
161
162     pt->stamp = obj->stamp++;
163     pt->sync  = SyncPoint;
164
165     /* Dup signal. */
166     status = gckOS_ReferenceSyncPoint(obj->os, SyncPoint);
167
168     if (gcmIS_ERROR(status))
169     {
170         sync_pt_free((struct sync_pt *)pt);
171         return NULL;
172     }
173
174     return (struct sync_pt *) pt;
175 }
176
177 #endif