Oded Gabbay | 8bf4889 | 2022-10-31 15:28:35 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 |
| 2 | * |
| 3 | * Copyright 2022 HabanaLabs, Ltd. |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef DRM_ACCEL_H_ |
| 9 | #define DRM_ACCEL_H_ |
| 10 | |
Oded Gabbay | 2c204f3 | 2022-10-31 15:33:06 +0200 | [diff] [blame] | 11 | #include <drm/drm_file.h> |
| 12 | |
Oded Gabbay | 8bf4889 | 2022-10-31 15:28:35 +0200 | [diff] [blame] | 13 | #define ACCEL_MAJOR 261 |
Oded Gabbay | 2c204f3 | 2022-10-31 15:33:06 +0200 | [diff] [blame] | 14 | #define ACCEL_MAX_MINORS 256 |
| 15 | |
| 16 | /** |
| 17 | * DRM_ACCEL_FOPS - Default drm accelerators file operations |
| 18 | * |
| 19 | * This macro provides a shorthand for setting the accelerator file ops in the |
| 20 | * &file_operations structure. If all you need are the default ops, use |
| 21 | * DEFINE_DRM_ACCEL_FOPS instead. |
| 22 | */ |
| 23 | #define DRM_ACCEL_FOPS \ |
| 24 | .open = accel_open,\ |
| 25 | .release = drm_release,\ |
| 26 | .unlocked_ioctl = drm_ioctl,\ |
| 27 | .compat_ioctl = drm_compat_ioctl,\ |
| 28 | .poll = drm_poll,\ |
| 29 | .read = drm_read,\ |
Jeffrey Hugo | e868cc5 | 2023-01-17 10:45:58 -0700 | [diff] [blame] | 30 | .llseek = noop_llseek, \ |
Christian Brauner | 641bb43 | 2024-08-09 12:38:56 +0200 | [diff] [blame] | 31 | .mmap = drm_gem_mmap, \ |
| 32 | .fop_flags = FOP_UNSIGNED_OFFSET |
Oded Gabbay | 2c204f3 | 2022-10-31 15:33:06 +0200 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * DEFINE_DRM_ACCEL_FOPS() - macro to generate file operations for accelerators drivers |
| 36 | * @name: name for the generated structure |
| 37 | * |
| 38 | * This macro autogenerates a suitable &struct file_operations for accelerators based |
| 39 | * drivers, which can be assigned to &drm_driver.fops. Note that this structure |
| 40 | * cannot be shared between drivers, because it contains a reference to the |
| 41 | * current module using THIS_MODULE. |
| 42 | * |
| 43 | * Note that the declaration is already marked as static - if you need a |
| 44 | * non-static version of this you're probably doing it wrong and will break the |
| 45 | * THIS_MODULE reference by accident. |
| 46 | */ |
| 47 | #define DEFINE_DRM_ACCEL_FOPS(name) \ |
| 48 | static const struct file_operations name = {\ |
| 49 | .owner = THIS_MODULE,\ |
| 50 | DRM_ACCEL_FOPS,\ |
| 51 | } |
Oded Gabbay | 8bf4889 | 2022-10-31 15:28:35 +0200 | [diff] [blame] | 52 | |
| 53 | #if IS_ENABLED(CONFIG_DRM_ACCEL) |
| 54 | |
Michał Winiarski | 45c4d99 | 2024-08-23 18:30:47 +0200 | [diff] [blame] | 55 | extern struct xarray accel_minors_xa; |
| 56 | |
Oded Gabbay | 8bf4889 | 2022-10-31 15:28:35 +0200 | [diff] [blame] | 57 | void accel_core_exit(void); |
| 58 | int accel_core_init(void); |
Oded Gabbay | 2c204f3 | 2022-10-31 15:33:06 +0200 | [diff] [blame] | 59 | void accel_set_device_instance_params(struct device *kdev, int index); |
| 60 | int accel_open(struct inode *inode, struct file *filp); |
Christian König | 0b30d57 | 2023-08-29 13:01:13 +0200 | [diff] [blame] | 61 | void accel_debugfs_init(struct drm_device *dev); |
| 62 | void accel_debugfs_register(struct drm_device *dev); |
Oded Gabbay | 8bf4889 | 2022-10-31 15:28:35 +0200 | [diff] [blame] | 63 | |
| 64 | #else |
| 65 | |
| 66 | static inline void accel_core_exit(void) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | static inline int __init accel_core_init(void) |
| 71 | { |
| 72 | /* Return 0 to allow drm_core_init to complete successfully */ |
| 73 | return 0; |
| 74 | } |
| 75 | |
Oded Gabbay | 2c204f3 | 2022-10-31 15:33:06 +0200 | [diff] [blame] | 76 | static inline void accel_set_device_instance_params(struct device *kdev, int index) |
| 77 | { |
| 78 | } |
| 79 | |
Christian König | 0b30d57 | 2023-08-29 13:01:13 +0200 | [diff] [blame] | 80 | static inline void accel_debugfs_init(struct drm_device *dev) |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | static inline void accel_debugfs_register(struct drm_device *dev) |
Oded Gabbay | 2c204f3 | 2022-10-31 15:33:06 +0200 | [diff] [blame] | 85 | { |
| 86 | } |
| 87 | |
Oded Gabbay | 8bf4889 | 2022-10-31 15:28:35 +0200 | [diff] [blame] | 88 | #endif /* IS_ENABLED(CONFIG_DRM_ACCEL) */ |
| 89 | |
| 90 | #endif /* DRM_ACCEL_H_ */ |