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 * struct host1x_client_ops - host1x client operations
25 * @init: host1x client initialization code
26 * @exit: host1x client tear down code
27 * @suspend: host1x client suspend code
28 * @resume: host1x client resume code
30 struct host1x_client_ops
{
31 int (*init
)(struct host1x_client
*client
);
32 int (*exit
)(struct host1x_client
*client
);
33 int (*suspend
)(struct host1x_client
*client
);
34 int (*resume
)(struct host1x_client
*client
);
38 * struct host1x_client - host1x client structure
39 * @list: list node for the host1x client
40 * @host: pointer to struct device representing the host1x controller
41 * @dev: pointer to struct device backing this host1x client
42 * @group: IOMMU group that this client is a member of
43 * @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
49 struct host1x_client
{
50 struct list_head list
;
53 struct iommu_group
*group
;
55 const struct host1x_client_ops
*ops
;
57 enum host1x_class
class;
58 struct host1x_channel
*channel
;
60 struct host1x_syncpt
**syncpts
;
61 unsigned int num_syncpts
;
63 struct host1x_client
*parent
;
64 unsigned int usecount
;
69 * host1x buffer objects
75 struct host1x_bo_ops
{
76 struct host1x_bo
*(*get
)(struct host1x_bo
*bo
);
77 void (*put
)(struct host1x_bo
*bo
);
78 struct sg_table
*(*pin
)(struct device
*dev
, struct host1x_bo
*bo
,
80 void (*unpin
)(struct device
*dev
, struct sg_table
*sgt
);
81 void *(*mmap
)(struct host1x_bo
*bo
);
82 void (*munmap
)(struct host1x_bo
*bo
, void *addr
);
86 const struct host1x_bo_ops
*ops
;
89 static inline void host1x_bo_init(struct host1x_bo
*bo
,
90 const struct host1x_bo_ops
*ops
)
95 static inline struct host1x_bo
*host1x_bo_get(struct host1x_bo
*bo
)
97 return bo
->ops
->get(bo
);
100 static inline void host1x_bo_put(struct host1x_bo
*bo
)
105 static inline struct sg_table
*host1x_bo_pin(struct device
*dev
,
106 struct host1x_bo
*bo
,
109 return bo
->ops
->pin(dev
, bo
, phys
);
112 static inline void host1x_bo_unpin(struct device
*dev
, struct host1x_bo
*bo
,
113 struct sg_table
*sgt
)
115 bo
->ops
->unpin(dev
, sgt
);
118 static inline void *host1x_bo_mmap(struct host1x_bo
*bo
)
120 return bo
->ops
->mmap(bo
);
123 static inline void host1x_bo_munmap(struct host1x_bo
*bo
, void *addr
)
125 bo
->ops
->munmap(bo
, addr
);
132 #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
133 #define HOST1X_SYNCPT_HAS_BASE (1 << 1)
135 struct host1x_syncpt_base
;
136 struct host1x_syncpt
;
139 struct host1x_syncpt
*host1x_syncpt_get(struct host1x
*host
, u32 id
);
140 u32
host1x_syncpt_id(struct host1x_syncpt
*sp
);
141 u32
host1x_syncpt_read_min(struct host1x_syncpt
*sp
);
142 u32
host1x_syncpt_read_max(struct host1x_syncpt
*sp
);
143 u32
host1x_syncpt_read(struct host1x_syncpt
*sp
);
144 int host1x_syncpt_incr(struct host1x_syncpt
*sp
);
145 u32
host1x_syncpt_incr_max(struct host1x_syncpt
*sp
, u32 incrs
);
146 int host1x_syncpt_wait(struct host1x_syncpt
*sp
, u32 thresh
, long timeout
,
148 struct host1x_syncpt
*host1x_syncpt_request(struct host1x_client
*client
,
149 unsigned long flags
);
150 void host1x_syncpt_free(struct host1x_syncpt
*sp
);
152 struct host1x_syncpt_base
*host1x_syncpt_get_base(struct host1x_syncpt
*sp
);
153 u32
host1x_syncpt_base_id(struct host1x_syncpt_base
*base
);
159 struct host1x_channel
;
162 struct host1x_channel
*host1x_channel_request(struct host1x_client
*client
);
163 struct host1x_channel
*host1x_channel_get(struct host1x_channel
*channel
);
164 void host1x_channel_put(struct host1x_channel
*channel
);
165 int host1x_job_submit(struct host1x_job
*job
);
171 #define HOST1X_RELOC_READ (1 << 0)
172 #define HOST1X_RELOC_WRITE (1 << 1)
174 struct host1x_reloc
{
176 struct host1x_bo
*bo
;
177 unsigned long offset
;
180 struct host1x_bo
*bo
;
181 unsigned long offset
;
188 /* When refcount goes to zero, job can be freed */
192 struct list_head list
;
194 /* Channel where job is submitted to */
195 struct host1x_channel
*channel
;
197 /* client where the job originated */
198 struct host1x_client
*client
;
200 /* Gathers and their memory */
201 struct host1x_job_gather
*gathers
;
202 unsigned int num_gathers
;
204 /* Array of handles to be pinned & unpinned */
205 struct host1x_reloc
*relocs
;
206 unsigned int num_relocs
;
207 struct host1x_job_unpin_data
*unpins
;
208 unsigned int num_unpins
;
210 dma_addr_t
*addr_phys
;
211 dma_addr_t
*gather_addr_phys
;
212 dma_addr_t
*reloc_addr_phys
;
214 /* Sync point id, number of increments and end related to the submit */
219 /* Maximum time to wait for this job */
220 unsigned int timeout
;
222 /* Index and number of slots used in the push buffer */
223 unsigned int first_get
;
224 unsigned int num_slots
;
226 /* Copy of gathers */
227 size_t gather_copy_size
;
228 dma_addr_t gather_copy
;
229 u8
*gather_copy_mapped
;
231 /* Check if register is marked as an address reg */
232 int (*is_addr_reg
)(struct device
*dev
, u32
class, u32 reg
);
234 /* Check if class belongs to the unit */
235 int (*is_valid_class
)(u32
class);
237 /* Request a SETCLASS to this class */
240 /* Add a channel wait for previous ops to complete */
244 struct host1x_job
*host1x_job_alloc(struct host1x_channel
*ch
,
245 u32 num_cmdbufs
, u32 num_relocs
);
246 void host1x_job_add_gather(struct host1x_job
*job
, struct host1x_bo
*bo
,
247 unsigned int words
, unsigned int offset
);
248 struct host1x_job
*host1x_job_get(struct host1x_job
*job
);
249 void host1x_job_put(struct host1x_job
*job
);
250 int host1x_job_pin(struct host1x_job
*job
, struct device
*dev
);
251 void host1x_job_unpin(struct host1x_job
*job
);
254 * subdevice probe infrastructure
257 struct host1x_device
;
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
268 struct host1x_driver
{
269 struct device_driver driver
;
271 const struct of_device_id
*subdevs
;
272 struct list_head list
;
274 int (*probe
)(struct host1x_device
*device
);
275 int (*remove
)(struct host1x_device
*device
);
276 void (*shutdown
)(struct host1x_device
*device
);
279 static inline struct host1x_driver
*
280 to_host1x_driver(struct device_driver
*driver
)
282 return container_of(driver
, struct host1x_driver
, driver
);
285 int host1x_driver_register_full(struct host1x_driver
*driver
,
286 struct module
*owner
);
287 void host1x_driver_unregister(struct host1x_driver
*driver
);
289 #define host1x_driver_register(driver) \
290 host1x_driver_register_full(driver, THIS_MODULE)
292 struct host1x_device
{
293 struct host1x_driver
*driver
;
294 struct list_head list
;
297 struct mutex subdevs_lock
;
298 struct list_head subdevs
;
299 struct list_head active
;
301 struct mutex clients_lock
;
302 struct list_head clients
;
306 struct device_dma_parameters dma_parms
;
309 static inline struct host1x_device
*to_host1x_device(struct device
*dev
)
311 return container_of(dev
, struct host1x_device
, dev
);
314 int host1x_device_init(struct host1x_device
*device
);
315 int host1x_device_exit(struct host1x_device
*device
);
317 int host1x_client_register(struct host1x_client
*client
);
318 int host1x_client_unregister(struct host1x_client
*client
);
320 int host1x_client_suspend(struct host1x_client
*client
);
321 int host1x_client_resume(struct host1x_client
*client
);
323 struct tegra_mipi_device
;
325 struct tegra_mipi_device
*tegra_mipi_request(struct device
*device
);
326 void tegra_mipi_free(struct tegra_mipi_device
*device
);
327 int tegra_mipi_enable(struct tegra_mipi_device
*device
);
328 int tegra_mipi_disable(struct tegra_mipi_device
*device
);
329 int tegra_mipi_calibrate(struct tegra_mipi_device
*device
);