cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

aarch64-xlnx-zcu102-machine.c (2925B)


      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.1 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 "qemu/module.h"
     22#include "malloc.h"
     23#include "qgraph.h"
     24#include "sdhci.h"
     25
     26typedef struct QXlnxZCU102Machine QXlnxZCU102Machine;
     27
     28struct QXlnxZCU102Machine {
     29    QOSGraphObject obj;
     30    QGuestAllocator alloc;
     31    QSDHCI_MemoryMapped sdhci;
     32};
     33
     34#define ARM_PAGE_SIZE          4096
     35#define XLNX_ZCU102_RAM_ADDR   0
     36#define XLNX_ZCU102_RAM_SIZE   0x20000000
     37
     38static void *xlnx_zcu102_get_driver(void *object, const char *interface)
     39{
     40    QXlnxZCU102Machine *machine = object;
     41    if (!g_strcmp0(interface, "memory")) {
     42        return &machine->alloc;
     43    }
     44
     45    fprintf(stderr, "%s not present in aarch64/xlnx-zcu102\n", interface);
     46    g_assert_not_reached();
     47}
     48
     49static QOSGraphObject *xlnx_zcu102_get_device(void *obj, const char *device)
     50{
     51    QXlnxZCU102Machine *machine = obj;
     52    if (!g_strcmp0(device, "generic-sdhci")) {
     53        return &machine->sdhci.obj;
     54    }
     55
     56    fprintf(stderr, "%s not present in aarch64/xlnx-zcu102\n", device);
     57    g_assert_not_reached();
     58}
     59
     60static void xlnx_zcu102_destructor(QOSGraphObject *obj)
     61{
     62    QXlnxZCU102Machine *machine = (QXlnxZCU102Machine *) obj;
     63    alloc_destroy(&machine->alloc);
     64}
     65
     66static void *qos_create_machine_aarch64_xlnx_zcu102(QTestState *qts)
     67{
     68    QXlnxZCU102Machine *machine = g_new0(QXlnxZCU102Machine, 1);
     69
     70    alloc_init(&machine->alloc, 0,
     71               XLNX_ZCU102_RAM_ADDR + (1 << 20),
     72               XLNX_ZCU102_RAM_ADDR + XLNX_ZCU102_RAM_SIZE,
     73               ARM_PAGE_SIZE);
     74
     75    machine->obj.get_device = xlnx_zcu102_get_device;
     76    machine->obj.get_driver = xlnx_zcu102_get_driver;
     77    machine->obj.destructor = xlnx_zcu102_destructor;
     78    /* Datasheet: UG1085 (v1.7) */
     79    qos_init_sdhci_mm(&machine->sdhci, qts, 0xff160000, &(QSDHCIProperties) {
     80        .version = 3,
     81        .baseclock = 0,
     82        .capab.sdma = true,
     83        .capab.reg = 0x280737ec6481
     84    });
     85    return &machine->obj;
     86}
     87
     88static void xlnx_zcu102_register_nodes(void)
     89{
     90    qos_node_create_machine("aarch64/xlnx-zcu102",
     91                            qos_create_machine_aarch64_xlnx_zcu102);
     92    qos_node_contains("aarch64/xlnx-zcu102", "generic-sdhci", NULL);
     93}
     94
     95libqos_init(xlnx_zcu102_register_nodes);