xref: /qemu/tests/qtest/libqos/arm-imx25-pdk-machine.c (revision bbaf7a0d4c9f653edd085c06bc2a343e356d9b6a)
1 /*
2  * libqos driver framework
3  *
4  * Copyright (c) 2019 Red Hat, Inc.
5  *
6  * Author: Paolo Bonzini <pbonzini@redhat.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, see <http://www.gnu.org/licenses/>
19  */
20 
21 #include "qemu/osdep.h"
22 #include "../libqtest.h"
23 #include "libqos-malloc.h"
24 #include "qgraph.h"
25 #include "i2c.h"
26 #include "hw/i2c/imx_i2c.h"
27 
28 #define ARM_PAGE_SIZE            4096
29 #define IMX25_PDK_RAM_START      0x80000000
30 #define IMX25_PDK_RAM_END        0x88000000
31 
32 typedef struct QIMX25PDKMachine QIMX25PDKMachine;
33 
34 struct QIMX25PDKMachine {
35     QOSGraphObject obj;
36     QGuestAllocator alloc;
37     IMXI2C i2c_1;
38 };
39 
imx25_pdk_get_driver(void * object,const char * interface)40 static void *imx25_pdk_get_driver(void *object, const char *interface)
41 {
42     QIMX25PDKMachine *machine = object;
43     if (!g_strcmp0(interface, "memory")) {
44         return &machine->alloc;
45     }
46 
47     fprintf(stderr, "%s not present in arm/imx25_pdk\n", interface);
48     g_assert_not_reached();
49 }
50 
imx25_pdk_get_device(void * obj,const char * device)51 static QOSGraphObject *imx25_pdk_get_device(void *obj, const char *device)
52 {
53     QIMX25PDKMachine *machine = obj;
54     if (!g_strcmp0(device, TYPE_IMX_I2C)) {
55         return &machine->i2c_1.obj;
56     }
57 
58     fprintf(stderr, "%s not present in arm/imx25_pdk\n", device);
59     g_assert_not_reached();
60 }
61 
imx25_pdk_destructor(QOSGraphObject * obj)62 static void imx25_pdk_destructor(QOSGraphObject *obj)
63 {
64     QIMX25PDKMachine *machine = (QIMX25PDKMachine *) obj;
65     alloc_destroy(&machine->alloc);
66 }
67 
qos_create_machine_arm_imx25_pdk(QTestState * qts)68 static void *qos_create_machine_arm_imx25_pdk(QTestState *qts)
69 {
70     QIMX25PDKMachine *machine = g_new0(QIMX25PDKMachine, 1);
71 
72     alloc_init(&machine->alloc, 0,
73                IMX25_PDK_RAM_START,
74                IMX25_PDK_RAM_END,
75                ARM_PAGE_SIZE);
76     machine->obj.get_device = imx25_pdk_get_device;
77     machine->obj.get_driver = imx25_pdk_get_driver;
78     machine->obj.destructor = imx25_pdk_destructor;
79 
80     imx_i2c_init(&machine->i2c_1, qts, 0x43f80000);
81     return &machine->obj;
82 }
83 
imx25_pdk_register_nodes(void)84 static void imx25_pdk_register_nodes(void)
85 {
86     QOSGraphEdgeOptions edge = {
87         .extra_device_opts = "bus=i2c-bus.0"
88     };
89     qos_node_create_machine("arm/imx25-pdk", qos_create_machine_arm_imx25_pdk);
90     qos_node_contains("arm/imx25-pdk", TYPE_IMX_I2C, &edge, NULL);
91 }
92 
93 libqos_init(imx25_pdk_register_nodes);
94