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 
18*38998c79SZhenzhong Duan /**
19*38998c79SZhenzhong Duan  * struct HostIOMMUDeviceCaps - Define host IOMMU device capabilities.
20*38998c79SZhenzhong Duan  *
21*38998c79SZhenzhong Duan  * @type: host platform IOMMU type.
22*38998c79SZhenzhong Duan  *
23*38998c79SZhenzhong Duan  * @aw_bits: host IOMMU address width. 0xff if no limitation.
24*38998c79SZhenzhong Duan  */
25*38998c79SZhenzhong Duan typedef struct HostIOMMUDeviceCaps {
26*38998c79SZhenzhong Duan     uint32_t type;
27*38998c79SZhenzhong Duan     uint8_t aw_bits;
28*38998c79SZhenzhong Duan } HostIOMMUDeviceCaps;
29*38998c79SZhenzhong 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;
37*38998c79SZhenzhong Duan     HostIOMMUDeviceCaps caps;
381f94b218SZhenzhong Duan };
391f94b218SZhenzhong Duan 
401f94b218SZhenzhong Duan /**
411f94b218SZhenzhong Duan  * struct HostIOMMUDeviceClass - The base class for all host IOMMU devices.
421f94b218SZhenzhong Duan  *
431f94b218SZhenzhong Duan  * Different types of host devices (e.g., VFIO or VDPA device) or devices
441f94b218SZhenzhong Duan  * with different backend (e.g., VFIO legacy container or IOMMUFD backend)
451f94b218SZhenzhong Duan  * will have different implementations of the HostIOMMUDeviceClass.
461f94b218SZhenzhong Duan  */
471f94b218SZhenzhong Duan struct HostIOMMUDeviceClass {
481f94b218SZhenzhong Duan     ObjectClass parent_class;
491f94b218SZhenzhong Duan 
501f94b218SZhenzhong Duan     /**
511f94b218SZhenzhong Duan      * @realize: initialize host IOMMU device instance further.
521f94b218SZhenzhong Duan      *
531f94b218SZhenzhong Duan      * Mandatory callback.
541f94b218SZhenzhong Duan      *
551f94b218SZhenzhong Duan      * @hiod: pointer to a host IOMMU device instance.
561f94b218SZhenzhong Duan      *
571f94b218SZhenzhong Duan      * @opaque: pointer to agent device of this host IOMMU device,
581f94b218SZhenzhong Duan      *          e.g., VFIO base device or VDPA device.
591f94b218SZhenzhong Duan      *
601f94b218SZhenzhong Duan      * @errp: pass an Error out when realize fails.
611f94b218SZhenzhong Duan      *
621f94b218SZhenzhong Duan      * Returns: true on success, false on failure.
631f94b218SZhenzhong Duan      */
641f94b218SZhenzhong Duan     bool (*realize)(HostIOMMUDevice *hiod, void *opaque, Error **errp);
65*38998c79SZhenzhong Duan     /**
66*38998c79SZhenzhong Duan      * @get_cap: check if a host IOMMU device capability is supported.
67*38998c79SZhenzhong Duan      *
68*38998c79SZhenzhong Duan      * Optional callback, if not implemented, hint not supporting query
69*38998c79SZhenzhong Duan      * of @cap.
70*38998c79SZhenzhong Duan      *
71*38998c79SZhenzhong Duan      * @hiod: pointer to a host IOMMU device instance.
72*38998c79SZhenzhong Duan      *
73*38998c79SZhenzhong Duan      * @cap: capability to check.
74*38998c79SZhenzhong Duan      *
75*38998c79SZhenzhong Duan      * @errp: pass an Error out when fails to query capability.
76*38998c79SZhenzhong Duan      *
77*38998c79SZhenzhong Duan      * Returns: <0 on failure, 0 if a @cap is unsupported, or else
78*38998c79SZhenzhong Duan      * 1 or some positive value for some special @cap,
79*38998c79SZhenzhong Duan      * i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS.
80*38998c79SZhenzhong Duan      */
81*38998c79SZhenzhong Duan     int (*get_cap)(HostIOMMUDevice *hiod, int cap, Error **errp);
821f94b218SZhenzhong Duan };
83*38998c79SZhenzhong Duan 
84*38998c79SZhenzhong Duan /*
85*38998c79SZhenzhong Duan  * Host IOMMU device capability list.
86*38998c79SZhenzhong Duan  */
87*38998c79SZhenzhong Duan #define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE        0
88*38998c79SZhenzhong Duan #define HOST_IOMMU_DEVICE_CAP_AW_BITS           1
89*38998c79SZhenzhong Duan 
90*38998c79SZhenzhong Duan #define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX       64
911f94b218SZhenzhong Duan #endif
92