drm_file.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. * All rights reserved.
  6. *
  7. * Author: Rickard E. (Rik) Faith <faith@valinux.com>
  8. * Author: Gareth Hughes <gareth@valinux.com>
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a
  11. * copy of this software and associated documentation files (the "Software"),
  12. * to deal in the Software without restriction, including without limitation
  13. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14. * and/or sell copies of the Software, and to permit persons to whom the
  15. * Software is furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice (including the next
  18. * paragraph) shall be included in all copies or substantial portions of the
  19. * Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  24. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  25. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  26. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  27. * OTHER DEALINGS IN THE SOFTWARE.
  28. */
  29. #ifndef _DRM_FILE_H_
  30. #define _DRM_FILE_H_
  31. #include <linux/types.h>
  32. #include <linux/completion.h>
  33. #include <linux/idr.h>
  34. #include <uapi/drm/drm.h>
  35. #include <drm/drm_prime.h>
  36. struct dma_fence;
  37. struct drm_file;
  38. struct drm_device;
  39. struct device;
  40. struct file;
  41. /*
  42. * FIXME: Not sure we want to have drm_minor here in the end, but to avoid
  43. * header include loops we need it here for now.
  44. */
  45. /* Note that the order of this enum is ABI (it determines
  46. * /dev/dri/renderD* numbers).
  47. */
  48. enum drm_minor_type {
  49. DRM_MINOR_PRIMARY,
  50. DRM_MINOR_CONTROL,
  51. DRM_MINOR_RENDER,
  52. };
  53. /**
  54. * struct drm_minor - DRM device minor structure
  55. *
  56. * This structure represents a DRM minor number for device nodes in /dev.
  57. * Entirely opaque to drivers and should never be inspected directly by drivers.
  58. * Drivers instead should only interact with &struct drm_file and of course
  59. * &struct drm_device, which is also where driver-private data and resources can
  60. * be attached to.
  61. */
  62. struct drm_minor {
  63. /* private: */
  64. int index; /* Minor device number */
  65. int type; /* Control or render */
  66. struct device *kdev; /* Linux device */
  67. struct drm_device *dev;
  68. struct dentry *debugfs_root;
  69. struct list_head debugfs_list;
  70. struct mutex debugfs_lock; /* Protects debugfs_list. */
  71. };
  72. /**
  73. * struct drm_pending_event - Event queued up for userspace to read
  74. *
  75. * This represents a DRM event. Drivers can use this as a generic completion
  76. * mechanism, which supports kernel-internal &struct completion, &struct dma_fence
  77. * and also the DRM-specific &struct drm_event delivery mechanism.
  78. */
  79. struct drm_pending_event {
  80. /**
  81. * @completion:
  82. *
  83. * Optional pointer to a kernel internal completion signalled when
  84. * drm_send_event() is called, useful to internally synchronize with
  85. * nonblocking operations.
  86. */
  87. struct completion *completion;
  88. /**
  89. * @completion_release:
  90. *
  91. * Optional callback currently only used by the atomic modeset helpers
  92. * to clean up the reference count for the structure @completion is
  93. * stored in.
  94. */
  95. void (*completion_release)(struct completion *completion);
  96. /**
  97. * @event:
  98. *
  99. * Pointer to the actual event that should be sent to userspace to be
  100. * read using drm_read(). Can be optional, since nowadays events are
  101. * also used to signal kernel internal threads with @completion or DMA
  102. * transactions using @fence.
  103. */
  104. struct drm_event *event;
  105. /**
  106. * @fence:
  107. *
  108. * Optional DMA fence to unblock other hardware transactions which
  109. * depend upon the nonblocking DRM operation this event represents.
  110. */
  111. struct dma_fence *fence;
  112. /**
  113. * @file_priv:
  114. *
  115. * &struct drm_file where @event should be delivered to. Only set when
  116. * @event is set.
  117. */
  118. struct drm_file *file_priv;
  119. /**
  120. * @link:
  121. *
  122. * Double-linked list to keep track of this event. Can be used by the
  123. * driver up to the point when it calls drm_send_event(), after that
  124. * this list entry is owned by the core for its own book-keeping.
  125. */
  126. struct list_head link;
  127. /**
  128. * @pending_link:
  129. *
  130. * Entry on &drm_file.pending_event_list, to keep track of all pending
  131. * events for @file_priv, to allow correct unwinding of them when
  132. * userspace closes the file before the event is delivered.
  133. */
  134. struct list_head pending_link;
  135. };
  136. /**
  137. * struct drm_file - DRM file private data
  138. *
  139. * This structure tracks DRM state per open file descriptor.
  140. */
  141. struct drm_file {
  142. /**
  143. * @authenticated:
  144. *
  145. * Whether the client is allowed to submit rendering, which for legacy
  146. * nodes means it must be authenticated.
  147. *
  148. * See also the :ref:`section on primary nodes and authentication
  149. * <drm_primary_node>`.
  150. */
  151. bool authenticated;
  152. /**
  153. * @stereo_allowed:
  154. *
  155. * True when the client has asked us to expose stereo 3D mode flags.
  156. */
  157. bool stereo_allowed;
  158. /**
  159. * @universal_planes:
  160. *
  161. * True if client understands CRTC primary planes and cursor planes
  162. * in the plane list. Automatically set when @atomic is set.
  163. */
  164. bool universal_planes;
  165. /** @atomic: True if client understands atomic properties. */
  166. bool atomic;
  167. /**
  168. * @aspect_ratio_allowed:
  169. *
  170. * True, if client can handle picture aspect ratios, and has requested
  171. * to pass this information along with the mode.
  172. */
  173. bool aspect_ratio_allowed;
  174. /**
  175. * @writeback_connectors:
  176. *
  177. * True if client understands writeback connectors
  178. */
  179. bool writeback_connectors;
  180. /**
  181. * @was_master:
  182. *
  183. * This client has or had, master capability. Protected by struct
  184. * &drm_device.master_mutex.
  185. *
  186. * This is used to ensure that CAP_SYS_ADMIN is not enforced, if the
  187. * client is or was master in the past.
  188. */
  189. bool was_master;
  190. /**
  191. * @is_master:
  192. *
  193. * This client is the creator of @master. Protected by struct
  194. * &drm_device.master_mutex.
  195. *
  196. * See also the :ref:`section on primary nodes and authentication
  197. * <drm_primary_node>`.
  198. */
  199. bool is_master;
  200. /**
  201. * @master:
  202. *
  203. * Master this node is currently associated with. Only relevant if
  204. * drm_is_primary_client() returns true. Note that this only
  205. * matches &drm_device.master if the master is the currently active one.
  206. *
  207. * See also @authentication and @is_master and the :ref:`section on
  208. * primary nodes and authentication <drm_primary_node>`.
  209. */
  210. struct drm_master *master;
  211. /** @pid: Process that opened this file. */
  212. struct pid *pid;
  213. /** @magic: Authentication magic, see @authenticated. */
  214. drm_magic_t magic;
  215. /**
  216. * @lhead:
  217. *
  218. * List of all open files of a DRM device, linked into
  219. * &drm_device.filelist. Protected by &drm_device.filelist_mutex.
  220. */
  221. struct list_head lhead;
  222. /** @minor: &struct drm_minor for this file. */
  223. struct drm_minor *minor;
  224. /**
  225. * @object_idr:
  226. *
  227. * Mapping of mm object handles to object pointers. Used by the GEM
  228. * subsystem. Protected by @table_lock.
  229. */
  230. struct idr object_idr;
  231. /** @table_lock: Protects @object_idr. */
  232. spinlock_t table_lock;
  233. /** @syncobj_idr: Mapping of sync object handles to object pointers. */
  234. struct idr syncobj_idr;
  235. /** @syncobj_table_lock: Protects @syncobj_idr. */
  236. spinlock_t syncobj_table_lock;
  237. /** @filp: Pointer to the core file structure. */
  238. struct file *filp;
  239. /**
  240. * @driver_priv:
  241. *
  242. * Optional pointer for driver private data. Can be allocated in
  243. * &drm_driver.open and should be freed in &drm_driver.postclose.
  244. */
  245. void *driver_priv;
  246. /**
  247. * @fbs:
  248. *
  249. * List of &struct drm_framebuffer associated with this file, using the
  250. * &drm_framebuffer.filp_head entry.
  251. *
  252. * Protected by @fbs_lock. Note that the @fbs list holds a reference on
  253. * the framebuffer object to prevent it from untimely disappearing.
  254. */
  255. struct list_head fbs;
  256. /** @fbs_lock: Protects @fbs. */
  257. struct mutex fbs_lock;
  258. /**
  259. * @blobs:
  260. *
  261. * User-created blob properties; this retains a reference on the
  262. * property.
  263. *
  264. * Protected by @drm_mode_config.blob_lock;
  265. */
  266. struct list_head blobs;
  267. /** @event_wait: Waitqueue for new events added to @event_list. */
  268. wait_queue_head_t event_wait;
  269. /**
  270. * @pending_event_list:
  271. *
  272. * List of pending &struct drm_pending_event, used to clean up pending
  273. * events in case this file gets closed before the event is signalled.
  274. * Uses the &drm_pending_event.pending_link entry.
  275. *
  276. * Protect by &drm_device.event_lock.
  277. */
  278. struct list_head pending_event_list;
  279. /**
  280. * @event_list:
  281. *
  282. * List of &struct drm_pending_event, ready for delivery to userspace
  283. * through drm_read(). Uses the &drm_pending_event.link entry.
  284. *
  285. * Protect by &drm_device.event_lock.
  286. */
  287. struct list_head event_list;
  288. /**
  289. * @event_space:
  290. *
  291. * Available event space to prevent userspace from
  292. * exhausting kernel memory. Currently limited to the fairly arbitrary
  293. * value of 4KB.
  294. */
  295. int event_space;
  296. /** @event_read_lock: Serializes drm_read(). */
  297. struct mutex event_read_lock;
  298. /**
  299. * @prime:
  300. *
  301. * Per-file buffer caches used by the PRIME buffer sharing code.
  302. */
  303. struct drm_prime_file_private prime;
  304. /* private: */
  305. #if IS_ENABLED(CONFIG_DRM_LEGACY)
  306. unsigned long lock_count; /* DRI1 legacy lock count */
  307. #endif
  308. };
  309. /**
  310. * drm_is_primary_client - is this an open file of the primary node
  311. * @file_priv: DRM file
  312. *
  313. * Returns true if this is an open file of the primary node, i.e.
  314. * &drm_file.minor of @file_priv is a primary minor.
  315. *
  316. * See also the :ref:`section on primary nodes and authentication
  317. * <drm_primary_node>`.
  318. */
  319. static inline bool drm_is_primary_client(const struct drm_file *file_priv)
  320. {
  321. return file_priv->minor->type == DRM_MINOR_PRIMARY;
  322. }
  323. /**
  324. * drm_is_render_client - is this an open file of the render node
  325. * @file_priv: DRM file
  326. *
  327. * Returns true if this is an open file of the render node, i.e.
  328. * &drm_file.minor of @file_priv is a render minor.
  329. *
  330. * See also the :ref:`section on render nodes <drm_render_node>`.
  331. */
  332. static inline bool drm_is_render_client(const struct drm_file *file_priv)
  333. {
  334. return file_priv->minor->type == DRM_MINOR_RENDER;
  335. }
  336. int drm_open(struct inode *inode, struct file *filp);
  337. ssize_t drm_read(struct file *filp, char __user *buffer,
  338. size_t count, loff_t *offset);
  339. int drm_release(struct inode *inode, struct file *filp);
  340. int drm_release_noglobal(struct inode *inode, struct file *filp);
  341. __poll_t drm_poll(struct file *filp, struct poll_table_struct *wait);
  342. int drm_event_reserve_init_locked(struct drm_device *dev,
  343. struct drm_file *file_priv,
  344. struct drm_pending_event *p,
  345. struct drm_event *e);
  346. int drm_event_reserve_init(struct drm_device *dev,
  347. struct drm_file *file_priv,
  348. struct drm_pending_event *p,
  349. struct drm_event *e);
  350. void drm_event_cancel_free(struct drm_device *dev,
  351. struct drm_pending_event *p);
  352. void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
  353. void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
  354. void drm_send_event_timestamp_locked(struct drm_device *dev,
  355. struct drm_pending_event *e,
  356. ktime_t timestamp);
  357. struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);
  358. #ifdef CONFIG_MMU
  359. struct drm_vma_offset_manager;
  360. unsigned long drm_get_unmapped_area(struct file *file,
  361. unsigned long uaddr, unsigned long len,
  362. unsigned long pgoff, unsigned long flags,
  363. struct drm_vma_offset_manager *mgr);
  364. #endif /* CONFIG_MMU */
  365. #endif /* _DRM_FILE_H_ */