]> Git Repo - qemu.git/blob - hw/s390x/s390-virtio.c
Merge remote-tracking branch 'remotes/stefanha/tags/tracing-pull-request' into staging
[qemu.git] / hw / s390x / s390-virtio.c
1 /*
2  * QEMU S390 virtio target
3  *
4  * Copyright (c) 2009 Alexander Graf <[email protected]>
5  * Copyright IBM Corp 2012
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * Contributions after 2012-10-29 are licensed under the terms of the
18  * GNU GPL, version 2 or (at your option) any later version.
19  *
20  * You should have received a copy of the GNU (Lesser) General Public
21  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22  */
23
24 #include "qemu/osdep.h"
25 #include "hw/hw.h"
26 #include "qapi/qmp/qerror.h"
27 #include "qemu/error-report.h"
28 #include "sysemu/block-backend.h"
29 #include "sysemu/blockdev.h"
30 #include "sysemu/sysemu.h"
31 #include "net/net.h"
32 #include "hw/boards.h"
33 #include "hw/loader.h"
34 #include "hw/virtio/virtio.h"
35 #include "sysemu/kvm.h"
36 #include "exec/address-spaces.h"
37 #include "sysemu/qtest.h"
38
39 #include "hw/s390x/sclp.h"
40 #include "hw/s390x/s390_flic.h"
41 #include "hw/s390x/s390-virtio.h"
42 #include "hw/s390x/storage-keys.h"
43 #include "hw/s390x/ipl.h"
44 #include "cpu.h"
45
46 //#define DEBUG_S390
47
48 #ifdef DEBUG_S390
49 #define DPRINTF(fmt, ...) \
50     do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
51 #else
52 #define DPRINTF(fmt, ...) \
53     do { } while (0)
54 #endif
55
56 #define MAX_BLK_DEVS                    10
57
58 #define S390_TOD_CLOCK_VALUE_MISSING    0x00
59 #define S390_TOD_CLOCK_VALUE_PRESENT    0x01
60
61 static S390CPU **ipi_states;
62
63 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
64 {
65     if (cpu_addr >= smp_cpus) {
66         return NULL;
67     }
68
69     return ipi_states[cpu_addr];
70 }
71
72 void s390_init_ipl_dev(const char *kernel_filename,
73                        const char *kernel_cmdline,
74                        const char *initrd_filename,
75                        const char *firmware,
76                        bool enforce_bios)
77 {
78     Object *new = object_new(TYPE_S390_IPL);
79     DeviceState *dev = DEVICE(new);
80
81     if (kernel_filename) {
82         qdev_prop_set_string(dev, "kernel", kernel_filename);
83     }
84     if (initrd_filename) {
85         qdev_prop_set_string(dev, "initrd", initrd_filename);
86     }
87     qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
88     qdev_prop_set_string(dev, "firmware", firmware);
89     qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
90     object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
91                               new, NULL);
92     object_unref(new);
93     qdev_init_nofail(dev);
94 }
95
96 void s390_init_cpus(const char *cpu_model)
97 {
98     int i;
99
100     if (cpu_model == NULL) {
101         cpu_model = "host";
102     }
103
104     ipi_states = g_malloc(sizeof(S390CPU *) * smp_cpus);
105
106     for (i = 0; i < smp_cpus; i++) {
107         S390CPU *cpu;
108         CPUState *cs;
109
110         cpu = cpu_s390x_init(cpu_model);
111         cs = CPU(cpu);
112
113         ipi_states[i] = cpu;
114         cs->halted = 1;
115         cs->exception_index = EXCP_HLT;
116     }
117 }
118
119
120 void s390_create_virtio_net(BusState *bus, const char *name)
121 {
122     int i;
123
124     for (i = 0; i < nb_nics; i++) {
125         NICInfo *nd = &nd_table[i];
126         DeviceState *dev;
127
128         if (!nd->model) {
129             nd->model = g_strdup("virtio");
130         }
131
132         qemu_check_nic_model(nd, "virtio");
133
134         dev = qdev_create(bus, name);
135         qdev_set_nic_properties(dev, nd);
136         qdev_init_nofail(dev);
137     }
138 }
139
140 void gtod_save(QEMUFile *f, void *opaque)
141 {
142     uint64_t tod_low;
143     uint8_t tod_high;
144     int r;
145
146     r = s390_get_clock(&tod_high, &tod_low);
147     if (r) {
148         fprintf(stderr, "WARNING: Unable to get guest clock for migration. "
149                         "Error code %d. Guest clock will not be migrated "
150                         "which could cause the guest to hang.\n", r);
151         qemu_put_byte(f, S390_TOD_CLOCK_VALUE_MISSING);
152         return;
153     }
154
155     qemu_put_byte(f, S390_TOD_CLOCK_VALUE_PRESENT);
156     qemu_put_byte(f, tod_high);
157     qemu_put_be64(f, tod_low);
158 }
159
160 int gtod_load(QEMUFile *f, void *opaque, int version_id)
161 {
162     uint64_t tod_low;
163     uint8_t tod_high;
164     int r;
165
166     if (qemu_get_byte(f) == S390_TOD_CLOCK_VALUE_MISSING) {
167         fprintf(stderr, "WARNING: Guest clock was not migrated. This could "
168                         "cause the guest to hang.\n");
169         return 0;
170     }
171
172     tod_high = qemu_get_byte(f);
173     tod_low = qemu_get_be64(f);
174
175     r = s390_set_clock(&tod_high, &tod_low);
176     if (r) {
177         fprintf(stderr, "WARNING: Unable to set guest clock value. "
178                         "s390_get_clock returned error %d. This could cause "
179                         "the guest to hang.\n", r);
180     }
181
182     return 0;
183 }
184
185 void s390_nmi(NMIState *n, int cpu_index, Error **errp)
186 {
187     CPUState *cs = qemu_get_cpu(cpu_index);
188
189     if (s390_cpu_restart(S390_CPU(cs))) {
190         error_setg(errp, QERR_UNSUPPORTED);
191     }
192 }
193
194 void s390_machine_reset(void)
195 {
196     S390CPU *ipl_cpu = S390_CPU(qemu_get_cpu(0));
197
198     qemu_devices_reset();
199     s390_cmma_reset();
200     s390_crypto_reset();
201
202     /* all cpus are stopped - configure and start the ipl cpu only */
203     s390_ipl_prepare_cpu(ipl_cpu);
204     s390_cpu_set_state(CPU_STATE_OPERATING, ipl_cpu);
205 }
This page took 0.034441 seconds and 4 git commands to generate.