drm_file.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 <uapi/drm/drm.h>
  34. #include <drm/drm_prime.h>
  35. struct dma_fence;
  36. struct drm_file;
  37. struct drm_device;
  38. struct device;
  39. /*
  40. * FIXME: Not sure we want to have drm_minor here in the end, but to avoid
  41. * header include loops we need it here for now.
  42. */
  43. /* Note that the order of this enum is ABI (it determines
  44. * /dev/dri/renderD* numbers).
  45. */
  46. enum drm_minor_type {
  47. DRM_MINOR_PRIMARY,
  48. DRM_MINOR_CONTROL,
  49. DRM_MINOR_RENDER,
  50. };
  51. /**
  52. * struct drm_minor - DRM device minor structure
  53. *
  54. * This structure represents a DRM minor number for device nodes in /dev.
  55. * Entirely opaque to drivers and should never be inspected directly by drivers.
  56. * Drivers instead should only interact with &struct drm_file and of course
  57. * &struct drm_device, which is also where driver-private data and resources can
  58. * be attached to.
  59. */
  60. struct drm_minor {
  61. /* private: */
  62. int index; /* Minor device number */
  63. int type; /* Control or render */
  64. struct device *kdev; /* Linux device */
  65. struct drm_device *dev;
  66. struct dentry *debugfs_root;
  67. struct list_head debugfs_list;
  68. struct mutex debugfs_lock; /* Protects debugfs_list. */
  69. };
  70. /**
  71. * struct drm_pending_event - Event queued up for userspace to read
  72. *
  73. * This represents a DRM event. Drivers can use this as a generic completion
  74. * mechanism, which supports kernel-internal &struct completion, &struct dma_fence
  75. * and also the DRM-specific &struct drm_event delivery mechanism.
  76. */
  77. struct drm_pending_event {
  78. /**
  79. * @completion:
  80. *
  81. * Optional pointer to a kernel internal completion signalled when
  82. * drm_send_event() is called, useful to internally synchronize with
  83. * nonblocking operations.
  84. */
  85. struct completion *completion;
  86. /**
  87. * @completion_release:
  88. *
  89. * Optional callback currently only used by the atomic modeset helpers
  90. * to clean up the reference count for the structure @completion is
  91. * stored in.
  92. */
  93. void (*completion_release)(struct completion *completion);
  94. /**
  95. * @event:
  96. *
  97. * Pointer to the actual event that should be sent to userspace to be
  98. * read using drm_read(). Can be optional, since nowadays events are
  99. * also used to signal kernel internal threads with @completion or DMA
  100. * transactions using @fence.
  101. */
  102. struct drm_event *event;
  103. /**
  104. * @fence:
  105. *
  106. * Optional DMA fence to unblock other hardware transactions which
  107. * depend upon the nonblocking DRM operation this event represents.
  108. */
  109. struct dma_fence *fence;
  110. /**
  111. * @file_priv:
  112. *
  113. * &struct drm_file where @event should be delivered to. Only set when
  114. * @event is set.
  115. */
  116. struct drm_file *file_priv;
  117. /**
  118. * @link:
  119. *
  120. * Double-linked list to keep track of this event. Can be used by the
  121. * driver up to the point when it calls drm_send_event(), after that
  122. * this list entry is owned by the core for its own book-keeping.
  123. */
  124. struct list_head link;
  125. /**
  126. * @pending_link:
  127. *
  128. * Entry on &drm_file.pending_event_list, to keep track of all pending
  129. * events for @file_priv, to allow correct unwinding of them when
  130. * userspace closes the file before the event is delivered.
  131. */
  132. struct list_head pending_link;
  133. };
  134. /**
  135. * struct drm_file - DRM file private data
  136. *
  137. * This structure tracks DRM state per open file descriptor.
  138. */
  139. struct drm_file {
  140. /**
  141. * @authenticated:
  142. *
  143. * Whether the client is allowed to submit rendering, which for legacy
  144. * nodes means it must be authenticated.
  145. *
  146. * See also the :ref:`section on primary nodes and authentication
  147. * <drm_primary_node>`.
  148. */
  149. unsigned authenticated :1;
  150. /**
  151. * @stereo_allowed:
  152. *
  153. * True when the client has asked us to expose stereo 3D mode flags.
  154. */
  155. unsigned stereo_allowed :1;
  156. /**
  157. * @universal_planes:
  158. *
  159. * True if client understands CRTC primary planes and cursor planes
  160. * in the plane list. Automatically set when @atomic is set.
  161. */
  162. unsigned universal_planes:1;
  163. /** @atomic: True if client understands atomic properties. */
  164. unsigned atomic:1;
  165. /**
  166. * @aspect_ratio_allowed:
  167. *
  168. * True, if client can handle picture aspect ratios, and has requested
  169. * to pass this information along with the mode.
  170. */
  171. unsigned aspect_ratio_allowed:1;
  172. /**
  173. * @writeback_connectors:
  174. *
  175. * True if client understands writeback connectors
  176. */
  177. unsigned writeback_connectors:1;
  178. /**
  179. * @is_master:
  180. *
  181. * This client is the creator of @master. Protected by struct
  182. * &drm_device.master_mutex.
  183. *
  184. * See also the :ref:`section on primary nodes and authentication
  185. * <drm_primary_node>`.
  186. */
  187. unsigned is_master:1;
  188. /**
  189. * @master:
  190. *
  191. * Master this node is currently associated with. Only relevant if
  192. * drm_is_primary_client() returns true. Note that this only
  193. * matches &drm_device.master if the master is the currently active one.
  194. *
  195. * See also @authentication and @is_master and the :ref:`section on
  196. * primary nodes and authentication <drm_primary_node>`.
  197. */
  198. struct drm_master *master;
  199. /** @pid: Process that opened this file. */
  200. struct pid *pid;
  201. /** @magic: Authentication magic, see @authenticated. */
  202. drm_magic_t magic;
  203. /**
  204. * @lhead:
  205. *
  206. * List of all open files of a DRM device, linked into
  207. * &drm_device.filelist. Protected by &drm_device.filelist_mutex.
  208. */
  209. struct list_head lhead;
  210. /** @minor: &struct drm_minor for this file. */
  211. struct drm_minor *minor;
  212. /**
  213. * @object_idr:
  214. *
  215. * Mapping of mm object handles to object pointers. Used by the GEM
  216. * subsystem. Protected by @table_lock.
  217. */
  218. struct idr object_idr;
  219. /** @table_lock: Protects @object_idr. */
  220. spinlock_t table_lock;
  221. /** @syncobj_idr: Mapping of sync object handles to object pointers. */
  222. struct idr syncobj_idr;
  223. /** @syncobj_table_lock: Protects @syncobj_idr. */
  224. spinlock_t syncobj_table_lock;
  225. /** @filp: Pointer to the core file structure. */
  226. struct file *filp;
  227. /**
  228. * @driver_priv:
  229. *
  230. * Optional pointer for driver private data. Can be allocated in
  231. * &drm_driver.open and should be freed in &drm_driver.postclose.
  232. */
  233. void *driver_priv;
  234. /**
  235. * @fbs:
  236. *
  237. * List of &struct drm_framebuffer associated with this file, using the
  238. * &drm_framebuffer.filp_head entry.
  239. *
  240. * Protected by @fbs_lock. Note that the @fbs list holds a reference on
  241. * the framebuffer object to prevent it from untimely disappearing.
  242. */
  243. struct list_head fbs;
  244. /** @fbs_lock: Protects @fbs. */
  245. struct mutex fbs_lock;
  246. /**
  247. * @blobs:
  248. *
  249. * User-created blob properties; this retains a reference on the
  250. * property.
  251. *
  252. * Protected by @drm_mode_config.blob_lock;
  253. */
  254. struct list_head blobs;
  255. /** @event_wait: Waitqueue for new events added to @event_list. */
  256. wait_queue_head_t event_wait;
  257. /**
  258. * @pending_event_list:
  259. *
  260. * List of pending &struct drm_pending_event, used to clean up pending
  261. * events in case this file gets closed before the event is signalled.
  262. * Uses the &drm_pending_event.pending_link entry.
  263. *
  264. * Protect by &drm_device.event_lock.
  265. */
  266. struct list_head pending_event_list;
  267. /**
  268. * @event_list:
  269. *
  270. * List of &struct drm_pending_event, ready for delivery to userspace
  271. * through drm_read(). Uses the &drm_pending_event.link entry.
  272. *
  273. * Protect by &drm_device.event_lock.
  274. */
  275. struct list_head event_list;
  276. /**
  277. * @event_space:
  278. *
  279. * Available event space to prevent userspace from
  280. * exhausting kernel memory. Currently limited to the fairly arbitrary
  281. * value of 4KB.
  282. */
  283. int event_space;
  284. /** @event_read_lock: Serializes drm_read(). */
  285. struct mutex event_read_lock;
  286. /**
  287. * @prime:
  288. *
  289. * Per-file buffer caches used by the PRIME buffer sharing code.
  290. */
  291. struct drm_prime_file_private prime;
  292. /* private: */
  293. unsigned long lock_count; /* DRI1 legacy lock count */
  294. };
  295. /**
  296. * drm_is_primary_client - is this an open file of the primary node
  297. * @file_priv: DRM file
  298. *
  299. * Returns true if this is an open file of the primary node, i.e.
  300. * &drm_file.minor of @file_priv is a primary minor.
  301. *
  302. * See also the :ref:`section on primary nodes and authentication
  303. * <drm_primary_node>`.
  304. */
  305. static inline bool drm_is_primary_client(const struct drm_file *file_priv)
  306. {
  307. return file_priv->minor->type == DRM_MINOR_PRIMARY;
  308. }
  309. /**
  310. * drm_is_render_client - is this an open file of the render node
  311. * @file_priv: DRM file
  312. *
  313. * Returns true if this is an open file of the render node, i.e.
  314. * &drm_file.minor of @file_priv is a render minor.
  315. *
  316. * See also the :ref:`section on render nodes <drm_render_node>`.
  317. */
  318. static inline bool drm_is_render_client(const struct drm_file *file_priv)
  319. {
  320. return file_priv->minor->type == DRM_MINOR_RENDER;
  321. }
  322. int drm_open(struct inode *inode, struct file *filp);
  323. ssize_t drm_read(struct file *filp, char __user *buffer,
  324. size_t count, loff_t *offset);
  325. int drm_release(struct inode *inode, struct file *filp);
  326. __poll_t drm_poll(struct file *filp, struct poll_table_struct *wait);
  327. int drm_event_reserve_init_locked(struct drm_device *dev,
  328. struct drm_file *file_priv,
  329. struct drm_pending_event *p,
  330. struct drm_event *e);
  331. int drm_event_reserve_init(struct drm_device *dev,
  332. struct drm_file *file_priv,
  333. struct drm_pending_event *p,
  334. struct drm_event *e);
  335. void drm_event_cancel_free(struct drm_device *dev,
  336. struct drm_pending_event *p);
  337. void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
  338. void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
  339. #endif /* _DRM_FILE_H_ */