Merge remote branch 'common/android-2.6.36' into android-tegra-2.6.36
[firefly-linux-kernel-4.4.55.git] / drivers / video / tegra / host / nvhost_syncpt.h
1 /*
2  * drivers/video/tegra/host/nvhost_syncpt.h
3  *
4  * Tegra Graphics Host Syncpoints
5  *
6  * Copyright (c) 2010, NVIDIA Corporation.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16  * more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21  */
22
23 #ifndef __NVHOST_SYNCPT_H
24 #define __NVHOST_SYNCPT_H
25
26 #include <linux/kernel.h>
27 #include <linux/sched.h>
28 #include <mach/nvhost.h>
29 #include <mach/nvmap.h>
30 #include <asm/atomic.h>
31
32 #include "nvhost_hardware.h"
33
34 #define NVSYNCPT_GRAPHICS_HOST               (0)
35 #define NVSYNCPT_VI_ISP_0                    (12)
36 #define NVSYNCPT_VI_ISP_1                    (13)
37 #define NVSYNCPT_VI_ISP_2                    (14)
38 #define NVSYNCPT_VI_ISP_3                    (15)
39 #define NVSYNCPT_VI_ISP_4                    (16)
40 #define NVSYNCPT_VI_ISP_5                    (17)
41 #define NVSYNCPT_2D_0                        (18)
42 #define NVSYNCPT_2D_1                        (19)
43 #define NVSYNCPT_3D                          (22)
44 #define NVSYNCPT_MPE                         (23)
45 #define NVSYNCPT_DISP0                       (24)
46 #define NVSYNCPT_DISP1                       (25)
47 #define NVSYNCPT_VBLANK0                     (26)
48 #define NVSYNCPT_VBLANK1                     (27)
49 #define NVSYNCPT_MPE_EBM_EOF                 (28)
50 #define NVSYNCPT_MPE_WR_SAFE                 (29)
51 #define NVSYNCPT_DSI                         (31)
52 #define NVSYNCPT_INVALID                     (-1)
53
54 /*#define NVSYNCPT_2D_CHANNEL2_0    (20) */
55 /*#define NVSYNCPT_2D_CHANNEL2_1    (21) */
56 /*#define NVSYNCPT_2D_TINYBLT_WAR                    (30)*/
57 /*#define NVSYNCPT_2D_TINYBLT_RESTORE_CLASS_ID (30)*/
58
59 /* sync points that are wholly managed by the client */
60 #define NVSYNCPTS_CLIENT_MANAGED ( \
61         BIT(NVSYNCPT_DISP0) | BIT(NVSYNCPT_DISP1) | BIT(NVSYNCPT_DSI) | \
62         BIT(NVSYNCPT_VI_ISP_0) | BIT(NVSYNCPT_VI_ISP_2) | \
63         BIT(NVSYNCPT_VI_ISP_3) | BIT(NVSYNCPT_VI_ISP_4) | BIT(NVSYNCPT_VI_ISP_5) | \
64         BIT(NVSYNCPT_MPE_EBM_EOF) | BIT(NVSYNCPT_MPE_WR_SAFE) | \
65         BIT(NVSYNCPT_2D_1))
66
67 #define NVWAITBASE_2D_0 (1)
68 #define NVWAITBASE_2D_1 (2)
69 #define NVWAITBASE_3D   (3)
70 #define NVWAITBASE_MPE  (4)
71
72 struct nvhost_syncpt {
73         atomic_t min_val[NV_HOST1X_SYNCPT_NB_PTS];
74         atomic_t max_val[NV_HOST1X_SYNCPT_NB_PTS];
75         u32 base_val[NV_HOST1X_SYNCPT_NB_BASES];
76 };
77
78 /**
79  * Updates the value sent to hardware.
80  */
81 static inline u32 nvhost_syncpt_incr_max(struct nvhost_syncpt *sp,
82                                         u32 id, u32 incrs)
83 {
84         return (u32)atomic_add_return(incrs, &sp->max_val[id]);
85 }
86
87 /**
88  * Updated the value sent to hardware.
89  */
90 static inline u32 nvhost_syncpt_set_max(struct nvhost_syncpt *sp,
91                                         u32 id, u32 val)
92 {
93         atomic_set(&sp->max_val[id], val);
94         smp_wmb();
95         return val;
96 }
97
98 static inline u32 nvhost_syncpt_read_max(struct nvhost_syncpt *sp, u32 id)
99 {
100         smp_rmb();
101         return (u32)atomic_read(&sp->max_val[id]);
102 }
103
104 /**
105  * Returns true if syncpoint has reached threshold
106  */
107 static inline bool nvhost_syncpt_min_cmp(struct nvhost_syncpt *sp,
108                                         u32 id, u32 thresh)
109 {
110         u32 cur;
111         smp_rmb();
112         cur = (u32)atomic_read(&sp->min_val[id]);
113         return ((s32)(cur - thresh) >= 0);
114 }
115
116 /**
117  * Returns true if syncpoint min == max
118  */
119 static inline bool nvhost_syncpt_min_eq_max(struct nvhost_syncpt *sp, u32 id)
120 {
121         int min, max;
122         smp_rmb();
123         min = atomic_read(&sp->min_val[id]);
124         max = atomic_read(&sp->max_val[id]);
125         return (min == max);
126 }
127
128 void nvhost_syncpt_cpu_incr(struct nvhost_syncpt *sp, u32 id);
129
130 u32 nvhost_syncpt_update_min(struct nvhost_syncpt *sp, u32 id);
131
132 void nvhost_syncpt_save(struct nvhost_syncpt *sp);
133
134 void nvhost_syncpt_reset(struct nvhost_syncpt *sp);
135
136 u32 nvhost_syncpt_read(struct nvhost_syncpt *sp, u32 id);
137
138 void nvhost_syncpt_incr(struct nvhost_syncpt *sp, u32 id);
139
140 int nvhost_syncpt_wait_timeout(struct nvhost_syncpt *sp, u32 id, u32 thresh,
141                         u32 timeout);
142
143 static inline int nvhost_syncpt_wait(struct nvhost_syncpt *sp, u32 id, u32 thresh)
144 {
145         return nvhost_syncpt_wait_timeout(sp, id, thresh, MAX_SCHEDULE_TIMEOUT);
146 }
147
148 int nvhost_syncpt_wait_check(struct nvmap_client *nvmap,
149                         struct nvhost_syncpt *sp, u32 mask,
150                         struct nvhost_waitchk *waitp, u32 num_waits);
151
152 const char *nvhost_syncpt_name(u32 id);
153
154 void nvhost_syncpt_debug(struct nvhost_syncpt *sp);
155
156 #endif