]> Git Repo - qemu.git/blob - hw/s390x/s390-virtio-ccw.c
s390: disallow memory hotplug for the s390-virtio machine
[qemu.git] / hw / s390x / s390-virtio-ccw.c
1 /*
2  * virtio ccw machine
3  *
4  * Copyright 2012 IBM Corp.
5  * Author(s): Cornelia Huck <[email protected]>
6  *
7  * This work is licensed under the terms of the GNU GPL, version 2 or (at
8  * your option) any later version. See the COPYING file in the top-level
9  * directory.
10  */
11
12 #include "hw/boards.h"
13 #include "exec/address-spaces.h"
14 #include "s390-virtio.h"
15 #include "hw/s390x/sclp.h"
16 #include "hw/s390x/s390_flic.h"
17 #include "ioinst.h"
18 #include "css.h"
19 #include "virtio-ccw.h"
20 #include "qemu/config-file.h"
21 #include "s390-pci-bus.h"
22 #include "hw/s390x/storage-keys.h"
23
24 #define TYPE_S390_CCW_MACHINE               "s390-ccw-machine"
25
26 #define S390_CCW_MACHINE(obj) \
27     OBJECT_CHECK(S390CcwMachineState, (obj), TYPE_S390_CCW_MACHINE)
28
29 typedef struct S390CcwMachineState {
30     /*< private >*/
31     MachineState parent_obj;
32
33     /*< public >*/
34     bool aes_key_wrap;
35     bool dea_key_wrap;
36 } S390CcwMachineState;
37
38 void io_subsystem_reset(void)
39 {
40     DeviceState *css, *sclp, *flic, *diag288;
41
42     css = DEVICE(object_resolve_path_type("", "virtual-css-bridge", NULL));
43     if (css) {
44         qdev_reset_all(css);
45     }
46     sclp = DEVICE(object_resolve_path_type("",
47                   "s390-sclp-event-facility", NULL));
48     if (sclp) {
49         qdev_reset_all(sclp);
50     }
51     flic = DEVICE(object_resolve_path_type("", "s390-flic", NULL));
52     if (flic) {
53         qdev_reset_all(flic);
54     }
55     diag288 = DEVICE(object_resolve_path_type("", "diag288", NULL));
56     if (diag288) {
57         qdev_reset_all(diag288);
58     }
59 }
60
61 static int virtio_ccw_hcall_notify(const uint64_t *args)
62 {
63     uint64_t subch_id = args[0];
64     uint64_t queue = args[1];
65     SubchDev *sch;
66     int cssid, ssid, schid, m;
67
68     if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
69         return -EINVAL;
70     }
71     sch = css_find_subch(m, cssid, ssid, schid);
72     if (!sch || !css_subch_visible(sch)) {
73         return -EINVAL;
74     }
75     if (queue >= VIRTIO_CCW_QUEUE_MAX) {
76         return -EINVAL;
77     }
78     virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
79     return 0;
80
81 }
82
83 static int virtio_ccw_hcall_early_printk(const uint64_t *args)
84 {
85     uint64_t mem = args[0];
86
87     if (mem < ram_size) {
88         /* Early printk */
89         return 0;
90     }
91     return -EINVAL;
92 }
93
94 static void virtio_ccw_register_hcalls(void)
95 {
96     s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
97                                    virtio_ccw_hcall_notify);
98     /* Tolerate early printk. */
99     s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
100                                    virtio_ccw_hcall_early_printk);
101 }
102
103 static void ccw_init(MachineState *machine)
104 {
105     ram_addr_t my_ram_size = machine->ram_size;
106     MemoryRegion *sysmem = get_system_memory();
107     MemoryRegion *ram = g_new(MemoryRegion, 1);
108     sclpMemoryHotplugDev *mhd = init_sclp_memory_hotplug_dev();
109     int ret;
110     VirtualCssBus *css_bus;
111     DeviceState *dev;
112     ram_addr_t pad_size = 0;
113     ram_addr_t maxmem = machine->maxram_size;
114     ram_addr_t standby_mem_size = maxmem - my_ram_size;
115     uint64_t kvm_limit;
116
117     /* The storage increment size is a multiple of 1M and is a power of 2.
118      * The number of storage increments must be MAX_STORAGE_INCREMENTS or fewer.
119      * The variable 'mhd->increment_size' is an exponent of 2 that can be
120      * used to calculate the size (in bytes) of an increment. */
121     mhd->increment_size = 20;
122     while ((my_ram_size >> mhd->increment_size) > MAX_STORAGE_INCREMENTS) {
123         mhd->increment_size++;
124     }
125     while ((standby_mem_size >> mhd->increment_size) > MAX_STORAGE_INCREMENTS) {
126         mhd->increment_size++;
127     }
128
129     /* The core and standby memory areas need to be aligned with
130      * the increment size.  In effect, this can cause the
131      * user-specified memory size to be rounded down to align
132      * with the nearest increment boundary. */
133     standby_mem_size = standby_mem_size >> mhd->increment_size
134                                         << mhd->increment_size;
135     my_ram_size = my_ram_size >> mhd->increment_size
136                               << mhd->increment_size;
137
138     /* let's propagate the changed ram size into the global variable. */
139     ram_size = my_ram_size;
140     machine->maxram_size = my_ram_size + standby_mem_size;
141
142     ret = s390_set_memory_limit(machine->maxram_size, &kvm_limit);
143     if (ret == -E2BIG) {
144         hw_error("qemu: host supports a maximum of %" PRIu64 " GB",
145                  kvm_limit >> 30);
146     } else if (ret) {
147         hw_error("qemu: setting the guest size failed");
148     }
149
150     /* get a BUS */
151     css_bus = virtual_css_bus_init();
152     s390_sclp_init();
153     s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
154                       machine->initrd_filename, "s390-ccw.img", true);
155     s390_flic_init();
156
157     dev = qdev_create(NULL, TYPE_S390_PCI_HOST_BRIDGE);
158     object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
159                               OBJECT(dev), NULL);
160     qdev_init_nofail(dev);
161
162     /* register hypercalls */
163     virtio_ccw_register_hcalls();
164
165     /* allocate RAM for core */
166     memory_region_init_ram(ram, NULL, "s390.ram", my_ram_size, &error_abort);
167     vmstate_register_ram_global(ram);
168     memory_region_add_subregion(sysmem, 0, ram);
169
170     /* If the size of ram is not on a MEM_SECTION_SIZE boundary,
171        calculate the pad size necessary to force this boundary. */
172     if (standby_mem_size) {
173         if (my_ram_size % MEM_SECTION_SIZE) {
174             pad_size = MEM_SECTION_SIZE - my_ram_size % MEM_SECTION_SIZE;
175         }
176         my_ram_size += standby_mem_size + pad_size;
177         mhd->pad_size = pad_size;
178         mhd->standby_mem_size = standby_mem_size;
179     }
180
181     /* Initialize storage key device */
182     s390_skeys_init();
183
184     /* init CPUs */
185     s390_init_cpus(machine->cpu_model);
186
187     if (kvm_enabled()) {
188         kvm_s390_enable_css_support(s390_cpu_addr2state(0));
189     }
190     /*
191      * Create virtual css and set it as default so that non mcss-e
192      * enabled guests only see virtio devices.
193      */
194     ret = css_create_css_image(VIRTUAL_CSSID, true);
195     assert(ret == 0);
196
197     /* Create VirtIO network adapters */
198     s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
199
200     /* Register savevm handler for guest TOD clock */
201     register_savevm(NULL, "todclock", 0, 1,
202                     gtod_save, gtod_load, kvm_state);
203 }
204
205 static void ccw_machine_class_init(ObjectClass *oc, void *data)
206 {
207     MachineClass *mc = MACHINE_CLASS(oc);
208     NMIClass *nc = NMI_CLASS(oc);
209
210     mc->init = ccw_init;
211     mc->block_default_type = IF_VIRTIO;
212     mc->no_cdrom = 1;
213     mc->no_floppy = 1;
214     mc->no_serial = 1;
215     mc->no_parallel = 1;
216     mc->no_sdcard = 1;
217     mc->use_sclp = 1;
218     mc->max_cpus = 255;
219     nc->nmi_monitor_handler = s390_nmi;
220 }
221
222 static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
223 {
224     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
225
226     return ms->aes_key_wrap;
227 }
228
229 static inline void machine_set_aes_key_wrap(Object *obj, bool value,
230                                             Error **errp)
231 {
232     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
233
234     ms->aes_key_wrap = value;
235 }
236
237 static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
238 {
239     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
240
241     return ms->dea_key_wrap;
242 }
243
244 static inline void machine_set_dea_key_wrap(Object *obj, bool value,
245                                             Error **errp)
246 {
247     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
248
249     ms->dea_key_wrap = value;
250 }
251
252 static inline void s390_machine_initfn(Object *obj)
253 {
254     object_property_add_bool(obj, "aes-key-wrap",
255                              machine_get_aes_key_wrap,
256                              machine_set_aes_key_wrap, NULL);
257     object_property_set_description(obj, "aes-key-wrap",
258             "enable/disable AES key wrapping using the CPACF wrapping key",
259             NULL);
260     object_property_set_bool(obj, true, "aes-key-wrap", NULL);
261
262     object_property_add_bool(obj, "dea-key-wrap",
263                              machine_get_dea_key_wrap,
264                              machine_set_dea_key_wrap, NULL);
265     object_property_set_description(obj, "dea-key-wrap",
266             "enable/disable DEA key wrapping using the CPACF wrapping key",
267             NULL);
268     object_property_set_bool(obj, true, "dea-key-wrap", NULL);
269 }
270
271 static const TypeInfo ccw_machine_info = {
272     .name          = TYPE_S390_CCW_MACHINE,
273     .parent        = TYPE_MACHINE,
274     .abstract      = true,
275     .instance_size = sizeof(S390CcwMachineState),
276     .instance_init = s390_machine_initfn,
277     .class_init    = ccw_machine_class_init,
278     .interfaces = (InterfaceInfo[]) {
279         { TYPE_NMI },
280         { }
281     },
282 };
283
284 #define CCW_COMPAT_2_4 \
285         {\
286             .driver   = TYPE_S390_SKEYS,\
287             .property = "migration-enabled",\
288             .value    = "off",\
289         },
290
291 static void ccw_machine_2_4_class_init(ObjectClass *oc, void *data)
292 {
293     MachineClass *mc = MACHINE_CLASS(oc);
294     static GlobalProperty compat_props[] = {
295         CCW_COMPAT_2_4
296         { /* end of list */ }
297     };
298
299     mc->name = "s390-ccw-virtio-2.4";
300     mc->desc = "VirtIO-ccw based S390 machine v2.4";
301     mc->compat_props = compat_props;
302 }
303
304 static const TypeInfo ccw_machine_2_4_info = {
305     .name          = TYPE_S390_CCW_MACHINE "2.4",
306     .parent        = TYPE_S390_CCW_MACHINE,
307     .class_init    = ccw_machine_2_4_class_init,
308 };
309
310 static void ccw_machine_2_5_class_init(ObjectClass *oc, void *data)
311 {
312     MachineClass *mc = MACHINE_CLASS(oc);
313
314     mc->name = "s390-ccw-virtio-2.5";
315     mc->alias = "s390-ccw-virtio";
316     mc->desc = "VirtIO-ccw based S390 machine v2.5";
317     mc->is_default = 1;
318 }
319
320 static const TypeInfo ccw_machine_2_5_info = {
321     .name          = TYPE_S390_CCW_MACHINE "2.5",
322     .parent        = TYPE_S390_CCW_MACHINE,
323     .class_init    = ccw_machine_2_5_class_init,
324 };
325
326 static void ccw_machine_register_types(void)
327 {
328     type_register_static(&ccw_machine_info);
329     type_register_static(&ccw_machine_2_4_info);
330     type_register_static(&ccw_machine_2_5_info);
331 }
332
333 type_init(ccw_machine_register_types)
This page took 0.043734 seconds and 4 git commands to generate.