]>
Commit | Line | Data |
---|---|---|
3f0e7e57 JR |
1 | /* |
2 | * Machine for remote device | |
3 | * | |
4 | * This machine type is used by the remote device process in multi-process | |
5 | * QEMU. QEMU device models depend on parent busses, interrupt controllers, | |
6 | * memory regions, etc. The remote machine type offers this environment so | |
7 | * that QEMU device models can be used as remote devices. | |
8 | * | |
9 | * Copyright © 2018, 2021 Oracle and/or its affiliates. | |
10 | * | |
11 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | |
12 | * See the COPYING file in the top-level directory. | |
13 | * | |
14 | */ | |
15 | ||
16 | #include "qemu/osdep.h" | |
3f0e7e57 JR |
17 | |
18 | #include "hw/remote/machine.h" | |
3f0e7e57 JR |
19 | #include "exec/memory.h" |
20 | #include "qapi/error.h" | |
bd36adb8 JR |
21 | #include "hw/pci/pci_host.h" |
22 | #include "hw/remote/iohub.h" | |
253007d1 | 23 | #include "hw/remote/iommu.h" |
661e21c4 | 24 | #include "hw/qdev-core.h" |
15ccf9be | 25 | #include "hw/remote/iommu.h" |
3f0e7e57 JR |
26 | |
27 | static void remote_machine_init(MachineState *machine) | |
28 | { | |
29 | MemoryRegion *system_memory, *system_io, *pci_memory; | |
30 | RemoteMachineState *s = REMOTE_MACHINE(machine); | |
31 | RemotePCIHost *rem_host; | |
bd36adb8 | 32 | PCIHostState *pci_host; |
3f0e7e57 JR |
33 | |
34 | system_memory = get_system_memory(); | |
35 | system_io = get_system_io(); | |
36 | ||
37 | pci_memory = g_new(MemoryRegion, 1); | |
38 | memory_region_init(pci_memory, NULL, "pci", UINT64_MAX); | |
39 | ||
40 | rem_host = REMOTE_PCIHOST(qdev_new(TYPE_REMOTE_PCIHOST)); | |
41 | ||
42 | rem_host->mr_pci_mem = pci_memory; | |
43 | rem_host->mr_sys_mem = system_memory; | |
44 | rem_host->mr_sys_io = system_io; | |
45 | ||
46 | s->host = rem_host; | |
47 | ||
48 | object_property_add_child(OBJECT(s), "remote-pcihost", OBJECT(rem_host)); | |
49 | memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1); | |
50 | ||
51 | qdev_realize(DEVICE(rem_host), sysbus_get_default(), &error_fatal); | |
bd36adb8 JR |
52 | |
53 | pci_host = PCI_HOST_BRIDGE(rem_host); | |
54 | ||
15ccf9be JR |
55 | if (s->vfio_user) { |
56 | remote_iommu_setup(pci_host->bus); | |
57 | } | |
58 | ||
bd36adb8 JR |
59 | remote_iohub_init(&s->iohub); |
60 | ||
61 | pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, | |
62 | &s->iohub, REMOTE_IOHUB_NB_PIRQS); | |
661e21c4 JR |
63 | |
64 | qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s)); | |
3f0e7e57 JR |
65 | } |
66 | ||
9b5b473e JR |
67 | static bool remote_machine_get_vfio_user(Object *obj, Error **errp) |
68 | { | |
69 | RemoteMachineState *s = REMOTE_MACHINE(obj); | |
70 | ||
71 | return s->vfio_user; | |
72 | } | |
73 | ||
74 | static void remote_machine_set_vfio_user(Object *obj, bool value, Error **errp) | |
75 | { | |
76 | RemoteMachineState *s = REMOTE_MACHINE(obj); | |
77 | ||
78 | if (phase_check(PHASE_MACHINE_CREATED)) { | |
79 | error_setg(errp, "Error enabling vfio-user - machine already created"); | |
80 | return; | |
81 | } | |
82 | ||
83 | s->vfio_user = value; | |
84 | } | |
85 | ||
8f9a9259 JR |
86 | static bool remote_machine_get_auto_shutdown(Object *obj, Error **errp) |
87 | { | |
88 | RemoteMachineState *s = REMOTE_MACHINE(obj); | |
89 | ||
90 | return s->auto_shutdown; | |
91 | } | |
92 | ||
93 | static void remote_machine_set_auto_shutdown(Object *obj, bool value, | |
94 | Error **errp) | |
95 | { | |
96 | RemoteMachineState *s = REMOTE_MACHINE(obj); | |
97 | ||
98 | s->auto_shutdown = value; | |
99 | } | |
100 | ||
101 | static void remote_machine_instance_init(Object *obj) | |
102 | { | |
103 | RemoteMachineState *s = REMOTE_MACHINE(obj); | |
104 | ||
105 | s->auto_shutdown = true; | |
106 | } | |
107 | ||
253007d1 JR |
108 | static void remote_machine_dev_unplug_cb(HotplugHandler *hotplug_dev, |
109 | DeviceState *dev, Error **errp) | |
110 | { | |
111 | qdev_unrealize(dev); | |
112 | ||
113 | if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { | |
114 | remote_iommu_unplug_dev(PCI_DEVICE(dev)); | |
115 | } | |
116 | } | |
117 | ||
3f0e7e57 JR |
118 | static void remote_machine_class_init(ObjectClass *oc, void *data) |
119 | { | |
120 | MachineClass *mc = MACHINE_CLASS(oc); | |
661e21c4 | 121 | HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); |
3f0e7e57 JR |
122 | |
123 | mc->init = remote_machine_init; | |
124 | mc->desc = "Experimental remote machine"; | |
661e21c4 | 125 | |
253007d1 | 126 | hc->unplug = remote_machine_dev_unplug_cb; |
9b5b473e JR |
127 | |
128 | object_class_property_add_bool(oc, "vfio-user", | |
129 | remote_machine_get_vfio_user, | |
130 | remote_machine_set_vfio_user); | |
8f9a9259 JR |
131 | |
132 | object_class_property_add_bool(oc, "auto-shutdown", | |
133 | remote_machine_get_auto_shutdown, | |
134 | remote_machine_set_auto_shutdown); | |
3f0e7e57 JR |
135 | } |
136 | ||
137 | static const TypeInfo remote_machine = { | |
138 | .name = TYPE_REMOTE_MACHINE, | |
139 | .parent = TYPE_MACHINE, | |
140 | .instance_size = sizeof(RemoteMachineState), | |
8f9a9259 | 141 | .instance_init = remote_machine_instance_init, |
3f0e7e57 | 142 | .class_init = remote_machine_class_init, |
661e21c4 JR |
143 | .interfaces = (InterfaceInfo[]) { |
144 | { TYPE_HOTPLUG_HANDLER }, | |
145 | { } | |
146 | } | |
3f0e7e57 JR |
147 | }; |
148 | ||
149 | static void remote_machine_register_types(void) | |
150 | { | |
151 | type_register_static(&remote_machine); | |
152 | } | |
153 | ||
154 | type_init(remote_machine_register_types); |