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 12 #ifndef HOST_IOMMU_DEVICE_H 13 #define HOST_IOMMU_DEVICE_H 14 15 #include "qom/object.h" 16 #include "qapi/error.h" 17 18 /** 19 * struct HostIOMMUDeviceCaps - Define host IOMMU device capabilities. 20 * 21 * @type: host platform IOMMU type. 22 * 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) 25 */ 26 typedef struct HostIOMMUDeviceCaps { 27 uint32_t type; 28 uint64_t hw_caps; 29 } HostIOMMUDeviceCaps; 30 31 #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" 32 OBJECT_DECLARE_TYPE(HostIOMMUDevice, HostIOMMUDeviceClass, HOST_IOMMU_DEVICE) 33 34 struct HostIOMMUDevice { 35 Object parent_obj; 36 37 char *name; 38 void *agent; /* pointer to agent device, ie. VFIO or VDPA device */ 39 PCIBus *aliased_bus; 40 int aliased_devfn; 41 HostIOMMUDeviceCaps caps; 42 }; 43 44 /** 45 * struct HostIOMMUDeviceClass - The base class for all host IOMMU devices. 46 * 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. 50 */ 51 struct HostIOMMUDeviceClass { 52 ObjectClass parent_class; 53 54 /** 55 * @realize: initialize host IOMMU device instance further. 56 * 57 * Mandatory callback. 58 * 59 * @hiod: pointer to a host IOMMU device instance. 60 * 61 * @opaque: pointer to agent device of this host IOMMU device, 62 * e.g., VFIO base device or VDPA device. 63 * 64 * @errp: pass an Error out when realize fails. 65 * 66 * Returns: true on success, false on failure. 67 */ 68 bool (*realize)(HostIOMMUDevice *hiod, void *opaque, Error **errp); 69 /** 70 * @get_cap: check if a host IOMMU device capability is supported. 71 * 72 * Optional callback, if not implemented, hint not supporting query 73 * of @cap. 74 * 75 * @hiod: pointer to a host IOMMU device instance. 76 * 77 * @cap: capability to check. 78 * 79 * @errp: pass an Error out when fails to query capability. 80 * 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. 84 */ 85 int (*get_cap)(HostIOMMUDevice *hiod, int cap, Error **errp); 86 /** 87 * @get_iova_ranges: Return the list of usable iova_ranges along with 88 * @hiod Host IOMMU device 89 * 90 * @hiod: handle to the host IOMMU device 91 */ 92 GList* (*get_iova_ranges)(HostIOMMUDevice *hiod); 93 /** 94 * 95 * @get_page_size_mask: Return the page size mask supported along this 96 * @hiod Host IOMMU device 97 * 98 * @hiod: handle to the host IOMMU device 99 */ 100 uint64_t (*get_page_size_mask)(HostIOMMUDevice *hiod); 101 }; 102 103 /* 104 * Host IOMMU device capability list. 105 */ 106 #define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE 0 107 #define HOST_IOMMU_DEVICE_CAP_AW_BITS 1 108 109 #define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX 64 110 #endif 111