]> Git Repo - qemu.git/blob - hw/s390x/s390-virtio.c
Merge remote-tracking branch 'remotes/stsquad/tags/pull-mttcg-240217-1' 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 "qapi/error.h"
26 #include "hw/hw.h"
27 #include "qapi/qmp/qerror.h"
28 #include "qemu/error-report.h"
29 #include "sysemu/block-backend.h"
30 #include "sysemu/blockdev.h"
31 #include "sysemu/sysemu.h"
32 #include "net/net.h"
33 #include "hw/boards.h"
34 #include "hw/loader.h"
35 #include "hw/virtio/virtio.h"
36 #include "sysemu/kvm.h"
37 #include "exec/address-spaces.h"
38 #include "sysemu/qtest.h"
39
40 #include "hw/s390x/sclp.h"
41 #include "hw/s390x/s390_flic.h"
42 #include "hw/s390x/s390-virtio.h"
43 #include "hw/s390x/storage-keys.h"
44 #include "hw/s390x/ipl.h"
45 #include "cpu.h"
46
47 #define MAX_BLK_DEVS                    10
48
49 #define S390_TOD_CLOCK_VALUE_MISSING    0x00
50 #define S390_TOD_CLOCK_VALUE_PRESENT    0x01
51
52 static S390CPU **cpu_states;
53
54 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
55 {
56     if (cpu_addr >= max_cpus) {
57         return NULL;
58     }
59
60     /* Fast lookup via CPU ID */
61     return cpu_states[cpu_addr];
62 }
63
64 void s390_init_ipl_dev(const char *kernel_filename,
65                        const char *kernel_cmdline,
66                        const char *initrd_filename,
67                        const char *firmware,
68                        bool enforce_bios)
69 {
70     Object *new = object_new(TYPE_S390_IPL);
71     DeviceState *dev = DEVICE(new);
72
73     if (kernel_filename) {
74         qdev_prop_set_string(dev, "kernel", kernel_filename);
75     }
76     if (initrd_filename) {
77         qdev_prop_set_string(dev, "initrd", initrd_filename);
78     }
79     qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
80     qdev_prop_set_string(dev, "firmware", firmware);
81     qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
82     object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
83                               new, NULL);
84     object_unref(new);
85     qdev_init_nofail(dev);
86 }
87
88 void s390_init_cpus(MachineState *machine)
89 {
90     int i;
91     gchar *name;
92
93     if (machine->cpu_model == NULL) {
94         if (kvm_enabled()) {
95             machine->cpu_model = "host";
96         } else {
97             machine->cpu_model = "qemu";
98         }
99     }
100
101     cpu_states = g_new0(S390CPU *, max_cpus);
102
103     for (i = 0; i < max_cpus; i++) {
104         name = g_strdup_printf("cpu[%i]", i);
105         object_property_add_link(OBJECT(machine), name, TYPE_S390_CPU,
106                                  (Object **) &cpu_states[i],
107                                  object_property_allow_set_link,
108                                  OBJ_PROP_LINK_UNREF_ON_RELEASE,
109                                  &error_abort);
110         g_free(name);
111     }
112
113     for (i = 0; i < smp_cpus; i++) {
114         s390x_new_cpu(machine->cpu_model, i, &error_fatal);
115     }
116 }
117
118
119 void s390_create_virtio_net(BusState *bus, const char *name)
120 {
121     int i;
122
123     for (i = 0; i < nb_nics; i++) {
124         NICInfo *nd = &nd_table[i];
125         DeviceState *dev;
126
127         if (!nd->model) {
128             nd->model = g_strdup("virtio");
129         }
130
131         qemu_check_nic_model(nd, "virtio");
132
133         dev = qdev_create(bus, name);
134         qdev_set_nic_properties(dev, nd);
135         qdev_init_nofail(dev);
136     }
137 }
138
139 void gtod_save(QEMUFile *f, void *opaque)
140 {
141     uint64_t tod_low;
142     uint8_t tod_high;
143     int r;
144
145     r = s390_get_clock(&tod_high, &tod_low);
146     if (r) {
147         fprintf(stderr, "WARNING: Unable to get guest clock for migration. "
148                         "Error code %d. Guest clock will not be migrated "
149                         "which could cause the guest to hang.\n", r);
150         qemu_put_byte(f, S390_TOD_CLOCK_VALUE_MISSING);
151         return;
152     }
153
154     qemu_put_byte(f, S390_TOD_CLOCK_VALUE_PRESENT);
155     qemu_put_byte(f, tod_high);
156     qemu_put_be64(f, tod_low);
157 }
158
159 int gtod_load(QEMUFile *f, void *opaque, int version_id)
160 {
161     uint64_t tod_low;
162     uint8_t tod_high;
163     int r;
164
165     if (qemu_get_byte(f) == S390_TOD_CLOCK_VALUE_MISSING) {
166         fprintf(stderr, "WARNING: Guest clock was not migrated. This could "
167                         "cause the guest to hang.\n");
168         return 0;
169     }
170
171     tod_high = qemu_get_byte(f);
172     tod_low = qemu_get_be64(f);
173
174     r = s390_set_clock(&tod_high, &tod_low);
175     if (r) {
176         fprintf(stderr, "WARNING: Unable to set guest clock value. "
177                         "s390_get_clock returned error %d. This could cause "
178                         "the guest to hang.\n", r);
179     }
180
181     return 0;
182 }
183
184 void s390_nmi(NMIState *n, int cpu_index, Error **errp)
185 {
186     CPUState *cs = qemu_get_cpu(cpu_index);
187
188     if (s390_cpu_restart(S390_CPU(cs))) {
189         error_setg(errp, QERR_UNSUPPORTED);
190     }
191 }
192
193 void s390_machine_reset(void)
194 {
195     S390CPU *ipl_cpu = S390_CPU(qemu_get_cpu(0));
196
197     s390_cmma_reset();
198     qemu_devices_reset();
199     s390_crypto_reset();
200
201     /* all cpus are stopped - configure and start the ipl cpu only */
202     s390_ipl_prepare_cpu(ipl_cpu);
203     s390_cpu_set_state(CPU_STATE_OPERATING, ipl_cpu);
204 }
This page took 0.035755 seconds and 4 git commands to generate.