11cf4323eSThomas Huth /*
21cf4323eSThomas Huth * libqos driver framework
31cf4323eSThomas Huth *
41cf4323eSThomas Huth * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
51cf4323eSThomas Huth *
61cf4323eSThomas Huth * This library is free software; you can redistribute it and/or
71cf4323eSThomas Huth * modify it under the terms of the GNU Lesser General Public
8dc0ad02dSThomas Huth * License version 2.1 as published by the Free Software Foundation.
91cf4323eSThomas Huth *
101cf4323eSThomas Huth * This library is distributed in the hope that it will be useful,
111cf4323eSThomas Huth * but WITHOUT ANY WARRANTY; without even the implied warranty of
121cf4323eSThomas Huth * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
131cf4323eSThomas Huth * Lesser General Public License for more details.
141cf4323eSThomas Huth *
151cf4323eSThomas Huth * You should have received a copy of the GNU Lesser General Public
161cf4323eSThomas Huth * License along with this library; if not, see <http://www.gnu.org/licenses/>
171cf4323eSThomas Huth */
181cf4323eSThomas Huth
191cf4323eSThomas Huth #include "qemu/osdep.h"
20907b5105SMarc-André Lureau #include "../libqtest.h"
211cf4323eSThomas Huth #include "qemu/module.h"
22*b243c73cSXuzhou Cheng #include "libqos-malloc.h"
23a2ce7dbdSPaolo Bonzini #include "qgraph.h"
241cf4323eSThomas Huth #include "sdhci.h"
251cf4323eSThomas Huth
261cf4323eSThomas Huth #define ARM_PAGE_SIZE 4096
271cf4323eSThomas Huth #define SABRELITE_RAM_START 0x10000000
281cf4323eSThomas Huth #define SABRELITE_RAM_END 0x30000000
291cf4323eSThomas Huth
301cf4323eSThomas Huth typedef struct QSabreliteMachine QSabreliteMachine;
311cf4323eSThomas Huth
321cf4323eSThomas Huth struct QSabreliteMachine {
331cf4323eSThomas Huth QOSGraphObject obj;
341cf4323eSThomas Huth QGuestAllocator alloc;
351cf4323eSThomas Huth QSDHCI_MemoryMapped sdhci;
361cf4323eSThomas Huth };
371cf4323eSThomas Huth
sabrelite_get_driver(void * object,const char * interface)381cf4323eSThomas Huth static void *sabrelite_get_driver(void *object, const char *interface)
391cf4323eSThomas Huth {
401cf4323eSThomas Huth QSabreliteMachine *machine = object;
411cf4323eSThomas Huth if (!g_strcmp0(interface, "memory")) {
421cf4323eSThomas Huth return &machine->alloc;
431cf4323eSThomas Huth }
441cf4323eSThomas Huth
451cf4323eSThomas Huth fprintf(stderr, "%s not present in arm/sabrelite\n", interface);
461cf4323eSThomas Huth g_assert_not_reached();
471cf4323eSThomas Huth }
481cf4323eSThomas Huth
sabrelite_get_device(void * obj,const char * device)491cf4323eSThomas Huth static QOSGraphObject *sabrelite_get_device(void *obj, const char *device)
501cf4323eSThomas Huth {
511cf4323eSThomas Huth QSabreliteMachine *machine = obj;
521cf4323eSThomas Huth if (!g_strcmp0(device, "generic-sdhci")) {
531cf4323eSThomas Huth return &machine->sdhci.obj;
541cf4323eSThomas Huth }
551cf4323eSThomas Huth
561cf4323eSThomas Huth fprintf(stderr, "%s not present in arm/sabrelite\n", device);
571cf4323eSThomas Huth g_assert_not_reached();
581cf4323eSThomas Huth }
591cf4323eSThomas Huth
sabrelite_destructor(QOSGraphObject * obj)601cf4323eSThomas Huth static void sabrelite_destructor(QOSGraphObject *obj)
611cf4323eSThomas Huth {
621cf4323eSThomas Huth QSabreliteMachine *machine = (QSabreliteMachine *) obj;
631cf4323eSThomas Huth alloc_destroy(&machine->alloc);
641cf4323eSThomas Huth }
651cf4323eSThomas Huth
qos_create_machine_arm_sabrelite(QTestState * qts)661cf4323eSThomas Huth static void *qos_create_machine_arm_sabrelite(QTestState *qts)
671cf4323eSThomas Huth {
681cf4323eSThomas Huth QSabreliteMachine *machine = g_new0(QSabreliteMachine, 1);
691cf4323eSThomas Huth
701cf4323eSThomas Huth alloc_init(&machine->alloc, 0,
711cf4323eSThomas Huth SABRELITE_RAM_START,
721cf4323eSThomas Huth SABRELITE_RAM_END,
731cf4323eSThomas Huth ARM_PAGE_SIZE);
741cf4323eSThomas Huth machine->obj.get_device = sabrelite_get_device;
751cf4323eSThomas Huth machine->obj.get_driver = sabrelite_get_driver;
761cf4323eSThomas Huth machine->obj.destructor = sabrelite_destructor;
771cf4323eSThomas Huth qos_init_sdhci_mm(&machine->sdhci, qts, 0x02190000, &(QSDHCIProperties) {
781cf4323eSThomas Huth .version = 3,
791cf4323eSThomas Huth .baseclock = 0,
801cf4323eSThomas Huth .capab.sdma = true,
811cf4323eSThomas Huth .capab.reg = 0x057834b4,
821cf4323eSThomas Huth });
831cf4323eSThomas Huth return &machine->obj;
841cf4323eSThomas Huth }
851cf4323eSThomas Huth
sabrelite_register_nodes(void)861cf4323eSThomas Huth static void sabrelite_register_nodes(void)
871cf4323eSThomas Huth {
881cf4323eSThomas Huth qos_node_create_machine("arm/sabrelite", qos_create_machine_arm_sabrelite);
891cf4323eSThomas Huth qos_node_contains("arm/sabrelite", "generic-sdhci", NULL);
901cf4323eSThomas Huth }
911cf4323eSThomas Huth
921cf4323eSThomas Huth libqos_init(sabrelite_register_nodes);
93