xref: /linux/drivers/gpu/drm/drm_internal.h (revision c7a472297169156252a50d76965eb36b081186e2)
118882995SDaniel Vetter /*
218882995SDaniel Vetter  * Copyright © 2014 Intel Corporation
318882995SDaniel Vetter  *   Daniel Vetter <daniel.vetter@ffwll.ch>
418882995SDaniel Vetter  *
518882995SDaniel Vetter  * Permission is hereby granted, free of charge, to any person obtaining a
618882995SDaniel Vetter  * copy of this software and associated documentation files (the "Software"),
718882995SDaniel Vetter  * to deal in the Software without restriction, including without limitation
818882995SDaniel Vetter  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
918882995SDaniel Vetter  * and/or sell copies of the Software, and to permit persons to whom the
1018882995SDaniel Vetter  * Software is furnished to do so, subject to the following conditions:
1118882995SDaniel Vetter  *
1218882995SDaniel Vetter  * The above copyright notice and this permission notice shall be included in
1318882995SDaniel Vetter  * all copies or substantial portions of the Software.
1418882995SDaniel Vetter  *
1518882995SDaniel Vetter  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1618882995SDaniel Vetter  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1718882995SDaniel Vetter  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1818882995SDaniel Vetter  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1918882995SDaniel Vetter  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2018882995SDaniel Vetter  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2118882995SDaniel Vetter  * OTHER DEALINGS IN THE SOFTWARE.
2218882995SDaniel Vetter  */
2318882995SDaniel Vetter 
245e6c2b4fSLyude Paul #include <linux/kthread.h>
255e6c2b4fSLyude Paul 
2699f45e32SDaniel Vetter #include <drm/drm_ioctl.h>
275e6c2b4fSLyude Paul #include <drm/drm_vblank.h>
2899f45e32SDaniel Vetter 
2982d5e73fSDavid Herrmann #define DRM_IF_MAJOR 1
3082d5e73fSDavid Herrmann #define DRM_IF_MINOR 4
3182d5e73fSDavid Herrmann 
32ecb2e2fdSSam Ravnborg #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
33ecb2e2fdSSam Ravnborg 
347a44fdceSSam Ravnborg struct dentry;
3599f45e32SDaniel Vetter struct dma_buf;
367938f421SLucas De Marchi struct iosys_map;
377a44fdceSSam Ravnborg struct drm_connector;
387a44fdceSSam Ravnborg struct drm_crtc;
397a44fdceSSam Ravnborg struct drm_framebuffer;
407a44fdceSSam Ravnborg struct drm_gem_object;
417a44fdceSSam Ravnborg struct drm_master;
427a44fdceSSam Ravnborg struct drm_minor;
437a44fdceSSam Ravnborg struct drm_prime_file_private;
447a44fdceSSam Ravnborg struct drm_printer;
455e6c2b4fSLyude Paul struct drm_vblank_crtc;
4699f45e32SDaniel Vetter 
479acdac68SDaniel Vetter /* drm_file.c */
4844af3f5cSDaniel Vetter extern struct mutex drm_global_mutex;
494017ad7bSDaniel Vetter bool drm_dev_needs_global_mutex(struct drm_device *dev);
501572042aSDavid Herrmann struct drm_file *drm_file_alloc(struct drm_minor *minor);
511572042aSDavid Herrmann void drm_file_free(struct drm_file *file);
5268dfbebaSDaniel Vetter void drm_lastclose(struct drm_device *dev);
5367d0ec4eSDaniel Vetter 
545c7a0bb0SThomas Zimmermann #ifdef CONFIG_PCI
555c7a0bb0SThomas Zimmermann 
5667d0ec4eSDaniel Vetter /* drm_pci.c */
575c484ceeSDaniel Vetter int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master);
5867d0ec4eSDaniel Vetter 
595c7a0bb0SThomas Zimmermann #else
605c7a0bb0SThomas Zimmermann 
615c7a0bb0SThomas Zimmermann static inline int drm_pci_set_busid(struct drm_device *dev,
625c7a0bb0SThomas Zimmermann 				    struct drm_master *master)
635c7a0bb0SThomas Zimmermann {
645c7a0bb0SThomas Zimmermann 	return -EINVAL;
655c7a0bb0SThomas Zimmermann }
665c7a0bb0SThomas Zimmermann 
675c7a0bb0SThomas Zimmermann #endif
685c7a0bb0SThomas Zimmermann 
6967d0ec4eSDaniel Vetter /* drm_prime.c */
7067d0ec4eSDaniel Vetter int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
7167d0ec4eSDaniel Vetter 				 struct drm_file *file_priv);
7267d0ec4eSDaniel Vetter int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
7367d0ec4eSDaniel Vetter 				 struct drm_file *file_priv);
7467d0ec4eSDaniel Vetter 
7567d0ec4eSDaniel Vetter void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
7667d0ec4eSDaniel Vetter void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
77ea2aa97cSJeffy Chen void drm_prime_remove_buf_handle(struct drm_prime_file_private *prime_fpriv,
78ea2aa97cSJeffy Chen 				 uint32_t handle);
7967d0ec4eSDaniel Vetter 
8085e634bcSDaniel Vetter /* drm_drv.c */
8185e634bcSDaniel Vetter struct drm_minor *drm_minor_acquire(unsigned int minor_id);
8285e634bcSDaniel Vetter void drm_minor_release(struct drm_minor *minor);
8385e634bcSDaniel Vetter 
84c6603c74SDaniel Vetter /* drm_managed.c */
85c6603c74SDaniel Vetter void drm_managed_release(struct drm_device *dev);
86a7d39439SDaniel Vetter void drmm_add_final_kfree(struct drm_device *dev, void *container);
87c6603c74SDaniel Vetter 
883ed4351aSDaniel Vetter /* drm_vblank.c */
895e6c2b4fSLyude Paul static inline bool drm_vblank_passed(u64 seq, u64 ref)
905e6c2b4fSLyude Paul {
915e6c2b4fSLyude Paul 	return (seq - ref) <= (1 << 23);
925e6c2b4fSLyude Paul }
935e6c2b4fSLyude Paul 
943ed4351aSDaniel Vetter void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe);
955e6c2b4fSLyude Paul int drm_vblank_get(struct drm_device *dev, unsigned int pipe);
965e6c2b4fSLyude Paul void drm_vblank_put(struct drm_device *dev, unsigned int pipe);
975e6c2b4fSLyude Paul u64 drm_vblank_count(struct drm_device *dev, unsigned int pipe);
985e6c2b4fSLyude Paul 
995e6c2b4fSLyude Paul /* drm_vblank_work.c */
1005e6c2b4fSLyude Paul static inline void drm_vblank_flush_worker(struct drm_vblank_crtc *vblank)
1015e6c2b4fSLyude Paul {
1025e6c2b4fSLyude Paul 	kthread_flush_worker(vblank->worker);
1035e6c2b4fSLyude Paul }
1045e6c2b4fSLyude Paul 
1055e6c2b4fSLyude Paul static inline void drm_vblank_destroy_worker(struct drm_vblank_crtc *vblank)
1065e6c2b4fSLyude Paul {
1074979524fSShang XiaoJing 	if (vblank->worker)
1085e6c2b4fSLyude Paul 		kthread_destroy_worker(vblank->worker);
1095e6c2b4fSLyude Paul }
1105e6c2b4fSLyude Paul 
1115e6c2b4fSLyude Paul int drm_vblank_worker_init(struct drm_vblank_crtc *vblank);
1125e6c2b4fSLyude Paul void drm_vblank_cancel_pending_works(struct drm_vblank_crtc *vblank);
1135e6c2b4fSLyude Paul void drm_handle_vblank_works(struct drm_vblank_crtc *vblank);
114b9876d50SDaniel Vetter 
115b9876d50SDaniel Vetter /* IOCTLS */
116b6dcaaacSDaniel Vetter int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
117b9876d50SDaniel Vetter 			  struct drm_file *filp);
118b6dcaaacSDaniel Vetter int drm_legacy_modeset_ctl_ioctl(struct drm_device *dev, void *data,
11967d0ec4eSDaniel Vetter 				 struct drm_file *file_priv);
120b6dcaaacSDaniel Vetter 
121b6dcaaacSDaniel Vetter /* drm_irq.c */
122b6dcaaacSDaniel Vetter 
123b6dcaaacSDaniel Vetter /* IOCTLS */
12461ae2270SDave Airlie #if IS_ENABLED(CONFIG_DRM_LEGACY)
125b6dcaaacSDaniel Vetter int drm_legacy_irq_control(struct drm_device *dev, void *data,
126e7f0a889SDaniel Vetter 			   struct drm_file *file_priv);
12761ae2270SDave Airlie #endif
12867d0ec4eSDaniel Vetter 
1293064abfaSKeith Packard int drm_crtc_get_sequence_ioctl(struct drm_device *dev, void *data,
1303064abfaSKeith Packard 				struct drm_file *filp);
1313064abfaSKeith Packard 
1323064abfaSKeith Packard int drm_crtc_queue_sequence_ioctl(struct drm_device *dev, void *data,
1333064abfaSKeith Packard 				  struct drm_file *filp);
1343064abfaSKeith Packard 
13567d0ec4eSDaniel Vetter /* drm_auth.c */
13667d0ec4eSDaniel Vetter int drm_getmagic(struct drm_device *dev, void *data,
13767d0ec4eSDaniel Vetter 		 struct drm_file *file_priv);
13867d0ec4eSDaniel Vetter int drm_authmagic(struct drm_device *dev, void *data,
13967d0ec4eSDaniel Vetter 		  struct drm_file *file_priv);
1406548f4e7SDaniel Vetter int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1416548f4e7SDaniel Vetter 			struct drm_file *file_priv);
1426548f4e7SDaniel Vetter int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1436548f4e7SDaniel Vetter 			 struct drm_file *file_priv);
1442cbae7e6SDaniel Vetter int drm_master_open(struct drm_file *file_priv);
14514d71ebdSDaniel Vetter void drm_master_release(struct drm_file *file_priv);
14603a9606eSNoralf Trønnes bool drm_master_internal_acquire(struct drm_device *dev);
14703a9606eSNoralf Trønnes void drm_master_internal_release(struct drm_device *dev);
14867d0ec4eSDaniel Vetter 
14967d0ec4eSDaniel Vetter /* drm_sysfs.c */
15000285be8SDaniel Vetter extern struct class *drm_class;
15100285be8SDaniel Vetter 
152fcc90213SDavid Herrmann int drm_sysfs_init(void);
15367d0ec4eSDaniel Vetter void drm_sysfs_destroy(void);
15467d0ec4eSDaniel Vetter struct device *drm_sysfs_minor_alloc(struct drm_minor *minor);
15567d0ec4eSDaniel Vetter int drm_sysfs_connector_add(struct drm_connector *connector);
15667d0ec4eSDaniel Vetter void drm_sysfs_connector_remove(struct drm_connector *connector);
15767d0ec4eSDaniel Vetter 
158ce858828SDaniel Vetter void drm_sysfs_lease_event(struct drm_device *dev);
159ce858828SDaniel Vetter 
16067d0ec4eSDaniel Vetter /* drm_gem.c */
16167d0ec4eSDaniel Vetter int drm_gem_init(struct drm_device *dev);
16267d0ec4eSDaniel Vetter int drm_gem_handle_create_tail(struct drm_file *file_priv,
16367d0ec4eSDaniel Vetter 			       struct drm_gem_object *obj,
16467d0ec4eSDaniel Vetter 			       u32 *handlep);
16567d0ec4eSDaniel Vetter int drm_gem_close_ioctl(struct drm_device *dev, void *data,
16667d0ec4eSDaniel Vetter 			struct drm_file *file_priv);
16767d0ec4eSDaniel Vetter int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
16867d0ec4eSDaniel Vetter 			struct drm_file *file_priv);
16967d0ec4eSDaniel Vetter int drm_gem_open_ioctl(struct drm_device *dev, void *data,
17067d0ec4eSDaniel Vetter 		       struct drm_file *file_priv);
17167d0ec4eSDaniel Vetter void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
17267d0ec4eSDaniel Vetter void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
17345d58b40SNoralf Trønnes void drm_gem_print_info(struct drm_printer *p, unsigned int indent,
17445d58b40SNoralf Trønnes 			const struct drm_gem_object *obj);
175e7f0a889SDaniel Vetter 
176eb69c8a4SDaniel Vetter int drm_gem_pin(struct drm_gem_object *obj);
177eb69c8a4SDaniel Vetter void drm_gem_unpin(struct drm_gem_object *obj);
1787938f421SLucas De Marchi int drm_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map);
1797938f421SLucas De Marchi void drm_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map);
180eb69c8a4SDaniel Vetter 
1810cad7f71SDaniel Vetter /* drm_debugfs.c drm_debugfs_crc.c */
182c2611031SDaniel Vetter #if defined(CONFIG_DEBUG_FS)
183c2611031SDaniel Vetter int drm_debugfs_init(struct drm_minor *minor, int minor_id,
184c2611031SDaniel Vetter 		     struct dentry *root);
185b792e640SGreg Kroah-Hartman void drm_debugfs_cleanup(struct drm_minor *minor);
186dbb23cf5SMaíra Canal void drm_debugfs_late_register(struct drm_device *dev);
187b792e640SGreg Kroah-Hartman void drm_debugfs_connector_add(struct drm_connector *connector);
188c2611031SDaniel Vetter void drm_debugfs_connector_remove(struct drm_connector *connector);
189b792e640SGreg Kroah-Hartman void drm_debugfs_crtc_add(struct drm_crtc *crtc);
1909edbf1faSTomeu Vizoso void drm_debugfs_crtc_remove(struct drm_crtc *crtc);
191b792e640SGreg Kroah-Hartman void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc);
192c2611031SDaniel Vetter #else
193c2611031SDaniel Vetter static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id,
194c2611031SDaniel Vetter 				   struct dentry *root)
195c2611031SDaniel Vetter {
196c2611031SDaniel Vetter 	return 0;
197c2611031SDaniel Vetter }
198c2611031SDaniel Vetter 
199b792e640SGreg Kroah-Hartman static inline void drm_debugfs_cleanup(struct drm_minor *minor)
200c2611031SDaniel Vetter {
201c2611031SDaniel Vetter }
202c2611031SDaniel Vetter 
203dbb23cf5SMaíra Canal static inline void drm_debugfs_late_register(struct drm_device *dev)
204dbb23cf5SMaíra Canal {
205dbb23cf5SMaíra Canal }
206dbb23cf5SMaíra Canal 
207b792e640SGreg Kroah-Hartman static inline void drm_debugfs_connector_add(struct drm_connector *connector)
208c2611031SDaniel Vetter {
209c2611031SDaniel Vetter }
210c2611031SDaniel Vetter static inline void drm_debugfs_connector_remove(struct drm_connector *connector)
211c2611031SDaniel Vetter {
212c2611031SDaniel Vetter }
2139edbf1faSTomeu Vizoso 
214b792e640SGreg Kroah-Hartman static inline void drm_debugfs_crtc_add(struct drm_crtc *crtc)
2159edbf1faSTomeu Vizoso {
2169edbf1faSTomeu Vizoso }
2179edbf1faSTomeu Vizoso static inline void drm_debugfs_crtc_remove(struct drm_crtc *crtc)
2189edbf1faSTomeu Vizoso {
2199edbf1faSTomeu Vizoso }
2209edbf1faSTomeu Vizoso 
221b792e640SGreg Kroah-Hartman static inline void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc)
2229edbf1faSTomeu Vizoso {
2239edbf1faSTomeu Vizoso }
224e9083420SDave Airlie 
225c2611031SDaniel Vetter #endif
226e9083420SDave Airlie 
227012c6741SAl Viro drm_ioctl_t drm_version;
22817e3dadeSAl Viro drm_ioctl_t drm_getunique;
2299e92662dSAl Viro drm_ioctl_t drm_getclient;
230af3c8d98SLinus Torvalds 
231e9083420SDave Airlie /* drm_syncobj.c */
232e9083420SDave Airlie void drm_syncobj_open(struct drm_file *file_private);
233e9083420SDave Airlie void drm_syncobj_release(struct drm_file *file_private);
234e9083420SDave Airlie int drm_syncobj_create_ioctl(struct drm_device *dev, void *data,
235e9083420SDave Airlie 			     struct drm_file *file_private);
236e9083420SDave Airlie int drm_syncobj_destroy_ioctl(struct drm_device *dev, void *data,
237e9083420SDave Airlie 			      struct drm_file *file_private);
238e9083420SDave Airlie int drm_syncobj_handle_to_fd_ioctl(struct drm_device *dev, void *data,
239e9083420SDave Airlie 				   struct drm_file *file_private);
240e9083420SDave Airlie int drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,
241e9083420SDave Airlie 				   struct drm_file *file_private);
242ea569910SChunming Zhou int drm_syncobj_transfer_ioctl(struct drm_device *dev, void *data,
243ea569910SChunming Zhou 			       struct drm_file *file_private);
2445e60a10eSDave Airlie int drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
2455e60a10eSDave Airlie 			   struct drm_file *file_private);
24601d6c357SChunming Zhou int drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
24701d6c357SChunming Zhou 				    struct drm_file *file_private);
248*c7a47229SSimon Ser int drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data,
249*c7a47229SSimon Ser 			      struct drm_file *file_private);
250aa4035d2SJason Ekstrand int drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
251aa4035d2SJason Ekstrand 			    struct drm_file *file_private);
252ffa9443fSJason Ekstrand int drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
253ffa9443fSJason Ekstrand 			     struct drm_file *file_private);
25450d1ebefSChunming Zhou int drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
25550d1ebefSChunming Zhou 				      struct drm_file *file_private);
25627b575a9SChunming Zhou int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
25727b575a9SChunming Zhou 			    struct drm_file *file_private);
25845d58b40SNoralf Trønnes 
25945d58b40SNoralf Trønnes /* drm_framebuffer.c */
26045d58b40SNoralf Trønnes void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
26145d58b40SNoralf Trønnes 				const struct drm_framebuffer *fb);
2627ce84471SWambui Karuga void drm_framebuffer_debugfs_init(struct drm_minor *minor);
263