xref: /linux/include/drm/drm_accel.h (revision e868cc591e89cf735a11fb24f38d48c7574c4d01)
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,\
30*e868cc59SJeffrey Hugo 	.llseek		= noop_llseek, \
31*e868cc59SJeffrey Hugo 	.mmap		= drm_gem_mmap
322c204f3dSOded Gabbay 
332c204f3dSOded Gabbay /**
342c204f3dSOded Gabbay  * DEFINE_DRM_ACCEL_FOPS() - macro to generate file operations for accelerators drivers
352c204f3dSOded Gabbay  * @name: name for the generated structure
362c204f3dSOded Gabbay  *
372c204f3dSOded Gabbay  * This macro autogenerates a suitable &struct file_operations for accelerators based
382c204f3dSOded Gabbay  * drivers, which can be assigned to &drm_driver.fops. Note that this structure
392c204f3dSOded Gabbay  * cannot be shared between drivers, because it contains a reference to the
402c204f3dSOded Gabbay  * current module using THIS_MODULE.
412c204f3dSOded Gabbay  *
422c204f3dSOded Gabbay  * Note that the declaration is already marked as static - if you need a
432c204f3dSOded Gabbay  * non-static version of this you're probably doing it wrong and will break the
442c204f3dSOded Gabbay  * THIS_MODULE reference by accident.
452c204f3dSOded Gabbay  */
462c204f3dSOded Gabbay #define DEFINE_DRM_ACCEL_FOPS(name) \
472c204f3dSOded Gabbay 	static const struct file_operations name = {\
482c204f3dSOded Gabbay 		.owner		= THIS_MODULE,\
492c204f3dSOded Gabbay 		DRM_ACCEL_FOPS,\
502c204f3dSOded Gabbay 	}
518bf48897SOded Gabbay 
528bf48897SOded Gabbay #if IS_ENABLED(CONFIG_DRM_ACCEL)
538bf48897SOded Gabbay 
548bf48897SOded Gabbay void accel_core_exit(void);
558bf48897SOded Gabbay int accel_core_init(void);
562c204f3dSOded Gabbay void accel_minor_remove(int index);
572c204f3dSOded Gabbay int accel_minor_alloc(void);
582c204f3dSOded Gabbay void accel_minor_replace(struct drm_minor *minor, int index);
592c204f3dSOded Gabbay void accel_set_device_instance_params(struct device *kdev, int index);
602c204f3dSOded Gabbay int accel_open(struct inode *inode, struct file *filp);
612c204f3dSOded Gabbay void accel_debugfs_init(struct drm_minor *minor, int minor_id);
628bf48897SOded Gabbay 
638bf48897SOded Gabbay #else
648bf48897SOded Gabbay 
658bf48897SOded Gabbay static inline void accel_core_exit(void)
668bf48897SOded Gabbay {
678bf48897SOded Gabbay }
688bf48897SOded Gabbay 
698bf48897SOded Gabbay static inline int __init accel_core_init(void)
708bf48897SOded Gabbay {
718bf48897SOded Gabbay 	/* Return 0 to allow drm_core_init to complete successfully */
728bf48897SOded Gabbay 	return 0;
738bf48897SOded Gabbay }
748bf48897SOded Gabbay 
752c204f3dSOded Gabbay static inline void accel_minor_remove(int index)
762c204f3dSOded Gabbay {
772c204f3dSOded Gabbay }
782c204f3dSOded Gabbay 
792c204f3dSOded Gabbay static inline int accel_minor_alloc(void)
802c204f3dSOded Gabbay {
812c204f3dSOded Gabbay 	return -EOPNOTSUPP;
822c204f3dSOded Gabbay }
832c204f3dSOded Gabbay 
842c204f3dSOded Gabbay static inline void accel_minor_replace(struct drm_minor *minor, int index)
852c204f3dSOded Gabbay {
862c204f3dSOded Gabbay }
872c204f3dSOded Gabbay 
882c204f3dSOded Gabbay static inline void accel_set_device_instance_params(struct device *kdev, int index)
892c204f3dSOded Gabbay {
902c204f3dSOded Gabbay }
912c204f3dSOded Gabbay 
922c204f3dSOded Gabbay static inline void accel_debugfs_init(struct drm_minor *minor, int minor_id)
932c204f3dSOded Gabbay {
942c204f3dSOded Gabbay }
952c204f3dSOded Gabbay 
968bf48897SOded Gabbay #endif /* IS_ENABLED(CONFIG_DRM_ACCEL) */
978bf48897SOded Gabbay 
988bf48897SOded Gabbay #endif /* DRM_ACCEL_H_ */
99