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 #ifdef CONFIG_LINUX 18 #include "linux/iommufd.h" 19 20 typedef union VendorCaps { 21 struct iommu_hw_info_vtd vtd; 22 struct iommu_hw_info_arm_smmuv3 smmuv3; 23 } VendorCaps; 24 25 /** 26 * struct HostIOMMUDeviceCaps - Define host IOMMU device capabilities. 27 * 28 * @type: host platform IOMMU type. 29 * 30 * @hw_caps: host platform IOMMU capabilities (e.g. on IOMMUFD this represents 31 * the @out_capabilities value returned from IOMMU_GET_HW_INFO ioctl) 32 * 33 * @vendor_caps: host platform IOMMU vendor specific capabilities (e.g. on 34 * IOMMUFD this represents a user-space buffer filled by kernel 35 * with host IOMMU @type specific hardware information data) 36 */ 37 typedef struct HostIOMMUDeviceCaps { 38 uint32_t type; 39 uint64_t hw_caps; 40 VendorCaps vendor_caps; 41 } HostIOMMUDeviceCaps; 42 #endif 43 44 #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" 45 OBJECT_DECLARE_TYPE(HostIOMMUDevice, HostIOMMUDeviceClass, HOST_IOMMU_DEVICE) 46 47 struct HostIOMMUDevice { 48 Object parent_obj; 49 50 char *name; 51 void *agent; /* pointer to agent device, ie. VFIO or VDPA device */ 52 PCIBus *aliased_bus; 53 int aliased_devfn; 54 #ifdef CONFIG_LINUX 55 HostIOMMUDeviceCaps caps; 56 #endif 57 }; 58 59 /** 60 * struct HostIOMMUDeviceClass - The base class for all host IOMMU devices. 61 * 62 * Different types of host devices (e.g., VFIO or VDPA device) or devices 63 * with different backend (e.g., VFIO legacy container or IOMMUFD backend) 64 * will have different implementations of the HostIOMMUDeviceClass. 65 */ 66 struct HostIOMMUDeviceClass { 67 ObjectClass parent_class; 68 69 /** 70 * @realize: initialize host IOMMU device instance further. 71 * 72 * Mandatory callback. 73 * 74 * @hiod: pointer to a host IOMMU device instance. 75 * 76 * @opaque: pointer to agent device of this host IOMMU device, 77 * e.g., VFIO base device or VDPA device. 78 * 79 * @errp: pass an Error out when realize fails. 80 * 81 * Returns: true on success, false on failure. 82 */ 83 bool (*realize)(HostIOMMUDevice *hiod, void *opaque, Error **errp); 84 /** 85 * @get_cap: check if a host IOMMU device capability is supported. 86 * 87 * Optional callback, if not implemented, hint not supporting query 88 * of @cap. 89 * 90 * @hiod: pointer to a host IOMMU device instance. 91 * 92 * @cap: capability to check. 93 * 94 * @errp: pass an Error out when fails to query capability. 95 * 96 * Returns: <0 on failure, 0 if a @cap is unsupported, or else 97 * 1 or some positive value for some special @cap, 98 * i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS. 99 */ 100 int (*get_cap)(HostIOMMUDevice *hiod, int cap, Error **errp); 101 /** 102 * @get_iova_ranges: Return the list of usable iova_ranges along with 103 * @hiod Host IOMMU device 104 * 105 * @hiod: handle to the host IOMMU device 106 */ 107 GList* (*get_iova_ranges)(HostIOMMUDevice *hiod); 108 /** 109 * 110 * @get_page_size_mask: Return the page size mask supported along this 111 * @hiod Host IOMMU device 112 * 113 * @hiod: handle to the host IOMMU device 114 */ 115 uint64_t (*get_page_size_mask)(HostIOMMUDevice *hiod); 116 }; 117 118 /* 119 * Host IOMMU device capability list. 120 */ 121 #define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE 0 122 #define HOST_IOMMU_DEVICE_CAP_AW_BITS 1 123 124 #define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX 64 125 #endif 126