tests/libqos: arm/sabrelite machine node
[qemu/ar7.git] / tests / libqos / arm-sabrelite-machine.c
blobc4128d8686aec003094fa728c3db7d9c186eff0b
1 /*
2 * libqos driver framework
4 * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
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.
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.
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/>
19 #include "qemu/osdep.h"
20 #include "libqtest.h"
21 #include "libqos/malloc.h"
22 #include "libqos/qgraph.h"
23 #include "sdhci.h"
25 #define ARM_PAGE_SIZE 4096
26 #define SABRELITE_RAM_START 0x10000000
27 #define SABRELITE_RAM_END 0x30000000
29 typedef struct QSabreliteMachine QSabreliteMachine;
31 struct QSabreliteMachine {
32 QOSGraphObject obj;
33 QGuestAllocator alloc;
34 QSDHCI_MemoryMapped sdhci;
37 static void *sabrelite_get_driver(void *object, const char *interface)
39 QSabreliteMachine *machine = object;
40 if (!g_strcmp0(interface, "memory")) {
41 return &machine->alloc;
44 fprintf(stderr, "%s not present in arm/sabrelite\n", interface);
45 g_assert_not_reached();
48 static QOSGraphObject *sabrelite_get_device(void *obj, const char *device)
50 QSabreliteMachine *machine = obj;
51 if (!g_strcmp0(device, "generic-sdhci")) {
52 return &machine->sdhci.obj;
55 fprintf(stderr, "%s not present in arm/sabrelite\n", device);
56 g_assert_not_reached();
59 static void sabrelite_destructor(QOSGraphObject *obj)
61 QSabreliteMachine *machine = (QSabreliteMachine *) obj;
62 alloc_destroy(&machine->alloc);
65 static void *qos_create_machine_arm_sabrelite(QTestState *qts)
67 QSabreliteMachine *machine = g_new0(QSabreliteMachine, 1);
69 alloc_init(&machine->alloc, 0,
70 SABRELITE_RAM_START,
71 SABRELITE_RAM_END,
72 ARM_PAGE_SIZE);
73 machine->obj.get_device = sabrelite_get_device;
74 machine->obj.get_driver = sabrelite_get_driver;
75 machine->obj.destructor = sabrelite_destructor;
76 qos_init_sdhci_mm(&machine->sdhci, qts, 0x02190000, &(QSDHCIProperties) {
77 .version = 3,
78 .baseclock = 0,
79 .capab.sdma = true,
80 .capab.reg = 0x057834b4,
81 });
82 return &machine->obj;
85 static void sabrelite_register_nodes(void)
87 qos_node_create_machine("arm/sabrelite", qos_create_machine_arm_sabrelite);
88 qos_node_contains("arm/sabrelite", "generic-sdhci", NULL);
91 libqos_init(sabrelite_register_nodes);