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

iotkit-sysinfo.c (5071B)


      1/*
      2 * ARM IoTKit system information block
      3 *
      4 * Copyright (c) 2018 Linaro Limited
      5 * Written by Peter Maydell
      6 *
      7 *  This program is free software; you can redistribute it and/or modify
      8 *  it under the terms of the GNU General Public License version 2 or
      9 *  (at your option) any later version.
     10 */
     11
     12/*
     13 * This is a model of the "system information block" which is part of the
     14 * Arm IoTKit and documented in
     15 * https://developer.arm.com/documentation/ecm0601256/latest
     16 * It consists of 2 read-only version/config registers, plus the
     17 * usual ID registers.
     18 */
     19
     20#include "qemu/osdep.h"
     21#include "qemu/log.h"
     22#include "qemu/module.h"
     23#include "trace.h"
     24#include "qapi/error.h"
     25#include "hw/sysbus.h"
     26#include "hw/registerfields.h"
     27#include "hw/misc/iotkit-sysinfo.h"
     28#include "hw/qdev-properties.h"
     29#include "hw/arm/armsse-version.h"
     30
     31REG32(SYS_VERSION, 0x0)
     32REG32(SYS_CONFIG, 0x4)
     33REG32(SYS_CONFIG1, 0x8)
     34REG32(IIDR, 0xfc8)
     35REG32(PID4, 0xfd0)
     36REG32(PID5, 0xfd4)
     37REG32(PID6, 0xfd8)
     38REG32(PID7, 0xfdc)
     39REG32(PID0, 0xfe0)
     40REG32(PID1, 0xfe4)
     41REG32(PID2, 0xfe8)
     42REG32(PID3, 0xfec)
     43REG32(CID0, 0xff0)
     44REG32(CID1, 0xff4)
     45REG32(CID2, 0xff8)
     46REG32(CID3, 0xffc)
     47
     48/* PID/CID values */
     49static const int sysinfo_id[] = {
     50    0x04, 0x00, 0x00, 0x00, /* PID4..PID7 */
     51    0x58, 0xb8, 0x0b, 0x00, /* PID0..PID3 */
     52    0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */
     53};
     54
     55static const int sysinfo_sse300_id[] = {
     56    0x04, 0x00, 0x00, 0x00, /* PID4..PID7 */
     57    0x58, 0xb8, 0x1b, 0x00, /* PID0..PID3 */
     58    0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */
     59};
     60
     61static uint64_t iotkit_sysinfo_read(void *opaque, hwaddr offset,
     62                                    unsigned size)
     63{
     64    IoTKitSysInfo *s = IOTKIT_SYSINFO(opaque);
     65    uint64_t r;
     66
     67    switch (offset) {
     68    case A_SYS_VERSION:
     69        r = s->sys_version;
     70        break;
     71
     72    case A_SYS_CONFIG:
     73        r = s->sys_config;
     74        break;
     75    case A_SYS_CONFIG1:
     76        switch (s->sse_version) {
     77        case ARMSSE_SSE300:
     78            return 0;
     79            break;
     80        default:
     81            goto bad_read;
     82        }
     83        break;
     84    case A_IIDR:
     85        switch (s->sse_version) {
     86        case ARMSSE_SSE300:
     87            return s->iidr;
     88            break;
     89        default:
     90            goto bad_read;
     91        }
     92        break;
     93    case A_PID4 ... A_CID3:
     94        switch (s->sse_version) {
     95        case ARMSSE_SSE300:
     96            r = sysinfo_sse300_id[(offset - A_PID4) / 4];
     97            break;
     98        default:
     99            r = sysinfo_id[(offset - A_PID4) / 4];
    100            break;
    101        }
    102        break;
    103    default:
    104    bad_read:
    105        qemu_log_mask(LOG_GUEST_ERROR,
    106                      "IoTKit SysInfo read: bad offset %x\n", (int)offset);
    107        r = 0;
    108        break;
    109    }
    110    trace_iotkit_sysinfo_read(offset, r, size);
    111    return r;
    112}
    113
    114static void iotkit_sysinfo_write(void *opaque, hwaddr offset,
    115                                 uint64_t value, unsigned size)
    116{
    117    trace_iotkit_sysinfo_write(offset, value, size);
    118
    119    qemu_log_mask(LOG_GUEST_ERROR,
    120                  "IoTKit SysInfo: write to RO offset 0x%x\n", (int)offset);
    121}
    122
    123static const MemoryRegionOps iotkit_sysinfo_ops = {
    124    .read = iotkit_sysinfo_read,
    125    .write = iotkit_sysinfo_write,
    126    .endianness = DEVICE_LITTLE_ENDIAN,
    127    /* byte/halfword accesses are just zero-padded on reads and writes */
    128    .impl.min_access_size = 4,
    129    .impl.max_access_size = 4,
    130    .valid.min_access_size = 1,
    131    .valid.max_access_size = 4,
    132};
    133
    134static Property iotkit_sysinfo_props[] = {
    135    DEFINE_PROP_UINT32("SYS_VERSION", IoTKitSysInfo, sys_version, 0),
    136    DEFINE_PROP_UINT32("SYS_CONFIG", IoTKitSysInfo, sys_config, 0),
    137    DEFINE_PROP_UINT32("sse-version", IoTKitSysInfo, sse_version, 0),
    138    DEFINE_PROP_UINT32("IIDR", IoTKitSysInfo, iidr, 0),
    139    DEFINE_PROP_END_OF_LIST()
    140};
    141
    142static void iotkit_sysinfo_init(Object *obj)
    143{
    144    SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
    145    IoTKitSysInfo *s = IOTKIT_SYSINFO(obj);
    146
    147    memory_region_init_io(&s->iomem, obj, &iotkit_sysinfo_ops,
    148                          s, "iotkit-sysinfo", 0x1000);
    149    sysbus_init_mmio(sbd, &s->iomem);
    150}
    151
    152static void iotkit_sysinfo_realize(DeviceState *dev, Error **errp)
    153{
    154    IoTKitSysInfo *s = IOTKIT_SYSINFO(dev);
    155
    156    if (!armsse_version_valid(s->sse_version)) {
    157        error_setg(errp, "invalid sse-version value %d", s->sse_version);
    158        return;
    159    }
    160}
    161
    162static void iotkit_sysinfo_class_init(ObjectClass *klass, void *data)
    163{
    164    DeviceClass *dc = DEVICE_CLASS(klass);
    165
    166    /*
    167     * This device has no guest-modifiable state and so it
    168     * does not need a reset function or VMState.
    169     */
    170    dc->realize = iotkit_sysinfo_realize;
    171    device_class_set_props(dc, iotkit_sysinfo_props);
    172}
    173
    174static const TypeInfo iotkit_sysinfo_info = {
    175    .name = TYPE_IOTKIT_SYSINFO,
    176    .parent = TYPE_SYS_BUS_DEVICE,
    177    .instance_size = sizeof(IoTKitSysInfo),
    178    .instance_init = iotkit_sysinfo_init,
    179    .class_init = iotkit_sysinfo_class_init,
    180};
    181
    182static void iotkit_sysinfo_register_types(void)
    183{
    184    type_register_static(&iotkit_sysinfo_info);
    185}
    186
    187type_init(iotkit_sysinfo_register_types);