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