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);
78 const struct host1x_bo_ops *ops;
81 static inline void host1x_bo_init(struct host1x_bo *bo,
82 const struct host1x_bo_ops *ops)
87 static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
89 return bo->ops->get(bo);
92 static inline void host1x_bo_put(struct host1x_bo *bo)
97 static inline struct sg_table *host1x_bo_pin(struct device *dev,
101 return bo->ops->pin(dev, bo, phys);
104 static inline void host1x_bo_unpin(struct device *dev, struct host1x_bo *bo,
105 struct sg_table *sgt)
107 bo->ops->unpin(dev, sgt);
110 static inline void *host1x_bo_mmap(struct host1x_bo *bo)
112 return bo->ops->mmap(bo);
115 static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
117 bo->ops->munmap(bo, addr);
124 #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
125 #define HOST1X_SYNCPT_HAS_BASE (1 << 1)
127 struct host1x_syncpt_base;
128 struct host1x_syncpt;
131 struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
132 u32 host1x_syncpt_id(struct host1x_syncpt *sp);
133 u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
134 u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
135 u32 host1x_syncpt_read(struct host1x_syncpt *sp);
136 int host1x_syncpt_incr(struct host1x_syncpt *sp);
137 u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
138 int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
140 struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
141 unsigned long flags);
142 void host1x_syncpt_free(struct host1x_syncpt *sp);
144 struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
145 u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
151 struct host1x_channel;
154 struct host1x_channel *host1x_channel_request(struct host1x_client *client);
155 struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
156 void host1x_channel_put(struct host1x_channel *channel);
157 int host1x_job_submit(struct host1x_job *job);
163 #define HOST1X_RELOC_READ (1 << 0)
164 #define HOST1X_RELOC_WRITE (1 << 1)
166 struct host1x_reloc {
168 struct host1x_bo *bo;
169 unsigned long offset;
172 struct host1x_bo *bo;
173 unsigned long offset;
180 /* When refcount goes to zero, job can be freed */
184 struct list_head list;
186 /* Channel where job is submitted to */
187 struct host1x_channel *channel;
189 /* client where the job originated */
190 struct host1x_client *client;
192 /* Gathers and their memory */
193 struct host1x_job_gather *gathers;
194 unsigned int num_gathers;
196 /* Array of handles to be pinned & unpinned */
197 struct host1x_reloc *relocs;
198 unsigned int num_relocs;
199 struct host1x_job_unpin_data *unpins;
200 unsigned int num_unpins;
202 dma_addr_t *addr_phys;
203 dma_addr_t *gather_addr_phys;
204 dma_addr_t *reloc_addr_phys;
206 /* Sync point id, number of increments and end related to the submit */
211 /* Maximum time to wait for this job */
212 unsigned int timeout;
214 /* Index and number of slots used in the push buffer */
215 unsigned int first_get;
216 unsigned int num_slots;
218 /* Copy of gathers */
219 size_t gather_copy_size;
220 dma_addr_t gather_copy;
221 u8 *gather_copy_mapped;
223 /* Check if register is marked as an address reg */
224 int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
226 /* Check if class belongs to the unit */
227 int (*is_valid_class)(u32 class);
229 /* Request a SETCLASS to this class */
232 /* Add a channel wait for previous ops to complete */
236 struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
237 u32 num_cmdbufs, u32 num_relocs);
238 void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo,
239 unsigned int words, unsigned int offset);
240 struct host1x_job *host1x_job_get(struct host1x_job *job);
241 void host1x_job_put(struct host1x_job *job);
242 int host1x_job_pin(struct host1x_job *job, struct device *dev);
243 void host1x_job_unpin(struct host1x_job *job);
246 * subdevice probe infrastructure
249 struct host1x_device;
252 * struct host1x_driver - host1x logical device driver
253 * @driver: core driver
254 * @subdevs: table of OF device IDs matching subdevices for this driver
255 * @list: list node for the driver
256 * @probe: called when the host1x logical device is probed
257 * @remove: called when the host1x logical device is removed
258 * @shutdown: called when the host1x logical device is shut down
260 struct host1x_driver {
261 struct device_driver driver;
263 const struct of_device_id *subdevs;
264 struct list_head list;
266 int (*probe)(struct host1x_device *device);
267 int (*remove)(struct host1x_device *device);
268 void (*shutdown)(struct host1x_device *device);
271 static inline struct host1x_driver *
272 to_host1x_driver(struct device_driver *driver)
274 return container_of(driver, struct host1x_driver, driver);
277 int host1x_driver_register_full(struct host1x_driver *driver,
278 struct module *owner);
279 void host1x_driver_unregister(struct host1x_driver *driver);
281 #define host1x_driver_register(driver) \
282 host1x_driver_register_full(driver, THIS_MODULE)
284 struct host1x_device {
285 struct host1x_driver *driver;
286 struct list_head list;
289 struct mutex subdevs_lock;
290 struct list_head subdevs;
291 struct list_head active;
293 struct mutex clients_lock;
294 struct list_head clients;
298 struct device_dma_parameters dma_parms;
301 static inline struct host1x_device *to_host1x_device(struct device *dev)
303 return container_of(dev, struct host1x_device, dev);
306 int host1x_device_init(struct host1x_device *device);
307 int host1x_device_exit(struct host1x_device *device);
309 int host1x_client_register(struct host1x_client *client);
310 int host1x_client_unregister(struct host1x_client *client);
312 struct tegra_mipi_device;
314 struct tegra_mipi_device *tegra_mipi_request(struct device *device);
315 void tegra_mipi_free(struct tegra_mipi_device *device);
316 int tegra_mipi_enable(struct tegra_mipi_device *device);
317 int tegra_mipi_disable(struct tegra_mipi_device *device);
318 int tegra_mipi_calibrate(struct tegra_mipi_device *device);