1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef HW_I386_X86_IOMMU_H
21#define HW_I386_X86_IOMMU_H
22
23#include "hw/sysbus.h"
24#include "hw/pci/pci.h"
25#include "hw/pci/msi.h"
26#include "qom/object.h"
27
28#define TYPE_X86_IOMMU_DEVICE ("x86-iommu")
29OBJECT_DECLARE_TYPE(X86IOMMUState, X86IOMMUClass, X86_IOMMU_DEVICE)
30
31#define X86_IOMMU_SID_INVALID (0xffff)
32
33typedef struct X86IOMMUIrq X86IOMMUIrq;
34typedef struct X86IOMMU_MSIMessage X86IOMMU_MSIMessage;
35
36struct X86IOMMUClass {
37 SysBusDeviceClass parent;
38
39 DeviceRealize realize;
40
41 int (*int_remap)(X86IOMMUState *iommu, MSIMessage *src,
42 MSIMessage *dst, uint16_t sid);
43};
44
45
46
47
48
49
50
51
52
53typedef void (*iec_notify_fn)(void *private, bool global,
54 uint32_t index, uint32_t mask);
55
56struct IEC_Notifier {
57 iec_notify_fn iec_notify;
58 void *private;
59 QLIST_ENTRY(IEC_Notifier) list;
60};
61typedef struct IEC_Notifier IEC_Notifier;
62
63struct X86IOMMUState {
64 SysBusDevice busdev;
65 OnOffAuto intr_supported;
66 bool dt_supported;
67 bool pt_supported;
68 QLIST_HEAD(, IEC_Notifier) iec_notifiers;
69};
70
71bool x86_iommu_ir_supported(X86IOMMUState *s);
72
73
74struct X86IOMMUIrq {
75
76 uint8_t trigger_mode;
77 uint8_t vector;
78 uint8_t delivery_mode;
79 uint32_t dest;
80 uint8_t dest_mode;
81
82
83 uint8_t redir_hint;
84 uint8_t msi_addr_last_bits;
85};
86
87struct X86IOMMU_MSIMessage {
88 union {
89 struct {
90#if HOST_BIG_ENDIAN
91 uint32_t __addr_head:12;
92 uint32_t dest:8;
93 uint32_t __reserved:8;
94 uint32_t redir_hint:1;
95 uint32_t dest_mode:1;
96 uint32_t __not_used:2;
97#else
98 uint32_t __not_used:2;
99 uint32_t dest_mode:1;
100 uint32_t redir_hint:1;
101 uint32_t __reserved:8;
102 uint32_t dest:8;
103 uint32_t __addr_head:12;
104#endif
105 uint32_t __addr_hi;
106 } QEMU_PACKED;
107 uint64_t msi_addr;
108 };
109 union {
110 struct {
111#if HOST_BIG_ENDIAN
112 uint16_t trigger_mode:1;
113 uint16_t level:1;
114 uint16_t __resved:3;
115 uint16_t delivery_mode:3;
116 uint16_t vector:8;
117#else
118 uint16_t vector:8;
119 uint16_t delivery_mode:3;
120 uint16_t __resved:3;
121 uint16_t level:1;
122 uint16_t trigger_mode:1;
123#endif
124 uint16_t __resved1;
125 } QEMU_PACKED;
126 uint32_t msi_data;
127 };
128};
129
130
131
132
133
134X86IOMMUState *x86_iommu_get_default(void);
135
136
137
138
139
140
141
142
143void x86_iommu_iec_register_notifier(X86IOMMUState *iommu,
144 iec_notify_fn fn, void *data);
145
146
147
148
149
150
151
152
153
154void x86_iommu_iec_notify_all(X86IOMMUState *iommu, bool global,
155 uint32_t index, uint32_t mask);
156
157
158
159
160
161
162void x86_iommu_irq_to_msi_message(X86IOMMUIrq *irq, MSIMessage *out);
163#endif
164