1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved.
6 #ifndef __LINUX_HOST1X_H
7 #define __LINUX_HOST1X_H
9 #include <linux/device.h>
10 #include <linux/types.h>
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,
24 u64 host1x_get_dma_mask(struct host1x *host1x);
27 * struct host1x_client_ops - host1x client operations
28 * @early_init: host1x client early initialization code
29 * @init: host1x client initialization code
30 * @exit: host1x client tear down code
31 * @late_exit: host1x client late tear down code
32 * @suspend: host1x client suspend code
33 * @resume: host1x client resume code
35 struct host1x_client_ops {
36 int (*early_init)(struct host1x_client *client);
37 int (*init)(struct host1x_client *client);
38 int (*exit)(struct host1x_client *client);
39 int (*late_exit)(struct host1x_client *client);
40 int (*suspend)(struct host1x_client *client);
41 int (*resume)(struct host1x_client *client);
45 * struct host1x_client - host1x client structure
46 * @list: list node for the host1x client
47 * @host: pointer to struct device representing the host1x controller
48 * @dev: pointer to struct device backing this host1x client
49 * @group: IOMMU group that this client is a member of
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
55 * @parent: pointer to parent structure
56 * @usecount: reference count for this structure
57 * @lock: mutex for mutually exclusive concurrency
59 struct host1x_client {
60 struct list_head list;
63 struct iommu_group *group;
65 const struct host1x_client_ops *ops;
67 enum host1x_class class;
68 struct host1x_channel *channel;
70 struct host1x_syncpt **syncpts;
71 unsigned int num_syncpts;
73 struct host1x_client *parent;
74 unsigned int usecount;
79 * host1x buffer objects
85 struct host1x_bo_ops {
86 struct host1x_bo *(*get)(struct host1x_bo *bo);
87 void (*put)(struct host1x_bo *bo);
88 struct sg_table *(*pin)(struct device *dev, struct host1x_bo *bo,
90 void (*unpin)(struct device *dev, struct sg_table *sgt);
91 void *(*mmap)(struct host1x_bo *bo);
92 void (*munmap)(struct host1x_bo *bo, void *addr);
96 const struct host1x_bo_ops *ops;
99 static inline void host1x_bo_init(struct host1x_bo *bo,
100 const struct host1x_bo_ops *ops)
105 static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
107 return bo->ops->get(bo);
110 static inline void host1x_bo_put(struct host1x_bo *bo)
115 static inline struct sg_table *host1x_bo_pin(struct device *dev,
116 struct host1x_bo *bo,
119 return bo->ops->pin(dev, bo, phys);
122 static inline void host1x_bo_unpin(struct device *dev, struct host1x_bo *bo,
123 struct sg_table *sgt)
125 bo->ops->unpin(dev, sgt);
128 static inline void *host1x_bo_mmap(struct host1x_bo *bo)
130 return bo->ops->mmap(bo);
133 static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
135 bo->ops->munmap(bo, addr);
142 #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
143 #define HOST1X_SYNCPT_HAS_BASE (1 << 1)
145 struct host1x_syncpt_base;
146 struct host1x_syncpt;
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);
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);
155 u32 host1x_syncpt_read(struct host1x_syncpt *sp);
156 int host1x_syncpt_incr(struct host1x_syncpt *sp);
157 u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
158 int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
160 struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
161 unsigned long flags);
162 void host1x_syncpt_put(struct host1x_syncpt *sp);
163 struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,
167 struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
168 u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
170 void host1x_syncpt_release_vblank_reservation(struct host1x_client *client,
177 struct host1x_channel;
180 struct host1x_channel *host1x_channel_request(struct host1x_client *client);
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);
189 #define HOST1X_RELOC_READ (1 << 0)
190 #define HOST1X_RELOC_WRITE (1 << 1)
192 struct host1x_reloc {
194 struct host1x_bo *bo;
195 unsigned long offset;
198 struct host1x_bo *bo;
199 unsigned long offset;
206 /* When refcount goes to zero, job can be freed */
210 struct list_head list;
212 /* Channel where job is submitted to */
213 struct host1x_channel *channel;
215 /* client where the job originated */
216 struct host1x_client *client;
218 /* Gathers and their memory */
219 struct host1x_job_gather *gathers;
220 unsigned int num_gathers;
222 /* Array of handles to be pinned & unpinned */
223 struct host1x_reloc *relocs;
224 unsigned int num_relocs;
225 struct host1x_job_unpin_data *unpins;
226 unsigned int num_unpins;
228 dma_addr_t *addr_phys;
229 dma_addr_t *gather_addr_phys;
230 dma_addr_t *reloc_addr_phys;
232 /* Sync point id, number of increments and end related to the submit */
233 struct host1x_syncpt *syncpt;
237 /* Maximum time to wait for this job */
238 unsigned int timeout;
240 /* Index and number of slots used in the push buffer */
241 unsigned int first_get;
242 unsigned int num_slots;
244 /* Copy of gathers */
245 size_t gather_copy_size;
246 dma_addr_t gather_copy;
247 u8 *gather_copy_mapped;
249 /* Check if register is marked as an address reg */
250 int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
252 /* Check if class belongs to the unit */
253 int (*is_valid_class)(u32 class);
255 /* Request a SETCLASS to this class */
258 /* Add a channel wait for previous ops to complete */
262 struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
263 u32 num_cmdbufs, u32 num_relocs);
264 void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo,
265 unsigned int words, unsigned int offset);
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);
272 * subdevice probe infrastructure
275 struct host1x_device;
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
286 struct host1x_driver {
287 struct device_driver driver;
289 const struct of_device_id *subdevs;
290 struct list_head list;
292 int (*probe)(struct host1x_device *device);
293 int (*remove)(struct host1x_device *device);
294 void (*shutdown)(struct host1x_device *device);
297 static inline struct host1x_driver *
298 to_host1x_driver(struct device_driver *driver)
300 return container_of(driver, struct host1x_driver, driver);
303 int host1x_driver_register_full(struct host1x_driver *driver,
304 struct module *owner);
305 void host1x_driver_unregister(struct host1x_driver *driver);
307 #define host1x_driver_register(driver) \
308 host1x_driver_register_full(driver, THIS_MODULE)
310 struct host1x_device {
311 struct host1x_driver *driver;
312 struct list_head list;
315 struct mutex subdevs_lock;
316 struct list_head subdevs;
317 struct list_head active;
319 struct mutex clients_lock;
320 struct list_head clients;
324 struct device_dma_parameters dma_parms;
327 static inline struct host1x_device *to_host1x_device(struct device *dev)
329 return container_of(dev, struct host1x_device, dev);
332 int host1x_device_init(struct host1x_device *device);
333 int host1x_device_exit(struct host1x_device *device);
335 int __host1x_client_register(struct host1x_client *client,
336 struct lock_class_key *key);
337 #define host1x_client_register(class) \
339 static struct lock_class_key __key; \
340 __host1x_client_register(class, &__key); \
343 int host1x_client_unregister(struct host1x_client *client);
345 int host1x_client_suspend(struct host1x_client *client);
346 int host1x_client_resume(struct host1x_client *client);
348 struct tegra_mipi_device;
350 struct tegra_mipi_device *tegra_mipi_request(struct device *device,
351 struct device_node *np);
352 void tegra_mipi_free(struct tegra_mipi_device *device);
353 int tegra_mipi_enable(struct tegra_mipi_device *device);
354 int tegra_mipi_disable(struct tegra_mipi_device *device);
355 int tegra_mipi_start_calibration(struct tegra_mipi_device *device);
356 int tegra_mipi_finish_calibration(struct tegra_mipi_device *device);