]> Git Repo - qemu.git/blame - hw/s390x/s390-virtio.c
sparc: Clean up includes
[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
b73d3531 24#include "hw/hw.h"
cc7a8ea7 25#include "qapi/qmp/qerror.h"
2998ffee 26#include "qemu/error-report.h"
4be74634 27#include "sysemu/block-backend.h"
9c17d615
PB
28#include "sysemu/blockdev.h"
29#include "sysemu/sysemu.h"
1422e32d 30#include "net/net.h"
b73d3531 31#include "hw/boards.h"
b73d3531 32#include "hw/loader.h"
0d09e41a 33#include "hw/virtio/virtio.h"
9c17d615 34#include "sysemu/kvm.h"
022c62cb 35#include "exec/address-spaces.h"
567c88c3 36#include "sysemu/qtest.h"
8cb310e1 37
559a17a1 38#include "hw/s390x/sclp.h"
3a553fc6 39#include "hw/s390x/s390_flic.h"
b73d3531 40#include "hw/s390x/s390-virtio.h"
0f5f6691 41#include "hw/s390x/storage-keys.h"
db3b2566 42#include "hw/s390x/ipl.h"
3f9e59bb 43#include "cpu.h"
8cb310e1
AG
44
45//#define DEBUG_S390
46
47#ifdef DEBUG_S390
e67137c6 48#define DPRINTF(fmt, ...) \
8cb310e1
AG
49 do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
50#else
e67137c6 51#define DPRINTF(fmt, ...) \
8cb310e1
AG
52 do { } while (0)
53#endif
54
8cb310e1 55#define MAX_BLK_DEVS 10
d0249ce5 56#define ZIPL_FILENAME "s390-zipl.rom"
4c264d4b
EH
57#define S390_MACHINE "s390-virtio"
58#define TYPE_S390_MACHINE MACHINE_TYPE_NAME(S390_MACHINE)
8cb310e1 59
3f9e59bb
JH
60#define S390_TOD_CLOCK_VALUE_MISSING 0x00
61#define S390_TOD_CLOCK_VALUE_PRESENT 0x01
62
45fa769b 63static S390CPU **ipi_states;
8cb310e1 64
45fa769b 65S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
8cb310e1
AG
66{
67 if (cpu_addr >= smp_cpus) {
68 return NULL;
69 }
70
71 return ipi_states[cpu_addr];
72}
73
fad37673
CH
74void s390_init_ipl_dev(const char *kernel_filename,
75 const char *kernel_cmdline,
d0249ce5 76 const char *initrd_filename,
f0180f91
FZ
77 const char *firmware,
78 bool enforce_bios)
fad37673 79{
04fccf10
DH
80 Object *new = object_new(TYPE_S390_IPL);
81 DeviceState *dev = DEVICE(new);
fad37673 82
fad37673
CH
83 if (kernel_filename) {
84 qdev_prop_set_string(dev, "kernel", kernel_filename);
85 }
86 if (initrd_filename) {
87 qdev_prop_set_string(dev, "initrd", initrd_filename);
88 }
89 qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
d0249ce5 90 qdev_prop_set_string(dev, "firmware", firmware);
f0180f91 91 qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
04fccf10
DH
92 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
93 new, NULL);
94 object_unref(new);
fad37673
CH
95 qdev_init_nofail(dev);
96}
97
0f5f6691 98void s390_init_cpus(const char *cpu_model)
fad37673
CH
99{
100 int i;
101
102 if (cpu_model == NULL) {
103 cpu_model = "host";
104 }
105
106 ipi_states = g_malloc(sizeof(S390CPU *) * smp_cpus);
107
108 for (i = 0; i < smp_cpus; i++) {
109 S390CPU *cpu;
259186a7 110 CPUState *cs;
fad37673
CH
111
112 cpu = cpu_s390x_init(cpu_model);
259186a7 113 cs = CPU(cpu);
fad37673
CH
114
115 ipi_states[i] = cpu;
259186a7 116 cs->halted = 1;
27103424 117 cs->exception_index = EXCP_HLT;
fad37673
CH
118 }
119}
120
121
122void s390_create_virtio_net(BusState *bus, const char *name)
123{
124 int i;
125
126 for (i = 0; i < nb_nics; i++) {
127 NICInfo *nd = &nd_table[i];
128 DeviceState *dev;
129
130 if (!nd->model) {
131 nd->model = g_strdup("virtio");
132 }
133
e11f4632 134 qemu_check_nic_model(nd, "virtio");
fad37673
CH
135
136 dev = qdev_create(bus, name);
137 qdev_set_nic_properties(dev, nd);
138 qdev_init_nofail(dev);
139 }
140}
141
3f9e59bb
JH
142void gtod_save(QEMUFile *f, void *opaque)
143{
144 uint64_t tod_low;
145 uint8_t tod_high;
146 int r;
147
148 r = s390_get_clock(&tod_high, &tod_low);
149 if (r) {
150 fprintf(stderr, "WARNING: Unable to get guest clock for migration. "
151 "Error code %d. Guest clock will not be migrated "
152 "which could cause the guest to hang.\n", r);
153 qemu_put_byte(f, S390_TOD_CLOCK_VALUE_MISSING);
154 return;
155 }
156
157 qemu_put_byte(f, S390_TOD_CLOCK_VALUE_PRESENT);
158 qemu_put_byte(f, tod_high);
159 qemu_put_be64(f, tod_low);
160}
161
162int gtod_load(QEMUFile *f, void *opaque, int version_id)
163{
164 uint64_t tod_low;
165 uint8_t tod_high;
166 int r;
167
168 if (qemu_get_byte(f) == S390_TOD_CLOCK_VALUE_MISSING) {
169 fprintf(stderr, "WARNING: Guest clock was not migrated. This could "
170 "cause the guest to hang.\n");
171 return 0;
172 }
173
174 tod_high = qemu_get_byte(f);
175 tod_low = qemu_get_be64(f);
176
177 r = s390_set_clock(&tod_high, &tod_low);
178 if (r) {
179 fprintf(stderr, "WARNING: Unable to set guest clock value. "
180 "s390_get_clock returned error %d. This could cause "
181 "the guest to hang.\n", r);
182 }
183
184 return 0;
185}
186
3dd7852f
AK
187void s390_nmi(NMIState *n, int cpu_index, Error **errp)
188{
189 CPUState *cs = qemu_get_cpu(cpu_index);
190
191 if (s390_cpu_restart(S390_CPU(cs))) {
c6bd8c70 192 error_setg(errp, QERR_UNSUPPORTED);
3dd7852f
AK
193 }
194}
195
db3b2566
DH
196void s390_machine_reset(void)
197{
198 S390CPU *ipl_cpu = S390_CPU(qemu_get_cpu(0));
199
200 qemu_devices_reset();
1cd4e0f6 201 s390_cmma_reset();
4ab72920 202 s390_crypto_reset();
db3b2566
DH
203
204 /* all cpus are stopped - configure and start the ipl cpu only */
205 s390_ipl_prepare_cpu(ipl_cpu);
206 s390_cpu_set_state(CPU_STATE_OPERATING, ipl_cpu);
207}
This page took 0.637764 seconds and 4 git commands to generate.