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. 22*21e8d3a3SJoao Martins * 23*21e8d3a3SJoao Martins * @hw_caps: host platform IOMMU capabilities (e.g. on IOMMUFD this represents 24*21e8d3a3SJoao Martins * the @out_capabilities value returned from IOMMU_GET_HW_INFO ioctl) 2538998c79SZhenzhong Duan */ 2638998c79SZhenzhong Duan typedef struct HostIOMMUDeviceCaps { 2738998c79SZhenzhong Duan uint32_t type; 28*21e8d3a3SJoao Martins uint64_t hw_caps; 2938998c79SZhenzhong Duan } HostIOMMUDeviceCaps; 3038998c79SZhenzhong Duan 311f94b218SZhenzhong Duan #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" 321f94b218SZhenzhong Duan OBJECT_DECLARE_TYPE(HostIOMMUDevice, HostIOMMUDeviceClass, HOST_IOMMU_DEVICE) 331f94b218SZhenzhong Duan 341f94b218SZhenzhong Duan struct HostIOMMUDevice { 351f94b218SZhenzhong Duan Object parent_obj; 361f94b218SZhenzhong Duan 371f94b218SZhenzhong Duan char *name; 38dc169694SEric Auger void *agent; /* pointer to agent device, ie. VFIO or VDPA device */ 39a9526419SEric Auger PCIBus *aliased_bus; 40a9526419SEric Auger int aliased_devfn; 4138998c79SZhenzhong Duan HostIOMMUDeviceCaps caps; 421f94b218SZhenzhong Duan }; 431f94b218SZhenzhong Duan 441f94b218SZhenzhong Duan /** 451f94b218SZhenzhong Duan * struct HostIOMMUDeviceClass - The base class for all host IOMMU devices. 461f94b218SZhenzhong Duan * 471f94b218SZhenzhong Duan * Different types of host devices (e.g., VFIO or VDPA device) or devices 481f94b218SZhenzhong Duan * with different backend (e.g., VFIO legacy container or IOMMUFD backend) 491f94b218SZhenzhong Duan * will have different implementations of the HostIOMMUDeviceClass. 501f94b218SZhenzhong Duan */ 511f94b218SZhenzhong Duan struct HostIOMMUDeviceClass { 521f94b218SZhenzhong Duan ObjectClass parent_class; 531f94b218SZhenzhong Duan 541f94b218SZhenzhong Duan /** 551f94b218SZhenzhong Duan * @realize: initialize host IOMMU device instance further. 561f94b218SZhenzhong Duan * 571f94b218SZhenzhong Duan * Mandatory callback. 581f94b218SZhenzhong Duan * 591f94b218SZhenzhong Duan * @hiod: pointer to a host IOMMU device instance. 601f94b218SZhenzhong Duan * 611f94b218SZhenzhong Duan * @opaque: pointer to agent device of this host IOMMU device, 621f94b218SZhenzhong Duan * e.g., VFIO base device or VDPA device. 631f94b218SZhenzhong Duan * 641f94b218SZhenzhong Duan * @errp: pass an Error out when realize fails. 651f94b218SZhenzhong Duan * 661f94b218SZhenzhong Duan * Returns: true on success, false on failure. 671f94b218SZhenzhong Duan */ 681f94b218SZhenzhong Duan bool (*realize)(HostIOMMUDevice *hiod, void *opaque, Error **errp); 6938998c79SZhenzhong Duan /** 7038998c79SZhenzhong Duan * @get_cap: check if a host IOMMU device capability is supported. 7138998c79SZhenzhong Duan * 7238998c79SZhenzhong Duan * Optional callback, if not implemented, hint not supporting query 7338998c79SZhenzhong Duan * of @cap. 7438998c79SZhenzhong Duan * 7538998c79SZhenzhong Duan * @hiod: pointer to a host IOMMU device instance. 7638998c79SZhenzhong Duan * 7738998c79SZhenzhong Duan * @cap: capability to check. 7838998c79SZhenzhong Duan * 7938998c79SZhenzhong Duan * @errp: pass an Error out when fails to query capability. 8038998c79SZhenzhong Duan * 8138998c79SZhenzhong Duan * Returns: <0 on failure, 0 if a @cap is unsupported, or else 8238998c79SZhenzhong Duan * 1 or some positive value for some special @cap, 8338998c79SZhenzhong Duan * i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS. 8438998c79SZhenzhong Duan */ 8538998c79SZhenzhong Duan int (*get_cap)(HostIOMMUDevice *hiod, int cap, Error **errp); 863ad35d91SEric Auger /** 873ad35d91SEric Auger * @get_iova_ranges: Return the list of usable iova_ranges along with 883ad35d91SEric Auger * @hiod Host IOMMU device 893ad35d91SEric Auger * 903ad35d91SEric Auger * @hiod: handle to the host IOMMU device 913ad35d91SEric Auger */ 92d59ca1caSEric Auger GList* (*get_iova_ranges)(HostIOMMUDevice *hiod); 938fe0ebe1SEric Auger /** 948fe0ebe1SEric Auger * 958fe0ebe1SEric Auger * @get_page_size_mask: Return the page size mask supported along this 968fe0ebe1SEric Auger * @hiod Host IOMMU device 978fe0ebe1SEric Auger * 988fe0ebe1SEric Auger * @hiod: handle to the host IOMMU device 998fe0ebe1SEric Auger */ 1008fe0ebe1SEric Auger uint64_t (*get_page_size_mask)(HostIOMMUDevice *hiod); 1011f94b218SZhenzhong Duan }; 10238998c79SZhenzhong Duan 10338998c79SZhenzhong Duan /* 10438998c79SZhenzhong Duan * Host IOMMU device capability list. 10538998c79SZhenzhong Duan */ 10638998c79SZhenzhong Duan #define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE 0 10738998c79SZhenzhong Duan #define HOST_IOMMU_DEVICE_CAP_AW_BITS 1 10838998c79SZhenzhong Duan 10938998c79SZhenzhong Duan #define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX 64 1101f94b218SZhenzhong Duan #endif 111