1
2
3
4
5
6#ifndef __LINUX_HOST1X_H
7#define __LINUX_HOST1X_H
8
9#include <linux/device.h>
10#include <linux/dma-direction.h>
11#include <linux/spinlock.h>
12#include <linux/types.h>
13
14enum host1x_class {
15 HOST1X_CLASS_HOST1X = 0x1,
16 HOST1X_CLASS_GR2D = 0x51,
17 HOST1X_CLASS_GR2D_SB = 0x52,
18 HOST1X_CLASS_VIC = 0x5D,
19 HOST1X_CLASS_GR3D = 0x60,
20 HOST1X_CLASS_NVDEC = 0xF0,
21 HOST1X_CLASS_NVDEC1 = 0xF5,
22};
23
24struct host1x;
25struct host1x_client;
26struct iommu_group;
27
28u64 host1x_get_dma_mask(struct host1x *host1x);
29
30
31
32
33
34
35struct host1x_bo_cache {
36 struct list_head mappings;
37 struct mutex lock;
38};
39
40static inline void host1x_bo_cache_init(struct host1x_bo_cache *cache)
41{
42 INIT_LIST_HEAD(&cache->mappings);
43 mutex_init(&cache->lock);
44}
45
46static inline void host1x_bo_cache_destroy(struct host1x_bo_cache *cache)
47{
48
49 mutex_destroy(&cache->lock);
50}
51
52
53
54
55
56
57
58
59
60
61struct host1x_client_ops {
62 int (*early_init)(struct host1x_client *client);
63 int (*init)(struct host1x_client *client);
64 int (*exit)(struct host1x_client *client);
65 int (*late_exit)(struct host1x_client *client);
66 int (*suspend)(struct host1x_client *client);
67 int (*resume)(struct host1x_client *client);
68};
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85struct host1x_client {
86 struct list_head list;
87 struct device *host;
88 struct device *dev;
89 struct iommu_group *group;
90
91 const struct host1x_client_ops *ops;
92
93 enum host1x_class class;
94 struct host1x_channel *channel;
95
96 struct host1x_syncpt **syncpts;
97 unsigned int num_syncpts;
98
99 struct host1x_client *parent;
100 unsigned int usecount;
101 struct mutex lock;
102
103 struct host1x_bo_cache cache;
104};
105
106
107
108
109
110struct host1x_bo;
111struct sg_table;
112
113struct host1x_bo_mapping {
114 struct kref ref;
115 struct dma_buf_attachment *attach;
116 enum dma_data_direction direction;
117 struct list_head list;
118 struct host1x_bo *bo;
119 struct sg_table *sgt;
120 unsigned int chunks;
121 struct device *dev;
122 dma_addr_t phys;
123 size_t size;
124
125 struct host1x_bo_cache *cache;
126 struct list_head entry;
127};
128
129static inline struct host1x_bo_mapping *to_host1x_bo_mapping(struct kref *ref)
130{
131 return container_of(ref, struct host1x_bo_mapping, ref);
132}
133
134struct host1x_bo_ops {
135 struct host1x_bo *(*get)(struct host1x_bo *bo);
136 void (*put)(struct host1x_bo *bo);
137 struct host1x_bo_mapping *(*pin)(struct device *dev, struct host1x_bo *bo,
138 enum dma_data_direction dir);
139 void (*unpin)(struct host1x_bo_mapping *map);
140 void *(*mmap)(struct host1x_bo *bo);
141 void (*munmap)(struct host1x_bo *bo, void *addr);
142};
143
144struct host1x_bo {
145 const struct host1x_bo_ops *ops;
146 struct list_head mappings;
147 spinlock_t lock;
148};
149
150static inline void host1x_bo_init(struct host1x_bo *bo,
151 const struct host1x_bo_ops *ops)
152{
153 INIT_LIST_HEAD(&bo->mappings);
154 spin_lock_init(&bo->lock);
155 bo->ops = ops;
156}
157
158static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
159{
160 return bo->ops->get(bo);
161}
162
163static inline void host1x_bo_put(struct host1x_bo *bo)
164{
165 bo->ops->put(bo);
166}
167
168struct host1x_bo_mapping *host1x_bo_pin(struct device *dev, struct host1x_bo *bo,
169 enum dma_data_direction dir,
170 struct host1x_bo_cache *cache);
171void host1x_bo_unpin(struct host1x_bo_mapping *map);
172
173static inline void *host1x_bo_mmap(struct host1x_bo *bo)
174{
175 return bo->ops->mmap(bo);
176}
177
178static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
179{
180 bo->ops->munmap(bo, addr);
181}
182
183
184
185
186
187#define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
188#define HOST1X_SYNCPT_HAS_BASE (1 << 1)
189
190struct host1x_syncpt_base;
191struct host1x_syncpt;
192struct host1x;
193
194struct host1x_syncpt *host1x_syncpt_get_by_id(struct host1x *host, u32 id);
195struct host1x_syncpt *host1x_syncpt_get_by_id_noref(struct host1x *host, u32 id);
196struct host1x_syncpt *host1x_syncpt_get(struct host1x_syncpt *sp);
197u32 host1x_syncpt_id(struct host1x_syncpt *sp);
198u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
199u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
200u32 host1x_syncpt_read(struct host1x_syncpt *sp);
201int host1x_syncpt_incr(struct host1x_syncpt *sp);
202u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
203int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
204 u32 *value);
205struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
206 unsigned long flags);
207void host1x_syncpt_put(struct host1x_syncpt *sp);
208struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,
209 unsigned long flags,
210 const char *name);
211
212struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
213u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
214
215void host1x_syncpt_release_vblank_reservation(struct host1x_client *client,
216 u32 syncpt_id);
217
218struct dma_fence *host1x_fence_create(struct host1x_syncpt *sp, u32 threshold);
219
220
221
222
223
224struct host1x_channel;
225struct host1x_job;
226
227struct host1x_channel *host1x_channel_request(struct host1x_client *client);
228struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
229void host1x_channel_stop(struct host1x_channel *channel);
230void host1x_channel_put(struct host1x_channel *channel);
231int host1x_job_submit(struct host1x_job *job);
232
233
234
235
236
237#define HOST1X_RELOC_READ (1 << 0)
238#define HOST1X_RELOC_WRITE (1 << 1)
239
240struct host1x_reloc {
241 struct {
242 struct host1x_bo *bo;
243 unsigned long offset;
244 } cmdbuf;
245 struct {
246 struct host1x_bo *bo;
247 unsigned long offset;
248 } target;
249 unsigned long shift;
250 unsigned long flags;
251};
252
253struct host1x_job {
254
255 struct kref ref;
256
257
258 struct list_head list;
259
260
261 struct host1x_channel *channel;
262
263
264 struct host1x_client *client;
265
266
267 struct host1x_job_cmd *cmds;
268 unsigned int num_cmds;
269
270
271 struct host1x_reloc *relocs;
272 unsigned int num_relocs;
273 struct host1x_job_unpin_data *unpins;
274 unsigned int num_unpins;
275
276 dma_addr_t *addr_phys;
277 dma_addr_t *gather_addr_phys;
278 dma_addr_t *reloc_addr_phys;
279
280
281 struct host1x_syncpt *syncpt;
282 u32 syncpt_incrs;
283 u32 syncpt_end;
284
285
286 void *waiter;
287
288
289 unsigned int timeout;
290
291
292 bool cancelled;
293
294
295 unsigned int first_get;
296 unsigned int num_slots;
297
298
299 size_t gather_copy_size;
300 dma_addr_t gather_copy;
301 u8 *gather_copy_mapped;
302
303
304 int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
305
306
307 int (*is_valid_class)(u32 class);
308
309
310 u32 class;
311
312
313 bool serialize;
314
315
316 bool syncpt_recovery;
317
318
319 void (*release)(struct host1x_job *job);
320 void *user_data;
321
322
323 bool enable_firewall;
324};
325
326struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
327 u32 num_cmdbufs, u32 num_relocs,
328 bool skip_firewall);
329void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo,
330 unsigned int words, unsigned int offset);
331void host1x_job_add_wait(struct host1x_job *job, u32 id, u32 thresh,
332 bool relative, u32 next_class);
333struct host1x_job *host1x_job_get(struct host1x_job *job);
334void host1x_job_put(struct host1x_job *job);
335int host1x_job_pin(struct host1x_job *job, struct device *dev);
336void host1x_job_unpin(struct host1x_job *job);
337
338
339
340
341
342struct host1x_device;
343
344
345
346
347
348
349
350
351
352
353struct host1x_driver {
354 struct device_driver driver;
355
356 const struct of_device_id *subdevs;
357 struct list_head list;
358
359 int (*probe)(struct host1x_device *device);
360 int (*remove)(struct host1x_device *device);
361 void (*shutdown)(struct host1x_device *device);
362};
363
364static inline struct host1x_driver *
365to_host1x_driver(struct device_driver *driver)
366{
367 return container_of(driver, struct host1x_driver, driver);
368}
369
370int host1x_driver_register_full(struct host1x_driver *driver,
371 struct module *owner);
372void host1x_driver_unregister(struct host1x_driver *driver);
373
374#define host1x_driver_register(driver) \
375 host1x_driver_register_full(driver, THIS_MODULE)
376
377struct host1x_device {
378 struct host1x_driver *driver;
379 struct list_head list;
380 struct device dev;
381
382 struct mutex subdevs_lock;
383 struct list_head subdevs;
384 struct list_head active;
385
386 struct mutex clients_lock;
387 struct list_head clients;
388
389 bool registered;
390
391 struct device_dma_parameters dma_parms;
392};
393
394static inline struct host1x_device *to_host1x_device(struct device *dev)
395{
396 return container_of(dev, struct host1x_device, dev);
397}
398
399int host1x_device_init(struct host1x_device *device);
400int host1x_device_exit(struct host1x_device *device);
401
402void __host1x_client_init(struct host1x_client *client, struct lock_class_key *key);
403void host1x_client_exit(struct host1x_client *client);
404
405#define host1x_client_init(client) \
406 ({ \
407 static struct lock_class_key __key; \
408 __host1x_client_init(client, &__key); \
409 })
410
411int __host1x_client_register(struct host1x_client *client);
412
413
414
415
416
417
418
419
420
421#define host1x_client_register(client) \
422 ({ \
423 static struct lock_class_key __key; \
424 __host1x_client_init(client, &__key); \
425 __host1x_client_register(client); \
426 })
427
428int host1x_client_unregister(struct host1x_client *client);
429
430int host1x_client_suspend(struct host1x_client *client);
431int host1x_client_resume(struct host1x_client *client);
432
433struct tegra_mipi_device;
434
435struct tegra_mipi_device *tegra_mipi_request(struct device *device,
436 struct device_node *np);
437void tegra_mipi_free(struct tegra_mipi_device *device);
438int tegra_mipi_enable(struct tegra_mipi_device *device);
439int tegra_mipi_disable(struct tegra_mipi_device *device);
440int tegra_mipi_start_calibration(struct tegra_mipi_device *device);
441int tegra_mipi_finish_calibration(struct tegra_mipi_device *device);
442
443#endif
444