0001
0002 #ifndef _LINUX_UACCE_H
0003 #define _LINUX_UACCE_H
0004
0005 #include <linux/cdev.h>
0006 #include <uapi/misc/uacce/uacce.h>
0007
0008 #define UACCE_NAME "uacce"
0009 #define UACCE_MAX_REGION 2
0010 #define UACCE_MAX_NAME_SIZE 64
0011
0012 struct uacce_queue;
0013 struct uacce_device;
0014
0015
0016
0017
0018
0019 struct uacce_qfile_region {
0020 enum uacce_qfrt type;
0021 };
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 struct uacce_ops {
0035 int (*get_available_instances)(struct uacce_device *uacce);
0036 int (*get_queue)(struct uacce_device *uacce, unsigned long arg,
0037 struct uacce_queue *q);
0038 void (*put_queue)(struct uacce_queue *q);
0039 int (*start_queue)(struct uacce_queue *q);
0040 void (*stop_queue)(struct uacce_queue *q);
0041 int (*is_q_updated)(struct uacce_queue *q);
0042 int (*mmap)(struct uacce_queue *q, struct vm_area_struct *vma,
0043 struct uacce_qfile_region *qfr);
0044 long (*ioctl)(struct uacce_queue *q, unsigned int cmd,
0045 unsigned long arg);
0046 };
0047
0048
0049
0050
0051
0052
0053
0054 struct uacce_interface {
0055 char name[UACCE_MAX_NAME_SIZE];
0056 unsigned int flags;
0057 const struct uacce_ops *ops;
0058 };
0059
0060 enum uacce_q_state {
0061 UACCE_Q_ZOMBIE = 0,
0062 UACCE_Q_INIT,
0063 UACCE_Q_STARTED,
0064 };
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 struct uacce_queue {
0079 struct uacce_device *uacce;
0080 void *priv;
0081 wait_queue_head_t wait;
0082 struct list_head list;
0083 struct uacce_qfile_region *qfrs[UACCE_MAX_REGION];
0084 struct mutex mutex;
0085 enum uacce_q_state state;
0086 u32 pasid;
0087 struct iommu_sva *handle;
0088 };
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107 struct uacce_device {
0108 const char *algs;
0109 const char *api_ver;
0110 const struct uacce_ops *ops;
0111 unsigned long qf_pg_num[UACCE_MAX_REGION];
0112 struct device *parent;
0113 bool is_vf;
0114 u32 flags;
0115 u32 dev_id;
0116 struct cdev *cdev;
0117 struct device dev;
0118 struct mutex mutex;
0119 void *priv;
0120 struct list_head queues;
0121 struct inode *inode;
0122 };
0123
0124 #if IS_ENABLED(CONFIG_UACCE)
0125
0126 struct uacce_device *uacce_alloc(struct device *parent,
0127 struct uacce_interface *interface);
0128 int uacce_register(struct uacce_device *uacce);
0129 void uacce_remove(struct uacce_device *uacce);
0130
0131 #else
0132
0133 static inline
0134 struct uacce_device *uacce_alloc(struct device *parent,
0135 struct uacce_interface *interface)
0136 {
0137 return ERR_PTR(-ENODEV);
0138 }
0139
0140 static inline int uacce_register(struct uacce_device *uacce)
0141 {
0142 return -EINVAL;
0143 }
0144
0145 static inline void uacce_remove(struct uacce_device *uacce) {}
0146
0147 #endif
0148
0149 #endif