uacce.h 3.7 KB

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