drm_file.h 10 KB

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