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

tpm_tis_isa.c (4896B)


      1/*
      2 * tpm_tis_isa.c - QEMU's TPM TIS ISA Device
      3 *
      4 * Copyright (C) 2006,2010-2013 IBM Corporation
      5 *
      6 * Authors:
      7 *  Stefan Berger <stefanb@us.ibm.com>
      8 *  David Safford <safford@us.ibm.com>
      9 *
     10 * Xen 4 support: Andrease Niederl <andreas.niederl@iaik.tugraz.at>
     11 *
     12 * This work is licensed under the terms of the GNU GPL, version 2 or later.
     13 * See the COPYING file in the top-level directory.
     14 *
     15 * Implementation of the TIS interface according to specs found at
     16 * http://www.trustedcomputinggroup.org. This implementation currently
     17 * supports version 1.3, 21 March 2013
     18 * In the developers menu choose the PC Client section then find the TIS
     19 * specification.
     20 *
     21 * TPM TIS for TPM 2 implementation following TCG PC Client Platform
     22 * TPM Profile (PTP) Specification, Familiy 2.0, Revision 00.43
     23 */
     24
     25#include "qemu/osdep.h"
     26#include "hw/isa/isa.h"
     27#include "hw/qdev-properties.h"
     28#include "migration/vmstate.h"
     29#include "hw/acpi/tpm.h"
     30#include "tpm_prop.h"
     31#include "tpm_tis.h"
     32#include "qom/object.h"
     33
     34struct TPMStateISA {
     35    /*< private >*/
     36    ISADevice parent_obj;
     37
     38    /*< public >*/
     39    TPMState state; /* not a QOM object */
     40};
     41
     42OBJECT_DECLARE_SIMPLE_TYPE(TPMStateISA, TPM_TIS_ISA)
     43
     44static int tpm_tis_pre_save_isa(void *opaque)
     45{
     46    TPMStateISA *isadev = opaque;
     47
     48    return tpm_tis_pre_save(&isadev->state);
     49}
     50
     51static const VMStateDescription vmstate_tpm_tis_isa = {
     52    .name = "tpm-tis",
     53    .version_id = 0,
     54    .pre_save  = tpm_tis_pre_save_isa,
     55    .fields = (VMStateField[]) {
     56        VMSTATE_BUFFER(state.buffer, TPMStateISA),
     57        VMSTATE_UINT16(state.rw_offset, TPMStateISA),
     58        VMSTATE_UINT8(state.active_locty, TPMStateISA),
     59        VMSTATE_UINT8(state.aborting_locty, TPMStateISA),
     60        VMSTATE_UINT8(state.next_locty, TPMStateISA),
     61
     62        VMSTATE_STRUCT_ARRAY(state.loc, TPMStateISA, TPM_TIS_NUM_LOCALITIES, 0,
     63                             vmstate_locty, TPMLocality),
     64
     65        VMSTATE_END_OF_LIST()
     66    }
     67};
     68
     69static void tpm_tis_isa_request_completed(TPMIf *ti, int ret)
     70{
     71    TPMStateISA *isadev = TPM_TIS_ISA(ti);
     72    TPMState *s = &isadev->state;
     73
     74    tpm_tis_request_completed(s, ret);
     75}
     76
     77static enum TPMVersion tpm_tis_isa_get_tpm_version(TPMIf *ti)
     78{
     79    TPMStateISA *isadev = TPM_TIS_ISA(ti);
     80    TPMState *s = &isadev->state;
     81
     82    return tpm_tis_get_tpm_version(s);
     83}
     84
     85static void tpm_tis_isa_reset(DeviceState *dev)
     86{
     87    TPMStateISA *isadev = TPM_TIS_ISA(dev);
     88    TPMState *s = &isadev->state;
     89
     90    return tpm_tis_reset(s);
     91}
     92
     93static Property tpm_tis_isa_properties[] = {
     94    DEFINE_PROP_UINT32("irq", TPMStateISA, state.irq_num, TPM_TIS_IRQ),
     95    DEFINE_PROP_TPMBE("tpmdev", TPMStateISA, state.be_driver),
     96    DEFINE_PROP_BOOL("ppi", TPMStateISA, state.ppi_enabled, true),
     97    DEFINE_PROP_END_OF_LIST(),
     98};
     99
    100static void tpm_tis_isa_initfn(Object *obj)
    101{
    102    TPMStateISA *isadev = TPM_TIS_ISA(obj);
    103    TPMState *s = &isadev->state;
    104
    105    memory_region_init_io(&s->mmio, obj, &tpm_tis_memory_ops,
    106                          s, "tpm-tis-mmio",
    107                          TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT);
    108}
    109
    110static void tpm_tis_isa_realizefn(DeviceState *dev, Error **errp)
    111{
    112    TPMStateISA *isadev = TPM_TIS_ISA(dev);
    113    TPMState *s = &isadev->state;
    114
    115    if (!tpm_find()) {
    116        error_setg(errp, "at most one TPM device is permitted");
    117        return;
    118    }
    119
    120    if (!s->be_driver) {
    121        error_setg(errp, "'tpmdev' property is required");
    122        return;
    123    }
    124    if (s->irq_num > 15) {
    125        error_setg(errp, "IRQ %d is outside valid range of 0 to 15",
    126                   s->irq_num);
    127        return;
    128    }
    129
    130    isa_init_irq(ISA_DEVICE(dev), &s->irq, s->irq_num);
    131
    132    memory_region_add_subregion(isa_address_space(ISA_DEVICE(dev)),
    133                                TPM_TIS_ADDR_BASE, &s->mmio);
    134
    135    if (s->ppi_enabled) {
    136        tpm_ppi_init(&s->ppi, isa_address_space(ISA_DEVICE(dev)),
    137                     TPM_PPI_ADDR_BASE, OBJECT(dev));
    138    }
    139}
    140
    141static void tpm_tis_isa_class_init(ObjectClass *klass, void *data)
    142{
    143    DeviceClass *dc = DEVICE_CLASS(klass);
    144    TPMIfClass *tc = TPM_IF_CLASS(klass);
    145
    146    device_class_set_props(dc, tpm_tis_isa_properties);
    147    dc->vmsd  = &vmstate_tpm_tis_isa;
    148    tc->model = TPM_MODEL_TPM_TIS;
    149    dc->realize = tpm_tis_isa_realizefn;
    150    dc->reset = tpm_tis_isa_reset;
    151    tc->request_completed = tpm_tis_isa_request_completed;
    152    tc->get_version = tpm_tis_isa_get_tpm_version;
    153    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
    154}
    155
    156static const TypeInfo tpm_tis_isa_info = {
    157    .name = TYPE_TPM_TIS_ISA,
    158    .parent = TYPE_ISA_DEVICE,
    159    .instance_size = sizeof(TPMStateISA),
    160    .instance_init = tpm_tis_isa_initfn,
    161    .class_init  = tpm_tis_isa_class_init,
    162    .interfaces = (InterfaceInfo[]) {
    163        { TYPE_TPM_IF },
    164        { }
    165    }
    166};
    167
    168static void tpm_tis_isa_register(void)
    169{
    170    type_register_static(&tpm_tis_isa_info);
    171}
    172
    173type_init(tpm_tis_isa_register)