ioasid.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_IOASID_H
  3. #define __LINUX_IOASID_H
  4. #include <linux/types.h>
  5. #include <linux/errno.h>
  6. #define INVALID_IOASID ((ioasid_t)-1)
  7. typedef unsigned int ioasid_t;
  8. typedef ioasid_t (*ioasid_alloc_fn_t)(ioasid_t min, ioasid_t max, void *data);
  9. typedef void (*ioasid_free_fn_t)(ioasid_t ioasid, void *data);
  10. struct ioasid_set {
  11. int dummy;
  12. };
  13. /**
  14. * struct ioasid_allocator_ops - IOASID allocator helper functions and data
  15. *
  16. * @alloc: helper function to allocate IOASID
  17. * @free: helper function to free IOASID
  18. * @list: for tracking ops that share helper functions but not data
  19. * @pdata: data belong to the allocator, provided when calling alloc()
  20. */
  21. struct ioasid_allocator_ops {
  22. ioasid_alloc_fn_t alloc;
  23. ioasid_free_fn_t free;
  24. struct list_head list;
  25. void *pdata;
  26. };
  27. #define DECLARE_IOASID_SET(name) struct ioasid_set name = { 0 }
  28. #if IS_ENABLED(CONFIG_IOASID)
  29. ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min, ioasid_t max,
  30. void *private);
  31. void ioasid_free(ioasid_t ioasid);
  32. void *ioasid_find(struct ioasid_set *set, ioasid_t ioasid,
  33. bool (*getter)(void *));
  34. int ioasid_register_allocator(struct ioasid_allocator_ops *allocator);
  35. void ioasid_unregister_allocator(struct ioasid_allocator_ops *allocator);
  36. int ioasid_set_data(ioasid_t ioasid, void *data);
  37. static inline bool pasid_valid(ioasid_t ioasid)
  38. {
  39. return ioasid != INVALID_IOASID;
  40. }
  41. #else /* !CONFIG_IOASID */
  42. static inline ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min,
  43. ioasid_t max, void *private)
  44. {
  45. return INVALID_IOASID;
  46. }
  47. static inline void ioasid_free(ioasid_t ioasid) { }
  48. static inline void *ioasid_find(struct ioasid_set *set, ioasid_t ioasid,
  49. bool (*getter)(void *))
  50. {
  51. return NULL;
  52. }
  53. static inline int ioasid_register_allocator(struct ioasid_allocator_ops *allocator)
  54. {
  55. return -ENOTSUPP;
  56. }
  57. static inline void ioasid_unregister_allocator(struct ioasid_allocator_ops *allocator)
  58. {
  59. }
  60. static inline int ioasid_set_data(ioasid_t ioasid, void *data)
  61. {
  62. return -ENOTSUPP;
  63. }
  64. static inline bool pasid_valid(ioasid_t ioasid)
  65. {
  66. return false;
  67. }
  68. #endif /* CONFIG_IOASID */
  69. #endif /* __LINUX_IOASID_H */