target-ppc: Add helpers for updating a CPU's SDR1 and external HPT
[qemu.git] / hw / s390x / s390-virtio.c
blob7c6e281af1be30cd1e6d6eefaceaf3935d43ee4e
1 /*
2 * QEMU S390 virtio target
4 * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
5 * Copyright IBM Corp 2012
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.
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.
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.
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/>.
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"
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"
46 //#define DEBUG_S390
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
56 #define MAX_BLK_DEVS 10
58 #define S390_TOD_CLOCK_VALUE_MISSING 0x00
59 #define S390_TOD_CLOCK_VALUE_PRESENT 0x01
61 static S390CPU **cpu_states;
63 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
65 if (cpu_addr >= max_cpus) {
66 return NULL;
69 /* Fast lookup via CPU ID */
70 return cpu_states[cpu_addr];
73 void s390_init_ipl_dev(const char *kernel_filename,
74 const char *kernel_cmdline,
75 const char *initrd_filename,
76 const char *firmware,
77 bool enforce_bios)
79 Object *new = object_new(TYPE_S390_IPL);
80 DeviceState *dev = DEVICE(new);
82 if (kernel_filename) {
83 qdev_prop_set_string(dev, "kernel", kernel_filename);
85 if (initrd_filename) {
86 qdev_prop_set_string(dev, "initrd", initrd_filename);
88 qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
89 qdev_prop_set_string(dev, "firmware", firmware);
90 qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
91 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
92 new, NULL);
93 object_unref(new);
94 qdev_init_nofail(dev);
97 void s390_init_cpus(MachineState *machine)
99 int i;
100 gchar *name;
102 if (machine->cpu_model == NULL) {
103 machine->cpu_model = "host";
106 cpu_states = g_new0(S390CPU *, max_cpus);
108 for (i = 0; i < max_cpus; i++) {
109 name = g_strdup_printf("cpu[%i]", i);
110 object_property_add_link(OBJECT(machine), name, TYPE_S390_CPU,
111 (Object **) &cpu_states[i],
112 object_property_allow_set_link,
113 OBJ_PROP_LINK_UNREF_ON_RELEASE,
114 &error_abort);
115 g_free(name);
118 for (i = 0; i < smp_cpus; i++) {
119 s390x_new_cpu(machine->cpu_model, i, &error_fatal);
124 void s390_create_virtio_net(BusState *bus, const char *name)
126 int i;
128 for (i = 0; i < nb_nics; i++) {
129 NICInfo *nd = &nd_table[i];
130 DeviceState *dev;
132 if (!nd->model) {
133 nd->model = g_strdup("virtio");
136 qemu_check_nic_model(nd, "virtio");
138 dev = qdev_create(bus, name);
139 qdev_set_nic_properties(dev, nd);
140 qdev_init_nofail(dev);
144 void gtod_save(QEMUFile *f, void *opaque)
146 uint64_t tod_low;
147 uint8_t tod_high;
148 int r;
150 r = s390_get_clock(&tod_high, &tod_low);
151 if (r) {
152 fprintf(stderr, "WARNING: Unable to get guest clock for migration. "
153 "Error code %d. Guest clock will not be migrated "
154 "which could cause the guest to hang.\n", r);
155 qemu_put_byte(f, S390_TOD_CLOCK_VALUE_MISSING);
156 return;
159 qemu_put_byte(f, S390_TOD_CLOCK_VALUE_PRESENT);
160 qemu_put_byte(f, tod_high);
161 qemu_put_be64(f, tod_low);
164 int gtod_load(QEMUFile *f, void *opaque, int version_id)
166 uint64_t tod_low;
167 uint8_t tod_high;
168 int r;
170 if (qemu_get_byte(f) == S390_TOD_CLOCK_VALUE_MISSING) {
171 fprintf(stderr, "WARNING: Guest clock was not migrated. This could "
172 "cause the guest to hang.\n");
173 return 0;
176 tod_high = qemu_get_byte(f);
177 tod_low = qemu_get_be64(f);
179 r = s390_set_clock(&tod_high, &tod_low);
180 if (r) {
181 fprintf(stderr, "WARNING: Unable to set guest clock value. "
182 "s390_get_clock returned error %d. This could cause "
183 "the guest to hang.\n", r);
186 return 0;
189 void s390_nmi(NMIState *n, int cpu_index, Error **errp)
191 CPUState *cs = qemu_get_cpu(cpu_index);
193 if (s390_cpu_restart(S390_CPU(cs))) {
194 error_setg(errp, QERR_UNSUPPORTED);
198 void s390_machine_reset(void)
200 S390CPU *ipl_cpu = S390_CPU(qemu_get_cpu(0));
202 qemu_devices_reset();
203 s390_cmma_reset();
204 s390_crypto_reset();
206 /* all cpus are stopped - configure and start the ipl cpu only */
207 s390_ipl_prepare_cpu(ipl_cpu);
208 s390_cpu_set_state(CPU_STATE_OPERATING, ipl_cpu);