Commit | Line | Data |
---|---|---|
75471687 TB |
1 | /* |
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 | ||
6579324a | 23 | #include "channel.h" |
75471687 | 24 | #include "syncpt.h" |
7ede0b0b | 25 | #include "intr.h" |
6579324a TB |
26 | #include "cdma.h" |
27 | #include "job.h" | |
75471687 TB |
28 | |
29 | struct host1x_syncpt; | |
6579324a TB |
30 | struct host1x_channel; |
31 | struct host1x_cdma; | |
32 | struct host1x_job; | |
33 | struct push_buffer; | |
34 | ||
35 | struct 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 | ||
41 | struct 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 | ||
53 | struct host1x_pushbuffer_ops { | |
54 | void (*init)(struct push_buffer *pb); | |
55 | }; | |
75471687 TB |
56 | |
57 | struct 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 | ||
7ede0b0b TB |
66 | struct 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 | ||
75471687 TB |
77 | struct 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 | ||
86 | struct 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 | ||
7ede0b0b TB |
94 | struct mutex intr_mutex; |
95 | struct workqueue_struct *intr_wq; | |
96 | int intr_syncpt_irq; | |
97 | ||
75471687 | 98 | const struct host1x_syncpt_ops *syncpt_op; |
7ede0b0b | 99 | const struct host1x_intr_ops *intr_op; |
6579324a TB |
100 | const struct host1x_channel_ops *channel_op; |
101 | const struct host1x_cdma_ops *cdma_op; | |
102 | const struct host1x_pushbuffer_ops *cdma_pb_op; | |
7ede0b0b | 103 | |
6579324a TB |
104 | 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; | |
75471687 TB |
110 | }; |
111 | ||
112 | void host1x_sync_writel(struct host1x *host1x, u32 r, u32 v); | |
113 | u32 host1x_sync_readl(struct host1x *host1x, u32 r); | |
6579324a TB |
114 | void host1x_ch_writel(struct host1x_channel *ch, u32 r, u32 v); |
115 | u32 host1x_ch_readl(struct host1x_channel *ch, u32 r); | |
75471687 TB |
116 | |
117 | static inline void host1x_hw_syncpt_restore(struct host1x *host, | |
118 | struct host1x_syncpt *sp) | |
119 | { | |
120 | host->syncpt_op->restore(sp); | |
121 | } | |
122 | ||
123 | static 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 | ||
129 | static 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 | ||
135 | static inline u32 host1x_hw_syncpt_load(struct host1x *host, | |
136 | struct host1x_syncpt *sp) | |
137 | { | |
138 | return host->syncpt_op->load(sp); | |
139 | } | |
140 | ||
141 | static 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 | ||
147 | static 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 | ||
7ede0b0b TB |
154 | static 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 | ||
160 | static 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 | ||
166 | static 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 | ||
172 | static 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 | ||
178 | static inline void host1x_hw_intr_disable_all_syncpt_intrs(struct host1x *host) | |
179 | { | |
180 | host->intr_op->disable_all_syncpt_intrs(host); | |
181 | } | |
182 | ||
183 | static inline int host1x_hw_intr_free_syncpt_irq(struct host1x *host) | |
184 | { | |
185 | return host->intr_op->free_syncpt_irq(host); | |
186 | } | |
6579324a TB |
187 | |
188 | static 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 | ||
195 | static inline int host1x_hw_channel_submit(struct host1x *host, | |
196 | struct host1x_job *job) | |
197 | { | |
198 | return host->channel_op->submit(job); | |
199 | } | |
200 | ||
201 | static inline void host1x_hw_cdma_start(struct host1x *host, | |
202 | struct host1x_cdma *cdma) | |
203 | { | |
204 | host->cdma_op->start(cdma); | |
205 | } | |
206 | ||
207 | static inline void host1x_hw_cdma_stop(struct host1x *host, | |
208 | struct host1x_cdma *cdma) | |
209 | { | |
210 | host->cdma_op->stop(cdma); | |
211 | } | |
212 | ||
213 | static inline void host1x_hw_cdma_flush(struct host1x *host, | |
214 | struct host1x_cdma *cdma) | |
215 | { | |
216 | host->cdma_op->flush(cdma); | |
217 | } | |
218 | ||
219 | static 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 | ||
226 | static 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 | ||
232 | static inline void host1x_hw_cdma_freeze(struct host1x *host, | |
233 | struct host1x_cdma *cdma) | |
234 | { | |
235 | host->cdma_op->freeze(cdma); | |
236 | } | |
237 | ||
238 | static 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 | ||
244 | static 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 | ||
254 | static inline void host1x_hw_pushbuffer_init(struct host1x *host, | |
255 | struct push_buffer *pb) | |
256 | { | |
257 | host->cdma_pb_op->init(pb); | |
258 | } | |
259 | ||
75471687 | 260 | #endif |