2 * Common IOMMU interface for X86 platform
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef IOMMU_COMMON_H
21 #define IOMMU_COMMON_H
23 #include "hw/sysbus.h"
24 #include "hw/pci/pci.h"
26 #define TYPE_X86_IOMMU_DEVICE ("x86-iommu")
27 #define X86_IOMMU_DEVICE(obj) \
28 OBJECT_CHECK(X86IOMMUState, (obj), TYPE_X86_IOMMU_DEVICE)
29 #define X86_IOMMU_CLASS(klass) \
30 OBJECT_CLASS_CHECK(X86IOMMUClass, (klass), TYPE_X86_IOMMU_DEVICE)
31 #define X86_IOMMU_GET_CLASS(obj) \
32 OBJECT_GET_CLASS(X86IOMMUClass, obj, TYPE_X86_IOMMU_DEVICE)
34 #define X86_IOMMU_PCI_DEVFN_MAX 256
35 #define X86_IOMMU_SID_INVALID (0xffff)
37 typedef struct X86IOMMUState X86IOMMUState;
38 typedef struct X86IOMMUClass X86IOMMUClass;
40 typedef enum IommuType {
46 struct X86IOMMUClass {
47 SysBusDeviceClass parent;
48 /* Intel/AMD specific realize() hook */
49 DeviceRealize realize;
50 /* MSI-based interrupt remapping */
51 int (*int_remap)(X86IOMMUState *iommu, MSIMessage *src,
52 MSIMessage *dst, uint16_t sid);
56 * iec_notify_fn - IEC (Interrupt Entry Cache) notifier hook,
57 * triggered when IR invalidation happens.
58 * @private: private data
59 * @global: whether this is a global IEC invalidation
60 * @index: IRTE index to invalidate (start from)
61 * @mask: invalidation mask
63 typedef void (*iec_notify_fn)(void *private, bool global,
64 uint32_t index, uint32_t mask);
67 iec_notify_fn iec_notify;
69 QLIST_ENTRY(IEC_Notifier) list;
71 typedef struct IEC_Notifier IEC_Notifier;
73 struct X86IOMMUState {
75 bool intr_supported; /* Whether vIOMMU supports IR */
76 bool dt_supported; /* Whether vIOMMU supports DT */
77 bool pt_supported; /* Whether vIOMMU supports pass-through */
78 IommuType type; /* IOMMU type - AMD/Intel */
79 QLIST_HEAD(, IEC_Notifier) iec_notifiers; /* IEC notify list */
83 * x86_iommu_get_default - get default IOMMU device
84 * @return: pointer to default IOMMU device
86 X86IOMMUState *x86_iommu_get_default(void);
89 * x86_iommu_get_type - get IOMMU type
91 IommuType x86_iommu_get_type(void);
94 * x86_iommu_iec_register_notifier - register IEC (Interrupt Entry
96 * @iommu: IOMMU device to register
97 * @fn: IEC notifier hook function
98 * @data: notifier private data
100 void x86_iommu_iec_register_notifier(X86IOMMUState *iommu,
101 iec_notify_fn fn, void *data);
104 * x86_iommu_iec_notify_all - Notify IEC invalidations
105 * @iommu: IOMMU device that sends the notification
106 * @global: whether this is a global invalidation. If true, @index
107 * and @mask are undefined.
108 * @index: starting index of interrupt entry to invalidate
109 * @mask: index mask for the invalidation
111 void x86_iommu_iec_notify_all(X86IOMMUState *iommu, bool global,
112 uint32_t index, uint32_t mask);