]> Git Repo - qemu.git/blame - hw/s390x/s390-virtio.c
Merge remote-tracking branch 'kraxel/tags/pull-vga-20170511-1' into staging
[qemu.git] / hw / s390x / s390-virtio.c
CommitLineData
8cb310e1
AG
1/*
2 * QEMU S390 virtio target
3 *
4 * Copyright (c) 2009 Alexander Graf <[email protected]>
904e5fd5 5 * Copyright IBM Corp 2012
8cb310e1
AG
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 *
904e5fd5
VM
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
8cb310e1
AG
21 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 */
23
9615495a 24#include "qemu/osdep.h"
da34e65c 25#include "qapi/error.h"
b73d3531 26#include "hw/hw.h"
cc7a8ea7 27#include "qapi/qmp/qerror.h"
2998ffee 28#include "qemu/error-report.h"
4be74634 29#include "sysemu/block-backend.h"
9c17d615
PB
30#include "sysemu/blockdev.h"
31#include "sysemu/sysemu.h"
1422e32d 32#include "net/net.h"
b73d3531 33#include "hw/boards.h"
b73d3531 34#include "hw/loader.h"
0d09e41a 35#include "hw/virtio/virtio.h"
9c17d615 36#include "sysemu/kvm.h"
022c62cb 37#include "exec/address-spaces.h"
567c88c3 38#include "sysemu/qtest.h"
8cb310e1 39
559a17a1 40#include "hw/s390x/sclp.h"
3a553fc6 41#include "hw/s390x/s390_flic.h"
b73d3531 42#include "hw/s390x/s390-virtio.h"
0f5f6691 43#include "hw/s390x/storage-keys.h"
db3b2566 44#include "hw/s390x/ipl.h"
3f9e59bb 45#include "cpu.h"
8cb310e1 46
8cb310e1
AG
47#define MAX_BLK_DEVS 10
48
3f9e59bb
JH
49#define S390_TOD_CLOCK_VALUE_MISSING 0x00
50#define S390_TOD_CLOCK_VALUE_PRESENT 0x01
51
25637d31 52static S390CPU **cpu_states;
8cb310e1 53
45fa769b 54S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
8cb310e1 55{
25637d31 56 if (cpu_addr >= max_cpus) {
8cb310e1
AG
57 return NULL;
58 }
59
25637d31
MR
60 /* Fast lookup via CPU ID */
61 return cpu_states[cpu_addr];
8cb310e1
AG
62}
63
fad37673
CH
64void s390_init_ipl_dev(const char *kernel_filename,
65 const char *kernel_cmdline,
d0249ce5 66 const char *initrd_filename,
f0180f91 67 const char *firmware,
5f31ade0 68 const char *netboot_fw,
f0180f91 69 bool enforce_bios)
fad37673 70{
04fccf10
DH
71 Object *new = object_new(TYPE_S390_IPL);
72 DeviceState *dev = DEVICE(new);
fad37673 73
fad37673
CH
74 if (kernel_filename) {
75 qdev_prop_set_string(dev, "kernel", kernel_filename);
76 }
77 if (initrd_filename) {
78 qdev_prop_set_string(dev, "initrd", initrd_filename);
79 }
80 qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
d0249ce5 81 qdev_prop_set_string(dev, "firmware", firmware);
5f31ade0 82 qdev_prop_set_string(dev, "netboot_fw", netboot_fw);
f0180f91 83 qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
04fccf10
DH
84 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
85 new, NULL);
86 object_unref(new);
fad37673
CH
87 qdev_init_nofail(dev);
88}
89
d2eae207 90void s390_init_cpus(MachineState *machine)
fad37673
CH
91{
92 int i;
502edbf8 93 gchar *name;
fad37673 94
d2eae207 95 if (machine->cpu_model == NULL) {
41868f84
DH
96 if (kvm_enabled()) {
97 machine->cpu_model = "host";
98 } else {
99 machine->cpu_model = "qemu";
100 }
fad37673
CH
101 }
102
75cfb3bb 103 cpu_states = g_new0(S390CPU *, max_cpus);
fad37673 104
502edbf8
MR
105 for (i = 0; i < max_cpus; i++) {
106 name = g_strdup_printf("cpu[%i]", i);
107 object_property_add_link(OBJECT(machine), name, TYPE_S390_CPU,
108 (Object **) &cpu_states[i],
109 object_property_allow_set_link,
110 OBJ_PROP_LINK_UNREF_ON_RELEASE,
111 &error_abort);
112 g_free(name);
113 }
fad37673 114
502edbf8 115 for (i = 0; i < smp_cpus; i++) {
96b1a8bb 116 s390x_new_cpu(machine->cpu_model, i, &error_fatal);
fad37673
CH
117 }
118}
119
120
121void s390_create_virtio_net(BusState *bus, const char *name)
122{
123 int i;
124
125 for (i = 0; i < nb_nics; i++) {
126 NICInfo *nd = &nd_table[i];
127 DeviceState *dev;
128
129 if (!nd->model) {
130 nd->model = g_strdup("virtio");
131 }
132
e11f4632 133 qemu_check_nic_model(nd, "virtio");
fad37673
CH
134
135 dev = qdev_create(bus, name);
136 qdev_set_nic_properties(dev, nd);
137 qdev_init_nofail(dev);
138 }
139}
140
3f9e59bb
JH
141void gtod_save(QEMUFile *f, void *opaque)
142{
143 uint64_t tod_low;
144 uint8_t tod_high;
145 int r;
146
147 r = s390_get_clock(&tod_high, &tod_low);
148 if (r) {
149 fprintf(stderr, "WARNING: Unable to get guest clock for migration. "
150 "Error code %d. Guest clock will not be migrated "
151 "which could cause the guest to hang.\n", r);
152 qemu_put_byte(f, S390_TOD_CLOCK_VALUE_MISSING);
153 return;
154 }
155
156 qemu_put_byte(f, S390_TOD_CLOCK_VALUE_PRESENT);
157 qemu_put_byte(f, tod_high);
158 qemu_put_be64(f, tod_low);
159}
160
161int gtod_load(QEMUFile *f, void *opaque, int version_id)
162{
163 uint64_t tod_low;
164 uint8_t tod_high;
165 int r;
166
167 if (qemu_get_byte(f) == S390_TOD_CLOCK_VALUE_MISSING) {
168 fprintf(stderr, "WARNING: Guest clock was not migrated. This could "
169 "cause the guest to hang.\n");
170 return 0;
171 }
172
173 tod_high = qemu_get_byte(f);
174 tod_low = qemu_get_be64(f);
175
176 r = s390_set_clock(&tod_high, &tod_low);
177 if (r) {
178 fprintf(stderr, "WARNING: Unable to set guest clock value. "
179 "s390_get_clock returned error %d. This could cause "
180 "the guest to hang.\n", r);
181 }
182
183 return 0;
184}
185
3dd7852f
AK
186void s390_nmi(NMIState *n, int cpu_index, Error **errp)
187{
188 CPUState *cs = qemu_get_cpu(cpu_index);
189
190 if (s390_cpu_restart(S390_CPU(cs))) {
c6bd8c70 191 error_setg(errp, QERR_UNSUPPORTED);
3dd7852f
AK
192 }
193}
194
db3b2566
DH
195void s390_machine_reset(void)
196{
197 S390CPU *ipl_cpu = S390_CPU(qemu_get_cpu(0));
198
1cd4e0f6 199 s390_cmma_reset();
1a0e4c8b 200 qemu_devices_reset();
4ab72920 201 s390_crypto_reset();
db3b2566
DH
202
203 /* all cpus are stopped - configure and start the ipl cpu only */
204 s390_ipl_prepare_cpu(ipl_cpu);
205 s390_cpu_set_state(CPU_STATE_OPERATING, ipl_cpu);
206}
This page took 0.655595 seconds and 4 git commands to generate.