drm_device.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. #ifndef _DRM_DEVICE_H_
  2. #define _DRM_DEVICE_H_
  3. #include <linux/list.h>
  4. #include <linux/kref.h>
  5. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  6. #include <linux/mount.h>
  7. #endif
  8. #include <linux/mutex.h>
  9. #include <linux/idr.h>
  10. #include <linux/sched.h>
  11. #include <drm/drm_mode_config.h>
  12. struct drm_driver;
  13. struct drm_minor;
  14. struct drm_master;
  15. struct drm_vblank_crtc;
  16. struct drm_vma_offset_manager;
  17. struct drm_vram_mm;
  18. struct drm_fb_helper;
  19. struct inode;
  20. struct pci_dev;
  21. struct pci_controller;
  22. /*
  23. * Recovery methods for wedged device in order of less to more side-effects.
  24. * To be used with drm_dev_wedged_event() as recovery @method. Callers can
  25. * use any one, multiple (or'd) or none depending on their needs.
  26. *
  27. * Refer to "Device Wedging" chapter in Documentation/gpu/drm-uapi.rst for more
  28. * details.
  29. */
  30. #define DRM_WEDGE_RECOVERY_NONE BIT(0) /* optional telemetry collection */
  31. #define DRM_WEDGE_RECOVERY_REBIND BIT(1) /* unbind + bind driver */
  32. #define DRM_WEDGE_RECOVERY_BUS_RESET BIT(2) /* unbind + reset bus device + bind */
  33. #define DRM_WEDGE_RECOVERY_VENDOR BIT(3) /* vendor specific recovery method */
  34. /**
  35. * struct drm_wedge_task_info - information about the guilty task of a wedge dev
  36. */
  37. struct drm_wedge_task_info {
  38. /** @pid: pid of the task */
  39. pid_t pid;
  40. /** @comm: command name of the task */
  41. char comm[TASK_COMM_LEN];
  42. };
  43. /**
  44. * enum switch_power_state - power state of drm device
  45. */
  46. enum switch_power_state {
  47. /** @DRM_SWITCH_POWER_ON: Power state is ON */
  48. DRM_SWITCH_POWER_ON = 0,
  49. /** @DRM_SWITCH_POWER_OFF: Power state is OFF */
  50. DRM_SWITCH_POWER_OFF = 1,
  51. /** @DRM_SWITCH_POWER_CHANGING: Power state is changing */
  52. DRM_SWITCH_POWER_CHANGING = 2,
  53. /** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */
  54. DRM_SWITCH_POWER_DYNAMIC_OFF = 3,
  55. };
  56. /**
  57. * struct drm_device - DRM device structure
  58. *
  59. * This structure represent a complete card that
  60. * may contain multiple heads.
  61. */
  62. struct drm_device {
  63. /** @if_version: Highest interface version set */
  64. int if_version;
  65. /** @ref: Object ref-count */
  66. struct kref ref;
  67. /** @dev: Device structure of bus-device */
  68. struct device *dev;
  69. /**
  70. * @dma_dev:
  71. *
  72. * Device for DMA operations. Only required if the device @dev
  73. * cannot perform DMA by itself. Should be NULL otherwise. Call
  74. * drm_dev_dma_dev() to get the DMA device instead of using this
  75. * field directly. Call drm_dev_set_dma_dev() to set this field.
  76. *
  77. * DRM devices are sometimes bound to virtual devices that cannot
  78. * perform DMA by themselves. Drivers should set this field to the
  79. * respective DMA controller.
  80. *
  81. * Devices on USB and other peripheral busses also cannot perform
  82. * DMA by themselves. The @dma_dev field should point the bus
  83. * controller that does DMA on behalve of such a device. Required
  84. * for importing buffers via dma-buf.
  85. *
  86. * If set, the DRM core automatically releases the reference on the
  87. * device.
  88. */
  89. struct device *dma_dev;
  90. /**
  91. * @managed:
  92. *
  93. * Managed resources linked to the lifetime of this &drm_device as
  94. * tracked by @ref.
  95. */
  96. struct {
  97. /** @managed.resources: managed resources list */
  98. struct list_head resources;
  99. /** @managed.final_kfree: pointer for final kfree() call */
  100. void *final_kfree;
  101. /** @managed.lock: protects @managed.resources */
  102. spinlock_t lock;
  103. } managed;
  104. /** @driver: DRM driver managing the device */
  105. const struct drm_driver *driver;
  106. /**
  107. * @dev_private:
  108. *
  109. * DRM driver private data. This is deprecated and should be left set to
  110. * NULL.
  111. *
  112. * Instead of using this pointer it is recommended that drivers use
  113. * devm_drm_dev_alloc() and embed struct &drm_device in their larger
  114. * per-device structure.
  115. */
  116. void *dev_private;
  117. /**
  118. * @primary:
  119. *
  120. * Primary node. Drivers should not interact with this
  121. * directly. debugfs interfaces can be registered with
  122. * drm_debugfs_add_file(), and sysfs should be directly added on the
  123. * hardware (and not character device node) struct device @dev.
  124. */
  125. struct drm_minor *primary;
  126. /**
  127. * @render:
  128. *
  129. * Render node. Drivers should not interact with this directly ever.
  130. * Drivers should not expose any additional interfaces in debugfs or
  131. * sysfs on this node.
  132. */
  133. struct drm_minor *render;
  134. /** @accel: Compute Acceleration node */
  135. struct drm_minor *accel;
  136. /**
  137. * @registered:
  138. *
  139. * Internally used by drm_dev_register() and drm_connector_register().
  140. */
  141. bool registered;
  142. /**
  143. * @master:
  144. *
  145. * Currently active master for this device.
  146. * Protected by &master_mutex
  147. */
  148. struct drm_master *master;
  149. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  150. /**
  151. * @huge_mnt:
  152. *
  153. * Huge tmpfs mountpoint used at GEM object initialization
  154. * drm_gem_object_init(). Drivers can call drm_gem_huge_mnt_create() to
  155. * create, mount and use it. The default tmpfs mountpoint (`shm_mnt`) is
  156. * used if NULL.
  157. */
  158. struct vfsmount *huge_mnt;
  159. #endif
  160. /**
  161. * @driver_features: per-device driver features
  162. *
  163. * Drivers can clear specific flags here to disallow
  164. * certain features on a per-device basis while still
  165. * sharing a single &struct drm_driver instance across
  166. * all devices.
  167. */
  168. u32 driver_features;
  169. /**
  170. * @unplugged:
  171. *
  172. * Flag to tell if the device has been unplugged.
  173. * See drm_dev_enter() and drm_dev_is_unplugged().
  174. */
  175. bool unplugged;
  176. /** @anon_inode: inode for private address-space */
  177. struct inode *anon_inode;
  178. /** @unique: Unique name of the device */
  179. char *unique;
  180. /**
  181. * @master_mutex:
  182. *
  183. * Lock for &drm_minor.master and &drm_file.is_master
  184. */
  185. struct mutex master_mutex;
  186. /**
  187. * @open_count:
  188. *
  189. * Usage counter for outstanding files open,
  190. * protected by drm_global_mutex
  191. */
  192. atomic_t open_count;
  193. /** @filelist_mutex: Protects @filelist. */
  194. struct mutex filelist_mutex;
  195. /**
  196. * @filelist:
  197. *
  198. * List of userspace clients, linked through &drm_file.lhead.
  199. */
  200. struct list_head filelist;
  201. /**
  202. * @filelist_internal:
  203. *
  204. * List of open DRM files for in-kernel clients.
  205. * Protected by &filelist_mutex.
  206. */
  207. struct list_head filelist_internal;
  208. /**
  209. * @clientlist_mutex:
  210. *
  211. * Protects &clientlist access.
  212. */
  213. struct mutex clientlist_mutex;
  214. /**
  215. * @clientlist:
  216. *
  217. * List of in-kernel clients. Protected by &clientlist_mutex.
  218. */
  219. struct list_head clientlist;
  220. /**
  221. * @client_sysrq_list:
  222. *
  223. * Entry into list of devices registered for sysrq. Allows in-kernel
  224. * clients on this device to handle sysrq keys.
  225. */
  226. struct list_head client_sysrq_list;
  227. /**
  228. * @vblank_disable_immediate:
  229. *
  230. * If true, vblank interrupt will be disabled immediately when the
  231. * refcount drops to zero, as opposed to via the vblank disable
  232. * timer.
  233. *
  234. * This can be set to true it the hardware has a working vblank counter
  235. * with high-precision timestamping (otherwise there are races) and the
  236. * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()
  237. * appropriately. Also, see @max_vblank_count,
  238. * &drm_crtc_funcs.get_vblank_counter and
  239. * &drm_vblank_crtc_config.disable_immediate.
  240. */
  241. bool vblank_disable_immediate;
  242. /**
  243. * @vblank:
  244. *
  245. * Array of vblank tracking structures, one per &struct drm_crtc. For
  246. * historical reasons (vblank support predates kernel modesetting) this
  247. * is free-standing and not part of &struct drm_crtc itself. It must be
  248. * initialized explicitly by calling drm_vblank_init().
  249. */
  250. struct drm_vblank_crtc *vblank;
  251. /**
  252. * @vblank_time_lock:
  253. *
  254. * Protects vblank count and time updates during vblank enable/disable
  255. */
  256. spinlock_t vblank_time_lock;
  257. /**
  258. * @vbl_lock: Top-level vblank references lock, wraps the low-level
  259. * @vblank_time_lock.
  260. */
  261. spinlock_t vbl_lock;
  262. /**
  263. * @max_vblank_count:
  264. *
  265. * Maximum value of the vblank registers. This value +1 will result in a
  266. * wrap-around of the vblank register. It is used by the vblank core to
  267. * handle wrap-arounds.
  268. *
  269. * If set to zero the vblank core will try to guess the elapsed vblanks
  270. * between times when the vblank interrupt is disabled through
  271. * high-precision timestamps. That approach is suffering from small
  272. * races and imprecision over longer time periods, hence exposing a
  273. * hardware vblank counter is always recommended.
  274. *
  275. * This is the statically configured device wide maximum. The driver
  276. * can instead choose to use a runtime configurable per-crtc value
  277. * &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count
  278. * must be left at zero. See drm_crtc_set_max_vblank_count() on how
  279. * to use the per-crtc value.
  280. *
  281. * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.
  282. */
  283. u32 max_vblank_count;
  284. /** @vblank_event_list: List of vblank events */
  285. struct list_head vblank_event_list;
  286. /**
  287. * @event_lock:
  288. *
  289. * Protects @vblank_event_list and event delivery in
  290. * general. See drm_send_event() and drm_send_event_locked().
  291. */
  292. spinlock_t event_lock;
  293. /** @num_crtcs: Number of CRTCs on this device */
  294. unsigned int num_crtcs;
  295. /** @mode_config: Current mode config */
  296. struct drm_mode_config mode_config;
  297. /** @object_name_lock: GEM information */
  298. struct mutex object_name_lock;
  299. /** @object_name_idr: GEM information */
  300. struct idr object_name_idr;
  301. /** @vma_offset_manager: GEM information */
  302. struct drm_vma_offset_manager *vma_offset_manager;
  303. /** @vram_mm: VRAM MM memory manager */
  304. struct drm_vram_mm *vram_mm;
  305. /**
  306. * @switch_power_state:
  307. *
  308. * Power state of the client.
  309. * Used by drivers supporting the switcheroo driver.
  310. * The state is maintained in the
  311. * &vga_switcheroo_client_ops.set_gpu_state callback
  312. */
  313. enum switch_power_state switch_power_state;
  314. /**
  315. * @fb_helper:
  316. *
  317. * Pointer to the fbdev emulation structure.
  318. * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
  319. */
  320. struct drm_fb_helper *fb_helper;
  321. /**
  322. * @debugfs_root:
  323. *
  324. * Root directory for debugfs files.
  325. */
  326. struct dentry *debugfs_root;
  327. };
  328. void drm_dev_set_dma_dev(struct drm_device *dev, struct device *dma_dev);
  329. /**
  330. * drm_dev_dma_dev - returns the DMA device for a DRM device
  331. * @dev: DRM device
  332. *
  333. * Returns the DMA device of the given DRM device. By default, this
  334. * the DRM device's parent. See drm_dev_set_dma_dev().
  335. *
  336. * Returns:
  337. * A DMA-capable device for the DRM device.
  338. */
  339. static inline struct device *drm_dev_dma_dev(struct drm_device *dev)
  340. {
  341. if (dev->dma_dev)
  342. return dev->dma_dev;
  343. return dev->dev;
  344. }
  345. #endif