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/host1x.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
31 /* Reserved for replacing an expired wait with a NOP */
32 #define HOST1X_SYNCPT_RESERVED 0
34 struct host1x_syncpt_base
{
39 struct host1x_syncpt
{
47 struct host1x_client
*client
;
48 struct host1x_syncpt_base
*base
;
51 struct host1x_syncpt_intr intr
;
54 /* Initialize sync point array */
55 int host1x_syncpt_init(struct host1x
*host
);
57 /* Free sync point array */
58 void host1x_syncpt_deinit(struct host1x
*host
);
60 /* Return number of sync point supported. */
61 unsigned int host1x_syncpt_nb_pts(struct host1x
*host
);
63 /* Return number of wait bases supported. */
64 unsigned int host1x_syncpt_nb_bases(struct host1x
*host
);
66 /* Return number of mlocks supported. */
67 unsigned int host1x_syncpt_nb_mlocks(struct host1x
*host
);
70 * Check sync point sanity. If max is larger than min, there have too many
71 * sync point increments.
73 * Client managed sync point are not tracked.
75 static inline bool host1x_syncpt_check_max(struct host1x_syncpt
*sp
, u32 real
)
78 if (sp
->client_managed
)
80 max
= host1x_syncpt_read_max(sp
);
81 return (s32
)(max
- real
) >= 0;
84 /* Return true if sync point is client managed. */
85 static inline bool host1x_syncpt_client_managed(struct host1x_syncpt
*sp
)
87 return sp
->client_managed
;
91 * Returns true if syncpoint min == max, which means that there are no
92 * outstanding operations.
94 static inline bool host1x_syncpt_idle(struct host1x_syncpt
*sp
)
98 min
= atomic_read(&sp
->min_val
);
99 max
= atomic_read(&sp
->max_val
);
103 /* Load current value from hardware to the shadow register. */
104 u32
host1x_syncpt_load(struct host1x_syncpt
*sp
);
106 /* Check if the given syncpoint value has already passed */
107 bool host1x_syncpt_is_expired(struct host1x_syncpt
*sp
, u32 thresh
);
109 /* Save host1x sync point state into shadow registers. */
110 void host1x_syncpt_save(struct host1x
*host
);
112 /* Reset host1x sync point state from shadow registers. */
113 void host1x_syncpt_restore(struct host1x
*host
);
115 /* Read current wait base value into shadow register and return it. */
116 u32
host1x_syncpt_load_wait_base(struct host1x_syncpt
*sp
);
118 /* Indicate future operations by incrementing the sync point max. */
119 u32
host1x_syncpt_incr_max(struct host1x_syncpt
*sp
, u32 incrs
);
121 /* Check if sync point id is valid. */
122 static inline int host1x_syncpt_is_valid(struct host1x_syncpt
*sp
)
124 return sp
->id
< host1x_syncpt_nb_pts(sp
->host
);
127 /* Patch a wait by replacing it with a wait for syncpt 0 value 0 */
128 int host1x_syncpt_patch_wait(struct host1x_syncpt
*sp
, void *patch_addr
);