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 * struct host1x_client_ops - host1x client operations
25 * @init: host1x client initialization code
26 * @exit: host1x client tear down code
28 struct host1x_client_ops {
29 int (*init)(struct host1x_client *client);
30 int (*exit)(struct host1x_client *client);
34 * struct host1x_client - host1x client structure
35 * @list: list node for the host1x client
36 * @parent: pointer to struct device representing the host1x controller
37 * @dev: pointer to struct device backing this host1x client
38 * @group: IOMMU group that this client is a member of
39 * @ops: host1x client operations
40 * @class: host1x class represented by this client
41 * @channel: host1x channel associated with this client
42 * @syncpts: array of syncpoints requested for this client
43 * @num_syncpts: number of syncpoints requested for this client
45 struct host1x_client {
46 struct list_head list;
47 struct device *parent;
49 struct iommu_group *group;
51 const struct host1x_client_ops *ops;
53 enum host1x_class class;
54 struct host1x_channel *channel;
56 struct host1x_syncpt **syncpts;
57 unsigned int num_syncpts;
61 * host1x buffer objects
67 struct host1x_bo_ops {
68 struct host1x_bo *(*get)(struct host1x_bo *bo);
69 void (*put)(struct host1x_bo *bo);
70 struct sg_table *(*pin)(struct device *dev, struct host1x_bo *bo,
72 void (*unpin)(struct device *dev, struct sg_table *sgt);
73 void *(*mmap)(struct host1x_bo *bo);
74 void (*munmap)(struct host1x_bo *bo, void *addr);
75 void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum);
76 void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr);
80 const struct host1x_bo_ops *ops;
83 static inline void host1x_bo_init(struct host1x_bo *bo,
84 const struct host1x_bo_ops *ops)
89 static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
91 return bo->ops->get(bo);
94 static inline void host1x_bo_put(struct host1x_bo *bo)
99 static inline struct sg_table *host1x_bo_pin(struct device *dev,
100 struct host1x_bo *bo,
103 return bo->ops->pin(dev, bo, phys);
106 static inline void host1x_bo_unpin(struct device *dev, struct host1x_bo *bo,
107 struct sg_table *sgt)
109 bo->ops->unpin(dev, sgt);
112 static inline void *host1x_bo_mmap(struct host1x_bo *bo)
114 return bo->ops->mmap(bo);
117 static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
119 bo->ops->munmap(bo, addr);
122 static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
124 return bo->ops->kmap(bo, pagenum);
127 static inline void host1x_bo_kunmap(struct host1x_bo *bo,
128 unsigned int pagenum, void *addr)
130 bo->ops->kunmap(bo, pagenum, addr);
137 #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
138 #define HOST1X_SYNCPT_HAS_BASE (1 << 1)
140 struct host1x_syncpt_base;
141 struct host1x_syncpt;
144 struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
145 u32 host1x_syncpt_id(struct host1x_syncpt *sp);
146 u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
147 u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
148 u32 host1x_syncpt_read(struct host1x_syncpt *sp);
149 int host1x_syncpt_incr(struct host1x_syncpt *sp);
150 u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
151 int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
153 struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
154 unsigned long flags);
155 void host1x_syncpt_free(struct host1x_syncpt *sp);
157 struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
158 u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
164 struct host1x_channel;
167 struct host1x_channel *host1x_channel_request(struct host1x_client *client);
168 struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
169 void host1x_channel_put(struct host1x_channel *channel);
170 int host1x_job_submit(struct host1x_job *job);
176 #define HOST1X_RELOC_READ (1 << 0)
177 #define HOST1X_RELOC_WRITE (1 << 1)
179 struct host1x_reloc {
181 struct host1x_bo *bo;
182 unsigned long offset;
185 struct host1x_bo *bo;
186 unsigned long offset;
193 /* When refcount goes to zero, job can be freed */
197 struct list_head list;
199 /* Channel where job is submitted to */
200 struct host1x_channel *channel;
202 /* client where the job originated */
203 struct host1x_client *client;
205 /* Gathers and their memory */
206 struct host1x_job_gather *gathers;
207 unsigned int num_gathers;
209 /* Array of handles to be pinned & unpinned */
210 struct host1x_reloc *relocs;
211 unsigned int num_relocs;
212 struct host1x_job_unpin_data *unpins;
213 unsigned int num_unpins;
215 dma_addr_t *addr_phys;
216 dma_addr_t *gather_addr_phys;
217 dma_addr_t *reloc_addr_phys;
219 /* Sync point id, number of increments and end related to the submit */
224 /* Maximum time to wait for this job */
225 unsigned int timeout;
227 /* Index and number of slots used in the push buffer */
228 unsigned int first_get;
229 unsigned int num_slots;
231 /* Copy of gathers */
232 size_t gather_copy_size;
233 dma_addr_t gather_copy;
234 u8 *gather_copy_mapped;
236 /* Check if register is marked as an address reg */
237 int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
239 /* Check if class belongs to the unit */
240 int (*is_valid_class)(u32 class);
242 /* Request a SETCLASS to this class */
245 /* Add a channel wait for previous ops to complete */
249 struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
250 u32 num_cmdbufs, u32 num_relocs);
251 void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo,
252 unsigned int words, unsigned int offset);
253 struct host1x_job *host1x_job_get(struct host1x_job *job);
254 void host1x_job_put(struct host1x_job *job);
255 int host1x_job_pin(struct host1x_job *job, struct device *dev);
256 void host1x_job_unpin(struct host1x_job *job);
259 * subdevice probe infrastructure
262 struct host1x_device;
265 * struct host1x_driver - host1x logical device driver
266 * @driver: core driver
267 * @subdevs: table of OF device IDs matching subdevices for this driver
268 * @list: list node for the driver
269 * @probe: called when the host1x logical device is probed
270 * @remove: called when the host1x logical device is removed
271 * @shutdown: called when the host1x logical device is shut down
273 struct host1x_driver {
274 struct device_driver driver;
276 const struct of_device_id *subdevs;
277 struct list_head list;
279 int (*probe)(struct host1x_device *device);
280 int (*remove)(struct host1x_device *device);
281 void (*shutdown)(struct host1x_device *device);
284 static inline struct host1x_driver *
285 to_host1x_driver(struct device_driver *driver)
287 return container_of(driver, struct host1x_driver, driver);
290 int host1x_driver_register_full(struct host1x_driver *driver,
291 struct module *owner);
292 void host1x_driver_unregister(struct host1x_driver *driver);
294 #define host1x_driver_register(driver) \
295 host1x_driver_register_full(driver, THIS_MODULE)
297 struct host1x_device {
298 struct host1x_driver *driver;
299 struct list_head list;
302 struct mutex subdevs_lock;
303 struct list_head subdevs;
304 struct list_head active;
306 struct mutex clients_lock;
307 struct list_head clients;
311 struct device_dma_parameters dma_parms;
314 static inline struct host1x_device *to_host1x_device(struct device *dev)
316 return container_of(dev, struct host1x_device, dev);
319 int host1x_device_init(struct host1x_device *device);
320 int host1x_device_exit(struct host1x_device *device);
322 int host1x_client_register(struct host1x_client *client);
323 int host1x_client_unregister(struct host1x_client *client);
325 struct tegra_mipi_device;
327 struct tegra_mipi_device *tegra_mipi_request(struct device *device);
328 void tegra_mipi_free(struct tegra_mipi_device *device);
329 int tegra_mipi_enable(struct tegra_mipi_device *device);
330 int tegra_mipi_disable(struct tegra_mipi_device *device);
331 int tegra_mipi_calibrate(struct tegra_mipi_device *device);