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>
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.
52 /* Note that the order of this enum is ABI (it determines
53 * /dev/dri/renderD* numbers).
62 * struct drm_minor - DRM device minor structure
64 * This structure represents a DRM minor number for device nodes in /dev.
65 * Entirely opaque to drivers and should never be inspected directly by drivers.
66 * Drivers instead should only interact with &struct drm_file and of course
67 * &struct drm_device, which is also where driver-private data and resources can
72 int index
; /* Minor device number */
73 int type
; /* Control or render */
74 struct device
*kdev
; /* Linux device */
75 struct drm_device
*dev
;
77 struct dentry
*debugfs_root
;
79 struct list_head debugfs_list
;
80 struct mutex debugfs_lock
; /* Protects debugfs_list. */
84 * struct drm_pending_event - Event queued up for userspace to read
86 * This represents a DRM event. Drivers can use this as a generic completion
87 * mechanism, which supports kernel-internal &struct completion, &struct dma_fence
88 * and also the DRM-specific &struct drm_event delivery mechanism.
90 struct drm_pending_event
{
94 * Optional pointer to a kernel internal completion signalled when
95 * drm_send_event() is called, useful to internally synchronize with
96 * nonblocking operations.
98 struct completion
*completion
;
101 * @completion_release:
103 * Optional callback currently only used by the atomic modeset helpers
104 * to clean up the reference count for the structure @completion is
107 void (*completion_release
)(struct completion
*completion
);
112 * Pointer to the actual event that should be sent to userspace to be
113 * read using drm_read(). Can be optional, since nowadays events are
114 * also used to signal kernel internal threads with @completion or DMA
115 * transactions using @fence.
117 struct drm_event
*event
;
122 * Optional DMA fence to unblock other hardware transactions which
123 * depend upon the nonblocking DRM operation this event represents.
125 struct dma_fence
*fence
;
130 * &struct drm_file where @event should be delivered to. Only set when
133 struct drm_file
*file_priv
;
138 * Double-linked list to keep track of this event. Can be used by the
139 * driver up to the point when it calls drm_send_event(), after that
140 * this list entry is owned by the core for its own book-keeping.
142 struct list_head link
;
147 * Entry on &drm_file.pending_event_list, to keep track of all pending
148 * events for @file_priv, to allow correct unwinding of them when
149 * userspace closes the file before the event is delivered.
151 struct list_head pending_link
;
155 * struct drm_file - DRM file private data
157 * This structure tracks DRM state per open file descriptor.
163 * Whether the client is allowed to submit rendering, which for legacy
164 * nodes means it must be authenticated.
166 * See also the :ref:`section on primary nodes and authentication
167 * <drm_primary_node>`.
174 * True when the client has asked us to expose stereo 3D mode flags.
181 * True if client understands CRTC primary planes and cursor planes
182 * in the plane list. Automatically set when @atomic is set.
184 bool universal_planes
;
186 /** @atomic: True if client understands atomic properties. */
190 * @aspect_ratio_allowed:
192 * True, if client can handle picture aspect ratios, and has requested
193 * to pass this information along with the mode.
195 bool aspect_ratio_allowed
;
198 * @writeback_connectors:
200 * True if client understands writeback connectors
202 bool writeback_connectors
;
207 * This client has or had, master capability. Protected by struct
208 * &drm_device.master_mutex.
210 * This is used to ensure that CAP_SYS_ADMIN is not enforced, if the
211 * client is or was master in the past.
218 * This client is the creator of @master. Protected by struct
219 * &drm_device.master_mutex.
221 * See also the :ref:`section on primary nodes and authentication
222 * <drm_primary_node>`.
229 * Master this node is currently associated with. Only relevant if
230 * drm_is_primary_client() returns true. Note that this only
231 * matches &drm_device.master if the master is the currently active one.
233 * See also @authentication and @is_master and the :ref:`section on
234 * primary nodes and authentication <drm_primary_node>`.
236 struct drm_master
*master
;
238 /** @pid: Process that opened this file. */
241 /** @magic: Authentication magic, see @authenticated. */
247 * List of all open files of a DRM device, linked into
248 * &drm_device.filelist. Protected by &drm_device.filelist_mutex.
250 struct list_head lhead
;
252 /** @minor: &struct drm_minor for this file. */
253 struct drm_minor
*minor
;
258 * Mapping of mm object handles to object pointers. Used by the GEM
259 * subsystem. Protected by @table_lock.
261 struct idr object_idr
;
263 /** @table_lock: Protects @object_idr. */
264 spinlock_t table_lock
;
266 /** @syncobj_idr: Mapping of sync object handles to object pointers. */
267 struct idr syncobj_idr
;
268 /** @syncobj_table_lock: Protects @syncobj_idr. */
269 spinlock_t syncobj_table_lock
;
271 /** @filp: Pointer to the core file structure. */
277 * Optional pointer for driver private data. Can be allocated in
278 * &drm_driver.open and should be freed in &drm_driver.postclose.
285 * List of &struct drm_framebuffer associated with this file, using the
286 * &drm_framebuffer.filp_head entry.
288 * Protected by @fbs_lock. Note that the @fbs list holds a reference on
289 * the framebuffer object to prevent it from untimely disappearing.
291 struct list_head fbs
;
293 /** @fbs_lock: Protects @fbs. */
294 struct mutex fbs_lock
;
299 * User-created blob properties; this retains a reference on the
302 * Protected by @drm_mode_config.blob_lock;
304 struct list_head blobs
;
306 /** @event_wait: Waitqueue for new events added to @event_list. */
307 wait_queue_head_t event_wait
;
310 * @pending_event_list:
312 * List of pending &struct drm_pending_event, used to clean up pending
313 * events in case this file gets closed before the event is signalled.
314 * Uses the &drm_pending_event.pending_link entry.
316 * Protect by &drm_device.event_lock.
318 struct list_head pending_event_list
;
323 * List of &struct drm_pending_event, ready for delivery to userspace
324 * through drm_read(). Uses the &drm_pending_event.link entry.
326 * Protect by &drm_device.event_lock.
328 struct list_head event_list
;
333 * Available event space to prevent userspace from
334 * exhausting kernel memory. Currently limited to the fairly arbitrary
339 /** @event_read_lock: Serializes drm_read(). */
340 struct mutex event_read_lock
;
345 * Per-file buffer caches used by the PRIME buffer sharing code.
347 struct drm_prime_file_private prime
;
350 #if IS_ENABLED(CONFIG_DRM_LEGACY)
351 unsigned long lock_count
; /* DRI1 legacy lock count */
356 * drm_is_primary_client - is this an open file of the primary node
357 * @file_priv: DRM file
359 * Returns true if this is an open file of the primary node, i.e.
360 * &drm_file.minor of @file_priv is a primary minor.
362 * See also the :ref:`section on primary nodes and authentication
363 * <drm_primary_node>`.
365 static inline bool drm_is_primary_client(const struct drm_file
*file_priv
)
367 return file_priv
->minor
->type
== DRM_MINOR_PRIMARY
;
371 * drm_is_render_client - is this an open file of the render node
372 * @file_priv: DRM file
374 * Returns true if this is an open file of the render node, i.e.
375 * &drm_file.minor of @file_priv is a render minor.
377 * See also the :ref:`section on render nodes <drm_render_node>`.
379 static inline bool drm_is_render_client(const struct drm_file
*file_priv
)
381 return file_priv
->minor
->type
== DRM_MINOR_RENDER
;
384 int drm_open(struct inode
*inode
, struct file
*filp
);
385 ssize_t
drm_read(struct file
*filp
, char __user
*buffer
,
386 size_t count
, loff_t
*offset
);
387 int drm_release(struct inode
*inode
, struct file
*filp
);
388 int drm_release_noglobal(struct inode
*inode
, struct file
*filp
);
389 __poll_t
drm_poll(struct file
*filp
, struct poll_table_struct
*wait
);
390 int drm_event_reserve_init_locked(struct drm_device
*dev
,
391 struct drm_file
*file_priv
,
392 struct drm_pending_event
*p
,
393 struct drm_event
*e
);
394 int drm_event_reserve_init(struct drm_device
*dev
,
395 struct drm_file
*file_priv
,
396 struct drm_pending_event
*p
,
397 struct drm_event
*e
);
398 void drm_event_cancel_free(struct drm_device
*dev
,
399 struct drm_pending_event
*p
);
400 void drm_send_event_locked(struct drm_device
*dev
, struct drm_pending_event
*e
);
401 void drm_send_event(struct drm_device
*dev
, struct drm_pending_event
*e
);
403 struct file
*mock_drm_getfile(struct drm_minor
*minor
, unsigned int flags
);
406 struct drm_vma_offset_manager
;
407 unsigned long drm_get_unmapped_area(struct file
*file
,
408 unsigned long uaddr
, unsigned long len
,
409 unsigned long pgoff
, unsigned long flags
,
410 struct drm_vma_offset_manager
*mgr
);
411 #endif /* CONFIG_MMU */
414 #endif /* _DRM_FILE_H_ */