qemu/tests/libqos/aarch64-xlnx-zcu102-machine.c
<<
>>
Prefs
   1/*
   2 * libqos driver framework
   3 *
   4 * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
   5 *
   6 * This library is free software; you can redistribute it and/or
   7 * modify it under the terms of the GNU Lesser General Public
   8 * License version 2 as published by the Free Software Foundation.
   9 *
  10 * This library is distributed in the hope that it will be useful,
  11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13 * Lesser General Public License for more details.
  14 *
  15 * You should have received a copy of the GNU Lesser General Public
  16 * License along with this library; if not, see <http://www.gnu.org/licenses/>
  17 */
  18
  19#include "qemu/osdep.h"
  20#include "libqtest.h"
  21#include "libqos/malloc.h"
  22#include "libqos/qgraph.h"
  23#include "sdhci.h"
  24
  25typedef struct QXlnxZCU102Machine QXlnxZCU102Machine;
  26
  27struct QXlnxZCU102Machine {
  28    QOSGraphObject obj;
  29    QGuestAllocator alloc;
  30    QSDHCI_MemoryMapped sdhci;
  31};
  32
  33#define ARM_PAGE_SIZE          4096
  34#define XLNX_ZCU102_RAM_ADDR   0
  35#define XLNX_ZCU102_RAM_SIZE   0x20000000
  36
  37static void *xlnx_zcu102_get_driver(void *object, const char *interface)
  38{
  39    QXlnxZCU102Machine *machine = object;
  40    if (!g_strcmp0(interface, "memory")) {
  41        return &machine->alloc;
  42    }
  43
  44    fprintf(stderr, "%s not present in aarch64/xlnx-zcu102\n", interface);
  45    g_assert_not_reached();
  46}
  47
  48static QOSGraphObject *xlnx_zcu102_get_device(void *obj, const char *device)
  49{
  50    QXlnxZCU102Machine *machine = obj;
  51    if (!g_strcmp0(device, "generic-sdhci")) {
  52        return &machine->sdhci.obj;
  53    }
  54
  55    fprintf(stderr, "%s not present in aarch64/xlnx-zcu102\n", device);
  56    g_assert_not_reached();
  57}
  58
  59static void xlnx_zcu102_destructor(QOSGraphObject *obj)
  60{
  61    QXlnxZCU102Machine *machine = (QXlnxZCU102Machine *) obj;
  62    alloc_destroy(&machine->alloc);
  63}
  64
  65static void *qos_create_machine_aarch64_xlnx_zcu102(QTestState *qts)
  66{
  67    QXlnxZCU102Machine *machine = g_new0(QXlnxZCU102Machine, 1);
  68
  69    alloc_init(&machine->alloc, 0,
  70               XLNX_ZCU102_RAM_ADDR + (1 << 20),
  71               XLNX_ZCU102_RAM_ADDR + XLNX_ZCU102_RAM_SIZE,
  72               ARM_PAGE_SIZE);
  73
  74    machine->obj.get_device = xlnx_zcu102_get_device;
  75    machine->obj.get_driver = xlnx_zcu102_get_driver;
  76    machine->obj.destructor = xlnx_zcu102_destructor;
  77    /* Datasheet: UG1085 (v1.7) */
  78    qos_init_sdhci_mm(&machine->sdhci, qts, 0xff160000, &(QSDHCIProperties) {
  79        .version = 3,
  80        .baseclock = 0,
  81        .capab.sdma = true,
  82        .capab.reg = 0x280737ec6481
  83    });
  84    return &machine->obj;
  85}
  86
  87static void xlnx_zcu102_register_nodes(void)
  88{
  89    qos_node_create_machine("aarch64/xlnx-zcu102",
  90                            qos_create_machine_aarch64_xlnx_zcu102);
  91    qos_node_contains("aarch64/xlnx-zcu102", "generic-sdhci", NULL);
  92}
  93
  94libqos_init(xlnx_zcu102_register_nodes);
  95