blob: 17c1616de100b47853b3750ad8760eedad91f812 [file] [log] [blame]
Terje Bergstrom75471682013-03-22 16:34:01 +02001/*
2 * Tegra host1x Syncpoints
3 *
4 * Copyright (c) 2010-2013, NVIDIA Corporation.
5 *
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.
9 *
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.
14 *
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/>.
17 */
18
19#ifndef __HOST1X_SYNCPT_H
20#define __HOST1X_SYNCPT_H
21
22#include <linux/atomic.h>
23#include <linux/kernel.h>
24#include <linux/sched.h>
25
Terje Bergstrom7ede0b02013-03-22 16:34:02 +020026#include "intr.h"
27
Terje Bergstrom75471682013-03-22 16:34:01 +020028struct host1x;
29
30struct host1x_syncpt {
31 int id;
32 atomic_t min_val;
33 atomic_t max_val;
34 u32 base_val;
35 const char *name;
36 int client_managed;
37 struct host1x *host;
38 struct device *dev;
Terje Bergstrom7ede0b02013-03-22 16:34:02 +020039
40 /* interrupt data */
41 struct host1x_syncpt_intr intr;
Terje Bergstrom75471682013-03-22 16:34:01 +020042};
43
44/* Initialize sync point array */
45int host1x_syncpt_init(struct host1x *host);
46
47/* Free sync point array */
48void host1x_syncpt_deinit(struct host1x *host);
49
50/*
51 * Read max. It indicates how many operations there are in queue, either in
52 * channel or in a software thread.
53 * */
54static inline u32 host1x_syncpt_read_max(struct host1x_syncpt *sp)
55{
56 smp_rmb();
57 return (u32)atomic_read(&sp->max_val);
58}
59
60/*
61 * Read min, which is a shadow of the current sync point value in hardware.
62 */
63static inline u32 host1x_syncpt_read_min(struct host1x_syncpt *sp)
64{
65 smp_rmb();
66 return (u32)atomic_read(&sp->min_val);
67}
68
69/* Return number of sync point supported. */
70int host1x_syncpt_nb_pts(struct host1x *host);
71
72/* Return number of wait bases supported. */
73int host1x_syncpt_nb_bases(struct host1x *host);
74
75/* Return number of mlocks supported. */
76int host1x_syncpt_nb_mlocks(struct host1x *host);
77
78/*
79 * Check sync point sanity. If max is larger than min, there have too many
80 * sync point increments.
81 *
82 * Client managed sync point are not tracked.
83 * */
84static inline bool host1x_syncpt_check_max(struct host1x_syncpt *sp, u32 real)
85{
86 u32 max;
87 if (sp->client_managed)
88 return true;
89 max = host1x_syncpt_read_max(sp);
90 return (s32)(max - real) >= 0;
91}
92
93/* Return true if sync point is client managed. */
94static inline int host1x_syncpt_client_managed(struct host1x_syncpt *sp)
95{
96 return sp->client_managed;
97}
98
99/*
100 * Returns true if syncpoint min == max, which means that there are no
101 * outstanding operations.
102 */
103static inline bool host1x_syncpt_idle(struct host1x_syncpt *sp)
104{
105 int min, max;
106 smp_rmb();
107 min = atomic_read(&sp->min_val);
108 max = atomic_read(&sp->max_val);
109 return (min == max);
110}
111
112/* Return pointer to struct denoting sync point id. */
113struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
114
115/* Request incrementing a sync point. */
116void host1x_syncpt_cpu_incr(struct host1x_syncpt *sp);
117
118/* Load current value from hardware to the shadow register. */
119u32 host1x_syncpt_load(struct host1x_syncpt *sp);
120
Terje Bergstrom7ede0b02013-03-22 16:34:02 +0200121/* Check if the given syncpoint value has already passed */
122bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
123
Terje Bergstrom75471682013-03-22 16:34:01 +0200124/* Save host1x sync point state into shadow registers. */
125void host1x_syncpt_save(struct host1x *host);
126
127/* Reset host1x sync point state from shadow registers. */
128void host1x_syncpt_restore(struct host1x *host);
129
130/* Read current wait base value into shadow register and return it. */
131u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp);
132
133/* Increment sync point and its max. */
134void host1x_syncpt_incr(struct host1x_syncpt *sp);
135
136/* Indicate future operations by incrementing the sync point max. */
137u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
138
Terje Bergstrom7ede0b02013-03-22 16:34:02 +0200139/* Wait until sync point reaches a threshold value, or a timeout. */
140int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh,
141 long timeout, u32 *value);
142
Terje Bergstrom75471682013-03-22 16:34:01 +0200143/* Check if sync point id is valid. */
144static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
145{
146 return sp->id < host1x_syncpt_nb_pts(sp->host);
147}
148
149/* Return id of the sync point */
150u32 host1x_syncpt_id(struct host1x_syncpt *sp);
151
152/* Allocate a sync point for a device. */
153struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
154 int client_managed);
155
156/* Free a sync point. */
157void host1x_syncpt_free(struct host1x_syncpt *sp);
158
159#endif