]>
Commit | Line | Data |
---|---|---|
85e634bc DV |
1 | /* |
2 | * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. | |
3 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. | |
4 | * Copyright (c) 2009-2010, Code Aurora Forum. | |
5 | * Copyright 2016 Intel Corp. | |
6 | * | |
7 | * Permission is hereby granted, free of charge, to any person obtaining a | |
8 | * copy of this software and associated documentation files (the "Software"), | |
9 | * to deal in the Software without restriction, including without limitation | |
10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
11 | * and/or sell copies of the Software, and to permit persons to whom the | |
12 | * Software is furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice (including the next | |
15 | * paragraph) shall be included in all copies or substantial portions of the | |
16 | * Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
21 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
22 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
23 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
24 | * OTHER DEALINGS IN THE SOFTWARE. | |
25 | */ | |
26 | ||
27 | #ifndef _DRM_DRV_H_ | |
28 | #define _DRM_DRV_H_ | |
29 | ||
30 | #include <linux/list.h> | |
31 | #include <linux/irqreturn.h> | |
32 | ||
33 | struct drm_device; | |
34 | struct drm_file; | |
35 | struct drm_gem_object; | |
36 | struct drm_master; | |
37 | struct drm_minor; | |
38 | struct dma_buf_attachment; | |
39 | struct drm_display_mode; | |
40 | struct drm_mode_create_dumb; | |
41 | ||
42 | /* driver capabilities and requirements mask */ | |
43 | #define DRIVER_USE_AGP 0x1 | |
44 | #define DRIVER_LEGACY 0x2 | |
45 | #define DRIVER_PCI_DMA 0x8 | |
46 | #define DRIVER_SG 0x10 | |
47 | #define DRIVER_HAVE_DMA 0x20 | |
48 | #define DRIVER_HAVE_IRQ 0x40 | |
49 | #define DRIVER_IRQ_SHARED 0x80 | |
50 | #define DRIVER_GEM 0x1000 | |
51 | #define DRIVER_MODESET 0x2000 | |
52 | #define DRIVER_PRIME 0x4000 | |
53 | #define DRIVER_RENDER 0x8000 | |
54 | #define DRIVER_ATOMIC 0x10000 | |
55 | #define DRIVER_KMS_LEGACY_CONTEXT 0x20000 | |
56 | ||
57 | /** | |
58 | * struct drm_driver - DRM driver structure | |
59 | * | |
60 | * This structure represent the common code for a family of cards. There will | |
61 | * one drm_device for each card present in this family. It contains lots of | |
62 | * vfunc entries, and a pile of those probably should be moved to more | |
63 | * appropriate places like &drm_mode_config_funcs or into a new operations | |
64 | * structure for GEM drivers. | |
65 | */ | |
66 | struct drm_driver { | |
56926500 GKB |
67 | |
68 | /** | |
69 | * @load: | |
70 | * | |
71 | * Backward-compatible driver callback to complete | |
72 | * initialization steps after the driver is registered. For | |
73 | * this reason, may suffer from race conditions and its use is | |
74 | * deprecated for new drivers. It is therefore only supported | |
75 | * for existing drivers not yet converted to the new scheme. | |
76 | * See drm_dev_init() and drm_dev_register() for proper and | |
77 | * race-free way to set up a &struct drm_device. | |
78 | * | |
79 | * Returns: | |
80 | * | |
81 | * Zero on success, non-zero value on failure. | |
82 | */ | |
85e634bc | 83 | int (*load) (struct drm_device *, unsigned long flags); |
85e634bc DV |
84 | int (*open) (struct drm_device *, struct drm_file *); |
85 | void (*preclose) (struct drm_device *, struct drm_file *file_priv); | |
86 | void (*postclose) (struct drm_device *, struct drm_file *); | |
87 | void (*lastclose) (struct drm_device *); | |
56926500 GKB |
88 | |
89 | /** | |
90 | * @unload: | |
91 | * | |
92 | * Reverse the effects of the driver load callback. Ideally, | |
93 | * the clean up performed by the driver should happen in the | |
94 | * reverse order of the initialization. Similarly to the load | |
95 | * hook, this handler is deprecated and its usage should be | |
96 | * dropped in favor of an open-coded teardown function at the | |
97 | * driver layer. See drm_dev_unregister() and drm_dev_unref() | |
98 | * for the proper way to remove a &struct drm_device. | |
99 | * | |
100 | * The unload() hook is called right after unregistering | |
101 | * the device. | |
102 | * | |
56926500 | 103 | */ |
11b3c20b | 104 | void (*unload) (struct drm_device *); |
85e634bc DV |
105 | int (*set_busid)(struct drm_device *dev, struct drm_master *master); |
106 | ||
107 | /** | |
6c4789ed | 108 | * @get_vblank_counter: |
85e634bc | 109 | * |
6c4789ed DV |
110 | * Driver callback for fetching a raw hardware vblank counter for the |
111 | * CRTC specified with the pipe argument. If a device doesn't have a | |
112 | * hardware counter, the driver can simply use | |
113 | * drm_vblank_no_hw_counter() function. The DRM core will account for | |
85e634bc DV |
114 | * missed vblank events while interrupts where disabled based on system |
115 | * timestamps. | |
116 | * | |
117 | * Wraparound handling and loss of events due to modesetting is dealt | |
6c4789ed DV |
118 | * with in the DRM core code, as long as drivers call |
119 | * drm_crtc_vblank_off() and drm_crtc_vblank_on() when disabling or | |
120 | * enabling a CRTC. | |
121 | * | |
122 | * Returns: | |
85e634bc | 123 | * |
85e634bc DV |
124 | * Raw vblank counter value. |
125 | */ | |
126 | u32 (*get_vblank_counter) (struct drm_device *dev, unsigned int pipe); | |
127 | ||
128 | /** | |
6c4789ed DV |
129 | * @enable_vblank: |
130 | * | |
131 | * Enable vblank interrupts for the CRTC specified with the pipe | |
132 | * argument. | |
85e634bc | 133 | * |
6c4789ed | 134 | * Returns: |
85e634bc | 135 | * |
85e634bc DV |
136 | * Zero on success, appropriate errno if the given @crtc's vblank |
137 | * interrupt cannot be enabled. | |
138 | */ | |
139 | int (*enable_vblank) (struct drm_device *dev, unsigned int pipe); | |
140 | ||
141 | /** | |
6c4789ed | 142 | * @disable_vblank: |
85e634bc | 143 | * |
6c4789ed DV |
144 | * Disable vblank interrupts for the CRTC specified with the pipe |
145 | * argument. | |
85e634bc DV |
146 | */ |
147 | void (*disable_vblank) (struct drm_device *dev, unsigned int pipe); | |
148 | ||
85e634bc | 149 | /** |
6c4789ed DV |
150 | * @get_scanout_position: |
151 | * | |
85e634bc DV |
152 | * Called by vblank timestamping code. |
153 | * | |
6c4789ed DV |
154 | * Returns the current display scanout position from a crtc, and an |
155 | * optional accurate ktime_get() timestamp of when position was | |
156 | * measured. Note that this is a helper callback which is only used if a | |
157 | * driver uses drm_calc_vbltimestamp_from_scanoutpos() for the | |
158 | * @get_vblank_timestamp callback. | |
159 | * | |
160 | * Parameters: | |
85e634bc | 161 | * |
6c4789ed DV |
162 | * dev: |
163 | * DRM device. | |
164 | * pipe: | |
165 | * Id of the crtc to query. | |
166 | * flags: | |
167 | * Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0). | |
168 | * vpos: | |
169 | * Target location for current vertical scanout position. | |
170 | * hpos: | |
171 | * Target location for current horizontal scanout position. | |
172 | * stime: | |
173 | * Target location for timestamp taken immediately before | |
174 | * scanout position query. Can be NULL to skip timestamp. | |
175 | * etime: | |
176 | * Target location for timestamp taken immediately after | |
177 | * scanout position query. Can be NULL to skip timestamp. | |
178 | * mode: | |
179 | * Current display timings. | |
85e634bc DV |
180 | * |
181 | * Returns vpos as a positive number while in active scanout area. | |
182 | * Returns vpos as a negative number inside vblank, counting the number | |
183 | * of scanlines to go until end of vblank, e.g., -1 means "one scanline | |
184 | * until start of active scanout / end of vblank." | |
185 | * | |
6c4789ed DV |
186 | * Returns: |
187 | * | |
188 | * Flags, or'ed together as follows: | |
85e634bc | 189 | * |
6c4789ed DV |
190 | * DRM_SCANOUTPOS_VALID: |
191 | * Query successful. | |
192 | * DRM_SCANOUTPOS_INVBL: | |
193 | * Inside vblank. | |
194 | * DRM_SCANOUTPOS_ACCURATE: Returned position is accurate. A lack of | |
195 | * this flag means that returned position may be offset by a | |
196 | * constant but unknown small number of scanlines wrt. real scanout | |
197 | * position. | |
85e634bc DV |
198 | * |
199 | */ | |
200 | int (*get_scanout_position) (struct drm_device *dev, unsigned int pipe, | |
201 | unsigned int flags, int *vpos, int *hpos, | |
202 | ktime_t *stime, ktime_t *etime, | |
203 | const struct drm_display_mode *mode); | |
204 | ||
205 | /** | |
6c4789ed DV |
206 | * @get_vblank_timestamp: |
207 | * | |
208 | * Called by drm_get_last_vbltimestamp(). Should return a precise | |
85e634bc DV |
209 | * timestamp when the most recent VBLANK interval ended or will end. |
210 | * | |
211 | * Specifically, the timestamp in @vblank_time should correspond as | |
212 | * closely as possible to the time when the first video scanline of | |
213 | * the video frame after the end of VBLANK will start scanning out, | |
214 | * the time immediately after end of the VBLANK interval. If the | |
215 | * @crtc is currently inside VBLANK, this will be a time in the future. | |
216 | * If the @crtc is currently scanning out a frame, this will be the | |
217 | * past start time of the current scanout. This is meant to adhere | |
218 | * to the OpenML OML_sync_control extension specification. | |
219 | * | |
6c4789ed DV |
220 | * Paramters: |
221 | * | |
222 | * dev: | |
223 | * dev DRM device handle. | |
224 | * pipe: | |
225 | * crtc for which timestamp should be returned. | |
226 | * max_error: | |
227 | * Maximum allowable timestamp error in nanoseconds. | |
228 | * Implementation should strive to provide timestamp | |
229 | * with an error of at most max_error nanoseconds. | |
230 | * Returns true upper bound on error for timestamp. | |
231 | * vblank_time: | |
232 | * Target location for returned vblank timestamp. | |
233 | * flags: | |
234 | * 0 = Defaults, no special treatment needed. | |
235 | * DRM_CALLED_FROM_VBLIRQ = Function is called from vblank | |
236 | * irq handler. Some drivers need to apply some workarounds | |
237 | * for gpu-specific vblank irq quirks if flag is set. | |
238 | * | |
239 | * Returns: | |
240 | * | |
85e634bc DV |
241 | * Zero if timestamping isn't supported in current display mode or a |
242 | * negative number on failure. A positive status code on success, | |
243 | * which describes how the vblank_time timestamp was computed. | |
244 | */ | |
245 | int (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe, | |
246 | int *max_error, | |
247 | struct timeval *vblank_time, | |
248 | unsigned flags); | |
249 | ||
250 | /* these have to be filled in */ | |
251 | ||
252 | irqreturn_t(*irq_handler) (int irq, void *arg); | |
253 | void (*irq_preinstall) (struct drm_device *dev); | |
254 | int (*irq_postinstall) (struct drm_device *dev); | |
255 | void (*irq_uninstall) (struct drm_device *dev); | |
256 | ||
6c4789ed DV |
257 | /** |
258 | * @master_create: | |
259 | * | |
260 | * Called whenever a new master is created. Only used by vmwgfx. | |
261 | */ | |
85e634bc | 262 | int (*master_create)(struct drm_device *dev, struct drm_master *master); |
6c4789ed | 263 | |
85e634bc | 264 | /** |
6c4789ed DV |
265 | * @master_destroy: |
266 | * | |
267 | * Called whenever a master is destroyed. Only used by vmwgfx. | |
85e634bc | 268 | */ |
6c4789ed | 269 | void (*master_destroy)(struct drm_device *dev, struct drm_master *master); |
85e634bc | 270 | |
6c4789ed DV |
271 | /** |
272 | * @master_set: | |
273 | * | |
274 | * Called whenever the minor master is set. Only used by vmwgfx. | |
275 | */ | |
85e634bc DV |
276 | int (*master_set)(struct drm_device *dev, struct drm_file *file_priv, |
277 | bool from_open); | |
6c4789ed DV |
278 | /** |
279 | * @master_drop: | |
280 | * | |
281 | * Called whenever the minor master is dropped. Only used by vmwgfx. | |
282 | */ | |
85e634bc DV |
283 | void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv); |
284 | ||
285 | int (*debugfs_init)(struct drm_minor *minor); | |
286 | void (*debugfs_cleanup)(struct drm_minor *minor); | |
287 | ||
288 | /** | |
289 | * @gem_free_object: deconstructor for drm_gem_objects | |
290 | * | |
291 | * This is deprecated and should not be used by new drivers. Use | |
292 | * @gem_free_object_unlocked instead. | |
293 | */ | |
294 | void (*gem_free_object) (struct drm_gem_object *obj); | |
295 | ||
296 | /** | |
297 | * @gem_free_object_unlocked: deconstructor for drm_gem_objects | |
298 | * | |
ef40cbf9 | 299 | * This is for drivers which are not encumbered with &drm_device.struct_mutex |
85e634bc DV |
300 | * legacy locking schemes. Use this hook instead of @gem_free_object. |
301 | */ | |
302 | void (*gem_free_object_unlocked) (struct drm_gem_object *obj); | |
303 | ||
304 | int (*gem_open_object) (struct drm_gem_object *, struct drm_file *); | |
305 | void (*gem_close_object) (struct drm_gem_object *, struct drm_file *); | |
306 | ||
307 | /** | |
218adc17 CW |
308 | * @gem_create_object: constructor for gem objects |
309 | * | |
85e634bc DV |
310 | * Hook for allocating the GEM object struct, for use by core |
311 | * helpers. | |
312 | */ | |
313 | struct drm_gem_object *(*gem_create_object)(struct drm_device *dev, | |
314 | size_t size); | |
315 | ||
316 | /* prime: */ | |
317 | /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */ | |
318 | int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv, | |
319 | uint32_t handle, uint32_t flags, int *prime_fd); | |
320 | /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */ | |
321 | int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv, | |
322 | int prime_fd, uint32_t *handle); | |
323 | /* export GEM -> dmabuf */ | |
324 | struct dma_buf * (*gem_prime_export)(struct drm_device *dev, | |
325 | struct drm_gem_object *obj, int flags); | |
326 | /* import dmabuf -> GEM */ | |
327 | struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev, | |
328 | struct dma_buf *dma_buf); | |
329 | /* low-level interface used by drm_gem_prime_{import,export} */ | |
330 | int (*gem_prime_pin)(struct drm_gem_object *obj); | |
331 | void (*gem_prime_unpin)(struct drm_gem_object *obj); | |
332 | struct reservation_object * (*gem_prime_res_obj)( | |
333 | struct drm_gem_object *obj); | |
334 | struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj); | |
335 | struct drm_gem_object *(*gem_prime_import_sg_table)( | |
336 | struct drm_device *dev, | |
337 | struct dma_buf_attachment *attach, | |
338 | struct sg_table *sgt); | |
339 | void *(*gem_prime_vmap)(struct drm_gem_object *obj); | |
340 | void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr); | |
341 | int (*gem_prime_mmap)(struct drm_gem_object *obj, | |
342 | struct vm_area_struct *vma); | |
343 | ||
4f93624e DV |
344 | /** |
345 | * @dumb_create: | |
346 | * | |
347 | * This creates a new dumb buffer in the driver's backing storage manager (GEM, | |
348 | * TTM or something else entirely) and returns the resulting buffer handle. This | |
349 | * handle can then be wrapped up into a framebuffer modeset object. | |
350 | * | |
351 | * Note that userspace is not allowed to use such objects for render | |
352 | * acceleration - drivers must create their own private ioctls for such a use | |
353 | * case. | |
354 | * | |
355 | * Width, height and depth are specified in the &drm_mode_create_dumb | |
356 | * argument. The callback needs to fill the handle, pitch and size for | |
357 | * the created buffer. | |
358 | * | |
359 | * Called by the user via ioctl. | |
360 | * | |
361 | * Returns: | |
362 | * | |
363 | * Zero on success, negative errno on failure. | |
364 | */ | |
85e634bc DV |
365 | int (*dumb_create)(struct drm_file *file_priv, |
366 | struct drm_device *dev, | |
367 | struct drm_mode_create_dumb *args); | |
4f93624e DV |
368 | /** |
369 | * @dumb_map_offset: | |
370 | * | |
371 | * Allocate an offset in the drm device node's address space to be able to | |
372 | * memory map a dumb buffer. GEM-based drivers must use | |
373 | * drm_gem_create_mmap_offset() to implement this. | |
374 | * | |
375 | * Called by the user via ioctl. | |
376 | * | |
377 | * Returns: | |
378 | * | |
379 | * Zero on success, negative errno on failure. | |
380 | */ | |
85e634bc DV |
381 | int (*dumb_map_offset)(struct drm_file *file_priv, |
382 | struct drm_device *dev, uint32_t handle, | |
383 | uint64_t *offset); | |
4f93624e DV |
384 | /** |
385 | * @dumb_destroy: | |
386 | * | |
387 | * This destroys the userspace handle for the given dumb backing storage buffer. | |
388 | * Since buffer objects must be reference counted in the kernel a buffer object | |
389 | * won't be immediately freed if a framebuffer modeset object still uses it. | |
390 | * | |
391 | * Called by the user via ioctl. | |
392 | * | |
393 | * Returns: | |
394 | * | |
395 | * Zero on success, negative errno on failure. | |
396 | */ | |
85e634bc DV |
397 | int (*dumb_destroy)(struct drm_file *file_priv, |
398 | struct drm_device *dev, | |
399 | uint32_t handle); | |
400 | ||
401 | /* Driver private ops for this object */ | |
402 | const struct vm_operations_struct *gem_vm_ops; | |
403 | ||
404 | int major; | |
405 | int minor; | |
406 | int patchlevel; | |
407 | char *name; | |
408 | char *desc; | |
409 | char *date; | |
410 | ||
411 | u32 driver_features; | |
85e634bc DV |
412 | const struct drm_ioctl_desc *ioctls; |
413 | int num_ioctls; | |
414 | const struct file_operations *fops; | |
415 | ||
0683c0ab DV |
416 | /* Everything below here is for legacy driver, never use! */ |
417 | /* private: */ | |
418 | ||
85e634bc DV |
419 | /* List of devices hanging off this driver with stealth attach. */ |
420 | struct list_head legacy_dev_list; | |
0683c0ab DV |
421 | int (*firstopen) (struct drm_device *); |
422 | int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv); | |
423 | int (*dma_quiescent) (struct drm_device *); | |
424 | int (*context_dtor) (struct drm_device *dev, int context); | |
425 | int dev_priv_size; | |
85e634bc DV |
426 | }; |
427 | ||
428 | extern __printf(6, 7) | |
429 | void drm_dev_printk(const struct device *dev, const char *level, | |
430 | unsigned int category, const char *function_name, | |
431 | const char *prefix, const char *format, ...); | |
432 | extern __printf(3, 4) | |
433 | void drm_printk(const char *level, unsigned int category, | |
434 | const char *format, ...); | |
435 | extern unsigned int drm_debug; | |
436 | ||
437 | int drm_dev_init(struct drm_device *dev, | |
438 | struct drm_driver *driver, | |
439 | struct device *parent); | |
440 | struct drm_device *drm_dev_alloc(struct drm_driver *driver, | |
441 | struct device *parent); | |
442 | int drm_dev_register(struct drm_device *dev, unsigned long flags); | |
443 | void drm_dev_unregister(struct drm_device *dev); | |
444 | ||
445 | void drm_dev_ref(struct drm_device *dev); | |
446 | void drm_dev_unref(struct drm_device *dev); | |
447 | void drm_put_dev(struct drm_device *dev); | |
448 | void drm_unplug_dev(struct drm_device *dev); | |
449 | ||
63207455 DA |
450 | int drm_dev_set_unique(struct drm_device *dev, const char *name); |
451 | ||
452 | ||
85e634bc | 453 | #endif |