1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved.
6 #ifndef __LINUX_HOST1X_H
7 #define __LINUX_HOST1X_H
9 #include <linux/device.h>
10 #include <linux/types.h>
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,
24 u64
host1x_get_dma_mask(struct host1x
*host1x
);
27 * struct host1x_client_ops - host1x client operations
28 * @early_init: host1x client early initialization code
29 * @init: host1x client initialization code
30 * @exit: host1x client tear down code
31 * @late_exit: host1x client late tear down code
32 * @suspend: host1x client suspend code
33 * @resume: host1x client resume code
35 struct host1x_client_ops
{
36 int (*early_init
)(struct host1x_client
*client
);
37 int (*init
)(struct host1x_client
*client
);
38 int (*exit
)(struct host1x_client
*client
);
39 int (*late_exit
)(struct host1x_client
*client
);
40 int (*suspend
)(struct host1x_client
*client
);
41 int (*resume
)(struct host1x_client
*client
);
45 * struct host1x_client - host1x client structure
46 * @list: list node for the host1x client
47 * @host: pointer to struct device representing the host1x controller
48 * @dev: pointer to struct device backing this host1x client
49 * @group: IOMMU group that this client is a member of
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 * @parent: pointer to parent structure
56 * @usecount: reference count for this structure
57 * @lock: mutex for mutually exclusive concurrency
59 struct host1x_client
{
60 struct list_head list
;
63 struct iommu_group
*group
;
65 const struct host1x_client_ops
*ops
;
67 enum host1x_class
class;
68 struct host1x_channel
*channel
;
70 struct host1x_syncpt
**syncpts
;
71 unsigned int num_syncpts
;
73 struct host1x_client
*parent
;
74 unsigned int usecount
;
79 * host1x buffer objects
85 struct host1x_bo_ops
{
86 struct host1x_bo
*(*get
)(struct host1x_bo
*bo
);
87 void (*put
)(struct host1x_bo
*bo
);
88 struct sg_table
*(*pin
)(struct device
*dev
, struct host1x_bo
*bo
,
90 void (*unpin
)(struct device
*dev
, struct sg_table
*sgt
);
91 void *(*mmap
)(struct host1x_bo
*bo
);
92 void (*munmap
)(struct host1x_bo
*bo
, void *addr
);
96 const struct host1x_bo_ops
*ops
;
99 static inline void host1x_bo_init(struct host1x_bo
*bo
,
100 const struct host1x_bo_ops
*ops
)
105 static inline struct host1x_bo
*host1x_bo_get(struct host1x_bo
*bo
)
107 return bo
->ops
->get(bo
);
110 static inline void host1x_bo_put(struct host1x_bo
*bo
)
115 static inline struct sg_table
*host1x_bo_pin(struct device
*dev
,
116 struct host1x_bo
*bo
,
119 return bo
->ops
->pin(dev
, bo
, phys
);
122 static inline void host1x_bo_unpin(struct device
*dev
, struct host1x_bo
*bo
,
123 struct sg_table
*sgt
)
125 bo
->ops
->unpin(dev
, sgt
);
128 static inline void *host1x_bo_mmap(struct host1x_bo
*bo
)
130 return bo
->ops
->mmap(bo
);
133 static inline void host1x_bo_munmap(struct host1x_bo
*bo
, void *addr
)
135 bo
->ops
->munmap(bo
, addr
);
142 #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
143 #define HOST1X_SYNCPT_HAS_BASE (1 << 1)
145 struct host1x_syncpt_base
;
146 struct host1x_syncpt
;
149 struct host1x_syncpt
*host1x_syncpt_get_by_id(struct host1x
*host
, u32 id
);
150 struct host1x_syncpt
*host1x_syncpt_get_by_id_noref(struct host1x
*host
, u32 id
);
151 struct host1x_syncpt
*host1x_syncpt_get(struct host1x_syncpt
*sp
);
152 u32
host1x_syncpt_id(struct host1x_syncpt
*sp
);
153 u32
host1x_syncpt_read_min(struct host1x_syncpt
*sp
);
154 u32
host1x_syncpt_read_max(struct host1x_syncpt
*sp
);
155 u32
host1x_syncpt_read(struct host1x_syncpt
*sp
);
156 int host1x_syncpt_incr(struct host1x_syncpt
*sp
);
157 u32
host1x_syncpt_incr_max(struct host1x_syncpt
*sp
, u32 incrs
);
158 int host1x_syncpt_wait(struct host1x_syncpt
*sp
, u32 thresh
, long timeout
,
160 struct host1x_syncpt
*host1x_syncpt_request(struct host1x_client
*client
,
161 unsigned long flags
);
162 void host1x_syncpt_put(struct host1x_syncpt
*sp
);
163 struct host1x_syncpt
*host1x_syncpt_alloc(struct host1x
*host
,
167 struct host1x_syncpt_base
*host1x_syncpt_get_base(struct host1x_syncpt
*sp
);
168 u32
host1x_syncpt_base_id(struct host1x_syncpt_base
*base
);
170 void host1x_syncpt_release_vblank_reservation(struct host1x_client
*client
,
173 struct dma_fence
*host1x_fence_create(struct host1x_syncpt
*sp
, u32 threshold
);
179 struct host1x_channel
;
182 struct host1x_channel
*host1x_channel_request(struct host1x_client
*client
);
183 struct host1x_channel
*host1x_channel_get(struct host1x_channel
*channel
);
184 void host1x_channel_put(struct host1x_channel
*channel
);
185 int host1x_job_submit(struct host1x_job
*job
);
191 #define HOST1X_RELOC_READ (1 << 0)
192 #define HOST1X_RELOC_WRITE (1 << 1)
194 struct host1x_reloc
{
196 struct host1x_bo
*bo
;
197 unsigned long offset
;
200 struct host1x_bo
*bo
;
201 unsigned long offset
;
208 /* When refcount goes to zero, job can be freed */
212 struct list_head list
;
214 /* Channel where job is submitted to */
215 struct host1x_channel
*channel
;
217 /* client where the job originated */
218 struct host1x_client
*client
;
220 /* Gathers and their memory */
221 struct host1x_job_cmd
*cmds
;
222 unsigned int num_cmds
;
224 /* Array of handles to be pinned & unpinned */
225 struct host1x_reloc
*relocs
;
226 unsigned int num_relocs
;
227 struct host1x_job_unpin_data
*unpins
;
228 unsigned int num_unpins
;
230 dma_addr_t
*addr_phys
;
231 dma_addr_t
*gather_addr_phys
;
232 dma_addr_t
*reloc_addr_phys
;
234 /* Sync point id, number of increments and end related to the submit */
235 struct host1x_syncpt
*syncpt
;
239 /* Completion waiter ref */
242 /* Maximum time to wait for this job */
243 unsigned int timeout
;
245 /* Job has timed out and should be released */
248 /* Index and number of slots used in the push buffer */
249 unsigned int first_get
;
250 unsigned int num_slots
;
252 /* Copy of gathers */
253 size_t gather_copy_size
;
254 dma_addr_t gather_copy
;
255 u8
*gather_copy_mapped
;
257 /* Check if register is marked as an address reg */
258 int (*is_addr_reg
)(struct device
*dev
, u32
class, u32 reg
);
260 /* Check if class belongs to the unit */
261 int (*is_valid_class
)(u32
class);
263 /* Request a SETCLASS to this class */
266 /* Add a channel wait for previous ops to complete */
269 /* Fast-forward syncpoint increments on job timeout */
270 bool syncpt_recovery
;
272 /* Callback called when job is freed */
273 void (*release
)(struct host1x_job
*job
);
276 /* Whether host1x-side firewall should be ran for this job or not */
277 bool enable_firewall
;
280 struct host1x_job
*host1x_job_alloc(struct host1x_channel
*ch
,
281 u32 num_cmdbufs
, u32 num_relocs
,
283 void host1x_job_add_gather(struct host1x_job
*job
, struct host1x_bo
*bo
,
284 unsigned int words
, unsigned int offset
);
285 void host1x_job_add_wait(struct host1x_job
*job
, u32 id
, u32 thresh
,
286 bool relative
, u32 next_class
);
287 struct host1x_job
*host1x_job_get(struct host1x_job
*job
);
288 void host1x_job_put(struct host1x_job
*job
);
289 int host1x_job_pin(struct host1x_job
*job
, struct device
*dev
);
290 void host1x_job_unpin(struct host1x_job
*job
);
293 * subdevice probe infrastructure
296 struct host1x_device
;
299 * struct host1x_driver - host1x logical device driver
300 * @driver: core driver
301 * @subdevs: table of OF device IDs matching subdevices for this driver
302 * @list: list node for the driver
303 * @probe: called when the host1x logical device is probed
304 * @remove: called when the host1x logical device is removed
305 * @shutdown: called when the host1x logical device is shut down
307 struct host1x_driver
{
308 struct device_driver driver
;
310 const struct of_device_id
*subdevs
;
311 struct list_head list
;
313 int (*probe
)(struct host1x_device
*device
);
314 int (*remove
)(struct host1x_device
*device
);
315 void (*shutdown
)(struct host1x_device
*device
);
318 static inline struct host1x_driver
*
319 to_host1x_driver(struct device_driver
*driver
)
321 return container_of(driver
, struct host1x_driver
, driver
);
324 int host1x_driver_register_full(struct host1x_driver
*driver
,
325 struct module
*owner
);
326 void host1x_driver_unregister(struct host1x_driver
*driver
);
328 #define host1x_driver_register(driver) \
329 host1x_driver_register_full(driver, THIS_MODULE)
331 struct host1x_device
{
332 struct host1x_driver
*driver
;
333 struct list_head list
;
336 struct mutex subdevs_lock
;
337 struct list_head subdevs
;
338 struct list_head active
;
340 struct mutex clients_lock
;
341 struct list_head clients
;
345 struct device_dma_parameters dma_parms
;
348 static inline struct host1x_device
*to_host1x_device(struct device
*dev
)
350 return container_of(dev
, struct host1x_device
, dev
);
353 int host1x_device_init(struct host1x_device
*device
);
354 int host1x_device_exit(struct host1x_device
*device
);
356 void __host1x_client_init(struct host1x_client
*client
, struct lock_class_key
*key
);
357 void host1x_client_exit(struct host1x_client
*client
);
359 #define host1x_client_init(client) \
361 static struct lock_class_key __key; \
362 __host1x_client_init(client, &__key); \
365 int __host1x_client_register(struct host1x_client
*client
);
368 * Note that this wrapper calls __host1x_client_init() for compatibility
369 * with existing callers. Callers that want to separately initialize and
370 * register a host1x client must first initialize using either of the
371 * __host1x_client_init() or host1x_client_init() functions and then use
372 * the low-level __host1x_client_register() function to avoid the client
373 * getting reinitialized.
375 #define host1x_client_register(client) \
377 static struct lock_class_key __key; \
378 __host1x_client_init(client, &__key); \
379 __host1x_client_register(client); \
382 int host1x_client_unregister(struct host1x_client
*client
);
384 int host1x_client_suspend(struct host1x_client
*client
);
385 int host1x_client_resume(struct host1x_client
*client
);
387 struct tegra_mipi_device
;
389 struct tegra_mipi_device
*tegra_mipi_request(struct device
*device
,
390 struct device_node
*np
);
391 void tegra_mipi_free(struct tegra_mipi_device
*device
);
392 int tegra_mipi_enable(struct tegra_mipi_device
*device
);
393 int tegra_mipi_disable(struct tegra_mipi_device
*device
);
394 int tegra_mipi_start_calibration(struct tegra_mipi_device
*device
);
395 int tegra_mipi_finish_calibration(struct tegra_mipi_device
*device
);