xref: /openbmc/qemu/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c (revision e93ded1bf6c94ab95015b33e188bc8b0b0c32670)
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 typedef struct QXilinxZynqA9Machine QXilinxZynqA9Machine;
271cf4323eSThomas Huth 
281cf4323eSThomas Huth struct QXilinxZynqA9Machine {
291cf4323eSThomas Huth     QOSGraphObject obj;
301cf4323eSThomas Huth     QGuestAllocator alloc;
311cf4323eSThomas Huth     QSDHCI_MemoryMapped sdhci;
321cf4323eSThomas Huth };
331cf4323eSThomas Huth 
341cf4323eSThomas Huth #define ARM_PAGE_SIZE             4096
351cf4323eSThomas Huth #define XILINX_ZYNQ_A9_RAM_ADDR   0
361cf4323eSThomas Huth #define XILINX_ZYNQ_A9_RAM_SIZE   0x20000000
371cf4323eSThomas Huth 
xilinx_zynq_a9_get_driver(void * object,const char * interface)381cf4323eSThomas Huth static void *xilinx_zynq_a9_get_driver(void *object, const char *interface)
391cf4323eSThomas Huth {
401cf4323eSThomas Huth     QXilinxZynqA9Machine *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/xilinx-zynq-a9\n", interface);
461cf4323eSThomas Huth     g_assert_not_reached();
471cf4323eSThomas Huth }
481cf4323eSThomas Huth 
xilinx_zynq_a9_get_device(void * obj,const char * device)491cf4323eSThomas Huth static QOSGraphObject *xilinx_zynq_a9_get_device(void *obj, const char *device)
501cf4323eSThomas Huth {
511cf4323eSThomas Huth     QXilinxZynqA9Machine *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/xilinx-zynq-a9\n", device);
571cf4323eSThomas Huth     g_assert_not_reached();
581cf4323eSThomas Huth }
591cf4323eSThomas Huth 
xilinx_zynq_a9_destructor(QOSGraphObject * obj)601cf4323eSThomas Huth static void xilinx_zynq_a9_destructor(QOSGraphObject *obj)
611cf4323eSThomas Huth {
621cf4323eSThomas Huth     QXilinxZynqA9Machine *machine = (QXilinxZynqA9Machine *) obj;
631cf4323eSThomas Huth     alloc_destroy(&machine->alloc);
641cf4323eSThomas Huth }
651cf4323eSThomas Huth 
qos_create_machine_arm_xilinx_zynq_a9(QTestState * qts)661cf4323eSThomas Huth static void *qos_create_machine_arm_xilinx_zynq_a9(QTestState *qts)
671cf4323eSThomas Huth {
681cf4323eSThomas Huth     QXilinxZynqA9Machine *machine = g_new0(QXilinxZynqA9Machine, 1);
691cf4323eSThomas Huth 
701cf4323eSThomas Huth     alloc_init(&machine->alloc, 0,
711cf4323eSThomas Huth                XILINX_ZYNQ_A9_RAM_ADDR + (1 << 20),
721cf4323eSThomas Huth                XILINX_ZYNQ_A9_RAM_ADDR + XILINX_ZYNQ_A9_RAM_SIZE,
731cf4323eSThomas Huth                ARM_PAGE_SIZE);
741cf4323eSThomas Huth 
751cf4323eSThomas Huth     machine->obj.get_device = xilinx_zynq_a9_get_device;
761cf4323eSThomas Huth     machine->obj.get_driver = xilinx_zynq_a9_get_driver;
771cf4323eSThomas Huth     machine->obj.destructor = xilinx_zynq_a9_destructor;
781cf4323eSThomas Huth     /* Datasheet: UG585 (v1.12.1) */
791cf4323eSThomas Huth     qos_init_sdhci_mm(&machine->sdhci, qts, 0xe0100000, &(QSDHCIProperties) {
801cf4323eSThomas Huth         .version = 2,
811cf4323eSThomas Huth         .baseclock = 0,
821cf4323eSThomas Huth         .capab.sdma = true,
831cf4323eSThomas Huth         .capab.reg = 0x69ec0080,
841cf4323eSThomas Huth     });
851cf4323eSThomas Huth     return &machine->obj;
861cf4323eSThomas Huth }
871cf4323eSThomas Huth 
xilinx_zynq_a9_register_nodes(void)881cf4323eSThomas Huth static void xilinx_zynq_a9_register_nodes(void)
891cf4323eSThomas Huth {
901cf4323eSThomas Huth     qos_node_create_machine("arm/xilinx-zynq-a9",
911cf4323eSThomas Huth                             qos_create_machine_arm_xilinx_zynq_a9);
921cf4323eSThomas Huth     qos_node_contains("arm/xilinx-zynq-a9", "generic-sdhci", NULL);
931cf4323eSThomas Huth }
941cf4323eSThomas Huth 
951cf4323eSThomas Huth libqos_init(xilinx_zynq_a9_register_nodes);
96