arm-virt-machine.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * libqos driver framework
  3. *
  4. * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License version 2.1 as published by the Free Software Foundation.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, see <http://www.gnu.org/licenses/>
  17. */
  18. #include "qemu/osdep.h"
  19. #include "../libqtest.h"
  20. #include "qemu/module.h"
  21. #include "malloc.h"
  22. #include "qgraph.h"
  23. #include "virtio-mmio.h"
  24. #define ARM_PAGE_SIZE 4096
  25. #define VIRTIO_MMIO_BASE_ADDR 0x0A003E00
  26. #define ARM_VIRT_RAM_ADDR 0x40000000
  27. #define ARM_VIRT_RAM_SIZE 0x20000000
  28. #define VIRTIO_MMIO_SIZE 0x00000200
  29. typedef struct QVirtMachine QVirtMachine;
  30. struct QVirtMachine {
  31. QOSGraphObject obj;
  32. QGuestAllocator alloc;
  33. QVirtioMMIODevice virtio_mmio;
  34. };
  35. static void virt_destructor(QOSGraphObject *obj)
  36. {
  37. QVirtMachine *machine = (QVirtMachine *) obj;
  38. alloc_destroy(&machine->alloc);
  39. }
  40. static void *virt_get_driver(void *object, const char *interface)
  41. {
  42. QVirtMachine *machine = object;
  43. if (!g_strcmp0(interface, "memory")) {
  44. return &machine->alloc;
  45. }
  46. fprintf(stderr, "%s not present in arm/virtio\n", interface);
  47. g_assert_not_reached();
  48. }
  49. static QOSGraphObject *virt_get_device(void *obj, const char *device)
  50. {
  51. QVirtMachine *machine = obj;
  52. if (!g_strcmp0(device, "virtio-mmio")) {
  53. return &machine->virtio_mmio.obj;
  54. }
  55. fprintf(stderr, "%s not present in arm/virtio\n", device);
  56. g_assert_not_reached();
  57. }
  58. static void *qos_create_machine_arm_virt(QTestState *qts)
  59. {
  60. QVirtMachine *machine = g_new0(QVirtMachine, 1);
  61. alloc_init(&machine->alloc, 0,
  62. ARM_VIRT_RAM_ADDR,
  63. ARM_VIRT_RAM_ADDR + ARM_VIRT_RAM_SIZE,
  64. ARM_PAGE_SIZE);
  65. qvirtio_mmio_init_device(&machine->virtio_mmio, qts, VIRTIO_MMIO_BASE_ADDR,
  66. VIRTIO_MMIO_SIZE);
  67. machine->obj.get_device = virt_get_device;
  68. machine->obj.get_driver = virt_get_driver;
  69. machine->obj.destructor = virt_destructor;
  70. return machine;
  71. }
  72. static void virtio_mmio_register_nodes(void)
  73. {
  74. qos_node_create_machine("arm/virt", qos_create_machine_arm_virt);
  75. qos_node_contains("arm/virt", "virtio-mmio", NULL);
  76. }
  77. libqos_init(virtio_mmio_register_nodes);