drm_file.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. * @is_master:
  174. *
  175. * This client is the creator of @master. Protected by struct
  176. * &drm_device.master_mutex.
  177. *
  178. * See also the :ref:`section on primary nodes and authentication
  179. * <drm_primary_node>`.
  180. */
  181. unsigned is_master:1;
  182. /**
  183. * @master:
  184. *
  185. * Master this node is currently associated with. Only relevant if
  186. * drm_is_primary_client() returns true. Note that this only
  187. * matches &drm_device.master if the master is the currently active one.
  188. *
  189. * See also @authentication and @is_master and the :ref:`section on
  190. * primary nodes and authentication <drm_primary_node>`.
  191. */
  192. struct drm_master *master;
  193. /** @pid: Process that opened this file. */
  194. struct pid *pid;
  195. /** @magic: Authentication magic, see @authenticated. */
  196. drm_magic_t magic;
  197. /**
  198. * @lhead:
  199. *
  200. * List of all open files of a DRM device, linked into
  201. * &drm_device.filelist. Protected by &drm_device.filelist_mutex.
  202. */
  203. struct list_head lhead;
  204. /** @minor: &struct drm_minor for this file. */
  205. struct drm_minor *minor;
  206. /**
  207. * @object_idr:
  208. *
  209. * Mapping of mm object handles to object pointers. Used by the GEM
  210. * subsystem. Protected by @table_lock.
  211. */
  212. struct idr object_idr;
  213. /** @table_lock: Protects @object_idr. */
  214. spinlock_t table_lock;
  215. /** @syncobj_idr: Mapping of sync object handles to object pointers. */
  216. struct idr syncobj_idr;
  217. /** @syncobj_table_lock: Protects @syncobj_idr. */
  218. spinlock_t syncobj_table_lock;
  219. /** @filp: Pointer to the core file structure. */
  220. struct file *filp;
  221. /**
  222. * @driver_priv:
  223. *
  224. * Optional pointer for driver private data. Can be allocated in
  225. * &drm_driver.open and should be freed in &drm_driver.postclose.
  226. */
  227. void *driver_priv;
  228. /**
  229. * @fbs:
  230. *
  231. * List of &struct drm_framebuffer associated with this file, using the
  232. * &drm_framebuffer.filp_head entry.
  233. *
  234. * Protected by @fbs_lock. Note that the @fbs list holds a reference on
  235. * the framebuffer object to prevent it from untimely disappearing.
  236. */
  237. struct list_head fbs;
  238. /** @fbs_lock: Protects @fbs. */
  239. struct mutex fbs_lock;
  240. /**
  241. * @blobs:
  242. *
  243. * User-created blob properties; this retains a reference on the
  244. * property.
  245. *
  246. * Protected by @drm_mode_config.blob_lock;
  247. */
  248. struct list_head blobs;
  249. /** @event_wait: Waitqueue for new events added to @event_list. */
  250. wait_queue_head_t event_wait;
  251. /**
  252. * @pending_event_list:
  253. *
  254. * List of pending &struct drm_pending_event, used to clean up pending
  255. * events in case this file gets closed before the event is signalled.
  256. * Uses the &drm_pending_event.pending_link entry.
  257. *
  258. * Protect by &drm_device.event_lock.
  259. */
  260. struct list_head pending_event_list;
  261. /**
  262. * @event_list:
  263. *
  264. * List of &struct drm_pending_event, ready for delivery to userspace
  265. * through drm_read(). Uses the &drm_pending_event.link entry.
  266. *
  267. * Protect by &drm_device.event_lock.
  268. */
  269. struct list_head event_list;
  270. /**
  271. * @event_space:
  272. *
  273. * Available event space to prevent userspace from
  274. * exhausting kernel memory. Currently limited to the fairly arbitrary
  275. * value of 4KB.
  276. */
  277. int event_space;
  278. /** @event_read_lock: Serializes drm_read(). */
  279. struct mutex event_read_lock;
  280. /**
  281. * @prime:
  282. *
  283. * Per-file buffer caches used by the PRIME buffer sharing code.
  284. */
  285. struct drm_prime_file_private prime;
  286. /* private: */
  287. unsigned long lock_count; /* DRI1 legacy lock count */
  288. };
  289. /**
  290. * drm_is_primary_client - is this an open file of the primary node
  291. * @file_priv: DRM file
  292. *
  293. * Returns true if this is an open file of the primary node, i.e.
  294. * &drm_file.minor of @file_priv is a primary minor.
  295. *
  296. * See also the :ref:`section on primary nodes and authentication
  297. * <drm_primary_node>`.
  298. */
  299. static inline bool drm_is_primary_client(const struct drm_file *file_priv)
  300. {
  301. return file_priv->minor->type == DRM_MINOR_PRIMARY;
  302. }
  303. /**
  304. * drm_is_render_client - is this an open file of the render node
  305. * @file_priv: DRM file
  306. *
  307. * Returns true if this is an open file of the render node, i.e.
  308. * &drm_file.minor of @file_priv is a render minor.
  309. *
  310. * See also the :ref:`section on render nodes <drm_render_node>`.
  311. */
  312. static inline bool drm_is_render_client(const struct drm_file *file_priv)
  313. {
  314. return file_priv->minor->type == DRM_MINOR_RENDER;
  315. }
  316. int drm_open(struct inode *inode, struct file *filp);
  317. ssize_t drm_read(struct file *filp, char __user *buffer,
  318. size_t count, loff_t *offset);
  319. int drm_release(struct inode *inode, struct file *filp);
  320. __poll_t drm_poll(struct file *filp, struct poll_table_struct *wait);
  321. int drm_event_reserve_init_locked(struct drm_device *dev,
  322. struct drm_file *file_priv,
  323. struct drm_pending_event *p,
  324. struct drm_event *e);
  325. int drm_event_reserve_init(struct drm_device *dev,
  326. struct drm_file *file_priv,
  327. struct drm_pending_event *p,
  328. struct drm_event *e);
  329. void drm_event_cancel_free(struct drm_device *dev,
  330. struct drm_pending_event *p);
  331. void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
  332. void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
  333. #endif /* _DRM_FILE_H_ */