drm/tegra: Introduce tegra_drm_submit()
[deliverable/linux.git] / include / linux / host1x.h
CommitLineData
6579324a 1/*
6579324a
TB
2 * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved.
3 *
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.
8 *
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
12 * more details.
13 *
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.
17 */
18
19#ifndef __LINUX_HOST1X_H
20#define __LINUX_HOST1X_H
21
776dc384 22#include <linux/device.h>
35d747a8
TR
23#include <linux/types.h>
24
6579324a 25enum host1x_class {
e1e90644
TR
26 HOST1X_CLASS_HOST1X = 0x1,
27 HOST1X_CLASS_GR2D = 0x51,
28 HOST1X_CLASS_GR2D_SB = 0x52,
6579324a
TB
29};
30
53fa7f72
TR
31struct host1x_client;
32
33struct host1x_client_ops {
34 int (*init)(struct host1x_client *client);
35 int (*exit)(struct host1x_client *client);
36};
37
38struct host1x_client {
39 struct list_head list;
776dc384 40 struct device *parent;
53fa7f72
TR
41 struct device *dev;
42
43 const struct host1x_client_ops *ops;
44
45 enum host1x_class class;
46 struct host1x_channel *channel;
47
48 struct host1x_syncpt **syncpts;
49 unsigned int num_syncpts;
50};
51
35d747a8
TR
52/*
53 * host1x buffer objects
54 */
55
56struct host1x_bo;
57struct sg_table;
58
59struct 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);
68};
69
70struct host1x_bo {
71 const struct host1x_bo_ops *ops;
72};
73
74static inline void host1x_bo_init(struct host1x_bo *bo,
75 const struct host1x_bo_ops *ops)
76{
77 bo->ops = ops;
78}
79
80static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
81{
82 return bo->ops->get(bo);
83}
84
85static inline void host1x_bo_put(struct host1x_bo *bo)
86{
87 bo->ops->put(bo);
88}
89
90static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo,
91 struct sg_table **sgt)
92{
93 return bo->ops->pin(bo, sgt);
94}
95
96static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt)
97{
98 bo->ops->unpin(bo, sgt);
99}
100
101static inline void *host1x_bo_mmap(struct host1x_bo *bo)
102{
103 return bo->ops->mmap(bo);
104}
105
106static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
107{
108 bo->ops->munmap(bo, addr);
109}
110
111static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
112{
113 return bo->ops->kmap(bo, pagenum);
114}
115
116static inline void host1x_bo_kunmap(struct host1x_bo *bo,
117 unsigned int pagenum, void *addr)
118{
119 bo->ops->kunmap(bo, pagenum, addr);
120}
121
122/*
123 * host1x syncpoints
124 */
125
126struct host1x_syncpt;
127struct host1x;
128
129struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
130u32 host1x_syncpt_id(struct host1x_syncpt *sp);
131u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
132u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
133int host1x_syncpt_incr(struct host1x_syncpt *sp);
134int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
135 u32 *value);
136struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
137 bool client_managed);
138void host1x_syncpt_free(struct host1x_syncpt *sp);
139
140/*
141 * host1x channel
142 */
143
144struct host1x_channel;
145struct host1x_job;
146
147struct host1x_channel *host1x_channel_request(struct device *dev);
148void host1x_channel_free(struct host1x_channel *channel);
149struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
150void host1x_channel_put(struct host1x_channel *channel);
151int host1x_job_submit(struct host1x_job *job);
152
153/*
154 * host1x job
155 */
156
157struct host1x_reloc {
158 struct host1x_bo *cmdbuf;
159 u32 cmdbuf_offset;
160 struct host1x_bo *target;
161 u32 target_offset;
162 u32 shift;
163 u32 pad;
164};
165
166struct host1x_job {
167 /* When refcount goes to zero, job can be freed */
168 struct kref ref;
169
170 /* List entry */
171 struct list_head list;
172
173 /* Channel where job is submitted to */
174 struct host1x_channel *channel;
175
176 u32 client;
177
178 /* Gathers and their memory */
179 struct host1x_job_gather *gathers;
180 unsigned int num_gathers;
181
182 /* Wait checks to be processed at submit time */
183 struct host1x_waitchk *waitchk;
184 unsigned int num_waitchk;
185 u32 waitchk_mask;
186
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;
192
193 dma_addr_t *addr_phys;
194 dma_addr_t *gather_addr_phys;
195 dma_addr_t *reloc_addr_phys;
196
197 /* Sync point id, number of increments and end related to the submit */
198 u32 syncpt_id;
199 u32 syncpt_incrs;
200 u32 syncpt_end;
201
202 /* Maximum time to wait for this job */
203 unsigned int timeout;
204
205 /* Index and number of slots used in the push buffer */
206 unsigned int first_get;
207 unsigned int num_slots;
208
209 /* Copy of gathers */
210 size_t gather_copy_size;
211 dma_addr_t gather_copy;
212 u8 *gather_copy_mapped;
213
214 /* Check if register is marked as an address reg */
215 int (*is_addr_reg)(struct device *dev, u32 reg, u32 class);
216
217 /* Request a SETCLASS to this class */
218 u32 class;
219
220 /* Add a channel wait for previous ops to complete */
221 bool serialize;
222};
223
224struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
225 u32 num_cmdbufs, u32 num_relocs,
226 u32 num_waitchks);
227void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id,
228 u32 words, u32 offset);
229struct host1x_job *host1x_job_get(struct host1x_job *job);
230void host1x_job_put(struct host1x_job *job);
231int host1x_job_pin(struct host1x_job *job, struct device *dev);
232void host1x_job_unpin(struct host1x_job *job);
233
776dc384
TR
234/*
235 * subdevice probe infrastructure
236 */
237
238struct host1x_device;
239
240struct host1x_driver {
241 const struct of_device_id *subdevs;
242 struct list_head list;
243 const char *name;
244
245 int (*probe)(struct host1x_device *device);
246 int (*remove)(struct host1x_device *device);
247};
248
249int host1x_driver_register(struct host1x_driver *driver);
250void host1x_driver_unregister(struct host1x_driver *driver);
251
252struct host1x_device {
253 struct host1x_driver *driver;
254 struct list_head list;
255 struct device dev;
256
257 struct mutex subdevs_lock;
258 struct list_head subdevs;
259 struct list_head active;
260
261 struct mutex clients_lock;
262 struct list_head clients;
263};
264
265static inline struct host1x_device *to_host1x_device(struct device *dev)
266{
267 return container_of(dev, struct host1x_device, dev);
268}
269
270int host1x_device_init(struct host1x_device *device);
271int host1x_device_exit(struct host1x_device *device);
272
273int host1x_client_register(struct host1x_client *client);
274int host1x_client_unregister(struct host1x_client *client);
275
6579324a 276#endif
This page took 0.102529 seconds and 5 git commands to generate.