machine.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include "qemu/osdep.h"
  16. #include "qemu-common.h"
  17. #include "hw/remote/machine.h"
  18. #include "exec/memory.h"
  19. #include "qapi/error.h"
  20. #include "hw/pci/pci_host.h"
  21. #include "hw/remote/iohub.h"
  22. static void remote_machine_init(MachineState *machine)
  23. {
  24. MemoryRegion *system_memory, *system_io, *pci_memory;
  25. RemoteMachineState *s = REMOTE_MACHINE(machine);
  26. RemotePCIHost *rem_host;
  27. PCIHostState *pci_host;
  28. system_memory = get_system_memory();
  29. system_io = get_system_io();
  30. pci_memory = g_new(MemoryRegion, 1);
  31. memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
  32. rem_host = REMOTE_PCIHOST(qdev_new(TYPE_REMOTE_PCIHOST));
  33. rem_host->mr_pci_mem = pci_memory;
  34. rem_host->mr_sys_mem = system_memory;
  35. rem_host->mr_sys_io = system_io;
  36. s->host = rem_host;
  37. object_property_add_child(OBJECT(s), "remote-pcihost", OBJECT(rem_host));
  38. memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1);
  39. qdev_realize(DEVICE(rem_host), sysbus_get_default(), &error_fatal);
  40. pci_host = PCI_HOST_BRIDGE(rem_host);
  41. remote_iohub_init(&s->iohub);
  42. pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq,
  43. &s->iohub, REMOTE_IOHUB_NB_PIRQS);
  44. }
  45. static void remote_machine_class_init(ObjectClass *oc, void *data)
  46. {
  47. MachineClass *mc = MACHINE_CLASS(oc);
  48. mc->init = remote_machine_init;
  49. mc->desc = "Experimental remote machine";
  50. }
  51. static const TypeInfo remote_machine = {
  52. .name = TYPE_REMOTE_MACHINE,
  53. .parent = TYPE_MACHINE,
  54. .instance_size = sizeof(RemoteMachineState),
  55. .class_init = remote_machine_class_init,
  56. };
  57. static void remote_machine_register_types(void)
  58. {
  59. type_register_static(&remote_machine);
  60. }
  61. type_init(remote_machine_register_types);