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_GR3D = 0x60,
34 struct host1x_client_ops {
35 int (*init)(struct host1x_client *client);
36 int (*exit)(struct host1x_client *client);
39 struct host1x_client {
40 struct list_head list;
41 struct device *parent;
44 const struct host1x_client_ops *ops;
46 enum host1x_class class;
47 struct host1x_channel *channel;
49 struct host1x_syncpt **syncpts;
50 unsigned int num_syncpts;
54 * host1x buffer objects
60 struct host1x_bo_ops {
61 struct host1x_bo *(*get)(struct host1x_bo *bo);
62 void (*put)(struct host1x_bo *bo);
63 dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt);
64 void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt);
65 void *(*mmap)(struct host1x_bo *bo);
66 void (*munmap)(struct host1x_bo *bo, void *addr);
67 void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum);
68 void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr);
72 const struct host1x_bo_ops *ops;
75 static inline void host1x_bo_init(struct host1x_bo *bo,
76 const struct host1x_bo_ops *ops)
81 static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
83 return bo->ops->get(bo);
86 static inline void host1x_bo_put(struct host1x_bo *bo)
91 static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo,
92 struct sg_table **sgt)
94 return bo->ops->pin(bo, sgt);
97 static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt)
99 bo->ops->unpin(bo, sgt);
102 static inline void *host1x_bo_mmap(struct host1x_bo *bo)
104 return bo->ops->mmap(bo);
107 static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
109 bo->ops->munmap(bo, addr);
112 static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
114 return bo->ops->kmap(bo, pagenum);
117 static inline void host1x_bo_kunmap(struct host1x_bo *bo,
118 unsigned int pagenum, void *addr)
120 bo->ops->kunmap(bo, pagenum, addr);
127 #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
128 #define HOST1X_SYNCPT_HAS_BASE (1 << 1)
130 struct host1x_syncpt_base;
131 struct host1x_syncpt;
134 struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
135 u32 host1x_syncpt_id(struct host1x_syncpt *sp);
136 u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
137 u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
138 int host1x_syncpt_incr(struct host1x_syncpt *sp);
139 u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
140 int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
142 struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
143 unsigned long flags);
144 void host1x_syncpt_free(struct host1x_syncpt *sp);
146 struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
147 u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
153 struct host1x_channel;
156 struct host1x_channel *host1x_channel_request(struct device *dev);
157 void host1x_channel_free(struct host1x_channel *channel);
158 struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
159 void host1x_channel_put(struct host1x_channel *channel);
160 int host1x_job_submit(struct host1x_job *job);
166 struct host1x_reloc {
168 struct host1x_bo *bo;
169 unsigned long offset;
172 struct host1x_bo *bo;
173 unsigned long offset;
179 /* When refcount goes to zero, job can be freed */
183 struct list_head list;
185 /* Channel where job is submitted to */
186 struct host1x_channel *channel;
190 /* Gathers and their memory */
191 struct host1x_job_gather *gathers;
192 unsigned int num_gathers;
194 /* Wait checks to be processed at submit time */
195 struct host1x_waitchk *waitchk;
196 unsigned int num_waitchk;
199 /* Array of handles to be pinned & unpinned */
200 struct host1x_reloc *relocarray;
201 unsigned int num_relocs;
202 struct host1x_job_unpin_data *unpins;
203 unsigned int num_unpins;
205 dma_addr_t *addr_phys;
206 dma_addr_t *gather_addr_phys;
207 dma_addr_t *reloc_addr_phys;
209 /* Sync point id, number of increments and end related to the submit */
214 /* Maximum time to wait for this job */
215 unsigned int timeout;
217 /* Index and number of slots used in the push buffer */
218 unsigned int first_get;
219 unsigned int num_slots;
221 /* Copy of gathers */
222 size_t gather_copy_size;
223 dma_addr_t gather_copy;
224 u8 *gather_copy_mapped;
226 /* Check if register is marked as an address reg */
227 int (*is_addr_reg)(struct device *dev, u32 reg, 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,
239 void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id,
240 u32 words, u32 offset);
241 struct host1x_job *host1x_job_get(struct host1x_job *job);
242 void host1x_job_put(struct host1x_job *job);
243 int host1x_job_pin(struct host1x_job *job, struct device *dev);
244 void host1x_job_unpin(struct host1x_job *job);
247 * subdevice probe infrastructure
250 struct host1x_device;
252 struct host1x_driver {
253 const struct of_device_id *subdevs;
254 struct list_head list;
257 int (*probe)(struct host1x_device *device);
258 int (*remove)(struct host1x_device *device);
261 int host1x_driver_register(struct host1x_driver *driver);
262 void host1x_driver_unregister(struct host1x_driver *driver);
264 struct host1x_device {
265 struct host1x_driver *driver;
266 struct list_head list;
269 struct mutex subdevs_lock;
270 struct list_head subdevs;
271 struct list_head active;
273 struct mutex clients_lock;
274 struct list_head clients;
277 static inline struct host1x_device *to_host1x_device(struct device *dev)
279 return container_of(dev, struct host1x_device, dev);
282 int host1x_device_init(struct host1x_device *device);
283 int host1x_device_exit(struct host1x_device *device);
285 int host1x_client_register(struct host1x_client *client);
286 int host1x_client_unregister(struct host1x_client *client);
288 struct tegra_mipi_device;
290 struct tegra_mipi_device *tegra_mipi_request(struct device *device);
291 void tegra_mipi_free(struct tegra_mipi_device *device);
292 int tegra_mipi_calibrate(struct tegra_mipi_device *device);