drm_drv.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  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 <linux/uuid.h>
  31. #include <drm/drm_device.h>
  32. struct drm_file;
  33. struct drm_gem_object;
  34. struct drm_master;
  35. struct drm_minor;
  36. struct dma_buf_attachment;
  37. struct drm_display_mode;
  38. struct drm_mode_create_dumb;
  39. struct drm_printer;
  40. /**
  41. * enum drm_driver_feature - feature flags
  42. *
  43. * See &drm_driver.driver_features, drm_device.driver_features and
  44. * drm_core_check_feature().
  45. */
  46. enum drm_driver_feature {
  47. /**
  48. * @DRIVER_GEM:
  49. *
  50. * Driver use the GEM memory manager. This should be set for all modern
  51. * drivers.
  52. */
  53. DRIVER_GEM = BIT(0),
  54. /**
  55. * @DRIVER_MODESET:
  56. *
  57. * Driver supports mode setting interfaces (KMS).
  58. */
  59. DRIVER_MODESET = BIT(1),
  60. /**
  61. * @DRIVER_RENDER:
  62. *
  63. * Driver supports dedicated render nodes. See also the :ref:`section on
  64. * render nodes <drm_render_node>` for details.
  65. */
  66. DRIVER_RENDER = BIT(3),
  67. /**
  68. * @DRIVER_ATOMIC:
  69. *
  70. * Driver supports the full atomic modesetting userspace API. Drivers
  71. * which only use atomic internally, but do not the support the full
  72. * userspace API (e.g. not all properties converted to atomic, or
  73. * multi-plane updates are not guaranteed to be tear-free) should not
  74. * set this flag.
  75. */
  76. DRIVER_ATOMIC = BIT(4),
  77. /**
  78. * @DRIVER_SYNCOBJ:
  79. *
  80. * Driver supports &drm_syncobj for explicit synchronization of command
  81. * submission.
  82. */
  83. DRIVER_SYNCOBJ = BIT(5),
  84. /**
  85. * @DRIVER_SYNCOBJ_TIMELINE:
  86. *
  87. * Driver supports the timeline flavor of &drm_syncobj for explicit
  88. * synchronization of command submission.
  89. */
  90. DRIVER_SYNCOBJ_TIMELINE = BIT(6),
  91. /* IMPORTANT: Below are all the legacy flags, add new ones above. */
  92. /**
  93. * @DRIVER_USE_AGP:
  94. *
  95. * Set up DRM AGP support, see drm_agp_init(), the DRM core will manage
  96. * AGP resources. New drivers don't need this.
  97. */
  98. DRIVER_USE_AGP = BIT(25),
  99. /**
  100. * @DRIVER_LEGACY:
  101. *
  102. * Denote a legacy driver using shadow attach. Do not use.
  103. */
  104. DRIVER_LEGACY = BIT(26),
  105. /**
  106. * @DRIVER_PCI_DMA:
  107. *
  108. * Driver is capable of PCI DMA, mapping of PCI DMA buffers to userspace
  109. * will be enabled. Only for legacy drivers. Do not use.
  110. */
  111. DRIVER_PCI_DMA = BIT(27),
  112. /**
  113. * @DRIVER_SG:
  114. *
  115. * Driver can perform scatter/gather DMA, allocation and mapping of
  116. * scatter/gather buffers will be enabled. Only for legacy drivers. Do
  117. * not use.
  118. */
  119. DRIVER_SG = BIT(28),
  120. /**
  121. * @DRIVER_HAVE_DMA:
  122. *
  123. * Driver supports DMA, the userspace DMA API will be supported. Only
  124. * for legacy drivers. Do not use.
  125. */
  126. DRIVER_HAVE_DMA = BIT(29),
  127. /**
  128. * @DRIVER_HAVE_IRQ:
  129. *
  130. * Legacy irq support. Only for legacy drivers. Do not use.
  131. *
  132. * New drivers can either use the drm_irq_install() and
  133. * drm_irq_uninstall() helper functions, or roll their own irq support
  134. * code by calling request_irq() directly.
  135. */
  136. DRIVER_HAVE_IRQ = BIT(30),
  137. /**
  138. * @DRIVER_KMS_LEGACY_CONTEXT:
  139. *
  140. * Used only by nouveau for backwards compatibility with existing
  141. * userspace. Do not use.
  142. */
  143. DRIVER_KMS_LEGACY_CONTEXT = BIT(31),
  144. };
  145. /**
  146. * struct drm_driver - DRM driver structure
  147. *
  148. * This structure represent the common code for a family of cards. There will be
  149. * one &struct drm_device for each card present in this family. It contains lots
  150. * of vfunc entries, and a pile of those probably should be moved to more
  151. * appropriate places like &drm_mode_config_funcs or into a new operations
  152. * structure for GEM drivers.
  153. */
  154. struct drm_driver {
  155. /**
  156. * @load:
  157. *
  158. * Backward-compatible driver callback to complete initialization steps
  159. * after the driver is registered. For this reason, may suffer from
  160. * race conditions and its use is deprecated for new drivers. It is
  161. * therefore only supported for existing drivers not yet converted to
  162. * the new scheme. See devm_drm_dev_alloc() and drm_dev_register() for
  163. * proper and race-free way to set up a &struct drm_device.
  164. *
  165. * This is deprecated, do not use!
  166. *
  167. * Returns:
  168. *
  169. * Zero on success, non-zero value on failure.
  170. */
  171. int (*load) (struct drm_device *, unsigned long flags);
  172. /**
  173. * @open:
  174. *
  175. * Driver callback when a new &struct drm_file is opened. Useful for
  176. * setting up driver-private data structures like buffer allocators,
  177. * execution contexts or similar things. Such driver-private resources
  178. * must be released again in @postclose.
  179. *
  180. * Since the display/modeset side of DRM can only be owned by exactly
  181. * one &struct drm_file (see &drm_file.is_master and &drm_device.master)
  182. * there should never be a need to set up any modeset related resources
  183. * in this callback. Doing so would be a driver design bug.
  184. *
  185. * Returns:
  186. *
  187. * 0 on success, a negative error code on failure, which will be
  188. * promoted to userspace as the result of the open() system call.
  189. */
  190. int (*open) (struct drm_device *, struct drm_file *);
  191. /**
  192. * @postclose:
  193. *
  194. * One of the driver callbacks when a new &struct drm_file is closed.
  195. * Useful for tearing down driver-private data structures allocated in
  196. * @open like buffer allocators, execution contexts or similar things.
  197. *
  198. * Since the display/modeset side of DRM can only be owned by exactly
  199. * one &struct drm_file (see &drm_file.is_master and &drm_device.master)
  200. * there should never be a need to tear down any modeset related
  201. * resources in this callback. Doing so would be a driver design bug.
  202. */
  203. void (*postclose) (struct drm_device *, struct drm_file *);
  204. /**
  205. * @lastclose:
  206. *
  207. * Called when the last &struct drm_file has been closed and there's
  208. * currently no userspace client for the &struct drm_device.
  209. *
  210. * Modern drivers should only use this to force-restore the fbdev
  211. * framebuffer using drm_fb_helper_restore_fbdev_mode_unlocked().
  212. * Anything else would indicate there's something seriously wrong.
  213. * Modern drivers can also use this to execute delayed power switching
  214. * state changes, e.g. in conjunction with the :ref:`vga_switcheroo`
  215. * infrastructure.
  216. *
  217. * This is called after @postclose hook has been called.
  218. *
  219. * NOTE:
  220. *
  221. * All legacy drivers use this callback to de-initialize the hardware.
  222. * This is purely because of the shadow-attach model, where the DRM
  223. * kernel driver does not really own the hardware. Instead ownershipe is
  224. * handled with the help of userspace through an inheritedly racy dance
  225. * to set/unset the VT into raw mode.
  226. *
  227. * Legacy drivers initialize the hardware in the @firstopen callback,
  228. * which isn't even called for modern drivers.
  229. */
  230. void (*lastclose) (struct drm_device *);
  231. /**
  232. * @unload:
  233. *
  234. * Reverse the effects of the driver load callback. Ideally,
  235. * the clean up performed by the driver should happen in the
  236. * reverse order of the initialization. Similarly to the load
  237. * hook, this handler is deprecated and its usage should be
  238. * dropped in favor of an open-coded teardown function at the
  239. * driver layer. See drm_dev_unregister() and drm_dev_put()
  240. * for the proper way to remove a &struct drm_device.
  241. *
  242. * The unload() hook is called right after unregistering
  243. * the device.
  244. *
  245. */
  246. void (*unload) (struct drm_device *);
  247. /**
  248. * @release:
  249. *
  250. * Optional callback for destroying device data after the final
  251. * reference is released, i.e. the device is being destroyed.
  252. *
  253. * This is deprecated, clean up all memory allocations associated with a
  254. * &drm_device using drmm_add_action(), drmm_kmalloc() and related
  255. * managed resources functions.
  256. */
  257. void (*release) (struct drm_device *);
  258. /**
  259. * @irq_handler:
  260. *
  261. * Interrupt handler called when using drm_irq_install(). Not used by
  262. * drivers which implement their own interrupt handling.
  263. */
  264. irqreturn_t(*irq_handler) (int irq, void *arg);
  265. /**
  266. * @irq_preinstall:
  267. *
  268. * Optional callback used by drm_irq_install() which is called before
  269. * the interrupt handler is registered. This should be used to clear out
  270. * any pending interrupts (from e.g. firmware based drives) and reset
  271. * the interrupt handling registers.
  272. */
  273. void (*irq_preinstall) (struct drm_device *dev);
  274. /**
  275. * @irq_postinstall:
  276. *
  277. * Optional callback used by drm_irq_install() which is called after
  278. * the interrupt handler is registered. This should be used to enable
  279. * interrupt generation in the hardware.
  280. */
  281. int (*irq_postinstall) (struct drm_device *dev);
  282. /**
  283. * @irq_uninstall:
  284. *
  285. * Optional callback used by drm_irq_uninstall() which is called before
  286. * the interrupt handler is unregistered. This should be used to disable
  287. * interrupt generation in the hardware.
  288. */
  289. void (*irq_uninstall) (struct drm_device *dev);
  290. /**
  291. * @master_set:
  292. *
  293. * Called whenever the minor master is set. Only used by vmwgfx.
  294. */
  295. void (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
  296. bool from_open);
  297. /**
  298. * @master_drop:
  299. *
  300. * Called whenever the minor master is dropped. Only used by vmwgfx.
  301. */
  302. void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
  303. /**
  304. * @debugfs_init:
  305. *
  306. * Allows drivers to create driver-specific debugfs files.
  307. */
  308. void (*debugfs_init)(struct drm_minor *minor);
  309. /**
  310. * @gem_free_object_unlocked: deconstructor for drm_gem_objects
  311. *
  312. * This is deprecated and should not be used by new drivers. Use
  313. * &drm_gem_object_funcs.free instead.
  314. */
  315. void (*gem_free_object_unlocked) (struct drm_gem_object *obj);
  316. /**
  317. * @gem_open_object:
  318. *
  319. * This callback is deprecated in favour of &drm_gem_object_funcs.open.
  320. *
  321. * Driver hook called upon gem handle creation
  322. */
  323. int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  324. /**
  325. * @gem_close_object:
  326. *
  327. * This callback is deprecated in favour of &drm_gem_object_funcs.close.
  328. *
  329. * Driver hook called upon gem handle release
  330. */
  331. void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  332. /**
  333. * @gem_create_object: constructor for gem objects
  334. *
  335. * Hook for allocating the GEM object struct, for use by the CMA and
  336. * SHMEM GEM helpers.
  337. */
  338. struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
  339. size_t size);
  340. /**
  341. * @prime_handle_to_fd:
  342. *
  343. * Main PRIME export function. Should be implemented with
  344. * drm_gem_prime_handle_to_fd() for GEM based drivers.
  345. *
  346. * For an in-depth discussion see :ref:`PRIME buffer sharing
  347. * documentation <prime_buffer_sharing>`.
  348. */
  349. int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
  350. uint32_t handle, uint32_t flags, int *prime_fd);
  351. /**
  352. * @prime_fd_to_handle:
  353. *
  354. * Main PRIME import function. Should be implemented with
  355. * drm_gem_prime_fd_to_handle() for GEM based drivers.
  356. *
  357. * For an in-depth discussion see :ref:`PRIME buffer sharing
  358. * documentation <prime_buffer_sharing>`.
  359. */
  360. int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
  361. int prime_fd, uint32_t *handle);
  362. /**
  363. * @gem_prime_export:
  364. *
  365. * Export hook for GEM drivers. Deprecated in favour of
  366. * &drm_gem_object_funcs.export.
  367. */
  368. struct dma_buf * (*gem_prime_export)(struct drm_gem_object *obj,
  369. int flags);
  370. /**
  371. * @gem_prime_import:
  372. *
  373. * Import hook for GEM drivers.
  374. *
  375. * This defaults to drm_gem_prime_import() if not set.
  376. */
  377. struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
  378. struct dma_buf *dma_buf);
  379. /**
  380. * @gem_prime_pin:
  381. *
  382. * Deprecated hook in favour of &drm_gem_object_funcs.pin.
  383. */
  384. int (*gem_prime_pin)(struct drm_gem_object *obj);
  385. /**
  386. * @gem_prime_unpin:
  387. *
  388. * Deprecated hook in favour of &drm_gem_object_funcs.unpin.
  389. */
  390. void (*gem_prime_unpin)(struct drm_gem_object *obj);
  391. /**
  392. * @gem_prime_get_sg_table:
  393. *
  394. * Deprecated hook in favour of &drm_gem_object_funcs.get_sg_table.
  395. */
  396. struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
  397. /**
  398. * @gem_prime_import_sg_table:
  399. *
  400. * Optional hook used by the PRIME helper functions
  401. * drm_gem_prime_import() respectively drm_gem_prime_import_dev().
  402. */
  403. struct drm_gem_object *(*gem_prime_import_sg_table)(
  404. struct drm_device *dev,
  405. struct dma_buf_attachment *attach,
  406. struct sg_table *sgt);
  407. /**
  408. * @gem_prime_vmap:
  409. *
  410. * Deprecated vmap hook for GEM drivers. Please use
  411. * &drm_gem_object_funcs.vmap instead.
  412. */
  413. void *(*gem_prime_vmap)(struct drm_gem_object *obj);
  414. /**
  415. * @gem_prime_vunmap:
  416. *
  417. * Deprecated vunmap hook for GEM drivers. Please use
  418. * &drm_gem_object_funcs.vunmap instead.
  419. */
  420. void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
  421. /**
  422. * @gem_prime_mmap:
  423. *
  424. * mmap hook for GEM drivers, used to implement dma-buf mmap in the
  425. * PRIME helpers.
  426. *
  427. * FIXME: There's way too much duplication going on here, and also moved
  428. * to &drm_gem_object_funcs.
  429. */
  430. int (*gem_prime_mmap)(struct drm_gem_object *obj,
  431. struct vm_area_struct *vma);
  432. /**
  433. * @gem_prime_get_uuid
  434. *
  435. * get_uuid hook for GEM drivers. Retrieves the virtio uuid of the
  436. * given GEM buffer.
  437. */
  438. int (*gem_prime_get_uuid)(struct drm_gem_object *obj,
  439. uuid_t *uuid);
  440. /**
  441. * @dumb_create:
  442. *
  443. * This creates a new dumb buffer in the driver's backing storage manager (GEM,
  444. * TTM or something else entirely) and returns the resulting buffer handle. This
  445. * handle can then be wrapped up into a framebuffer modeset object.
  446. *
  447. * Note that userspace is not allowed to use such objects for render
  448. * acceleration - drivers must create their own private ioctls for such a use
  449. * case.
  450. *
  451. * Width, height and depth are specified in the &drm_mode_create_dumb
  452. * argument. The callback needs to fill the handle, pitch and size for
  453. * the created buffer.
  454. *
  455. * Called by the user via ioctl.
  456. *
  457. * Returns:
  458. *
  459. * Zero on success, negative errno on failure.
  460. */
  461. int (*dumb_create)(struct drm_file *file_priv,
  462. struct drm_device *dev,
  463. struct drm_mode_create_dumb *args);
  464. /**
  465. * @dumb_map_offset:
  466. *
  467. * Allocate an offset in the drm device node's address space to be able to
  468. * memory map a dumb buffer.
  469. *
  470. * The default implementation is drm_gem_create_mmap_offset(). GEM based
  471. * drivers must not overwrite this.
  472. *
  473. * Called by the user via ioctl.
  474. *
  475. * Returns:
  476. *
  477. * Zero on success, negative errno on failure.
  478. */
  479. int (*dumb_map_offset)(struct drm_file *file_priv,
  480. struct drm_device *dev, uint32_t handle,
  481. uint64_t *offset);
  482. /**
  483. * @dumb_destroy:
  484. *
  485. * This destroys the userspace handle for the given dumb backing storage buffer.
  486. * Since buffer objects must be reference counted in the kernel a buffer object
  487. * won't be immediately freed if a framebuffer modeset object still uses it.
  488. *
  489. * Called by the user via ioctl.
  490. *
  491. * The default implementation is drm_gem_dumb_destroy(). GEM based drivers
  492. * must not overwrite this.
  493. *
  494. * Returns:
  495. *
  496. * Zero on success, negative errno on failure.
  497. */
  498. int (*dumb_destroy)(struct drm_file *file_priv,
  499. struct drm_device *dev,
  500. uint32_t handle);
  501. /**
  502. * @gem_vm_ops: Driver private ops for this object
  503. *
  504. * For GEM drivers this is deprecated in favour of
  505. * &drm_gem_object_funcs.vm_ops.
  506. */
  507. const struct vm_operations_struct *gem_vm_ops;
  508. /** @major: driver major number */
  509. int major;
  510. /** @minor: driver minor number */
  511. int minor;
  512. /** @patchlevel: driver patch level */
  513. int patchlevel;
  514. /** @name: driver name */
  515. char *name;
  516. /** @desc: driver description */
  517. char *desc;
  518. /** @date: driver date */
  519. char *date;
  520. /**
  521. * @driver_features:
  522. * Driver features, see &enum drm_driver_feature. Drivers can disable
  523. * some features on a per-instance basis using
  524. * &drm_device.driver_features.
  525. */
  526. u32 driver_features;
  527. /**
  528. * @ioctls:
  529. *
  530. * Array of driver-private IOCTL description entries. See the chapter on
  531. * :ref:`IOCTL support in the userland interfaces
  532. * chapter<drm_driver_ioctl>` for the full details.
  533. */
  534. const struct drm_ioctl_desc *ioctls;
  535. /** @num_ioctls: Number of entries in @ioctls. */
  536. int num_ioctls;
  537. /**
  538. * @fops:
  539. *
  540. * File operations for the DRM device node. See the discussion in
  541. * :ref:`file operations<drm_driver_fops>` for in-depth coverage and
  542. * some examples.
  543. */
  544. const struct file_operations *fops;
  545. /* Everything below here is for legacy driver, never use! */
  546. /* private: */
  547. /* List of devices hanging off this driver with stealth attach. */
  548. struct list_head legacy_dev_list;
  549. int (*firstopen) (struct drm_device *);
  550. void (*preclose) (struct drm_device *, struct drm_file *file_priv);
  551. int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
  552. int (*dma_quiescent) (struct drm_device *);
  553. int (*context_dtor) (struct drm_device *dev, int context);
  554. u32 (*get_vblank_counter)(struct drm_device *dev, unsigned int pipe);
  555. int (*enable_vblank)(struct drm_device *dev, unsigned int pipe);
  556. void (*disable_vblank)(struct drm_device *dev, unsigned int pipe);
  557. int dev_priv_size;
  558. };
  559. void *__devm_drm_dev_alloc(struct device *parent, struct drm_driver *driver,
  560. size_t size, size_t offset);
  561. /**
  562. * devm_drm_dev_alloc - Resource managed allocation of a &drm_device instance
  563. * @parent: Parent device object
  564. * @driver: DRM driver
  565. * @type: the type of the struct which contains struct &drm_device
  566. * @member: the name of the &drm_device within @type.
  567. *
  568. * This allocates and initialize a new DRM device. No device registration is done.
  569. * Call drm_dev_register() to advertice the device to user space and register it
  570. * with other core subsystems. This should be done last in the device
  571. * initialization sequence to make sure userspace can't access an inconsistent
  572. * state.
  573. *
  574. * The initial ref-count of the object is 1. Use drm_dev_get() and
  575. * drm_dev_put() to take and drop further ref-counts.
  576. *
  577. * It is recommended that drivers embed &struct drm_device into their own device
  578. * structure.
  579. *
  580. * Note that this manages the lifetime of the resulting &drm_device
  581. * automatically using devres. The DRM device initialized with this function is
  582. * automatically put on driver detach using drm_dev_put().
  583. *
  584. * RETURNS:
  585. * Pointer to new DRM device, or ERR_PTR on failure.
  586. */
  587. #define devm_drm_dev_alloc(parent, driver, type, member) \
  588. ((type *) __devm_drm_dev_alloc(parent, driver, sizeof(type), \
  589. offsetof(type, member)))
  590. struct drm_device *drm_dev_alloc(struct drm_driver *driver,
  591. struct device *parent);
  592. int drm_dev_register(struct drm_device *dev, unsigned long flags);
  593. void drm_dev_unregister(struct drm_device *dev);
  594. void drm_dev_get(struct drm_device *dev);
  595. void drm_dev_put(struct drm_device *dev);
  596. void drm_put_dev(struct drm_device *dev);
  597. bool drm_dev_enter(struct drm_device *dev, int *idx);
  598. void drm_dev_exit(int idx);
  599. void drm_dev_unplug(struct drm_device *dev);
  600. /**
  601. * drm_dev_is_unplugged - is a DRM device unplugged
  602. * @dev: DRM device
  603. *
  604. * This function can be called to check whether a hotpluggable is unplugged.
  605. * Unplugging itself is singalled through drm_dev_unplug(). If a device is
  606. * unplugged, these two functions guarantee that any store before calling
  607. * drm_dev_unplug() is visible to callers of this function after it completes
  608. *
  609. * WARNING: This function fundamentally races against drm_dev_unplug(). It is
  610. * recommended that drivers instead use the underlying drm_dev_enter() and
  611. * drm_dev_exit() function pairs.
  612. */
  613. static inline bool drm_dev_is_unplugged(struct drm_device *dev)
  614. {
  615. int idx;
  616. if (drm_dev_enter(dev, &idx)) {
  617. drm_dev_exit(idx);
  618. return false;
  619. }
  620. return true;
  621. }
  622. /**
  623. * drm_core_check_all_features - check driver feature flags mask
  624. * @dev: DRM device to check
  625. * @features: feature flag(s) mask
  626. *
  627. * This checks @dev for driver features, see &drm_driver.driver_features,
  628. * &drm_device.driver_features, and the various &enum drm_driver_feature flags.
  629. *
  630. * Returns true if all features in the @features mask are supported, false
  631. * otherwise.
  632. */
  633. static inline bool drm_core_check_all_features(const struct drm_device *dev,
  634. u32 features)
  635. {
  636. u32 supported = dev->driver->driver_features & dev->driver_features;
  637. return features && (supported & features) == features;
  638. }
  639. /**
  640. * drm_core_check_feature - check driver feature flags
  641. * @dev: DRM device to check
  642. * @feature: feature flag
  643. *
  644. * This checks @dev for driver features, see &drm_driver.driver_features,
  645. * &drm_device.driver_features, and the various &enum drm_driver_feature flags.
  646. *
  647. * Returns true if the @feature is supported, false otherwise.
  648. */
  649. static inline bool drm_core_check_feature(const struct drm_device *dev,
  650. enum drm_driver_feature feature)
  651. {
  652. return drm_core_check_all_features(dev, feature);
  653. }
  654. /**
  655. * drm_drv_uses_atomic_modeset - check if the driver implements
  656. * atomic_commit()
  657. * @dev: DRM device
  658. *
  659. * This check is useful if drivers do not have DRIVER_ATOMIC set but
  660. * have atomic modesetting internally implemented.
  661. */
  662. static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
  663. {
  664. return drm_core_check_feature(dev, DRIVER_ATOMIC) ||
  665. (dev->mode_config.funcs && dev->mode_config.funcs->atomic_commit != NULL);
  666. }
  667. int drm_dev_set_unique(struct drm_device *dev, const char *name);
  668. #endif