blob: 62d216ff1097940c3d28626213d4e581589637ef [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;
Thierry Redingaacdf192019-02-08 14:35:13 +010021struct iommu_group;
Thierry Reding53fa7f72013-09-24 15:35:40 +020022
Thierry Reding466749f2017-04-10 12:27:01 +020023/**
24 * struct host1x_client_ops - host1x client operations
25 * @init: host1x client initialization code
26 * @exit: host1x client tear down code
Thierry Redingfd67e9c2019-12-02 15:29:03 +010027 * @suspend: host1x client suspend code
28 * @resume: host1x client resume code
Thierry Reding466749f2017-04-10 12:27:01 +020029 */
Thierry Reding53fa7f72013-09-24 15:35:40 +020030struct host1x_client_ops {
31 int (*init)(struct host1x_client *client);
32 int (*exit)(struct host1x_client *client);
Thierry Redingfd67e9c2019-12-02 15:29:03 +010033 int (*suspend)(struct host1x_client *client);
34 int (*resume)(struct host1x_client *client);
Thierry Reding53fa7f72013-09-24 15:35:40 +020035};
36
Thierry Reding466749f2017-04-10 12:27:01 +020037/**
38 * struct host1x_client - host1x client structure
39 * @list: list node for the host1x client
Thierry Reding608f43a2019-12-02 10:51:58 +010040 * @host: pointer to struct device representing the host1x controller
Thierry Reding466749f2017-04-10 12:27:01 +020041 * @dev: pointer to struct device backing this host1x client
Thierry Redingaacdf192019-02-08 14:35:13 +010042 * @group: IOMMU group that this client is a member of
Thierry Reding466749f2017-04-10 12:27:01 +020043 * @ops: host1x client operations
44 * @class: host1x class represented by this client
45 * @channel: host1x channel associated with this client
46 * @syncpts: array of syncpoints requested for this client
47 * @num_syncpts: number of syncpoints requested for this client
48 */
Thierry Reding53fa7f72013-09-24 15:35:40 +020049struct host1x_client {
50 struct list_head list;
Thierry Reding608f43a2019-12-02 10:51:58 +010051 struct device *host;
Thierry Reding53fa7f72013-09-24 15:35:40 +020052 struct device *dev;
Thierry Redingaacdf192019-02-08 14:35:13 +010053 struct iommu_group *group;
Thierry Reding53fa7f72013-09-24 15:35:40 +020054
55 const struct host1x_client_ops *ops;
56
57 enum host1x_class class;
58 struct host1x_channel *channel;
59
60 struct host1x_syncpt **syncpts;
61 unsigned int num_syncpts;
Thierry Redingfd67e9c2019-12-02 15:29:03 +010062
63 struct host1x_client *parent;
64 unsigned int usecount;
65 struct mutex lock;
Thierry Reding53fa7f72013-09-24 15:35:40 +020066};
67
Thierry Reding35d747a2013-09-24 16:30:32 +020068/*
69 * host1x buffer objects
70 */
71
72struct host1x_bo;
73struct sg_table;
74
75struct host1x_bo_ops {
76 struct host1x_bo *(*get)(struct host1x_bo *bo);
77 void (*put)(struct host1x_bo *bo);
Thierry Reding80327ce2019-10-28 13:37:09 +010078 struct sg_table *(*pin)(struct device *dev, struct host1x_bo *bo,
79 dma_addr_t *phys);
80 void (*unpin)(struct device *dev, struct sg_table *sgt);
Thierry Reding35d747a2013-09-24 16:30:32 +020081 void *(*mmap)(struct host1x_bo *bo);
82 void (*munmap)(struct host1x_bo *bo, void *addr);
Thierry Reding35d747a2013-09-24 16:30:32 +020083};
84
85struct host1x_bo {
86 const struct host1x_bo_ops *ops;
87};
88
89static inline void host1x_bo_init(struct host1x_bo *bo,
90 const struct host1x_bo_ops *ops)
91{
92 bo->ops = ops;
93}
94
95static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
96{
97 return bo->ops->get(bo);
98}
99
100static inline void host1x_bo_put(struct host1x_bo *bo)
101{
102 bo->ops->put(bo);
103}
104
Thierry Reding80327ce2019-10-28 13:37:09 +0100105static inline struct sg_table *host1x_bo_pin(struct device *dev,
106 struct host1x_bo *bo,
107 dma_addr_t *phys)
Thierry Reding35d747a2013-09-24 16:30:32 +0200108{
Thierry Reding80327ce2019-10-28 13:37:09 +0100109 return bo->ops->pin(dev, bo, phys);
Thierry Reding35d747a2013-09-24 16:30:32 +0200110}
111
Thierry Reding80327ce2019-10-28 13:37:09 +0100112static inline void host1x_bo_unpin(struct device *dev, struct host1x_bo *bo,
113 struct sg_table *sgt)
Thierry Reding35d747a2013-09-24 16:30:32 +0200114{
Thierry Reding80327ce2019-10-28 13:37:09 +0100115 bo->ops->unpin(dev, sgt);
Thierry Reding35d747a2013-09-24 16:30:32 +0200116}
117
118static inline void *host1x_bo_mmap(struct host1x_bo *bo)
119{
120 return bo->ops->mmap(bo);
121}
122
123static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
124{
125 bo->ops->munmap(bo, addr);
126}
127
Thierry Reding35d747a2013-09-24 16:30:32 +0200128/*
129 * host1x syncpoints
130 */
131
Arto Merilainen8736fe82013-10-14 15:21:52 +0300132#define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
Arto Merilainenf5a954f2013-10-14 15:21:53 +0300133#define HOST1X_SYNCPT_HAS_BASE (1 << 1)
Arto Merilainen8736fe82013-10-14 15:21:52 +0300134
Arto Merilainenf5a954f2013-10-14 15:21:53 +0300135struct host1x_syncpt_base;
Thierry Reding35d747a2013-09-24 16:30:32 +0200136struct host1x_syncpt;
137struct host1x;
138
139struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
140u32 host1x_syncpt_id(struct host1x_syncpt *sp);
141u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
142u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
Thierry Redingb4a201442015-01-28 14:29:02 +0100143u32 host1x_syncpt_read(struct host1x_syncpt *sp);
Thierry Reding35d747a2013-09-24 16:30:32 +0200144int host1x_syncpt_incr(struct host1x_syncpt *sp);
Bryan Wu64400c32014-02-19 14:48:36 -0800145u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
Thierry Reding35d747a2013-09-24 16:30:32 +0200146int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
147 u32 *value);
Thierry Reding617dd7c2017-08-30 12:48:31 +0200148struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
Arto Merilainen8736fe82013-10-14 15:21:52 +0300149 unsigned long flags);
Thierry Reding35d747a2013-09-24 16:30:32 +0200150void host1x_syncpt_free(struct host1x_syncpt *sp);
151
Arto Merilainenf5a954f2013-10-14 15:21:53 +0300152struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
153u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
154
Thierry Reding35d747a2013-09-24 16:30:32 +0200155/*
156 * host1x channel
157 */
158
159struct host1x_channel;
160struct host1x_job;
161
Thierry Redingcaccddc2018-06-18 14:01:51 +0200162struct host1x_channel *host1x_channel_request(struct host1x_client *client);
Thierry Reding35d747a2013-09-24 16:30:32 +0200163struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
164void host1x_channel_put(struct host1x_channel *channel);
165int host1x_job_submit(struct host1x_job *job);
166
167/*
168 * host1x job
169 */
170
Thierry Redingab4f81b2019-10-28 13:37:11 +0100171#define HOST1X_RELOC_READ (1 << 0)
172#define HOST1X_RELOC_WRITE (1 << 1)
173
Thierry Reding35d747a2013-09-24 16:30:32 +0200174struct host1x_reloc {
Thierry Reding961e3be2014-06-10 10:25:00 +0200175 struct {
176 struct host1x_bo *bo;
177 unsigned long offset;
178 } cmdbuf;
179 struct {
180 struct host1x_bo *bo;
181 unsigned long offset;
182 } target;
183 unsigned long shift;
Thierry Redingab4f81b2019-10-28 13:37:11 +0100184 unsigned long flags;
Thierry Reding35d747a2013-09-24 16:30:32 +0200185};
186
187struct host1x_job {
188 /* When refcount goes to zero, job can be freed */
189 struct kref ref;
190
191 /* List entry */
192 struct list_head list;
193
194 /* Channel where job is submitted to */
195 struct host1x_channel *channel;
196
Thierry Redingbf3d41c2018-05-16 14:12:33 +0200197 /* client where the job originated */
198 struct host1x_client *client;
Thierry Reding35d747a2013-09-24 16:30:32 +0200199
200 /* Gathers and their memory */
201 struct host1x_job_gather *gathers;
202 unsigned int num_gathers;
203
Thierry Reding35d747a2013-09-24 16:30:32 +0200204 /* Array of handles to be pinned & unpinned */
Thierry Reding06490bb2018-05-16 16:58:44 +0200205 struct host1x_reloc *relocs;
Thierry Reding35d747a2013-09-24 16:30:32 +0200206 unsigned int num_relocs;
207 struct host1x_job_unpin_data *unpins;
208 unsigned int num_unpins;
209
210 dma_addr_t *addr_phys;
211 dma_addr_t *gather_addr_phys;
212 dma_addr_t *reloc_addr_phys;
213
214 /* Sync point id, number of increments and end related to the submit */
215 u32 syncpt_id;
216 u32 syncpt_incrs;
217 u32 syncpt_end;
218
219 /* Maximum time to wait for this job */
220 unsigned int timeout;
221
222 /* Index and number of slots used in the push buffer */
223 unsigned int first_get;
224 unsigned int num_slots;
225
226 /* Copy of gathers */
227 size_t gather_copy_size;
228 dma_addr_t gather_copy;
229 u8 *gather_copy_mapped;
230
231 /* Check if register is marked as an address reg */
Dmitry Osipenkoa2b78b02017-06-15 02:18:38 +0300232 int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
Thierry Reding35d747a2013-09-24 16:30:32 +0200233
Dmitry Osipenko0f563a42017-06-15 02:18:37 +0300234 /* Check if class belongs to the unit */
235 int (*is_valid_class)(u32 class);
236
Thierry Reding35d747a2013-09-24 16:30:32 +0200237 /* Request a SETCLASS to this class */
238 u32 class;
239
240 /* Add a channel wait for previous ops to complete */
241 bool serialize;
242};
243
244struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
Thierry Reding24c94e12018-05-05 08:45:47 +0200245 u32 num_cmdbufs, u32 num_relocs);
Thierry Reding326bbd72018-05-16 17:01:43 +0200246void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo,
247 unsigned int words, unsigned int offset);
Thierry Reding35d747a2013-09-24 16:30:32 +0200248struct host1x_job *host1x_job_get(struct host1x_job *job);
249void host1x_job_put(struct host1x_job *job);
250int host1x_job_pin(struct host1x_job *job, struct device *dev);
251void host1x_job_unpin(struct host1x_job *job);
252
Thierry Reding776dc382013-10-14 14:43:22 +0200253/*
254 * subdevice probe infrastructure
255 */
256
257struct host1x_device;
258
Thierry Reding466749f2017-04-10 12:27:01 +0200259/**
260 * struct host1x_driver - host1x logical device driver
261 * @driver: core driver
262 * @subdevs: table of OF device IDs matching subdevices for this driver
263 * @list: list node for the driver
264 * @probe: called when the host1x logical device is probed
265 * @remove: called when the host1x logical device is removed
266 * @shutdown: called when the host1x logical device is shut down
267 */
Thierry Reding776dc382013-10-14 14:43:22 +0200268struct host1x_driver {
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100269 struct device_driver driver;
270
Thierry Reding776dc382013-10-14 14:43:22 +0200271 const struct of_device_id *subdevs;
272 struct list_head list;
Thierry Reding776dc382013-10-14 14:43:22 +0200273
274 int (*probe)(struct host1x_device *device);
275 int (*remove)(struct host1x_device *device);
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100276 void (*shutdown)(struct host1x_device *device);
Thierry Reding776dc382013-10-14 14:43:22 +0200277};
278
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100279static inline struct host1x_driver *
280to_host1x_driver(struct device_driver *driver)
281{
282 return container_of(driver, struct host1x_driver, driver);
283}
284
285int host1x_driver_register_full(struct host1x_driver *driver,
286 struct module *owner);
Thierry Reding776dc382013-10-14 14:43:22 +0200287void host1x_driver_unregister(struct host1x_driver *driver);
288
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100289#define host1x_driver_register(driver) \
290 host1x_driver_register_full(driver, THIS_MODULE)
291
Thierry Reding776dc382013-10-14 14:43:22 +0200292struct host1x_device {
293 struct host1x_driver *driver;
294 struct list_head list;
295 struct device dev;
296
297 struct mutex subdevs_lock;
298 struct list_head subdevs;
299 struct list_head active;
300
301 struct mutex clients_lock;
302 struct list_head clients;
Thierry Reding536e1712014-11-05 11:43:26 +0100303
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100304 bool registered;
Thierry Reding1e390472019-06-05 10:46:05 +0200305
306 struct device_dma_parameters dma_parms;
Thierry Reding776dc382013-10-14 14:43:22 +0200307};
308
309static inline struct host1x_device *to_host1x_device(struct device *dev)
310{
311 return container_of(dev, struct host1x_device, dev);
312}
313
314int host1x_device_init(struct host1x_device *device);
315int host1x_device_exit(struct host1x_device *device);
316
317int host1x_client_register(struct host1x_client *client);
318int host1x_client_unregister(struct host1x_client *client);
319
Thierry Redingfd67e9c2019-12-02 15:29:03 +0100320int host1x_client_suspend(struct host1x_client *client);
321int host1x_client_resume(struct host1x_client *client);
322
Thierry Reding4de6a2d2013-09-02 09:48:53 +0200323struct tegra_mipi_device;
324
325struct tegra_mipi_device *tegra_mipi_request(struct device *device);
326void tegra_mipi_free(struct tegra_mipi_device *device);
Thierry Reding87904c32016-08-12 16:00:53 +0200327int tegra_mipi_enable(struct tegra_mipi_device *device);
328int tegra_mipi_disable(struct tegra_mipi_device *device);
Thierry Reding4de6a2d2013-09-02 09:48:53 +0200329int tegra_mipi_calibrate(struct tegra_mipi_device *device);
330
Terje Bergstrom65793242013-03-22 16:34:03 +0200331#endif