drm_drv.h 18 KB

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