1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef __LINUX_HOST1X_H
20#define __LINUX_HOST1X_H
21
22#include <linux/device.h>
23#include <linux/types.h>
24
25enum host1x_class {
26 HOST1X_CLASS_HOST1X = 0x1,
27 HOST1X_CLASS_GR2D = 0x51,
28 HOST1X_CLASS_GR2D_SB = 0x52,
29 HOST1X_CLASS_VIC = 0x5D,
30 HOST1X_CLASS_GR3D = 0x60,
31};
32
33struct host1x_client;
34
35
36
37
38
39
40struct host1x_client_ops {
41 int (*init)(struct host1x_client *client);
42 int (*exit)(struct host1x_client *client);
43};
44
45
46
47
48
49
50
51
52
53
54
55
56struct host1x_client {
57 struct list_head list;
58 struct device *parent;
59 struct device *dev;
60
61 const struct host1x_client_ops *ops;
62
63 enum host1x_class class;
64 struct host1x_channel *channel;
65
66 struct host1x_syncpt **syncpts;
67 unsigned int num_syncpts;
68};
69
70
71
72
73
74struct host1x_bo;
75struct sg_table;
76
77struct host1x_bo_ops {
78 struct host1x_bo *(*get)(struct host1x_bo *bo);
79 void (*put)(struct host1x_bo *bo);
80 dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt);
81 void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt);
82 void *(*mmap)(struct host1x_bo *bo);
83 void (*munmap)(struct host1x_bo *bo, void *addr);
84 void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum);
85 void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr);
86};
87
88struct host1x_bo {
89 const struct host1x_bo_ops *ops;
90};
91
92static inline void host1x_bo_init(struct host1x_bo *bo,
93 const struct host1x_bo_ops *ops)
94{
95 bo->ops = ops;
96}
97
98static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
99{
100 return bo->ops->get(bo);
101}
102
103static inline void host1x_bo_put(struct host1x_bo *bo)
104{
105 bo->ops->put(bo);
106}
107
108static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo,
109 struct sg_table **sgt)
110{
111 return bo->ops->pin(bo, sgt);
112}
113
114static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt)
115{
116 bo->ops->unpin(bo, sgt);
117}
118
119static inline void *host1x_bo_mmap(struct host1x_bo *bo)
120{
121 return bo->ops->mmap(bo);
122}
123
124static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
125{
126 bo->ops->munmap(bo, addr);
127}
128
129static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
130{
131 return bo->ops->kmap(bo, pagenum);
132}
133
134static inline void host1x_bo_kunmap(struct host1x_bo *bo,
135 unsigned int pagenum, void *addr)
136{
137 bo->ops->kunmap(bo, pagenum, addr);
138}
139
140
141
142
143
144#define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
145#define HOST1X_SYNCPT_HAS_BASE (1 << 1)
146
147struct host1x_syncpt_base;
148struct host1x_syncpt;
149struct host1x;
150
151struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
152u32 host1x_syncpt_id(struct host1x_syncpt *sp);
153u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
154u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
155u32 host1x_syncpt_read(struct host1x_syncpt *sp);
156int host1x_syncpt_incr(struct host1x_syncpt *sp);
157u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
158int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
159 u32 *value);
160struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
161 unsigned long flags);
162void host1x_syncpt_free(struct host1x_syncpt *sp);
163
164struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
165u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
166
167
168
169
170
171struct host1x_channel;
172struct host1x_job;
173
174struct host1x_channel *host1x_channel_request(struct device *dev);
175struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
176void host1x_channel_put(struct host1x_channel *channel);
177int host1x_job_submit(struct host1x_job *job);
178
179
180
181
182
183struct host1x_reloc {
184 struct {
185 struct host1x_bo *bo;
186 unsigned long offset;
187 } cmdbuf;
188 struct {
189 struct host1x_bo *bo;
190 unsigned long offset;
191 } target;
192 unsigned long shift;
193};
194
195struct host1x_waitchk {
196 struct host1x_bo *bo;
197 u32 offset;
198 u32 syncpt_id;
199 u32 thresh;
200};
201
202struct host1x_job {
203
204 struct kref ref;
205
206
207 struct list_head list;
208
209
210 struct host1x_channel *channel;
211
212 u32 client;
213
214
215 struct host1x_job_gather *gathers;
216 unsigned int num_gathers;
217
218
219 struct host1x_waitchk *waitchk;
220 unsigned int num_waitchk;
221 u32 waitchk_mask;
222
223
224 struct host1x_reloc *relocarray;
225 unsigned int num_relocs;
226 struct host1x_job_unpin_data *unpins;
227 unsigned int num_unpins;
228
229 dma_addr_t *addr_phys;
230 dma_addr_t *gather_addr_phys;
231 dma_addr_t *reloc_addr_phys;
232
233
234 u32 syncpt_id;
235 u32 syncpt_incrs;
236 u32 syncpt_end;
237
238
239 unsigned int timeout;
240
241
242 unsigned int first_get;
243 unsigned int num_slots;
244
245
246 size_t gather_copy_size;
247 dma_addr_t gather_copy;
248 u8 *gather_copy_mapped;
249
250
251 int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
252
253
254 int (*is_valid_class)(u32 class);
255
256
257 u32 class;
258
259
260 bool serialize;
261};
262
263struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
264 u32 num_cmdbufs, u32 num_relocs,
265 u32 num_waitchks);
266void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id,
267 u32 words, u32 offset);
268struct host1x_job *host1x_job_get(struct host1x_job *job);
269void host1x_job_put(struct host1x_job *job);
270int host1x_job_pin(struct host1x_job *job, struct device *dev);
271void host1x_job_unpin(struct host1x_job *job);
272
273
274
275
276
277struct host1x_device;
278
279
280
281
282
283
284
285
286
287
288struct host1x_driver {
289 struct device_driver driver;
290
291 const struct of_device_id *subdevs;
292 struct list_head list;
293
294 int (*probe)(struct host1x_device *device);
295 int (*remove)(struct host1x_device *device);
296 void (*shutdown)(struct host1x_device *device);
297};
298
299static inline struct host1x_driver *
300to_host1x_driver(struct device_driver *driver)
301{
302 return container_of(driver, struct host1x_driver, driver);
303}
304
305int host1x_driver_register_full(struct host1x_driver *driver,
306 struct module *owner);
307void host1x_driver_unregister(struct host1x_driver *driver);
308
309#define host1x_driver_register(driver) \
310 host1x_driver_register_full(driver, THIS_MODULE)
311
312struct host1x_device {
313 struct host1x_driver *driver;
314 struct list_head list;
315 struct device dev;
316
317 struct mutex subdevs_lock;
318 struct list_head subdevs;
319 struct list_head active;
320
321 struct mutex clients_lock;
322 struct list_head clients;
323
324 bool registered;
325};
326
327static inline struct host1x_device *to_host1x_device(struct device *dev)
328{
329 return container_of(dev, struct host1x_device, dev);
330}
331
332int host1x_device_init(struct host1x_device *device);
333int host1x_device_exit(struct host1x_device *device);
334
335int host1x_client_register(struct host1x_client *client);
336int host1x_client_unregister(struct host1x_client *client);
337
338struct tegra_mipi_device;
339
340struct tegra_mipi_device *tegra_mipi_request(struct device *device);
341void tegra_mipi_free(struct tegra_mipi_device *device);
342int tegra_mipi_enable(struct tegra_mipi_device *device);
343int tegra_mipi_disable(struct tegra_mipi_device *device);
344int tegra_mipi_calibrate(struct tegra_mipi_device *device);
345
346#endif
347