Commit | Line | Data |
---|---|---|
a8f8b1d9 DV |
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 | ||
30 | #ifndef _DRM_FILE_H_ | |
31 | #define _DRM_FILE_H_ | |
32 | ||
33 | #include <linux/types.h> | |
34 | #include <linux/completion.h> | |
39e23674 | 35 | #include <linux/idr.h> |
a8f8b1d9 DV |
36 | |
37 | #include <uapi/drm/drm.h> | |
38 | ||
39 | #include <drm/drm_prime.h> | |
40 | ||
41 | struct dma_fence; | |
42 | struct drm_file; | |
43 | struct drm_device; | |
3ed4351a | 44 | struct device; |
4748aa16 | 45 | struct file; |
a8f8b1d9 DV |
46 | |
47 | /* | |
48 | * FIXME: Not sure we want to have drm_minor here in the end, but to avoid | |
49 | * header include loops we need it here for now. | |
50 | */ | |
b93658f8 | 51 | |
c9ac371d EA |
52 | /* Note that the order of this enum is ABI (it determines |
53 | * /dev/dri/renderD* numbers). | |
2c204f3d OG |
54 | * |
55 | * Setting DRM_MINOR_ACCEL to 32 gives enough space for more drm minors to | |
56 | * be implemented before we hit any future | |
c9ac371d | 57 | */ |
a8f8b1d9 DV |
58 | enum drm_minor_type { |
59 | DRM_MINOR_PRIMARY, | |
c9ac371d | 60 | DRM_MINOR_CONTROL, |
a8f8b1d9 | 61 | DRM_MINOR_RENDER, |
2c204f3d | 62 | DRM_MINOR_ACCEL = 32, |
a8f8b1d9 DV |
63 | }; |
64 | ||
65 | /** | |
b93658f8 DV |
66 | * struct drm_minor - DRM device minor structure |
67 | * | |
68 | * This structure represents a DRM minor number for device nodes in /dev. | |
69 | * Entirely opaque to drivers and should never be inspected directly by drivers. | |
70 | * Drivers instead should only interact with &struct drm_file and of course | |
71 | * &struct drm_device, which is also where driver-private data and resources can | |
72 | * be attached to. | |
a8f8b1d9 DV |
73 | */ |
74 | struct drm_minor { | |
b93658f8 DV |
75 | /* private: */ |
76 | int index; /* Minor device number */ | |
2c204f3d | 77 | int type; /* Control or render or accel */ |
b93658f8 | 78 | struct device *kdev; /* Linux device */ |
a8f8b1d9 DV |
79 | struct drm_device *dev; |
80 | ||
81 | struct dentry *debugfs_root; | |
82 | ||
83 | struct list_head debugfs_list; | |
84 | struct mutex debugfs_lock; /* Protects debugfs_list. */ | |
85 | }; | |
86 | ||
b93658f8 DV |
87 | /** |
88 | * struct drm_pending_event - Event queued up for userspace to read | |
89 | * | |
90 | * This represents a DRM event. Drivers can use this as a generic completion | |
91 | * mechanism, which supports kernel-internal &struct completion, &struct dma_fence | |
92 | * and also the DRM-specific &struct drm_event delivery mechanism. | |
93 | */ | |
a8f8b1d9 | 94 | struct drm_pending_event { |
b93658f8 DV |
95 | /** |
96 | * @completion: | |
97 | * | |
98 | * Optional pointer to a kernel internal completion signalled when | |
99 | * drm_send_event() is called, useful to internally synchronize with | |
100 | * nonblocking operations. | |
101 | */ | |
a8f8b1d9 | 102 | struct completion *completion; |
b93658f8 DV |
103 | |
104 | /** | |
105 | * @completion_release: | |
106 | * | |
107 | * Optional callback currently only used by the atomic modeset helpers | |
108 | * to clean up the reference count for the structure @completion is | |
109 | * stored in. | |
110 | */ | |
a8f8b1d9 | 111 | void (*completion_release)(struct completion *completion); |
b93658f8 DV |
112 | |
113 | /** | |
114 | * @event: | |
115 | * | |
116 | * Pointer to the actual event that should be sent to userspace to be | |
117 | * read using drm_read(). Can be optional, since nowadays events are | |
118 | * also used to signal kernel internal threads with @completion or DMA | |
119 | * transactions using @fence. | |
120 | */ | |
a8f8b1d9 | 121 | struct drm_event *event; |
b93658f8 DV |
122 | |
123 | /** | |
124 | * @fence: | |
125 | * | |
126 | * Optional DMA fence to unblock other hardware transactions which | |
127 | * depend upon the nonblocking DRM operation this event represents. | |
128 | */ | |
a8f8b1d9 | 129 | struct dma_fence *fence; |
b93658f8 DV |
130 | |
131 | /** | |
132 | * @file_priv: | |
133 | * | |
134 | * &struct drm_file where @event should be delivered to. Only set when | |
135 | * @event is set. | |
136 | */ | |
137 | struct drm_file *file_priv; | |
138 | ||
139 | /** | |
140 | * @link: | |
141 | * | |
142 | * Double-linked list to keep track of this event. Can be used by the | |
143 | * driver up to the point when it calls drm_send_event(), after that | |
144 | * this list entry is owned by the core for its own book-keeping. | |
145 | */ | |
a8f8b1d9 | 146 | struct list_head link; |
b93658f8 DV |
147 | |
148 | /** | |
149 | * @pending_link: | |
150 | * | |
151 | * Entry on &drm_file.pending_event_list, to keep track of all pending | |
152 | * events for @file_priv, to allow correct unwinding of them when | |
153 | * userspace closes the file before the event is delivered. | |
154 | */ | |
a8f8b1d9 | 155 | struct list_head pending_link; |
a8f8b1d9 DV |
156 | }; |
157 | ||
b93658f8 DV |
158 | /** |
159 | * struct drm_file - DRM file private data | |
160 | * | |
161 | * This structure tracks DRM state per open file descriptor. | |
162 | */ | |
a8f8b1d9 | 163 | struct drm_file { |
b93658f8 DV |
164 | /** |
165 | * @authenticated: | |
166 | * | |
167 | * Whether the client is allowed to submit rendering, which for legacy | |
168 | * nodes means it must be authenticated. | |
169 | * | |
170 | * See also the :ref:`section on primary nodes and authentication | |
171 | * <drm_primary_node>`. | |
172 | */ | |
078b7de4 | 173 | bool authenticated; |
b93658f8 DV |
174 | |
175 | /** | |
176 | * @stereo_allowed: | |
177 | * | |
178 | * True when the client has asked us to expose stereo 3D mode flags. | |
179 | */ | |
078b7de4 | 180 | bool stereo_allowed; |
b93658f8 DV |
181 | |
182 | /** | |
183 | * @universal_planes: | |
184 | * | |
185 | * True if client understands CRTC primary planes and cursor planes | |
186 | * in the plane list. Automatically set when @atomic is set. | |
a8f8b1d9 | 187 | */ |
078b7de4 | 188 | bool universal_planes; |
b93658f8 DV |
189 | |
190 | /** @atomic: True if client understands atomic properties. */ | |
078b7de4 | 191 | bool atomic; |
b93658f8 | 192 | |
7595bda2 AN |
193 | /** |
194 | * @aspect_ratio_allowed: | |
195 | * | |
196 | * True, if client can handle picture aspect ratios, and has requested | |
197 | * to pass this information along with the mode. | |
198 | */ | |
078b7de4 | 199 | bool aspect_ratio_allowed; |
7595bda2 | 200 | |
d67b6a20 LD |
201 | /** |
202 | * @writeback_connectors: | |
203 | * | |
204 | * True if client understands writeback connectors | |
205 | */ | |
078b7de4 | 206 | bool writeback_connectors; |
d67b6a20 | 207 | |
45bc3d26 EV |
208 | /** |
209 | * @was_master: | |
210 | * | |
211 | * This client has or had, master capability. Protected by struct | |
212 | * &drm_device.master_mutex. | |
213 | * | |
214 | * This is used to ensure that CAP_SYS_ADMIN is not enforced, if the | |
215 | * client is or was master in the past. | |
216 | */ | |
217 | bool was_master; | |
218 | ||
b93658f8 DV |
219 | /** |
220 | * @is_master: | |
221 | * | |
222 | * This client is the creator of @master. Protected by struct | |
223 | * &drm_device.master_mutex. | |
224 | * | |
225 | * See also the :ref:`section on primary nodes and authentication | |
226 | * <drm_primary_node>`. | |
a8f8b1d9 | 227 | */ |
078b7de4 | 228 | bool is_master; |
a8f8b1d9 | 229 | |
b93658f8 DV |
230 | /** |
231 | * @master: | |
232 | * | |
0b0860a3 DCZX |
233 | * Master this node is currently associated with. Protected by struct |
234 | * &drm_device.master_mutex, and serialized by @master_lookup_lock. | |
235 | * | |
236 | * Only relevant if drm_is_primary_client() returns true. Note that | |
237 | * this only matches &drm_device.master if the master is the currently | |
238 | * active one. | |
b93658f8 | 239 | * |
649839d7 DCZX |
240 | * To update @master, both &drm_device.master_mutex and |
241 | * @master_lookup_lock need to be held, therefore holding either of | |
242 | * them is safe and enough for the read side. | |
243 | * | |
56f0729a DCZX |
244 | * When dereferencing this pointer, either hold struct |
245 | * &drm_device.master_mutex for the duration of the pointer's use, or | |
246 | * use drm_file_get_master() if struct &drm_device.master_mutex is not | |
247 | * currently held and there is no other need to hold it. This prevents | |
248 | * @master from being freed during use. | |
249 | * | |
b93658f8 DV |
250 | * See also @authentication and @is_master and the :ref:`section on |
251 | * primary nodes and authentication <drm_primary_node>`. | |
252 | */ | |
253 | struct drm_master *master; | |
254 | ||
35352081 | 255 | /** @master_lookup_lock: Serializes @master. */ |
0b0860a3 DCZX |
256 | spinlock_t master_lookup_lock; |
257 | ||
b93658f8 | 258 | /** @pid: Process that opened this file. */ |
a8f8b1d9 | 259 | struct pid *pid; |
b93658f8 DV |
260 | |
261 | /** @magic: Authentication magic, see @authenticated. */ | |
a8f8b1d9 | 262 | drm_magic_t magic; |
b93658f8 DV |
263 | |
264 | /** | |
265 | * @lhead: | |
266 | * | |
267 | * List of all open files of a DRM device, linked into | |
268 | * &drm_device.filelist. Protected by &drm_device.filelist_mutex. | |
269 | */ | |
a8f8b1d9 | 270 | struct list_head lhead; |
b93658f8 DV |
271 | |
272 | /** @minor: &struct drm_minor for this file. */ | |
a8f8b1d9 | 273 | struct drm_minor *minor; |
a8f8b1d9 | 274 | |
b93658f8 DV |
275 | /** |
276 | * @object_idr: | |
277 | * | |
278 | * Mapping of mm object handles to object pointers. Used by the GEM | |
279 | * subsystem. Protected by @table_lock. | |
280 | */ | |
a8f8b1d9 | 281 | struct idr object_idr; |
b93658f8 DV |
282 | |
283 | /** @table_lock: Protects @object_idr. */ | |
a8f8b1d9 DV |
284 | spinlock_t table_lock; |
285 | ||
e9083420 DA |
286 | /** @syncobj_idr: Mapping of sync object handles to object pointers. */ |
287 | struct idr syncobj_idr; | |
288 | /** @syncobj_table_lock: Protects @syncobj_idr. */ | |
289 | spinlock_t syncobj_table_lock; | |
290 | ||
b93658f8 | 291 | /** @filp: Pointer to the core file structure. */ |
a8f8b1d9 | 292 | struct file *filp; |
b93658f8 DV |
293 | |
294 | /** | |
295 | * @driver_priv: | |
296 | * | |
297 | * Optional pointer for driver private data. Can be allocated in | |
298 | * &drm_driver.open and should be freed in &drm_driver.postclose. | |
299 | */ | |
a8f8b1d9 DV |
300 | void *driver_priv; |
301 | ||
a8f8b1d9 | 302 | /** |
b93658f8 DV |
303 | * @fbs: |
304 | * | |
305 | * List of &struct drm_framebuffer associated with this file, using the | |
306 | * &drm_framebuffer.filp_head entry. | |
a8f8b1d9 | 307 | * |
b93658f8 DV |
308 | * Protected by @fbs_lock. Note that the @fbs list holds a reference on |
309 | * the framebuffer object to prevent it from untimely disappearing. | |
a8f8b1d9 DV |
310 | */ |
311 | struct list_head fbs; | |
b93658f8 DV |
312 | |
313 | /** @fbs_lock: Protects @fbs. */ | |
a8f8b1d9 DV |
314 | struct mutex fbs_lock; |
315 | ||
b93658f8 DV |
316 | /** |
317 | * @blobs: | |
318 | * | |
319 | * User-created blob properties; this retains a reference on the | |
320 | * property. | |
321 | * | |
322 | * Protected by @drm_mode_config.blob_lock; | |
323 | */ | |
a8f8b1d9 DV |
324 | struct list_head blobs; |
325 | ||
b93658f8 | 326 | /** @event_wait: Waitqueue for new events added to @event_list. */ |
a8f8b1d9 | 327 | wait_queue_head_t event_wait; |
b93658f8 DV |
328 | |
329 | /** | |
330 | * @pending_event_list: | |
331 | * | |
332 | * List of pending &struct drm_pending_event, used to clean up pending | |
333 | * events in case this file gets closed before the event is signalled. | |
334 | * Uses the &drm_pending_event.pending_link entry. | |
335 | * | |
336 | * Protect by &drm_device.event_lock. | |
337 | */ | |
a8f8b1d9 | 338 | struct list_head pending_event_list; |
b93658f8 DV |
339 | |
340 | /** | |
341 | * @event_list: | |
342 | * | |
343 | * List of &struct drm_pending_event, ready for delivery to userspace | |
344 | * through drm_read(). Uses the &drm_pending_event.link entry. | |
345 | * | |
346 | * Protect by &drm_device.event_lock. | |
347 | */ | |
a8f8b1d9 | 348 | struct list_head event_list; |
b93658f8 DV |
349 | |
350 | /** | |
351 | * @event_space: | |
352 | * | |
353 | * Available event space to prevent userspace from | |
354 | * exhausting kernel memory. Currently limited to the fairly arbitrary | |
355 | * value of 4KB. | |
356 | */ | |
a8f8b1d9 DV |
357 | int event_space; |
358 | ||
b93658f8 | 359 | /** @event_read_lock: Serializes drm_read(). */ |
a8f8b1d9 DV |
360 | struct mutex event_read_lock; |
361 | ||
b93658f8 DV |
362 | /** |
363 | * @prime: | |
364 | * | |
365 | * Per-file buffer caches used by the PRIME buffer sharing code. | |
366 | */ | |
a8f8b1d9 | 367 | struct drm_prime_file_private prime; |
b93658f8 DV |
368 | |
369 | /* private: */ | |
ee22f763 | 370 | #if IS_ENABLED(CONFIG_DRM_LEGACY) |
b93658f8 | 371 | unsigned long lock_count; /* DRI1 legacy lock count */ |
ee22f763 | 372 | #endif |
a8f8b1d9 DV |
373 | }; |
374 | ||
b93658f8 DV |
375 | /** |
376 | * drm_is_primary_client - is this an open file of the primary node | |
377 | * @file_priv: DRM file | |
378 | * | |
379 | * Returns true if this is an open file of the primary node, i.e. | |
380 | * &drm_file.minor of @file_priv is a primary minor. | |
381 | * | |
382 | * See also the :ref:`section on primary nodes and authentication | |
383 | * <drm_primary_node>`. | |
384 | */ | |
385 | static inline bool drm_is_primary_client(const struct drm_file *file_priv) | |
386 | { | |
387 | return file_priv->minor->type == DRM_MINOR_PRIMARY; | |
388 | } | |
389 | ||
390 | /** | |
391 | * drm_is_render_client - is this an open file of the render node | |
392 | * @file_priv: DRM file | |
393 | * | |
394 | * Returns true if this is an open file of the render node, i.e. | |
395 | * &drm_file.minor of @file_priv is a render minor. | |
396 | * | |
397 | * See also the :ref:`section on render nodes <drm_render_node>`. | |
398 | */ | |
a8f8b1d9 DV |
399 | static inline bool drm_is_render_client(const struct drm_file *file_priv) |
400 | { | |
401 | return file_priv->minor->type == DRM_MINOR_RENDER; | |
402 | } | |
403 | ||
2c204f3d OG |
404 | /** |
405 | * drm_is_accel_client - is this an open file of the compute acceleration node | |
406 | * @file_priv: DRM file | |
407 | * | |
408 | * Returns true if this is an open file of the compute acceleration node, i.e. | |
409 | * &drm_file.minor of @file_priv is a accel minor. | |
410 | * | |
6d179f84 BS |
411 | * See also :doc:`Introduction to compute accelerators subsystem |
412 | * </accel/introduction>`. | |
2c204f3d OG |
413 | */ |
414 | static inline bool drm_is_accel_client(const struct drm_file *file_priv) | |
415 | { | |
416 | return file_priv->minor->type == DRM_MINOR_ACCEL; | |
417 | } | |
418 | ||
a8f8b1d9 | 419 | int drm_open(struct inode *inode, struct file *filp); |
2c204f3d | 420 | int drm_open_helper(struct file *filp, struct drm_minor *minor); |
a8f8b1d9 DV |
421 | ssize_t drm_read(struct file *filp, char __user *buffer, |
422 | size_t count, loff_t *offset); | |
423 | int drm_release(struct inode *inode, struct file *filp); | |
7a2c65dd | 424 | int drm_release_noglobal(struct inode *inode, struct file *filp); |
afc9a42b | 425 | __poll_t drm_poll(struct file *filp, struct poll_table_struct *wait); |
a8f8b1d9 DV |
426 | int drm_event_reserve_init_locked(struct drm_device *dev, |
427 | struct drm_file *file_priv, | |
428 | struct drm_pending_event *p, | |
429 | struct drm_event *e); | |
430 | int drm_event_reserve_init(struct drm_device *dev, | |
431 | struct drm_file *file_priv, | |
432 | struct drm_pending_event *p, | |
433 | struct drm_event *e); | |
434 | void drm_event_cancel_free(struct drm_device *dev, | |
435 | struct drm_pending_event *p); | |
436 | void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e); | |
437 | void drm_send_event(struct drm_device *dev, struct drm_pending_event *e); | |
a78e7a51 VSS |
438 | void drm_send_event_timestamp_locked(struct drm_device *dev, |
439 | struct drm_pending_event *e, | |
440 | ktime_t timestamp); | |
a8f8b1d9 | 441 | |
4748aa16 CW |
442 | struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags); |
443 | ||
a8f8b1d9 | 444 | #endif /* _DRM_FILE_H_ */ |