host_iommu_device.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Host IOMMU device abstract declaration
  3. *
  4. * Copyright (C) 2024 Intel Corporation.
  5. *
  6. * Authors: Zhenzhong Duan <zhenzhong.duan@intel.com>
  7. *
  8. * This work is licensed under the terms of the GNU GPL, version 2. See
  9. * the COPYING file in the top-level directory.
  10. */
  11. #ifndef HOST_IOMMU_DEVICE_H
  12. #define HOST_IOMMU_DEVICE_H
  13. #include "qom/object.h"
  14. #include "qapi/error.h"
  15. /**
  16. * struct HostIOMMUDeviceCaps - Define host IOMMU device capabilities.
  17. *
  18. * @type: host platform IOMMU type.
  19. *
  20. * @hw_caps: host platform IOMMU capabilities (e.g. on IOMMUFD this represents
  21. * the @out_capabilities value returned from IOMMU_GET_HW_INFO ioctl)
  22. */
  23. typedef struct HostIOMMUDeviceCaps {
  24. uint32_t type;
  25. uint64_t hw_caps;
  26. } HostIOMMUDeviceCaps;
  27. #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device"
  28. OBJECT_DECLARE_TYPE(HostIOMMUDevice, HostIOMMUDeviceClass, HOST_IOMMU_DEVICE)
  29. struct HostIOMMUDevice {
  30. Object parent_obj;
  31. char *name;
  32. void *agent; /* pointer to agent device, ie. VFIO or VDPA device */
  33. PCIBus *aliased_bus;
  34. int aliased_devfn;
  35. HostIOMMUDeviceCaps caps;
  36. };
  37. /**
  38. * struct HostIOMMUDeviceClass - The base class for all host IOMMU devices.
  39. *
  40. * Different types of host devices (e.g., VFIO or VDPA device) or devices
  41. * with different backend (e.g., VFIO legacy container or IOMMUFD backend)
  42. * will have different implementations of the HostIOMMUDeviceClass.
  43. */
  44. struct HostIOMMUDeviceClass {
  45. ObjectClass parent_class;
  46. /**
  47. * @realize: initialize host IOMMU device instance further.
  48. *
  49. * Mandatory callback.
  50. *
  51. * @hiod: pointer to a host IOMMU device instance.
  52. *
  53. * @opaque: pointer to agent device of this host IOMMU device,
  54. * e.g., VFIO base device or VDPA device.
  55. *
  56. * @errp: pass an Error out when realize fails.
  57. *
  58. * Returns: true on success, false on failure.
  59. */
  60. bool (*realize)(HostIOMMUDevice *hiod, void *opaque, Error **errp);
  61. /**
  62. * @get_cap: check if a host IOMMU device capability is supported.
  63. *
  64. * Optional callback, if not implemented, hint not supporting query
  65. * of @cap.
  66. *
  67. * @hiod: pointer to a host IOMMU device instance.
  68. *
  69. * @cap: capability to check.
  70. *
  71. * @errp: pass an Error out when fails to query capability.
  72. *
  73. * Returns: <0 on failure, 0 if a @cap is unsupported, or else
  74. * 1 or some positive value for some special @cap,
  75. * i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS.
  76. */
  77. int (*get_cap)(HostIOMMUDevice *hiod, int cap, Error **errp);
  78. /**
  79. * @get_iova_ranges: Return the list of usable iova_ranges along with
  80. * @hiod Host IOMMU device
  81. *
  82. * @hiod: handle to the host IOMMU device
  83. */
  84. GList* (*get_iova_ranges)(HostIOMMUDevice *hiod);
  85. /**
  86. *
  87. * @get_page_size_mask: Return the page size mask supported along this
  88. * @hiod Host IOMMU device
  89. *
  90. * @hiod: handle to the host IOMMU device
  91. */
  92. uint64_t (*get_page_size_mask)(HostIOMMUDevice *hiod);
  93. };
  94. /*
  95. * Host IOMMU device capability list.
  96. */
  97. #define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE 0
  98. #define HOST_IOMMU_DEVICE_CAP_AW_BITS 1
  99. #define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX 64
  100. #endif