drm_device.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. #ifndef _DRM_DEVICE_H_
  2. #define _DRM_DEVICE_H_
  3. #include <linux/list.h>
  4. #include <linux/kref.h>
  5. #include <linux/mutex.h>
  6. #include <linux/idr.h>
  7. #include <drm/drm_mode_config.h>
  8. struct drm_driver;
  9. struct drm_minor;
  10. struct drm_master;
  11. struct drm_vblank_crtc;
  12. struct drm_vma_offset_manager;
  13. struct drm_vram_mm;
  14. struct drm_fb_helper;
  15. struct inode;
  16. struct pci_dev;
  17. struct pci_controller;
  18. /**
  19. * enum switch_power_state - power state of drm device
  20. */
  21. enum switch_power_state {
  22. /** @DRM_SWITCH_POWER_ON: Power state is ON */
  23. DRM_SWITCH_POWER_ON = 0,
  24. /** @DRM_SWITCH_POWER_OFF: Power state is OFF */
  25. DRM_SWITCH_POWER_OFF = 1,
  26. /** @DRM_SWITCH_POWER_CHANGING: Power state is changing */
  27. DRM_SWITCH_POWER_CHANGING = 2,
  28. /** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */
  29. DRM_SWITCH_POWER_DYNAMIC_OFF = 3,
  30. };
  31. /**
  32. * struct drm_device - DRM device structure
  33. *
  34. * This structure represent a complete card that
  35. * may contain multiple heads.
  36. */
  37. struct drm_device {
  38. /** @if_version: Highest interface version set */
  39. int if_version;
  40. /** @ref: Object ref-count */
  41. struct kref ref;
  42. /** @dev: Device structure of bus-device */
  43. struct device *dev;
  44. /**
  45. * @managed:
  46. *
  47. * Managed resources linked to the lifetime of this &drm_device as
  48. * tracked by @ref.
  49. */
  50. struct {
  51. /** @managed.resources: managed resources list */
  52. struct list_head resources;
  53. /** @managed.final_kfree: pointer for final kfree() call */
  54. void *final_kfree;
  55. /** @managed.lock: protects @managed.resources */
  56. spinlock_t lock;
  57. } managed;
  58. /** @driver: DRM driver managing the device */
  59. const struct drm_driver *driver;
  60. /**
  61. * @dev_private:
  62. *
  63. * DRM driver private data. This is deprecated and should be left set to
  64. * NULL.
  65. *
  66. * Instead of using this pointer it is recommended that drivers use
  67. * devm_drm_dev_alloc() and embed struct &drm_device in their larger
  68. * per-device structure.
  69. */
  70. void *dev_private;
  71. /**
  72. * @primary:
  73. *
  74. * Primary node. Drivers should not interact with this
  75. * directly. debugfs interfaces can be registered with
  76. * drm_debugfs_add_file(), and sysfs should be directly added on the
  77. * hardware (and not character device node) struct device @dev.
  78. */
  79. struct drm_minor *primary;
  80. /**
  81. * @render:
  82. *
  83. * Render node. Drivers should not interact with this directly ever.
  84. * Drivers should not expose any additional interfaces in debugfs or
  85. * sysfs on this node.
  86. */
  87. struct drm_minor *render;
  88. /** @accel: Compute Acceleration node */
  89. struct drm_minor *accel;
  90. /**
  91. * @registered:
  92. *
  93. * Internally used by drm_dev_register() and drm_connector_register().
  94. */
  95. bool registered;
  96. /**
  97. * @master:
  98. *
  99. * Currently active master for this device.
  100. * Protected by &master_mutex
  101. */
  102. struct drm_master *master;
  103. /**
  104. * @driver_features: per-device driver features
  105. *
  106. * Drivers can clear specific flags here to disallow
  107. * certain features on a per-device basis while still
  108. * sharing a single &struct drm_driver instance across
  109. * all devices.
  110. */
  111. u32 driver_features;
  112. /**
  113. * @unplugged:
  114. *
  115. * Flag to tell if the device has been unplugged.
  116. * See drm_dev_enter() and drm_dev_is_unplugged().
  117. */
  118. bool unplugged;
  119. /** @anon_inode: inode for private address-space */
  120. struct inode *anon_inode;
  121. /** @unique: Unique name of the device */
  122. char *unique;
  123. /**
  124. * @struct_mutex:
  125. *
  126. * Lock for others (not &drm_minor.master and &drm_file.is_master)
  127. *
  128. * TODO: This lock used to be the BKL of the DRM subsystem. Move the
  129. * lock into i915, which is the only remaining user.
  130. */
  131. struct mutex struct_mutex;
  132. /**
  133. * @master_mutex:
  134. *
  135. * Lock for &drm_minor.master and &drm_file.is_master
  136. */
  137. struct mutex master_mutex;
  138. /**
  139. * @open_count:
  140. *
  141. * Usage counter for outstanding files open,
  142. * protected by drm_global_mutex
  143. */
  144. atomic_t open_count;
  145. /** @filelist_mutex: Protects @filelist. */
  146. struct mutex filelist_mutex;
  147. /**
  148. * @filelist:
  149. *
  150. * List of userspace clients, linked through &drm_file.lhead.
  151. */
  152. struct list_head filelist;
  153. /**
  154. * @filelist_internal:
  155. *
  156. * List of open DRM files for in-kernel clients.
  157. * Protected by &filelist_mutex.
  158. */
  159. struct list_head filelist_internal;
  160. /**
  161. * @clientlist_mutex:
  162. *
  163. * Protects &clientlist access.
  164. */
  165. struct mutex clientlist_mutex;
  166. /**
  167. * @clientlist:
  168. *
  169. * List of in-kernel clients. Protected by &clientlist_mutex.
  170. */
  171. struct list_head clientlist;
  172. /**
  173. * @vblank_disable_immediate:
  174. *
  175. * If true, vblank interrupt will be disabled immediately when the
  176. * refcount drops to zero, as opposed to via the vblank disable
  177. * timer.
  178. *
  179. * This can be set to true it the hardware has a working vblank counter
  180. * with high-precision timestamping (otherwise there are races) and the
  181. * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()
  182. * appropriately. Also, see @max_vblank_count,
  183. * &drm_crtc_funcs.get_vblank_counter and
  184. * &drm_vblank_crtc_config.disable_immediate.
  185. */
  186. bool vblank_disable_immediate;
  187. /**
  188. * @vblank:
  189. *
  190. * Array of vblank tracking structures, one per &struct drm_crtc. For
  191. * historical reasons (vblank support predates kernel modesetting) this
  192. * is free-standing and not part of &struct drm_crtc itself. It must be
  193. * initialized explicitly by calling drm_vblank_init().
  194. */
  195. struct drm_vblank_crtc *vblank;
  196. /**
  197. * @vblank_time_lock:
  198. *
  199. * Protects vblank count and time updates during vblank enable/disable
  200. */
  201. spinlock_t vblank_time_lock;
  202. /**
  203. * @vbl_lock: Top-level vblank references lock, wraps the low-level
  204. * @vblank_time_lock.
  205. */
  206. spinlock_t vbl_lock;
  207. /**
  208. * @max_vblank_count:
  209. *
  210. * Maximum value of the vblank registers. This value +1 will result in a
  211. * wrap-around of the vblank register. It is used by the vblank core to
  212. * handle wrap-arounds.
  213. *
  214. * If set to zero the vblank core will try to guess the elapsed vblanks
  215. * between times when the vblank interrupt is disabled through
  216. * high-precision timestamps. That approach is suffering from small
  217. * races and imprecision over longer time periods, hence exposing a
  218. * hardware vblank counter is always recommended.
  219. *
  220. * This is the statically configured device wide maximum. The driver
  221. * can instead choose to use a runtime configurable per-crtc value
  222. * &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count
  223. * must be left at zero. See drm_crtc_set_max_vblank_count() on how
  224. * to use the per-crtc value.
  225. *
  226. * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.
  227. */
  228. u32 max_vblank_count;
  229. /** @vblank_event_list: List of vblank events */
  230. struct list_head vblank_event_list;
  231. /**
  232. * @event_lock:
  233. *
  234. * Protects @vblank_event_list and event delivery in
  235. * general. See drm_send_event() and drm_send_event_locked().
  236. */
  237. spinlock_t event_lock;
  238. /** @num_crtcs: Number of CRTCs on this device */
  239. unsigned int num_crtcs;
  240. /** @mode_config: Current mode config */
  241. struct drm_mode_config mode_config;
  242. /** @object_name_lock: GEM information */
  243. struct mutex object_name_lock;
  244. /** @object_name_idr: GEM information */
  245. struct idr object_name_idr;
  246. /** @vma_offset_manager: GEM information */
  247. struct drm_vma_offset_manager *vma_offset_manager;
  248. /** @vram_mm: VRAM MM memory manager */
  249. struct drm_vram_mm *vram_mm;
  250. /**
  251. * @switch_power_state:
  252. *
  253. * Power state of the client.
  254. * Used by drivers supporting the switcheroo driver.
  255. * The state is maintained in the
  256. * &vga_switcheroo_client_ops.set_gpu_state callback
  257. */
  258. enum switch_power_state switch_power_state;
  259. /**
  260. * @fb_helper:
  261. *
  262. * Pointer to the fbdev emulation structure.
  263. * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
  264. */
  265. struct drm_fb_helper *fb_helper;
  266. /**
  267. * @debugfs_root:
  268. *
  269. * Root directory for debugfs files.
  270. */
  271. struct dentry *debugfs_root;
  272. };
  273. #endif