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,
33 struct host1x_client_ops {
34 int (*init)(struct host1x_client *client);
35 int (*exit)(struct host1x_client *client);
38 struct host1x_client {
39 struct list_head list;
40 struct device *parent;
43 const struct host1x_client_ops *ops;
45 enum host1x_class class;
46 struct host1x_channel *channel;
48 struct host1x_syncpt **syncpts;
49 unsigned int num_syncpts;
53 * host1x buffer objects
59 struct host1x_bo_ops {
60 struct host1x_bo *(*get)(struct host1x_bo *bo);
61 void (*put)(struct host1x_bo *bo);
62 dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt);
63 void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt);
64 void *(*mmap)(struct host1x_bo *bo);
65 void (*munmap)(struct host1x_bo *bo, void *addr);
66 void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum);
67 void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr);
71 const struct host1x_bo_ops *ops;
74 static inline void host1x_bo_init(struct host1x_bo *bo,
75 const struct host1x_bo_ops *ops)
80 static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
82 return bo->ops->get(bo);
85 static inline void host1x_bo_put(struct host1x_bo *bo)
90 static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo,
91 struct sg_table **sgt)
93 return bo->ops->pin(bo, sgt);
96 static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt)
98 bo->ops->unpin(bo, sgt);
101 static inline void *host1x_bo_mmap(struct host1x_bo *bo)
103 return bo->ops->mmap(bo);
106 static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
108 bo->ops->munmap(bo, addr);
111 static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
113 return bo->ops->kmap(bo, pagenum);
116 static inline void host1x_bo_kunmap(struct host1x_bo *bo,
117 unsigned int pagenum, void *addr)
119 bo->ops->kunmap(bo, pagenum, addr);
126 struct host1x_syncpt;
129 struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
130 u32 host1x_syncpt_id(struct host1x_syncpt *sp);
131 u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
132 u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
133 int host1x_syncpt_incr(struct host1x_syncpt *sp);
134 int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
136 struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
137 bool client_managed);
138 void host1x_syncpt_free(struct host1x_syncpt *sp);
144 struct host1x_channel;
147 struct host1x_channel *host1x_channel_request(struct device *dev);
148 void host1x_channel_free(struct host1x_channel *channel);
149 struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
150 void host1x_channel_put(struct host1x_channel *channel);
151 int host1x_job_submit(struct host1x_job *job);
157 struct host1x_reloc {
158 struct host1x_bo *cmdbuf;
160 struct host1x_bo *target;
167 /* When refcount goes to zero, job can be freed */
171 struct list_head list;
173 /* Channel where job is submitted to */
174 struct host1x_channel *channel;
178 /* Gathers and their memory */
179 struct host1x_job_gather *gathers;
180 unsigned int num_gathers;
182 /* Wait checks to be processed at submit time */
183 struct host1x_waitchk *waitchk;
184 unsigned int num_waitchk;
187 /* Array of handles to be pinned & unpinned */
188 struct host1x_reloc *relocarray;
189 unsigned int num_relocs;
190 struct host1x_job_unpin_data *unpins;
191 unsigned int num_unpins;
193 dma_addr_t *addr_phys;
194 dma_addr_t *gather_addr_phys;
195 dma_addr_t *reloc_addr_phys;
197 /* Sync point id, number of increments and end related to the submit */
202 /* Maximum time to wait for this job */
203 unsigned int timeout;
205 /* Index and number of slots used in the push buffer */
206 unsigned int first_get;
207 unsigned int num_slots;
209 /* Copy of gathers */
210 size_t gather_copy_size;
211 dma_addr_t gather_copy;
212 u8 *gather_copy_mapped;
214 /* Check if register is marked as an address reg */
215 int (*is_addr_reg)(struct device *dev, u32 reg, u32 class);
217 /* Request a SETCLASS to this class */
220 /* Add a channel wait for previous ops to complete */
224 struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
225 u32 num_cmdbufs, u32 num_relocs,
227 void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id,
228 u32 words, u32 offset);
229 struct host1x_job *host1x_job_get(struct host1x_job *job);
230 void host1x_job_put(struct host1x_job *job);
231 int host1x_job_pin(struct host1x_job *job, struct device *dev);
232 void host1x_job_unpin(struct host1x_job *job);
235 * subdevice probe infrastructure
238 struct host1x_device;
240 struct host1x_driver {
241 const struct of_device_id *subdevs;
242 struct list_head list;
245 int (*probe)(struct host1x_device *device);
246 int (*remove)(struct host1x_device *device);
249 int host1x_driver_register(struct host1x_driver *driver);
250 void host1x_driver_unregister(struct host1x_driver *driver);
252 struct host1x_device {
253 struct host1x_driver *driver;
254 struct list_head list;
257 struct mutex subdevs_lock;
258 struct list_head subdevs;
259 struct list_head active;
261 struct mutex clients_lock;
262 struct list_head clients;
265 static inline struct host1x_device *to_host1x_device(struct device *dev)
267 return container_of(dev, struct host1x_device, dev);
270 int host1x_device_init(struct host1x_device *device);
271 int host1x_device_exit(struct host1x_device *device);
273 int host1x_client_register(struct host1x_client *client);
274 int host1x_client_unregister(struct host1x_client *client);