xref: /linux/include/drm/drm_accel.h (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
18bf48897SOded Gabbay /* SPDX-License-Identifier: GPL-2.0
28bf48897SOded Gabbay  *
38bf48897SOded Gabbay  * Copyright 2022 HabanaLabs, Ltd.
48bf48897SOded Gabbay  * All Rights Reserved.
58bf48897SOded Gabbay  *
68bf48897SOded Gabbay  */
78bf48897SOded Gabbay 
88bf48897SOded Gabbay #ifndef DRM_ACCEL_H_
98bf48897SOded Gabbay #define DRM_ACCEL_H_
108bf48897SOded Gabbay 
112c204f3dSOded Gabbay #include <drm/drm_file.h>
122c204f3dSOded Gabbay 
138bf48897SOded Gabbay #define ACCEL_MAJOR		261
142c204f3dSOded Gabbay #define ACCEL_MAX_MINORS	256
152c204f3dSOded Gabbay 
162c204f3dSOded Gabbay /**
172c204f3dSOded Gabbay  * DRM_ACCEL_FOPS - Default drm accelerators file operations
182c204f3dSOded Gabbay  *
192c204f3dSOded Gabbay  * This macro provides a shorthand for setting the accelerator file ops in the
202c204f3dSOded Gabbay  * &file_operations structure.  If all you need are the default ops, use
212c204f3dSOded Gabbay  * DEFINE_DRM_ACCEL_FOPS instead.
222c204f3dSOded Gabbay  */
232c204f3dSOded Gabbay #define DRM_ACCEL_FOPS \
242c204f3dSOded Gabbay 	.open		= accel_open,\
252c204f3dSOded Gabbay 	.release	= drm_release,\
262c204f3dSOded Gabbay 	.unlocked_ioctl	= drm_ioctl,\
272c204f3dSOded Gabbay 	.compat_ioctl	= drm_compat_ioctl,\
282c204f3dSOded Gabbay 	.poll		= drm_poll,\
292c204f3dSOded Gabbay 	.read		= drm_read,\
30e868cc59SJeffrey Hugo 	.llseek		= noop_llseek, \
31641bb439SChristian Brauner 	.mmap		= drm_gem_mmap, \
32641bb439SChristian Brauner 	.fop_flags	= FOP_UNSIGNED_OFFSET
332c204f3dSOded Gabbay 
342c204f3dSOded Gabbay /**
352c204f3dSOded Gabbay  * DEFINE_DRM_ACCEL_FOPS() - macro to generate file operations for accelerators drivers
362c204f3dSOded Gabbay  * @name: name for the generated structure
372c204f3dSOded Gabbay  *
382c204f3dSOded Gabbay  * This macro autogenerates a suitable &struct file_operations for accelerators based
392c204f3dSOded Gabbay  * drivers, which can be assigned to &drm_driver.fops. Note that this structure
402c204f3dSOded Gabbay  * cannot be shared between drivers, because it contains a reference to the
412c204f3dSOded Gabbay  * current module using THIS_MODULE.
422c204f3dSOded Gabbay  *
432c204f3dSOded Gabbay  * Note that the declaration is already marked as static - if you need a
442c204f3dSOded Gabbay  * non-static version of this you're probably doing it wrong and will break the
452c204f3dSOded Gabbay  * THIS_MODULE reference by accident.
462c204f3dSOded Gabbay  */
472c204f3dSOded Gabbay #define DEFINE_DRM_ACCEL_FOPS(name) \
482c204f3dSOded Gabbay 	static const struct file_operations name = {\
492c204f3dSOded Gabbay 		.owner		= THIS_MODULE,\
502c204f3dSOded Gabbay 		DRM_ACCEL_FOPS,\
512c204f3dSOded Gabbay 	}
528bf48897SOded Gabbay 
538bf48897SOded Gabbay #if IS_ENABLED(CONFIG_DRM_ACCEL)
548bf48897SOded Gabbay 
55*45c4d994SMichał Winiarski extern struct xarray accel_minors_xa;
56*45c4d994SMichał Winiarski 
578bf48897SOded Gabbay void accel_core_exit(void);
588bf48897SOded Gabbay int accel_core_init(void);
592c204f3dSOded Gabbay void accel_set_device_instance_params(struct device *kdev, int index);
602c204f3dSOded Gabbay int accel_open(struct inode *inode, struct file *filp);
610b30d57aSChristian König void accel_debugfs_init(struct drm_device *dev);
620b30d57aSChristian König void accel_debugfs_register(struct drm_device *dev);
638bf48897SOded Gabbay 
648bf48897SOded Gabbay #else
658bf48897SOded Gabbay 
accel_core_exit(void)668bf48897SOded Gabbay static inline void accel_core_exit(void)
678bf48897SOded Gabbay {
688bf48897SOded Gabbay }
698bf48897SOded Gabbay 
accel_core_init(void)708bf48897SOded Gabbay static inline int __init accel_core_init(void)
718bf48897SOded Gabbay {
728bf48897SOded Gabbay 	/* Return 0 to allow drm_core_init to complete successfully */
738bf48897SOded Gabbay 	return 0;
748bf48897SOded Gabbay }
758bf48897SOded Gabbay 
accel_set_device_instance_params(struct device * kdev,int index)762c204f3dSOded Gabbay static inline void accel_set_device_instance_params(struct device *kdev, int index)
772c204f3dSOded Gabbay {
782c204f3dSOded Gabbay }
792c204f3dSOded Gabbay 
accel_debugfs_init(struct drm_device * dev)800b30d57aSChristian König static inline void accel_debugfs_init(struct drm_device *dev)
810b30d57aSChristian König {
820b30d57aSChristian König }
830b30d57aSChristian König 
accel_debugfs_register(struct drm_device * dev)840b30d57aSChristian König static inline void accel_debugfs_register(struct drm_device *dev)
852c204f3dSOded Gabbay {
862c204f3dSOded Gabbay }
872c204f3dSOded Gabbay 
888bf48897SOded Gabbay #endif /* IS_ENABLED(CONFIG_DRM_ACCEL) */
898bf48897SOded Gabbay 
908bf48897SOded Gabbay #endif /* DRM_ACCEL_H_ */
91