/*
 * S390x machine definitions and functions
 *
 * Copyright IBM Corp. 2014
 *
 * Authors:
 *   Thomas Huth <thuth@linux.vnet.ibm.com>
 *   Christian Borntraeger <borntraeger@de.ibm.com>
 *   Jason J. Herne <jjherne@us.ibm.com>
 *
 * This work is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 */

#include "qemu/osdep.h"
#include "hw/hw.h"
#include "cpu.h"
#include "internal.h"
#include "kvm_s390x.h"
#include "sysemu/kvm.h"

static int cpu_post_load(void *opaque, int version_id)
{
    S390CPU *cpu = opaque;

    /*
     * As the cpu state is pushed to kvm via kvm_set_mp_state rather
     * than via cpu_synchronize_state, we need update kvm here.
     */
    if (kvm_enabled()) {
        kvm_s390_set_cpu_state(cpu, cpu->env.cpu_state);
        return kvm_s390_vcpu_interrupt_post_load(cpu);
    }

    return 0;
}

static int cpu_pre_save(void *opaque)
{
    S390CPU *cpu = opaque;

    if (kvm_enabled()) {
        kvm_s390_vcpu_interrupt_pre_save(cpu);
    }

    return 0;
}

static inline bool fpu_needed(void *opaque)
{
    /* This looks odd, but we might want to NOT transfer fprs in the future */
    return true;
}

static const VMStateDescription vmstate_fpu = {
    .name = "cpu/fpu",
    .version_id = 1,
    .minimum_version_id = 1,
    .needed = fpu_needed,
    .fields = (VMStateField[]) {
        VMSTATE_UINT64(env.vregs[0][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[1][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[2][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[3][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[4][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[5][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[6][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[7][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[8][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[9][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[10][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[11][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[12][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[13][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[14][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[15][0].ll, S390CPU),
        VMSTATE_UINT32(env.fpc, S390CPU),
        VMSTATE_END_OF_LIST()
    }
};

static bool vregs_needed(void *opaque)
{
    return s390_has_feat(S390_FEAT_VECTOR);
}

static const VMStateDescription vmstate_vregs = {
    .name = "cpu/vregs",
    .version_id = 1,
    .minimum_version_id = 1,
    .needed = vregs_needed,
    .fields = (VMStateField[]) {
        /* vregs[0][0] -> vregs[15][0] and fregs are overlays */
        VMSTATE_UINT64(env.vregs[16][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[17][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[18][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[19][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[20][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[21][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[22][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[23][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[24][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[25][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[26][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[27][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[28][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[29][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[30][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[31][0].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[0][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[1][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[2][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[3][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[4][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[5][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[6][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[7][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[8][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[9][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[10][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[11][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[12][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[13][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[14][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[15][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[16][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[17][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[18][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[19][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[20][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[21][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[22][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[23][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[24][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[25][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[26][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[27][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[28][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[29][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[30][1].ll, S390CPU),
        VMSTATE_UINT64(env.vregs[31][1].ll, S390CPU),
        VMSTATE_END_OF_LIST()
    }
};

static bool riccb_needed(void *opaque)
{
    return s390_has_feat(S390_FEAT_RUNTIME_INSTRUMENTATION);
}

const VMStateDescription vmstate_riccb = {
    .name = "cpu/riccb",
    .version_id = 1,
    .minimum_version_id = 1,
    .needed = riccb_needed,
    .fields = (VMStateField[]) {
        VMSTATE_UINT8_ARRAY(env.riccb, S390CPU, 64),
        VMSTATE_END_OF_LIST()
    }
};

static bool exval_needed(void *opaque)
{
    S390CPU *cpu = opaque;
    return cpu->env.ex_value != 0;
}

const VMStateDescription vmstate_exval = {
    .name = "cpu/exval",
    .version_id = 1,
    .minimum_version_id = 1,
    .needed = exval_needed,
    .fields = (VMStateField[]) {
        VMSTATE_UINT64(env.ex_value, S390CPU),
        VMSTATE_END_OF_LIST()
    }
};

static bool gscb_needed(void *opaque)
{
    return kvm_s390_get_gs();
}

const VMStateDescription vmstate_gscb = {
    .name = "cpu/gscb",
    .version_id = 1,
    .minimum_version_id = 1,
    .needed = gscb_needed,
    .fields = (VMStateField[]) {
        VMSTATE_UINT64_ARRAY(env.gscb, S390CPU, 4),
        VMSTATE_END_OF_LIST()
        }
};

const VMStateDescription vmstate_s390_cpu = {
    .name = "cpu",
    .post_load = cpu_post_load,
    .pre_save = cpu_pre_save,
    .version_id = 4,
    .minimum_version_id = 3,
    .fields      = (VMStateField[]) {
        VMSTATE_UINT64_ARRAY(env.regs, S390CPU, 16),
        VMSTATE_UINT64(env.psw.mask, S390CPU),
        VMSTATE_UINT64(env.psw.addr, S390CPU),
        VMSTATE_UINT64(env.psa, S390CPU),
        VMSTATE_UINT32(env.todpr, S390CPU),
        VMSTATE_UINT64(env.pfault_token, S390CPU),
        VMSTATE_UINT64(env.pfault_compare, S390CPU),
        VMSTATE_UINT64(env.pfault_select, S390CPU),
        VMSTATE_UINT64(env.cputm, S390CPU),
        VMSTATE_UINT64(env.ckc, S390CPU),
        VMSTATE_UINT64(env.gbea, S390CPU),
        VMSTATE_UINT64(env.pp, S390CPU),
        VMSTATE_UINT32_ARRAY(env.aregs, S390CPU, 16),
        VMSTATE_UINT64_ARRAY(env.cregs, S390CPU, 16),
        VMSTATE_UINT8(env.cpu_state, S390CPU),
        VMSTATE_UINT8(env.sigp_order, S390CPU),
        VMSTATE_UINT32_V(irqstate_saved_size, S390CPU, 4),
        VMSTATE_VBUFFER_UINT32(irqstate, S390CPU, 4, NULL,
                               irqstate_saved_size),
        VMSTATE_END_OF_LIST()
    },
    .subsections = (const VMStateDescription*[]) {
        &vmstate_fpu,
        &vmstate_vregs,
        &vmstate_riccb,
        &vmstate_exval,
        &vmstate_gscb,
        NULL
    },
};
