Blame view

include/linux/host1x.h 8.74 KB
162163332   Thomas Gleixner   treewide: Replace...
1
  /* SPDX-License-Identifier: GPL-2.0-or-later */
6579324a4   Terje Bergstrom   gpu: host1x: Add ...
2
  /*
6579324a4   Terje Bergstrom   gpu: host1x: Add ...
3
   * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved.
6579324a4   Terje Bergstrom   gpu: host1x: Add ...
4
5
6
7
   */
  
  #ifndef __LINUX_HOST1X_H
  #define __LINUX_HOST1X_H
776dc3840   Thierry Reding   drm/tegra: Move s...
8
  #include <linux/device.h>
35d747a81   Thierry Reding   gpu: host1x: Expo...
9
  #include <linux/types.h>
6579324a4   Terje Bergstrom   gpu: host1x: Add ...
10
  enum host1x_class {
e1e906448   Thierry Reding   gpu: host1x: Make...
11
12
13
  	HOST1X_CLASS_HOST1X = 0x1,
  	HOST1X_CLASS_GR2D = 0x51,
  	HOST1X_CLASS_GR2D_SB = 0x52,
0ae797a8b   Arto Merilainen   drm/tegra: Add VI...
14
  	HOST1X_CLASS_VIC = 0x5D,
5f60ed0d8   Thierry Reding   drm/tegra: Add 3D...
15
  	HOST1X_CLASS_GR3D = 0x60,
6579324a4   Terje Bergstrom   gpu: host1x: Add ...
16
  };
501be6c1c   Thierry Reding   drm/tegra: Fix SM...
17
  struct host1x;
53fa7f720   Thierry Reding   drm/tegra: Introd...
18
  struct host1x_client;
aacdf1984   Thierry Reding   drm/tegra: Move I...
19
  struct iommu_group;
53fa7f720   Thierry Reding   drm/tegra: Introd...
20

501be6c1c   Thierry Reding   drm/tegra: Fix SM...
21
  u64 host1x_get_dma_mask(struct host1x *host1x);
466749f13   Thierry Reding   gpu: host1x: Fles...
22
23
24
25
  /**
   * struct host1x_client_ops - host1x client operations
   * @init: host1x client initialization code
   * @exit: host1x client tear down code
fd67e9c6e   Thierry Reding   drm/tegra: Do not...
26
27
   * @suspend: host1x client suspend code
   * @resume: host1x client resume code
466749f13   Thierry Reding   gpu: host1x: Fles...
28
   */
53fa7f720   Thierry Reding   drm/tegra: Introd...
29
30
31
  struct host1x_client_ops {
  	int (*init)(struct host1x_client *client);
  	int (*exit)(struct host1x_client *client);
fd67e9c6e   Thierry Reding   drm/tegra: Do not...
32
33
  	int (*suspend)(struct host1x_client *client);
  	int (*resume)(struct host1x_client *client);
53fa7f720   Thierry Reding   drm/tegra: Introd...
34
  };
466749f13   Thierry Reding   gpu: host1x: Fles...
35
36
37
  /**
   * struct host1x_client - host1x client structure
   * @list: list node for the host1x client
608f43ad2   Thierry Reding   gpu: host1x: Rena...
38
   * @host: pointer to struct device representing the host1x controller
466749f13   Thierry Reding   gpu: host1x: Fles...
39
   * @dev: pointer to struct device backing this host1x client
aacdf1984   Thierry Reding   drm/tegra: Move I...
40
   * @group: IOMMU group that this client is a member of
466749f13   Thierry Reding   gpu: host1x: Fles...
41
42
43
44
45
   * @ops: host1x client operations
   * @class: host1x class represented by this client
   * @channel: host1x channel associated with this client
   * @syncpts: array of syncpoints requested for this client
   * @num_syncpts: number of syncpoints requested for this client
2fd2bc7f4   Colton Lewis   gpu: host1x: Corr...
46
47
48
   * @parent: pointer to parent structure
   * @usecount: reference count for this structure
   * @lock: mutex for mutually exclusive concurrency
466749f13   Thierry Reding   gpu: host1x: Fles...
49
   */
53fa7f720   Thierry Reding   drm/tegra: Introd...
50
51
  struct host1x_client {
  	struct list_head list;
608f43ad2   Thierry Reding   gpu: host1x: Rena...
52
  	struct device *host;
53fa7f720   Thierry Reding   drm/tegra: Introd...
53
  	struct device *dev;
aacdf1984   Thierry Reding   drm/tegra: Move I...
54
  	struct iommu_group *group;
53fa7f720   Thierry Reding   drm/tegra: Introd...
55
56
57
58
59
60
61
62
  
  	const struct host1x_client_ops *ops;
  
  	enum host1x_class class;
  	struct host1x_channel *channel;
  
  	struct host1x_syncpt **syncpts;
  	unsigned int num_syncpts;
fd67e9c6e   Thierry Reding   drm/tegra: Do not...
63
64
65
66
  
  	struct host1x_client *parent;
  	unsigned int usecount;
  	struct mutex lock;
53fa7f720   Thierry Reding   drm/tegra: Introd...
67
  };
35d747a81   Thierry Reding   gpu: host1x: Expo...
68
69
70
71
72
73
74
75
76
77
  /*
   * host1x buffer objects
   */
  
  struct host1x_bo;
  struct sg_table;
  
  struct host1x_bo_ops {
  	struct host1x_bo *(*get)(struct host1x_bo *bo);
  	void (*put)(struct host1x_bo *bo);
80327ce3d   Thierry Reding   gpu: host1x: Over...
78
79
80
  	struct sg_table *(*pin)(struct device *dev, struct host1x_bo *bo,
  				dma_addr_t *phys);
  	void (*unpin)(struct device *dev, struct sg_table *sgt);
35d747a81   Thierry Reding   gpu: host1x: Expo...
81
82
  	void *(*mmap)(struct host1x_bo *bo);
  	void (*munmap)(struct host1x_bo *bo, void *addr);
35d747a81   Thierry Reding   gpu: host1x: Expo...
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  };
  
  struct host1x_bo {
  	const struct host1x_bo_ops *ops;
  };
  
  static inline void host1x_bo_init(struct host1x_bo *bo,
  				  const struct host1x_bo_ops *ops)
  {
  	bo->ops = ops;
  }
  
  static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
  {
  	return bo->ops->get(bo);
  }
  
  static inline void host1x_bo_put(struct host1x_bo *bo)
  {
  	bo->ops->put(bo);
  }
80327ce3d   Thierry Reding   gpu: host1x: Over...
104
105
106
  static inline struct sg_table *host1x_bo_pin(struct device *dev,
  					     struct host1x_bo *bo,
  					     dma_addr_t *phys)
35d747a81   Thierry Reding   gpu: host1x: Expo...
107
  {
80327ce3d   Thierry Reding   gpu: host1x: Over...
108
  	return bo->ops->pin(dev, bo, phys);
35d747a81   Thierry Reding   gpu: host1x: Expo...
109
  }
80327ce3d   Thierry Reding   gpu: host1x: Over...
110
111
  static inline void host1x_bo_unpin(struct device *dev, struct host1x_bo *bo,
  				   struct sg_table *sgt)
35d747a81   Thierry Reding   gpu: host1x: Expo...
112
  {
80327ce3d   Thierry Reding   gpu: host1x: Over...
113
  	bo->ops->unpin(dev, sgt);
35d747a81   Thierry Reding   gpu: host1x: Expo...
114
115
116
117
118
119
120
121
122
123
124
  }
  
  static inline void *host1x_bo_mmap(struct host1x_bo *bo)
  {
  	return bo->ops->mmap(bo);
  }
  
  static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
  {
  	bo->ops->munmap(bo, addr);
  }
35d747a81   Thierry Reding   gpu: host1x: Expo...
125
126
127
  /*
   * host1x syncpoints
   */
8736fe815   Arto Merilainen   gpu: host1x: Add ...
128
  #define HOST1X_SYNCPT_CLIENT_MANAGED	(1 << 0)
f5a954fed   Arto Merilainen   gpu: host1x: Add ...
129
  #define HOST1X_SYNCPT_HAS_BASE		(1 << 1)
8736fe815   Arto Merilainen   gpu: host1x: Add ...
130

f5a954fed   Arto Merilainen   gpu: host1x: Add ...
131
  struct host1x_syncpt_base;
35d747a81   Thierry Reding   gpu: host1x: Expo...
132
133
134
135
136
137
138
  struct host1x_syncpt;
  struct host1x;
  
  struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
  u32 host1x_syncpt_id(struct host1x_syncpt *sp);
  u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
  u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
b4a20144e   Thierry Reding   gpu: host1x: Expo...
139
  u32 host1x_syncpt_read(struct host1x_syncpt *sp);
35d747a81   Thierry Reding   gpu: host1x: Expo...
140
  int host1x_syncpt_incr(struct host1x_syncpt *sp);
64400c379   Bryan Wu   gpu: host1x: expo...
141
  u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
35d747a81   Thierry Reding   gpu: host1x: Expo...
142
143
  int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
  		       u32 *value);
617dd7cc4   Thierry Reding   gpu: host1x: sync...
144
  struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
8736fe815   Arto Merilainen   gpu: host1x: Add ...
145
  					    unsigned long flags);
35d747a81   Thierry Reding   gpu: host1x: Expo...
146
  void host1x_syncpt_free(struct host1x_syncpt *sp);
f5a954fed   Arto Merilainen   gpu: host1x: Add ...
147
148
  struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
  u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
35d747a81   Thierry Reding   gpu: host1x: Expo...
149
150
151
152
153
154
  /*
   * host1x channel
   */
  
  struct host1x_channel;
  struct host1x_job;
caccddcfc   Thierry Reding   gpu: host1x: Requ...
155
  struct host1x_channel *host1x_channel_request(struct host1x_client *client);
35d747a81   Thierry Reding   gpu: host1x: Expo...
156
157
158
159
160
161
162
  struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
  void host1x_channel_put(struct host1x_channel *channel);
  int host1x_job_submit(struct host1x_job *job);
  
  /*
   * host1x job
   */
ab4f81bfc   Thierry Reding   gpu: host1x: Add ...
163
164
  #define HOST1X_RELOC_READ	(1 << 0)
  #define HOST1X_RELOC_WRITE	(1 << 1)
35d747a81   Thierry Reding   gpu: host1x: Expo...
165
  struct host1x_reloc {
961e3beae   Thierry Reding   drm/tegra: Make j...
166
167
168
169
170
171
172
173
174
  	struct {
  		struct host1x_bo *bo;
  		unsigned long offset;
  	} cmdbuf;
  	struct {
  		struct host1x_bo *bo;
  		unsigned long offset;
  	} target;
  	unsigned long shift;
ab4f81bfc   Thierry Reding   gpu: host1x: Add ...
175
  	unsigned long flags;
35d747a81   Thierry Reding   gpu: host1x: Expo...
176
177
178
179
180
181
182
183
184
185
186
  };
  
  struct host1x_job {
  	/* When refcount goes to zero, job can be freed */
  	struct kref ref;
  
  	/* List entry */
  	struct list_head list;
  
  	/* Channel where job is submitted to */
  	struct host1x_channel *channel;
bf3d41cca   Thierry Reding   gpu: host1x: Stor...
187
188
  	/* client where the job originated */
  	struct host1x_client *client;
35d747a81   Thierry Reding   gpu: host1x: Expo...
189
190
191
192
  
  	/* Gathers and their memory */
  	struct host1x_job_gather *gathers;
  	unsigned int num_gathers;
35d747a81   Thierry Reding   gpu: host1x: Expo...
193
  	/* Array of handles to be pinned & unpinned */
06490bb99   Thierry Reding   gpu: host1x: Rena...
194
  	struct host1x_reloc *relocs;
35d747a81   Thierry Reding   gpu: host1x: Expo...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
  	unsigned int num_relocs;
  	struct host1x_job_unpin_data *unpins;
  	unsigned int num_unpins;
  
  	dma_addr_t *addr_phys;
  	dma_addr_t *gather_addr_phys;
  	dma_addr_t *reloc_addr_phys;
  
  	/* Sync point id, number of increments and end related to the submit */
  	u32 syncpt_id;
  	u32 syncpt_incrs;
  	u32 syncpt_end;
  
  	/* Maximum time to wait for this job */
  	unsigned int timeout;
  
  	/* Index and number of slots used in the push buffer */
  	unsigned int first_get;
  	unsigned int num_slots;
  
  	/* Copy of gathers */
  	size_t gather_copy_size;
  	dma_addr_t gather_copy;
  	u8 *gather_copy_mapped;
  
  	/* Check if register is marked as an address reg */
a2b78b0d5   Dmitry Osipenko   gpu: host1x: Corr...
221
  	int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
35d747a81   Thierry Reding   gpu: host1x: Expo...
222

0f563a4bf   Dmitry Osipenko   gpu: host1x: Forb...
223
224
  	/* Check if class belongs to the unit */
  	int (*is_valid_class)(u32 class);
35d747a81   Thierry Reding   gpu: host1x: Expo...
225
226
227
228
229
230
231
232
  	/* Request a SETCLASS to this class */
  	u32 class;
  
  	/* Add a channel wait for previous ops to complete */
  	bool serialize;
  };
  
  struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
24c94e166   Thierry Reding   gpu: host1x: Remo...
233
  				    u32 num_cmdbufs, u32 num_relocs);
326bbd79f   Thierry Reding   gpu: host1x: Use ...
234
235
  void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo,
  			   unsigned int words, unsigned int offset);
35d747a81   Thierry Reding   gpu: host1x: Expo...
236
237
238
239
  struct host1x_job *host1x_job_get(struct host1x_job *job);
  void host1x_job_put(struct host1x_job *job);
  int host1x_job_pin(struct host1x_job *job, struct device *dev);
  void host1x_job_unpin(struct host1x_job *job);
776dc3840   Thierry Reding   drm/tegra: Move s...
240
241
242
243
244
  /*
   * subdevice probe infrastructure
   */
  
  struct host1x_device;
466749f13   Thierry Reding   gpu: host1x: Fles...
245
246
247
248
249
250
251
252
253
  /**
   * struct host1x_driver - host1x logical device driver
   * @driver: core driver
   * @subdevs: table of OF device IDs matching subdevices for this driver
   * @list: list node for the driver
   * @probe: called when the host1x logical device is probed
   * @remove: called when the host1x logical device is removed
   * @shutdown: called when the host1x logical device is shut down
   */
776dc3840   Thierry Reding   drm/tegra: Move s...
254
  struct host1x_driver {
f4c5cf88f   Thierry Reding   gpu: host1x: Prov...
255
  	struct device_driver driver;
776dc3840   Thierry Reding   drm/tegra: Move s...
256
257
  	const struct of_device_id *subdevs;
  	struct list_head list;
776dc3840   Thierry Reding   drm/tegra: Move s...
258
259
260
  
  	int (*probe)(struct host1x_device *device);
  	int (*remove)(struct host1x_device *device);
f4c5cf88f   Thierry Reding   gpu: host1x: Prov...
261
  	void (*shutdown)(struct host1x_device *device);
776dc3840   Thierry Reding   drm/tegra: Move s...
262
  };
f4c5cf88f   Thierry Reding   gpu: host1x: Prov...
263
264
265
266
267
268
269
270
  static inline struct host1x_driver *
  to_host1x_driver(struct device_driver *driver)
  {
  	return container_of(driver, struct host1x_driver, driver);
  }
  
  int host1x_driver_register_full(struct host1x_driver *driver,
  				struct module *owner);
776dc3840   Thierry Reding   drm/tegra: Move s...
271
  void host1x_driver_unregister(struct host1x_driver *driver);
f4c5cf88f   Thierry Reding   gpu: host1x: Prov...
272
273
  #define host1x_driver_register(driver) \
  	host1x_driver_register_full(driver, THIS_MODULE)
776dc3840   Thierry Reding   drm/tegra: Move s...
274
275
276
277
278
279
280
281
282
283
284
  struct host1x_device {
  	struct host1x_driver *driver;
  	struct list_head list;
  	struct device dev;
  
  	struct mutex subdevs_lock;
  	struct list_head subdevs;
  	struct list_head active;
  
  	struct mutex clients_lock;
  	struct list_head clients;
536e17152   Thierry Reding   gpu: host1x: Call...
285

f4c5cf88f   Thierry Reding   gpu: host1x: Prov...
286
  	bool registered;
1e390478c   Thierry Reding   gpu: host1x: Incr...
287
288
  
  	struct device_dma_parameters dma_parms;
776dc3840   Thierry Reding   drm/tegra: Move s...
289
290
291
292
293
294
295
296
297
298
299
300
  };
  
  static inline struct host1x_device *to_host1x_device(struct device *dev)
  {
  	return container_of(dev, struct host1x_device, dev);
  }
  
  int host1x_device_init(struct host1x_device *device);
  int host1x_device_exit(struct host1x_device *device);
  
  int host1x_client_register(struct host1x_client *client);
  int host1x_client_unregister(struct host1x_client *client);
fd67e9c6e   Thierry Reding   drm/tegra: Do not...
301
302
  int host1x_client_suspend(struct host1x_client *client);
  int host1x_client_resume(struct host1x_client *client);
4de6a2d6a   Thierry Reding   gpu: host1x: Add ...
303
  struct tegra_mipi_device;
767598d44   Sowjanya Komatineni   gpu: host1x: mipi...
304
305
  struct tegra_mipi_device *tegra_mipi_request(struct device *device,
  					     struct device_node *np);
4de6a2d6a   Thierry Reding   gpu: host1x: Add ...
306
  void tegra_mipi_free(struct tegra_mipi_device *device);
87904c3e8   Thierry Reding   drm/tegra: dsi: E...
307
308
  int tegra_mipi_enable(struct tegra_mipi_device *device);
  int tegra_mipi_disable(struct tegra_mipi_device *device);
cf5153e43   Sowjanya Komatineni   media: gpu: host1...
309
310
  int tegra_mipi_start_calibration(struct tegra_mipi_device *device);
  int tegra_mipi_finish_calibration(struct tegra_mipi_device *device);
4de6a2d6a   Thierry Reding   gpu: host1x: Add ...
311

6579324a4   Terje Bergstrom   gpu: host1x: Add ...
312
  #endif