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