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>
36 #include <uapi/drm/drm.h>
38 #include <drm/drm_prime.h>
46 * FIXME: Not sure we want to have drm_minor here in the end, but to avoid
47 * header include loops we need it here for now.
50 /* Note that the order of this enum is ABI (it determines
51 * /dev/dri/renderD* numbers).
60 * struct drm_minor - DRM device minor structure
62 * This structure represents a DRM minor number for device nodes in /dev.
63 * Entirely opaque to drivers and should never be inspected directly by drivers.
64 * Drivers instead should only interact with &struct drm_file and of course
65 * &struct drm_device, which is also where driver-private data and resources can
70 int index; /* Minor device number */
71 int type; /* Control or render */
72 struct device *kdev; /* Linux device */
73 struct drm_device *dev;
75 struct dentry *debugfs_root;
77 struct list_head debugfs_list;
78 struct mutex debugfs_lock; /* Protects debugfs_list. */
82 * struct drm_pending_event - Event queued up for userspace to read
84 * This represents a DRM event. Drivers can use this as a generic completion
85 * mechanism, which supports kernel-internal &struct completion, &struct dma_fence
86 * and also the DRM-specific &struct drm_event delivery mechanism.
88 struct drm_pending_event {
92 * Optional pointer to a kernel internal completion signalled when
93 * drm_send_event() is called, useful to internally synchronize with
94 * nonblocking operations.
96 struct completion *completion;
99 * @completion_release:
101 * Optional callback currently only used by the atomic modeset helpers
102 * to clean up the reference count for the structure @completion is
105 void (*completion_release)(struct completion *completion);
110 * Pointer to the actual event that should be sent to userspace to be
111 * read using drm_read(). Can be optional, since nowadays events are
112 * also used to signal kernel internal threads with @completion or DMA
113 * transactions using @fence.
115 struct drm_event *event;
120 * Optional DMA fence to unblock other hardware transactions which
121 * depend upon the nonblocking DRM operation this event represents.
123 struct dma_fence *fence;
128 * &struct drm_file where @event should be delivered to. Only set when
131 struct drm_file *file_priv;
136 * Double-linked list to keep track of this event. Can be used by the
137 * driver up to the point when it calls drm_send_event(), after that
138 * this list entry is owned by the core for its own book-keeping.
140 struct list_head link;
145 * Entry on &drm_file.pending_event_list, to keep track of all pending
146 * events for @file_priv, to allow correct unwinding of them when
147 * userspace closes the file before the event is delivered.
149 struct list_head pending_link;
153 * struct drm_file - DRM file private data
155 * This structure tracks DRM state per open file descriptor.
161 * Whether the client is allowed to submit rendering, which for legacy
162 * nodes means it must be authenticated.
164 * See also the :ref:`section on primary nodes and authentication
165 * <drm_primary_node>`.
167 unsigned authenticated :1;
172 * True when the client has asked us to expose stereo 3D mode flags.
174 unsigned stereo_allowed :1;
179 * True if client understands CRTC primary planes and cursor planes
180 * in the plane list. Automatically set when @atomic is set.
182 unsigned universal_planes:1;
184 /** @atomic: True if client understands atomic properties. */
188 * @aspect_ratio_allowed:
190 * True, if client can handle picture aspect ratios, and has requested
191 * to pass this information along with the mode.
193 unsigned aspect_ratio_allowed:1;
198 * This client is the creator of @master. Protected by struct
199 * &drm_device.master_mutex.
201 * See also the :ref:`section on primary nodes and authentication
202 * <drm_primary_node>`.
204 unsigned is_master:1;
209 * Master this node is currently associated with. Only relevant if
210 * drm_is_primary_client() returns true. Note that this only
211 * matches &drm_device.master if the master is the currently active one.
213 * See also @authentication and @is_master and the :ref:`section on
214 * primary nodes and authentication <drm_primary_node>`.
216 struct drm_master *master;
218 /** @pid: Process that opened this file. */
221 /** @magic: Authentication magic, see @authenticated. */
227 * List of all open files of a DRM device, linked into
228 * &drm_device.filelist. Protected by &drm_device.filelist_mutex.
230 struct list_head lhead;
232 /** @minor: &struct drm_minor for this file. */
233 struct drm_minor *minor;
238 * Mapping of mm object handles to object pointers. Used by the GEM
239 * subsystem. Protected by @table_lock.
241 struct idr object_idr;
243 /** @table_lock: Protects @object_idr. */
244 spinlock_t table_lock;
246 /** @syncobj_idr: Mapping of sync object handles to object pointers. */
247 struct idr syncobj_idr;
248 /** @syncobj_table_lock: Protects @syncobj_idr. */
249 spinlock_t syncobj_table_lock;
251 /** @filp: Pointer to the core file structure. */
257 * Optional pointer for driver private data. Can be allocated in
258 * &drm_driver.open and should be freed in &drm_driver.postclose.
265 * List of &struct drm_framebuffer associated with this file, using the
266 * &drm_framebuffer.filp_head entry.
268 * Protected by @fbs_lock. Note that the @fbs list holds a reference on
269 * the framebuffer object to prevent it from untimely disappearing.
271 struct list_head fbs;
273 /** @fbs_lock: Protects @fbs. */
274 struct mutex fbs_lock;
279 * User-created blob properties; this retains a reference on the
282 * Protected by @drm_mode_config.blob_lock;
284 struct list_head blobs;
286 /** @event_wait: Waitqueue for new events added to @event_list. */
287 wait_queue_head_t event_wait;
290 * @pending_event_list:
292 * List of pending &struct drm_pending_event, used to clean up pending
293 * events in case this file gets closed before the event is signalled.
294 * Uses the &drm_pending_event.pending_link entry.
296 * Protect by &drm_device.event_lock.
298 struct list_head pending_event_list;
303 * List of &struct drm_pending_event, ready for delivery to userspace
304 * through drm_read(). Uses the &drm_pending_event.link entry.
306 * Protect by &drm_device.event_lock.
308 struct list_head event_list;
313 * Available event space to prevent userspace from
314 * exhausting kernel memory. Currently limited to the fairly arbitrary
319 /** @event_read_lock: Serializes drm_read(). */
320 struct mutex event_read_lock;
325 * Per-file buffer caches used by the PRIME buffer sharing code.
327 struct drm_prime_file_private prime;
330 unsigned long lock_count; /* DRI1 legacy lock count */
334 * drm_is_primary_client - is this an open file of the primary node
335 * @file_priv: DRM file
337 * Returns true if this is an open file of the primary node, i.e.
338 * &drm_file.minor of @file_priv is a primary minor.
340 * See also the :ref:`section on primary nodes and authentication
341 * <drm_primary_node>`.
343 static inline bool drm_is_primary_client(const struct drm_file *file_priv)
345 return file_priv->minor->type == DRM_MINOR_PRIMARY;
349 * drm_is_render_client - is this an open file of the render node
350 * @file_priv: DRM file
352 * Returns true if this is an open file of the render node, i.e.
353 * &drm_file.minor of @file_priv is a render minor.
355 * See also the :ref:`section on render nodes <drm_render_node>`.
357 static inline bool drm_is_render_client(const struct drm_file *file_priv)
359 return file_priv->minor->type == DRM_MINOR_RENDER;
362 int drm_open(struct inode *inode, struct file *filp);
363 ssize_t drm_read(struct file *filp, char __user *buffer,
364 size_t count, loff_t *offset);
365 int drm_release(struct inode *inode, struct file *filp);
366 __poll_t drm_poll(struct file *filp, struct poll_table_struct *wait);
367 int drm_event_reserve_init_locked(struct drm_device *dev,
368 struct drm_file *file_priv,
369 struct drm_pending_event *p,
370 struct drm_event *e);
371 int drm_event_reserve_init(struct drm_device *dev,
372 struct drm_file *file_priv,
373 struct drm_pending_event *p,
374 struct drm_event *e);
375 void drm_event_cancel_free(struct drm_device *dev,
376 struct drm_pending_event *p);
377 void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
378 void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
380 #endif /* _DRM_FILE_H_ */