18b4eb09eSEric Auger /* 28b4eb09eSEric Auger * Virtio IOMMU PCI Bindings 38b4eb09eSEric Auger * 48b4eb09eSEric Auger * Copyright (c) 2019 Red Hat, Inc. 58b4eb09eSEric Auger * Written by Eric Auger 68b4eb09eSEric Auger * 78b4eb09eSEric Auger * This program is free software; you can redistribute it and/or modify 88b4eb09eSEric Auger * it under the terms of the GNU General Public License version 2 or 98b4eb09eSEric Auger * (at your option) any later version. 108b4eb09eSEric Auger */ 118b4eb09eSEric Auger 128b4eb09eSEric Auger #include "qemu/osdep.h" 138b4eb09eSEric Auger 148b4eb09eSEric Auger #include "virtio-pci.h" 158b4eb09eSEric Auger #include "hw/virtio/virtio-iommu.h" 168b4eb09eSEric Auger #include "hw/qdev-properties.h" 178b4eb09eSEric Auger #include "qapi/error.h" 188b4eb09eSEric Auger #include "hw/boards.h" 198b4eb09eSEric Auger 208b4eb09eSEric Auger typedef struct VirtIOIOMMUPCI VirtIOIOMMUPCI; 218b4eb09eSEric Auger 228b4eb09eSEric Auger /* 238b4eb09eSEric Auger * virtio-iommu-pci: This extends VirtioPCIProxy. 248b4eb09eSEric Auger * 258b4eb09eSEric Auger */ 268b4eb09eSEric Auger #define VIRTIO_IOMMU_PCI(obj) \ 278b4eb09eSEric Auger OBJECT_CHECK(VirtIOIOMMUPCI, (obj), TYPE_VIRTIO_IOMMU_PCI) 288b4eb09eSEric Auger 298b4eb09eSEric Auger struct VirtIOIOMMUPCI { 308b4eb09eSEric Auger VirtIOPCIProxy parent_obj; 318b4eb09eSEric Auger VirtIOIOMMU vdev; 328b4eb09eSEric Auger }; 338b4eb09eSEric Auger 348b4eb09eSEric Auger static Property virtio_iommu_pci_properties[] = { 358b4eb09eSEric Auger DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0), 368b4eb09eSEric Auger DEFINE_PROP_END_OF_LIST(), 378b4eb09eSEric Auger }; 388b4eb09eSEric Auger 398b4eb09eSEric Auger static void virtio_iommu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) 408b4eb09eSEric Auger { 418b4eb09eSEric Auger VirtIOIOMMUPCI *dev = VIRTIO_IOMMU_PCI(vpci_dev); 428b4eb09eSEric Auger DeviceState *vdev = DEVICE(&dev->vdev); 438b4eb09eSEric Auger 448b4eb09eSEric Auger if (!qdev_get_machine_hotplug_handler(DEVICE(vpci_dev))) { 458b4eb09eSEric Auger MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine()); 468b4eb09eSEric Auger 478b4eb09eSEric Auger error_setg(errp, 488b4eb09eSEric Auger "%s machine fails to create iommu-map device tree bindings", 498b4eb09eSEric Auger mc->name); 508b4eb09eSEric Auger error_append_hint(errp, 51*590090b4SPeter Maydell "Check your machine implements a hotplug handler " 528b4eb09eSEric Auger "for the virtio-iommu-pci device\n"); 538b4eb09eSEric Auger error_append_hint(errp, "Check the guest is booted without FW or with " 548b4eb09eSEric Auger "-no-acpi\n"); 558b4eb09eSEric Auger return; 568b4eb09eSEric Auger } 578b4eb09eSEric Auger object_property_set_link(OBJECT(dev), 588b4eb09eSEric Auger OBJECT(pci_get_bus(&vpci_dev->pci_dev)), 598b4eb09eSEric Auger "primary-bus", errp); 6099ba777eSMarkus Armbruster qdev_realize(vdev, BUS(&vpci_dev->bus), errp); 618b4eb09eSEric Auger } 628b4eb09eSEric Auger 638b4eb09eSEric Auger static void virtio_iommu_pci_class_init(ObjectClass *klass, void *data) 648b4eb09eSEric Auger { 658b4eb09eSEric Auger DeviceClass *dc = DEVICE_CLASS(klass); 668b4eb09eSEric Auger VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); 678b4eb09eSEric Auger PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); 688b4eb09eSEric Auger k->realize = virtio_iommu_pci_realize; 698b4eb09eSEric Auger set_bit(DEVICE_CATEGORY_MISC, dc->categories); 708b4eb09eSEric Auger device_class_set_props(dc, virtio_iommu_pci_properties); 718b4eb09eSEric Auger pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; 728b4eb09eSEric Auger pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_IOMMU; 738b4eb09eSEric Auger pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; 748b4eb09eSEric Auger pcidev_k->class_id = PCI_CLASS_OTHERS; 758b4eb09eSEric Auger dc->hotpluggable = false; 768b4eb09eSEric Auger } 778b4eb09eSEric Auger 788b4eb09eSEric Auger static void virtio_iommu_pci_instance_init(Object *obj) 798b4eb09eSEric Auger { 808b4eb09eSEric Auger VirtIOIOMMUPCI *dev = VIRTIO_IOMMU_PCI(obj); 818b4eb09eSEric Auger 828b4eb09eSEric Auger virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 838b4eb09eSEric Auger TYPE_VIRTIO_IOMMU); 848b4eb09eSEric Auger } 858b4eb09eSEric Auger 868b4eb09eSEric Auger static const VirtioPCIDeviceTypeInfo virtio_iommu_pci_info = { 878b4eb09eSEric Auger .base_name = TYPE_VIRTIO_IOMMU_PCI, 888b4eb09eSEric Auger .generic_name = "virtio-iommu-pci", 898b4eb09eSEric Auger .transitional_name = "virtio-iommu-pci-transitional", 908b4eb09eSEric Auger .non_transitional_name = "virtio-iommu-pci-non-transitional", 918b4eb09eSEric Auger .instance_size = sizeof(VirtIOIOMMUPCI), 928b4eb09eSEric Auger .instance_init = virtio_iommu_pci_instance_init, 938b4eb09eSEric Auger .class_init = virtio_iommu_pci_class_init, 948b4eb09eSEric Auger }; 958b4eb09eSEric Auger 968b4eb09eSEric Auger static void virtio_iommu_pci_register(void) 978b4eb09eSEric Auger { 988b4eb09eSEric Auger virtio_pci_types_register(&virtio_iommu_pci_info); 998b4eb09eSEric Auger } 1008b4eb09eSEric Auger 1018b4eb09eSEric Auger type_init(virtio_iommu_pci_register) 1028b4eb09eSEric Auger 1038b4eb09eSEric Auger 104