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 typedef enum IommuType
{
42 struct X86IOMMUClass
{
43 SysBusDeviceClass parent
;
44 /* Intel/AMD specific realize() hook */
45 DeviceRealize realize
;
46 /* MSI-based interrupt remapping */
47 int (*int_remap
)(X86IOMMUState
*iommu
, MSIMessage
*src
,
48 MSIMessage
*dst
, uint16_t sid
);
52 * iec_notify_fn - IEC (Interrupt Entry Cache) notifier hook,
53 * triggered when IR invalidation happens.
54 * @private: private data
55 * @global: whether this is a global IEC invalidation
56 * @index: IRTE index to invalidate (start from)
57 * @mask: invalidation mask
59 typedef void (*iec_notify_fn
)(void *private, bool global
,
60 uint32_t index
, uint32_t mask
);
63 iec_notify_fn iec_notify
;
65 QLIST_ENTRY(IEC_Notifier
) list
;
67 typedef struct IEC_Notifier IEC_Notifier
;
69 struct X86IOMMUState
{
71 OnOffAuto intr_supported
; /* Whether vIOMMU supports IR */
72 bool dt_supported
; /* Whether vIOMMU supports DT */
73 bool pt_supported
; /* Whether vIOMMU supports pass-through */
74 IommuType type
; /* IOMMU type - AMD/Intel */
75 QLIST_HEAD(, IEC_Notifier
) iec_notifiers
; /* IEC notify list */
78 bool x86_iommu_ir_supported(X86IOMMUState
*s
);
80 /* Generic IRQ entry information when interrupt remapping is enabled */
82 /* Used by both IOAPIC/MSI interrupt remapping */
85 uint8_t delivery_mode
;
89 /* only used by MSI interrupt remapping */
91 uint8_t msi_addr_last_bits
;
94 struct X86IOMMU_MSIMessage
{
97 #ifdef HOST_WORDS_BIGENDIAN
98 uint32_t __addr_head
:12; /* 0xfee */
100 uint32_t __reserved
:8;
101 uint32_t redir_hint
:1;
102 uint32_t dest_mode
:1;
103 uint32_t __not_used
:2;
105 uint32_t __not_used
:2;
106 uint32_t dest_mode
:1;
107 uint32_t redir_hint
:1;
108 uint32_t __reserved
:8;
110 uint32_t __addr_head
:12; /* 0xfee */
118 #ifdef HOST_WORDS_BIGENDIAN
119 uint16_t trigger_mode
:1;
122 uint16_t delivery_mode
:3;
126 uint16_t delivery_mode
:3;
129 uint16_t trigger_mode
:1;
138 * x86_iommu_get_default - get default IOMMU device
139 * @return: pointer to default IOMMU device
141 X86IOMMUState
*x86_iommu_get_default(void);
144 * x86_iommu_get_type - get IOMMU type
146 IommuType
x86_iommu_get_type(void);
149 * x86_iommu_iec_register_notifier - register IEC (Interrupt Entry
151 * @iommu: IOMMU device to register
152 * @fn: IEC notifier hook function
153 * @data: notifier private data
155 void x86_iommu_iec_register_notifier(X86IOMMUState
*iommu
,
156 iec_notify_fn fn
, void *data
);
159 * x86_iommu_iec_notify_all - Notify IEC invalidations
160 * @iommu: IOMMU device that sends the notification
161 * @global: whether this is a global invalidation. If true, @index
162 * and @mask are undefined.
163 * @index: starting index of interrupt entry to invalidate
164 * @mask: index mask for the invalidation
166 void x86_iommu_iec_notify_all(X86IOMMUState
*iommu
, bool global
,
167 uint32_t index
, uint32_t mask
);
170 * x86_iommu_irq_to_msi_message - Populate one MSIMessage from X86IOMMUIrq
171 * @X86IOMMUIrq: The IRQ information
172 * @out: Output MSI message
174 void x86_iommu_irq_to_msi_message(X86IOMMUIrq
*irq
, MSIMessage
*out
);