drm/tegra: Move subdevice infrastructure to host1x
[firefly-linux-kernel-4.4.55.git] / include / linux / host1x.h
1 /*
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
22 #include <linux/device.h>
23 #include <linux/types.h>
24
25 enum host1x_class {
26         HOST1X_CLASS_HOST1X = 0x1,
27         HOST1X_CLASS_GR2D = 0x51,
28         HOST1X_CLASS_GR2D_SB = 0x52,
29 };
30
31 struct host1x_client;
32
33 struct host1x_client_ops {
34         int (*init)(struct host1x_client *client);
35         int (*exit)(struct host1x_client *client);
36 };
37
38 struct host1x_client {
39         struct list_head list;
40         struct device *parent;
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
52 /*
53  * host1x buffer objects
54  */
55
56 struct host1x_bo;
57 struct sg_table;
58
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);
68 };
69
70 struct host1x_bo {
71         const struct host1x_bo_ops *ops;
72 };
73
74 static inline void host1x_bo_init(struct host1x_bo *bo,
75                                   const struct host1x_bo_ops *ops)
76 {
77         bo->ops = ops;
78 }
79
80 static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
81 {
82         return bo->ops->get(bo);
83 }
84
85 static inline void host1x_bo_put(struct host1x_bo *bo)
86 {
87         bo->ops->put(bo);
88 }
89
90 static 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
96 static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt)
97 {
98         bo->ops->unpin(bo, sgt);
99 }
100
101 static inline void *host1x_bo_mmap(struct host1x_bo *bo)
102 {
103         return bo->ops->mmap(bo);
104 }
105
106 static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
107 {
108         bo->ops->munmap(bo, addr);
109 }
110
111 static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
112 {
113         return bo->ops->kmap(bo, pagenum);
114 }
115
116 static 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
126 struct host1x_syncpt;
127 struct host1x;
128
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,
135                        u32 *value);
136 struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
137                                             bool client_managed);
138 void host1x_syncpt_free(struct host1x_syncpt *sp);
139
140 /*
141  * host1x channel
142  */
143
144 struct host1x_channel;
145 struct host1x_job;
146
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);
152
153 /*
154  * host1x job
155  */
156
157 struct 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
166 struct 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
224 struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
225                                     u32 num_cmdbufs, u32 num_relocs,
226                                     u32 num_waitchks);
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);
233
234 /*
235  * subdevice probe infrastructure
236  */
237
238 struct host1x_device;
239
240 struct 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
249 int host1x_driver_register(struct host1x_driver *driver);
250 void host1x_driver_unregister(struct host1x_driver *driver);
251
252 struct 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
265 static inline struct host1x_device *to_host1x_device(struct device *dev)
266 {
267         return container_of(dev, struct host1x_device, dev);
268 }
269
270 int host1x_device_init(struct host1x_device *device);
271 int host1x_device_exit(struct host1x_device *device);
272
273 int host1x_client_register(struct host1x_client *client);
274 int host1x_client_unregister(struct host1x_client *client);
275
276 #endif