Kenneth Lee | 015d239 | 2020-02-11 15:54:23 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | #ifndef _LINUX_UACCE_H |
| 3 | #define _LINUX_UACCE_H |
| 4 | |
| 5 | #include <linux/cdev.h> |
| 6 | #include <uapi/misc/uacce/uacce.h> |
| 7 | |
| 8 | #define UACCE_NAME "uacce" |
| 9 | #define UACCE_MAX_REGION 2 |
| 10 | #define UACCE_MAX_NAME_SIZE 64 |
| 11 | |
| 12 | struct uacce_queue; |
| 13 | struct uacce_device; |
| 14 | |
| 15 | /** |
| 16 | * struct uacce_qfile_region - structure of queue file region |
| 17 | * @type: type of the region |
| 18 | */ |
| 19 | struct uacce_qfile_region { |
| 20 | enum uacce_qfrt type; |
| 21 | }; |
| 22 | |
| 23 | /** |
| 24 | * struct uacce_ops - uacce device operations |
| 25 | * @get_available_instances: get available instances left of the device |
| 26 | * @get_queue: get a queue from the device |
| 27 | * @put_queue: free a queue to the device |
| 28 | * @start_queue: make the queue start work after get_queue |
| 29 | * @stop_queue: make the queue stop work before put_queue |
| 30 | * @is_q_updated: check whether the task is finished |
| 31 | * @mmap: mmap addresses of queue to user space |
| 32 | * @ioctl: ioctl for user space users of the queue |
| 33 | */ |
| 34 | struct uacce_ops { |
| 35 | int (*get_available_instances)(struct uacce_device *uacce); |
| 36 | int (*get_queue)(struct uacce_device *uacce, unsigned long arg, |
| 37 | struct uacce_queue *q); |
| 38 | void (*put_queue)(struct uacce_queue *q); |
| 39 | int (*start_queue)(struct uacce_queue *q); |
| 40 | void (*stop_queue)(struct uacce_queue *q); |
| 41 | int (*is_q_updated)(struct uacce_queue *q); |
| 42 | int (*mmap)(struct uacce_queue *q, struct vm_area_struct *vma, |
| 43 | struct uacce_qfile_region *qfr); |
| 44 | long (*ioctl)(struct uacce_queue *q, unsigned int cmd, |
| 45 | unsigned long arg); |
| 46 | }; |
| 47 | |
| 48 | /** |
| 49 | * struct uacce_interface - interface required for uacce_register() |
| 50 | * @name: the uacce device name. Will show up in sysfs |
| 51 | * @flags: uacce device attributes |
| 52 | * @ops: pointer to the struct uacce_ops |
| 53 | */ |
| 54 | struct uacce_interface { |
| 55 | char name[UACCE_MAX_NAME_SIZE]; |
| 56 | unsigned int flags; |
| 57 | const struct uacce_ops *ops; |
| 58 | }; |
| 59 | |
| 60 | enum uacce_q_state { |
| 61 | UACCE_Q_ZOMBIE = 0, |
| 62 | UACCE_Q_INIT, |
| 63 | UACCE_Q_STARTED, |
| 64 | }; |
| 65 | |
| 66 | /** |
| 67 | * struct uacce_queue |
| 68 | * @uacce: pointer to uacce |
| 69 | * @priv: private pointer |
| 70 | * @wait: wait queue head |
Jean-Philippe Brucker | fb01562 | 2020-04-23 14:53:28 +0200 | [diff] [blame^] | 71 | * @list: index into uacce queues list |
Kenneth Lee | 015d239 | 2020-02-11 15:54:23 +0800 | [diff] [blame] | 72 | * @qfrs: pointer of qfr regions |
| 73 | * @state: queue state machine |
Jean-Philippe Brucker | fb01562 | 2020-04-23 14:53:28 +0200 | [diff] [blame^] | 74 | * @pasid: pasid associated to the mm |
| 75 | * @handle: iommu_sva handle returned by iommu_sva_bind_device() |
Kenneth Lee | 015d239 | 2020-02-11 15:54:23 +0800 | [diff] [blame] | 76 | */ |
| 77 | struct uacce_queue { |
| 78 | struct uacce_device *uacce; |
| 79 | void *priv; |
| 80 | wait_queue_head_t wait; |
| 81 | struct list_head list; |
Kenneth Lee | 015d239 | 2020-02-11 15:54:23 +0800 | [diff] [blame] | 82 | struct uacce_qfile_region *qfrs[UACCE_MAX_REGION]; |
| 83 | enum uacce_q_state state; |
Jean-Philippe Brucker | fb01562 | 2020-04-23 14:53:28 +0200 | [diff] [blame^] | 84 | int pasid; |
| 85 | struct iommu_sva *handle; |
Kenneth Lee | 015d239 | 2020-02-11 15:54:23 +0800 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | /** |
| 89 | * struct uacce_device |
| 90 | * @algs: supported algorithms |
| 91 | * @api_ver: api version |
| 92 | * @ops: pointer to the struct uacce_ops |
| 93 | * @qf_pg_num: page numbers of the queue file regions |
| 94 | * @parent: pointer to the parent device |
| 95 | * @is_vf: whether virtual function |
| 96 | * @flags: uacce attributes |
| 97 | * @dev_id: id of the uacce device |
| 98 | * @cdev: cdev of the uacce |
| 99 | * @dev: dev of the uacce |
| 100 | * @priv: private pointer of the uacce |
Jean-Philippe Brucker | fb01562 | 2020-04-23 14:53:28 +0200 | [diff] [blame^] | 101 | * @queues: list of queues |
| 102 | * @queues_lock: lock for queues list |
Zhangfei Gao | acc670d | 2020-02-26 15:12:06 +0800 | [diff] [blame] | 103 | * @inode: core vfs |
Kenneth Lee | 015d239 | 2020-02-11 15:54:23 +0800 | [diff] [blame] | 104 | */ |
| 105 | struct uacce_device { |
| 106 | const char *algs; |
| 107 | const char *api_ver; |
| 108 | const struct uacce_ops *ops; |
| 109 | unsigned long qf_pg_num[UACCE_MAX_REGION]; |
| 110 | struct device *parent; |
| 111 | bool is_vf; |
| 112 | u32 flags; |
| 113 | u32 dev_id; |
| 114 | struct cdev *cdev; |
| 115 | struct device dev; |
| 116 | void *priv; |
Kenneth Lee | 015d239 | 2020-02-11 15:54:23 +0800 | [diff] [blame] | 117 | struct list_head queues; |
Jean-Philippe Brucker | fb01562 | 2020-04-23 14:53:28 +0200 | [diff] [blame^] | 118 | struct mutex queues_lock; |
| 119 | struct inode *inode; |
Kenneth Lee | 015d239 | 2020-02-11 15:54:23 +0800 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | #if IS_ENABLED(CONFIG_UACCE) |
| 123 | |
| 124 | struct uacce_device *uacce_alloc(struct device *parent, |
| 125 | struct uacce_interface *interface); |
| 126 | int uacce_register(struct uacce_device *uacce); |
| 127 | void uacce_remove(struct uacce_device *uacce); |
| 128 | |
| 129 | #else /* CONFIG_UACCE */ |
| 130 | |
| 131 | static inline |
| 132 | struct uacce_device *uacce_alloc(struct device *parent, |
| 133 | struct uacce_interface *interface) |
| 134 | { |
| 135 | return ERR_PTR(-ENODEV); |
| 136 | } |
| 137 | |
| 138 | static inline int uacce_register(struct uacce_device *uacce) |
| 139 | { |
| 140 | return -EINVAL; |
| 141 | } |
| 142 | |
| 143 | static inline void uacce_remove(struct uacce_device *uacce) {} |
| 144 | |
| 145 | #endif /* CONFIG_UACCE */ |
| 146 | |
| 147 | #endif /* _LINUX_UACCE_H */ |