Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
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  * struct uacce_qfile_region - structure of queue file region
0017  * @type: type of the region
0018  */
0019 struct uacce_qfile_region {
0020     enum uacce_qfrt type;
0021 };
0022 
0023 /**
0024  * struct uacce_ops - uacce device operations
0025  * @get_available_instances:  get available instances left of the device
0026  * @get_queue: get a queue from the device
0027  * @put_queue: free a queue to the device
0028  * @start_queue: make the queue start work after get_queue
0029  * @stop_queue: make the queue stop work before put_queue
0030  * @is_q_updated: check whether the task is finished
0031  * @mmap: mmap addresses of queue to user space
0032  * @ioctl: ioctl for user space users of the queue
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  * struct uacce_interface - interface required for uacce_register()
0050  * @name: the uacce device name.  Will show up in sysfs
0051  * @flags: uacce device attributes
0052  * @ops: pointer to the struct uacce_ops
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  * struct uacce_queue
0068  * @uacce: pointer to uacce
0069  * @priv: private pointer
0070  * @wait: wait queue head
0071  * @list: index into uacce queues list
0072  * @qfrs: pointer of qfr regions
0073  * @mutex: protects queue state
0074  * @state: queue state machine
0075  * @pasid: pasid associated to the mm
0076  * @handle: iommu_sva handle returned by iommu_sva_bind_device()
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  * struct uacce_device
0092  * @algs: supported algorithms
0093  * @api_ver: api version
0094  * @ops: pointer to the struct uacce_ops
0095  * @qf_pg_num: page numbers of the queue file regions
0096  * @parent: pointer to the parent device
0097  * @is_vf: whether virtual function
0098  * @flags: uacce attributes
0099  * @dev_id: id of the uacce device
0100  * @cdev: cdev of the uacce
0101  * @dev: dev of the uacce
0102  * @mutex: protects uacce operation
0103  * @priv: private pointer of the uacce
0104  * @queues: list of queues
0105  * @inode: core vfs
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 /* CONFIG_UACCE */
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 /* CONFIG_UACCE */
0148 
0149 #endif /* _LINUX_UACCE_H */