drm_device.h 8.5 KB

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