]> git.proxmox.com Git - mirror_qemu.git/blame - hw/virtio/virtio-iommu-pci.c
bsd-user: pull in target_arch_thread.h update target_arch_elf.h
[mirror_qemu.git] / hw / virtio / virtio-iommu-pci.c
CommitLineData
8b4eb09e
EA
1/*
2 * Virtio IOMMU PCI Bindings
3 *
4 * Copyright (c) 2019 Red Hat, Inc.
5 * Written by Eric Auger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 or
9 * (at your option) any later version.
10 */
11
12#include "qemu/osdep.h"
13
14#include "virtio-pci.h"
15#include "hw/virtio/virtio-iommu.h"
16#include "hw/qdev-properties.h"
ce35e229 17#include "hw/qdev-properties-system.h"
8b4eb09e
EA
18#include "qapi/error.h"
19#include "hw/boards.h"
db1015e9 20#include "qom/object.h"
8b4eb09e
EA
21
22typedef struct VirtIOIOMMUPCI VirtIOIOMMUPCI;
23
24/*
25 * virtio-iommu-pci: This extends VirtioPCIProxy.
26 *
27 */
8110fa1d
EH
28DECLARE_INSTANCE_CHECKER(VirtIOIOMMUPCI, VIRTIO_IOMMU_PCI,
29 TYPE_VIRTIO_IOMMU_PCI)
8b4eb09e
EA
30
31struct VirtIOIOMMUPCI {
32 VirtIOPCIProxy parent_obj;
33 VirtIOIOMMU vdev;
34};
35
36static Property virtio_iommu_pci_properties[] = {
37 DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
8077b8e5
EA
38 DEFINE_PROP_ARRAY("reserved-regions", VirtIOIOMMUPCI,
39 vdev.nb_reserved_regions, vdev.reserved_regions,
40 qdev_prop_reserved_region, ReservedRegion),
8b4eb09e
EA
41 DEFINE_PROP_END_OF_LIST(),
42};
43
44static void virtio_iommu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
45{
46 VirtIOIOMMUPCI *dev = VIRTIO_IOMMU_PCI(vpci_dev);
47 DeviceState *vdev = DEVICE(&dev->vdev);
8077b8e5 48 VirtIOIOMMU *s = VIRTIO_IOMMU(vdev);
8b4eb09e
EA
49
50 if (!qdev_get_machine_hotplug_handler(DEVICE(vpci_dev))) {
51 MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
52
53 error_setg(errp,
54 "%s machine fails to create iommu-map device tree bindings",
55 mc->name);
56 error_append_hint(errp,
590090b4 57 "Check your machine implements a hotplug handler "
8b4eb09e
EA
58 "for the virtio-iommu-pci device\n");
59 error_append_hint(errp, "Check the guest is booted without FW or with "
60 "-no-acpi\n");
61 return;
62 }
8077b8e5
EA
63 for (int i = 0; i < s->nb_reserved_regions; i++) {
64 if (s->reserved_regions[i].type != VIRTIO_IOMMU_RESV_MEM_T_RESERVED &&
65 s->reserved_regions[i].type != VIRTIO_IOMMU_RESV_MEM_T_MSI) {
66 error_setg(errp, "reserved region %d has an invalid type", i);
67 error_append_hint(errp, "Valid values are 0 and 1\n");
68 }
69 }
5325cc34 70 object_property_set_link(OBJECT(dev), "primary-bus",
8b4eb09e 71 OBJECT(pci_get_bus(&vpci_dev->pci_dev)),
5325cc34 72 &error_abort);
8f39562a 73 virtio_pci_force_virtio_1(vpci_dev);
99ba777e 74 qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
8b4eb09e
EA
75}
76
77static void virtio_iommu_pci_class_init(ObjectClass *klass, void *data)
78{
79 DeviceClass *dc = DEVICE_CLASS(klass);
80 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
81 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
82 k->realize = virtio_iommu_pci_realize;
83 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
84 device_class_set_props(dc, virtio_iommu_pci_properties);
85 pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
86 pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_IOMMU;
87 pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
88 pcidev_k->class_id = PCI_CLASS_OTHERS;
89 dc->hotpluggable = false;
90}
91
92static void virtio_iommu_pci_instance_init(Object *obj)
93{
94 VirtIOIOMMUPCI *dev = VIRTIO_IOMMU_PCI(obj);
95
96 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
97 TYPE_VIRTIO_IOMMU);
98}
99
100static const VirtioPCIDeviceTypeInfo virtio_iommu_pci_info = {
101 .base_name = TYPE_VIRTIO_IOMMU_PCI,
102 .generic_name = "virtio-iommu-pci",
8b4eb09e
EA
103 .non_transitional_name = "virtio-iommu-pci-non-transitional",
104 .instance_size = sizeof(VirtIOIOMMUPCI),
105 .instance_init = virtio_iommu_pci_instance_init,
106 .class_init = virtio_iommu_pci_class_init,
107};
108
109static void virtio_iommu_pci_register(void)
110{
111 virtio_pci_types_register(&virtio_iommu_pci_info);
112}
113
114type_init(virtio_iommu_pci_register)
115
116