1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Tegra host1x Syncpoints
5 * Copyright (c) 2010-2013, NVIDIA Corporation.
8 #ifndef __HOST1X_SYNCPT_H
9 #define __HOST1X_SYNCPT_H
11 #include <linux/atomic.h>
12 #include <linux/host1x.h>
13 #include <linux/kernel.h>
14 #include <linux/kref.h>
15 #include <linux/sched.h>
21 /* Reserved for replacing an expired wait with a NOP */
22 #define HOST1X_SYNCPT_RESERVED 0
24 struct host1x_syncpt_base {
29 struct host1x_syncpt {
39 struct host1x_syncpt_base *base;
42 struct host1x_syncpt_intr intr;
45 /* Initialize sync point array */
46 int host1x_syncpt_init(struct host1x *host);
48 /* Free sync point array */
49 void host1x_syncpt_deinit(struct host1x *host);
51 /* Return number of sync point supported. */
52 unsigned int host1x_syncpt_nb_pts(struct host1x *host);
54 /* Return number of wait bases supported. */
55 unsigned int host1x_syncpt_nb_bases(struct host1x *host);
57 /* Return number of mlocks supported. */
58 unsigned int host1x_syncpt_nb_mlocks(struct host1x *host);
61 * Check sync point sanity. If max is larger than min, there have too many
62 * sync point increments.
64 * Client managed sync point are not tracked.
66 static inline bool host1x_syncpt_check_max(struct host1x_syncpt *sp, u32 real)
69 if (sp->client_managed)
71 max = host1x_syncpt_read_max(sp);
72 return (s32)(max - real) >= 0;
75 /* Return true if sync point is client managed. */
76 static inline bool host1x_syncpt_client_managed(struct host1x_syncpt *sp)
78 return sp->client_managed;
82 * Returns true if syncpoint min == max, which means that there are no
83 * outstanding operations.
85 static inline bool host1x_syncpt_idle(struct host1x_syncpt *sp)
89 min = atomic_read(&sp->min_val);
90 max = atomic_read(&sp->max_val);
94 /* Load current value from hardware to the shadow register. */
95 u32 host1x_syncpt_load(struct host1x_syncpt *sp);
97 /* Check if the given syncpoint value has already passed */
98 bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
100 /* Save host1x sync point state into shadow registers. */
101 void host1x_syncpt_save(struct host1x *host);
103 /* Reset host1x sync point state from shadow registers. */
104 void host1x_syncpt_restore(struct host1x *host);
106 /* Read current wait base value into shadow register and return it. */
107 u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp);
109 /* Indicate future operations by incrementing the sync point max. */
110 u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
112 /* Check if sync point id is valid. */
113 static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
115 return sp->id < host1x_syncpt_nb_pts(sp->host);