1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include "qemu/osdep.h"
20#include "../libqtest.h"
21#include "qemu/module.h"
22#include "libqos-malloc.h"
23#include "qgraph.h"
24#include "sdhci.h"
25
26#define ARM_PAGE_SIZE 4096
27#define RASPI2_RAM_ADDR 0
28#define RASPI2_RAM_SIZE 0x20000000
29
30typedef struct QRaspi2Machine QRaspi2Machine;
31
32struct QRaspi2Machine {
33 QOSGraphObject obj;
34 QGuestAllocator alloc;
35 QSDHCI_MemoryMapped sdhci;
36};
37
38static void *raspi2_get_driver(void *object, const char *interface)
39{
40 QRaspi2Machine *machine = object;
41 if (!g_strcmp0(interface, "memory")) {
42 return &machine->alloc;
43 }
44
45 fprintf(stderr, "%s not present in arm/raspi2b\n", interface);
46 g_assert_not_reached();
47}
48
49static QOSGraphObject *raspi2_get_device(void *obj, const char *device)
50{
51 QRaspi2Machine *machine = obj;
52 if (!g_strcmp0(device, "generic-sdhci")) {
53 return &machine->sdhci.obj;
54 }
55
56 fprintf(stderr, "%s not present in arm/raspi2b\n", device);
57 g_assert_not_reached();
58}
59
60static void raspi2_destructor(QOSGraphObject *obj)
61{
62 QRaspi2Machine *machine = (QRaspi2Machine *) obj;
63 alloc_destroy(&machine->alloc);
64}
65
66static void *qos_create_machine_arm_raspi2(QTestState *qts)
67{
68 QRaspi2Machine *machine = g_new0(QRaspi2Machine, 1);
69
70 alloc_init(&machine->alloc, 0,
71 RASPI2_RAM_ADDR + (1 << 20),
72 RASPI2_RAM_ADDR + RASPI2_RAM_SIZE,
73 ARM_PAGE_SIZE);
74 machine->obj.get_device = raspi2_get_device;
75 machine->obj.get_driver = raspi2_get_driver;
76 machine->obj.destructor = raspi2_destructor;
77 qos_init_sdhci_mm(&machine->sdhci, qts, 0x3f300000, &(QSDHCIProperties) {
78 .version = 3,
79 .baseclock = 52,
80 .capab.sdma = false,
81 .capab.reg = 0x052134b4
82 });
83 return &machine->obj;
84}
85
86static void raspi2_register_nodes(void)
87{
88 qos_node_create_machine("arm/raspi2b", qos_create_machine_arm_raspi2);
89 qos_node_contains("arm/raspi2b", "generic-sdhci", NULL);
90}
91
92libqos_init(raspi2_register_nodes);
93