1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include "qemu/osdep.h"
21#include "hw/sysbus.h"
22#include "hw/boards.h"
23#include "hw/i386/x86-iommu.h"
24#include "qemu/error-report.h"
25#include "trace.h"
26
27void x86_iommu_iec_register_notifier(X86IOMMUState *iommu,
28 iec_notify_fn fn, void *data)
29{
30 IEC_Notifier *notifier = g_new0(IEC_Notifier, 1);
31
32 notifier->iec_notify = fn;
33 notifier->private = data;
34
35 QLIST_INSERT_HEAD(&iommu->iec_notifiers, notifier, list);
36}
37
38void x86_iommu_iec_notify_all(X86IOMMUState *iommu, bool global,
39 uint32_t index, uint32_t mask)
40{
41 IEC_Notifier *notifier;
42
43 trace_x86_iommu_iec_notify(global, index, mask);
44
45 QLIST_FOREACH(notifier, &iommu->iec_notifiers, list) {
46 if (notifier->iec_notify) {
47 notifier->iec_notify(notifier->private, global,
48 index, mask);
49 }
50 }
51}
52
53
54static X86IOMMUState *x86_iommu_default = NULL;
55
56static void x86_iommu_set_default(X86IOMMUState *x86_iommu)
57{
58 assert(x86_iommu);
59
60 if (x86_iommu_default) {
61 error_report("QEMU does not support multiple vIOMMUs "
62 "for x86 yet.");
63 exit(1);
64 }
65
66 x86_iommu_default = x86_iommu;
67}
68
69X86IOMMUState *x86_iommu_get_default(void)
70{
71 return x86_iommu_default;
72}
73
74IommuType x86_iommu_get_type(void)
75{
76 return x86_iommu_default->type;
77}
78
79static void x86_iommu_realize(DeviceState *dev, Error **errp)
80{
81 X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(dev);
82 X86IOMMUClass *x86_class = X86_IOMMU_GET_CLASS(dev);
83 QLIST_INIT(&x86_iommu->iec_notifiers);
84 if (x86_class->realize) {
85 x86_class->realize(dev, errp);
86 }
87
88 x86_iommu_set_default(X86_IOMMU_DEVICE(dev));
89}
90
91static Property x86_iommu_properties[] = {
92 DEFINE_PROP_BOOL("intremap", X86IOMMUState, intr_supported, false),
93 DEFINE_PROP_BOOL("device-iotlb", X86IOMMUState, dt_supported, false),
94 DEFINE_PROP_BOOL("pt", X86IOMMUState, pt_supported, true),
95 DEFINE_PROP_END_OF_LIST(),
96};
97
98static void x86_iommu_class_init(ObjectClass *klass, void *data)
99{
100 DeviceClass *dc = DEVICE_CLASS(klass);
101 dc->realize = x86_iommu_realize;
102 dc->props = x86_iommu_properties;
103}
104
105static const TypeInfo x86_iommu_info = {
106 .name = TYPE_X86_IOMMU_DEVICE,
107 .parent = TYPE_SYS_BUS_DEVICE,
108 .instance_size = sizeof(X86IOMMUState),
109 .class_init = x86_iommu_class_init,
110 .class_size = sizeof(X86IOMMUClass),
111 .abstract = true,
112};
113
114static void x86_iommu_register_types(void)
115{
116 type_register_static(&x86_iommu_info);
117}
118
119type_init(x86_iommu_register_types)
120