Linux 4.14.5
[linux/fpc-iii.git] / include / drm / drm_file.h
blob0e0c868451a5ae276baae0c57e7caa99d2c23158
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.
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
19 * Software.
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.
30 #ifndef _DRM_FILE_H_
31 #define _DRM_FILE_H_
33 #include <linux/types.h>
34 #include <linux/completion.h>
36 #include <uapi/drm/drm.h>
38 #include <drm/drm_prime.h>
40 struct dma_fence;
41 struct drm_file;
42 struct drm_device;
43 struct device;
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 enum drm_minor_type {
51 DRM_MINOR_PRIMARY,
52 DRM_MINOR_CONTROL,
53 DRM_MINOR_RENDER,
56 /**
57 * struct drm_minor - DRM device minor structure
59 * This structure represents a DRM minor number for device nodes in /dev.
60 * Entirely opaque to drivers and should never be inspected directly by drivers.
61 * Drivers instead should only interact with &struct drm_file and of course
62 * &struct drm_device, which is also where driver-private data and resources can
63 * be attached to.
65 struct drm_minor {
66 /* private: */
67 int index; /* Minor device number */
68 int type; /* Control or render */
69 struct device *kdev; /* Linux device */
70 struct drm_device *dev;
72 struct dentry *debugfs_root;
74 struct list_head debugfs_list;
75 struct mutex debugfs_lock; /* Protects debugfs_list. */
78 /**
79 * struct drm_pending_event - Event queued up for userspace to read
81 * This represents a DRM event. Drivers can use this as a generic completion
82 * mechanism, which supports kernel-internal &struct completion, &struct dma_fence
83 * and also the DRM-specific &struct drm_event delivery mechanism.
85 struct drm_pending_event {
86 /**
87 * @completion:
89 * Optional pointer to a kernel internal completion signalled when
90 * drm_send_event() is called, useful to internally synchronize with
91 * nonblocking operations.
93 struct completion *completion;
95 /**
96 * @completion_release:
98 * Optional callback currently only used by the atomic modeset helpers
99 * to clean up the reference count for the structure @completion is
100 * stored in.
102 void (*completion_release)(struct completion *completion);
105 * @event:
107 * Pointer to the actual event that should be sent to userspace to be
108 * read using drm_read(). Can be optional, since nowadays events are
109 * also used to signal kernel internal threads with @completion or DMA
110 * transactions using @fence.
112 struct drm_event *event;
115 * @fence:
117 * Optional DMA fence to unblock other hardware transactions which
118 * depend upon the nonblocking DRM operation this event represents.
120 struct dma_fence *fence;
123 * @file_priv:
125 * &struct drm_file where @event should be delivered to. Only set when
126 * @event is set.
128 struct drm_file *file_priv;
131 * @link:
133 * Double-linked list to keep track of this event. Can be used by the
134 * driver up to the point when it calls drm_send_event(), after that
135 * this list entry is owned by the core for its own book-keeping.
137 struct list_head link;
140 * @pending_link:
142 * Entry on &drm_file.pending_event_list, to keep track of all pending
143 * events for @file_priv, to allow correct unwinding of them when
144 * userspace closes the file before the event is delivered.
146 struct list_head pending_link;
150 * struct drm_file - DRM file private data
152 * This structure tracks DRM state per open file descriptor.
154 struct drm_file {
156 * @authenticated:
158 * Whether the client is allowed to submit rendering, which for legacy
159 * nodes means it must be authenticated.
161 * See also the :ref:`section on primary nodes and authentication
162 * <drm_primary_node>`.
164 unsigned authenticated :1;
167 * @stereo_allowed:
169 * True when the client has asked us to expose stereo 3D mode flags.
171 unsigned stereo_allowed :1;
174 * @universal_planes:
176 * True if client understands CRTC primary planes and cursor planes
177 * in the plane list. Automatically set when @atomic is set.
179 unsigned universal_planes:1;
181 /** @atomic: True if client understands atomic properties. */
182 unsigned atomic:1;
185 * @is_master:
187 * This client is the creator of @master. Protected by struct
188 * &drm_device.master_mutex.
190 * See also the :ref:`section on primary nodes and authentication
191 * <drm_primary_node>`.
193 unsigned is_master:1;
196 * @master:
198 * Master this node is currently associated with. Only relevant if
199 * drm_is_primary_client() returns true. Note that this only
200 * matches &drm_device.master if the master is the currently active one.
202 * See also @authentication and @is_master and the :ref:`section on
203 * primary nodes and authentication <drm_primary_node>`.
205 struct drm_master *master;
207 /** @pid: Process that opened this file. */
208 struct pid *pid;
210 /** @magic: Authentication magic, see @authenticated. */
211 drm_magic_t magic;
214 * @lhead:
216 * List of all open files of a DRM device, linked into
217 * &drm_device.filelist. Protected by &drm_device.filelist_mutex.
219 struct list_head lhead;
221 /** @minor: &struct drm_minor for this file. */
222 struct drm_minor *minor;
225 * @object_idr:
227 * Mapping of mm object handles to object pointers. Used by the GEM
228 * subsystem. Protected by @table_lock.
230 struct idr object_idr;
232 /** @table_lock: Protects @object_idr. */
233 spinlock_t table_lock;
235 /** @syncobj_idr: Mapping of sync object handles to object pointers. */
236 struct idr syncobj_idr;
237 /** @syncobj_table_lock: Protects @syncobj_idr. */
238 spinlock_t syncobj_table_lock;
240 /** @filp: Pointer to the core file structure. */
241 struct file *filp;
244 * @driver_priv:
246 * Optional pointer for driver private data. Can be allocated in
247 * &drm_driver.open and should be freed in &drm_driver.postclose.
249 void *driver_priv;
252 * @fbs:
254 * List of &struct drm_framebuffer associated with this file, using the
255 * &drm_framebuffer.filp_head entry.
257 * Protected by @fbs_lock. Note that the @fbs list holds a reference on
258 * the framebuffer object to prevent it from untimely disappearing.
260 struct list_head fbs;
262 /** @fbs_lock: Protects @fbs. */
263 struct mutex fbs_lock;
266 * @blobs:
268 * User-created blob properties; this retains a reference on the
269 * property.
271 * Protected by @drm_mode_config.blob_lock;
273 struct list_head blobs;
275 /** @event_wait: Waitqueue for new events added to @event_list. */
276 wait_queue_head_t event_wait;
279 * @pending_event_list:
281 * List of pending &struct drm_pending_event, used to clean up pending
282 * events in case this file gets closed before the event is signalled.
283 * Uses the &drm_pending_event.pending_link entry.
285 * Protect by &drm_device.event_lock.
287 struct list_head pending_event_list;
290 * @event_list:
292 * List of &struct drm_pending_event, ready for delivery to userspace
293 * through drm_read(). Uses the &drm_pending_event.link entry.
295 * Protect by &drm_device.event_lock.
297 struct list_head event_list;
300 * @event_space:
302 * Available event space to prevent userspace from
303 * exhausting kernel memory. Currently limited to the fairly arbitrary
304 * value of 4KB.
306 int event_space;
308 /** @event_read_lock: Serializes drm_read(). */
309 struct mutex event_read_lock;
312 * @prime:
314 * Per-file buffer caches used by the PRIME buffer sharing code.
316 struct drm_prime_file_private prime;
318 /* private: */
319 unsigned long lock_count; /* DRI1 legacy lock count */
323 * drm_is_primary_client - is this an open file of the primary node
324 * @file_priv: DRM file
326 * Returns true if this is an open file of the primary node, i.e.
327 * &drm_file.minor of @file_priv is a primary minor.
329 * See also the :ref:`section on primary nodes and authentication
330 * <drm_primary_node>`.
332 static inline bool drm_is_primary_client(const struct drm_file *file_priv)
334 return file_priv->minor->type == DRM_MINOR_PRIMARY;
338 * drm_is_render_client - is this an open file of the render node
339 * @file_priv: DRM file
341 * Returns true if this is an open file of the render node, i.e.
342 * &drm_file.minor of @file_priv is a render minor.
344 * See also the :ref:`section on render nodes <drm_render_node>`.
346 static inline bool drm_is_render_client(const struct drm_file *file_priv)
348 return file_priv->minor->type == DRM_MINOR_RENDER;
352 * drm_is_control_client - is this an open file of the control node
353 * @file_priv: DRM file
355 * Control nodes are deprecated and in the process of getting removed from the
356 * DRM userspace API. Do not ever use!
358 static inline bool drm_is_control_client(const struct drm_file *file_priv)
360 return file_priv->minor->type == DRM_MINOR_CONTROL;
363 int drm_open(struct inode *inode, struct file *filp);
364 ssize_t drm_read(struct file *filp, char __user *buffer,
365 size_t count, loff_t *offset);
366 int drm_release(struct inode *inode, struct file *filp);
367 unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
368 int drm_event_reserve_init_locked(struct drm_device *dev,
369 struct drm_file *file_priv,
370 struct drm_pending_event *p,
371 struct drm_event *e);
372 int drm_event_reserve_init(struct drm_device *dev,
373 struct drm_file *file_priv,
374 struct drm_pending_event *p,
375 struct drm_event *e);
376 void drm_event_cancel_free(struct drm_device *dev,
377 struct drm_pending_event *p);
378 void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
379 void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
381 #endif /* _DRM_FILE_H_ */