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