]> Git Repo - qemu.git/blob - tests/libqos/arm-virt-machine.c
Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2019-05-21' into...
[qemu.git] / tests / libqos / arm-virt-machine.c
1 /*
2  * libqos driver framework
3  *
4  * Copyright (c) 2018 Emanuele Giuseppe Esposito <[email protected]>
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 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
19 #include "qemu/osdep.h"
20 #include "libqtest.h"
21 #include "libqos/malloc.h"
22 #include "libqos/qgraph.h"
23 #include "libqos/virtio-mmio.h"
24
25 #define ARM_PAGE_SIZE               4096
26 #define VIRTIO_MMIO_BASE_ADDR       0x0A003E00
27 #define ARM_VIRT_RAM_ADDR           0x40000000
28 #define ARM_VIRT_RAM_SIZE           0x20000000
29 #define VIRTIO_MMIO_SIZE            0x00000200
30
31 typedef struct QVirtMachine QVirtMachine;
32
33 struct QVirtMachine {
34     QOSGraphObject obj;
35     QGuestAllocator alloc;
36     QVirtioMMIODevice virtio_mmio;
37 };
38
39 static void virt_destructor(QOSGraphObject *obj)
40 {
41     QVirtMachine *machine = (QVirtMachine *) obj;
42     alloc_destroy(&machine->alloc);
43 }
44
45 static void *virt_get_driver(void *object, const char *interface)
46 {
47     QVirtMachine *machine = object;
48     if (!g_strcmp0(interface, "memory")) {
49         return &machine->alloc;
50     }
51
52     fprintf(stderr, "%s not present in arm/virtio\n", interface);
53     g_assert_not_reached();
54 }
55
56 static QOSGraphObject *virt_get_device(void *obj, const char *device)
57 {
58     QVirtMachine *machine = obj;
59     if (!g_strcmp0(device, "virtio-mmio")) {
60         return &machine->virtio_mmio.obj;
61     }
62
63     fprintf(stderr, "%s not present in arm/virtio\n", device);
64     g_assert_not_reached();
65 }
66
67 static void *qos_create_machine_arm_virt(QTestState *qts)
68 {
69     QVirtMachine *machine = g_new0(QVirtMachine, 1);
70
71     alloc_init(&machine->alloc, 0,
72                ARM_VIRT_RAM_ADDR,
73                ARM_VIRT_RAM_ADDR + ARM_VIRT_RAM_SIZE,
74                ARM_PAGE_SIZE);
75     qvirtio_mmio_init_device(&machine->virtio_mmio, qts, VIRTIO_MMIO_BASE_ADDR,
76                              VIRTIO_MMIO_SIZE);
77
78     machine->obj.get_device = virt_get_device;
79     machine->obj.get_driver = virt_get_driver;
80     machine->obj.destructor = virt_destructor;
81     return machine;
82 }
83
84 static void virtio_mmio_register_nodes(void)
85 {
86     qos_node_create_machine("arm/virt", qos_create_machine_arm_virt);
87     qos_node_contains("arm/virt", "virtio-mmio", NULL);
88 }
89
90 libqos_init(virtio_mmio_register_nodes);
This page took 0.030175 seconds and 4 git commands to generate.