drm_drv.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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. #ifndef _DRM_DRV_H_
  27. #define _DRM_DRV_H_
  28. #include <linux/list.h>
  29. #include <linux/irqreturn.h>
  30. #include <drm/drm_device.h>
  31. struct drm_file;
  32. struct drm_gem_object;
  33. struct drm_master;
  34. struct drm_minor;
  35. struct dma_buf_attachment;
  36. struct drm_display_mode;
  37. struct drm_mode_create_dumb;
  38. struct drm_printer;
  39. /* driver capabilities and requirements mask */
  40. #define DRIVER_USE_AGP 0x1
  41. #define DRIVER_LEGACY 0x2
  42. #define DRIVER_PCI_DMA 0x8
  43. #define DRIVER_SG 0x10
  44. #define DRIVER_HAVE_DMA 0x20
  45. #define DRIVER_HAVE_IRQ 0x40
  46. #define DRIVER_IRQ_SHARED 0x80
  47. #define DRIVER_GEM 0x1000
  48. #define DRIVER_MODESET 0x2000
  49. #define DRIVER_PRIME 0x4000
  50. #define DRIVER_RENDER 0x8000
  51. #define DRIVER_ATOMIC 0x10000
  52. #define DRIVER_KMS_LEGACY_CONTEXT 0x20000
  53. #define DRIVER_SYNCOBJ 0x40000
  54. #define DRIVER_PREFER_XBGR_30BPP 0x80000
  55. /**
  56. * struct drm_driver - DRM driver structure
  57. *
  58. * This structure represent the common code for a family of cards. There will
  59. * one drm_device for each card present in this family. It contains lots of
  60. * vfunc entries, and a pile of those probably should be moved to more
  61. * appropriate places like &drm_mode_config_funcs or into a new operations
  62. * structure for GEM drivers.
  63. */
  64. struct drm_driver {
  65. /**
  66. * @load:
  67. *
  68. * Backward-compatible driver callback to complete
  69. * initialization steps after the driver is registered. For
  70. * this reason, may suffer from race conditions and its use is
  71. * deprecated for new drivers. It is therefore only supported
  72. * for existing drivers not yet converted to the new scheme.
  73. * See drm_dev_init() and drm_dev_register() for proper and
  74. * race-free way to set up a &struct drm_device.
  75. *
  76. * This is deprecated, do not use!
  77. *
  78. * Returns:
  79. *
  80. * Zero on success, non-zero value on failure.
  81. */
  82. int (*load) (struct drm_device *, unsigned long flags);
  83. /**
  84. * @open:
  85. *
  86. * Driver callback when a new &struct drm_file is opened. Useful for
  87. * setting up driver-private data structures like buffer allocators,
  88. * execution contexts or similar things. Such driver-private resources
  89. * must be released again in @postclose.
  90. *
  91. * Since the display/modeset side of DRM can only be owned by exactly
  92. * one &struct drm_file (see &drm_file.is_master and &drm_device.master)
  93. * there should never be a need to set up any modeset related resources
  94. * in this callback. Doing so would be a driver design bug.
  95. *
  96. * Returns:
  97. *
  98. * 0 on success, a negative error code on failure, which will be
  99. * promoted to userspace as the result of the open() system call.
  100. */
  101. int (*open) (struct drm_device *, struct drm_file *);
  102. /**
  103. * @postclose:
  104. *
  105. * One of the driver callbacks when a new &struct drm_file is closed.
  106. * Useful for tearing down driver-private data structures allocated in
  107. * @open like buffer allocators, execution contexts or similar things.
  108. *
  109. * Since the display/modeset side of DRM can only be owned by exactly
  110. * one &struct drm_file (see &drm_file.is_master and &drm_device.master)
  111. * there should never be a need to tear down any modeset related
  112. * resources in this callback. Doing so would be a driver design bug.
  113. */
  114. void (*postclose) (struct drm_device *, struct drm_file *);
  115. /**
  116. * @lastclose:
  117. *
  118. * Called when the last &struct drm_file has been closed and there's
  119. * currently no userspace client for the &struct drm_device.
  120. *
  121. * Modern drivers should only use this to force-restore the fbdev
  122. * framebuffer using drm_fb_helper_restore_fbdev_mode_unlocked().
  123. * Anything else would indicate there's something seriously wrong.
  124. * Modern drivers can also use this to execute delayed power switching
  125. * state changes, e.g. in conjunction with the :ref:`vga_switcheroo`
  126. * infrastructure.
  127. *
  128. * This is called after @postclose hook has been called.
  129. *
  130. * NOTE:
  131. *
  132. * All legacy drivers use this callback to de-initialize the hardware.
  133. * This is purely because of the shadow-attach model, where the DRM
  134. * kernel driver does not really own the hardware. Instead ownershipe is
  135. * handled with the help of userspace through an inheritedly racy dance
  136. * to set/unset the VT into raw mode.
  137. *
  138. * Legacy drivers initialize the hardware in the @firstopen callback,
  139. * which isn't even called for modern drivers.
  140. */
  141. void (*lastclose) (struct drm_device *);
  142. /**
  143. * @unload:
  144. *
  145. * Reverse the effects of the driver load callback. Ideally,
  146. * the clean up performed by the driver should happen in the
  147. * reverse order of the initialization. Similarly to the load
  148. * hook, this handler is deprecated and its usage should be
  149. * dropped in favor of an open-coded teardown function at the
  150. * driver layer. See drm_dev_unregister() and drm_dev_put()
  151. * for the proper way to remove a &struct drm_device.
  152. *
  153. * The unload() hook is called right after unregistering
  154. * the device.
  155. *
  156. */
  157. void (*unload) (struct drm_device *);
  158. /**
  159. * @release:
  160. *
  161. * Optional callback for destroying device data after the final
  162. * reference is released, i.e. the device is being destroyed. Drivers
  163. * using this callback are responsible for calling drm_dev_fini()
  164. * to finalize the device and then freeing the struct themselves.
  165. */
  166. void (*release) (struct drm_device *);
  167. /**
  168. * @get_vblank_counter:
  169. *
  170. * Driver callback for fetching a raw hardware vblank counter for the
  171. * CRTC specified with the pipe argument. If a device doesn't have a
  172. * hardware counter, the driver can simply leave the hook as NULL.
  173. * The DRM core will account for missed vblank events while interrupts
  174. * where disabled based on system timestamps.
  175. *
  176. * Wraparound handling and loss of events due to modesetting is dealt
  177. * with in the DRM core code, as long as drivers call
  178. * drm_crtc_vblank_off() and drm_crtc_vblank_on() when disabling or
  179. * enabling a CRTC.
  180. *
  181. * This is deprecated and should not be used by new drivers.
  182. * Use &drm_crtc_funcs.get_vblank_counter instead.
  183. *
  184. * Returns:
  185. *
  186. * Raw vblank counter value.
  187. */
  188. u32 (*get_vblank_counter) (struct drm_device *dev, unsigned int pipe);
  189. /**
  190. * @enable_vblank:
  191. *
  192. * Enable vblank interrupts for the CRTC specified with the pipe
  193. * argument.
  194. *
  195. * This is deprecated and should not be used by new drivers.
  196. * Use &drm_crtc_funcs.enable_vblank instead.
  197. *
  198. * Returns:
  199. *
  200. * Zero on success, appropriate errno if the given @crtc's vblank
  201. * interrupt cannot be enabled.
  202. */
  203. int (*enable_vblank) (struct drm_device *dev, unsigned int pipe);
  204. /**
  205. * @disable_vblank:
  206. *
  207. * Disable vblank interrupts for the CRTC specified with the pipe
  208. * argument.
  209. *
  210. * This is deprecated and should not be used by new drivers.
  211. * Use &drm_crtc_funcs.disable_vblank instead.
  212. */
  213. void (*disable_vblank) (struct drm_device *dev, unsigned int pipe);
  214. /**
  215. * @get_scanout_position:
  216. *
  217. * Called by vblank timestamping code.
  218. *
  219. * Returns the current display scanout position from a crtc, and an
  220. * optional accurate ktime_get() timestamp of when position was
  221. * measured. Note that this is a helper callback which is only used if a
  222. * driver uses drm_calc_vbltimestamp_from_scanoutpos() for the
  223. * @get_vblank_timestamp callback.
  224. *
  225. * Parameters:
  226. *
  227. * dev:
  228. * DRM device.
  229. * pipe:
  230. * Id of the crtc to query.
  231. * in_vblank_irq:
  232. * True when called from drm_crtc_handle_vblank(). Some drivers
  233. * need to apply some workarounds for gpu-specific vblank irq quirks
  234. * if flag is set.
  235. * vpos:
  236. * Target location for current vertical scanout position.
  237. * hpos:
  238. * Target location for current horizontal scanout position.
  239. * stime:
  240. * Target location for timestamp taken immediately before
  241. * scanout position query. Can be NULL to skip timestamp.
  242. * etime:
  243. * Target location for timestamp taken immediately after
  244. * scanout position query. Can be NULL to skip timestamp.
  245. * mode:
  246. * Current display timings.
  247. *
  248. * Returns vpos as a positive number while in active scanout area.
  249. * Returns vpos as a negative number inside vblank, counting the number
  250. * of scanlines to go until end of vblank, e.g., -1 means "one scanline
  251. * until start of active scanout / end of vblank."
  252. *
  253. * Returns:
  254. *
  255. * True on success, false if a reliable scanout position counter could
  256. * not be read out.
  257. *
  258. * FIXME:
  259. *
  260. * Since this is a helper to implement @get_vblank_timestamp, we should
  261. * move it to &struct drm_crtc_helper_funcs, like all the other
  262. * helper-internal hooks.
  263. */
  264. bool (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
  265. bool in_vblank_irq, int *vpos, int *hpos,
  266. ktime_t *stime, ktime_t *etime,
  267. const struct drm_display_mode *mode);
  268. /**
  269. * @get_vblank_timestamp:
  270. *
  271. * Called by drm_get_last_vbltimestamp(). Should return a precise
  272. * timestamp when the most recent VBLANK interval ended or will end.
  273. *
  274. * Specifically, the timestamp in @vblank_time should correspond as
  275. * closely as possible to the time when the first video scanline of
  276. * the video frame after the end of VBLANK will start scanning out,
  277. * the time immediately after end of the VBLANK interval. If the
  278. * @crtc is currently inside VBLANK, this will be a time in the future.
  279. * If the @crtc is currently scanning out a frame, this will be the
  280. * past start time of the current scanout. This is meant to adhere
  281. * to the OpenML OML_sync_control extension specification.
  282. *
  283. * Paramters:
  284. *
  285. * dev:
  286. * dev DRM device handle.
  287. * pipe:
  288. * crtc for which timestamp should be returned.
  289. * max_error:
  290. * Maximum allowable timestamp error in nanoseconds.
  291. * Implementation should strive to provide timestamp
  292. * with an error of at most max_error nanoseconds.
  293. * Returns true upper bound on error for timestamp.
  294. * vblank_time:
  295. * Target location for returned vblank timestamp.
  296. * in_vblank_irq:
  297. * True when called from drm_crtc_handle_vblank(). Some drivers
  298. * need to apply some workarounds for gpu-specific vblank irq quirks
  299. * if flag is set.
  300. *
  301. * Returns:
  302. *
  303. * True on success, false on failure, which means the core should
  304. * fallback to a simple timestamp taken in drm_crtc_handle_vblank().
  305. *
  306. * FIXME:
  307. *
  308. * We should move this hook to &struct drm_crtc_funcs like all the other
  309. * vblank hooks.
  310. */
  311. bool (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe,
  312. int *max_error,
  313. ktime_t *vblank_time,
  314. bool in_vblank_irq);
  315. /**
  316. * @irq_handler:
  317. *
  318. * Interrupt handler called when using drm_irq_install(). Not used by
  319. * drivers which implement their own interrupt handling.
  320. */
  321. irqreturn_t(*irq_handler) (int irq, void *arg);
  322. /**
  323. * @irq_preinstall:
  324. *
  325. * Optional callback used by drm_irq_install() which is called before
  326. * the interrupt handler is registered. This should be used to clear out
  327. * any pending interrupts (from e.g. firmware based drives) and reset
  328. * the interrupt handling registers.
  329. */
  330. void (*irq_preinstall) (struct drm_device *dev);
  331. /**
  332. * @irq_postinstall:
  333. *
  334. * Optional callback used by drm_irq_install() which is called after
  335. * the interrupt handler is registered. This should be used to enable
  336. * interrupt generation in the hardware.
  337. */
  338. int (*irq_postinstall) (struct drm_device *dev);
  339. /**
  340. * @irq_uninstall:
  341. *
  342. * Optional callback used by drm_irq_uninstall() which is called before
  343. * the interrupt handler is unregistered. This should be used to disable
  344. * interrupt generation in the hardware.
  345. */
  346. void (*irq_uninstall) (struct drm_device *dev);
  347. /**
  348. * @master_create:
  349. *
  350. * Called whenever a new master is created. Only used by vmwgfx.
  351. */
  352. int (*master_create)(struct drm_device *dev, struct drm_master *master);
  353. /**
  354. * @master_destroy:
  355. *
  356. * Called whenever a master is destroyed. Only used by vmwgfx.
  357. */
  358. void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
  359. /**
  360. * @master_set:
  361. *
  362. * Called whenever the minor master is set. Only used by vmwgfx.
  363. */
  364. int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
  365. bool from_open);
  366. /**
  367. * @master_drop:
  368. *
  369. * Called whenever the minor master is dropped. Only used by vmwgfx.
  370. */
  371. void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
  372. /**
  373. * @debugfs_init:
  374. *
  375. * Allows drivers to create driver-specific debugfs files.
  376. */
  377. int (*debugfs_init)(struct drm_minor *minor);
  378. /**
  379. * @gem_free_object: deconstructor for drm_gem_objects
  380. *
  381. * This is deprecated and should not be used by new drivers. Use
  382. * @gem_free_object_unlocked instead.
  383. */
  384. void (*gem_free_object) (struct drm_gem_object *obj);
  385. /**
  386. * @gem_free_object_unlocked: deconstructor for drm_gem_objects
  387. *
  388. * This is for drivers which are not encumbered with &drm_device.struct_mutex
  389. * legacy locking schemes. Use this hook instead of @gem_free_object.
  390. */
  391. void (*gem_free_object_unlocked) (struct drm_gem_object *obj);
  392. /**
  393. * @gem_open_object:
  394. *
  395. * Driver hook called upon gem handle creation
  396. */
  397. int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  398. /**
  399. * @gem_close_object:
  400. *
  401. * Driver hook called upon gem handle release
  402. */
  403. void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  404. /**
  405. * @gem_print_info:
  406. *
  407. * If driver subclasses struct &drm_gem_object, it can implement this
  408. * optional hook for printing additional driver specific info.
  409. *
  410. * drm_printf_indent() should be used in the callback passing it the
  411. * indent argument.
  412. *
  413. * This callback is called from drm_gem_print_info().
  414. */
  415. void (*gem_print_info)(struct drm_printer *p, unsigned int indent,
  416. const struct drm_gem_object *obj);
  417. /**
  418. * @gem_create_object: constructor for gem objects
  419. *
  420. * Hook for allocating the GEM object struct, for use by core
  421. * helpers.
  422. */
  423. struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
  424. size_t size);
  425. /* prime: */
  426. /**
  427. * @prime_handle_to_fd:
  428. *
  429. * export handle -> fd (see drm_gem_prime_handle_to_fd() helper)
  430. */
  431. int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
  432. uint32_t handle, uint32_t flags, int *prime_fd);
  433. /**
  434. * @prime_fd_to_handle:
  435. *
  436. * import fd -> handle (see drm_gem_prime_fd_to_handle() helper)
  437. */
  438. int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
  439. int prime_fd, uint32_t *handle);
  440. /**
  441. * @gem_prime_export:
  442. *
  443. * export GEM -> dmabuf
  444. */
  445. struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
  446. struct drm_gem_object *obj, int flags);
  447. /**
  448. * @gem_prime_import:
  449. *
  450. * import dmabuf -> GEM
  451. */
  452. struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
  453. struct dma_buf *dma_buf);
  454. int (*gem_prime_pin)(struct drm_gem_object *obj);
  455. void (*gem_prime_unpin)(struct drm_gem_object *obj);
  456. struct reservation_object * (*gem_prime_res_obj)(
  457. struct drm_gem_object *obj);
  458. struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
  459. struct drm_gem_object *(*gem_prime_import_sg_table)(
  460. struct drm_device *dev,
  461. struct dma_buf_attachment *attach,
  462. struct sg_table *sgt);
  463. void *(*gem_prime_vmap)(struct drm_gem_object *obj);
  464. void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
  465. int (*gem_prime_mmap)(struct drm_gem_object *obj,
  466. struct vm_area_struct *vma);
  467. /**
  468. * @dumb_create:
  469. *
  470. * This creates a new dumb buffer in the driver's backing storage manager (GEM,
  471. * TTM or something else entirely) and returns the resulting buffer handle. This
  472. * handle can then be wrapped up into a framebuffer modeset object.
  473. *
  474. * Note that userspace is not allowed to use such objects for render
  475. * acceleration - drivers must create their own private ioctls for such a use
  476. * case.
  477. *
  478. * Width, height and depth are specified in the &drm_mode_create_dumb
  479. * argument. The callback needs to fill the handle, pitch and size for
  480. * the created buffer.
  481. *
  482. * Called by the user via ioctl.
  483. *
  484. * Returns:
  485. *
  486. * Zero on success, negative errno on failure.
  487. */
  488. int (*dumb_create)(struct drm_file *file_priv,
  489. struct drm_device *dev,
  490. struct drm_mode_create_dumb *args);
  491. /**
  492. * @dumb_map_offset:
  493. *
  494. * Allocate an offset in the drm device node's address space to be able to
  495. * memory map a dumb buffer. GEM-based drivers must use
  496. * drm_gem_create_mmap_offset() to implement this.
  497. *
  498. * Called by the user via ioctl.
  499. *
  500. * Returns:
  501. *
  502. * Zero on success, negative errno on failure.
  503. */
  504. int (*dumb_map_offset)(struct drm_file *file_priv,
  505. struct drm_device *dev, uint32_t handle,
  506. uint64_t *offset);
  507. /**
  508. * @dumb_destroy:
  509. *
  510. * This destroys the userspace handle for the given dumb backing storage buffer.
  511. * Since buffer objects must be reference counted in the kernel a buffer object
  512. * won't be immediately freed if a framebuffer modeset object still uses it.
  513. *
  514. * Called by the user via ioctl.
  515. *
  516. * Returns:
  517. *
  518. * Zero on success, negative errno on failure.
  519. */
  520. int (*dumb_destroy)(struct drm_file *file_priv,
  521. struct drm_device *dev,
  522. uint32_t handle);
  523. /**
  524. * @gem_vm_ops: Driver private ops for this object
  525. */
  526. const struct vm_operations_struct *gem_vm_ops;
  527. /** @major: driver major number */
  528. int major;
  529. /** @minor: driver minor number */
  530. int minor;
  531. /** @patchlevel: driver patch level */
  532. int patchlevel;
  533. /** @name: driver name */
  534. char *name;
  535. /** @desc: driver description */
  536. char *desc;
  537. /** @date: driver date */
  538. char *date;
  539. /** @driver_features: driver features */
  540. u32 driver_features;
  541. /**
  542. * @ioctls:
  543. *
  544. * Array of driver-private IOCTL description entries. See the chapter on
  545. * :ref:`IOCTL support in the userland interfaces
  546. * chapter<drm_driver_ioctl>` for the full details.
  547. */
  548. const struct drm_ioctl_desc *ioctls;
  549. /** @num_ioctls: Number of entries in @ioctls. */
  550. int num_ioctls;
  551. /**
  552. * @fops:
  553. *
  554. * File operations for the DRM device node. See the discussion in
  555. * :ref:`file operations<drm_driver_fops>` for in-depth coverage and
  556. * some examples.
  557. */
  558. const struct file_operations *fops;
  559. /* Everything below here is for legacy driver, never use! */
  560. /* private: */
  561. /* List of devices hanging off this driver with stealth attach. */
  562. struct list_head legacy_dev_list;
  563. int (*firstopen) (struct drm_device *);
  564. void (*preclose) (struct drm_device *, struct drm_file *file_priv);
  565. int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
  566. int (*dma_quiescent) (struct drm_device *);
  567. int (*context_dtor) (struct drm_device *dev, int context);
  568. int dev_priv_size;
  569. };
  570. extern unsigned int drm_debug;
  571. int drm_dev_init(struct drm_device *dev,
  572. struct drm_driver *driver,
  573. struct device *parent);
  574. void drm_dev_fini(struct drm_device *dev);
  575. struct drm_device *drm_dev_alloc(struct drm_driver *driver,
  576. struct device *parent);
  577. int drm_dev_register(struct drm_device *dev, unsigned long flags);
  578. void drm_dev_unregister(struct drm_device *dev);
  579. void drm_dev_get(struct drm_device *dev);
  580. void drm_dev_put(struct drm_device *dev);
  581. void drm_dev_unref(struct drm_device *dev);
  582. void drm_put_dev(struct drm_device *dev);
  583. bool drm_dev_enter(struct drm_device *dev, int *idx);
  584. void drm_dev_exit(int idx);
  585. void drm_dev_unplug(struct drm_device *dev);
  586. /**
  587. * drm_dev_is_unplugged - is a DRM device unplugged
  588. * @dev: DRM device
  589. *
  590. * This function can be called to check whether a hotpluggable is unplugged.
  591. * Unplugging itself is singalled through drm_dev_unplug(). If a device is
  592. * unplugged, these two functions guarantee that any store before calling
  593. * drm_dev_unplug() is visible to callers of this function after it completes
  594. */
  595. static inline bool drm_dev_is_unplugged(struct drm_device *dev)
  596. {
  597. int idx;
  598. if (drm_dev_enter(dev, &idx)) {
  599. drm_dev_exit(idx);
  600. return false;
  601. }
  602. return true;
  603. }
  604. /**
  605. * drm_core_check_feature - check driver feature flags
  606. * @dev: DRM device to check
  607. * @feature: feature flag
  608. *
  609. * This checks @dev for driver features, see &drm_driver.driver_features and the
  610. * various DRIVER_\* flags.
  611. *
  612. * Returns true if the @feature is supported, false otherwise.
  613. */
  614. static inline bool drm_core_check_feature(struct drm_device *dev, int feature)
  615. {
  616. return dev->driver->driver_features & feature;
  617. }
  618. /**
  619. * drm_drv_uses_atomic_modeset - check if the driver implements
  620. * atomic_commit()
  621. * @dev: DRM device
  622. *
  623. * This check is useful if drivers do not have DRIVER_ATOMIC set but
  624. * have atomic modesetting internally implemented.
  625. */
  626. static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
  627. {
  628. return drm_core_check_feature(dev, DRIVER_ATOMIC) ||
  629. (dev->mode_config.funcs && dev->mode_config.funcs->atomic_commit != NULL);
  630. }
  631. int drm_dev_set_unique(struct drm_device *dev, const char *name);
  632. #endif