xref: /dragonfly/sys/dev/drm/include/drm/drm_file.h (revision 527b525a)
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 #include <linux/idr.h>
36 
37 #include <uapi/drm/drm.h>
38 
39 #include <drm/drm_prime.h>
40 
41 struct dma_fence;
42 struct drm_file;
43 struct drm_device;
44 
45 /*
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.
48  */
49 enum drm_minor_type {
50 	DRM_MINOR_PRIMARY,
51 	DRM_MINOR_CONTROL,
52 	DRM_MINOR_RENDER,
53 };
54 
55 /**
56  * DRM minor structure. This structure represents a drm minor number.
57  */
58 struct drm_minor {
59 	int index;			/**< Minor device number */
60 	int type;                       /**< Control or render */
61 	struct device *kdev;		/**< Linux device */
62 	struct drm_device *dev;
63 
64 	struct dentry *debugfs_root;
65 
66 	struct list_head debugfs_list;
67 	struct lock debugfs_lock; /* Protects debugfs_list. */
68 };
69 
70 /* Event queued up for userspace to read */
71 struct drm_pending_event {
72 	struct completion *completion;
73 	void (*completion_release)(struct completion *completion);
74 	struct drm_event *event;
75 	struct dma_fence *fence;
76 	struct list_head link;
77 	struct list_head pending_link;
78 	struct drm_file *file_priv;
79 	pid_t pid; /* pid of requester, no guarantee it's valid by the time
80 		      we deliver the event, for tracing only */
81 };
82 
83 /** File private data */
84 struct drm_file {
85 	unsigned authenticated :1;
86 	/* true when the client has asked us to expose stereo 3D mode flags */
87 	unsigned stereo_allowed :1;
88 	/*
89 	 * true if client understands CRTC primary planes and cursor planes
90 	 * in the plane list
91 	 */
92 	unsigned universal_planes:1;
93 	/* true if client understands atomic properties */
94 	unsigned atomic:1;
95 	/*
96 	 * This client is the creator of @master.
97 	 * Protected by struct drm_device::master_mutex.
98 	 */
99 	unsigned is_master:1;
100 
101 	pid_t pid;
102 	drm_magic_t magic;
103 	struct list_head lhead;
104 	struct drm_minor *minor;
105 	unsigned long lock_count;
106 
107 	/** Mapping of mm object handles to object pointers. */
108 	struct idr object_idr;
109 	/** Lock for synchronization of access to object_idr. */
110 	spinlock_t table_lock;
111 
112 	struct file *filp;
113 	void *driver_priv;
114 
115 	struct drm_master *master; /* master this node is currently associated with
116 				      N.B. not always dev->master */
117 	/**
118 	 * fbs - List of framebuffers associated with this file.
119 	 *
120 	 * Protected by fbs_lock. Note that the fbs list holds a reference on
121 	 * the fb object to prevent it from untimely disappearing.
122 	 */
123 	struct list_head fbs;
124 	struct lock fbs_lock;
125 
126 	/** User-created blob properties; this retains a reference on the
127 	 *  property. */
128 	struct list_head blobs;
129 
130 	wait_queue_head_t event_wait;
131 	struct list_head pending_event_list;
132 	struct list_head event_list;
133 	int event_space;
134 
135 	struct lock event_read_lock;
136 
137 	struct drm_prime_file_private prime;
138 
139 #ifdef __DragonFly__
140 	struct drm_device *dev;
141 	struct kqinfo dkq;
142 #endif
143 };
144 
145 static inline bool drm_is_render_client(const struct drm_file *file_priv)
146 {
147 	return file_priv->minor->type == DRM_MINOR_RENDER;
148 }
149 
150 static inline bool drm_is_control_client(const struct drm_file *file_priv)
151 {
152 	return file_priv->minor->type == DRM_MINOR_CONTROL;
153 }
154 
155 static inline bool drm_is_primary_client(const struct drm_file *file_priv)
156 {
157 	return file_priv->minor->type == DRM_MINOR_PRIMARY;
158 }
159 
160 #ifdef __DragonFly__
161 d_open_t drm_open;
162 d_close_t drm_close;
163 d_read_t drm_read;
164 #else
165 int drm_open(struct inode *inode, struct file *filp);
166 ssize_t drm_read(struct file *filp, char __user *buffer,
167 		 size_t count, loff_t *offset);
168 #endif
169 int drm_release(struct inode *inode, struct file *filp);
170 unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
171 int drm_event_reserve_init_locked(struct drm_device *dev,
172 				  struct drm_file *file_priv,
173 				  struct drm_pending_event *p,
174 				  struct drm_event *e);
175 int drm_event_reserve_init(struct drm_device *dev,
176 			   struct drm_file *file_priv,
177 			   struct drm_pending_event *p,
178 			   struct drm_event *e);
179 void drm_event_cancel_free(struct drm_device *dev,
180 			   struct drm_pending_event *p);
181 void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
182 void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
183 
184 #endif /* _DRM_FILE_H_ */
185