xref: /qemu/target/s390x/machine.c (revision fcb79802e07fe06fe24ba97a027d8a1c3a714fa7)
1ef1df130SThomas Huth /*
2ef1df130SThomas Huth  * S390x machine definitions and functions
3ef1df130SThomas Huth  *
4ef1df130SThomas Huth  * Copyright IBM Corp. 2014
5ef1df130SThomas Huth  *
6ef1df130SThomas Huth  * Authors:
7ef1df130SThomas Huth  *   Thomas Huth <thuth@linux.vnet.ibm.com>
8ef1df130SThomas Huth  *   Christian Borntraeger <borntraeger@de.ibm.com>
9ef1df130SThomas Huth  *   Jason J. Herne <jjherne@us.ibm.com>
10ef1df130SThomas Huth  *
11ef1df130SThomas Huth  * This work is free software; you can redistribute it and/or modify
12ef1df130SThomas Huth  * it under the terms of the GNU General Public License as published
13ef1df130SThomas Huth  * by the Free Software Foundation; either version 2 of the License,
14ef1df130SThomas Huth  * or (at your option) any later version.
15ef1df130SThomas Huth  */
16ef1df130SThomas Huth 
17ef1df130SThomas Huth #include "hw/hw.h"
18ef1df130SThomas Huth #include "cpu.h"
19ef1df130SThomas Huth #include "sysemu/kvm.h"
20ef1df130SThomas Huth 
21ef1df130SThomas Huth static int cpu_post_load(void *opaque, int version_id)
22ef1df130SThomas Huth {
23ef1df130SThomas Huth     S390CPU *cpu = opaque;
24ef1df130SThomas Huth 
25ef1df130SThomas Huth     /*
26ef1df130SThomas Huth      * As the cpu state is pushed to kvm via kvm_set_mp_state rather
27ef1df130SThomas Huth      * than via cpu_synchronize_state, we need update kvm here.
28ef1df130SThomas Huth      */
29ef1df130SThomas Huth     if (kvm_enabled()) {
30ef1df130SThomas Huth         kvm_s390_set_cpu_state(cpu, cpu->env.cpu_state);
313cda44f7SJens Freimann         return kvm_s390_vcpu_interrupt_post_load(cpu);
32ef1df130SThomas Huth     }
33ef1df130SThomas Huth 
34ef1df130SThomas Huth     return 0;
35ef1df130SThomas Huth }
363cda44f7SJens Freimann static void cpu_pre_save(void *opaque)
373cda44f7SJens Freimann {
383cda44f7SJens Freimann     S390CPU *cpu = opaque;
393cda44f7SJens Freimann 
403cda44f7SJens Freimann     if (kvm_enabled()) {
413cda44f7SJens Freimann         kvm_s390_vcpu_interrupt_pre_save(cpu);
423cda44f7SJens Freimann     }
433cda44f7SJens Freimann }
44ef1df130SThomas Huth 
4546c804deSDavid Hildenbrand const VMStateDescription vmstate_fpu = {
4646c804deSDavid Hildenbrand     .name = "cpu/fpu",
4746c804deSDavid Hildenbrand     .version_id = 1,
4846c804deSDavid Hildenbrand     .minimum_version_id = 1,
49ef1df130SThomas Huth     .fields = (VMStateField[]) {
50fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[0][0].ll, S390CPU),
51fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[1][0].ll, S390CPU),
52fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[2][0].ll, S390CPU),
53fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[3][0].ll, S390CPU),
54fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[4][0].ll, S390CPU),
55fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[5][0].ll, S390CPU),
56fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[6][0].ll, S390CPU),
57fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[7][0].ll, S390CPU),
58fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[8][0].ll, S390CPU),
59fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[9][0].ll, S390CPU),
60fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[10][0].ll, S390CPU),
61fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[11][0].ll, S390CPU),
62fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[12][0].ll, S390CPU),
63fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[13][0].ll, S390CPU),
64fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[14][0].ll, S390CPU),
65fcb79802SEric Farman         VMSTATE_UINT64(env.vregs[15][0].ll, S390CPU),
6646c804deSDavid Hildenbrand         VMSTATE_UINT32(env.fpc, S390CPU),
6746c804deSDavid Hildenbrand         VMSTATE_END_OF_LIST()
6846c804deSDavid Hildenbrand     }
6946c804deSDavid Hildenbrand };
7046c804deSDavid Hildenbrand 
7146c804deSDavid Hildenbrand static inline bool fpu_needed(void *opaque)
7246c804deSDavid Hildenbrand {
7346c804deSDavid Hildenbrand     return true;
7446c804deSDavid Hildenbrand }
7546c804deSDavid Hildenbrand 
7646c804deSDavid Hildenbrand const VMStateDescription vmstate_s390_cpu = {
7746c804deSDavid Hildenbrand     .name = "cpu",
7846c804deSDavid Hildenbrand     .post_load = cpu_post_load,
793cda44f7SJens Freimann     .pre_save = cpu_pre_save,
803cda44f7SJens Freimann     .version_id = 4,
8146c804deSDavid Hildenbrand     .minimum_version_id = 3,
8246c804deSDavid Hildenbrand     .fields      = (VMStateField[]) {
83ef1df130SThomas Huth         VMSTATE_UINT64_ARRAY(env.regs, S390CPU, 16),
84ef1df130SThomas Huth         VMSTATE_UINT64(env.psw.mask, S390CPU),
85ef1df130SThomas Huth         VMSTATE_UINT64(env.psw.addr, S390CPU),
86ef1df130SThomas Huth         VMSTATE_UINT64(env.psa, S390CPU),
87ef1df130SThomas Huth         VMSTATE_UINT32(env.todpr, S390CPU),
88ef1df130SThomas Huth         VMSTATE_UINT64(env.pfault_token, S390CPU),
89ef1df130SThomas Huth         VMSTATE_UINT64(env.pfault_compare, S390CPU),
90ef1df130SThomas Huth         VMSTATE_UINT64(env.pfault_select, S390CPU),
91ef1df130SThomas Huth         VMSTATE_UINT64(env.cputm, S390CPU),
92ef1df130SThomas Huth         VMSTATE_UINT64(env.ckc, S390CPU),
93ef1df130SThomas Huth         VMSTATE_UINT64(env.gbea, S390CPU),
94ef1df130SThomas Huth         VMSTATE_UINT64(env.pp, S390CPU),
95ef1df130SThomas Huth         VMSTATE_UINT32_ARRAY(env.aregs, S390CPU, 16),
96ef1df130SThomas Huth         VMSTATE_UINT64_ARRAY(env.cregs, S390CPU, 16),
97ef1df130SThomas Huth         VMSTATE_UINT8(env.cpu_state, S390CPU),
9818ff9494SDavid Hildenbrand         VMSTATE_UINT8(env.sigp_order, S390CPU),
993cda44f7SJens Freimann         VMSTATE_UINT32_V(irqstate_saved_size, S390CPU, 4),
1003cda44f7SJens Freimann         VMSTATE_VBUFFER_UINT32(irqstate, S390CPU, 4, NULL, 0,
1013cda44f7SJens Freimann                                irqstate_saved_size),
102ef1df130SThomas Huth         VMSTATE_END_OF_LIST()
103ef1df130SThomas Huth      },
10446c804deSDavid Hildenbrand     .subsections = (VMStateSubsection[]) {
10546c804deSDavid Hildenbrand         {
10646c804deSDavid Hildenbrand             .vmsd = &vmstate_fpu,
10746c804deSDavid Hildenbrand             .needed = fpu_needed,
10846c804deSDavid Hildenbrand         } , {
10946c804deSDavid Hildenbrand             /* empty */
11046c804deSDavid Hildenbrand         }
11146c804deSDavid Hildenbrand     },
112ef1df130SThomas Huth };
113