projects/linux·blob master · refs

593 lines · 17.7 KiB

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#include <video/nomodeset.h>
34
35#include <drm/drm_device.h>
36
37struct dmem_cgroup_init;
38struct dmem_cgroup_region;
39struct drm_fb_helper;
40struct drm_fb_helper_surface_size;
41struct drm_file;
42struct drm_gem_object;
43struct drm_master;
44struct drm_minor;
45struct dma_buf;
46struct dma_buf_attachment;
47struct drm_display_mode;
48struct drm_mode_create_dumb;
49struct drm_printer;
50struct sg_table;
51
52/**
53 * enum drm_driver_feature - feature flags
54 *
55 * See &drm_driver.driver_features, drm_device.driver_features and
56 * drm_core_check_feature().
57 */
58enum drm_driver_feature {
59 /**
60 * @DRIVER_GEM:
61 *
62 * Driver use the GEM memory manager. This should be set for all modern
63 * drivers.
64 */
65 DRIVER_GEM = BIT(0),
66 /**
67 * @DRIVER_MODESET:
68 *
69 * Driver supports mode setting interfaces (KMS).
70 */
71 DRIVER_MODESET = BIT(1),
72 /**
73 * @DRIVER_RENDER:
74 *
75 * Driver supports dedicated render nodes. See also the :ref:`section on
76 * render nodes <drm_render_node>` for details.
77 */
78 DRIVER_RENDER = BIT(3),
79 /**
80 * @DRIVER_ATOMIC:
81 *
82 * Driver supports the full atomic modesetting userspace API. Drivers
83 * which only use atomic internally, but do not support the full
84 * userspace API (e.g. not all properties converted to atomic, or
85 * multi-plane updates are not guaranteed to be tear-free) should not
86 * set this flag.
87 */
88 DRIVER_ATOMIC = BIT(4),
89 /**
90 * @DRIVER_SYNCOBJ:
91 *
92 * Driver supports &drm_syncobj for explicit synchronization of command
93 * submission.
94 */
95 DRIVER_SYNCOBJ = BIT(5),
96 /**
97 * @DRIVER_SYNCOBJ_TIMELINE:
98 *
99 * Driver supports the timeline flavor of &drm_syncobj for explicit
100 * synchronization of command submission.
101 */
102 DRIVER_SYNCOBJ_TIMELINE = BIT(6),
103 /**
104 * @DRIVER_COMPUTE_ACCEL:
105 *
106 * Driver supports compute acceleration devices. This flag is mutually exclusive with
107 * @DRIVER_RENDER and @DRIVER_MODESET. Devices that support both graphics and compute
108 * acceleration should be handled by two drivers that are connected using auxiliary bus.
109 */
110 DRIVER_COMPUTE_ACCEL = BIT(7),
111 /**
112 * @DRIVER_CURSOR_HOTSPOT:
113 *
114 * Driver supports and requires cursor hotspot information in the
115 * cursor plane (e.g. cursor plane has to actually track the mouse
116 * cursor and the clients are required to set hotspot in order for
117 * the cursor planes to work correctly).
118 */
119 DRIVER_CURSOR_HOTSPOT = BIT(9),
120
121 /* IMPORTANT: Below are all the legacy flags, add new ones above. */
122
123 /**
124 * @DRIVER_USE_AGP:
125 *
126 * Set up DRM AGP support, see drm_agp_init(), the DRM core will manage
127 * AGP resources. New drivers don't need this.
128 */
129 DRIVER_USE_AGP = BIT(25),
130 /**
131 * @DRIVER_LEGACY:
132 *
133 * Denote a legacy driver using shadow attach. Do not use.
134 */
135 DRIVER_LEGACY = BIT(26),
136 /**
137 * @DRIVER_PCI_DMA:
138 *
139 * Driver is capable of PCI DMA, mapping of PCI DMA buffers to userspace
140 * will be enabled. Only for legacy drivers. Do not use.
141 */
142 DRIVER_PCI_DMA = BIT(27),
143 /**
144 * @DRIVER_SG:
145 *
146 * Driver can perform scatter/gather DMA, allocation and mapping of
147 * scatter/gather buffers will be enabled. Only for legacy drivers. Do
148 * not use.
149 */
150 DRIVER_SG = BIT(28),
151
152 /**
153 * @DRIVER_HAVE_DMA:
154 *
155 * Driver supports DMA, the userspace DMA API will be supported. Only
156 * for legacy drivers. Do not use.
157 */
158 DRIVER_HAVE_DMA = BIT(29),
159 /**
160 * @DRIVER_HAVE_IRQ:
161 *
162 * Legacy irq support. Only for legacy drivers. Do not use.
163 */
164 DRIVER_HAVE_IRQ = BIT(30),
165};
166
167/**
168 * struct drm_driver - DRM driver structure
169 *
170 * This structure represent the common code for a family of cards. There will be
171 * one &struct drm_device for each card present in this family. It contains lots
172 * of vfunc entries, and a pile of those probably should be moved to more
173 * appropriate places like &drm_mode_config_funcs or into a new operations
174 * structure for GEM drivers.
175 */
176struct drm_driver {
177 /**
178 * @load:
179 *
180 * Backward-compatible driver callback to complete initialization steps
181 * after the driver is registered. For this reason, may suffer from
182 * race conditions and its use is deprecated for new drivers. It is
183 * therefore only supported for existing drivers not yet converted to
184 * the new scheme. See devm_drm_dev_alloc() and drm_dev_register() for
185 * proper and race-free way to set up a &struct drm_device.
186 *
187 * This is deprecated, do not use!
188 *
189 * Returns:
190 *
191 * Zero on success, non-zero value on failure.
192 */
193 int (*load) (struct drm_device *, unsigned long flags);
194
195 /**
196 * @open:
197 *
198 * Driver callback when a new &struct drm_file is opened. Useful for
199 * setting up driver-private data structures like buffer allocators,
200 * execution contexts or similar things. Such driver-private resources
201 * must be released again in @postclose.
202 *
203 * Since the display/modeset side of DRM can only be owned by exactly
204 * one &struct drm_file (see &drm_file.is_master and &drm_device.master)
205 * there should never be a need to set up any modeset related resources
206 * in this callback. Doing so would be a driver design bug.
207 *
208 * Returns:
209 *
210 * 0 on success, a negative error code on failure, which will be
211 * promoted to userspace as the result of the open() system call.
212 */
213 int (*open) (struct drm_device *, struct drm_file *);
214
215 /**
216 * @postclose:
217 *
218 * One of the driver callbacks when a new &struct drm_file is closed.
219 * Useful for tearing down driver-private data structures allocated in
220 * @open like buffer allocators, execution contexts or similar things.
221 *
222 * Since the display/modeset side of DRM can only be owned by exactly
223 * one &struct drm_file (see &drm_file.is_master and &drm_device.master)
224 * there should never be a need to tear down any modeset related
225 * resources in this callback. Doing so would be a driver design bug.
226 */
227 void (*postclose) (struct drm_device *, struct drm_file *);
228
229 /**
230 * @unload:
231 *
232 * Reverse the effects of the driver load callback. Ideally,
233 * the clean up performed by the driver should happen in the
234 * reverse order of the initialization. Similarly to the load
235 * hook, this handler is deprecated and its usage should be
236 * dropped in favor of an open-coded teardown function at the
237 * driver layer. See drm_dev_unregister() and drm_dev_put()
238 * for the proper way to remove a &struct drm_device.
239 *
240 * The unload() hook is called right after unregistering
241 * the device.
242 *
243 */
244 void (*unload) (struct drm_device *);
245
246 /**
247 * @release:
248 *
249 * Optional callback for destroying device data after the final
250 * reference is released, i.e. the device is being destroyed.
251 *
252 * This is deprecated, clean up all memory allocations associated with a
253 * &drm_device using drmm_add_action(), drmm_kmalloc() and related
254 * managed resources functions.
255 */
256 void (*release) (struct drm_device *);
257
258 /**
259 * @master_set:
260 *
261 * Called whenever the minor master is set. Only used by vmwgfx.
262 */
263 void (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
264 bool from_open);
265 /**
266 * @master_drop:
267 *
268 * Called whenever the minor master is dropped. Only used by vmwgfx.
269 */
270 void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
271
272 /**
273 * @debugfs_init:
274 *
275 * Allows drivers to create driver-specific debugfs files.
276 */
277 void (*debugfs_init)(struct drm_minor *minor);
278
279 /**
280 * @gem_create_object: constructor for gem objects
281 *
282 * Hook for allocating the GEM object struct, for use by the CMA
283 * and SHMEM GEM helpers. Returns a GEM object on success, or an
284 * ERR_PTR()-encoded error code otherwise.
285 */
286 struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
287 size_t size);
288
289 /**
290 * @prime_handle_to_fd:
291 *
292 * PRIME export function. Only used by vmwgfx.
293 */
294 int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
295 uint32_t handle, uint32_t flags, int *prime_fd);
296 /**
297 * @prime_fd_to_handle:
298 *
299 * PRIME import function. Only used by vmwgfx.
300 */
301 int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
302 int prime_fd, uint32_t *handle);
303
304 /**
305 * @gem_prime_import:
306 *
307 * Import hook for GEM drivers.
308 *
309 * This defaults to drm_gem_prime_import() if not set.
310 */
311 struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
312 struct dma_buf *dma_buf);
313 /**
314 * @gem_prime_import_sg_table:
315 *
316 * Optional hook used by the PRIME helper functions
317 * drm_gem_prime_import() respectively drm_gem_prime_import_dev().
318 */
319 struct drm_gem_object *(*gem_prime_import_sg_table)(
320 struct drm_device *dev,
321 struct dma_buf_attachment *attach,
322 struct sg_table *sgt);
323
324 /**
325 * @dumb_create:
326 *
327 * This creates a new dumb buffer in the driver's backing storage manager (GEM,
328 * TTM or something else entirely) and returns the resulting buffer handle. This
329 * handle can then be wrapped up into a framebuffer modeset object.
330 *
331 * Note that userspace is not allowed to use such objects for render
332 * acceleration - drivers must create their own private ioctls for such a use
333 * case.
334 *
335 * Width, height and depth are specified in the &drm_mode_create_dumb
336 * argument. The callback needs to fill the handle, pitch and size for
337 * the created buffer.
338 *
339 * Called by the user via ioctl.
340 *
341 * Returns:
342 *
343 * Zero on success, negative errno on failure.
344 */
345 int (*dumb_create)(struct drm_file *file_priv,
346 struct drm_device *dev,
347 struct drm_mode_create_dumb *args);
348 /**
349 * @dumb_map_offset:
350 *
351 * Allocate an offset in the drm device node's address space to be able to
352 * memory map a dumb buffer.
353 *
354 * The default implementation is drm_gem_create_mmap_offset(). GEM based
355 * drivers must not overwrite this.
356 *
357 * Called by the user via ioctl.
358 *
359 * Returns:
360 *
361 * Zero on success, negative errno on failure.
362 */
363 int (*dumb_map_offset)(struct drm_file *file_priv,
364 struct drm_device *dev, uint32_t handle,
365 uint64_t *offset);
366
367 /**
368 * @fbdev_probe:
369 *
370 * Allocates and initialize the fb_info structure for fbdev emulation.
371 * Furthermore it also needs to allocate the DRM framebuffer used to
372 * back the fbdev.
373 *
374 * This callback is mandatory for fbdev support.
375 *
376 * Returns:
377 *
378 * 0 on success ot a negative error code otherwise.
379 */
380 int (*fbdev_probe)(struct drm_fb_helper *fbdev_helper,
381 struct drm_fb_helper_surface_size *sizes);
382
383 /**
384 * @show_fdinfo:
385 *
386 * Print device specific fdinfo. See Documentation/gpu/drm-usage-stats.rst.
387 */
388 void (*show_fdinfo)(struct drm_printer *p, struct drm_file *f);
389
390 /** @major: driver major number */
391 int major;
392 /** @minor: driver minor number */
393 int minor;
394 /** @patchlevel: driver patch level */
395 int patchlevel;
396 /** @name: driver name */
397 char *name;
398 /** @desc: driver description */
399 char *desc;
400
401 /**
402 * @driver_features:
403 * Driver features, see &enum drm_driver_feature. Drivers can disable
404 * some features on a per-instance basis using
405 * &drm_device.driver_features.
406 */
407 u32 driver_features;
408
409 /**
410 * @ioctls:
411 *
412 * Array of driver-private IOCTL description entries. See the chapter on
413 * :ref:`IOCTL support in the userland interfaces
414 * chapter<drm_driver_ioctl>` for the full details.
415 */
416
417 const struct drm_ioctl_desc *ioctls;
418 /** @num_ioctls: Number of entries in @ioctls. */
419 int num_ioctls;
420
421 /**
422 * @fops:
423 *
424 * File operations for the DRM device node. See the discussion in
425 * :ref:`file operations<drm_driver_fops>` for in-depth coverage and
426 * some examples.
427 */
428 const struct file_operations *fops;
429};
430
431void *__devm_drm_dev_alloc(struct device *parent,
432 const struct drm_driver *driver,
433 size_t size, size_t offset);
434
435struct dmem_cgroup_region *
436drmm_cgroup_register_region(struct drm_device *dev,
437 const char *region_name,
438 const struct dmem_cgroup_init *init);
439
440/**
441 * devm_drm_dev_alloc - Resource managed allocation of a &drm_device instance
442 * @parent: Parent device object
443 * @driver: DRM driver
444 * @type: the type of the struct which contains struct &drm_device
445 * @member: the name of the &drm_device within @type.
446 *
447 * This allocates and initialize a new DRM device. No device registration is done.
448 * Call drm_dev_register() to advertice the device to user space and register it
449 * with other core subsystems. This should be done last in the device
450 * initialization sequence to make sure userspace can't access an inconsistent
451 * state.
452 *
453 * The initial ref-count of the object is 1. Use drm_dev_get() and
454 * drm_dev_put() to take and drop further ref-counts.
455 *
456 * It is recommended that drivers embed &struct drm_device into their own device
457 * structure.
458 *
459 * Note that this manages the lifetime of the resulting &drm_device
460 * automatically using devres. The DRM device initialized with this function is
461 * automatically put on driver detach using drm_dev_put().
462 *
463 * RETURNS:
464 * Pointer to new DRM device, or ERR_PTR on failure.
465 */
466#define devm_drm_dev_alloc(parent, driver, type, member) \
467 ((type *) __devm_drm_dev_alloc(parent, driver, sizeof(type), \
468 offsetof(type, member)))
469
470struct drm_device *drm_dev_alloc(const struct drm_driver *driver,
471 struct device *parent);
472
473void *__drm_dev_alloc(struct device *parent,
474 const struct drm_driver *driver,
475 size_t size, size_t offset);
476
477int drm_dev_register(struct drm_device *dev, unsigned long flags);
478void drm_dev_unregister(struct drm_device *dev);
479
480void drm_dev_get(struct drm_device *dev);
481void drm_dev_put(struct drm_device *dev);
482void drm_put_dev(struct drm_device *dev);
483bool drm_dev_enter(struct drm_device *dev, int *idx);
484void drm_dev_exit(int idx);
485void drm_dev_unplug(struct drm_device *dev);
486int drm_dev_wedged_event(struct drm_device *dev, unsigned long method,
487 struct drm_wedge_task_info *info);
488
489/**
490 * drm_dev_is_unplugged - is a DRM device unplugged
491 * @dev: DRM device
492 *
493 * This function can be called to check whether a hotpluggable is unplugged.
494 * Unplugging itself is singalled through drm_dev_unplug(). If a device is
495 * unplugged, these two functions guarantee that any store before calling
496 * drm_dev_unplug() is visible to callers of this function after it completes
497 *
498 * WARNING: This function fundamentally races against drm_dev_unplug(). It is
499 * recommended that drivers instead use the underlying drm_dev_enter() and
500 * drm_dev_exit() function pairs.
501 */
502static inline bool drm_dev_is_unplugged(struct drm_device *dev)
503{
504 int idx;
505
506 if (drm_dev_enter(dev, &idx)) {
507 drm_dev_exit(idx);
508 return false;
509 }
510
511 return true;
512}
513
514/**
515 * drm_core_check_all_features - check driver feature flags mask
516 * @dev: DRM device to check
517 * @features: feature flag(s) mask
518 *
519 * This checks @dev for driver features, see &drm_driver.driver_features,
520 * &drm_device.driver_features, and the various &enum drm_driver_feature flags.
521 *
522 * Returns true if all features in the @features mask are supported, false
523 * otherwise.
524 */
525static inline bool drm_core_check_all_features(const struct drm_device *dev,
526 u32 features)
527{
528 u32 supported = dev->driver->driver_features & dev->driver_features;
529
530 return features && (supported & features) == features;
531}
532
533/**
534 * drm_core_check_feature - check driver feature flags
535 * @dev: DRM device to check
536 * @feature: feature flag
537 *
538 * This checks @dev for driver features, see &drm_driver.driver_features,
539 * &drm_device.driver_features, and the various &enum drm_driver_feature flags.
540 *
541 * Returns true if the @feature is supported, false otherwise.
542 */
543static inline bool drm_core_check_feature(const struct drm_device *dev,
544 enum drm_driver_feature feature)
545{
546 return drm_core_check_all_features(dev, feature);
547}
548
549/**
550 * drm_drv_uses_atomic_modeset - check if the driver implements
551 * atomic_commit()
552 * @dev: DRM device
553 *
554 * This check is useful if drivers do not have DRIVER_ATOMIC set but
555 * have atomic modesetting internally implemented.
556 */
557static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
558{
559 return drm_core_check_feature(dev, DRIVER_ATOMIC) ||
560 (dev->mode_config.funcs && dev->mode_config.funcs->atomic_commit != NULL);
561}
562
563
564/* TODO: Inline drm_firmware_drivers_only() in all its callers. */
565static inline bool drm_firmware_drivers_only(void)
566{
567 return video_firmware_drivers_only();
568}
569
570#if defined(CONFIG_DEBUG_FS)
571void drm_debugfs_dev_init(struct drm_device *dev);
572void drm_debugfs_init_root(void);
573void drm_debugfs_remove_root(void);
574void drm_debugfs_bridge_params(void);
575#else
576static inline void drm_debugfs_dev_init(struct drm_device *dev)
577{
578}
579
580static inline void drm_debugfs_init_root(void)
581{
582}
583
584static inline void drm_debugfs_remove_root(void)
585{
586}
587
588static inline void drm_debugfs_bridge_params(void)
589{
590}
591#endif
592
593#endif