blob: 840a8ad627b2180a08911f472b4f20ace1f2c188 [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,
Arto Merilainen0ae797a2016-12-14 13:16:13 +020029 HOST1X_CLASS_VIC = 0x5D,
Thierry Reding5f60ed02013-02-28 08:08:01 +010030 HOST1X_CLASS_GR3D = 0x60,
Terje Bergstrom65793242013-03-22 16:34:03 +020031};
32
Thierry Reding53fa7f72013-09-24 15:35:40 +020033struct host1x_client;
34
Thierry Reding466749f2017-04-10 12:27:01 +020035/**
36 * struct host1x_client_ops - host1x client operations
37 * @init: host1x client initialization code
38 * @exit: host1x client tear down code
39 */
Thierry Reding53fa7f72013-09-24 15:35:40 +020040struct host1x_client_ops {
41 int (*init)(struct host1x_client *client);
42 int (*exit)(struct host1x_client *client);
43};
44
Thierry Reding466749f2017-04-10 12:27:01 +020045/**
46 * struct host1x_client - host1x client structure
47 * @list: list node for the host1x client
48 * @parent: pointer to struct device representing the host1x controller
49 * @dev: pointer to struct device backing this host1x client
50 * @ops: host1x client operations
51 * @class: host1x class represented by this client
52 * @channel: host1x channel associated with this client
53 * @syncpts: array of syncpoints requested for this client
54 * @num_syncpts: number of syncpoints requested for this client
55 */
Thierry Reding53fa7f72013-09-24 15:35:40 +020056struct host1x_client {
57 struct list_head list;
Thierry Reding776dc382013-10-14 14:43:22 +020058 struct device *parent;
Thierry Reding53fa7f72013-09-24 15:35:40 +020059 struct device *dev;
60
61 const struct host1x_client_ops *ops;
62
63 enum host1x_class class;
64 struct host1x_channel *channel;
65
66 struct host1x_syncpt **syncpts;
67 unsigned int num_syncpts;
68};
69
Thierry Reding35d747a2013-09-24 16:30:32 +020070/*
71 * host1x buffer objects
72 */
73
74struct host1x_bo;
75struct sg_table;
76
77struct host1x_bo_ops {
78 struct host1x_bo *(*get)(struct host1x_bo *bo);
79 void (*put)(struct host1x_bo *bo);
80 dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt);
81 void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt);
82 void *(*mmap)(struct host1x_bo *bo);
83 void (*munmap)(struct host1x_bo *bo, void *addr);
84 void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum);
85 void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr);
86};
87
88struct host1x_bo {
89 const struct host1x_bo_ops *ops;
90};
91
92static inline void host1x_bo_init(struct host1x_bo *bo,
93 const struct host1x_bo_ops *ops)
94{
95 bo->ops = ops;
96}
97
98static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
99{
100 return bo->ops->get(bo);
101}
102
103static inline void host1x_bo_put(struct host1x_bo *bo)
104{
105 bo->ops->put(bo);
106}
107
108static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo,
109 struct sg_table **sgt)
110{
111 return bo->ops->pin(bo, sgt);
112}
113
114static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt)
115{
116 bo->ops->unpin(bo, sgt);
117}
118
119static inline void *host1x_bo_mmap(struct host1x_bo *bo)
120{
121 return bo->ops->mmap(bo);
122}
123
124static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
125{
126 bo->ops->munmap(bo, addr);
127}
128
129static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
130{
131 return bo->ops->kmap(bo, pagenum);
132}
133
134static inline void host1x_bo_kunmap(struct host1x_bo *bo,
135 unsigned int pagenum, void *addr)
136{
137 bo->ops->kunmap(bo, pagenum, addr);
138}
139
140/*
141 * host1x syncpoints
142 */
143
Arto Merilainen8736fe82013-10-14 15:21:52 +0300144#define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
Arto Merilainenf5a954f2013-10-14 15:21:53 +0300145#define HOST1X_SYNCPT_HAS_BASE (1 << 1)
Arto Merilainen8736fe82013-10-14 15:21:52 +0300146
Arto Merilainenf5a954f2013-10-14 15:21:53 +0300147struct host1x_syncpt_base;
Thierry Reding35d747a2013-09-24 16:30:32 +0200148struct host1x_syncpt;
149struct host1x;
150
151struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
152u32 host1x_syncpt_id(struct host1x_syncpt *sp);
153u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
154u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
Thierry Redingb4a201442015-01-28 14:29:02 +0100155u32 host1x_syncpt_read(struct host1x_syncpt *sp);
Thierry Reding35d747a2013-09-24 16:30:32 +0200156int host1x_syncpt_incr(struct host1x_syncpt *sp);
Bryan Wu64400c32014-02-19 14:48:36 -0800157u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
Thierry Reding35d747a2013-09-24 16:30:32 +0200158int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
159 u32 *value);
160struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
Arto Merilainen8736fe82013-10-14 15:21:52 +0300161 unsigned long flags);
Thierry Reding35d747a2013-09-24 16:30:32 +0200162void host1x_syncpt_free(struct host1x_syncpt *sp);
163
Arto Merilainenf5a954f2013-10-14 15:21:53 +0300164struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
165u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
166
Thierry Reding35d747a2013-09-24 16:30:32 +0200167/*
168 * host1x channel
169 */
170
171struct host1x_channel;
172struct host1x_job;
173
174struct host1x_channel *host1x_channel_request(struct device *dev);
175void host1x_channel_free(struct host1x_channel *channel);
176struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
177void host1x_channel_put(struct host1x_channel *channel);
178int host1x_job_submit(struct host1x_job *job);
179
180/*
181 * host1x job
182 */
183
184struct host1x_reloc {
Thierry Reding961e3be2014-06-10 10:25:00 +0200185 struct {
186 struct host1x_bo *bo;
187 unsigned long offset;
188 } cmdbuf;
189 struct {
190 struct host1x_bo *bo;
191 unsigned long offset;
192 } target;
193 unsigned long shift;
Thierry Reding35d747a2013-09-24 16:30:32 +0200194};
195
196struct host1x_job {
197 /* When refcount goes to zero, job can be freed */
198 struct kref ref;
199
200 /* List entry */
201 struct list_head list;
202
203 /* Channel where job is submitted to */
204 struct host1x_channel *channel;
205
206 u32 client;
207
208 /* Gathers and their memory */
209 struct host1x_job_gather *gathers;
210 unsigned int num_gathers;
211
212 /* Wait checks to be processed at submit time */
213 struct host1x_waitchk *waitchk;
214 unsigned int num_waitchk;
215 u32 waitchk_mask;
216
217 /* Array of handles to be pinned & unpinned */
218 struct host1x_reloc *relocarray;
219 unsigned int num_relocs;
220 struct host1x_job_unpin_data *unpins;
221 unsigned int num_unpins;
222
223 dma_addr_t *addr_phys;
224 dma_addr_t *gather_addr_phys;
225 dma_addr_t *reloc_addr_phys;
226
227 /* Sync point id, number of increments and end related to the submit */
228 u32 syncpt_id;
229 u32 syncpt_incrs;
230 u32 syncpt_end;
231
232 /* Maximum time to wait for this job */
233 unsigned int timeout;
234
235 /* Index and number of slots used in the push buffer */
236 unsigned int first_get;
237 unsigned int num_slots;
238
239 /* Copy of gathers */
240 size_t gather_copy_size;
241 dma_addr_t gather_copy;
242 u8 *gather_copy_mapped;
243
244 /* Check if register is marked as an address reg */
245 int (*is_addr_reg)(struct device *dev, u32 reg, u32 class);
246
247 /* Request a SETCLASS to this class */
248 u32 class;
249
250 /* Add a channel wait for previous ops to complete */
251 bool serialize;
252};
253
254struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
255 u32 num_cmdbufs, u32 num_relocs,
256 u32 num_waitchks);
257void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id,
258 u32 words, u32 offset);
259struct host1x_job *host1x_job_get(struct host1x_job *job);
260void host1x_job_put(struct host1x_job *job);
261int host1x_job_pin(struct host1x_job *job, struct device *dev);
262void host1x_job_unpin(struct host1x_job *job);
263
Thierry Reding776dc382013-10-14 14:43:22 +0200264/*
265 * subdevice probe infrastructure
266 */
267
268struct host1x_device;
269
Thierry Reding466749f2017-04-10 12:27:01 +0200270/**
271 * struct host1x_driver - host1x logical device driver
272 * @driver: core driver
273 * @subdevs: table of OF device IDs matching subdevices for this driver
274 * @list: list node for the driver
275 * @probe: called when the host1x logical device is probed
276 * @remove: called when the host1x logical device is removed
277 * @shutdown: called when the host1x logical device is shut down
278 */
Thierry Reding776dc382013-10-14 14:43:22 +0200279struct host1x_driver {
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100280 struct device_driver driver;
281
Thierry Reding776dc382013-10-14 14:43:22 +0200282 const struct of_device_id *subdevs;
283 struct list_head list;
Thierry Reding776dc382013-10-14 14:43:22 +0200284
285 int (*probe)(struct host1x_device *device);
286 int (*remove)(struct host1x_device *device);
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100287 void (*shutdown)(struct host1x_device *device);
Thierry Reding776dc382013-10-14 14:43:22 +0200288};
289
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100290static inline struct host1x_driver *
291to_host1x_driver(struct device_driver *driver)
292{
293 return container_of(driver, struct host1x_driver, driver);
294}
295
296int host1x_driver_register_full(struct host1x_driver *driver,
297 struct module *owner);
Thierry Reding776dc382013-10-14 14:43:22 +0200298void host1x_driver_unregister(struct host1x_driver *driver);
299
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100300#define host1x_driver_register(driver) \
301 host1x_driver_register_full(driver, THIS_MODULE)
302
Thierry Reding776dc382013-10-14 14:43:22 +0200303struct host1x_device {
304 struct host1x_driver *driver;
305 struct list_head list;
306 struct device dev;
307
308 struct mutex subdevs_lock;
309 struct list_head subdevs;
310 struct list_head active;
311
312 struct mutex clients_lock;
313 struct list_head clients;
Thierry Reding536e1712014-11-05 11:43:26 +0100314
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100315 bool registered;
Thierry Reding776dc382013-10-14 14:43:22 +0200316};
317
318static inline struct host1x_device *to_host1x_device(struct device *dev)
319{
320 return container_of(dev, struct host1x_device, dev);
321}
322
323int host1x_device_init(struct host1x_device *device);
324int host1x_device_exit(struct host1x_device *device);
325
326int host1x_client_register(struct host1x_client *client);
327int host1x_client_unregister(struct host1x_client *client);
328
Thierry Reding4de6a2d2013-09-02 09:48:53 +0200329struct tegra_mipi_device;
330
331struct tegra_mipi_device *tegra_mipi_request(struct device *device);
332void tegra_mipi_free(struct tegra_mipi_device *device);
Thierry Reding87904c32016-08-12 16:00:53 +0200333int tegra_mipi_enable(struct tegra_mipi_device *device);
334int tegra_mipi_disable(struct tegra_mipi_device *device);
Thierry Reding4de6a2d2013-09-02 09:48:53 +0200335int tegra_mipi_calibrate(struct tegra_mipi_device *device);
336
Terje Bergstrom65793242013-03-22 16:34:03 +0200337#endif