blob: d11e89db7d7f3eb37060f92d7c5bf14e49c92f33 [file] [log] [blame]
Thomas Gleixner16216332019-05-19 15:51:31 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Terje Bergstrom65793242013-03-22 16:34:03 +02002/*
Terje Bergstrom65793242013-03-22 16:34:03 +02003 * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved.
Terje Bergstrom65793242013-03-22 16:34:03 +02004 */
5
6#ifndef __LINUX_HOST1X_H
7#define __LINUX_HOST1X_H
8
Thierry Reding776dc382013-10-14 14:43:22 +02009#include <linux/device.h>
Thierry Reding35d747a2013-09-24 16:30:32 +020010#include <linux/types.h>
11
Terje Bergstrom65793242013-03-22 16:34:03 +020012enum host1x_class {
Thierry Redinge1e90642013-09-24 13:59:01 +020013 HOST1X_CLASS_HOST1X = 0x1,
14 HOST1X_CLASS_GR2D = 0x51,
15 HOST1X_CLASS_GR2D_SB = 0x52,
Arto Merilainen0ae797a2016-12-14 13:16:13 +020016 HOST1X_CLASS_VIC = 0x5D,
Thierry Reding5f60ed02013-02-28 08:08:01 +010017 HOST1X_CLASS_GR3D = 0x60,
Terje Bergstrom65793242013-03-22 16:34:03 +020018};
19
Thierry Reding53fa7f72013-09-24 15:35:40 +020020struct host1x_client;
21
Thierry Reding466749f2017-04-10 12:27:01 +020022/**
23 * struct host1x_client_ops - host1x client operations
24 * @init: host1x client initialization code
25 * @exit: host1x client tear down code
26 */
Thierry Reding53fa7f72013-09-24 15:35:40 +020027struct host1x_client_ops {
28 int (*init)(struct host1x_client *client);
29 int (*exit)(struct host1x_client *client);
30};
31
Thierry Reding466749f2017-04-10 12:27:01 +020032/**
33 * struct host1x_client - host1x client structure
34 * @list: list node for the host1x client
35 * @parent: pointer to struct device representing the host1x controller
36 * @dev: pointer to struct device backing this host1x client
37 * @ops: host1x client operations
38 * @class: host1x class represented by this client
39 * @channel: host1x channel associated with this client
40 * @syncpts: array of syncpoints requested for this client
41 * @num_syncpts: number of syncpoints requested for this client
42 */
Thierry Reding53fa7f72013-09-24 15:35:40 +020043struct host1x_client {
44 struct list_head list;
Thierry Reding776dc382013-10-14 14:43:22 +020045 struct device *parent;
Thierry Reding53fa7f72013-09-24 15:35:40 +020046 struct device *dev;
47
48 const struct host1x_client_ops *ops;
49
50 enum host1x_class class;
51 struct host1x_channel *channel;
52
53 struct host1x_syncpt **syncpts;
54 unsigned int num_syncpts;
55};
56
Thierry Reding35d747a2013-09-24 16:30:32 +020057/*
58 * host1x buffer objects
59 */
60
61struct host1x_bo;
62struct sg_table;
63
64struct host1x_bo_ops {
65 struct host1x_bo *(*get)(struct host1x_bo *bo);
66 void (*put)(struct host1x_bo *bo);
67 dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt);
68 void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt);
69 void *(*mmap)(struct host1x_bo *bo);
70 void (*munmap)(struct host1x_bo *bo, void *addr);
Thierry Reding35d747a2013-09-24 16:30:32 +020071};
72
73struct host1x_bo {
74 const struct host1x_bo_ops *ops;
75};
76
77static inline void host1x_bo_init(struct host1x_bo *bo,
78 const struct host1x_bo_ops *ops)
79{
80 bo->ops = ops;
81}
82
83static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
84{
85 return bo->ops->get(bo);
86}
87
88static inline void host1x_bo_put(struct host1x_bo *bo)
89{
90 bo->ops->put(bo);
91}
92
93static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo,
94 struct sg_table **sgt)
95{
96 return bo->ops->pin(bo, sgt);
97}
98
99static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt)
100{
101 bo->ops->unpin(bo, sgt);
102}
103
104static inline void *host1x_bo_mmap(struct host1x_bo *bo)
105{
106 return bo->ops->mmap(bo);
107}
108
109static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
110{
111 bo->ops->munmap(bo, addr);
112}
113
Thierry Reding35d747a2013-09-24 16:30:32 +0200114/*
115 * host1x syncpoints
116 */
117
Arto Merilainen8736fe82013-10-14 15:21:52 +0300118#define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
Arto Merilainenf5a954f2013-10-14 15:21:53 +0300119#define HOST1X_SYNCPT_HAS_BASE (1 << 1)
Arto Merilainen8736fe82013-10-14 15:21:52 +0300120
Arto Merilainenf5a954f2013-10-14 15:21:53 +0300121struct host1x_syncpt_base;
Thierry Reding35d747a2013-09-24 16:30:32 +0200122struct host1x_syncpt;
123struct host1x;
124
125struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
126u32 host1x_syncpt_id(struct host1x_syncpt *sp);
127u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
128u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
Thierry Redingb4a201442015-01-28 14:29:02 +0100129u32 host1x_syncpt_read(struct host1x_syncpt *sp);
Thierry Reding35d747a2013-09-24 16:30:32 +0200130int host1x_syncpt_incr(struct host1x_syncpt *sp);
Bryan Wu64400c32014-02-19 14:48:36 -0800131u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
Thierry Reding35d747a2013-09-24 16:30:32 +0200132int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
133 u32 *value);
Thierry Reding617dd7c2017-08-30 12:48:31 +0200134struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
Arto Merilainen8736fe82013-10-14 15:21:52 +0300135 unsigned long flags);
Thierry Reding35d747a2013-09-24 16:30:32 +0200136void host1x_syncpt_free(struct host1x_syncpt *sp);
137
Arto Merilainenf5a954f2013-10-14 15:21:53 +0300138struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
139u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
140
Thierry Reding35d747a2013-09-24 16:30:32 +0200141/*
142 * host1x channel
143 */
144
145struct host1x_channel;
146struct host1x_job;
147
148struct host1x_channel *host1x_channel_request(struct device *dev);
Thierry Reding35d747a2013-09-24 16:30:32 +0200149struct 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 {
Thierry Reding961e3be2014-06-10 10:25:00 +0200158 struct {
159 struct host1x_bo *bo;
160 unsigned long offset;
161 } cmdbuf;
162 struct {
163 struct host1x_bo *bo;
164 unsigned long offset;
165 } target;
166 unsigned long shift;
Thierry Reding35d747a2013-09-24 16:30:32 +0200167};
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
Thierry Redingbf3d41c2018-05-16 14:12:33 +0200179 /* client where the job originated */
180 struct host1x_client *client;
Thierry Reding35d747a2013-09-24 16:30:32 +0200181
182 /* Gathers and their memory */
183 struct host1x_job_gather *gathers;
184 unsigned int num_gathers;
185
Thierry Reding35d747a2013-09-24 16:30:32 +0200186 /* Array of handles to be pinned & unpinned */
Thierry Reding06490bb2018-05-16 16:58:44 +0200187 struct host1x_reloc *relocs;
Thierry Reding35d747a2013-09-24 16:30:32 +0200188 unsigned int num_relocs;
189 struct host1x_job_unpin_data *unpins;
190 unsigned int num_unpins;
191
192 dma_addr_t *addr_phys;
193 dma_addr_t *gather_addr_phys;
194 dma_addr_t *reloc_addr_phys;
195
196 /* Sync point id, number of increments and end related to the submit */
197 u32 syncpt_id;
198 u32 syncpt_incrs;
199 u32 syncpt_end;
200
201 /* Maximum time to wait for this job */
202 unsigned int timeout;
203
204 /* Index and number of slots used in the push buffer */
205 unsigned int first_get;
206 unsigned int num_slots;
207
208 /* Copy of gathers */
209 size_t gather_copy_size;
210 dma_addr_t gather_copy;
211 u8 *gather_copy_mapped;
212
213 /* Check if register is marked as an address reg */
Dmitry Osipenkoa2b78b02017-06-15 02:18:38 +0300214 int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
Thierry Reding35d747a2013-09-24 16:30:32 +0200215
Dmitry Osipenko0f563a42017-06-15 02:18:37 +0300216 /* Check if class belongs to the unit */
217 int (*is_valid_class)(u32 class);
218
Thierry Reding35d747a2013-09-24 16:30:32 +0200219 /* Request a SETCLASS to this class */
220 u32 class;
221
222 /* Add a channel wait for previous ops to complete */
223 bool serialize;
224};
225
226struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
Thierry Reding24c94e12018-05-05 08:45:47 +0200227 u32 num_cmdbufs, u32 num_relocs);
Thierry Reding326bbd72018-05-16 17:01:43 +0200228void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo,
229 unsigned int words, unsigned int offset);
Thierry Reding35d747a2013-09-24 16:30:32 +0200230struct host1x_job *host1x_job_get(struct host1x_job *job);
231void host1x_job_put(struct host1x_job *job);
232int host1x_job_pin(struct host1x_job *job, struct device *dev);
233void host1x_job_unpin(struct host1x_job *job);
234
Thierry Reding776dc382013-10-14 14:43:22 +0200235/*
236 * subdevice probe infrastructure
237 */
238
239struct host1x_device;
240
Thierry Reding466749f2017-04-10 12:27:01 +0200241/**
242 * struct host1x_driver - host1x logical device driver
243 * @driver: core driver
244 * @subdevs: table of OF device IDs matching subdevices for this driver
245 * @list: list node for the driver
246 * @probe: called when the host1x logical device is probed
247 * @remove: called when the host1x logical device is removed
248 * @shutdown: called when the host1x logical device is shut down
249 */
Thierry Reding776dc382013-10-14 14:43:22 +0200250struct host1x_driver {
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100251 struct device_driver driver;
252
Thierry Reding776dc382013-10-14 14:43:22 +0200253 const struct of_device_id *subdevs;
254 struct list_head list;
Thierry Reding776dc382013-10-14 14:43:22 +0200255
256 int (*probe)(struct host1x_device *device);
257 int (*remove)(struct host1x_device *device);
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100258 void (*shutdown)(struct host1x_device *device);
Thierry Reding776dc382013-10-14 14:43:22 +0200259};
260
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100261static inline struct host1x_driver *
262to_host1x_driver(struct device_driver *driver)
263{
264 return container_of(driver, struct host1x_driver, driver);
265}
266
267int host1x_driver_register_full(struct host1x_driver *driver,
268 struct module *owner);
Thierry Reding776dc382013-10-14 14:43:22 +0200269void host1x_driver_unregister(struct host1x_driver *driver);
270
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100271#define host1x_driver_register(driver) \
272 host1x_driver_register_full(driver, THIS_MODULE)
273
Thierry Reding776dc382013-10-14 14:43:22 +0200274struct host1x_device {
275 struct host1x_driver *driver;
276 struct list_head list;
277 struct device dev;
278
279 struct mutex subdevs_lock;
280 struct list_head subdevs;
281 struct list_head active;
282
283 struct mutex clients_lock;
284 struct list_head clients;
Thierry Reding536e1712014-11-05 11:43:26 +0100285
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100286 bool registered;
Thierry Reding1e390472019-06-05 10:46:05 +0200287
288 struct device_dma_parameters dma_parms;
Thierry Reding776dc382013-10-14 14:43:22 +0200289};
290
291static inline struct host1x_device *to_host1x_device(struct device *dev)
292{
293 return container_of(dev, struct host1x_device, dev);
294}
295
296int host1x_device_init(struct host1x_device *device);
297int host1x_device_exit(struct host1x_device *device);
298
299int host1x_client_register(struct host1x_client *client);
300int host1x_client_unregister(struct host1x_client *client);
301
Thierry Reding4de6a2d2013-09-02 09:48:53 +0200302struct tegra_mipi_device;
303
304struct tegra_mipi_device *tegra_mipi_request(struct device *device);
305void tegra_mipi_free(struct tegra_mipi_device *device);
Thierry Reding87904c32016-08-12 16:00:53 +0200306int tegra_mipi_enable(struct tegra_mipi_device *device);
307int tegra_mipi_disable(struct tegra_mipi_device *device);
Thierry Reding4de6a2d2013-09-02 09:48:53 +0200308int tegra_mipi_calibrate(struct tegra_mipi_device *device);
309
Terje Bergstrom65793242013-03-22 16:34:03 +0200310#endif