Home | History | Annotate | Line # | Download | only in drm
drm_drv.h revision 1.7
      1 /*	$NetBSD: drm_drv.h,v 1.7 2021/12/19 10:51:39 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
      5  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
      6  * Copyright (c) 2009-2010, Code Aurora Forum.
      7  * Copyright 2016 Intel Corp.
      8  *
      9  * Permission is hereby granted, free of charge, to any person obtaining a
     10  * copy of this software and associated documentation files (the "Software"),
     11  * to deal in the Software without restriction, including without limitation
     12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     13  * and/or sell copies of the Software, and to permit persons to whom the
     14  * Software is furnished to do so, subject to the following conditions:
     15  *
     16  * The above copyright notice and this permission notice (including the next
     17  * paragraph) shall be included in all copies or substantial portions of the
     18  * Software.
     19  *
     20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     23  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
     24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     26  * OTHER DEALINGS IN THE SOFTWARE.
     27  */
     28 
     29 #ifndef _DRM_DRV_H_
     30 #define _DRM_DRV_H_
     31 
     32 #include <linux/list.h>
     33 #include <linux/irqreturn.h>
     34 #include <linux/ktime.h>
     35 
     36 #include <drm/drm_device.h>
     37 
     38 struct drm_file;
     39 struct drm_gem_object;
     40 struct drm_master;
     41 struct drm_minor;
     42 struct dma_buf_attachment;
     43 struct drm_display_mode;
     44 struct drm_mode_create_dumb;
     45 struct drm_printer;
     46 struct drm_unique;
     47 
     48 /**
     49  * enum drm_driver_feature - feature flags
     50  *
     51  * See &drm_driver.driver_features, drm_device.driver_features and
     52  * drm_core_check_feature().
     53  */
     54 enum drm_driver_feature {
     55 	/**
     56 	 * @DRIVER_GEM:
     57 	 *
     58 	 * Driver use the GEM memory manager. This should be set for all modern
     59 	 * drivers.
     60 	 */
     61 	DRIVER_GEM			= BIT(0),
     62 	/**
     63 	 * @DRIVER_MODESET:
     64 	 *
     65 	 * Driver supports mode setting interfaces (KMS).
     66 	 */
     67 	DRIVER_MODESET			= BIT(1),
     68 	/**
     69 	 * @DRIVER_RENDER:
     70 	 *
     71 	 * Driver supports dedicated render nodes. See also the :ref:`section on
     72 	 * render nodes <drm_render_node>` for details.
     73 	 */
     74 	DRIVER_RENDER			= BIT(3),
     75 	/**
     76 	 * @DRIVER_ATOMIC:
     77 	 *
     78 	 * Driver supports the full atomic modesetting userspace API. Drivers
     79 	 * which only use atomic internally, but do not the support the full
     80 	 * userspace API (e.g. not all properties converted to atomic, or
     81 	 * multi-plane updates are not guaranteed to be tear-free) should not
     82 	 * set this flag.
     83 	 */
     84 	DRIVER_ATOMIC			= BIT(4),
     85 	/**
     86 	 * @DRIVER_SYNCOBJ:
     87 	 *
     88 	 * Driver supports &drm_syncobj for explicit synchronization of command
     89 	 * submission.
     90 	 */
     91 	DRIVER_SYNCOBJ                  = BIT(5),
     92 	/**
     93 	 * @DRIVER_SYNCOBJ_TIMELINE:
     94 	 *
     95 	 * Driver supports the timeline flavor of &drm_syncobj for explicit
     96 	 * synchronization of command submission.
     97 	 */
     98 	DRIVER_SYNCOBJ_TIMELINE         = BIT(6),
     99 
    100 	/* IMPORTANT: Below are all the legacy flags, add new ones above. */
    101 
    102 	/**
    103 	 * @DRIVER_USE_AGP:
    104 	 *
    105 	 * Set up DRM AGP support, see drm_agp_init(), the DRM core will manage
    106 	 * AGP resources. New drivers don't need this.
    107 	 */
    108 	DRIVER_USE_AGP			= BIT(25),
    109 	/**
    110 	 * @DRIVER_LEGACY:
    111 	 *
    112 	 * Denote a legacy driver using shadow attach. Do not use.
    113 	 */
    114 	DRIVER_LEGACY			= BIT(26),
    115 	/**
    116 	 * @DRIVER_PCI_DMA:
    117 	 *
    118 	 * Driver is capable of PCI DMA, mapping of PCI DMA buffers to userspace
    119 	 * will be enabled. Only for legacy drivers. Do not use.
    120 	 */
    121 	DRIVER_PCI_DMA			= BIT(27),
    122 	/**
    123 	 * @DRIVER_SG:
    124 	 *
    125 	 * Driver can perform scatter/gather DMA, allocation and mapping of
    126 	 * scatter/gather buffers will be enabled. Only for legacy drivers. Do
    127 	 * not use.
    128 	 */
    129 	DRIVER_SG			= BIT(28),
    130 
    131 	/**
    132 	 * @DRIVER_HAVE_DMA:
    133 	 *
    134 	 * Driver supports DMA, the userspace DMA API will be supported. Only
    135 	 * for legacy drivers. Do not use.
    136 	 */
    137 	DRIVER_HAVE_DMA			= BIT(29),
    138 	/**
    139 	 * @DRIVER_HAVE_IRQ:
    140 	 *
    141 	 * Legacy irq support. Only for legacy drivers. Do not use.
    142 	 *
    143 	 * New drivers can either use the drm_irq_install() and
    144 	 * drm_irq_uninstall() helper functions, or roll their own irq support
    145 	 * code by calling request_irq() directly.
    146 	 */
    147 	DRIVER_HAVE_IRQ			= BIT(30),
    148 	/**
    149 	 * @DRIVER_KMS_LEGACY_CONTEXT:
    150 	 *
    151 	 * Used only by nouveau for backwards compatibility with existing
    152 	 * userspace.  Do not use.
    153 	 */
    154 	DRIVER_KMS_LEGACY_CONTEXT	= BIT(31),
    155 };
    156 
    157 /**
    158  * struct drm_driver - DRM driver structure
    159  *
    160  * This structure represent the common code for a family of cards. There will be
    161  * one &struct drm_device for each card present in this family. It contains lots
    162  * of vfunc entries, and a pile of those probably should be moved to more
    163  * appropriate places like &drm_mode_config_funcs or into a new operations
    164  * structure for GEM drivers.
    165  */
    166 struct drm_driver {
    167 	/**
    168 	 * @load:
    169 	 *
    170 	 * Backward-compatible driver callback to complete
    171 	 * initialization steps after the driver is registered.  For
    172 	 * this reason, may suffer from race conditions and its use is
    173 	 * deprecated for new drivers.  It is therefore only supported
    174 	 * for existing drivers not yet converted to the new scheme.
    175 	 * See drm_dev_init() and drm_dev_register() for proper and
    176 	 * race-free way to set up a &struct drm_device.
    177 	 *
    178 	 * This is deprecated, do not use!
    179 	 *
    180 	 * Returns:
    181 	 *
    182 	 * Zero on success, non-zero value on failure.
    183 	 */
    184 	int (*load) (struct drm_device *, unsigned long flags);
    185 
    186 	/**
    187 	 * @open:
    188 	 *
    189 	 * Driver callback when a new &struct drm_file is opened. Useful for
    190 	 * setting up driver-private data structures like buffer allocators,
    191 	 * execution contexts or similar things. Such driver-private resources
    192 	 * must be released again in @postclose.
    193 	 *
    194 	 * Since the display/modeset side of DRM can only be owned by exactly
    195 	 * one &struct drm_file (see &drm_file.is_master and &drm_device.master)
    196 	 * there should never be a need to set up any modeset related resources
    197 	 * in this callback. Doing so would be a driver design bug.
    198 	 *
    199 	 * Returns:
    200 	 *
    201 	 * 0 on success, a negative error code on failure, which will be
    202 	 * promoted to userspace as the result of the open() system call.
    203 	 */
    204 	int (*open) (struct drm_device *, struct drm_file *);
    205 
    206 	/**
    207 	 * @postclose:
    208 	 *
    209 	 * One of the driver callbacks when a new &struct drm_file is closed.
    210 	 * Useful for tearing down driver-private data structures allocated in
    211 	 * @open like buffer allocators, execution contexts or similar things.
    212 	 *
    213 	 * Since the display/modeset side of DRM can only be owned by exactly
    214 	 * one &struct drm_file (see &drm_file.is_master and &drm_device.master)
    215 	 * there should never be a need to tear down any modeset related
    216 	 * resources in this callback. Doing so would be a driver design bug.
    217 	 */
    218 	void (*postclose) (struct drm_device *, struct drm_file *);
    219 
    220 	/**
    221 	 * @lastclose:
    222 	 *
    223 	 * Called when the last &struct drm_file has been closed and there's
    224 	 * currently no userspace client for the &struct drm_device.
    225 	 *
    226 	 * Modern drivers should only use this to force-restore the fbdev
    227 	 * framebuffer using drm_fb_helper_restore_fbdev_mode_unlocked().
    228 	 * Anything else would indicate there's something seriously wrong.
    229 	 * Modern drivers can also use this to execute delayed power switching
    230 	 * state changes, e.g. in conjunction with the :ref:`vga_switcheroo`
    231 	 * infrastructure.
    232 	 *
    233 	 * This is called after @postclose hook has been called.
    234 	 *
    235 	 * NOTE:
    236 	 *
    237 	 * All legacy drivers use this callback to de-initialize the hardware.
    238 	 * This is purely because of the shadow-attach model, where the DRM
    239 	 * kernel driver does not really own the hardware. Instead ownershipe is
    240 	 * handled with the help of userspace through an inheritedly racy dance
    241 	 * to set/unset the VT into raw mode.
    242 	 *
    243 	 * Legacy drivers initialize the hardware in the @firstopen callback,
    244 	 * which isn't even called for modern drivers.
    245 	 */
    246 	void (*lastclose) (struct drm_device *);
    247 
    248 	/**
    249 	 * @unload:
    250 	 *
    251 	 * Reverse the effects of the driver load callback.  Ideally,
    252 	 * the clean up performed by the driver should happen in the
    253 	 * reverse order of the initialization.  Similarly to the load
    254 	 * hook, this handler is deprecated and its usage should be
    255 	 * dropped in favor of an open-coded teardown function at the
    256 	 * driver layer.  See drm_dev_unregister() and drm_dev_put()
    257 	 * for the proper way to remove a &struct drm_device.
    258 	 *
    259 	 * The unload() hook is called right after unregistering
    260 	 * the device.
    261 	 *
    262 	 */
    263 	void (*unload) (struct drm_device *);
    264 
    265 	/**
    266 	 * @release:
    267 	 *
    268 	 * Optional callback for destroying device data after the final
    269 	 * reference is released, i.e. the device is being destroyed. Drivers
    270 	 * using this callback are responsible for calling drm_dev_fini()
    271 	 * to finalize the device and then freeing the struct themselves.
    272 	 */
    273 	void (*release) (struct drm_device *);
    274 
    275 	/**
    276 	 * @get_vblank_counter:
    277 	 *
    278 	 * Driver callback for fetching a raw hardware vblank counter for the
    279 	 * CRTC specified with the pipe argument.  If a device doesn't have a
    280 	 * hardware counter, the driver can simply leave the hook as NULL.
    281 	 * The DRM core will account for missed vblank events while interrupts
    282 	 * where disabled based on system timestamps.
    283 	 *
    284 	 * Wraparound handling and loss of events due to modesetting is dealt
    285 	 * with in the DRM core code, as long as drivers call
    286 	 * drm_crtc_vblank_off() and drm_crtc_vblank_on() when disabling or
    287 	 * enabling a CRTC.
    288 	 *
    289 	 * This is deprecated and should not be used by new drivers.
    290 	 * Use &drm_crtc_funcs.get_vblank_counter instead.
    291 	 *
    292 	 * Returns:
    293 	 *
    294 	 * Raw vblank counter value.
    295 	 */
    296 	u32 (*get_vblank_counter) (struct drm_device *dev, unsigned int pipe);
    297 
    298 	/**
    299 	 * @enable_vblank:
    300 	 *
    301 	 * Enable vblank interrupts for the CRTC specified with the pipe
    302 	 * argument.
    303 	 *
    304 	 * This is deprecated and should not be used by new drivers.
    305 	 * Use &drm_crtc_funcs.enable_vblank instead.
    306 	 *
    307 	 * Returns:
    308 	 *
    309 	 * Zero on success, appropriate errno if the given @crtc's vblank
    310 	 * interrupt cannot be enabled.
    311 	 */
    312 	int (*enable_vblank) (struct drm_device *dev, unsigned int pipe);
    313 
    314 	/**
    315 	 * @disable_vblank:
    316 	 *
    317 	 * Disable vblank interrupts for the CRTC specified with the pipe
    318 	 * argument.
    319 	 *
    320 	 * This is deprecated and should not be used by new drivers.
    321 	 * Use &drm_crtc_funcs.disable_vblank instead.
    322 	 */
    323 	void (*disable_vblank) (struct drm_device *dev, unsigned int pipe);
    324 
    325 	/**
    326 	 * @get_scanout_position:
    327 	 *
    328 	 * Called by vblank timestamping code.
    329 	 *
    330 	 * Returns the current display scanout position from a crtc, and an
    331 	 * optional accurate ktime_get() timestamp of when position was
    332 	 * measured. Note that this is a helper callback which is only used if a
    333 	 * driver uses drm_calc_vbltimestamp_from_scanoutpos() for the
    334 	 * @get_vblank_timestamp callback.
    335 	 *
    336 	 * Parameters:
    337 	 *
    338 	 * dev:
    339 	 *     DRM device.
    340 	 * pipe:
    341 	 *     Id of the crtc to query.
    342 	 * in_vblank_irq:
    343 	 *     True when called from drm_crtc_handle_vblank().  Some drivers
    344 	 *     need to apply some workarounds for gpu-specific vblank irq quirks
    345 	 *     if flag is set.
    346 	 * vpos:
    347 	 *     Target location for current vertical scanout position.
    348 	 * hpos:
    349 	 *     Target location for current horizontal scanout position.
    350 	 * stime:
    351 	 *     Target location for timestamp taken immediately before
    352 	 *     scanout position query. Can be NULL to skip timestamp.
    353 	 * etime:
    354 	 *     Target location for timestamp taken immediately after
    355 	 *     scanout position query. Can be NULL to skip timestamp.
    356 	 * mode:
    357 	 *     Current display timings.
    358 	 *
    359 	 * Returns vpos as a positive number while in active scanout area.
    360 	 * Returns vpos as a negative number inside vblank, counting the number
    361 	 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
    362 	 * until start of active scanout / end of vblank."
    363 	 *
    364 	 * Returns:
    365 	 *
    366 	 * True on success, false if a reliable scanout position counter could
    367 	 * not be read out.
    368 	 *
    369 	 * FIXME:
    370 	 *
    371 	 * Since this is a helper to implement @get_vblank_timestamp, we should
    372 	 * move it to &struct drm_crtc_helper_funcs, like all the other
    373 	 * helper-internal hooks.
    374 	 */
    375 	bool (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
    376 				      bool in_vblank_irq, int *vpos, int *hpos,
    377 				      ktime_t *stime, ktime_t *etime,
    378 				      const struct drm_display_mode *mode);
    379 
    380 	/**
    381 	 * @get_vblank_timestamp:
    382 	 *
    383 	 * Called by drm_get_last_vbltimestamp(). Should return a precise
    384 	 * timestamp when the most recent VBLANK interval ended or will end.
    385 	 *
    386 	 * Specifically, the timestamp in @vblank_time should correspond as
    387 	 * closely as possible to the time when the first video scanline of
    388 	 * the video frame after the end of VBLANK will start scanning out,
    389 	 * the time immediately after end of the VBLANK interval. If the
    390 	 * @crtc is currently inside VBLANK, this will be a time in the future.
    391 	 * If the @crtc is currently scanning out a frame, this will be the
    392 	 * past start time of the current scanout. This is meant to adhere
    393 	 * to the OpenML OML_sync_control extension specification.
    394 	 *
    395 	 * Paramters:
    396 	 *
    397 	 * dev:
    398 	 *     dev DRM device handle.
    399 	 * pipe:
    400 	 *     crtc for which timestamp should be returned.
    401 	 * max_error:
    402 	 *     Maximum allowable timestamp error in nanoseconds.
    403 	 *     Implementation should strive to provide timestamp
    404 	 *     with an error of at most max_error nanoseconds.
    405 	 *     Returns true upper bound on error for timestamp.
    406 	 * vblank_time:
    407 	 *     Target location for returned vblank timestamp.
    408 	 * in_vblank_irq:
    409 	 *     True when called from drm_crtc_handle_vblank().  Some drivers
    410 	 *     need to apply some workarounds for gpu-specific vblank irq quirks
    411 	 *     if flag is set.
    412 	 *
    413 	 * Returns:
    414 	 *
    415 	 * True on success, false on failure, which means the core should
    416 	 * fallback to a simple timestamp taken in drm_crtc_handle_vblank().
    417 	 *
    418 	 * FIXME:
    419 	 *
    420 	 * We should move this hook to &struct drm_crtc_funcs like all the other
    421 	 * vblank hooks.
    422 	 */
    423 	bool (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe,
    424 				     int *max_error,
    425 				     ktime_t *vblank_time,
    426 				     bool in_vblank_irq);
    427 
    428 	/**
    429 	 * @irq_handler:
    430 	 *
    431 	 * Interrupt handler called when using drm_irq_install(). Not used by
    432 	 * drivers which implement their own interrupt handling.
    433 	 */
    434 	irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
    435 
    436 	/**
    437 	 * @irq_preinstall:
    438 	 *
    439 	 * Optional callback used by drm_irq_install() which is called before
    440 	 * the interrupt handler is registered. This should be used to clear out
    441 	 * any pending interrupts (from e.g. firmware based drives) and reset
    442 	 * the interrupt handling registers.
    443 	 */
    444 	void (*irq_preinstall) (struct drm_device *dev);
    445 
    446 	/**
    447 	 * @irq_postinstall:
    448 	 *
    449 	 * Optional callback used by drm_irq_install() which is called after
    450 	 * the interrupt handler is registered. This should be used to enable
    451 	 * interrupt generation in the hardware.
    452 	 */
    453 	int (*irq_postinstall) (struct drm_device *dev);
    454 
    455 	/**
    456 	 * @irq_uninstall:
    457 	 *
    458 	 * Optional callback used by drm_irq_uninstall() which is called before
    459 	 * the interrupt handler is unregistered. This should be used to disable
    460 	 * interrupt generation in the hardware.
    461 	 */
    462 	void (*irq_uninstall) (struct drm_device *dev);
    463 
    464 #ifdef __NetBSD__
    465 	int (*request_irq)(struct drm_device *, int);
    466 	void (*free_irq)(struct drm_device *);
    467 #endif
    468 
    469 	/**
    470 	 * @master_create:
    471 	 *
    472 	 * Called whenever a new master is created. Only used by vmwgfx.
    473 	 */
    474 	int (*master_create)(struct drm_device *dev, struct drm_master *master);
    475 
    476 	/**
    477 	 * @master_destroy:
    478 	 *
    479 	 * Called whenever a master is destroyed. Only used by vmwgfx.
    480 	 */
    481 	void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
    482 
    483 	/**
    484 	 * @master_set:
    485 	 *
    486 	 * Called whenever the minor master is set. Only used by vmwgfx.
    487 	 */
    488 	int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
    489 			  bool from_open);
    490 	/**
    491 	 * @master_drop:
    492 	 *
    493 	 * Called whenever the minor master is dropped. Only used by vmwgfx.
    494 	 */
    495 	void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
    496 
    497 	/**
    498 	 * @debugfs_init:
    499 	 *
    500 	 * Allows drivers to create driver-specific debugfs files.
    501 	 */
    502 	int (*debugfs_init)(struct drm_minor *minor);
    503 
    504 	/**
    505 	 * @gem_free_object: deconstructor for drm_gem_objects
    506 	 *
    507 	 * This is deprecated and should not be used by new drivers. Use
    508 	 * &drm_gem_object_funcs.free instead.
    509 	 */
    510 	void (*gem_free_object) (struct drm_gem_object *obj);
    511 
    512 	/**
    513 	 * @gem_free_object_unlocked: deconstructor for drm_gem_objects
    514 	 *
    515 	 * This is deprecated and should not be used by new drivers. Use
    516 	 * &drm_gem_object_funcs.free instead.
    517 	 * Compared to @gem_free_object this is not encumbered with
    518 	 * &drm_device.struct_mutex legacy locking schemes.
    519 	 */
    520 	void (*gem_free_object_unlocked) (struct drm_gem_object *obj);
    521 
    522 	/**
    523 	 * @gem_open_object:
    524 	 *
    525 	 * This callback is deprecated in favour of &drm_gem_object_funcs.open.
    526 	 *
    527 	 * Driver hook called upon gem handle creation
    528 	 */
    529 	int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
    530 
    531 	/**
    532 	 * @gem_close_object:
    533 	 *
    534 	 * This callback is deprecated in favour of &drm_gem_object_funcs.close.
    535 	 *
    536 	 * Driver hook called upon gem handle release
    537 	 */
    538 	void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
    539 
    540 	/**
    541 	 * @gem_print_info:
    542 	 *
    543 	 * This callback is deprecated in favour of
    544 	 * &drm_gem_object_funcs.print_info.
    545 	 *
    546 	 * If driver subclasses struct &drm_gem_object, it can implement this
    547 	 * optional hook for printing additional driver specific info.
    548 	 *
    549 	 * drm_printf_indent() should be used in the callback passing it the
    550 	 * indent argument.
    551 	 *
    552 	 * This callback is called from drm_gem_print_info().
    553 	 */
    554 	void (*gem_print_info)(struct drm_printer *p, unsigned int indent,
    555 			       const struct drm_gem_object *obj);
    556 
    557 	/**
    558 	 * @gem_create_object: constructor for gem objects
    559 	 *
    560 	 * Hook for allocating the GEM object struct, for use by the CMA and
    561 	 * SHMEM GEM helpers.
    562 	 */
    563 	struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
    564 						    size_t size);
    565 	/**
    566 	 * @prime_handle_to_fd:
    567 	 *
    568 	 * Main PRIME export function. Should be implemented with
    569 	 * drm_gem_prime_handle_to_fd() for GEM based drivers.
    570 	 *
    571 	 * For an in-depth discussion see :ref:`PRIME buffer sharing
    572 	 * documentation <prime_buffer_sharing>`.
    573 	 */
    574 	int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
    575 				uint32_t handle, uint32_t flags, int *prime_fd);
    576 	/**
    577 	 * @prime_fd_to_handle:
    578 	 *
    579 	 * Main PRIME import function. Should be implemented with
    580 	 * drm_gem_prime_fd_to_handle() for GEM based drivers.
    581 	 *
    582 	 * For an in-depth discussion see :ref:`PRIME buffer sharing
    583 	 * documentation <prime_buffer_sharing>`.
    584 	 */
    585 	int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
    586 				int prime_fd, uint32_t *handle);
    587 	/**
    588 	 * @gem_prime_export:
    589 	 *
    590 	 * Export hook for GEM drivers. Deprecated in favour of
    591 	 * &drm_gem_object_funcs.export.
    592 	 */
    593 	struct dma_buf * (*gem_prime_export)(struct drm_gem_object *obj,
    594 					     int flags);
    595 	/**
    596 	 * @gem_prime_import:
    597 	 *
    598 	 * Import hook for GEM drivers.
    599 	 *
    600 	 * This defaults to drm_gem_prime_import() if not set.
    601 	 */
    602 	struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
    603 				struct dma_buf *dma_buf);
    604 
    605 	/**
    606 	 * @gem_prime_pin:
    607 	 *
    608 	 * Deprecated hook in favour of &drm_gem_object_funcs.pin.
    609 	 */
    610 	int (*gem_prime_pin)(struct drm_gem_object *obj);
    611 
    612 	/**
    613 	 * @gem_prime_unpin:
    614 	 *
    615 	 * Deprecated hook in favour of &drm_gem_object_funcs.unpin.
    616 	 */
    617 	void (*gem_prime_unpin)(struct drm_gem_object *obj);
    618 
    619 
    620 	/**
    621 	 * @gem_prime_get_sg_table:
    622 	 *
    623 	 * Deprecated hook in favour of &drm_gem_object_funcs.get_sg_table.
    624 	 */
    625 	struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
    626 
    627 	/**
    628 	 * @gem_prime_import_sg_table:
    629 	 *
    630 	 * Optional hook used by the PRIME helper functions
    631 	 * drm_gem_prime_import() respectively drm_gem_prime_import_dev().
    632 	 */
    633 	struct drm_gem_object *(*gem_prime_import_sg_table)(
    634 				struct drm_device *dev,
    635 				struct dma_buf_attachment *attach,
    636 				struct sg_table *sgt);
    637 	/**
    638 	 * @gem_prime_vmap:
    639 	 *
    640 	 * Deprecated vmap hook for GEM drivers. Please use
    641 	 * &drm_gem_object_funcs.vmap instead.
    642 	 */
    643 	void *(*gem_prime_vmap)(struct drm_gem_object *obj);
    644 
    645 	/**
    646 	 * @gem_prime_vunmap:
    647 	 *
    648 	 * Deprecated vunmap hook for GEM drivers. Please use
    649 	 * &drm_gem_object_funcs.vunmap instead.
    650 	 */
    651 	void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
    652 
    653 	/**
    654 	 * @gem_prime_mmap:
    655 	 *
    656 	 * mmap hook for GEM drivers, used to implement dma-buf mmap in the
    657 	 * PRIME helpers.
    658 	 *
    659 	 * FIXME: There's way too much duplication going on here, and also moved
    660 	 * to &drm_gem_object_funcs.
    661 	 */
    662 #ifdef __NetBSD__
    663 	int (*gem_prime_mmap)(struct drm_gem_object *obj, off_t *offp,
    664 	    size_t len, int prot, int *flagsp, int *advicep,
    665 	    struct uvm_object **uobjp, int *maxprotp);
    666 #else
    667 	int (*gem_prime_mmap)(struct drm_gem_object *obj,
    668 				struct vm_area_struct *vma);
    669 #endif
    670 
    671 	/**
    672 	 * @dumb_create:
    673 	 *
    674 	 * This creates a new dumb buffer in the driver's backing storage manager (GEM,
    675 	 * TTM or something else entirely) and returns the resulting buffer handle. This
    676 	 * handle can then be wrapped up into a framebuffer modeset object.
    677 	 *
    678 	 * Note that userspace is not allowed to use such objects for render
    679 	 * acceleration - drivers must create their own private ioctls for such a use
    680 	 * case.
    681 	 *
    682 	 * Width, height and depth are specified in the &drm_mode_create_dumb
    683 	 * argument. The callback needs to fill the handle, pitch and size for
    684 	 * the created buffer.
    685 	 *
    686 	 * Called by the user via ioctl.
    687 	 *
    688 	 * Returns:
    689 	 *
    690 	 * Zero on success, negative errno on failure.
    691 	 */
    692 	int (*dumb_create)(struct drm_file *file_priv,
    693 			   struct drm_device *dev,
    694 			   struct drm_mode_create_dumb *args);
    695 	/**
    696 	 * @dumb_map_offset:
    697 	 *
    698 	 * Allocate an offset in the drm device node's address space to be able to
    699 	 * memory map a dumb buffer.
    700 	 *
    701 	 * The default implementation is drm_gem_create_mmap_offset(). GEM based
    702 	 * drivers must not overwrite this.
    703 	 *
    704 	 * Called by the user via ioctl.
    705 	 *
    706 	 * Returns:
    707 	 *
    708 	 * Zero on success, negative errno on failure.
    709 	 */
    710 	int (*dumb_map_offset)(struct drm_file *file_priv,
    711 			       struct drm_device *dev, uint32_t handle,
    712 			       uint64_t *offset);
    713 	/**
    714 	 * @dumb_destroy:
    715 	 *
    716 	 * This destroys the userspace handle for the given dumb backing storage buffer.
    717 	 * Since buffer objects must be reference counted in the kernel a buffer object
    718 	 * won't be immediately freed if a framebuffer modeset object still uses it.
    719 	 *
    720 	 * Called by the user via ioctl.
    721 	 *
    722 	 * The default implementation is drm_gem_dumb_destroy(). GEM based drivers
    723 	 * must not overwrite this.
    724 	 *
    725 	 * Returns:
    726 	 *
    727 	 * Zero on success, negative errno on failure.
    728 	 */
    729 	int (*dumb_destroy)(struct drm_file *file_priv,
    730 			    struct drm_device *dev,
    731 			    uint32_t handle);
    732 
    733 	/**
    734 	 * @gem_vm_ops: Driver private ops for this object
    735 	 *
    736 	 * For GEM drivers this is deprecated in favour of
    737 	 * &drm_gem_object_funcs.vm_ops.
    738 	 */
    739 #ifdef __NetBSD__
    740 	int (*mmap_object)(struct drm_device *, off_t, size_t, int,
    741 	    struct uvm_object **, voff_t *, struct file *);
    742 	const struct uvm_pagerops *gem_uvm_ops;
    743 #else
    744 	const struct vm_operations_struct *gem_vm_ops;
    745 #endif
    746 
    747 	/** @major: driver major number */
    748 	int major;
    749 	/** @minor: driver minor number */
    750 	int minor;
    751 	/** @patchlevel: driver patch level */
    752 	int patchlevel;
    753 	/** @name: driver name */
    754 	const char *name;
    755 	/** @desc: driver description */
    756 	const char *desc;
    757 	/** @date: driver date */
    758 	const char *date;
    759 
    760 	/**
    761 	 * @driver_features:
    762 	 * Driver features, see &enum drm_driver_feature. Drivers can disable
    763 	 * some features on a per-instance basis using
    764 	 * &drm_device.driver_features.
    765 	 */
    766 	u32 driver_features;
    767 
    768 	/**
    769 	 * @ioctls:
    770 	 *
    771 	 * Array of driver-private IOCTL description entries. See the chapter on
    772 	 * :ref:`IOCTL support in the userland interfaces
    773 	 * chapter<drm_driver_ioctl>` for the full details.
    774 	 */
    775 
    776 	const struct drm_ioctl_desc *ioctls;
    777 	/** @num_ioctls: Number of entries in @ioctls. */
    778 	int num_ioctls;
    779 
    780 	/**
    781 	 * @fops:
    782 	 *
    783 	 * File operations for the DRM device node. See the discussion in
    784 	 * :ref:`file operations<drm_driver_fops>` for in-depth coverage and
    785 	 * some examples.
    786 	 */
    787 	const struct file_operations *fops;
    788 
    789 #ifdef __NetBSD__
    790 	int (*ioctl_override)(struct file *, unsigned long, void *);
    791 #endif
    792 
    793 	/* Everything below here is for legacy driver, never use! */
    794 	/* private: */
    795 
    796 	/* List of devices hanging off this driver with stealth attach. */
    797 	struct list_head legacy_dev_list;
    798 	int (*firstopen) (struct drm_device *);
    799 	void (*preclose) (struct drm_device *, struct drm_file *file_priv);
    800 	int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
    801 	int (*dma_quiescent) (struct drm_device *);
    802 	int (*context_dtor) (struct drm_device *dev, int context);
    803 	int (*set_busid)(struct drm_device *dev, struct drm_master *master);
    804 	int dev_priv_size;
    805 };
    806 
    807 int drm_dev_init(struct drm_device *dev,
    808 		 struct drm_driver *driver,
    809 		 struct device *parent);
    810 int devm_drm_dev_init(struct device *parent,
    811 		      struct drm_device *dev,
    812 		      struct drm_driver *driver);
    813 void drm_dev_fini(struct drm_device *dev);
    814 
    815 struct drm_device *drm_dev_alloc(struct drm_driver *driver,
    816 				 struct device *parent);
    817 int drm_dev_register(struct drm_device *dev, unsigned long flags);
    818 void drm_dev_unregister(struct drm_device *dev);
    819 
    820 void drm_dev_get(struct drm_device *dev);
    821 void drm_dev_put(struct drm_device *dev);
    822 void drm_put_dev(struct drm_device *dev);
    823 bool drm_dev_enter(struct drm_device *dev, int *idx);
    824 void drm_dev_exit(int idx);
    825 void drm_dev_unplug(struct drm_device *dev);
    826 
    827 /**
    828  * drm_dev_is_unplugged - is a DRM device unplugged
    829  * @dev: DRM device
    830  *
    831  * This function can be called to check whether a hotpluggable is unplugged.
    832  * Unplugging itself is singalled through drm_dev_unplug(). If a device is
    833  * unplugged, these two functions guarantee that any store before calling
    834  * drm_dev_unplug() is visible to callers of this function after it completes
    835  *
    836  * WARNING: This function fundamentally races against drm_dev_unplug(). It is
    837  * recommended that drivers instead use the underlying drm_dev_enter() and
    838  * drm_dev_exit() function pairs.
    839  */
    840 static inline bool drm_dev_is_unplugged(struct drm_device *dev)
    841 {
    842 	int idx;
    843 
    844 	if (drm_dev_enter(dev, &idx)) {
    845 		drm_dev_exit(idx);
    846 		return false;
    847 	}
    848 
    849 	return true;
    850 }
    851 
    852 /**
    853  * drm_core_check_feature - check driver feature flags
    854  * @dev: DRM device to check
    855  * @feature: feature flag
    856  *
    857  * This checks @dev for driver features, see &drm_driver.driver_features,
    858  * &drm_device.driver_features, and the various &enum drm_driver_feature flags.
    859  *
    860  * Returns true if the @feature is supported, false otherwise.
    861  */
    862 static inline bool drm_core_check_feature(const struct drm_device *dev, u32 feature)
    863 {
    864 	return dev->driver->driver_features & dev->driver_features & feature;
    865 }
    866 
    867 /**
    868  * drm_drv_uses_atomic_modeset - check if the driver implements
    869  * atomic_commit()
    870  * @dev: DRM device
    871  *
    872  * This check is useful if drivers do not have DRIVER_ATOMIC set but
    873  * have atomic modesetting internally implemented.
    874  */
    875 static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
    876 {
    877 	return drm_core_check_feature(dev, DRIVER_ATOMIC) ||
    878 		(dev->mode_config.funcs && dev->mode_config.funcs->atomic_commit != NULL);
    879 }
    880 
    881 
    882 int drm_dev_set_unique(struct drm_device *dev, const char *name);
    883 
    884 
    885 #endif
    886