2 * Common IOMMU interface for X86 platform
4 * Copyright (C) 2016 Peter Xu, Red Hat <peterx@redhat.com>
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 HW_I386_X86_IOMMU_H
21 #define HW_I386_X86_IOMMU_H
23 #include "hw/sysbus.h"
24 #include "hw/pci/msi.h"
25 #include "qom/object.h"
27 #define TYPE_X86_IOMMU_DEVICE ("x86-iommu")
28 OBJECT_DECLARE_TYPE(X86IOMMUState
, X86IOMMUClass
, X86_IOMMU_DEVICE
)
30 #define X86_IOMMU_SID_INVALID (0xffff)
32 typedef struct X86IOMMUIrq X86IOMMUIrq
;
33 typedef struct X86IOMMU_MSIMessage X86IOMMU_MSIMessage
;
35 struct X86IOMMUClass
{
36 SysBusDeviceClass parent
;
37 /* Intel/AMD specific realize() hook */
38 DeviceRealize realize
;
39 /* MSI-based interrupt remapping */
40 int (*int_remap
)(X86IOMMUState
*iommu
, MSIMessage
*src
,
41 MSIMessage
*dst
, uint16_t sid
);
45 * iec_notify_fn - IEC (Interrupt Entry Cache) notifier hook,
46 * triggered when IR invalidation happens.
47 * @private: private data
48 * @global: whether this is a global IEC invalidation
49 * @index: IRTE index to invalidate (start from)
50 * @mask: invalidation mask
52 typedef void (*iec_notify_fn
)(void *private, bool global
,
53 uint32_t index
, uint32_t mask
);
56 iec_notify_fn iec_notify
;
58 QLIST_ENTRY(IEC_Notifier
) list
;
60 typedef struct IEC_Notifier IEC_Notifier
;
62 struct X86IOMMUState
{
64 OnOffAuto intr_supported
; /* Whether vIOMMU supports IR */
65 bool dt_supported
; /* Whether vIOMMU supports DT */
66 bool pt_supported
; /* Whether vIOMMU supports pass-through */
67 QLIST_HEAD(, IEC_Notifier
) iec_notifiers
; /* IEC notify list */
70 bool x86_iommu_ir_supported(X86IOMMUState
*s
);
72 /* Generic IRQ entry information when interrupt remapping is enabled */
74 /* Used by both IOAPIC/MSI interrupt remapping */
77 uint8_t delivery_mode
;
81 /* only used by MSI interrupt remapping */
83 uint8_t msi_addr_last_bits
;
86 struct X86IOMMU_MSIMessage
{
90 uint64_t __addr_hi
:32;
91 uint64_t __addr_head
:12; /* 0xfee */
93 uint64_t __reserved
:8;
94 uint64_t redir_hint
:1;
96 uint64_t __not_used
:2;
98 uint64_t __not_used
:2;
100 uint64_t redir_hint
:1;
101 uint64_t __reserved
:8;
103 uint64_t __addr_head
:12; /* 0xfee */
104 uint64_t __addr_hi
:32;
112 uint32_t __resved1
:16;
113 uint32_t trigger_mode
:1;
116 uint32_t delivery_mode
:3;
120 uint32_t delivery_mode
:3;
123 uint32_t trigger_mode
:1;
124 uint32_t __resved1
:16;
132 * x86_iommu_get_default - get default IOMMU device
133 * @return: pointer to default IOMMU device
135 X86IOMMUState
*x86_iommu_get_default(void);
138 * x86_iommu_iec_register_notifier - register IEC (Interrupt Entry
140 * @iommu: IOMMU device to register
141 * @fn: IEC notifier hook function
142 * @data: notifier private data
144 void x86_iommu_iec_register_notifier(X86IOMMUState
*iommu
,
145 iec_notify_fn fn
, void *data
);
148 * x86_iommu_iec_notify_all - Notify IEC invalidations
149 * @iommu: IOMMU device that sends the notification
150 * @global: whether this is a global invalidation. If true, @index
151 * and @mask are undefined.
152 * @index: starting index of interrupt entry to invalidate
153 * @mask: index mask for the invalidation
155 void x86_iommu_iec_notify_all(X86IOMMUState
*iommu
, bool global
,
156 uint32_t index
, uint32_t mask
);
159 * x86_iommu_irq_to_msi_message - Populate one MSIMessage from X86IOMMUIrq
160 * @X86IOMMUIrq: The IRQ information
161 * @out: Output MSI message
163 void x86_iommu_irq_to_msi_message(X86IOMMUIrq
*irq
, MSIMessage
*out
);