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