11f94b218SZhenzhong Duan /* 21f94b218SZhenzhong Duan * Host IOMMU device abstract declaration 31f94b218SZhenzhong Duan * 41f94b218SZhenzhong Duan * Copyright (C) 2024 Intel Corporation. 51f94b218SZhenzhong Duan * 61f94b218SZhenzhong Duan * Authors: Zhenzhong Duan <zhenzhong.duan@intel.com> 71f94b218SZhenzhong Duan * 81f94b218SZhenzhong Duan * This work is licensed under the terms of the GNU GPL, version 2. See 91f94b218SZhenzhong Duan * the COPYING file in the top-level directory. 101f94b218SZhenzhong Duan */ 111f94b218SZhenzhong Duan 121f94b218SZhenzhong Duan #ifndef HOST_IOMMU_DEVICE_H 131f94b218SZhenzhong Duan #define HOST_IOMMU_DEVICE_H 141f94b218SZhenzhong Duan 151f94b218SZhenzhong Duan #include "qom/object.h" 161f94b218SZhenzhong Duan #include "qapi/error.h" 171f94b218SZhenzhong Duan 1838998c79SZhenzhong Duan /** 1938998c79SZhenzhong Duan * struct HostIOMMUDeviceCaps - Define host IOMMU device capabilities. 2038998c79SZhenzhong Duan * 2138998c79SZhenzhong Duan * @type: host platform IOMMU type. 2238998c79SZhenzhong Duan * 2338998c79SZhenzhong Duan * @aw_bits: host IOMMU address width. 0xff if no limitation. 2438998c79SZhenzhong Duan */ 2538998c79SZhenzhong Duan typedef struct HostIOMMUDeviceCaps { 2638998c79SZhenzhong Duan uint32_t type; 2738998c79SZhenzhong Duan uint8_t aw_bits; 2838998c79SZhenzhong Duan } HostIOMMUDeviceCaps; 2938998c79SZhenzhong Duan 301f94b218SZhenzhong Duan #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" 311f94b218SZhenzhong Duan OBJECT_DECLARE_TYPE(HostIOMMUDevice, HostIOMMUDeviceClass, HOST_IOMMU_DEVICE) 321f94b218SZhenzhong Duan 331f94b218SZhenzhong Duan struct HostIOMMUDevice { 341f94b218SZhenzhong Duan Object parent_obj; 351f94b218SZhenzhong Duan 361f94b218SZhenzhong Duan char *name; 37dc169694SEric Auger void *agent; /* pointer to agent device, ie. VFIO or VDPA device */ 38*a9526419SEric Auger PCIBus *aliased_bus; 39*a9526419SEric Auger int aliased_devfn; 4038998c79SZhenzhong Duan HostIOMMUDeviceCaps caps; 411f94b218SZhenzhong Duan }; 421f94b218SZhenzhong Duan 431f94b218SZhenzhong Duan /** 441f94b218SZhenzhong Duan * struct HostIOMMUDeviceClass - The base class for all host IOMMU devices. 451f94b218SZhenzhong Duan * 461f94b218SZhenzhong Duan * Different types of host devices (e.g., VFIO or VDPA device) or devices 471f94b218SZhenzhong Duan * with different backend (e.g., VFIO legacy container or IOMMUFD backend) 481f94b218SZhenzhong Duan * will have different implementations of the HostIOMMUDeviceClass. 491f94b218SZhenzhong Duan */ 501f94b218SZhenzhong Duan struct HostIOMMUDeviceClass { 511f94b218SZhenzhong Duan ObjectClass parent_class; 521f94b218SZhenzhong Duan 531f94b218SZhenzhong Duan /** 541f94b218SZhenzhong Duan * @realize: initialize host IOMMU device instance further. 551f94b218SZhenzhong Duan * 561f94b218SZhenzhong Duan * Mandatory callback. 571f94b218SZhenzhong Duan * 581f94b218SZhenzhong Duan * @hiod: pointer to a host IOMMU device instance. 591f94b218SZhenzhong Duan * 601f94b218SZhenzhong Duan * @opaque: pointer to agent device of this host IOMMU device, 611f94b218SZhenzhong Duan * e.g., VFIO base device or VDPA device. 621f94b218SZhenzhong Duan * 631f94b218SZhenzhong Duan * @errp: pass an Error out when realize fails. 641f94b218SZhenzhong Duan * 651f94b218SZhenzhong Duan * Returns: true on success, false on failure. 661f94b218SZhenzhong Duan */ 671f94b218SZhenzhong Duan bool (*realize)(HostIOMMUDevice *hiod, void *opaque, Error **errp); 6838998c79SZhenzhong Duan /** 6938998c79SZhenzhong Duan * @get_cap: check if a host IOMMU device capability is supported. 7038998c79SZhenzhong Duan * 7138998c79SZhenzhong Duan * Optional callback, if not implemented, hint not supporting query 7238998c79SZhenzhong Duan * of @cap. 7338998c79SZhenzhong Duan * 7438998c79SZhenzhong Duan * @hiod: pointer to a host IOMMU device instance. 7538998c79SZhenzhong Duan * 7638998c79SZhenzhong Duan * @cap: capability to check. 7738998c79SZhenzhong Duan * 7838998c79SZhenzhong Duan * @errp: pass an Error out when fails to query capability. 7938998c79SZhenzhong Duan * 8038998c79SZhenzhong Duan * Returns: <0 on failure, 0 if a @cap is unsupported, or else 8138998c79SZhenzhong Duan * 1 or some positive value for some special @cap, 8238998c79SZhenzhong Duan * i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS. 8338998c79SZhenzhong Duan */ 8438998c79SZhenzhong Duan int (*get_cap)(HostIOMMUDevice *hiod, int cap, Error **errp); 853ad35d91SEric Auger /** 863ad35d91SEric Auger * @get_iova_ranges: Return the list of usable iova_ranges along with 873ad35d91SEric Auger * @hiod Host IOMMU device 883ad35d91SEric Auger * 893ad35d91SEric Auger * @hiod: handle to the host IOMMU device 903ad35d91SEric Auger * @errp: error handle 913ad35d91SEric Auger */ 923ad35d91SEric Auger GList* (*get_iova_ranges)(HostIOMMUDevice *hiod, Error **errp); 931f94b218SZhenzhong Duan }; 9438998c79SZhenzhong Duan 9538998c79SZhenzhong Duan /* 9638998c79SZhenzhong Duan * Host IOMMU device capability list. 9738998c79SZhenzhong Duan */ 9838998c79SZhenzhong Duan #define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE 0 9938998c79SZhenzhong Duan #define HOST_IOMMU_DEVICE_CAP_AW_BITS 1 10038998c79SZhenzhong Duan 10138998c79SZhenzhong Duan #define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX 64 1021f94b218SZhenzhong Duan #endif 103