]> Git Repo - qemu.git/blob - tests/libqos/arm-raspi2-machine.c
Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2019-05-21' into...
[qemu.git] / tests / libqos / arm-raspi2-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 "sdhci.h"
24
25 #define ARM_PAGE_SIZE             4096
26 #define RASPI2_RAM_ADDR           0
27 #define RASPI2_RAM_SIZE           0x20000000
28
29 typedef struct QRaspi2Machine QRaspi2Machine;
30
31 struct QRaspi2Machine {
32     QOSGraphObject obj;
33     QGuestAllocator alloc;
34     QSDHCI_MemoryMapped sdhci;
35 };
36
37 static void *raspi2_get_driver(void *object, const char *interface)
38 {
39     QRaspi2Machine *machine = object;
40     if (!g_strcmp0(interface, "memory")) {
41         return &machine->alloc;
42     }
43
44     fprintf(stderr, "%s not present in arm/raspi2\n", interface);
45     g_assert_not_reached();
46 }
47
48 static QOSGraphObject *raspi2_get_device(void *obj, const char *device)
49 {
50     QRaspi2Machine *machine = obj;
51     if (!g_strcmp0(device, "generic-sdhci")) {
52         return &machine->sdhci.obj;
53     }
54
55     fprintf(stderr, "%s not present in arm/raspi2\n", device);
56     g_assert_not_reached();
57 }
58
59 static void raspi2_destructor(QOSGraphObject *obj)
60 {
61     QRaspi2Machine *machine = (QRaspi2Machine *) obj;
62     alloc_destroy(&machine->alloc);
63 }
64
65 static void *qos_create_machine_arm_raspi2(QTestState *qts)
66 {
67     QRaspi2Machine *machine = g_new0(QRaspi2Machine, 1);
68
69     alloc_init(&machine->alloc, 0,
70                RASPI2_RAM_ADDR + (1 << 20),
71                RASPI2_RAM_ADDR + RASPI2_RAM_SIZE,
72                ARM_PAGE_SIZE);
73     machine->obj.get_device = raspi2_get_device;
74     machine->obj.get_driver = raspi2_get_driver;
75     machine->obj.destructor = raspi2_destructor;
76     qos_init_sdhci_mm(&machine->sdhci, qts, 0x3f300000, &(QSDHCIProperties) {
77         .version = 3,
78         .baseclock = 52,
79         .capab.sdma = false,
80         .capab.reg = 0x052134b4
81     });
82     return &machine->obj;
83 }
84
85 static void raspi2_register_nodes(void)
86 {
87     qos_node_create_machine("arm/raspi2", qos_create_machine_arm_raspi2);
88     qos_node_contains("arm/raspi2", "generic-sdhci", NULL);
89 }
90
91 libqos_init(raspi2_register_nodes);
This page took 0.028708 seconds and 4 git commands to generate.