blob: ed0005ce4285cfae49e3dba2062533fe21a55575 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-or-later */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved.
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00004 */
5
6#ifndef __LINUX_HOST1X_H
7#define __LINUX_HOST1X_H
8
9#include <linux/device.h>
10#include <linux/types.h>
11
12enum host1x_class {
13 HOST1X_CLASS_HOST1X = 0x1,
14 HOST1X_CLASS_GR2D = 0x51,
15 HOST1X_CLASS_GR2D_SB = 0x52,
16 HOST1X_CLASS_VIC = 0x5D,
17 HOST1X_CLASS_GR3D = 0x60,
18};
19
Olivier Deprez157378f2022-04-04 15:47:50 +020020struct host1x;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000021struct host1x_client;
Olivier Deprez157378f2022-04-04 15:47:50 +020022struct iommu_group;
23
24u64 host1x_get_dma_mask(struct host1x *host1x);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000025
26/**
27 * struct host1x_client_ops - host1x client operations
28 * @init: host1x client initialization code
29 * @exit: host1x client tear down code
Olivier Deprez157378f2022-04-04 15:47:50 +020030 * @suspend: host1x client suspend code
31 * @resume: host1x client resume code
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000032 */
33struct host1x_client_ops {
34 int (*init)(struct host1x_client *client);
35 int (*exit)(struct host1x_client *client);
Olivier Deprez157378f2022-04-04 15:47:50 +020036 int (*suspend)(struct host1x_client *client);
37 int (*resume)(struct host1x_client *client);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000038};
39
40/**
41 * struct host1x_client - host1x client structure
42 * @list: list node for the host1x client
Olivier Deprez157378f2022-04-04 15:47:50 +020043 * @host: pointer to struct device representing the host1x controller
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000044 * @dev: pointer to struct device backing this host1x client
Olivier Deprez157378f2022-04-04 15:47:50 +020045 * @group: IOMMU group that this client is a member of
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000046 * @ops: host1x client operations
47 * @class: host1x class represented by this client
48 * @channel: host1x channel associated with this client
49 * @syncpts: array of syncpoints requested for this client
50 * @num_syncpts: number of syncpoints requested for this client
Olivier Deprez157378f2022-04-04 15:47:50 +020051 * @parent: pointer to parent structure
52 * @usecount: reference count for this structure
53 * @lock: mutex for mutually exclusive concurrency
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000054 */
55struct host1x_client {
56 struct list_head list;
Olivier Deprez157378f2022-04-04 15:47:50 +020057 struct device *host;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000058 struct device *dev;
Olivier Deprez157378f2022-04-04 15:47:50 +020059 struct iommu_group *group;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000060
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;
Olivier Deprez157378f2022-04-04 15:47:50 +020068
69 struct host1x_client *parent;
70 unsigned int usecount;
71 struct mutex lock;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000072};
73
74/*
75 * host1x buffer objects
76 */
77
78struct host1x_bo;
79struct sg_table;
80
81struct host1x_bo_ops {
82 struct host1x_bo *(*get)(struct host1x_bo *bo);
83 void (*put)(struct host1x_bo *bo);
Olivier Deprez157378f2022-04-04 15:47:50 +020084 struct sg_table *(*pin)(struct device *dev, struct host1x_bo *bo,
85 dma_addr_t *phys);
86 void (*unpin)(struct device *dev, struct sg_table *sgt);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000087 void *(*mmap)(struct host1x_bo *bo);
88 void (*munmap)(struct host1x_bo *bo, void *addr);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000089};
90
91struct host1x_bo {
92 const struct host1x_bo_ops *ops;
93};
94
95static inline void host1x_bo_init(struct host1x_bo *bo,
96 const struct host1x_bo_ops *ops)
97{
98 bo->ops = ops;
99}
100
101static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
102{
103 return bo->ops->get(bo);
104}
105
106static inline void host1x_bo_put(struct host1x_bo *bo)
107{
108 bo->ops->put(bo);
109}
110
Olivier Deprez157378f2022-04-04 15:47:50 +0200111static inline struct sg_table *host1x_bo_pin(struct device *dev,
112 struct host1x_bo *bo,
113 dma_addr_t *phys)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000114{
Olivier Deprez157378f2022-04-04 15:47:50 +0200115 return bo->ops->pin(dev, bo, phys);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000116}
117
Olivier Deprez157378f2022-04-04 15:47:50 +0200118static inline void host1x_bo_unpin(struct device *dev, struct host1x_bo *bo,
119 struct sg_table *sgt)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000120{
Olivier Deprez157378f2022-04-04 15:47:50 +0200121 bo->ops->unpin(dev, sgt);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000122}
123
124static inline void *host1x_bo_mmap(struct host1x_bo *bo)
125{
126 return bo->ops->mmap(bo);
127}
128
129static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
130{
131 bo->ops->munmap(bo, addr);
132}
133
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000134/*
135 * host1x syncpoints
136 */
137
138#define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
139#define HOST1X_SYNCPT_HAS_BASE (1 << 1)
140
141struct host1x_syncpt_base;
142struct host1x_syncpt;
143struct host1x;
144
145struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
146u32 host1x_syncpt_id(struct host1x_syncpt *sp);
147u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
148u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
149u32 host1x_syncpt_read(struct host1x_syncpt *sp);
150int host1x_syncpt_incr(struct host1x_syncpt *sp);
151u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
152int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
153 u32 *value);
154struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
155 unsigned long flags);
156void host1x_syncpt_free(struct host1x_syncpt *sp);
157
158struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
159u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
160
161/*
162 * host1x channel
163 */
164
165struct host1x_channel;
166struct host1x_job;
167
Olivier Deprez157378f2022-04-04 15:47:50 +0200168struct host1x_channel *host1x_channel_request(struct host1x_client *client);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000169struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
170void host1x_channel_put(struct host1x_channel *channel);
171int host1x_job_submit(struct host1x_job *job);
172
173/*
174 * host1x job
175 */
176
Olivier Deprez157378f2022-04-04 15:47:50 +0200177#define HOST1X_RELOC_READ (1 << 0)
178#define HOST1X_RELOC_WRITE (1 << 1)
179
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000180struct host1x_reloc {
181 struct {
182 struct host1x_bo *bo;
183 unsigned long offset;
184 } cmdbuf;
185 struct {
186 struct host1x_bo *bo;
187 unsigned long offset;
188 } target;
189 unsigned long shift;
Olivier Deprez157378f2022-04-04 15:47:50 +0200190 unsigned long flags;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000191};
192
193struct host1x_job {
194 /* When refcount goes to zero, job can be freed */
195 struct kref ref;
196
197 /* List entry */
198 struct list_head list;
199
200 /* Channel where job is submitted to */
201 struct host1x_channel *channel;
202
203 /* client where the job originated */
204 struct host1x_client *client;
205
206 /* Gathers and their memory */
207 struct host1x_job_gather *gathers;
208 unsigned int num_gathers;
209
210 /* Array of handles to be pinned & unpinned */
211 struct host1x_reloc *relocs;
212 unsigned int num_relocs;
213 struct host1x_job_unpin_data *unpins;
214 unsigned int num_unpins;
215
216 dma_addr_t *addr_phys;
217 dma_addr_t *gather_addr_phys;
218 dma_addr_t *reloc_addr_phys;
219
220 /* Sync point id, number of increments and end related to the submit */
221 u32 syncpt_id;
222 u32 syncpt_incrs;
223 u32 syncpt_end;
224
225 /* Maximum time to wait for this job */
226 unsigned int timeout;
227
228 /* Index and number of slots used in the push buffer */
229 unsigned int first_get;
230 unsigned int num_slots;
231
232 /* Copy of gathers */
233 size_t gather_copy_size;
234 dma_addr_t gather_copy;
235 u8 *gather_copy_mapped;
236
237 /* Check if register is marked as an address reg */
238 int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
239
240 /* Check if class belongs to the unit */
241 int (*is_valid_class)(u32 class);
242
243 /* Request a SETCLASS to this class */
244 u32 class;
245
246 /* Add a channel wait for previous ops to complete */
247 bool serialize;
248};
249
250struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
251 u32 num_cmdbufs, u32 num_relocs);
252void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo,
253 unsigned int words, unsigned int offset);
254struct host1x_job *host1x_job_get(struct host1x_job *job);
255void host1x_job_put(struct host1x_job *job);
256int host1x_job_pin(struct host1x_job *job, struct device *dev);
257void host1x_job_unpin(struct host1x_job *job);
258
259/*
260 * subdevice probe infrastructure
261 */
262
263struct host1x_device;
264
265/**
266 * struct host1x_driver - host1x logical device driver
267 * @driver: core driver
268 * @subdevs: table of OF device IDs matching subdevices for this driver
269 * @list: list node for the driver
270 * @probe: called when the host1x logical device is probed
271 * @remove: called when the host1x logical device is removed
272 * @shutdown: called when the host1x logical device is shut down
273 */
274struct host1x_driver {
275 struct device_driver driver;
276
277 const struct of_device_id *subdevs;
278 struct list_head list;
279
280 int (*probe)(struct host1x_device *device);
281 int (*remove)(struct host1x_device *device);
282 void (*shutdown)(struct host1x_device *device);
283};
284
285static inline struct host1x_driver *
286to_host1x_driver(struct device_driver *driver)
287{
288 return container_of(driver, struct host1x_driver, driver);
289}
290
291int host1x_driver_register_full(struct host1x_driver *driver,
292 struct module *owner);
293void host1x_driver_unregister(struct host1x_driver *driver);
294
295#define host1x_driver_register(driver) \
296 host1x_driver_register_full(driver, THIS_MODULE)
297
298struct host1x_device {
299 struct host1x_driver *driver;
300 struct list_head list;
301 struct device dev;
302
303 struct mutex subdevs_lock;
304 struct list_head subdevs;
305 struct list_head active;
306
307 struct mutex clients_lock;
308 struct list_head clients;
309
310 bool registered;
David Brazdil0f672f62019-12-10 10:32:29 +0000311
312 struct device_dma_parameters dma_parms;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000313};
314
315static inline struct host1x_device *to_host1x_device(struct device *dev)
316{
317 return container_of(dev, struct host1x_device, dev);
318}
319
320int host1x_device_init(struct host1x_device *device);
321int host1x_device_exit(struct host1x_device *device);
322
Olivier Deprez157378f2022-04-04 15:47:50 +0200323void __host1x_client_init(struct host1x_client *client, struct lock_class_key *key);
324void host1x_client_exit(struct host1x_client *client);
325
326#define host1x_client_init(client) \
327 ({ \
328 static struct lock_class_key __key; \
329 __host1x_client_init(client, &__key); \
330 })
331
332int __host1x_client_register(struct host1x_client *client);
333
334/*
335 * Note that this wrapper calls __host1x_client_init() for compatibility
336 * with existing callers. Callers that want to separately initialize and
337 * register a host1x client must first initialize using either of the
338 * __host1x_client_init() or host1x_client_init() functions and then use
339 * the low-level __host1x_client_register() function to avoid the client
340 * getting reinitialized.
341 */
342#define host1x_client_register(client) \
343 ({ \
344 static struct lock_class_key __key; \
345 __host1x_client_init(client, &__key); \
346 __host1x_client_register(client); \
347 })
348
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000349int host1x_client_unregister(struct host1x_client *client);
350
Olivier Deprez157378f2022-04-04 15:47:50 +0200351int host1x_client_suspend(struct host1x_client *client);
352int host1x_client_resume(struct host1x_client *client);
353
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000354struct tegra_mipi_device;
355
Olivier Deprez157378f2022-04-04 15:47:50 +0200356struct tegra_mipi_device *tegra_mipi_request(struct device *device,
357 struct device_node *np);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000358void tegra_mipi_free(struct tegra_mipi_device *device);
359int tegra_mipi_enable(struct tegra_mipi_device *device);
360int tegra_mipi_disable(struct tegra_mipi_device *device);
Olivier Deprez157378f2022-04-04 15:47:50 +0200361int tegra_mipi_start_calibration(struct tegra_mipi_device *device);
362int tegra_mipi_finish_calibration(struct tegra_mipi_device *device);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000363
364#endif