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