1 /* SPDX-License-Identifier: GPL-2.0-or-later */
5 #include <linux/cdev.h>
6 #include <uapi/misc/uacce/uacce.h>
8 #define UACCE_NAME "uacce"
9 #define UACCE_MAX_REGION 2
10 #define UACCE_MAX_NAME_SIZE 64
11 #define UACCE_MAX_ERR_THRESHOLD 65535
17 * struct uacce_qfile_region - structure of queue file region
18 * @type: type of the region
20 struct uacce_qfile_region {
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
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
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,
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);
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
61 struct uacce_interface {
62 char name[UACCE_MAX_NAME_SIZE];
64 const struct uacce_ops *ops;
67 enum uacce_dev_state {
80 * @uacce: pointer to uacce
81 * @priv: private pointer
82 * @wait: wait queue head
83 * @list: index into uacce queues list
84 * @qfrs: pointer of qfr regions
85 * @mutex: protects queue state
86 * @state: queue state machine
87 * @pasid: pasid associated to the mm
88 * @handle: iommu_sva handle returned by iommu_sva_bind_device()
89 * @mapping: user space mapping of the queue
92 struct uacce_device *uacce;
94 wait_queue_head_t wait;
95 struct list_head list;
96 struct uacce_qfile_region *qfrs[UACCE_MAX_REGION];
98 enum uacce_q_state state;
100 struct iommu_sva *handle;
101 struct address_space *mapping;
105 * struct uacce_device
106 * @algs: supported algorithms
107 * @api_ver: api version
108 * @ops: pointer to the struct uacce_ops
109 * @qf_pg_num: page numbers of the queue file regions
110 * @parent: pointer to the parent device
111 * @is_vf: whether virtual function
112 * @flags: uacce attributes
113 * @dev_id: id of the uacce device
114 * @cdev: cdev of the uacce
115 * @dev: dev of the uacce
116 * @mutex: protects uacce operation
117 * @priv: private pointer of the uacce
118 * @queues: list of queues
120 struct uacce_device {
123 const struct uacce_ops *ops;
124 unsigned long qf_pg_num[UACCE_MAX_REGION];
125 struct device *parent;
133 struct list_head queues;
136 #if IS_ENABLED(CONFIG_UACCE)
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);
143 #else /* CONFIG_UACCE */
146 struct uacce_device *uacce_alloc(struct device *parent,
147 struct uacce_interface *interface)
149 return ERR_PTR(-ENODEV);
152 static inline int uacce_register(struct uacce_device *uacce)
157 static inline void uacce_remove(struct uacce_device *uacce) {}
159 #endif /* CONFIG_UACCE */
161 #endif /* _LINUX_UACCE_H */