1 /* 2 * QEMU emulation of common X86 IOMMU 3 * 4 * Copyright (C) 2016 Peter Xu, Red Hat <peterx@redhat.com> 5 * 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. 10 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. 15 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/>. 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 26 /* Default X86 IOMMU device */ 27 static X86IOMMUState *x86_iommu_default = NULL; 28 29 static void x86_iommu_set_default(X86IOMMUState *x86_iommu) 30 { 31 assert(x86_iommu); 32 33 if (x86_iommu_default) { 34 error_report("QEMU does not support multiple vIOMMUs " 35 "for x86 yet."); 36 exit(1); 37 } 38 39 x86_iommu_default = x86_iommu; 40 } 41 42 X86IOMMUState *x86_iommu_get_default(void) 43 { 44 return x86_iommu_default; 45 } 46 47 static void x86_iommu_realize(DeviceState *dev, Error **errp) 48 { 49 X86IOMMUClass *x86_class = X86_IOMMU_GET_CLASS(dev); 50 if (x86_class->realize) { 51 x86_class->realize(dev, errp); 52 } 53 x86_iommu_set_default(X86_IOMMU_DEVICE(dev)); 54 } 55 56 static void x86_iommu_class_init(ObjectClass *klass, void *data) 57 { 58 DeviceClass *dc = DEVICE_CLASS(klass); 59 dc->realize = x86_iommu_realize; 60 } 61 62 static bool x86_iommu_intremap_prop_get(Object *o, Error **errp) 63 { 64 X86IOMMUState *s = X86_IOMMU_DEVICE(o); 65 return s->intr_supported; 66 } 67 68 static void x86_iommu_intremap_prop_set(Object *o, bool value, Error **errp) 69 { 70 X86IOMMUState *s = X86_IOMMU_DEVICE(o); 71 s->intr_supported = value; 72 } 73 74 static void x86_iommu_instance_init(Object *o) 75 { 76 X86IOMMUState *s = X86_IOMMU_DEVICE(o); 77 78 /* By default, do not support IR */ 79 s->intr_supported = false; 80 object_property_add_bool(o, "intremap", x86_iommu_intremap_prop_get, 81 x86_iommu_intremap_prop_set, NULL); 82 } 83 84 static const TypeInfo x86_iommu_info = { 85 .name = TYPE_X86_IOMMU_DEVICE, 86 .parent = TYPE_SYS_BUS_DEVICE, 87 .instance_init = x86_iommu_instance_init, 88 .instance_size = sizeof(X86IOMMUState), 89 .class_init = x86_iommu_class_init, 90 .class_size = sizeof(X86IOMMUClass), 91 .abstract = true, 92 }; 93 94 static void x86_iommu_register_types(void) 95 { 96 type_register_static(&x86_iommu_info); 97 } 98 99 type_init(x86_iommu_register_types) 100