2 * Host IOMMU device abstract declaration
4 * Copyright (C) 2024 Intel Corporation.
6 * Authors: Zhenzhong Duan <zhenzhong.duan@intel.com>
8 * This work is licensed under the terms of the GNU GPL, version 2. See
9 * the COPYING file in the top-level directory.
12 #ifndef HOST_IOMMU_DEVICE_H
13 #define HOST_IOMMU_DEVICE_H
15 #include "qom/object.h"
16 #include "qapi/error.h"
19 * struct HostIOMMUDeviceCaps - Define host IOMMU device capabilities.
21 * @type: host platform IOMMU type.
23 * @hw_caps: host platform IOMMU capabilities (e.g. on IOMMUFD this represents
24 * the @out_capabilities value returned from IOMMU_GET_HW_INFO ioctl)
26 typedef struct HostIOMMUDeviceCaps
{
29 } HostIOMMUDeviceCaps
;
31 #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device"
32 OBJECT_DECLARE_TYPE(HostIOMMUDevice
, HostIOMMUDeviceClass
, HOST_IOMMU_DEVICE
)
34 struct HostIOMMUDevice
{
38 void *agent
; /* pointer to agent device, ie. VFIO or VDPA device */
41 HostIOMMUDeviceCaps caps
;
45 * struct HostIOMMUDeviceClass - The base class for all host IOMMU devices.
47 * Different types of host devices (e.g., VFIO or VDPA device) or devices
48 * with different backend (e.g., VFIO legacy container or IOMMUFD backend)
49 * will have different implementations of the HostIOMMUDeviceClass.
51 struct HostIOMMUDeviceClass
{
52 ObjectClass parent_class
;
55 * @realize: initialize host IOMMU device instance further.
59 * @hiod: pointer to a host IOMMU device instance.
61 * @opaque: pointer to agent device of this host IOMMU device,
62 * e.g., VFIO base device or VDPA device.
64 * @errp: pass an Error out when realize fails.
66 * Returns: true on success, false on failure.
68 bool (*realize
)(HostIOMMUDevice
*hiod
, void *opaque
, Error
**errp
);
70 * @get_cap: check if a host IOMMU device capability is supported.
72 * Optional callback, if not implemented, hint not supporting query
75 * @hiod: pointer to a host IOMMU device instance.
77 * @cap: capability to check.
79 * @errp: pass an Error out when fails to query capability.
81 * Returns: <0 on failure, 0 if a @cap is unsupported, or else
82 * 1 or some positive value for some special @cap,
83 * i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS.
85 int (*get_cap
)(HostIOMMUDevice
*hiod
, int cap
, Error
**errp
);
87 * @get_iova_ranges: Return the list of usable iova_ranges along with
88 * @hiod Host IOMMU device
90 * @hiod: handle to the host IOMMU device
92 GList
* (*get_iova_ranges
)(HostIOMMUDevice
*hiod
);
95 * @get_page_size_mask: Return the page size mask supported along this
96 * @hiod Host IOMMU device
98 * @hiod: handle to the host IOMMU device
100 uint64_t (*get_page_size_mask
)(HostIOMMUDevice
*hiod
);
104 * Host IOMMU device capability list.
106 #define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE 0
107 #define HOST_IOMMU_DEVICE_CAP_AW_BITS 1
109 #define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX 64