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
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>
30 /* Reserved for replacing an expired wait with a NOP */
31 #define HOST1X_SYNCPT_RESERVED 0
33 struct host1x_syncpt {
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.
57 static inline u32 host1x_syncpt_read_max(struct host1x_syncpt *sp)
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)
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.
87 static inline bool host1x_syncpt_check_max(struct host1x_syncpt *sp, u32 real)
90 if (sp->client_managed)
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 int 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)
110 min = atomic_read(&sp->min_val);
111 max = atomic_read(&sp->max_val);
115 /* Return pointer to struct denoting sync point id. */
116 struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
118 /* Request incrementing a sync point. */
119 void host1x_syncpt_cpu_incr(struct host1x_syncpt *sp);
121 /* Load current value from hardware to the shadow register. */
122 u32 host1x_syncpt_load(struct host1x_syncpt *sp);
124 /* Check if the given syncpoint value has already passed */
125 bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
127 /* Save host1x sync point state into shadow registers. */
128 void host1x_syncpt_save(struct host1x *host);
130 /* Reset host1x sync point state from shadow registers. */
131 void host1x_syncpt_restore(struct host1x *host);
133 /* Read current wait base value into shadow register and return it. */
134 u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp);
136 /* Increment sync point and its max. */
137 void host1x_syncpt_incr(struct host1x_syncpt *sp);
139 /* Indicate future operations by incrementing the sync point max. */
140 u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
142 /* Wait until sync point reaches a threshold value, or a timeout. */
143 int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh,
144 long timeout, u32 *value);
146 /* Check if sync point id is valid. */
147 static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
149 return sp->id < host1x_syncpt_nb_pts(sp->host);
152 /* Patch a wait by replacing it with a wait for syncpt 0 value 0 */
153 int host1x_syncpt_patch_wait(struct host1x_syncpt *sp, void *patch_addr);
155 /* Return id of the sync point */
156 u32 host1x_syncpt_id(struct host1x_syncpt *sp);
158 /* Allocate a sync point for a device. */
159 struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
162 /* Free a sync point. */
163 void host1x_syncpt_free(struct host1x_syncpt *sp);