2 * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef __LINUX_HOST1X_H
20 #define __LINUX_HOST1X_H
22 #include <linux/device.h>
23 #include <linux/types.h>
26 HOST1X_CLASS_HOST1X = 0x1,
27 HOST1X_CLASS_GR2D = 0x51,
28 HOST1X_CLASS_GR2D_SB = 0x52,
29 HOST1X_CLASS_VIC = 0x5D,
30 HOST1X_CLASS_GR3D = 0x60,
36 * struct host1x_client_ops - host1x client operations
37 * @init: host1x client initialization code
38 * @exit: host1x client tear down code
40 struct host1x_client_ops {
41 int (*init)(struct host1x_client *client);
42 int (*exit)(struct host1x_client *client);
46 * struct host1x_client - host1x client structure
47 * @list: list node for the host1x client
48 * @parent: pointer to struct device representing the host1x controller
49 * @dev: pointer to struct device backing this host1x client
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
56 struct host1x_client {
57 struct list_head list;
58 struct device *parent;
61 const struct host1x_client_ops *ops;
63 enum host1x_class class;
64 struct host1x_channel *channel;
66 struct host1x_syncpt **syncpts;
67 unsigned int num_syncpts;
71 * host1x buffer objects
77 struct host1x_bo_ops {
78 struct host1x_bo *(*get)(struct host1x_bo *bo);
79 void (*put)(struct host1x_bo *bo);
80 dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt);
81 void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt);
82 void *(*mmap)(struct host1x_bo *bo);
83 void (*munmap)(struct host1x_bo *bo, void *addr);
84 void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum);
85 void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr);
89 const struct host1x_bo_ops *ops;
92 static inline void host1x_bo_init(struct host1x_bo *bo,
93 const struct host1x_bo_ops *ops)
98 static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
100 return bo->ops->get(bo);
103 static inline void host1x_bo_put(struct host1x_bo *bo)
108 static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo,
109 struct sg_table **sgt)
111 return bo->ops->pin(bo, sgt);
114 static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt)
116 bo->ops->unpin(bo, sgt);
119 static inline void *host1x_bo_mmap(struct host1x_bo *bo)
121 return bo->ops->mmap(bo);
124 static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
126 bo->ops->munmap(bo, addr);
129 static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
131 return bo->ops->kmap(bo, pagenum);
134 static inline void host1x_bo_kunmap(struct host1x_bo *bo,
135 unsigned int pagenum, void *addr)
137 bo->ops->kunmap(bo, pagenum, addr);
144 #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
145 #define HOST1X_SYNCPT_HAS_BASE (1 << 1)
147 struct host1x_syncpt_base;
148 struct host1x_syncpt;
151 struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
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 device *dev,
161 unsigned long flags);
162 void host1x_syncpt_free(struct host1x_syncpt *sp);
164 struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
165 u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
171 struct host1x_channel;
174 struct host1x_channel *host1x_channel_request(struct device *dev);
175 void host1x_channel_free(struct host1x_channel *channel);
176 struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
177 void host1x_channel_put(struct host1x_channel *channel);
178 int host1x_job_submit(struct host1x_job *job);
184 struct host1x_reloc {
186 struct host1x_bo *bo;
187 unsigned long offset;
190 struct host1x_bo *bo;
191 unsigned long offset;
196 struct host1x_waitchk {
197 struct host1x_bo *bo;
204 /* When refcount goes to zero, job can be freed */
208 struct list_head list;
210 /* Channel where job is submitted to */
211 struct host1x_channel *channel;
215 /* Gathers and their memory */
216 struct host1x_job_gather *gathers;
217 unsigned int num_gathers;
219 /* Wait checks to be processed at submit time */
220 struct host1x_waitchk *waitchk;
221 unsigned int num_waitchk;
224 /* Array of handles to be pinned & unpinned */
225 struct host1x_reloc *relocarray;
226 unsigned int num_relocs;
227 struct host1x_job_unpin_data *unpins;
228 unsigned int num_unpins;
230 dma_addr_t *addr_phys;
231 dma_addr_t *gather_addr_phys;
232 dma_addr_t *reloc_addr_phys;
234 /* Sync point id, number of increments and end related to the submit */
239 /* Maximum time to wait for this job */
240 unsigned int timeout;
242 /* Index and number of slots used in the push buffer */
243 unsigned int first_get;
244 unsigned int num_slots;
246 /* Copy of gathers */
247 size_t gather_copy_size;
248 dma_addr_t gather_copy;
249 u8 *gather_copy_mapped;
251 /* Check if register is marked as an address reg */
252 int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
254 /* Check if class belongs to the unit */
255 int (*is_valid_class)(u32 class);
257 /* Request a SETCLASS to this class */
260 /* Add a channel wait for previous ops to complete */
264 struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
265 u32 num_cmdbufs, u32 num_relocs,
267 void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id,
268 u32 words, u32 offset);
269 struct host1x_job *host1x_job_get(struct host1x_job *job);
270 void host1x_job_put(struct host1x_job *job);
271 int host1x_job_pin(struct host1x_job *job, struct device *dev);
272 void host1x_job_unpin(struct host1x_job *job);
275 * subdevice probe infrastructure
278 struct host1x_device;
281 * struct host1x_driver - host1x logical device driver
282 * @driver: core driver
283 * @subdevs: table of OF device IDs matching subdevices for this driver
284 * @list: list node for the driver
285 * @probe: called when the host1x logical device is probed
286 * @remove: called when the host1x logical device is removed
287 * @shutdown: called when the host1x logical device is shut down
289 struct host1x_driver {
290 struct device_driver driver;
292 const struct of_device_id *subdevs;
293 struct list_head list;
295 int (*probe)(struct host1x_device *device);
296 int (*remove)(struct host1x_device *device);
297 void (*shutdown)(struct host1x_device *device);
300 static inline struct host1x_driver *
301 to_host1x_driver(struct device_driver *driver)
303 return container_of(driver, struct host1x_driver, driver);
306 int host1x_driver_register_full(struct host1x_driver *driver,
307 struct module *owner);
308 void host1x_driver_unregister(struct host1x_driver *driver);
310 #define host1x_driver_register(driver) \
311 host1x_driver_register_full(driver, THIS_MODULE)
313 struct host1x_device {
314 struct host1x_driver *driver;
315 struct list_head list;
318 struct mutex subdevs_lock;
319 struct list_head subdevs;
320 struct list_head active;
322 struct mutex clients_lock;
323 struct list_head clients;
328 static inline struct host1x_device *to_host1x_device(struct device *dev)
330 return container_of(dev, struct host1x_device, dev);
333 int host1x_device_init(struct host1x_device *device);
334 int host1x_device_exit(struct host1x_device *device);
336 int host1x_client_register(struct host1x_client *client);
337 int host1x_client_unregister(struct host1x_client *client);
339 struct tegra_mipi_device;
341 struct tegra_mipi_device *tegra_mipi_request(struct device *device);
342 void tegra_mipi_free(struct tegra_mipi_device *device);
343 int tegra_mipi_enable(struct tegra_mipi_device *device);
344 int tegra_mipi_disable(struct tegra_mipi_device *device);
345 int tegra_mipi_calibrate(struct tegra_mipi_device *device);