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