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,
35 struct host1x_client_ops {
36 int (*init)(struct host1x_client *client);
37 int (*exit)(struct host1x_client *client);
40 struct host1x_client {
41 struct list_head list;
42 struct device *parent;
45 const struct host1x_client_ops *ops;
47 enum host1x_class class;
48 struct host1x_channel *channel;
50 struct host1x_syncpt **syncpts;
51 unsigned int num_syncpts;
55 * host1x buffer objects
61 struct host1x_bo_ops {
62 struct host1x_bo *(*get)(struct host1x_bo *bo);
63 void (*put)(struct host1x_bo *bo);
64 dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt);
65 void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt);
66 void *(*mmap)(struct host1x_bo *bo);
67 void (*munmap)(struct host1x_bo *bo, void *addr);
68 void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum);
69 void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr);
73 const struct host1x_bo_ops *ops;
76 static inline void host1x_bo_init(struct host1x_bo *bo,
77 const struct host1x_bo_ops *ops)
82 static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
84 return bo->ops->get(bo);
87 static inline void host1x_bo_put(struct host1x_bo *bo)
92 static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo,
93 struct sg_table **sgt)
95 return bo->ops->pin(bo, sgt);
98 static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt)
100 bo->ops->unpin(bo, sgt);
103 static inline void *host1x_bo_mmap(struct host1x_bo *bo)
105 return bo->ops->mmap(bo);
108 static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
110 bo->ops->munmap(bo, addr);
113 static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
115 return bo->ops->kmap(bo, pagenum);
118 static inline void host1x_bo_kunmap(struct host1x_bo *bo,
119 unsigned int pagenum, void *addr)
121 bo->ops->kunmap(bo, pagenum, addr);
128 #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
129 #define HOST1X_SYNCPT_HAS_BASE (1 << 1)
131 struct host1x_syncpt_base;
132 struct host1x_syncpt;
135 struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
136 u32 host1x_syncpt_id(struct host1x_syncpt *sp);
137 u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
138 u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
139 u32 host1x_syncpt_read(struct host1x_syncpt *sp);
140 int host1x_syncpt_incr(struct host1x_syncpt *sp);
141 u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
142 int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
144 struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
145 unsigned long flags);
146 void host1x_syncpt_free(struct host1x_syncpt *sp);
148 struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
149 u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
155 struct host1x_channel;
158 struct host1x_channel *host1x_channel_request(struct device *dev);
159 void host1x_channel_free(struct host1x_channel *channel);
160 struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
161 void host1x_channel_put(struct host1x_channel *channel);
162 int host1x_job_submit(struct host1x_job *job);
168 struct host1x_reloc {
170 struct host1x_bo *bo;
171 unsigned long offset;
174 struct host1x_bo *bo;
175 unsigned long offset;
181 /* When refcount goes to zero, job can be freed */
185 struct list_head list;
187 /* Channel where job is submitted to */
188 struct host1x_channel *channel;
192 /* Gathers and their memory */
193 struct host1x_job_gather *gathers;
194 unsigned int num_gathers;
196 /* Wait checks to be processed at submit time */
197 struct host1x_waitchk *waitchk;
198 unsigned int num_waitchk;
201 /* Array of handles to be pinned & unpinned */
202 struct host1x_reloc *relocarray;
203 unsigned int num_relocs;
204 struct host1x_job_unpin_data *unpins;
205 unsigned int num_unpins;
207 dma_addr_t *addr_phys;
208 dma_addr_t *gather_addr_phys;
209 dma_addr_t *reloc_addr_phys;
211 /* Sync point id, number of increments and end related to the submit */
216 /* Maximum time to wait for this job */
217 unsigned int timeout;
219 /* Index and number of slots used in the push buffer */
220 unsigned int first_get;
221 unsigned int num_slots;
223 /* Copy of gathers */
224 size_t gather_copy_size;
225 dma_addr_t gather_copy;
226 u8 *gather_copy_mapped;
228 /* Check if register is marked as an address reg */
229 int (*is_addr_reg)(struct device *dev, u32 reg, u32 class);
231 /* Request a SETCLASS to this class */
234 /* Add a channel wait for previous ops to complete */
238 struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
239 u32 num_cmdbufs, u32 num_relocs,
241 void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id,
242 u32 words, u32 offset);
243 struct host1x_job *host1x_job_get(struct host1x_job *job);
244 void host1x_job_put(struct host1x_job *job);
245 int host1x_job_pin(struct host1x_job *job, struct device *dev);
246 void host1x_job_unpin(struct host1x_job *job);
249 * subdevice probe infrastructure
252 struct host1x_device;
254 struct host1x_driver {
255 struct device_driver driver;
257 const struct of_device_id *subdevs;
258 struct list_head list;
260 int (*probe)(struct host1x_device *device);
261 int (*remove)(struct host1x_device *device);
262 void (*shutdown)(struct host1x_device *device);
265 static inline struct host1x_driver *
266 to_host1x_driver(struct device_driver *driver)
268 return container_of(driver, struct host1x_driver, driver);
271 int host1x_driver_register_full(struct host1x_driver *driver,
272 struct module *owner);
273 void host1x_driver_unregister(struct host1x_driver *driver);
275 #define host1x_driver_register(driver) \
276 host1x_driver_register_full(driver, THIS_MODULE)
278 struct host1x_device {
279 struct host1x_driver *driver;
280 struct list_head list;
283 struct mutex subdevs_lock;
284 struct list_head subdevs;
285 struct list_head active;
287 struct mutex clients_lock;
288 struct list_head clients;
293 static inline struct host1x_device *to_host1x_device(struct device *dev)
295 return container_of(dev, struct host1x_device, dev);
298 int host1x_device_init(struct host1x_device *device);
299 int host1x_device_exit(struct host1x_device *device);
301 int host1x_client_register(struct host1x_client *client);
302 int host1x_client_unregister(struct host1x_client *client);
304 struct tegra_mipi_device;
306 struct tegra_mipi_device *tegra_mipi_request(struct device *device);
307 void tegra_mipi_free(struct tegra_mipi_device *device);
308 int tegra_mipi_enable(struct tegra_mipi_device *device);
309 int tegra_mipi_disable(struct tegra_mipi_device *device);
310 int tegra_mipi_calibrate(struct tegra_mipi_device *device);