xref: /qemu/include/system/host_iommu_device.h (revision 2a53c4f5c534a1ab825ba03e0d3ec45a7c2b90d8)
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"
17*1ab3d93fSZhenzhong Duan #ifdef CONFIG_LINUX
18*1ab3d93fSZhenzhong Duan #include "linux/iommufd.h"
19*1ab3d93fSZhenzhong Duan 
20*1ab3d93fSZhenzhong Duan typedef union VendorCaps {
21*1ab3d93fSZhenzhong Duan     struct iommu_hw_info_vtd vtd;
22*1ab3d93fSZhenzhong Duan     struct iommu_hw_info_arm_smmuv3 smmuv3;
23*1ab3d93fSZhenzhong Duan } VendorCaps;
241f94b218SZhenzhong Duan 
2538998c79SZhenzhong Duan /**
2638998c79SZhenzhong Duan  * struct HostIOMMUDeviceCaps - Define host IOMMU device capabilities.
2738998c79SZhenzhong Duan  *
2838998c79SZhenzhong Duan  * @type: host platform IOMMU type.
2921e8d3a3SJoao Martins  *
3021e8d3a3SJoao Martins  * @hw_caps: host platform IOMMU capabilities (e.g. on IOMMUFD this represents
3121e8d3a3SJoao Martins  *           the @out_capabilities value returned from IOMMU_GET_HW_INFO ioctl)
32*1ab3d93fSZhenzhong Duan  *
33*1ab3d93fSZhenzhong Duan  * @vendor_caps: host platform IOMMU vendor specific capabilities (e.g. on
34*1ab3d93fSZhenzhong Duan  *               IOMMUFD this represents a user-space buffer filled by kernel
35*1ab3d93fSZhenzhong Duan  *               with host IOMMU @type specific hardware information data)
3638998c79SZhenzhong Duan  */
3738998c79SZhenzhong Duan typedef struct HostIOMMUDeviceCaps {
3838998c79SZhenzhong Duan     uint32_t type;
3921e8d3a3SJoao Martins     uint64_t hw_caps;
40*1ab3d93fSZhenzhong Duan     VendorCaps vendor_caps;
4138998c79SZhenzhong Duan } HostIOMMUDeviceCaps;
42*1ab3d93fSZhenzhong Duan #endif
4338998c79SZhenzhong Duan 
441f94b218SZhenzhong Duan #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device"
451f94b218SZhenzhong Duan OBJECT_DECLARE_TYPE(HostIOMMUDevice, HostIOMMUDeviceClass, HOST_IOMMU_DEVICE)
461f94b218SZhenzhong Duan 
471f94b218SZhenzhong Duan struct HostIOMMUDevice {
481f94b218SZhenzhong Duan     Object parent_obj;
491f94b218SZhenzhong Duan 
501f94b218SZhenzhong Duan     char *name;
51dc169694SEric Auger     void *agent; /* pointer to agent device, ie. VFIO or VDPA device */
52a9526419SEric Auger     PCIBus *aliased_bus;
53a9526419SEric Auger     int aliased_devfn;
54*1ab3d93fSZhenzhong Duan #ifdef CONFIG_LINUX
5538998c79SZhenzhong Duan     HostIOMMUDeviceCaps caps;
56*1ab3d93fSZhenzhong Duan #endif
571f94b218SZhenzhong Duan };
581f94b218SZhenzhong Duan 
591f94b218SZhenzhong Duan /**
601f94b218SZhenzhong Duan  * struct HostIOMMUDeviceClass - The base class for all host IOMMU devices.
611f94b218SZhenzhong Duan  *
621f94b218SZhenzhong Duan  * Different types of host devices (e.g., VFIO or VDPA device) or devices
631f94b218SZhenzhong Duan  * with different backend (e.g., VFIO legacy container or IOMMUFD backend)
641f94b218SZhenzhong Duan  * will have different implementations of the HostIOMMUDeviceClass.
651f94b218SZhenzhong Duan  */
661f94b218SZhenzhong Duan struct HostIOMMUDeviceClass {
671f94b218SZhenzhong Duan     ObjectClass parent_class;
681f94b218SZhenzhong Duan 
691f94b218SZhenzhong Duan     /**
701f94b218SZhenzhong Duan      * @realize: initialize host IOMMU device instance further.
711f94b218SZhenzhong Duan      *
721f94b218SZhenzhong Duan      * Mandatory callback.
731f94b218SZhenzhong Duan      *
741f94b218SZhenzhong Duan      * @hiod: pointer to a host IOMMU device instance.
751f94b218SZhenzhong Duan      *
761f94b218SZhenzhong Duan      * @opaque: pointer to agent device of this host IOMMU device,
771f94b218SZhenzhong Duan      *          e.g., VFIO base device or VDPA device.
781f94b218SZhenzhong Duan      *
791f94b218SZhenzhong Duan      * @errp: pass an Error out when realize fails.
801f94b218SZhenzhong Duan      *
811f94b218SZhenzhong Duan      * Returns: true on success, false on failure.
821f94b218SZhenzhong Duan      */
831f94b218SZhenzhong Duan     bool (*realize)(HostIOMMUDevice *hiod, void *opaque, Error **errp);
8438998c79SZhenzhong Duan     /**
8538998c79SZhenzhong Duan      * @get_cap: check if a host IOMMU device capability is supported.
8638998c79SZhenzhong Duan      *
8738998c79SZhenzhong Duan      * Optional callback, if not implemented, hint not supporting query
8838998c79SZhenzhong Duan      * of @cap.
8938998c79SZhenzhong Duan      *
9038998c79SZhenzhong Duan      * @hiod: pointer to a host IOMMU device instance.
9138998c79SZhenzhong Duan      *
9238998c79SZhenzhong Duan      * @cap: capability to check.
9338998c79SZhenzhong Duan      *
9438998c79SZhenzhong Duan      * @errp: pass an Error out when fails to query capability.
9538998c79SZhenzhong Duan      *
9638998c79SZhenzhong Duan      * Returns: <0 on failure, 0 if a @cap is unsupported, or else
9738998c79SZhenzhong Duan      * 1 or some positive value for some special @cap,
9838998c79SZhenzhong Duan      * i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS.
9938998c79SZhenzhong Duan      */
10038998c79SZhenzhong Duan     int (*get_cap)(HostIOMMUDevice *hiod, int cap, Error **errp);
1013ad35d91SEric Auger     /**
1023ad35d91SEric Auger      * @get_iova_ranges: Return the list of usable iova_ranges along with
1033ad35d91SEric Auger      * @hiod Host IOMMU device
1043ad35d91SEric Auger      *
1053ad35d91SEric Auger      * @hiod: handle to the host IOMMU device
1063ad35d91SEric Auger      */
107d59ca1caSEric Auger     GList* (*get_iova_ranges)(HostIOMMUDevice *hiod);
1088fe0ebe1SEric Auger     /**
1098fe0ebe1SEric Auger      *
1108fe0ebe1SEric Auger      * @get_page_size_mask: Return the page size mask supported along this
1118fe0ebe1SEric Auger      * @hiod Host IOMMU device
1128fe0ebe1SEric Auger      *
1138fe0ebe1SEric Auger      * @hiod: handle to the host IOMMU device
1148fe0ebe1SEric Auger      */
1158fe0ebe1SEric Auger     uint64_t (*get_page_size_mask)(HostIOMMUDevice *hiod);
1161f94b218SZhenzhong Duan };
11738998c79SZhenzhong Duan 
11838998c79SZhenzhong Duan /*
11938998c79SZhenzhong Duan  * Host IOMMU device capability list.
12038998c79SZhenzhong Duan  */
12138998c79SZhenzhong Duan #define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE        0
12238998c79SZhenzhong Duan #define HOST_IOMMU_DEVICE_CAP_AW_BITS           1
12338998c79SZhenzhong Duan 
12438998c79SZhenzhong Duan #define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX       64
1251f94b218SZhenzhong Duan #endif
126