blob: 7890b553d12ec074421ded87a6722bec730fe5ee [file] [log] [blame]
Terje Bergstrom65793242013-03-22 16:34:03 +02001/*
Terje Bergstrom65793242013-03-22 16:34:03 +02002 * 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
Thierry Reding776dc382013-10-14 14:43:22 +020022#include <linux/device.h>
Thierry Reding35d747a2013-09-24 16:30:32 +020023#include <linux/types.h>
24
Terje Bergstrom65793242013-03-22 16:34:03 +020025enum host1x_class {
Thierry Redinge1e90642013-09-24 13:59:01 +020026 HOST1X_CLASS_HOST1X = 0x1,
27 HOST1X_CLASS_GR2D = 0x51,
28 HOST1X_CLASS_GR2D_SB = 0x52,
Thierry Reding5f60ed02013-02-28 08:08:01 +010029 HOST1X_CLASS_GR3D = 0x60,
Terje Bergstrom65793242013-03-22 16:34:03 +020030};
31
Thierry Reding53fa7f72013-09-24 15:35:40 +020032struct 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;
Thierry Reding776dc382013-10-14 14:43:22 +020041 struct device *parent;
Thierry Reding53fa7f72013-09-24 15:35:40 +020042 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
Thierry Reding35d747a2013-09-24 16:30:32 +020053/*
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
Arto Merilainen8736fe82013-10-14 15:21:52 +0300127#define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
Arto Merilainenf5a954f2013-10-14 15:21:53 +0300128#define HOST1X_SYNCPT_HAS_BASE (1 << 1)
Arto Merilainen8736fe82013-10-14 15:21:52 +0300129
Arto Merilainenf5a954f2013-10-14 15:21:53 +0300130struct host1x_syncpt_base;
Thierry Reding35d747a2013-09-24 16:30:32 +0200131struct host1x_syncpt;
132struct host1x;
133
134struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
135u32 host1x_syncpt_id(struct host1x_syncpt *sp);
136u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
137u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
138int host1x_syncpt_incr(struct host1x_syncpt *sp);
Bryan Wu64400c32014-02-19 14:48:36 -0800139u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
Thierry Reding35d747a2013-09-24 16:30:32 +0200140int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
141 u32 *value);
142struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
Arto Merilainen8736fe82013-10-14 15:21:52 +0300143 unsigned long flags);
Thierry Reding35d747a2013-09-24 16:30:32 +0200144void host1x_syncpt_free(struct host1x_syncpt *sp);
145
Arto Merilainenf5a954f2013-10-14 15:21:53 +0300146struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
147u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
148
Thierry Reding35d747a2013-09-24 16:30:32 +0200149/*
150 * host1x channel
151 */
152
153struct host1x_channel;
154struct host1x_job;
155
156struct host1x_channel *host1x_channel_request(struct device *dev);
157void host1x_channel_free(struct host1x_channel *channel);
158struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
159void host1x_channel_put(struct host1x_channel *channel);
160int host1x_job_submit(struct host1x_job *job);
161
162/*
163 * host1x job
164 */
165
166struct host1x_reloc {
Thierry Reding961e3be2014-06-10 10:25:00 +0200167 struct {
168 struct host1x_bo *bo;
169 unsigned long offset;
170 } cmdbuf;
171 struct {
172 struct host1x_bo *bo;
173 unsigned long offset;
174 } target;
175 unsigned long shift;
Thierry Reding35d747a2013-09-24 16:30:32 +0200176};
177
178struct host1x_job {
179 /* When refcount goes to zero, job can be freed */
180 struct kref ref;
181
182 /* List entry */
183 struct list_head list;
184
185 /* Channel where job is submitted to */
186 struct host1x_channel *channel;
187
188 u32 client;
189
190 /* Gathers and their memory */
191 struct host1x_job_gather *gathers;
192 unsigned int num_gathers;
193
194 /* Wait checks to be processed at submit time */
195 struct host1x_waitchk *waitchk;
196 unsigned int num_waitchk;
197 u32 waitchk_mask;
198
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;
204
205 dma_addr_t *addr_phys;
206 dma_addr_t *gather_addr_phys;
207 dma_addr_t *reloc_addr_phys;
208
209 /* Sync point id, number of increments and end related to the submit */
210 u32 syncpt_id;
211 u32 syncpt_incrs;
212 u32 syncpt_end;
213
214 /* Maximum time to wait for this job */
215 unsigned int timeout;
216
217 /* Index and number of slots used in the push buffer */
218 unsigned int first_get;
219 unsigned int num_slots;
220
221 /* Copy of gathers */
222 size_t gather_copy_size;
223 dma_addr_t gather_copy;
224 u8 *gather_copy_mapped;
225
226 /* Check if register is marked as an address reg */
227 int (*is_addr_reg)(struct device *dev, u32 reg, u32 class);
228
229 /* Request a SETCLASS to this class */
230 u32 class;
231
232 /* Add a channel wait for previous ops to complete */
233 bool serialize;
234};
235
236struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
237 u32 num_cmdbufs, u32 num_relocs,
238 u32 num_waitchks);
239void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id,
240 u32 words, u32 offset);
241struct host1x_job *host1x_job_get(struct host1x_job *job);
242void host1x_job_put(struct host1x_job *job);
243int host1x_job_pin(struct host1x_job *job, struct device *dev);
244void host1x_job_unpin(struct host1x_job *job);
245
Thierry Reding776dc382013-10-14 14:43:22 +0200246/*
247 * subdevice probe infrastructure
248 */
249
250struct host1x_device;
251
252struct host1x_driver {
253 const struct of_device_id *subdevs;
254 struct list_head list;
255 const char *name;
256
257 int (*probe)(struct host1x_device *device);
258 int (*remove)(struct host1x_device *device);
259};
260
261int host1x_driver_register(struct host1x_driver *driver);
262void host1x_driver_unregister(struct host1x_driver *driver);
263
264struct host1x_device {
265 struct host1x_driver *driver;
266 struct list_head list;
267 struct device dev;
268
269 struct mutex subdevs_lock;
270 struct list_head subdevs;
271 struct list_head active;
272
273 struct mutex clients_lock;
274 struct list_head clients;
Thierry Reding536e1712014-11-05 11:43:26 +0100275
276 bool bound;
Thierry Reding776dc382013-10-14 14:43:22 +0200277};
278
279static inline struct host1x_device *to_host1x_device(struct device *dev)
280{
281 return container_of(dev, struct host1x_device, dev);
282}
283
284int host1x_device_init(struct host1x_device *device);
285int host1x_device_exit(struct host1x_device *device);
286
287int host1x_client_register(struct host1x_client *client);
288int host1x_client_unregister(struct host1x_client *client);
289
Thierry Reding4de6a2d2013-09-02 09:48:53 +0200290struct tegra_mipi_device;
291
292struct tegra_mipi_device *tegra_mipi_request(struct device *device);
293void tegra_mipi_free(struct tegra_mipi_device *device);
294int tegra_mipi_calibrate(struct tegra_mipi_device *device);
295
Terje Bergstrom65793242013-03-22 16:34:03 +0200296#endif