1*8b4eb09eSEric Auger /* 2*8b4eb09eSEric Auger * Virtio IOMMU PCI Bindings 3*8b4eb09eSEric Auger * 4*8b4eb09eSEric Auger * Copyright (c) 2019 Red Hat, Inc. 5*8b4eb09eSEric Auger * Written by Eric Auger 6*8b4eb09eSEric Auger * 7*8b4eb09eSEric Auger * This program is free software; you can redistribute it and/or modify 8*8b4eb09eSEric Auger * it under the terms of the GNU General Public License version 2 or 9*8b4eb09eSEric Auger * (at your option) any later version. 10*8b4eb09eSEric Auger */ 11*8b4eb09eSEric Auger 12*8b4eb09eSEric Auger #include "qemu/osdep.h" 13*8b4eb09eSEric Auger 14*8b4eb09eSEric Auger #include "virtio-pci.h" 15*8b4eb09eSEric Auger #include "hw/virtio/virtio-iommu.h" 16*8b4eb09eSEric Auger #include "hw/qdev-properties.h" 17*8b4eb09eSEric Auger #include "qapi/error.h" 18*8b4eb09eSEric Auger #include "hw/boards.h" 19*8b4eb09eSEric Auger 20*8b4eb09eSEric Auger typedef struct VirtIOIOMMUPCI VirtIOIOMMUPCI; 21*8b4eb09eSEric Auger 22*8b4eb09eSEric Auger /* 23*8b4eb09eSEric Auger * virtio-iommu-pci: This extends VirtioPCIProxy. 24*8b4eb09eSEric Auger * 25*8b4eb09eSEric Auger */ 26*8b4eb09eSEric Auger #define VIRTIO_IOMMU_PCI(obj) \ 27*8b4eb09eSEric Auger OBJECT_CHECK(VirtIOIOMMUPCI, (obj), TYPE_VIRTIO_IOMMU_PCI) 28*8b4eb09eSEric Auger 29*8b4eb09eSEric Auger struct VirtIOIOMMUPCI { 30*8b4eb09eSEric Auger VirtIOPCIProxy parent_obj; 31*8b4eb09eSEric Auger VirtIOIOMMU vdev; 32*8b4eb09eSEric Auger }; 33*8b4eb09eSEric Auger 34*8b4eb09eSEric Auger static Property virtio_iommu_pci_properties[] = { 35*8b4eb09eSEric Auger DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0), 36*8b4eb09eSEric Auger DEFINE_PROP_END_OF_LIST(), 37*8b4eb09eSEric Auger }; 38*8b4eb09eSEric Auger 39*8b4eb09eSEric Auger static void virtio_iommu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) 40*8b4eb09eSEric Auger { 41*8b4eb09eSEric Auger VirtIOIOMMUPCI *dev = VIRTIO_IOMMU_PCI(vpci_dev); 42*8b4eb09eSEric Auger DeviceState *vdev = DEVICE(&dev->vdev); 43*8b4eb09eSEric Auger 44*8b4eb09eSEric Auger if (!qdev_get_machine_hotplug_handler(DEVICE(vpci_dev))) { 45*8b4eb09eSEric Auger MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine()); 46*8b4eb09eSEric Auger 47*8b4eb09eSEric Auger error_setg(errp, 48*8b4eb09eSEric Auger "%s machine fails to create iommu-map device tree bindings", 49*8b4eb09eSEric Auger mc->name); 50*8b4eb09eSEric Auger error_append_hint(errp, 51*8b4eb09eSEric Auger "Check you machine implements a hotplug handler " 52*8b4eb09eSEric Auger "for the virtio-iommu-pci device\n"); 53*8b4eb09eSEric Auger error_append_hint(errp, "Check the guest is booted without FW or with " 54*8b4eb09eSEric Auger "-no-acpi\n"); 55*8b4eb09eSEric Auger return; 56*8b4eb09eSEric Auger } 57*8b4eb09eSEric Auger qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); 58*8b4eb09eSEric Auger object_property_set_link(OBJECT(dev), 59*8b4eb09eSEric Auger OBJECT(pci_get_bus(&vpci_dev->pci_dev)), 60*8b4eb09eSEric Auger "primary-bus", errp); 61*8b4eb09eSEric Auger object_property_set_bool(OBJECT(vdev), true, "realized", errp); 62*8b4eb09eSEric Auger } 63*8b4eb09eSEric Auger 64*8b4eb09eSEric Auger static void virtio_iommu_pci_class_init(ObjectClass *klass, void *data) 65*8b4eb09eSEric Auger { 66*8b4eb09eSEric Auger DeviceClass *dc = DEVICE_CLASS(klass); 67*8b4eb09eSEric Auger VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); 68*8b4eb09eSEric Auger PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); 69*8b4eb09eSEric Auger k->realize = virtio_iommu_pci_realize; 70*8b4eb09eSEric Auger set_bit(DEVICE_CATEGORY_MISC, dc->categories); 71*8b4eb09eSEric Auger device_class_set_props(dc, virtio_iommu_pci_properties); 72*8b4eb09eSEric Auger pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; 73*8b4eb09eSEric Auger pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_IOMMU; 74*8b4eb09eSEric Auger pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; 75*8b4eb09eSEric Auger pcidev_k->class_id = PCI_CLASS_OTHERS; 76*8b4eb09eSEric Auger dc->hotpluggable = false; 77*8b4eb09eSEric Auger } 78*8b4eb09eSEric Auger 79*8b4eb09eSEric Auger static void virtio_iommu_pci_instance_init(Object *obj) 80*8b4eb09eSEric Auger { 81*8b4eb09eSEric Auger VirtIOIOMMUPCI *dev = VIRTIO_IOMMU_PCI(obj); 82*8b4eb09eSEric Auger 83*8b4eb09eSEric Auger virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 84*8b4eb09eSEric Auger TYPE_VIRTIO_IOMMU); 85*8b4eb09eSEric Auger } 86*8b4eb09eSEric Auger 87*8b4eb09eSEric Auger static const VirtioPCIDeviceTypeInfo virtio_iommu_pci_info = { 88*8b4eb09eSEric Auger .base_name = TYPE_VIRTIO_IOMMU_PCI, 89*8b4eb09eSEric Auger .generic_name = "virtio-iommu-pci", 90*8b4eb09eSEric Auger .transitional_name = "virtio-iommu-pci-transitional", 91*8b4eb09eSEric Auger .non_transitional_name = "virtio-iommu-pci-non-transitional", 92*8b4eb09eSEric Auger .instance_size = sizeof(VirtIOIOMMUPCI), 93*8b4eb09eSEric Auger .instance_init = virtio_iommu_pci_instance_init, 94*8b4eb09eSEric Auger .class_init = virtio_iommu_pci_class_init, 95*8b4eb09eSEric Auger }; 96*8b4eb09eSEric Auger 97*8b4eb09eSEric Auger static void virtio_iommu_pci_register(void) 98*8b4eb09eSEric Auger { 99*8b4eb09eSEric Auger virtio_pci_types_register(&virtio_iommu_pci_info); 100*8b4eb09eSEric Auger } 101*8b4eb09eSEric Auger 102*8b4eb09eSEric Auger type_init(virtio_iommu_pci_register) 103*8b4eb09eSEric Auger 104*8b4eb09eSEric Auger 105