/src/qemu/tests/qtest/libqos/arm-smdkc210-machine.c
Line | Count | Source |
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 | | |
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 | 0 | #define ARM_PAGE_SIZE 4096 |
27 | 0 | #define SMDKC210_RAM_ADDR 0x40000000ull |
28 | 0 | #define SMDKC210_RAM_SIZE 0x40000000ull |
29 | | |
30 | | typedef struct QSmdkc210Machine QSmdkc210Machine; |
31 | | |
32 | | struct QSmdkc210Machine { |
33 | | QOSGraphObject obj; |
34 | | QGuestAllocator alloc; |
35 | | QSDHCI_MemoryMapped sdhci; |
36 | | }; |
37 | | |
38 | | static void *smdkc210_get_driver(void *object, const char *interface) |
39 | 0 | { |
40 | 0 | QSmdkc210Machine *machine = object; |
41 | 0 | if (!g_strcmp0(interface, "memory")) { |
42 | 0 | return &machine->alloc; |
43 | 0 | } |
44 | | |
45 | 0 | fprintf(stderr, "%s not present in arm/smdkc210\n", interface); |
46 | 0 | g_assert_not_reached(); |
47 | 0 | } |
48 | | |
49 | | static QOSGraphObject *smdkc210_get_device(void *obj, const char *device) |
50 | 0 | { |
51 | 0 | QSmdkc210Machine *machine = obj; |
52 | 0 | if (!g_strcmp0(device, "generic-sdhci")) { |
53 | 0 | return &machine->sdhci.obj; |
54 | 0 | } |
55 | | |
56 | 0 | fprintf(stderr, "%s not present in arm/smdkc210\n", device); |
57 | 0 | g_assert_not_reached(); |
58 | 0 | } |
59 | | |
60 | | static void smdkc210_destructor(QOSGraphObject *obj) |
61 | 0 | { |
62 | 0 | QSmdkc210Machine *machine = (QSmdkc210Machine *) obj; |
63 | 0 | alloc_destroy(&machine->alloc); |
64 | 0 | } |
65 | | |
66 | | static void *qos_create_machine_arm_smdkc210(QTestState *qts) |
67 | 0 | { |
68 | 0 | QSmdkc210Machine *machine = g_new0(QSmdkc210Machine, 1); |
69 | |
|
70 | 0 | alloc_init(&machine->alloc, 0, |
71 | 0 | SMDKC210_RAM_ADDR, |
72 | 0 | SMDKC210_RAM_ADDR + SMDKC210_RAM_SIZE, |
73 | 0 | ARM_PAGE_SIZE); |
74 | 0 | machine->obj.get_device = smdkc210_get_device; |
75 | 0 | machine->obj.get_driver = smdkc210_get_driver; |
76 | 0 | machine->obj.destructor = smdkc210_destructor; |
77 | 0 | qos_init_sdhci_mm(&machine->sdhci, qts, 0x12510000, &(QSDHCIProperties) { |
78 | 0 | .version = 2, |
79 | 0 | .baseclock = 0, |
80 | 0 | .capab.sdma = true, |
81 | 0 | .capab.reg = 0x5e80080, |
82 | 0 | }); |
83 | 0 | return &machine->obj; |
84 | 0 | } |
85 | | |
86 | | static void smdkc210_register_nodes(void) |
87 | 61 | { |
88 | 61 | qos_node_create_machine("arm/smdkc210", qos_create_machine_arm_smdkc210); |
89 | | qos_node_contains("arm/smdkc210", "generic-sdhci", NULL); |
90 | 61 | } |
91 | | |
92 | | libqos_init(smdkc210_register_nodes); |