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/pci.h"
25 #include "hw/pci/msi.h"
26 #include "qom/object.h"
28 #define TYPE_X86_IOMMU_DEVICE ("x86-iommu")
29 OBJECT_DECLARE_TYPE(X86IOMMUState
, X86IOMMUClass
, X86_IOMMU_DEVICE
)
31 #define X86_IOMMU_SID_INVALID (0xffff)
33 typedef struct X86IOMMUIrq X86IOMMUIrq
;
34 typedef struct X86IOMMU_MSIMessage X86IOMMU_MSIMessage
;
36 struct X86IOMMUClass
{
37 SysBusDeviceClass parent
;
38 /* Intel/AMD specific realize() hook */
39 DeviceRealize realize
;
40 /* MSI-based interrupt remapping */
41 int (*int_remap
)(X86IOMMUState
*iommu
, MSIMessage
*src
,
42 MSIMessage
*dst
, uint16_t sid
);
46 * iec_notify_fn - IEC (Interrupt Entry Cache) notifier hook,
47 * triggered when IR invalidation happens.
48 * @private: private data
49 * @global: whether this is a global IEC invalidation
50 * @index: IRTE index to invalidate (start from)
51 * @mask: invalidation mask
53 typedef void (*iec_notify_fn
)(void *private, bool global
,
54 uint32_t index
, uint32_t mask
);
57 iec_notify_fn iec_notify
;
59 QLIST_ENTRY(IEC_Notifier
) list
;
61 typedef struct IEC_Notifier IEC_Notifier
;
63 struct X86IOMMUState
{
65 OnOffAuto intr_supported
; /* Whether vIOMMU supports IR */
66 bool dt_supported
; /* Whether vIOMMU supports DT */
67 bool pt_supported
; /* Whether vIOMMU supports pass-through */
68 QLIST_HEAD(, IEC_Notifier
) iec_notifiers
; /* IEC notify list */
71 bool x86_iommu_ir_supported(X86IOMMUState
*s
);
73 /* Generic IRQ entry information when interrupt remapping is enabled */
75 /* Used by both IOAPIC/MSI interrupt remapping */
78 uint8_t delivery_mode
;
82 /* only used by MSI interrupt remapping */
84 uint8_t msi_addr_last_bits
;
87 struct X86IOMMU_MSIMessage
{
90 #ifdef HOST_WORDS_BIGENDIAN
91 uint32_t __addr_head
:12; /* 0xfee */
93 uint32_t __reserved
:8;
94 uint32_t redir_hint
:1;
96 uint32_t __not_used
:2;
98 uint32_t __not_used
:2;
100 uint32_t redir_hint
:1;
101 uint32_t __reserved
:8;
103 uint32_t __addr_head
:12; /* 0xfee */
111 #ifdef HOST_WORDS_BIGENDIAN
112 uint16_t trigger_mode
:1;
115 uint16_t delivery_mode
:3;
119 uint16_t delivery_mode
:3;
122 uint16_t trigger_mode
:1;
131 * x86_iommu_get_default - get default IOMMU device
132 * @return: pointer to default IOMMU device
134 X86IOMMUState
*x86_iommu_get_default(void);
137 * x86_iommu_iec_register_notifier - register IEC (Interrupt Entry
139 * @iommu: IOMMU device to register
140 * @fn: IEC notifier hook function
141 * @data: notifier private data
143 void x86_iommu_iec_register_notifier(X86IOMMUState
*iommu
,
144 iec_notify_fn fn
, void *data
);
147 * x86_iommu_iec_notify_all - Notify IEC invalidations
148 * @iommu: IOMMU device that sends the notification
149 * @global: whether this is a global invalidation. If true, @index
150 * and @mask are undefined.
151 * @index: starting index of interrupt entry to invalidate
152 * @mask: index mask for the invalidation
154 void x86_iommu_iec_notify_all(X86IOMMUState
*iommu
, bool global
,
155 uint32_t index
, uint32_t mask
);
158 * x86_iommu_irq_to_msi_message - Populate one MSIMessage from X86IOMMUIrq
159 * @X86IOMMUIrq: The IRQ information
160 * @out: Output MSI message
162 void x86_iommu_irq_to_msi_message(X86IOMMUIrq
*irq
, MSIMessage
*out
);