blob: 5dd27ae5c47c0692a41cc272c0e8d47548c844b6 [file] [log] [blame]
Daniel Vettera8f8b1d2017-03-08 15:12:42 +01001/*
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>
35
36#include <uapi/drm/drm.h>
37
38#include <drm/drm_prime.h>
39
40struct dma_fence;
41struct drm_file;
42struct drm_device;
43
44/*
45 * FIXME: Not sure we want to have drm_minor here in the end, but to avoid
46 * header include loops we need it here for now.
47 */
Daniel Vetterb93658f2017-03-08 15:12:44 +010048
Daniel Vettera8f8b1d2017-03-08 15:12:42 +010049enum drm_minor_type {
50 DRM_MINOR_PRIMARY,
51 DRM_MINOR_CONTROL,
52 DRM_MINOR_RENDER,
53};
54
55/**
Daniel Vetterb93658f2017-03-08 15:12:44 +010056 * struct drm_minor - DRM device minor structure
57 *
58 * This structure represents a DRM minor number for device nodes in /dev.
59 * Entirely opaque to drivers and should never be inspected directly by drivers.
60 * Drivers instead should only interact with &struct drm_file and of course
61 * &struct drm_device, which is also where driver-private data and resources can
62 * be attached to.
Daniel Vettera8f8b1d2017-03-08 15:12:42 +010063 */
64struct drm_minor {
Daniel Vetterb93658f2017-03-08 15:12:44 +010065 /* private: */
66 int index; /* Minor device number */
67 int type; /* Control or render */
68 struct device *kdev; /* Linux device */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +010069 struct drm_device *dev;
70
71 struct dentry *debugfs_root;
72
73 struct list_head debugfs_list;
74 struct mutex debugfs_lock; /* Protects debugfs_list. */
75};
76
Daniel Vetterb93658f2017-03-08 15:12:44 +010077/**
78 * struct drm_pending_event - Event queued up for userspace to read
79 *
80 * This represents a DRM event. Drivers can use this as a generic completion
81 * mechanism, which supports kernel-internal &struct completion, &struct dma_fence
82 * and also the DRM-specific &struct drm_event delivery mechanism.
83 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +010084struct drm_pending_event {
Daniel Vetterb93658f2017-03-08 15:12:44 +010085 /**
86 * @completion:
87 *
88 * Optional pointer to a kernel internal completion signalled when
89 * drm_send_event() is called, useful to internally synchronize with
90 * nonblocking operations.
91 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +010092 struct completion *completion;
Daniel Vetterb93658f2017-03-08 15:12:44 +010093
94 /**
95 * @completion_release:
96 *
97 * Optional callback currently only used by the atomic modeset helpers
98 * to clean up the reference count for the structure @completion is
99 * stored in.
100 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100101 void (*completion_release)(struct completion *completion);
Daniel Vetterb93658f2017-03-08 15:12:44 +0100102
103 /**
104 * @event:
105 *
106 * Pointer to the actual event that should be sent to userspace to be
107 * read using drm_read(). Can be optional, since nowadays events are
108 * also used to signal kernel internal threads with @completion or DMA
109 * transactions using @fence.
110 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100111 struct drm_event *event;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100112
113 /**
114 * @fence:
115 *
116 * Optional DMA fence to unblock other hardware transactions which
117 * depend upon the nonblocking DRM operation this event represents.
118 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100119 struct dma_fence *fence;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100120
121 /**
122 * @file_priv:
123 *
124 * &struct drm_file where @event should be delivered to. Only set when
125 * @event is set.
126 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100127 struct drm_file *file_priv;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100128
129 /**
130 * @link:
131 *
132 * Double-linked list to keep track of this event. Can be used by the
133 * driver up to the point when it calls drm_send_event(), after that
134 * this list entry is owned by the core for its own book-keeping.
135 */
136 struct list_head link;
137
138 /**
139 * @pending_link:
140 *
141 * Entry on &drm_file.pending_event_list, to keep track of all pending
142 * events for @file_priv, to allow correct unwinding of them when
143 * userspace closes the file before the event is delivered.
144 */
145 struct list_head pending_link;
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100146};
147
Daniel Vetterb93658f2017-03-08 15:12:44 +0100148/**
149 * struct drm_file - DRM file private data
150 *
151 * This structure tracks DRM state per open file descriptor.
152 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100153struct drm_file {
Daniel Vetterb93658f2017-03-08 15:12:44 +0100154 /**
155 * @authenticated:
156 *
157 * Whether the client is allowed to submit rendering, which for legacy
158 * nodes means it must be authenticated.
159 *
160 * See also the :ref:`section on primary nodes and authentication
161 * <drm_primary_node>`.
162 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100163 unsigned authenticated :1;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100164
165 /**
166 * @stereo_allowed:
167 *
168 * True when the client has asked us to expose stereo 3D mode flags.
169 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100170 unsigned stereo_allowed :1;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100171
172 /**
173 * @universal_planes:
174 *
175 * True if client understands CRTC primary planes and cursor planes
176 * in the plane list. Automatically set when @atomic is set.
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100177 */
178 unsigned universal_planes:1;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100179
180 /** @atomic: True if client understands atomic properties. */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100181 unsigned atomic:1;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100182
183 /**
184 * @is_master:
185 *
186 * This client is the creator of @master. Protected by struct
187 * &drm_device.master_mutex.
188 *
189 * See also the :ref:`section on primary nodes and authentication
190 * <drm_primary_node>`.
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100191 */
192 unsigned is_master:1;
193
Daniel Vetterb93658f2017-03-08 15:12:44 +0100194 /**
195 * @master:
196 *
197 * Master this node is currently associated with. Only relevant if
198 * drm_is_primary_client() returns true. Note that this only
199 * matches &drm_device.master if the master is the currently active one.
200 *
201 * See also @authentication and @is_master and the :ref:`section on
202 * primary nodes and authentication <drm_primary_node>`.
203 */
204 struct drm_master *master;
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100205
Daniel Vetterb93658f2017-03-08 15:12:44 +0100206 /** @pid: Process that opened this file. */
207 struct pid *pid;
208
209 /** @magic: Authentication magic, see @authenticated. */
210 drm_magic_t magic;
211
212 /**
213 * @lhead:
214 *
215 * List of all open files of a DRM device, linked into
216 * &drm_device.filelist. Protected by &drm_device.filelist_mutex.
217 */
218 struct list_head lhead;
219
220 /** @minor: &struct drm_minor for this file. */
221 struct drm_minor *minor;
222
223 /**
224 * @object_idr:
225 *
226 * Mapping of mm object handles to object pointers. Used by the GEM
227 * subsystem. Protected by @table_lock.
228 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100229 struct idr object_idr;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100230
231 /** @table_lock: Protects @object_idr. */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100232 spinlock_t table_lock;
233
Daniel Vetterb93658f2017-03-08 15:12:44 +0100234 /** @filp: Pointer to the core file structure. */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100235 struct file *filp;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100236
237 /**
238 * @driver_priv:
239 *
240 * Optional pointer for driver private data. Can be allocated in
241 * &drm_driver.open and should be freed in &drm_driver.postclose.
242 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100243 void *driver_priv;
244
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100245 /**
Daniel Vetterb93658f2017-03-08 15:12:44 +0100246 * @fbs:
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100247 *
Daniel Vetterb93658f2017-03-08 15:12:44 +0100248 * List of &struct drm_framebuffer associated with this file, using the
249 * &drm_framebuffer.filp_head entry.
250 *
251 * Protected by @fbs_lock. Note that the @fbs list holds a reference on
252 * the framebuffer object to prevent it from untimely disappearing.
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100253 */
254 struct list_head fbs;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100255
256 /** @fbs_lock: Protects @fbs. */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100257 struct mutex fbs_lock;
258
Daniel Vetterb93658f2017-03-08 15:12:44 +0100259 /**
260 * @blobs:
261 *
262 * User-created blob properties; this retains a reference on the
263 * property.
264 *
265 * Protected by @drm_mode_config.blob_lock;
266 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100267 struct list_head blobs;
268
Daniel Vetterb93658f2017-03-08 15:12:44 +0100269 /** @event_wait: Waitqueue for new events added to @event_list. */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100270 wait_queue_head_t event_wait;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100271
272 /**
273 * @pending_event_list:
274 *
275 * List of pending &struct drm_pending_event, used to clean up pending
276 * events in case this file gets closed before the event is signalled.
277 * Uses the &drm_pending_event.pending_link entry.
278 *
279 * Protect by &drm_device.event_lock.
280 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100281 struct list_head pending_event_list;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100282
283 /**
284 * @event_list:
285 *
286 * List of &struct drm_pending_event, ready for delivery to userspace
287 * through drm_read(). Uses the &drm_pending_event.link entry.
288 *
289 * Protect by &drm_device.event_lock.
290 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100291 struct list_head event_list;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100292
293 /**
294 * @event_space:
295 *
296 * Available event space to prevent userspace from
297 * exhausting kernel memory. Currently limited to the fairly arbitrary
298 * value of 4KB.
299 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100300 int event_space;
301
Daniel Vetterb93658f2017-03-08 15:12:44 +0100302 /** @event_read_lock: Serializes drm_read(). */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100303 struct mutex event_read_lock;
304
Daniel Vetterb93658f2017-03-08 15:12:44 +0100305 /**
306 * @prime:
307 *
308 * Per-file buffer caches used by the PRIME buffer sharing code.
309 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100310 struct drm_prime_file_private prime;
Daniel Vetterb93658f2017-03-08 15:12:44 +0100311
312 /* private: */
313 unsigned long lock_count; /* DRI1 legacy lock count */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100314};
315
Daniel Vetterb93658f2017-03-08 15:12:44 +0100316/**
317 * drm_is_primary_client - is this an open file of the primary node
318 * @file_priv: DRM file
319 *
320 * Returns true if this is an open file of the primary node, i.e.
321 * &drm_file.minor of @file_priv is a primary minor.
322 *
323 * See also the :ref:`section on primary nodes and authentication
324 * <drm_primary_node>`.
325 */
326static inline bool drm_is_primary_client(const struct drm_file *file_priv)
327{
328 return file_priv->minor->type == DRM_MINOR_PRIMARY;
329}
330
331/**
332 * drm_is_render_client - is this an open file of the render node
333 * @file_priv: DRM file
334 *
335 * Returns true if this is an open file of the render node, i.e.
336 * &drm_file.minor of @file_priv is a render minor.
337 *
338 * See also the :ref:`section on render nodes <drm_render_node>`.
339 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100340static inline bool drm_is_render_client(const struct drm_file *file_priv)
341{
342 return file_priv->minor->type == DRM_MINOR_RENDER;
343}
344
Daniel Vetterb93658f2017-03-08 15:12:44 +0100345/**
346 * drm_is_control_client - is this an open file of the control node
347 * @file_priv: DRM file
348 *
349 * Control nodes are deprecated and in the process of getting removed from the
350 * DRM userspace API. Do not ever use!
351 */
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100352static inline bool drm_is_control_client(const struct drm_file *file_priv)
353{
354 return file_priv->minor->type == DRM_MINOR_CONTROL;
355}
356
Daniel Vettera8f8b1d2017-03-08 15:12:42 +0100357int drm_open(struct inode *inode, struct file *filp);
358ssize_t drm_read(struct file *filp, char __user *buffer,
359 size_t count, loff_t *offset);
360int drm_release(struct inode *inode, struct file *filp);
361unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
362int drm_event_reserve_init_locked(struct drm_device *dev,
363 struct drm_file *file_priv,
364 struct drm_pending_event *p,
365 struct drm_event *e);
366int drm_event_reserve_init(struct drm_device *dev,
367 struct drm_file *file_priv,
368 struct drm_pending_event *p,
369 struct drm_event *e);
370void drm_event_cancel_free(struct drm_device *dev,
371 struct drm_pending_event *p);
372void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
373void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
374
375#endif /* _DRM_FILE_H_ */