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 * @aw_bits: host IOMMU address width. 0xff if no limitation. 24 */ 25 typedef struct HostIOMMUDeviceCaps { 26 uint32_t type; 27 uint8_t aw_bits; 28 } HostIOMMUDeviceCaps; 29 30 #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" 31 OBJECT_DECLARE_TYPE(HostIOMMUDevice, HostIOMMUDeviceClass, HOST_IOMMU_DEVICE) 32 33 struct HostIOMMUDevice { 34 Object parent_obj; 35 36 char *name; 37 void *agent; /* pointer to agent device, ie. VFIO or VDPA device */ 38 HostIOMMUDeviceCaps caps; 39 }; 40 41 /** 42 * struct HostIOMMUDeviceClass - The base class for all host IOMMU devices. 43 * 44 * Different types of host devices (e.g., VFIO or VDPA device) or devices 45 * with different backend (e.g., VFIO legacy container or IOMMUFD backend) 46 * will have different implementations of the HostIOMMUDeviceClass. 47 */ 48 struct HostIOMMUDeviceClass { 49 ObjectClass parent_class; 50 51 /** 52 * @realize: initialize host IOMMU device instance further. 53 * 54 * Mandatory callback. 55 * 56 * @hiod: pointer to a host IOMMU device instance. 57 * 58 * @opaque: pointer to agent device of this host IOMMU device, 59 * e.g., VFIO base device or VDPA device. 60 * 61 * @errp: pass an Error out when realize fails. 62 * 63 * Returns: true on success, false on failure. 64 */ 65 bool (*realize)(HostIOMMUDevice *hiod, void *opaque, Error **errp); 66 /** 67 * @get_cap: check if a host IOMMU device capability is supported. 68 * 69 * Optional callback, if not implemented, hint not supporting query 70 * of @cap. 71 * 72 * @hiod: pointer to a host IOMMU device instance. 73 * 74 * @cap: capability to check. 75 * 76 * @errp: pass an Error out when fails to query capability. 77 * 78 * Returns: <0 on failure, 0 if a @cap is unsupported, or else 79 * 1 or some positive value for some special @cap, 80 * i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS. 81 */ 82 int (*get_cap)(HostIOMMUDevice *hiod, int cap, Error **errp); 83 /** 84 * @get_iova_ranges: Return the list of usable iova_ranges along with 85 * @hiod Host IOMMU device 86 * 87 * @hiod: handle to the host IOMMU device 88 * @errp: error handle 89 */ 90 GList* (*get_iova_ranges)(HostIOMMUDevice *hiod, Error **errp); 91 }; 92 93 /* 94 * Host IOMMU device capability list. 95 */ 96 #define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE 0 97 #define HOST_IOMMU_DEVICE_CAP_AW_BITS 1 98 99 #define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX 64 100 #endif 101