blob: 1a9b4383dc3bc60def4b4fb8fcf3e6c5061ed536 [file] [log] [blame]
Terje Bergstrom75471682013-03-22 16:34:01 +02001/*
2 * Copyright (c) 2012-2013, NVIDIA Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef HOST1X_DEV_H
18#define HOST1X_DEV_H
19
20#include <linux/platform_device.h>
21#include <linux/device.h>
22
Terje Bergstrom65793242013-03-22 16:34:03 +020023#include "channel.h"
Terje Bergstrom75471682013-03-22 16:34:01 +020024#include "syncpt.h"
Terje Bergstrom7ede0b02013-03-22 16:34:02 +020025#include "intr.h"
Terje Bergstrom65793242013-03-22 16:34:03 +020026#include "cdma.h"
27#include "job.h"
Terje Bergstrom75471682013-03-22 16:34:01 +020028
29struct host1x_syncpt;
Terje Bergstrom65793242013-03-22 16:34:03 +020030struct host1x_channel;
31struct host1x_cdma;
32struct host1x_job;
33struct push_buffer;
34
35struct host1x_channel_ops {
36 int (*init)(struct host1x_channel *channel, struct host1x *host,
37 unsigned int id);
38 int (*submit)(struct host1x_job *job);
39};
40
41struct host1x_cdma_ops {
42 void (*start)(struct host1x_cdma *cdma);
43 void (*stop)(struct host1x_cdma *cdma);
44 void (*flush)(struct host1x_cdma *cdma);
45 int (*timeout_init)(struct host1x_cdma *cdma, u32 syncpt_id);
46 void (*timeout_destroy)(struct host1x_cdma *cdma);
47 void (*freeze)(struct host1x_cdma *cdma);
48 void (*resume)(struct host1x_cdma *cdma, u32 getptr);
49 void (*timeout_cpu_incr)(struct host1x_cdma *cdma, u32 getptr,
50 u32 syncpt_incrs, u32 syncval, u32 nr_slots);
51};
52
53struct host1x_pushbuffer_ops {
54 void (*init)(struct push_buffer *pb);
55};
Terje Bergstrom75471682013-03-22 16:34:01 +020056
57struct host1x_syncpt_ops {
58 void (*restore)(struct host1x_syncpt *syncpt);
59 void (*restore_wait_base)(struct host1x_syncpt *syncpt);
60 void (*load_wait_base)(struct host1x_syncpt *syncpt);
61 u32 (*load)(struct host1x_syncpt *syncpt);
62 void (*cpu_incr)(struct host1x_syncpt *syncpt);
63 int (*patch_wait)(struct host1x_syncpt *syncpt, void *patch_addr);
64};
65
Terje Bergstrom7ede0b02013-03-22 16:34:02 +020066struct host1x_intr_ops {
67 int (*init_host_sync)(struct host1x *host, u32 cpm,
68 void (*syncpt_thresh_work)(struct work_struct *work));
69 void (*set_syncpt_threshold)(
70 struct host1x *host, u32 id, u32 thresh);
71 void (*enable_syncpt_intr)(struct host1x *host, u32 id);
72 void (*disable_syncpt_intr)(struct host1x *host, u32 id);
73 void (*disable_all_syncpt_intrs)(struct host1x *host);
74 int (*free_syncpt_irq)(struct host1x *host);
75};
76
Terje Bergstrom75471682013-03-22 16:34:01 +020077struct host1x_info {
78 int nb_channels; /* host1x: num channels supported */
79 int nb_pts; /* host1x: num syncpoints supported */
80 int nb_bases; /* host1x: num syncpoints supported */
81 int nb_mlocks; /* host1x: number of mlocks */
82 int (*init)(struct host1x *); /* initialize per SoC ops */
83 int sync_offset;
84};
85
86struct host1x {
87 const struct host1x_info *info;
88
89 void __iomem *regs;
90 struct host1x_syncpt *syncpt;
91 struct device *dev;
92 struct clk *clk;
93
Terje Bergstrom7ede0b02013-03-22 16:34:02 +020094 struct mutex intr_mutex;
95 struct workqueue_struct *intr_wq;
96 int intr_syncpt_irq;
97
Terje Bergstrom75471682013-03-22 16:34:01 +020098 const struct host1x_syncpt_ops *syncpt_op;
Terje Bergstrom7ede0b02013-03-22 16:34:02 +020099 const struct host1x_intr_ops *intr_op;
Terje Bergstrom65793242013-03-22 16:34:03 +0200100 const struct host1x_channel_ops *channel_op;
101 const struct host1x_cdma_ops *cdma_op;
102 const struct host1x_pushbuffer_ops *cdma_pb_op;
Terje Bergstrom7ede0b02013-03-22 16:34:02 +0200103
Terje Bergstrom65793242013-03-22 16:34:03 +0200104 struct host1x_syncpt *nop_sp;
105
106 struct mutex chlist_mutex;
107 struct host1x_channel chlist;
108 unsigned long allocated_channels;
109 unsigned int num_allocated_channels;
Terje Bergstrom75471682013-03-22 16:34:01 +0200110};
111
112void host1x_sync_writel(struct host1x *host1x, u32 r, u32 v);
113u32 host1x_sync_readl(struct host1x *host1x, u32 r);
Terje Bergstrom65793242013-03-22 16:34:03 +0200114void host1x_ch_writel(struct host1x_channel *ch, u32 r, u32 v);
115u32 host1x_ch_readl(struct host1x_channel *ch, u32 r);
Terje Bergstrom75471682013-03-22 16:34:01 +0200116
117static inline void host1x_hw_syncpt_restore(struct host1x *host,
118 struct host1x_syncpt *sp)
119{
120 host->syncpt_op->restore(sp);
121}
122
123static inline void host1x_hw_syncpt_restore_wait_base(struct host1x *host,
124 struct host1x_syncpt *sp)
125{
126 host->syncpt_op->restore_wait_base(sp);
127}
128
129static inline void host1x_hw_syncpt_load_wait_base(struct host1x *host,
130 struct host1x_syncpt *sp)
131{
132 host->syncpt_op->load_wait_base(sp);
133}
134
135static inline u32 host1x_hw_syncpt_load(struct host1x *host,
136 struct host1x_syncpt *sp)
137{
138 return host->syncpt_op->load(sp);
139}
140
141static inline void host1x_hw_syncpt_cpu_incr(struct host1x *host,
142 struct host1x_syncpt *sp)
143{
144 host->syncpt_op->cpu_incr(sp);
145}
146
147static inline int host1x_hw_syncpt_patch_wait(struct host1x *host,
148 struct host1x_syncpt *sp,
149 void *patch_addr)
150{
151 return host->syncpt_op->patch_wait(sp, patch_addr);
152}
153
Terje Bergstrom7ede0b02013-03-22 16:34:02 +0200154static inline int host1x_hw_intr_init_host_sync(struct host1x *host, u32 cpm,
155 void (*syncpt_thresh_work)(struct work_struct *))
156{
157 return host->intr_op->init_host_sync(host, cpm, syncpt_thresh_work);
158}
159
160static inline void host1x_hw_intr_set_syncpt_threshold(struct host1x *host,
161 u32 id, u32 thresh)
162{
163 host->intr_op->set_syncpt_threshold(host, id, thresh);
164}
165
166static inline void host1x_hw_intr_enable_syncpt_intr(struct host1x *host,
167 u32 id)
168{
169 host->intr_op->enable_syncpt_intr(host, id);
170}
171
172static inline void host1x_hw_intr_disable_syncpt_intr(struct host1x *host,
173 u32 id)
174{
175 host->intr_op->disable_syncpt_intr(host, id);
176}
177
178static inline void host1x_hw_intr_disable_all_syncpt_intrs(struct host1x *host)
179{
180 host->intr_op->disable_all_syncpt_intrs(host);
181}
182
183static inline int host1x_hw_intr_free_syncpt_irq(struct host1x *host)
184{
185 return host->intr_op->free_syncpt_irq(host);
186}
Terje Bergstrom65793242013-03-22 16:34:03 +0200187
188static inline int host1x_hw_channel_init(struct host1x *host,
189 struct host1x_channel *channel,
190 int chid)
191{
192 return host->channel_op->init(channel, host, chid);
193}
194
195static inline int host1x_hw_channel_submit(struct host1x *host,
196 struct host1x_job *job)
197{
198 return host->channel_op->submit(job);
199}
200
201static inline void host1x_hw_cdma_start(struct host1x *host,
202 struct host1x_cdma *cdma)
203{
204 host->cdma_op->start(cdma);
205}
206
207static inline void host1x_hw_cdma_stop(struct host1x *host,
208 struct host1x_cdma *cdma)
209{
210 host->cdma_op->stop(cdma);
211}
212
213static inline void host1x_hw_cdma_flush(struct host1x *host,
214 struct host1x_cdma *cdma)
215{
216 host->cdma_op->flush(cdma);
217}
218
219static inline int host1x_hw_cdma_timeout_init(struct host1x *host,
220 struct host1x_cdma *cdma,
221 u32 syncpt_id)
222{
223 return host->cdma_op->timeout_init(cdma, syncpt_id);
224}
225
226static inline void host1x_hw_cdma_timeout_destroy(struct host1x *host,
227 struct host1x_cdma *cdma)
228{
229 host->cdma_op->timeout_destroy(cdma);
230}
231
232static inline void host1x_hw_cdma_freeze(struct host1x *host,
233 struct host1x_cdma *cdma)
234{
235 host->cdma_op->freeze(cdma);
236}
237
238static inline void host1x_hw_cdma_resume(struct host1x *host,
239 struct host1x_cdma *cdma, u32 getptr)
240{
241 host->cdma_op->resume(cdma, getptr);
242}
243
244static inline void host1x_hw_cdma_timeout_cpu_incr(struct host1x *host,
245 struct host1x_cdma *cdma,
246 u32 getptr,
247 u32 syncpt_incrs,
248 u32 syncval, u32 nr_slots)
249{
250 host->cdma_op->timeout_cpu_incr(cdma, getptr, syncpt_incrs, syncval,
251 nr_slots);
252}
253
254static inline void host1x_hw_pushbuffer_init(struct host1x *host,
255 struct push_buffer *pb)
256{
257 host->cdma_pb_op->init(pb);
258}
259
Terje Bergstrom75471682013-03-22 16:34:01 +0200260#endif