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