]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/host1x.h
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[mirror_ubuntu-jammy-kernel.git] / include / linux / host1x.h
CommitLineData
16216333 1/* SPDX-License-Identifier: GPL-2.0-or-later */
6579324a 2/*
6579324a 3 * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved.
6579324a
TB
4 */
5
6#ifndef __LINUX_HOST1X_H
7#define __LINUX_HOST1X_H
8
776dc384 9#include <linux/device.h>
35d747a8
TR
10#include <linux/types.h>
11
6579324a 12enum host1x_class {
e1e90644
TR
13 HOST1X_CLASS_HOST1X = 0x1,
14 HOST1X_CLASS_GR2D = 0x51,
15 HOST1X_CLASS_GR2D_SB = 0x52,
0ae797a8 16 HOST1X_CLASS_VIC = 0x5D,
5f60ed0d 17 HOST1X_CLASS_GR3D = 0x60,
6579324a
TB
18};
19
53fa7f72 20struct host1x_client;
aacdf198 21struct iommu_group;
53fa7f72 22
466749f1
TR
23/**
24 * struct host1x_client_ops - host1x client operations
25 * @init: host1x client initialization code
26 * @exit: host1x client tear down code
27 */
53fa7f72
TR
28struct host1x_client_ops {
29 int (*init)(struct host1x_client *client);
30 int (*exit)(struct host1x_client *client);
31};
32
466749f1
TR
33/**
34 * struct host1x_client - host1x client structure
35 * @list: list node for the host1x client
36 * @parent: pointer to struct device representing the host1x controller
37 * @dev: pointer to struct device backing this host1x client
aacdf198 38 * @group: IOMMU group that this client is a member of
466749f1
TR
39 * @ops: host1x client operations
40 * @class: host1x class represented by this client
41 * @channel: host1x channel associated with this client
42 * @syncpts: array of syncpoints requested for this client
43 * @num_syncpts: number of syncpoints requested for this client
44 */
53fa7f72
TR
45struct host1x_client {
46 struct list_head list;
776dc384 47 struct device *parent;
53fa7f72 48 struct device *dev;
aacdf198 49 struct iommu_group *group;
53fa7f72
TR
50
51 const struct host1x_client_ops *ops;
52
53 enum host1x_class class;
54 struct host1x_channel *channel;
55
56 struct host1x_syncpt **syncpts;
57 unsigned int num_syncpts;
58};
59
35d747a8
TR
60/*
61 * host1x buffer objects
62 */
63
64struct host1x_bo;
65struct sg_table;
66
67struct host1x_bo_ops {
68 struct host1x_bo *(*get)(struct host1x_bo *bo);
69 void (*put)(struct host1x_bo *bo);
80327ce3
TR
70 struct sg_table *(*pin)(struct device *dev, struct host1x_bo *bo,
71 dma_addr_t *phys);
72 void (*unpin)(struct device *dev, struct sg_table *sgt);
35d747a8
TR
73 void *(*mmap)(struct host1x_bo *bo);
74 void (*munmap)(struct host1x_bo *bo, void *addr);
75 void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum);
76 void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr);
77};
78
79struct host1x_bo {
80 const struct host1x_bo_ops *ops;
81};
82
83static inline void host1x_bo_init(struct host1x_bo *bo,
84 const struct host1x_bo_ops *ops)
85{
86 bo->ops = ops;
87}
88
89static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
90{
91 return bo->ops->get(bo);
92}
93
94static inline void host1x_bo_put(struct host1x_bo *bo)
95{
96 bo->ops->put(bo);
97}
98
80327ce3
TR
99static inline struct sg_table *host1x_bo_pin(struct device *dev,
100 struct host1x_bo *bo,
101 dma_addr_t *phys)
35d747a8 102{
80327ce3 103 return bo->ops->pin(dev, bo, phys);
35d747a8
TR
104}
105
80327ce3
TR
106static inline void host1x_bo_unpin(struct device *dev, struct host1x_bo *bo,
107 struct sg_table *sgt)
35d747a8 108{
80327ce3 109 bo->ops->unpin(dev, sgt);
35d747a8
TR
110}
111
112static inline void *host1x_bo_mmap(struct host1x_bo *bo)
113{
114 return bo->ops->mmap(bo);
115}
116
117static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
118{
119 bo->ops->munmap(bo, addr);
120}
121
122static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
123{
124 return bo->ops->kmap(bo, pagenum);
125}
126
127static inline void host1x_bo_kunmap(struct host1x_bo *bo,
128 unsigned int pagenum, void *addr)
129{
130 bo->ops->kunmap(bo, pagenum, addr);
131}
132
133/*
134 * host1x syncpoints
135 */
136
8736fe81 137#define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
f5a954fe 138#define HOST1X_SYNCPT_HAS_BASE (1 << 1)
8736fe81 139
f5a954fe 140struct host1x_syncpt_base;
35d747a8
TR
141struct host1x_syncpt;
142struct host1x;
143
144struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
145u32 host1x_syncpt_id(struct host1x_syncpt *sp);
146u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
147u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
b4a20144 148u32 host1x_syncpt_read(struct host1x_syncpt *sp);
35d747a8 149int host1x_syncpt_incr(struct host1x_syncpt *sp);
64400c37 150u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
35d747a8
TR
151int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
152 u32 *value);
617dd7cc 153struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
8736fe81 154 unsigned long flags);
35d747a8
TR
155void host1x_syncpt_free(struct host1x_syncpt *sp);
156
f5a954fe
AM
157struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
158u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
159
35d747a8
TR
160/*
161 * host1x channel
162 */
163
164struct host1x_channel;
165struct host1x_job;
166
caccddcf 167struct host1x_channel *host1x_channel_request(struct host1x_client *client);
35d747a8
TR
168struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
169void host1x_channel_put(struct host1x_channel *channel);
170int host1x_job_submit(struct host1x_job *job);
171
172/*
173 * host1x job
174 */
175
ab4f81bf
TR
176#define HOST1X_RELOC_READ (1 << 0)
177#define HOST1X_RELOC_WRITE (1 << 1)
178
35d747a8 179struct host1x_reloc {
961e3bea
TR
180 struct {
181 struct host1x_bo *bo;
182 unsigned long offset;
183 } cmdbuf;
184 struct {
185 struct host1x_bo *bo;
186 unsigned long offset;
187 } target;
188 unsigned long shift;
ab4f81bf 189 unsigned long flags;
35d747a8
TR
190};
191
192struct host1x_job {
193 /* When refcount goes to zero, job can be freed */
194 struct kref ref;
195
196 /* List entry */
197 struct list_head list;
198
199 /* Channel where job is submitted to */
200 struct host1x_channel *channel;
201
bf3d41cc
TR
202 /* client where the job originated */
203 struct host1x_client *client;
35d747a8
TR
204
205 /* Gathers and their memory */
206 struct host1x_job_gather *gathers;
207 unsigned int num_gathers;
208
35d747a8 209 /* Array of handles to be pinned & unpinned */
06490bb9 210 struct host1x_reloc *relocs;
35d747a8
TR
211 unsigned int num_relocs;
212 struct host1x_job_unpin_data *unpins;
213 unsigned int num_unpins;
214
215 dma_addr_t *addr_phys;
216 dma_addr_t *gather_addr_phys;
217 dma_addr_t *reloc_addr_phys;
218
219 /* Sync point id, number of increments and end related to the submit */
220 u32 syncpt_id;
221 u32 syncpt_incrs;
222 u32 syncpt_end;
223
224 /* Maximum time to wait for this job */
225 unsigned int timeout;
226
227 /* Index and number of slots used in the push buffer */
228 unsigned int first_get;
229 unsigned int num_slots;
230
231 /* Copy of gathers */
232 size_t gather_copy_size;
233 dma_addr_t gather_copy;
234 u8 *gather_copy_mapped;
235
236 /* Check if register is marked as an address reg */
a2b78b0d 237 int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
35d747a8 238
0f563a4b
DO
239 /* Check if class belongs to the unit */
240 int (*is_valid_class)(u32 class);
241
35d747a8
TR
242 /* Request a SETCLASS to this class */
243 u32 class;
244
245 /* Add a channel wait for previous ops to complete */
246 bool serialize;
247};
248
249struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
24c94e16 250 u32 num_cmdbufs, u32 num_relocs);
326bbd79
TR
251void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo,
252 unsigned int words, unsigned int offset);
35d747a8
TR
253struct host1x_job *host1x_job_get(struct host1x_job *job);
254void host1x_job_put(struct host1x_job *job);
255int host1x_job_pin(struct host1x_job *job, struct device *dev);
256void host1x_job_unpin(struct host1x_job *job);
257
776dc384
TR
258/*
259 * subdevice probe infrastructure
260 */
261
262struct host1x_device;
263
466749f1
TR
264/**
265 * struct host1x_driver - host1x logical device driver
266 * @driver: core driver
267 * @subdevs: table of OF device IDs matching subdevices for this driver
268 * @list: list node for the driver
269 * @probe: called when the host1x logical device is probed
270 * @remove: called when the host1x logical device is removed
271 * @shutdown: called when the host1x logical device is shut down
272 */
776dc384 273struct host1x_driver {
f4c5cf88
TR
274 struct device_driver driver;
275
776dc384
TR
276 const struct of_device_id *subdevs;
277 struct list_head list;
776dc384
TR
278
279 int (*probe)(struct host1x_device *device);
280 int (*remove)(struct host1x_device *device);
f4c5cf88 281 void (*shutdown)(struct host1x_device *device);
776dc384
TR
282};
283
f4c5cf88
TR
284static inline struct host1x_driver *
285to_host1x_driver(struct device_driver *driver)
286{
287 return container_of(driver, struct host1x_driver, driver);
288}
289
290int host1x_driver_register_full(struct host1x_driver *driver,
291 struct module *owner);
776dc384
TR
292void host1x_driver_unregister(struct host1x_driver *driver);
293
f4c5cf88
TR
294#define host1x_driver_register(driver) \
295 host1x_driver_register_full(driver, THIS_MODULE)
296
776dc384
TR
297struct host1x_device {
298 struct host1x_driver *driver;
299 struct list_head list;
300 struct device dev;
301
302 struct mutex subdevs_lock;
303 struct list_head subdevs;
304 struct list_head active;
305
306 struct mutex clients_lock;
307 struct list_head clients;
536e1715 308
f4c5cf88 309 bool registered;
1e390478
TR
310
311 struct device_dma_parameters dma_parms;
776dc384
TR
312};
313
314static inline struct host1x_device *to_host1x_device(struct device *dev)
315{
316 return container_of(dev, struct host1x_device, dev);
317}
318
319int host1x_device_init(struct host1x_device *device);
320int host1x_device_exit(struct host1x_device *device);
321
322int host1x_client_register(struct host1x_client *client);
323int host1x_client_unregister(struct host1x_client *client);
324
4de6a2d6
TR
325struct tegra_mipi_device;
326
327struct tegra_mipi_device *tegra_mipi_request(struct device *device);
328void tegra_mipi_free(struct tegra_mipi_device *device);
87904c3e
TR
329int tegra_mipi_enable(struct tegra_mipi_device *device);
330int tegra_mipi_disable(struct tegra_mipi_device *device);
4de6a2d6
TR
331int tegra_mipi_calibrate(struct tegra_mipi_device *device);
332
6579324a 333#endif