drm_file.h 11 KB

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