]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/host1x/syncpt.h
Merge remote-tracking branch 'input/next'
[karo-tx-linux.git] / drivers / gpu / host1x / syncpt.h
1 /*
2  * Tegra host1x Syncpoints
3  *
4  * Copyright (c) 2010-2013, NVIDIA Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef __HOST1X_SYNCPT_H
20 #define __HOST1X_SYNCPT_H
21
22 #include <linux/atomic.h>
23 #include <linux/host1x.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
26
27 #include "intr.h"
28
29 struct host1x;
30
31 /* Reserved for replacing an expired wait with a NOP */
32 #define HOST1X_SYNCPT_RESERVED                  0
33
34 struct host1x_syncpt {
35         int id;
36         atomic_t min_val;
37         atomic_t max_val;
38         u32 base_val;
39         const char *name;
40         bool client_managed;
41         struct host1x *host;
42         struct device *dev;
43
44         /* interrupt data */
45         struct host1x_syncpt_intr intr;
46 };
47
48 /* Initialize sync point array  */
49 int host1x_syncpt_init(struct host1x *host);
50
51 /*  Free sync point array */
52 void host1x_syncpt_deinit(struct host1x *host);
53
54 /* Return number of sync point supported. */
55 int host1x_syncpt_nb_pts(struct host1x *host);
56
57 /* Return number of wait bases supported. */
58 int host1x_syncpt_nb_bases(struct host1x *host);
59
60 /* Return number of mlocks supported. */
61 int host1x_syncpt_nb_mlocks(struct host1x *host);
62
63 /*
64  * Check sync point sanity. If max is larger than min, there have too many
65  * sync point increments.
66  *
67  * Client managed sync point are not tracked.
68  * */
69 static inline bool host1x_syncpt_check_max(struct host1x_syncpt *sp, u32 real)
70 {
71         u32 max;
72         if (sp->client_managed)
73                 return true;
74         max = host1x_syncpt_read_max(sp);
75         return (s32)(max - real) >= 0;
76 }
77
78 /* Return true if sync point is client managed. */
79 static inline bool host1x_syncpt_client_managed(struct host1x_syncpt *sp)
80 {
81         return sp->client_managed;
82 }
83
84 /*
85  * Returns true if syncpoint min == max, which means that there are no
86  * outstanding operations.
87  */
88 static inline bool host1x_syncpt_idle(struct host1x_syncpt *sp)
89 {
90         int min, max;
91         smp_rmb();
92         min = atomic_read(&sp->min_val);
93         max = atomic_read(&sp->max_val);
94         return (min == max);
95 }
96
97 /* Load current value from hardware to the shadow register. */
98 u32 host1x_syncpt_load(struct host1x_syncpt *sp);
99
100 /* Check if the given syncpoint value has already passed */
101 bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
102
103 /* Save host1x sync point state into shadow registers. */
104 void host1x_syncpt_save(struct host1x *host);
105
106 /* Reset host1x sync point state from shadow registers. */
107 void host1x_syncpt_restore(struct host1x *host);
108
109 /* Read current wait base value into shadow register and return it. */
110 u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp);
111
112 /* Indicate future operations by incrementing the sync point max. */
113 u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
114
115 /* Check if sync point id is valid. */
116 static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
117 {
118         return sp->id < host1x_syncpt_nb_pts(sp->host);
119 }
120
121 /* Patch a wait by replacing it with a wait for syncpt 0 value 0 */
122 int host1x_syncpt_patch_wait(struct host1x_syncpt *sp, void *patch_addr);
123
124 #endif