Commit | Line | Data |
---|---|---|
015d239a KL |
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 | |
e3e289fb | 11 | #define UACCE_MAX_ERR_THRESHOLD 65535 |
015d239a KL |
12 | |
13 | struct uacce_queue; | |
14 | struct uacce_device; | |
15 | ||
16 | /** | |
17 | * struct uacce_qfile_region - structure of queue file region | |
18 | * @type: type of the region | |
19 | */ | |
20 | struct uacce_qfile_region { | |
21 | enum uacce_qfrt type; | |
22 | }; | |
23 | ||
24 | /** | |
25 | * struct uacce_ops - uacce device operations | |
26 | * @get_available_instances: get available instances left of the device | |
27 | * @get_queue: get a queue from the device | |
28 | * @put_queue: free a queue to the device | |
29 | * @start_queue: make the queue start work after get_queue | |
30 | * @stop_queue: make the queue stop work before put_queue | |
31 | * @is_q_updated: check whether the task is finished | |
32 | * @mmap: mmap addresses of queue to user space | |
33 | * @ioctl: ioctl for user space users of the queue | |
e3e289fb KY |
34 | * @get_isolate_state: get the device state after set the isolate strategy |
35 | * @isolate_err_threshold_write: stored the isolate error threshold to the device | |
36 | * @isolate_err_threshold_read: read the isolate error threshold value from the device | |
015d239a KL |
37 | */ |
38 | struct uacce_ops { | |
39 | int (*get_available_instances)(struct uacce_device *uacce); | |
40 | int (*get_queue)(struct uacce_device *uacce, unsigned long arg, | |
41 | struct uacce_queue *q); | |
42 | void (*put_queue)(struct uacce_queue *q); | |
43 | int (*start_queue)(struct uacce_queue *q); | |
44 | void (*stop_queue)(struct uacce_queue *q); | |
45 | int (*is_q_updated)(struct uacce_queue *q); | |
46 | int (*mmap)(struct uacce_queue *q, struct vm_area_struct *vma, | |
47 | struct uacce_qfile_region *qfr); | |
48 | long (*ioctl)(struct uacce_queue *q, unsigned int cmd, | |
49 | unsigned long arg); | |
e3e289fb KY |
50 | enum uacce_dev_state (*get_isolate_state)(struct uacce_device *uacce); |
51 | int (*isolate_err_threshold_write)(struct uacce_device *uacce, u32 num); | |
52 | u32 (*isolate_err_threshold_read)(struct uacce_device *uacce); | |
015d239a KL |
53 | }; |
54 | ||
55 | /** | |
56 | * struct uacce_interface - interface required for uacce_register() | |
57 | * @name: the uacce device name. Will show up in sysfs | |
58 | * @flags: uacce device attributes | |
59 | * @ops: pointer to the struct uacce_ops | |
60 | */ | |
61 | struct uacce_interface { | |
62 | char name[UACCE_MAX_NAME_SIZE]; | |
63 | unsigned int flags; | |
64 | const struct uacce_ops *ops; | |
65 | }; | |
66 | ||
e3e289fb KY |
67 | enum uacce_dev_state { |
68 | UACCE_DEV_NORMAL, | |
69 | UACCE_DEV_ISOLATE, | |
70 | }; | |
71 | ||
015d239a KL |
72 | enum uacce_q_state { |
73 | UACCE_Q_ZOMBIE = 0, | |
74 | UACCE_Q_INIT, | |
75 | UACCE_Q_STARTED, | |
76 | }; | |
77 | ||
78 | /** | |
79 | * struct uacce_queue | |
80 | * @uacce: pointer to uacce | |
81 | * @priv: private pointer | |
82 | * @wait: wait queue head | |
fb01562e | 83 | * @list: index into uacce queues list |
015d239a | 84 | * @qfrs: pointer of qfr regions |
80fc671b | 85 | * @mutex: protects queue state |
015d239a | 86 | * @state: queue state machine |
fb01562e JPB |
87 | * @pasid: pasid associated to the mm |
88 | * @handle: iommu_sva handle returned by iommu_sva_bind_device() | |
015d239a KL |
89 | */ |
90 | struct uacce_queue { | |
91 | struct uacce_device *uacce; | |
92 | void *priv; | |
93 | wait_queue_head_t wait; | |
94 | struct list_head list; | |
015d239a | 95 | struct uacce_qfile_region *qfrs[UACCE_MAX_REGION]; |
80fc671b | 96 | struct mutex mutex; |
015d239a | 97 | enum uacce_q_state state; |
c7b6bac9 | 98 | u32 pasid; |
fb01562e | 99 | struct iommu_sva *handle; |
015d239a KL |
100 | }; |
101 | ||
102 | /** | |
103 | * struct uacce_device | |
104 | * @algs: supported algorithms | |
105 | * @api_ver: api version | |
106 | * @ops: pointer to the struct uacce_ops | |
107 | * @qf_pg_num: page numbers of the queue file regions | |
108 | * @parent: pointer to the parent device | |
109 | * @is_vf: whether virtual function | |
110 | * @flags: uacce attributes | |
111 | * @dev_id: id of the uacce device | |
112 | * @cdev: cdev of the uacce | |
113 | * @dev: dev of the uacce | |
80fc671b | 114 | * @mutex: protects uacce operation |
015d239a | 115 | * @priv: private pointer of the uacce |
fb01562e | 116 | * @queues: list of queues |
acc670db | 117 | * @inode: core vfs |
015d239a KL |
118 | */ |
119 | struct uacce_device { | |
120 | const char *algs; | |
121 | const char *api_ver; | |
122 | const struct uacce_ops *ops; | |
123 | unsigned long qf_pg_num[UACCE_MAX_REGION]; | |
124 | struct device *parent; | |
125 | bool is_vf; | |
126 | u32 flags; | |
127 | u32 dev_id; | |
128 | struct cdev *cdev; | |
129 | struct device dev; | |
80fc671b | 130 | struct mutex mutex; |
015d239a | 131 | void *priv; |
015d239a | 132 | struct list_head queues; |
fb01562e | 133 | struct inode *inode; |
015d239a KL |
134 | }; |
135 | ||
136 | #if IS_ENABLED(CONFIG_UACCE) | |
137 | ||
138 | struct uacce_device *uacce_alloc(struct device *parent, | |
139 | struct uacce_interface *interface); | |
140 | int uacce_register(struct uacce_device *uacce); | |
141 | void uacce_remove(struct uacce_device *uacce); | |
142 | ||
143 | #else /* CONFIG_UACCE */ | |
144 | ||
145 | static inline | |
146 | struct uacce_device *uacce_alloc(struct device *parent, | |
147 | struct uacce_interface *interface) | |
148 | { | |
149 | return ERR_PTR(-ENODEV); | |
150 | } | |
151 | ||
152 | static inline int uacce_register(struct uacce_device *uacce) | |
153 | { | |
154 | return -EINVAL; | |
155 | } | |
156 | ||
157 | static inline void uacce_remove(struct uacce_device *uacce) {} | |
158 | ||
159 | #endif /* CONFIG_UACCE */ | |
160 | ||
161 | #endif /* _LINUX_UACCE_H */ |