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