xref: /openbmc/linux/drivers/gpu/drm/drm_internal.h (revision 6ea9a2b8)
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 dma_buf_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 mutex 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_legacy_irq_by_busid(struct drm_device *dev, void *data,
58 			    struct drm_file *file_priv);
59 void drm_pci_agp_destroy(struct drm_device *dev);
60 int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master);
61 
62 #else
63 
64 static inline int drm_legacy_irq_by_busid(struct drm_device *dev, void *data,
65 					  struct drm_file *file_priv)
66 {
67 	return -EINVAL;
68 }
69 
70 static inline void drm_pci_agp_destroy(struct drm_device *dev)
71 {
72 }
73 
74 static inline int drm_pci_set_busid(struct drm_device *dev,
75 				    struct drm_master *master)
76 {
77 	return -EINVAL;
78 }
79 
80 #endif
81 
82 /* drm_prime.c */
83 int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
84 				 struct drm_file *file_priv);
85 int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
86 				 struct drm_file *file_priv);
87 
88 void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
89 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
90 void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpriv,
91 					struct dma_buf *dma_buf);
92 
93 /* drm_drv.c */
94 struct drm_minor *drm_minor_acquire(unsigned int minor_id);
95 void drm_minor_release(struct drm_minor *minor);
96 
97 /* drm_managed.c */
98 void drm_managed_release(struct drm_device *dev);
99 void drmm_add_final_kfree(struct drm_device *dev, void *container);
100 
101 /* drm_vblank.c */
102 static inline bool drm_vblank_passed(u64 seq, u64 ref)
103 {
104 	return (seq - ref) <= (1 << 23);
105 }
106 
107 void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe);
108 int drm_vblank_get(struct drm_device *dev, unsigned int pipe);
109 void drm_vblank_put(struct drm_device *dev, unsigned int pipe);
110 u64 drm_vblank_count(struct drm_device *dev, unsigned int pipe);
111 
112 /* drm_vblank_work.c */
113 static inline void drm_vblank_flush_worker(struct drm_vblank_crtc *vblank)
114 {
115 	kthread_flush_worker(vblank->worker);
116 }
117 
118 static inline void drm_vblank_destroy_worker(struct drm_vblank_crtc *vblank)
119 {
120 	kthread_destroy_worker(vblank->worker);
121 }
122 
123 int drm_vblank_worker_init(struct drm_vblank_crtc *vblank);
124 void drm_vblank_cancel_pending_works(struct drm_vblank_crtc *vblank);
125 void drm_handle_vblank_works(struct drm_vblank_crtc *vblank);
126 
127 /* IOCTLS */
128 int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
129 			  struct drm_file *filp);
130 int drm_legacy_modeset_ctl_ioctl(struct drm_device *dev, void *data,
131 				 struct drm_file *file_priv);
132 
133 /* drm_irq.c */
134 
135 /* IOCTLS */
136 #if IS_ENABLED(CONFIG_DRM_LEGACY)
137 int drm_legacy_irq_control(struct drm_device *dev, void *data,
138 			   struct drm_file *file_priv);
139 #endif
140 
141 int drm_crtc_get_sequence_ioctl(struct drm_device *dev, void *data,
142 				struct drm_file *filp);
143 
144 int drm_crtc_queue_sequence_ioctl(struct drm_device *dev, void *data,
145 				  struct drm_file *filp);
146 
147 /* drm_auth.c */
148 int drm_getmagic(struct drm_device *dev, void *data,
149 		 struct drm_file *file_priv);
150 int drm_authmagic(struct drm_device *dev, void *data,
151 		  struct drm_file *file_priv);
152 int drm_setmaster_ioctl(struct drm_device *dev, void *data,
153 			struct drm_file *file_priv);
154 int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
155 			 struct drm_file *file_priv);
156 int drm_master_open(struct drm_file *file_priv);
157 void drm_master_release(struct drm_file *file_priv);
158 bool drm_master_internal_acquire(struct drm_device *dev);
159 void drm_master_internal_release(struct drm_device *dev);
160 
161 /* drm_sysfs.c */
162 extern struct class *drm_class;
163 
164 int drm_sysfs_init(void);
165 void drm_sysfs_destroy(void);
166 struct device *drm_sysfs_minor_alloc(struct drm_minor *minor);
167 int drm_sysfs_connector_add(struct drm_connector *connector);
168 void drm_sysfs_connector_remove(struct drm_connector *connector);
169 
170 void drm_sysfs_lease_event(struct drm_device *dev);
171 
172 /* drm_gem.c */
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 int drm_gem_vmap(struct drm_gem_object *obj, struct dma_buf_map *map);
191 void drm_gem_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map);
192 
193 int drm_gem_dumb_destroy(struct drm_file *file, struct drm_device *dev,
194 			 u32 handle);
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_connector_add(struct drm_connector *connector);
202 void drm_debugfs_connector_remove(struct drm_connector *connector);
203 void drm_debugfs_crtc_add(struct drm_crtc *crtc);
204 void drm_debugfs_crtc_remove(struct drm_crtc *crtc);
205 void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc);
206 #else
207 static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id,
208 				   struct dentry *root)
209 {
210 	return 0;
211 }
212 
213 static inline void drm_debugfs_cleanup(struct drm_minor *minor)
214 {
215 }
216 
217 static inline void drm_debugfs_connector_add(struct drm_connector *connector)
218 {
219 }
220 static inline void drm_debugfs_connector_remove(struct drm_connector *connector)
221 {
222 }
223 
224 static inline void drm_debugfs_crtc_add(struct drm_crtc *crtc)
225 {
226 }
227 static inline void drm_debugfs_crtc_remove(struct drm_crtc *crtc)
228 {
229 }
230 
231 static inline void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc)
232 {
233 }
234 
235 #endif
236 
237 drm_ioctl_t drm_version;
238 drm_ioctl_t drm_getunique;
239 drm_ioctl_t drm_getclient;
240 
241 /* drm_syncobj.c */
242 void drm_syncobj_open(struct drm_file *file_private);
243 void drm_syncobj_release(struct drm_file *file_private);
244 int drm_syncobj_create_ioctl(struct drm_device *dev, void *data,
245 			     struct drm_file *file_private);
246 int drm_syncobj_destroy_ioctl(struct drm_device *dev, void *data,
247 			      struct drm_file *file_private);
248 int drm_syncobj_handle_to_fd_ioctl(struct drm_device *dev, void *data,
249 				   struct drm_file *file_private);
250 int drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,
251 				   struct drm_file *file_private);
252 int drm_syncobj_transfer_ioctl(struct drm_device *dev, void *data,
253 			       struct drm_file *file_private);
254 int drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
255 			   struct drm_file *file_private);
256 int drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
257 				    struct drm_file *file_private);
258 int drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
259 			    struct drm_file *file_private);
260 int drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
261 			     struct drm_file *file_private);
262 int drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
263 				      struct drm_file *file_private);
264 int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
265 			    struct drm_file *file_private);
266 
267 /* drm_framebuffer.c */
268 void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
269 				const struct drm_framebuffer *fb);
270 void drm_framebuffer_debugfs_init(struct drm_minor *minor);
271