Commit | Line | Data |
---|---|---|
16216333 | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
6579324a | 2 | /* |
6579324a | 3 | * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved. |
6579324a TB |
4 | */ |
5 | ||
6 | #ifndef __LINUX_HOST1X_H | |
7 | #define __LINUX_HOST1X_H | |
8 | ||
776dc384 | 9 | #include <linux/device.h> |
35d747a8 TR |
10 | #include <linux/types.h> |
11 | ||
6579324a | 12 | enum host1x_class { |
e1e90644 TR |
13 | HOST1X_CLASS_HOST1X = 0x1, |
14 | HOST1X_CLASS_GR2D = 0x51, | |
15 | HOST1X_CLASS_GR2D_SB = 0x52, | |
0ae797a8 | 16 | HOST1X_CLASS_VIC = 0x5D, |
5f60ed0d | 17 | HOST1X_CLASS_GR3D = 0x60, |
6579324a TB |
18 | }; |
19 | ||
501be6c1 | 20 | struct host1x; |
53fa7f72 | 21 | struct host1x_client; |
aacdf198 | 22 | struct iommu_group; |
53fa7f72 | 23 | |
501be6c1 TR |
24 | u64 host1x_get_dma_mask(struct host1x *host1x); |
25 | ||
466749f1 TR |
26 | /** |
27 | * struct host1x_client_ops - host1x client operations | |
933deb8c | 28 | * @early_init: host1x client early initialization code |
466749f1 TR |
29 | * @init: host1x client initialization code |
30 | * @exit: host1x client tear down code | |
933deb8c | 31 | * @late_exit: host1x client late tear down code |
fd67e9c6 TR |
32 | * @suspend: host1x client suspend code |
33 | * @resume: host1x client resume code | |
466749f1 | 34 | */ |
53fa7f72 | 35 | struct host1x_client_ops { |
933deb8c | 36 | int (*early_init)(struct host1x_client *client); |
53fa7f72 TR |
37 | int (*init)(struct host1x_client *client); |
38 | int (*exit)(struct host1x_client *client); | |
933deb8c | 39 | int (*late_exit)(struct host1x_client *client); |
fd67e9c6 TR |
40 | int (*suspend)(struct host1x_client *client); |
41 | int (*resume)(struct host1x_client *client); | |
53fa7f72 TR |
42 | }; |
43 | ||
466749f1 TR |
44 | /** |
45 | * struct host1x_client - host1x client structure | |
46 | * @list: list node for the host1x client | |
608f43ad | 47 | * @host: pointer to struct device representing the host1x controller |
466749f1 | 48 | * @dev: pointer to struct device backing this host1x client |
aacdf198 | 49 | * @group: IOMMU group that this client is a member of |
466749f1 TR |
50 | * @ops: host1x client operations |
51 | * @class: host1x class represented by this client | |
52 | * @channel: host1x channel associated with this client | |
53 | * @syncpts: array of syncpoints requested for this client | |
54 | * @num_syncpts: number of syncpoints requested for this client | |
2fd2bc7f CL |
55 | * @parent: pointer to parent structure |
56 | * @usecount: reference count for this structure | |
57 | * @lock: mutex for mutually exclusive concurrency | |
466749f1 | 58 | */ |
53fa7f72 TR |
59 | struct host1x_client { |
60 | struct list_head list; | |
608f43ad | 61 | struct device *host; |
53fa7f72 | 62 | struct device *dev; |
aacdf198 | 63 | struct iommu_group *group; |
53fa7f72 TR |
64 | |
65 | const struct host1x_client_ops *ops; | |
66 | ||
67 | enum host1x_class class; | |
68 | struct host1x_channel *channel; | |
69 | ||
70 | struct host1x_syncpt **syncpts; | |
71 | unsigned int num_syncpts; | |
fd67e9c6 TR |
72 | |
73 | struct host1x_client *parent; | |
74 | unsigned int usecount; | |
75 | struct mutex lock; | |
53fa7f72 TR |
76 | }; |
77 | ||
35d747a8 TR |
78 | /* |
79 | * host1x buffer objects | |
80 | */ | |
81 | ||
82 | struct host1x_bo; | |
83 | struct sg_table; | |
84 | ||
85 | struct host1x_bo_ops { | |
86 | struct host1x_bo *(*get)(struct host1x_bo *bo); | |
87 | void (*put)(struct host1x_bo *bo); | |
80327ce3 TR |
88 | struct sg_table *(*pin)(struct device *dev, struct host1x_bo *bo, |
89 | dma_addr_t *phys); | |
90 | void (*unpin)(struct device *dev, struct sg_table *sgt); | |
35d747a8 TR |
91 | void *(*mmap)(struct host1x_bo *bo); |
92 | void (*munmap)(struct host1x_bo *bo, void *addr); | |
35d747a8 TR |
93 | }; |
94 | ||
95 | struct host1x_bo { | |
96 | const struct host1x_bo_ops *ops; | |
97 | }; | |
98 | ||
99 | static inline void host1x_bo_init(struct host1x_bo *bo, | |
100 | const struct host1x_bo_ops *ops) | |
101 | { | |
102 | bo->ops = ops; | |
103 | } | |
104 | ||
105 | static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo) | |
106 | { | |
107 | return bo->ops->get(bo); | |
108 | } | |
109 | ||
110 | static inline void host1x_bo_put(struct host1x_bo *bo) | |
111 | { | |
112 | bo->ops->put(bo); | |
113 | } | |
114 | ||
80327ce3 TR |
115 | static inline struct sg_table *host1x_bo_pin(struct device *dev, |
116 | struct host1x_bo *bo, | |
117 | dma_addr_t *phys) | |
35d747a8 | 118 | { |
80327ce3 | 119 | return bo->ops->pin(dev, bo, phys); |
35d747a8 TR |
120 | } |
121 | ||
80327ce3 TR |
122 | static inline void host1x_bo_unpin(struct device *dev, struct host1x_bo *bo, |
123 | struct sg_table *sgt) | |
35d747a8 | 124 | { |
80327ce3 | 125 | bo->ops->unpin(dev, sgt); |
35d747a8 TR |
126 | } |
127 | ||
128 | static inline void *host1x_bo_mmap(struct host1x_bo *bo) | |
129 | { | |
130 | return bo->ops->mmap(bo); | |
131 | } | |
132 | ||
133 | static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr) | |
134 | { | |
135 | bo->ops->munmap(bo, addr); | |
136 | } | |
137 | ||
35d747a8 TR |
138 | /* |
139 | * host1x syncpoints | |
140 | */ | |
141 | ||
8736fe81 | 142 | #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0) |
f5a954fe | 143 | #define HOST1X_SYNCPT_HAS_BASE (1 << 1) |
8736fe81 | 144 | |
f5a954fe | 145 | struct host1x_syncpt_base; |
35d747a8 TR |
146 | struct host1x_syncpt; |
147 | struct host1x; | |
148 | ||
2aed4f5a MP |
149 | struct host1x_syncpt *host1x_syncpt_get_by_id(struct host1x *host, u32 id); |
150 | struct host1x_syncpt *host1x_syncpt_get_by_id_noref(struct host1x *host, u32 id); | |
151 | struct host1x_syncpt *host1x_syncpt_get(struct host1x_syncpt *sp); | |
35d747a8 TR |
152 | u32 host1x_syncpt_id(struct host1x_syncpt *sp); |
153 | u32 host1x_syncpt_read_min(struct host1x_syncpt *sp); | |
154 | u32 host1x_syncpt_read_max(struct host1x_syncpt *sp); | |
b4a20144 | 155 | u32 host1x_syncpt_read(struct host1x_syncpt *sp); |
35d747a8 | 156 | int host1x_syncpt_incr(struct host1x_syncpt *sp); |
64400c37 | 157 | u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs); |
35d747a8 TR |
158 | int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout, |
159 | u32 *value); | |
617dd7cc | 160 | struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client, |
8736fe81 | 161 | unsigned long flags); |
2aed4f5a | 162 | void host1x_syncpt_put(struct host1x_syncpt *sp); |
86cec7ec MP |
163 | struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host, |
164 | unsigned long flags, | |
165 | const char *name); | |
35d747a8 | 166 | |
f5a954fe AM |
167 | struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp); |
168 | u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base); | |
169 | ||
f5ba33fb MP |
170 | void host1x_syncpt_release_vblank_reservation(struct host1x_client *client, |
171 | u32 syncpt_id); | |
172 | ||
35d747a8 TR |
173 | /* |
174 | * host1x channel | |
175 | */ | |
176 | ||
177 | struct host1x_channel; | |
178 | struct host1x_job; | |
179 | ||
caccddcf | 180 | struct host1x_channel *host1x_channel_request(struct host1x_client *client); |
35d747a8 TR |
181 | struct host1x_channel *host1x_channel_get(struct host1x_channel *channel); |
182 | void host1x_channel_put(struct host1x_channel *channel); | |
183 | int host1x_job_submit(struct host1x_job *job); | |
184 | ||
185 | /* | |
186 | * host1x job | |
187 | */ | |
188 | ||
ab4f81bf TR |
189 | #define HOST1X_RELOC_READ (1 << 0) |
190 | #define HOST1X_RELOC_WRITE (1 << 1) | |
191 | ||
35d747a8 | 192 | struct host1x_reloc { |
961e3bea TR |
193 | struct { |
194 | struct host1x_bo *bo; | |
195 | unsigned long offset; | |
196 | } cmdbuf; | |
197 | struct { | |
198 | struct host1x_bo *bo; | |
199 | unsigned long offset; | |
200 | } target; | |
201 | unsigned long shift; | |
ab4f81bf | 202 | unsigned long flags; |
35d747a8 TR |
203 | }; |
204 | ||
205 | struct host1x_job { | |
206 | /* When refcount goes to zero, job can be freed */ | |
207 | struct kref ref; | |
208 | ||
209 | /* List entry */ | |
210 | struct list_head list; | |
211 | ||
212 | /* Channel where job is submitted to */ | |
213 | struct host1x_channel *channel; | |
214 | ||
bf3d41cc TR |
215 | /* client where the job originated */ |
216 | struct host1x_client *client; | |
35d747a8 TR |
217 | |
218 | /* Gathers and their memory */ | |
219 | struct host1x_job_gather *gathers; | |
220 | unsigned int num_gathers; | |
221 | ||
35d747a8 | 222 | /* Array of handles to be pinned & unpinned */ |
06490bb9 | 223 | struct host1x_reloc *relocs; |
35d747a8 TR |
224 | unsigned int num_relocs; |
225 | struct host1x_job_unpin_data *unpins; | |
226 | unsigned int num_unpins; | |
227 | ||
228 | dma_addr_t *addr_phys; | |
229 | dma_addr_t *gather_addr_phys; | |
230 | dma_addr_t *reloc_addr_phys; | |
231 | ||
232 | /* Sync point id, number of increments and end related to the submit */ | |
2aed4f5a | 233 | struct host1x_syncpt *syncpt; |
35d747a8 TR |
234 | u32 syncpt_incrs; |
235 | u32 syncpt_end; | |
236 | ||
237 | /* Maximum time to wait for this job */ | |
238 | unsigned int timeout; | |
239 | ||
240 | /* Index and number of slots used in the push buffer */ | |
241 | unsigned int first_get; | |
242 | unsigned int num_slots; | |
243 | ||
244 | /* Copy of gathers */ | |
245 | size_t gather_copy_size; | |
246 | dma_addr_t gather_copy; | |
247 | u8 *gather_copy_mapped; | |
248 | ||
249 | /* Check if register is marked as an address reg */ | |
a2b78b0d | 250 | int (*is_addr_reg)(struct device *dev, u32 class, u32 reg); |
35d747a8 | 251 | |
0f563a4b DO |
252 | /* Check if class belongs to the unit */ |
253 | int (*is_valid_class)(u32 class); | |
254 | ||
35d747a8 TR |
255 | /* Request a SETCLASS to this class */ |
256 | u32 class; | |
257 | ||
258 | /* Add a channel wait for previous ops to complete */ | |
259 | bool serialize; | |
260 | }; | |
261 | ||
262 | struct host1x_job *host1x_job_alloc(struct host1x_channel *ch, | |
24c94e16 | 263 | u32 num_cmdbufs, u32 num_relocs); |
326bbd79 TR |
264 | void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo, |
265 | unsigned int words, unsigned int offset); | |
35d747a8 TR |
266 | struct host1x_job *host1x_job_get(struct host1x_job *job); |
267 | void host1x_job_put(struct host1x_job *job); | |
268 | int host1x_job_pin(struct host1x_job *job, struct device *dev); | |
269 | void host1x_job_unpin(struct host1x_job *job); | |
270 | ||
776dc384 TR |
271 | /* |
272 | * subdevice probe infrastructure | |
273 | */ | |
274 | ||
275 | struct host1x_device; | |
276 | ||
466749f1 TR |
277 | /** |
278 | * struct host1x_driver - host1x logical device driver | |
279 | * @driver: core driver | |
280 | * @subdevs: table of OF device IDs matching subdevices for this driver | |
281 | * @list: list node for the driver | |
282 | * @probe: called when the host1x logical device is probed | |
283 | * @remove: called when the host1x logical device is removed | |
284 | * @shutdown: called when the host1x logical device is shut down | |
285 | */ | |
776dc384 | 286 | struct host1x_driver { |
f4c5cf88 TR |
287 | struct device_driver driver; |
288 | ||
776dc384 TR |
289 | const struct of_device_id *subdevs; |
290 | struct list_head list; | |
776dc384 TR |
291 | |
292 | int (*probe)(struct host1x_device *device); | |
293 | int (*remove)(struct host1x_device *device); | |
f4c5cf88 | 294 | void (*shutdown)(struct host1x_device *device); |
776dc384 TR |
295 | }; |
296 | ||
f4c5cf88 TR |
297 | static inline struct host1x_driver * |
298 | to_host1x_driver(struct device_driver *driver) | |
299 | { | |
300 | return container_of(driver, struct host1x_driver, driver); | |
301 | } | |
302 | ||
303 | int host1x_driver_register_full(struct host1x_driver *driver, | |
304 | struct module *owner); | |
776dc384 TR |
305 | void host1x_driver_unregister(struct host1x_driver *driver); |
306 | ||
f4c5cf88 TR |
307 | #define host1x_driver_register(driver) \ |
308 | host1x_driver_register_full(driver, THIS_MODULE) | |
309 | ||
776dc384 TR |
310 | struct host1x_device { |
311 | struct host1x_driver *driver; | |
312 | struct list_head list; | |
313 | struct device dev; | |
314 | ||
315 | struct mutex subdevs_lock; | |
316 | struct list_head subdevs; | |
317 | struct list_head active; | |
318 | ||
319 | struct mutex clients_lock; | |
320 | struct list_head clients; | |
536e1715 | 321 | |
f4c5cf88 | 322 | bool registered; |
1e390478 TR |
323 | |
324 | struct device_dma_parameters dma_parms; | |
776dc384 TR |
325 | }; |
326 | ||
327 | static inline struct host1x_device *to_host1x_device(struct device *dev) | |
328 | { | |
329 | return container_of(dev, struct host1x_device, dev); | |
330 | } | |
331 | ||
332 | int host1x_device_init(struct host1x_device *device); | |
333 | int host1x_device_exit(struct host1x_device *device); | |
334 | ||
0cfe5a6e TR |
335 | void __host1x_client_init(struct host1x_client *client, struct lock_class_key *key); |
336 | void host1x_client_exit(struct host1x_client *client); | |
337 | ||
338 | #define host1x_client_init(client) \ | |
339 | ({ \ | |
340 | static struct lock_class_key __key; \ | |
341 | __host1x_client_init(client, &__key); \ | |
342 | }) | |
343 | ||
344 | int __host1x_client_register(struct host1x_client *client); | |
345 | ||
346 | /* | |
347 | * Note that this wrapper calls __host1x_client_init() for compatibility | |
348 | * with existing callers. Callers that want to separately initialize and | |
349 | * register a host1x client must first initialize using either of the | |
350 | * __host1x_client_init() or host1x_client_init() functions and then use | |
351 | * the low-level __host1x_client_register() function to avoid the client | |
352 | * getting reinitialized. | |
353 | */ | |
354 | #define host1x_client_register(client) \ | |
355 | ({ \ | |
356 | static struct lock_class_key __key; \ | |
357 | __host1x_client_init(client, &__key); \ | |
358 | __host1x_client_register(client); \ | |
a24f9817 MP |
359 | }) |
360 | ||
776dc384 TR |
361 | int host1x_client_unregister(struct host1x_client *client); |
362 | ||
fd67e9c6 TR |
363 | int host1x_client_suspend(struct host1x_client *client); |
364 | int host1x_client_resume(struct host1x_client *client); | |
365 | ||
4de6a2d6 TR |
366 | struct tegra_mipi_device; |
367 | ||
767598d4 SK |
368 | struct tegra_mipi_device *tegra_mipi_request(struct device *device, |
369 | struct device_node *np); | |
4de6a2d6 | 370 | void tegra_mipi_free(struct tegra_mipi_device *device); |
87904c3e TR |
371 | int tegra_mipi_enable(struct tegra_mipi_device *device); |
372 | int tegra_mipi_disable(struct tegra_mipi_device *device); | |
cf5153e4 SK |
373 | int tegra_mipi_start_calibration(struct tegra_mipi_device *device); |
374 | int tegra_mipi_finish_calibration(struct tegra_mipi_device *device); | |
4de6a2d6 | 375 | |
6579324a | 376 | #endif |