]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/drm/drm_file.h
net_sched: move tcf_lock down after gen_replace_estimator()
[karo-tx-linux.git] / include / drm / drm_file.h
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.
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
40 struct dma_fence;
41 struct drm_file;
42 struct 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  */
48
49 enum drm_minor_type {
50         DRM_MINOR_PRIMARY,
51         DRM_MINOR_CONTROL,
52         DRM_MINOR_RENDER,
53 };
54
55 /**
56  * 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.
63  */
64 struct drm_minor {
65         /* private: */
66         int index;                      /* Minor device number */
67         int type;                       /* Control or render */
68         struct device *kdev;            /* Linux device */
69         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
77 /**
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  */
84 struct drm_pending_event {
85         /**
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          */
92         struct completion *completion;
93
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          */
101         void (*completion_release)(struct completion *completion);
102
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          */
111         struct drm_event *event;
112
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          */
119         struct dma_fence *fence;
120
121         /**
122          * @file_priv:
123          *
124          * &struct drm_file where @event should be delivered to. Only set when
125          * @event is set.
126          */
127         struct drm_file *file_priv;
128
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;
146 };
147
148 /**
149  * struct drm_file - DRM file private data
150  *
151  * This structure tracks DRM state per open file descriptor.
152  */
153 struct drm_file {
154         /**
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          */
163         unsigned authenticated :1;
164
165         /**
166          * @stereo_allowed:
167          *
168          * True when the client has asked us to expose stereo 3D mode flags.
169          */
170         unsigned stereo_allowed :1;
171
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.
177          */
178         unsigned universal_planes:1;
179
180         /** @atomic: True if client understands atomic properties. */
181         unsigned atomic:1;
182
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>`.
191          */
192         unsigned is_master:1;
193
194         /**
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;
205
206         /** @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          */
229         struct idr object_idr;
230
231         /** @table_lock: Protects @object_idr. */
232         spinlock_t table_lock;
233
234         /** @filp: Pointer to the core file structure. */
235         struct file *filp;
236
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          */
243         void *driver_priv;
244
245         /**
246          * @fbs:
247          *
248          * 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.
253          */
254         struct list_head fbs;
255
256         /** @fbs_lock: Protects @fbs. */
257         struct mutex fbs_lock;
258
259         /**
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          */
267         struct list_head blobs;
268
269         /** @event_wait: Waitqueue for new events added to @event_list. */
270         wait_queue_head_t event_wait;
271
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          */
281         struct list_head pending_event_list;
282
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          */
291         struct list_head event_list;
292
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          */
300         int event_space;
301
302         /** @event_read_lock: Serializes drm_read(). */
303         struct mutex event_read_lock;
304
305         /**
306          * @prime:
307          *
308          * Per-file buffer caches used by the PRIME buffer sharing code.
309          */
310         struct drm_prime_file_private prime;
311
312         /* private: */
313         unsigned long lock_count; /* DRI1 legacy lock count */
314 };
315
316 /**
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  */
326 static 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  */
340 static inline bool drm_is_render_client(const struct drm_file *file_priv)
341 {
342         return file_priv->minor->type == DRM_MINOR_RENDER;
343 }
344
345 /**
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  */
352 static inline bool drm_is_control_client(const struct drm_file *file_priv)
353 {
354         return file_priv->minor->type == DRM_MINOR_CONTROL;
355 }
356
357 int drm_open(struct inode *inode, struct file *filp);
358 ssize_t drm_read(struct file *filp, char __user *buffer,
359                  size_t count, loff_t *offset);
360 int drm_release(struct inode *inode, struct file *filp);
361 unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
362 int 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);
366 int 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);
370 void drm_event_cancel_free(struct drm_device *dev,
371                            struct drm_pending_event *p);
372 void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
373 void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
374
375 #endif /* _DRM_FILE_H_ */