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.
7 * Author: Rickard E. (Rik) Faith <faith@valinux.com>
8 * Author: Gareth Hughes <gareth@valinux.com>
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:
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
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.
33 #include <linux/types.h>
34 #include <linux/completion.h>
35 #include <linux/idr.h>
37 #include <uapi/drm/drm.h>
39 #include <drm/drm_prime.h>
49 * FIXME: Not sure we want to have drm_minor here in the end, but to avoid
50 * header include loops we need it here for now.
53 /* Note that the values of this enum are ABI (it determines
54 * /dev/dri/renderD* numbers).
56 * Setting DRM_MINOR_ACCEL to 32 gives enough space for more drm minors to
57 * be implemented before we hit any future
60 DRM_MINOR_PRIMARY = 0,
61 DRM_MINOR_CONTROL = 1,
67 * struct drm_minor - DRM device minor structure
69 * This structure represents a DRM minor number for device nodes in /dev.
70 * Entirely opaque to drivers and should never be inspected directly by drivers.
71 * Drivers instead should only interact with &struct drm_file and of course
72 * &struct drm_device, which is also where driver-private data and resources can
77 int index; /* Minor device number */
78 int type; /* Control or render or accel */
79 struct device *kdev; /* Linux device */
80 struct drm_device *dev;
82 struct dentry *debugfs_root;
84 struct list_head debugfs_list;
85 struct mutex debugfs_lock; /* Protects debugfs_list. */
89 * struct drm_pending_event - Event queued up for userspace to read
91 * This represents a DRM event. Drivers can use this as a generic completion
92 * mechanism, which supports kernel-internal &struct completion, &struct dma_fence
93 * and also the DRM-specific &struct drm_event delivery mechanism.
95 struct drm_pending_event {
99 * Optional pointer to a kernel internal completion signalled when
100 * drm_send_event() is called, useful to internally synchronize with
101 * nonblocking operations.
103 struct completion *completion;
106 * @completion_release:
108 * Optional callback currently only used by the atomic modeset helpers
109 * to clean up the reference count for the structure @completion is
112 void (*completion_release)(struct completion *completion);
117 * Pointer to the actual event that should be sent to userspace to be
118 * read using drm_read(). Can be optional, since nowadays events are
119 * also used to signal kernel internal threads with @completion or DMA
120 * transactions using @fence.
122 struct drm_event *event;
127 * Optional DMA fence to unblock other hardware transactions which
128 * depend upon the nonblocking DRM operation this event represents.
130 struct dma_fence *fence;
135 * &struct drm_file where @event should be delivered to. Only set when
138 struct drm_file *file_priv;
143 * Double-linked list to keep track of this event. Can be used by the
144 * driver up to the point when it calls drm_send_event(), after that
145 * this list entry is owned by the core for its own book-keeping.
147 struct list_head link;
152 * Entry on &drm_file.pending_event_list, to keep track of all pending
153 * events for @file_priv, to allow correct unwinding of them when
154 * userspace closes the file before the event is delivered.
156 struct list_head pending_link;
160 * struct drm_file - DRM file private data
162 * This structure tracks DRM state per open file descriptor.
168 * Whether the client is allowed to submit rendering, which for legacy
169 * nodes means it must be authenticated.
171 * See also the :ref:`section on primary nodes and authentication
172 * <drm_primary_node>`.
179 * True when the client has asked us to expose stereo 3D mode flags.
186 * True if client understands CRTC primary planes and cursor planes
187 * in the plane list. Automatically set when @atomic is set.
189 bool universal_planes;
191 /** @atomic: True if client understands atomic properties. */
195 * @aspect_ratio_allowed:
197 * True, if client can handle picture aspect ratios, and has requested
198 * to pass this information along with the mode.
200 bool aspect_ratio_allowed;
203 * @writeback_connectors:
205 * True if client understands writeback connectors
207 bool writeback_connectors;
212 * This client has or had, master capability. Protected by struct
213 * &drm_device.master_mutex.
215 * This is used to ensure that CAP_SYS_ADMIN is not enforced, if the
216 * client is or was master in the past.
223 * This client is the creator of @master. Protected by struct
224 * &drm_device.master_mutex.
226 * See also the :ref:`section on primary nodes and authentication
227 * <drm_primary_node>`.
232 * @supports_virtualized_cursor_plane:
234 * This client is capable of handling the cursor plane with the
235 * restrictions imposed on it by the virtualized drivers.
237 * This implies that the cursor plane has to behave like a cursor
238 * i.e. track cursor movement. It also requires setting of the
239 * hotspot properties by the client on the cursor plane.
241 bool supports_virtualized_cursor_plane;
246 * Master this node is currently associated with. Protected by struct
247 * &drm_device.master_mutex, and serialized by @master_lookup_lock.
249 * Only relevant if drm_is_primary_client() returns true. Note that
250 * this only matches &drm_device.master if the master is the currently
253 * To update @master, both &drm_device.master_mutex and
254 * @master_lookup_lock need to be held, therefore holding either of
255 * them is safe and enough for the read side.
257 * When dereferencing this pointer, either hold struct
258 * &drm_device.master_mutex for the duration of the pointer's use, or
259 * use drm_file_get_master() if struct &drm_device.master_mutex is not
260 * currently held and there is no other need to hold it. This prevents
261 * @master from being freed during use.
263 * See also @authentication and @is_master and the :ref:`section on
264 * primary nodes and authentication <drm_primary_node>`.
266 struct drm_master *master;
268 /** @master_lookup_lock: Serializes @master. */
269 spinlock_t master_lookup_lock;
272 * @pid: Process that is using this file.
274 * Must only be dereferenced under a rcu_read_lock or equivalent.
276 * Updates are guarded with dev->filelist_mutex and reference must be
277 * dropped after a RCU grace period to accommodate lockless readers.
279 struct pid __rcu *pid;
281 /** @client_id: A unique id for fdinfo */
284 /** @magic: Authentication magic, see @authenticated. */
290 * List of all open files of a DRM device, linked into
291 * &drm_device.filelist. Protected by &drm_device.filelist_mutex.
293 struct list_head lhead;
295 /** @minor: &struct drm_minor for this file. */
296 struct drm_minor *minor;
301 * Mapping of mm object handles to object pointers. Used by the GEM
302 * subsystem. Protected by @table_lock.
304 struct idr object_idr;
306 /** @table_lock: Protects @object_idr. */
307 spinlock_t table_lock;
309 /** @syncobj_idr: Mapping of sync object handles to object pointers. */
310 struct idr syncobj_idr;
311 /** @syncobj_table_lock: Protects @syncobj_idr. */
312 spinlock_t syncobj_table_lock;
314 /** @filp: Pointer to the core file structure. */
320 * Optional pointer for driver private data. Can be allocated in
321 * &drm_driver.open and should be freed in &drm_driver.postclose.
328 * List of &struct drm_framebuffer associated with this file, using the
329 * &drm_framebuffer.filp_head entry.
331 * Protected by @fbs_lock. Note that the @fbs list holds a reference on
332 * the framebuffer object to prevent it from untimely disappearing.
334 struct list_head fbs;
336 /** @fbs_lock: Protects @fbs. */
337 struct mutex fbs_lock;
342 * User-created blob properties; this retains a reference on the
345 * Protected by @drm_mode_config.blob_lock;
347 struct list_head blobs;
349 /** @event_wait: Waitqueue for new events added to @event_list. */
350 wait_queue_head_t event_wait;
353 * @pending_event_list:
355 * List of pending &struct drm_pending_event, used to clean up pending
356 * events in case this file gets closed before the event is signalled.
357 * Uses the &drm_pending_event.pending_link entry.
359 * Protect by &drm_device.event_lock.
361 struct list_head pending_event_list;
366 * List of &struct drm_pending_event, ready for delivery to userspace
367 * through drm_read(). Uses the &drm_pending_event.link entry.
369 * Protect by &drm_device.event_lock.
371 struct list_head event_list;
376 * Available event space to prevent userspace from
377 * exhausting kernel memory. Currently limited to the fairly arbitrary
382 /** @event_read_lock: Serializes drm_read(). */
383 struct mutex event_read_lock;
388 * Per-file buffer caches used by the PRIME buffer sharing code.
390 struct drm_prime_file_private prime;
393 #if IS_ENABLED(CONFIG_DRM_LEGACY)
394 unsigned long lock_count; /* DRI1 legacy lock count */
399 * drm_is_primary_client - is this an open file of the primary node
400 * @file_priv: DRM file
402 * Returns true if this is an open file of the primary node, i.e.
403 * &drm_file.minor of @file_priv is a primary minor.
405 * See also the :ref:`section on primary nodes and authentication
406 * <drm_primary_node>`.
408 static inline bool drm_is_primary_client(const struct drm_file *file_priv)
410 return file_priv->minor->type == DRM_MINOR_PRIMARY;
414 * drm_is_render_client - is this an open file of the render node
415 * @file_priv: DRM file
417 * Returns true if this is an open file of the render node, i.e.
418 * &drm_file.minor of @file_priv is a render minor.
420 * See also the :ref:`section on render nodes <drm_render_node>`.
422 static inline bool drm_is_render_client(const struct drm_file *file_priv)
424 return file_priv->minor->type == DRM_MINOR_RENDER;
428 * drm_is_accel_client - is this an open file of the compute acceleration node
429 * @file_priv: DRM file
431 * Returns true if this is an open file of the compute acceleration node, i.e.
432 * &drm_file.minor of @file_priv is a accel minor.
434 * See also :doc:`Introduction to compute accelerators subsystem
435 * </accel/introduction>`.
437 static inline bool drm_is_accel_client(const struct drm_file *file_priv)
439 return file_priv->minor->type == DRM_MINOR_ACCEL;
442 void drm_file_update_pid(struct drm_file *);
444 int drm_open(struct inode *inode, struct file *filp);
445 int drm_open_helper(struct file *filp, struct drm_minor *minor);
446 ssize_t drm_read(struct file *filp, char __user *buffer,
447 size_t count, loff_t *offset);
448 int drm_release(struct inode *inode, struct file *filp);
449 int drm_release_noglobal(struct inode *inode, struct file *filp);
450 __poll_t drm_poll(struct file *filp, struct poll_table_struct *wait);
451 int drm_event_reserve_init_locked(struct drm_device *dev,
452 struct drm_file *file_priv,
453 struct drm_pending_event *p,
454 struct drm_event *e);
455 int drm_event_reserve_init(struct drm_device *dev,
456 struct drm_file *file_priv,
457 struct drm_pending_event *p,
458 struct drm_event *e);
459 void drm_event_cancel_free(struct drm_device *dev,
460 struct drm_pending_event *p);
461 void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
462 void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
463 void drm_send_event_timestamp_locked(struct drm_device *dev,
464 struct drm_pending_event *e,
468 * struct drm_memory_stats - GEM object stats associated
469 * @shared: Total size of GEM objects shared between processes
470 * @private: Total size of GEM objects
471 * @resident: Total size of GEM objects backing pages
472 * @purgeable: Total size of GEM objects that can be purged (resident and not active)
473 * @active: Total size of GEM objects active on one or more engines
475 * Used by drm_print_memory_stats()
477 struct drm_memory_stats {
485 enum drm_gem_object_status;
487 void drm_print_memory_stats(struct drm_printer *p,
488 const struct drm_memory_stats *stats,
489 enum drm_gem_object_status supported_status,
492 void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file);
493 void drm_show_fdinfo(struct seq_file *m, struct file *f);
495 struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);
497 #endif /* _DRM_FILE_H_ */