]>
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 | |
28 | * @init: host1x client initialization code | |
29 | * @exit: host1x client tear down code | |
fd67e9c6 TR |
30 | * @suspend: host1x client suspend code |
31 | * @resume: host1x client resume code | |
466749f1 | 32 | */ |
53fa7f72 TR |
33 | struct host1x_client_ops { |
34 | int (*init)(struct host1x_client *client); | |
35 | int (*exit)(struct host1x_client *client); | |
fd67e9c6 TR |
36 | int (*suspend)(struct host1x_client *client); |
37 | int (*resume)(struct host1x_client *client); | |
53fa7f72 TR |
38 | }; |
39 | ||
466749f1 TR |
40 | /** |
41 | * struct host1x_client - host1x client structure | |
42 | * @list: list node for the host1x client | |
608f43ad | 43 | * @host: pointer to struct device representing the host1x controller |
466749f1 | 44 | * @dev: pointer to struct device backing this host1x client |
aacdf198 | 45 | * @group: IOMMU group that this client is a member of |
466749f1 TR |
46 | * @ops: host1x client operations |
47 | * @class: host1x class represented by this client | |
48 | * @channel: host1x channel associated with this client | |
49 | * @syncpts: array of syncpoints requested for this client | |
50 | * @num_syncpts: number of syncpoints requested for this client | |
51 | */ | |
53fa7f72 TR |
52 | struct host1x_client { |
53 | struct list_head list; | |
608f43ad | 54 | struct device *host; |
53fa7f72 | 55 | struct device *dev; |
aacdf198 | 56 | struct iommu_group *group; |
53fa7f72 TR |
57 | |
58 | const struct host1x_client_ops *ops; | |
59 | ||
60 | enum host1x_class class; | |
61 | struct host1x_channel *channel; | |
62 | ||
63 | struct host1x_syncpt **syncpts; | |
64 | unsigned int num_syncpts; | |
fd67e9c6 TR |
65 | |
66 | struct host1x_client *parent; | |
67 | unsigned int usecount; | |
68 | struct mutex lock; | |
53fa7f72 TR |
69 | }; |
70 | ||
35d747a8 TR |
71 | /* |
72 | * host1x buffer objects | |
73 | */ | |
74 | ||
75 | struct host1x_bo; | |
76 | struct sg_table; | |
77 | ||
78 | struct host1x_bo_ops { | |
79 | struct host1x_bo *(*get)(struct host1x_bo *bo); | |
80 | void (*put)(struct host1x_bo *bo); | |
80327ce3 TR |
81 | struct sg_table *(*pin)(struct device *dev, struct host1x_bo *bo, |
82 | dma_addr_t *phys); | |
83 | void (*unpin)(struct device *dev, struct sg_table *sgt); | |
35d747a8 TR |
84 | void *(*mmap)(struct host1x_bo *bo); |
85 | void (*munmap)(struct host1x_bo *bo, void *addr); | |
35d747a8 TR |
86 | }; |
87 | ||
88 | struct host1x_bo { | |
89 | const struct host1x_bo_ops *ops; | |
90 | }; | |
91 | ||
92 | static inline void host1x_bo_init(struct host1x_bo *bo, | |
93 | const struct host1x_bo_ops *ops) | |
94 | { | |
95 | bo->ops = ops; | |
96 | } | |
97 | ||
98 | static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo) | |
99 | { | |
100 | return bo->ops->get(bo); | |
101 | } | |
102 | ||
103 | static inline void host1x_bo_put(struct host1x_bo *bo) | |
104 | { | |
105 | bo->ops->put(bo); | |
106 | } | |
107 | ||
80327ce3 TR |
108 | static inline struct sg_table *host1x_bo_pin(struct device *dev, |
109 | struct host1x_bo *bo, | |
110 | dma_addr_t *phys) | |
35d747a8 | 111 | { |
80327ce3 | 112 | return bo->ops->pin(dev, bo, phys); |
35d747a8 TR |
113 | } |
114 | ||
80327ce3 TR |
115 | static inline void host1x_bo_unpin(struct device *dev, struct host1x_bo *bo, |
116 | struct sg_table *sgt) | |
35d747a8 | 117 | { |
80327ce3 | 118 | bo->ops->unpin(dev, sgt); |
35d747a8 TR |
119 | } |
120 | ||
121 | static inline void *host1x_bo_mmap(struct host1x_bo *bo) | |
122 | { | |
123 | return bo->ops->mmap(bo); | |
124 | } | |
125 | ||
126 | static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr) | |
127 | { | |
128 | bo->ops->munmap(bo, addr); | |
129 | } | |
130 | ||
35d747a8 TR |
131 | /* |
132 | * host1x syncpoints | |
133 | */ | |
134 | ||
8736fe81 | 135 | #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0) |
f5a954fe | 136 | #define HOST1X_SYNCPT_HAS_BASE (1 << 1) |
8736fe81 | 137 | |
f5a954fe | 138 | struct host1x_syncpt_base; |
35d747a8 TR |
139 | struct host1x_syncpt; |
140 | struct host1x; | |
141 | ||
142 | struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id); | |
143 | u32 host1x_syncpt_id(struct host1x_syncpt *sp); | |
144 | u32 host1x_syncpt_read_min(struct host1x_syncpt *sp); | |
145 | u32 host1x_syncpt_read_max(struct host1x_syncpt *sp); | |
b4a20144 | 146 | u32 host1x_syncpt_read(struct host1x_syncpt *sp); |
35d747a8 | 147 | int host1x_syncpt_incr(struct host1x_syncpt *sp); |
64400c37 | 148 | u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs); |
35d747a8 TR |
149 | int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout, |
150 | u32 *value); | |
617dd7cc | 151 | struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client, |
8736fe81 | 152 | unsigned long flags); |
35d747a8 TR |
153 | void host1x_syncpt_free(struct host1x_syncpt *sp); |
154 | ||
f5a954fe AM |
155 | struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp); |
156 | u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base); | |
157 | ||
35d747a8 TR |
158 | /* |
159 | * host1x channel | |
160 | */ | |
161 | ||
162 | struct host1x_channel; | |
163 | struct host1x_job; | |
164 | ||
caccddcf | 165 | struct host1x_channel *host1x_channel_request(struct host1x_client *client); |
35d747a8 TR |
166 | struct host1x_channel *host1x_channel_get(struct host1x_channel *channel); |
167 | void host1x_channel_put(struct host1x_channel *channel); | |
168 | int host1x_job_submit(struct host1x_job *job); | |
169 | ||
170 | /* | |
171 | * host1x job | |
172 | */ | |
173 | ||
ab4f81bf TR |
174 | #define HOST1X_RELOC_READ (1 << 0) |
175 | #define HOST1X_RELOC_WRITE (1 << 1) | |
176 | ||
35d747a8 | 177 | struct host1x_reloc { |
961e3bea TR |
178 | struct { |
179 | struct host1x_bo *bo; | |
180 | unsigned long offset; | |
181 | } cmdbuf; | |
182 | struct { | |
183 | struct host1x_bo *bo; | |
184 | unsigned long offset; | |
185 | } target; | |
186 | unsigned long shift; | |
ab4f81bf | 187 | unsigned long flags; |
35d747a8 TR |
188 | }; |
189 | ||
190 | struct host1x_job { | |
191 | /* When refcount goes to zero, job can be freed */ | |
192 | struct kref ref; | |
193 | ||
194 | /* List entry */ | |
195 | struct list_head list; | |
196 | ||
197 | /* Channel where job is submitted to */ | |
198 | struct host1x_channel *channel; | |
199 | ||
bf3d41cc TR |
200 | /* client where the job originated */ |
201 | struct host1x_client *client; | |
35d747a8 TR |
202 | |
203 | /* Gathers and their memory */ | |
204 | struct host1x_job_gather *gathers; | |
205 | unsigned int num_gathers; | |
206 | ||
35d747a8 | 207 | /* Array of handles to be pinned & unpinned */ |
06490bb9 | 208 | struct host1x_reloc *relocs; |
35d747a8 TR |
209 | unsigned int num_relocs; |
210 | struct host1x_job_unpin_data *unpins; | |
211 | unsigned int num_unpins; | |
212 | ||
213 | dma_addr_t *addr_phys; | |
214 | dma_addr_t *gather_addr_phys; | |
215 | dma_addr_t *reloc_addr_phys; | |
216 | ||
217 | /* Sync point id, number of increments and end related to the submit */ | |
218 | u32 syncpt_id; | |
219 | u32 syncpt_incrs; | |
220 | u32 syncpt_end; | |
221 | ||
222 | /* Maximum time to wait for this job */ | |
223 | unsigned int timeout; | |
224 | ||
225 | /* Index and number of slots used in the push buffer */ | |
226 | unsigned int first_get; | |
227 | unsigned int num_slots; | |
228 | ||
229 | /* Copy of gathers */ | |
230 | size_t gather_copy_size; | |
231 | dma_addr_t gather_copy; | |
232 | u8 *gather_copy_mapped; | |
233 | ||
234 | /* Check if register is marked as an address reg */ | |
a2b78b0d | 235 | int (*is_addr_reg)(struct device *dev, u32 class, u32 reg); |
35d747a8 | 236 | |
0f563a4b DO |
237 | /* Check if class belongs to the unit */ |
238 | int (*is_valid_class)(u32 class); | |
239 | ||
35d747a8 TR |
240 | /* Request a SETCLASS to this class */ |
241 | u32 class; | |
242 | ||
243 | /* Add a channel wait for previous ops to complete */ | |
244 | bool serialize; | |
245 | }; | |
246 | ||
247 | struct host1x_job *host1x_job_alloc(struct host1x_channel *ch, | |
24c94e16 | 248 | u32 num_cmdbufs, u32 num_relocs); |
326bbd79 TR |
249 | void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo, |
250 | unsigned int words, unsigned int offset); | |
35d747a8 TR |
251 | struct host1x_job *host1x_job_get(struct host1x_job *job); |
252 | void host1x_job_put(struct host1x_job *job); | |
253 | int host1x_job_pin(struct host1x_job *job, struct device *dev); | |
254 | void host1x_job_unpin(struct host1x_job *job); | |
255 | ||
776dc384 TR |
256 | /* |
257 | * subdevice probe infrastructure | |
258 | */ | |
259 | ||
260 | struct host1x_device; | |
261 | ||
466749f1 TR |
262 | /** |
263 | * struct host1x_driver - host1x logical device driver | |
264 | * @driver: core driver | |
265 | * @subdevs: table of OF device IDs matching subdevices for this driver | |
266 | * @list: list node for the driver | |
267 | * @probe: called when the host1x logical device is probed | |
268 | * @remove: called when the host1x logical device is removed | |
269 | * @shutdown: called when the host1x logical device is shut down | |
270 | */ | |
776dc384 | 271 | struct host1x_driver { |
f4c5cf88 TR |
272 | struct device_driver driver; |
273 | ||
776dc384 TR |
274 | const struct of_device_id *subdevs; |
275 | struct list_head list; | |
776dc384 TR |
276 | |
277 | int (*probe)(struct host1x_device *device); | |
278 | int (*remove)(struct host1x_device *device); | |
f4c5cf88 | 279 | void (*shutdown)(struct host1x_device *device); |
776dc384 TR |
280 | }; |
281 | ||
f4c5cf88 TR |
282 | static inline struct host1x_driver * |
283 | to_host1x_driver(struct device_driver *driver) | |
284 | { | |
285 | return container_of(driver, struct host1x_driver, driver); | |
286 | } | |
287 | ||
288 | int host1x_driver_register_full(struct host1x_driver *driver, | |
289 | struct module *owner); | |
776dc384 TR |
290 | void host1x_driver_unregister(struct host1x_driver *driver); |
291 | ||
f4c5cf88 TR |
292 | #define host1x_driver_register(driver) \ |
293 | host1x_driver_register_full(driver, THIS_MODULE) | |
294 | ||
776dc384 TR |
295 | struct host1x_device { |
296 | struct host1x_driver *driver; | |
297 | struct list_head list; | |
298 | struct device dev; | |
299 | ||
300 | struct mutex subdevs_lock; | |
301 | struct list_head subdevs; | |
302 | struct list_head active; | |
303 | ||
304 | struct mutex clients_lock; | |
305 | struct list_head clients; | |
536e1715 | 306 | |
f4c5cf88 | 307 | bool registered; |
1e390478 TR |
308 | |
309 | struct device_dma_parameters dma_parms; | |
776dc384 TR |
310 | }; |
311 | ||
312 | static inline struct host1x_device *to_host1x_device(struct device *dev) | |
313 | { | |
314 | return container_of(dev, struct host1x_device, dev); | |
315 | } | |
316 | ||
317 | int host1x_device_init(struct host1x_device *device); | |
318 | int host1x_device_exit(struct host1x_device *device); | |
319 | ||
320 | int host1x_client_register(struct host1x_client *client); | |
321 | int host1x_client_unregister(struct host1x_client *client); | |
322 | ||
fd67e9c6 TR |
323 | int host1x_client_suspend(struct host1x_client *client); |
324 | int host1x_client_resume(struct host1x_client *client); | |
325 | ||
4de6a2d6 TR |
326 | struct tegra_mipi_device; |
327 | ||
328 | struct tegra_mipi_device *tegra_mipi_request(struct device *device); | |
329 | void tegra_mipi_free(struct tegra_mipi_device *device); | |
87904c3e TR |
330 | int tegra_mipi_enable(struct tegra_mipi_device *device); |
331 | int tegra_mipi_disable(struct tegra_mipi_device *device); | |
4de6a2d6 TR |
332 | int tegra_mipi_calibrate(struct tegra_mipi_device *device); |
333 | ||
6579324a | 334 | #endif |