usb: gadget: Use ERR_CAST inlined function instead of ERR_PTR(PTR_ERR(...))
[linux-2.6.git] / drivers / gpu / host1x / syncpt.h
blob267c0b9d3647d24f2a3bf7dc81504eacaf957005
1 /*
2 * Tegra host1x Syncpoints
4 * Copyright (c) 2010-2013, NVIDIA Corporation.
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.
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.
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/>.
19 #ifndef __HOST1X_SYNCPT_H
20 #define __HOST1X_SYNCPT_H
22 #include <linux/atomic.h>
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
26 #include "intr.h"
28 struct host1x;
30 /* Reserved for replacing an expired wait with a NOP */
31 #define HOST1X_SYNCPT_RESERVED 0
33 struct host1x_syncpt {
34 int id;
35 atomic_t min_val;
36 atomic_t max_val;
37 u32 base_val;
38 const char *name;
39 bool client_managed;
40 struct host1x *host;
41 struct device *dev;
43 /* interrupt data */
44 struct host1x_syncpt_intr intr;
47 /* Initialize sync point array */
48 int host1x_syncpt_init(struct host1x *host);
50 /* Free sync point array */
51 void host1x_syncpt_deinit(struct host1x *host);
54 * Read max. It indicates how many operations there are in queue, either in
55 * channel or in a software thread.
56 * */
57 static inline u32 host1x_syncpt_read_max(struct host1x_syncpt *sp)
59 smp_rmb();
60 return (u32)atomic_read(&sp->max_val);
64 * Read min, which is a shadow of the current sync point value in hardware.
66 static inline u32 host1x_syncpt_read_min(struct host1x_syncpt *sp)
68 smp_rmb();
69 return (u32)atomic_read(&sp->min_val);
72 /* Return number of sync point supported. */
73 int host1x_syncpt_nb_pts(struct host1x *host);
75 /* Return number of wait bases supported. */
76 int host1x_syncpt_nb_bases(struct host1x *host);
78 /* Return number of mlocks supported. */
79 int host1x_syncpt_nb_mlocks(struct host1x *host);
82 * Check sync point sanity. If max is larger than min, there have too many
83 * sync point increments.
85 * Client managed sync point are not tracked.
86 * */
87 static inline bool host1x_syncpt_check_max(struct host1x_syncpt *sp, u32 real)
89 u32 max;
90 if (sp->client_managed)
91 return true;
92 max = host1x_syncpt_read_max(sp);
93 return (s32)(max - real) >= 0;
96 /* Return true if sync point is client managed. */
97 static inline bool host1x_syncpt_client_managed(struct host1x_syncpt *sp)
99 return sp->client_managed;
103 * Returns true if syncpoint min == max, which means that there are no
104 * outstanding operations.
106 static inline bool host1x_syncpt_idle(struct host1x_syncpt *sp)
108 int min, max;
109 smp_rmb();
110 min = atomic_read(&sp->min_val);
111 max = atomic_read(&sp->max_val);
112 return (min == max);
115 /* Return pointer to struct denoting sync point id. */
116 struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
118 /* Load current value from hardware to the shadow register. */
119 u32 host1x_syncpt_load(struct host1x_syncpt *sp);
121 /* Check if the given syncpoint value has already passed */
122 bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
124 /* Save host1x sync point state into shadow registers. */
125 void host1x_syncpt_save(struct host1x *host);
127 /* Reset host1x sync point state from shadow registers. */
128 void host1x_syncpt_restore(struct host1x *host);
130 /* Read current wait base value into shadow register and return it. */
131 u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp);
133 /* Request incrementing a sync point. */
134 int host1x_syncpt_incr(struct host1x_syncpt *sp);
136 /* Indicate future operations by incrementing the sync point max. */
137 u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
139 /* Wait until sync point reaches a threshold value, or a timeout. */
140 int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh,
141 long timeout, u32 *value);
143 /* Check if sync point id is valid. */
144 static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
146 return sp->id < host1x_syncpt_nb_pts(sp->host);
149 /* Patch a wait by replacing it with a wait for syncpt 0 value 0 */
150 int host1x_syncpt_patch_wait(struct host1x_syncpt *sp, void *patch_addr);
152 /* Return id of the sync point */
153 u32 host1x_syncpt_id(struct host1x_syncpt *sp);
155 /* Allocate a sync point for a device. */
156 struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
157 bool client_managed);
159 /* Free a sync point. */
160 void host1x_syncpt_free(struct host1x_syncpt *sp);
162 #endif