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 iosys_map;
37 struct drm_connector;
38 struct drm_crtc;
39 struct drm_framebuffer;
40 struct drm_gem_object;
41 struct drm_master;
42 struct drm_minor;
43 struct drm_prime_file_private;
44 struct drm_printer;
45 struct drm_vblank_crtc;
46
47 /* drm_file.c */
48 extern struct rwlock drm_global_mutex;
49 bool drm_dev_needs_global_mutex(struct drm_device *dev);
50 struct drm_file *drm_file_alloc(struct drm_minor *minor);
51 void drm_file_free(struct drm_file *file);
52 void drm_lastclose(struct drm_device *dev);
53
54 #ifdef CONFIG_PCI
55
56 /* drm_pci.c */
57 int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master);
58
59 #else
60
drm_pci_set_busid(struct drm_device * dev,struct drm_master * master)61 static inline int drm_pci_set_busid(struct drm_device *dev,
62 struct drm_master *master)
63 {
64 return -EINVAL;
65 }
66
67 #endif
68
69 /* drm_prime.c */
70 int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
71 struct drm_file *file_priv);
72 int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
73 struct drm_file *file_priv);
74
75 void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
76 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
77 void drm_prime_remove_buf_handle(struct drm_prime_file_private *prime_fpriv,
78 uint32_t handle);
79
80 /* drm_managed.c */
81 void drm_managed_release(struct drm_device *dev);
82 void drmm_add_final_kfree(struct drm_device *dev, void *container);
83
84 /* drm_vblank.c */
drm_vblank_passed(u64 seq,u64 ref)85 static inline bool drm_vblank_passed(u64 seq, u64 ref)
86 {
87 return (seq - ref) <= (1 << 23);
88 }
89
90 void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe);
91 int drm_vblank_get(struct drm_device *dev, unsigned int pipe);
92 void drm_vblank_put(struct drm_device *dev, unsigned int pipe);
93 u64 drm_vblank_count(struct drm_device *dev, unsigned int pipe);
94
95 /* drm_vblank_work.c */
drm_vblank_flush_worker(struct drm_vblank_crtc * vblank)96 static inline void drm_vblank_flush_worker(struct drm_vblank_crtc *vblank)
97 {
98 kthread_flush_worker(vblank->worker);
99 }
100
drm_vblank_destroy_worker(struct drm_vblank_crtc * vblank)101 static inline void drm_vblank_destroy_worker(struct drm_vblank_crtc *vblank)
102 {
103 if (vblank->worker)
104 kthread_destroy_worker(vblank->worker);
105 }
106
107 int drm_vblank_worker_init(struct drm_vblank_crtc *vblank);
108 void drm_vblank_cancel_pending_works(struct drm_vblank_crtc *vblank);
109 void drm_handle_vblank_works(struct drm_vblank_crtc *vblank);
110
111 /* IOCTLS */
112 int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
113 struct drm_file *filp);
114 int drm_legacy_modeset_ctl_ioctl(struct drm_device *dev, void *data,
115 struct drm_file *file_priv);
116
117 /* drm_irq.c */
118
119 /* IOCTLS */
120 #if IS_ENABLED(CONFIG_DRM_LEGACY)
121 int drm_legacy_irq_control(struct drm_device *dev, void *data,
122 struct drm_file *file_priv);
123 #endif
124
125 int drm_crtc_get_sequence_ioctl(struct drm_device *dev, void *data,
126 struct drm_file *filp);
127
128 int drm_crtc_queue_sequence_ioctl(struct drm_device *dev, void *data,
129 struct drm_file *filp);
130
131 /* drm_auth.c */
132 int drm_getmagic(struct drm_device *dev, void *data,
133 struct drm_file *file_priv);
134 int drm_authmagic(struct drm_device *dev, void *data,
135 struct drm_file *file_priv);
136 int drm_setmaster_ioctl(struct drm_device *dev, void *data,
137 struct drm_file *file_priv);
138 int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
139 struct drm_file *file_priv);
140 int drm_master_open(struct drm_file *file_priv);
141 void drm_master_release(struct drm_file *file_priv);
142 bool drm_master_internal_acquire(struct drm_device *dev);
143 void drm_master_internal_release(struct drm_device *dev);
144
145 /* drm_sysfs.c */
146 #ifdef __linux__
147 extern struct class *drm_class;
148
149 int drm_sysfs_init(void);
150 void drm_sysfs_destroy(void);
151 struct device *drm_sysfs_minor_alloc(struct drm_minor *minor);
152 int drm_sysfs_connector_add(struct drm_connector *connector);
153 void drm_sysfs_connector_remove(struct drm_connector *connector);
154
155 void drm_sysfs_lease_event(struct drm_device *dev);
156 #else
157 static inline struct device *
drm_sysfs_minor_alloc(struct drm_minor * minor)158 drm_sysfs_minor_alloc(struct drm_minor *minor)
159 {
160 return ERR_PTR(-ENOSYS);
161 }
162
163 static inline int
drm_sysfs_connector_add(struct drm_connector * connector)164 drm_sysfs_connector_add(struct drm_connector *connector)
165 {
166 return 0;
167 }
168
169 static inline void
drm_sysfs_connector_remove(struct drm_connector * connector)170 drm_sysfs_connector_remove(struct drm_connector *connector)
171 {
172 }
173 #endif
174
175 /* drm_gem.c */
176 int drm_gem_init(struct drm_device *dev);
177 int drm_gem_handle_create_tail(struct drm_file *file_priv,
178 struct drm_gem_object *obj,
179 u32 *handlep);
180 int drm_gem_close_ioctl(struct drm_device *dev, void *data,
181 struct drm_file *file_priv);
182 int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
183 struct drm_file *file_priv);
184 int drm_gem_open_ioctl(struct drm_device *dev, void *data,
185 struct drm_file *file_priv);
186 void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
187 void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
188 void drm_gem_print_info(struct drm_printer *p, unsigned int indent,
189 const struct drm_gem_object *obj);
190
191 int drm_gem_pin(struct drm_gem_object *obj);
192 void drm_gem_unpin(struct drm_gem_object *obj);
193 int drm_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map);
194 void drm_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map);
195
196 /* drm_debugfs.c drm_debugfs_crc.c */
197 #if defined(CONFIG_DEBUG_FS)
198 int drm_debugfs_init(struct drm_minor *minor, int minor_id,
199 struct dentry *root);
200 void drm_debugfs_cleanup(struct drm_minor *minor);
201 void drm_debugfs_late_register(struct drm_device *dev);
202 void drm_debugfs_connector_add(struct drm_connector *connector);
203 void drm_debugfs_connector_remove(struct drm_connector *connector);
204 void drm_debugfs_crtc_add(struct drm_crtc *crtc);
205 void drm_debugfs_crtc_remove(struct drm_crtc *crtc);
206 void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc);
207 #else
drm_debugfs_init(struct drm_minor * minor,int minor_id,struct dentry * root)208 static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id,
209 struct dentry *root)
210 {
211 return 0;
212 }
213
drm_debugfs_cleanup(struct drm_minor * minor)214 static inline void drm_debugfs_cleanup(struct drm_minor *minor)
215 {
216 }
217
drm_debugfs_late_register(struct drm_device * dev)218 static inline void drm_debugfs_late_register(struct drm_device *dev)
219 {
220 }
221
drm_debugfs_connector_add(struct drm_connector * connector)222 static inline void drm_debugfs_connector_add(struct drm_connector *connector)
223 {
224 }
drm_debugfs_connector_remove(struct drm_connector * connector)225 static inline void drm_debugfs_connector_remove(struct drm_connector *connector)
226 {
227 }
228
drm_debugfs_crtc_add(struct drm_crtc * crtc)229 static inline void drm_debugfs_crtc_add(struct drm_crtc *crtc)
230 {
231 }
drm_debugfs_crtc_remove(struct drm_crtc * crtc)232 static inline void drm_debugfs_crtc_remove(struct drm_crtc *crtc)
233 {
234 }
235
drm_debugfs_crtc_crc_add(struct drm_crtc * crtc)236 static inline void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc)
237 {
238 }
239
240 #endif
241
242 drm_ioctl_t drm_version;
243 drm_ioctl_t drm_getunique;
244 drm_ioctl_t drm_getclient;
245
246 /* drm_syncobj.c */
247 void drm_syncobj_open(struct drm_file *file_private);
248 void drm_syncobj_release(struct drm_file *file_private);
249 int drm_syncobj_create_ioctl(struct drm_device *dev, void *data,
250 struct drm_file *file_private);
251 int drm_syncobj_destroy_ioctl(struct drm_device *dev, void *data,
252 struct drm_file *file_private);
253 int drm_syncobj_handle_to_fd_ioctl(struct drm_device *dev, void *data,
254 struct drm_file *file_private);
255 int drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,
256 struct drm_file *file_private);
257 int drm_syncobj_transfer_ioctl(struct drm_device *dev, void *data,
258 struct drm_file *file_private);
259 int drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
260 struct drm_file *file_private);
261 int drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
262 struct drm_file *file_private);
263 int drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data,
264 struct drm_file *file_private);
265 int drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
266 struct drm_file *file_private);
267 int drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
268 struct drm_file *file_private);
269 int drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
270 struct drm_file *file_private);
271 int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
272 struct drm_file *file_private);
273
274 /* drm_framebuffer.c */
275 void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
276 const struct drm_framebuffer *fb);
277 void drm_framebuffer_debugfs_init(struct drm_minor *minor);
278