1 /*
2  * Copyright © 2014 Intel Corporation
3  *   Daniel Vetter <daniel.vetter@ffwll.ch>
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include <linux/kthread.h>
25 
26 #include <drm/drm_ioctl.h>
27 #include <drm/drm_vblank.h>
28 
29 #define DRM_IF_MAJOR 1
30 #define DRM_IF_MINOR 4
31 
32 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
33 
34 struct dentry;
35 struct dma_buf;
36 struct drm_connector;
37 struct drm_crtc;
38 struct drm_framebuffer;
39 struct drm_gem_object;
40 struct drm_master;
41 struct drm_minor;
42 struct drm_prime_file_private;
43 struct drm_printer;
44 struct drm_vblank_crtc;
45 
46 /* drm_file.c */
47 extern struct mutex drm_global_mutex;
48 bool drm_dev_needs_global_mutex(struct drm_device *dev);
49 struct drm_file *drm_file_alloc(struct drm_minor *minor);
50 void drm_file_free(struct drm_file *file);
51 void drm_lastclose(struct drm_device *dev);
52 
53 #ifdef CONFIG_PCI
54 
55 /* drm_pci.c */
56 int drm_irq_by_busid(struct drm_device *dev, void *data,
57 		     struct drm_file *file_priv);
58 void drm_pci_agp_destroy(struct drm_device *dev);
59 int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master);
60 
61 #else
62 
drm_irq_by_busid(struct drm_device * dev,void * data,struct drm_file * file_priv)63 static inline int drm_irq_by_busid(struct drm_device *dev, void *data,
64 				   struct drm_file *file_priv)
65 {
66 	return -EINVAL;
67 }
68 
drm_pci_agp_destroy(struct drm_device * dev)69 static inline void drm_pci_agp_destroy(struct drm_device *dev)
70 {
71 }
72 
drm_pci_set_busid(struct drm_device * dev,struct drm_master * master)73 static inline int drm_pci_set_busid(struct drm_device *dev,
74 				    struct drm_master *master)
75 {
76 	return -EINVAL;
77 }
78 
79 #endif
80 
81 /* drm_prime.c */
82 int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
83 				 struct drm_file *file_priv);
84 int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
85 				 struct drm_file *file_priv);
86 
87 void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
88 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
89 void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpriv,
90 					struct dma_buf *dma_buf);
91 
92 /* drm_drv.c */
93 struct drm_minor *drm_minor_acquire(unsigned int minor_id);
94 void drm_minor_release(struct drm_minor *minor);
95 
96 /* drm_managed.c */
97 void drm_managed_release(struct drm_device *dev);
98 void drmm_add_final_kfree(struct drm_device *dev, void *container);
99 
100 /* drm_vblank.c */
drm_vblank_passed(u64 seq,u64 ref)101 static inline bool drm_vblank_passed(u64 seq, u64 ref)
102 {
103 	return (seq - ref) <= (1 << 23);
104 }
105 
106 void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe);
107 int drm_vblank_get(struct drm_device *dev, unsigned int pipe);
108 void drm_vblank_put(struct drm_device *dev, unsigned int pipe);
109 u64 drm_vblank_count(struct drm_device *dev, unsigned int pipe);
110 
111 /* drm_vblank_work.c */
drm_vblank_flush_worker(struct drm_vblank_crtc * vblank)112 static inline void drm_vblank_flush_worker(struct drm_vblank_crtc *vblank)
113 {
114 	kthread_flush_worker(vblank->worker);
115 }
116 
drm_vblank_destroy_worker(struct drm_vblank_crtc * vblank)117 static inline void drm_vblank_destroy_worker(struct drm_vblank_crtc *vblank)
118 {
119 	kthread_destroy_worker(vblank->worker);
120 }
121 
122 int drm_vblank_worker_init(struct drm_vblank_crtc *vblank);
123 void drm_vblank_cancel_pending_works(struct drm_vblank_crtc *vblank);
124 void drm_handle_vblank_works(struct drm_vblank_crtc *vblank);
125 
126 /* IOCTLS */
127 int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
128 			  struct drm_file *filp);
129 int drm_legacy_modeset_ctl_ioctl(struct drm_device *dev, void *data,
130 				 struct drm_file *file_priv);
131 
132 /* drm_irq.c */
133 
134 /* IOCTLS */
135 #if IS_ENABLED(CONFIG_DRM_LEGACY)
136 int drm_legacy_irq_control(struct drm_device *dev, void *data,
137 			   struct drm_file *file_priv);
138 #endif
139 
140 int drm_crtc_get_sequence_ioctl(struct drm_device *dev, void *data,
141 				struct drm_file *filp);
142 
143 int drm_crtc_queue_sequence_ioctl(struct drm_device *dev, void *data,
144 				  struct drm_file *filp);
145 
146 /* drm_auth.c */
147 int drm_getmagic(struct drm_device *dev, void *data,
148 		 struct drm_file *file_priv);
149 int drm_authmagic(struct drm_device *dev, void *data,
150 		  struct drm_file *file_priv);
151 int drm_setmaster_ioctl(struct drm_device *dev, void *data,
152 			struct drm_file *file_priv);
153 int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
154 			 struct drm_file *file_priv);
155 int drm_master_open(struct drm_file *file_priv);
156 void drm_master_release(struct drm_file *file_priv);
157 bool drm_master_internal_acquire(struct drm_device *dev);
158 void drm_master_internal_release(struct drm_device *dev);
159 
160 /* drm_sysfs.c */
161 extern struct class *drm_class;
162 
163 int drm_sysfs_init(void);
164 void drm_sysfs_destroy(void);
165 struct device *drm_sysfs_minor_alloc(struct drm_minor *minor);
166 int drm_sysfs_connector_add(struct drm_connector *connector);
167 void drm_sysfs_connector_remove(struct drm_connector *connector);
168 
169 void drm_sysfs_lease_event(struct drm_device *dev);
170 
171 /* drm_gem.c */
172 struct drm_gem_object;
173 int drm_gem_init(struct drm_device *dev);
174 int drm_gem_handle_create_tail(struct drm_file *file_priv,
175 			       struct drm_gem_object *obj,
176 			       u32 *handlep);
177 int drm_gem_close_ioctl(struct drm_device *dev, void *data,
178 			struct drm_file *file_priv);
179 int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
180 			struct drm_file *file_priv);
181 int drm_gem_open_ioctl(struct drm_device *dev, void *data,
182 		       struct drm_file *file_priv);
183 void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
184 void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
185 void drm_gem_print_info(struct drm_printer *p, unsigned int indent,
186 			const struct drm_gem_object *obj);
187 
188 int drm_gem_pin(struct drm_gem_object *obj);
189 void drm_gem_unpin(struct drm_gem_object *obj);
190 void *drm_gem_vmap(struct drm_gem_object *obj);
191 void drm_gem_vunmap(struct drm_gem_object *obj, void *vaddr);
192 
193 /* drm_debugfs.c drm_debugfs_crc.c */
194 #if defined(CONFIG_DEBUG_FS)
195 int drm_debugfs_init(struct drm_minor *minor, int minor_id,
196 		     struct dentry *root);
197 void drm_debugfs_cleanup(struct drm_minor *minor);
198 void drm_debugfs_connector_add(struct drm_connector *connector);
199 void drm_debugfs_connector_remove(struct drm_connector *connector);
200 void drm_debugfs_crtc_add(struct drm_crtc *crtc);
201 void drm_debugfs_crtc_remove(struct drm_crtc *crtc);
202 void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc);
203 #else
drm_debugfs_init(struct drm_minor * minor,int minor_id,struct dentry * root)204 static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id,
205 				   struct dentry *root)
206 {
207 	return 0;
208 }
209 
drm_debugfs_cleanup(struct drm_minor * minor)210 static inline void drm_debugfs_cleanup(struct drm_minor *minor)
211 {
212 }
213 
drm_debugfs_connector_add(struct drm_connector * connector)214 static inline void drm_debugfs_connector_add(struct drm_connector *connector)
215 {
216 }
drm_debugfs_connector_remove(struct drm_connector * connector)217 static inline void drm_debugfs_connector_remove(struct drm_connector *connector)
218 {
219 }
220 
drm_debugfs_crtc_add(struct drm_crtc * crtc)221 static inline void drm_debugfs_crtc_add(struct drm_crtc *crtc)
222 {
223 }
drm_debugfs_crtc_remove(struct drm_crtc * crtc)224 static inline void drm_debugfs_crtc_remove(struct drm_crtc *crtc)
225 {
226 }
227 
drm_debugfs_crtc_crc_add(struct drm_crtc * crtc)228 static inline void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc)
229 {
230 }
231 
232 #endif
233 
234 drm_ioctl_t drm_version;
235 drm_ioctl_t drm_getunique;
236 drm_ioctl_t drm_getclient;
237 
238 /* drm_syncobj.c */
239 void drm_syncobj_open(struct drm_file *file_private);
240 void drm_syncobj_release(struct drm_file *file_private);
241 int drm_syncobj_create_ioctl(struct drm_device *dev, void *data,
242 			     struct drm_file *file_private);
243 int drm_syncobj_destroy_ioctl(struct drm_device *dev, void *data,
244 			      struct drm_file *file_private);
245 int drm_syncobj_handle_to_fd_ioctl(struct drm_device *dev, void *data,
246 				   struct drm_file *file_private);
247 int drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,
248 				   struct drm_file *file_private);
249 int drm_syncobj_transfer_ioctl(struct drm_device *dev, void *data,
250 			       struct drm_file *file_private);
251 int drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
252 			   struct drm_file *file_private);
253 int drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
254 				    struct drm_file *file_private);
255 int drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
256 			    struct drm_file *file_private);
257 int drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
258 			     struct drm_file *file_private);
259 int drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
260 				      struct drm_file *file_private);
261 int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
262 			    struct drm_file *file_private);
263 
264 /* drm_framebuffer.c */
265 void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
266 				const struct drm_framebuffer *fb);
267 void drm_framebuffer_debugfs_init(struct drm_minor *minor);
268