11cf4323eSThomas Huth /*
21cf4323eSThomas Huth  * libqos driver framework
31cf4323eSThomas Huth  *
41cf4323eSThomas Huth  * Copyright (c) 2019 Red Hat, Inc.
51cf4323eSThomas Huth  *
61cf4323eSThomas Huth  * Author: Paolo Bonzini <pbonzini@redhat.com>
71cf4323eSThomas Huth  *
81cf4323eSThomas Huth  * This library is free software; you can redistribute it and/or
91cf4323eSThomas Huth  * modify it under the terms of the GNU Lesser General Public
10dc0ad02dSThomas Huth  * License version 2.1 as published by the Free Software Foundation.
111cf4323eSThomas Huth  *
121cf4323eSThomas Huth  * This library is distributed in the hope that it will be useful,
131cf4323eSThomas Huth  * but WITHOUT ANY WARRANTY; without even the implied warranty of
141cf4323eSThomas Huth  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
151cf4323eSThomas Huth  * Lesser General Public License for more details.
161cf4323eSThomas Huth  *
171cf4323eSThomas Huth  * You should have received a copy of the GNU Lesser General Public
181cf4323eSThomas Huth  * License along with this library; if not, see <http://www.gnu.org/licenses/>
191cf4323eSThomas Huth  */
201cf4323eSThomas Huth 
211cf4323eSThomas Huth #include "qemu/osdep.h"
22907b5105SMarc-André Lureau #include "../libqtest.h"
23*b243c73cSXuzhou Cheng #include "libqos-malloc.h"
24a2ce7dbdSPaolo Bonzini #include "qgraph.h"
25a2ce7dbdSPaolo Bonzini #include "i2c.h"
261cf4323eSThomas Huth 
271cf4323eSThomas Huth #define ARM_PAGE_SIZE            4096
281cf4323eSThomas Huth #define N800_RAM_START      0x80000000
291cf4323eSThomas Huth #define N800_RAM_END        0x88000000
301cf4323eSThomas Huth 
311cf4323eSThomas Huth typedef struct QN800Machine QN800Machine;
321cf4323eSThomas Huth 
331cf4323eSThomas Huth struct QN800Machine {
341cf4323eSThomas Huth     QOSGraphObject obj;
351cf4323eSThomas Huth     QGuestAllocator alloc;
361cf4323eSThomas Huth     OMAPI2C i2c_1;
371cf4323eSThomas Huth };
381cf4323eSThomas Huth 
n800_get_driver(void * object,const char * interface)391cf4323eSThomas Huth static void *n800_get_driver(void *object, const char *interface)
401cf4323eSThomas Huth {
411cf4323eSThomas Huth     QN800Machine *machine = object;
421cf4323eSThomas Huth     if (!g_strcmp0(interface, "memory")) {
431cf4323eSThomas Huth         return &machine->alloc;
441cf4323eSThomas Huth     }
451cf4323eSThomas Huth 
461cf4323eSThomas Huth     fprintf(stderr, "%s not present in arm/n800\n", interface);
471cf4323eSThomas Huth     g_assert_not_reached();
481cf4323eSThomas Huth }
491cf4323eSThomas Huth 
n800_get_device(void * obj,const char * device)501cf4323eSThomas Huth static QOSGraphObject *n800_get_device(void *obj, const char *device)
511cf4323eSThomas Huth {
521cf4323eSThomas Huth     QN800Machine *machine = obj;
531cf4323eSThomas Huth     if (!g_strcmp0(device, "omap_i2c")) {
541cf4323eSThomas Huth         return &machine->i2c_1.obj;
551cf4323eSThomas Huth     }
561cf4323eSThomas Huth 
571cf4323eSThomas Huth     fprintf(stderr, "%s not present in arm/n800\n", device);
581cf4323eSThomas Huth     g_assert_not_reached();
591cf4323eSThomas Huth }
601cf4323eSThomas Huth 
n800_destructor(QOSGraphObject * obj)611cf4323eSThomas Huth static void n800_destructor(QOSGraphObject *obj)
621cf4323eSThomas Huth {
631cf4323eSThomas Huth     QN800Machine *machine = (QN800Machine *) obj;
641cf4323eSThomas Huth     alloc_destroy(&machine->alloc);
651cf4323eSThomas Huth }
661cf4323eSThomas Huth 
qos_create_machine_arm_n800(QTestState * qts)671cf4323eSThomas Huth static void *qos_create_machine_arm_n800(QTestState *qts)
681cf4323eSThomas Huth {
691cf4323eSThomas Huth     QN800Machine *machine = g_new0(QN800Machine, 1);
701cf4323eSThomas Huth 
711cf4323eSThomas Huth     alloc_init(&machine->alloc, 0,
721cf4323eSThomas Huth                N800_RAM_START,
731cf4323eSThomas Huth                N800_RAM_END,
741cf4323eSThomas Huth                ARM_PAGE_SIZE);
751cf4323eSThomas Huth     machine->obj.get_device = n800_get_device;
761cf4323eSThomas Huth     machine->obj.get_driver = n800_get_driver;
771cf4323eSThomas Huth     machine->obj.destructor = n800_destructor;
781cf4323eSThomas Huth 
791cf4323eSThomas Huth     omap_i2c_init(&machine->i2c_1, qts, 0x48070000);
801cf4323eSThomas Huth     return &machine->obj;
811cf4323eSThomas Huth }
821cf4323eSThomas Huth 
n800_register_nodes(void)831cf4323eSThomas Huth static void n800_register_nodes(void)
841cf4323eSThomas Huth {
851cf4323eSThomas Huth     QOSGraphEdgeOptions edge = {
861cf4323eSThomas Huth         .extra_device_opts = "bus=i2c-bus.0"
871cf4323eSThomas Huth     };
881cf4323eSThomas Huth     qos_node_create_machine("arm/n800", qos_create_machine_arm_n800);
891cf4323eSThomas Huth     qos_node_contains("arm/n800", "omap_i2c", &edge, NULL);
901cf4323eSThomas Huth }
911cf4323eSThomas Huth 
921cf4323eSThomas Huth libqos_init(n800_register_nodes);
93