]> Git Repo - qemu.git/blame - hw/s390x/sclp.c
s390x/css: update css_adapter_interrupt
[qemu.git] / hw / s390x / sclp.c
CommitLineData
f6c98f92
HG
1/*
2 * SCLP Support
3 *
4 * Copyright IBM, Corp. 2012
5 *
6 * Authors:
7 * Christian Borntraeger <[email protected]>
8 * Heinz Graalfs <[email protected]>
9 *
10 * This work is licensed under the terms of the GNU GPL, version 2 or (at your
11 * option) any later version. See the COPYING file in the top-level directory.
12 *
13 */
14
9615495a 15#include "qemu/osdep.h"
da34e65c 16#include "qapi/error.h"
f6c98f92 17#include "cpu.h"
9c17d615 18#include "sysemu/kvm.h"
022c62cb 19#include "exec/memory.h"
8cc3aecf 20#include "sysemu/sysemu.h"
1def6656 21#include "exec/address-spaces.h"
311467f7 22#include "hw/boards.h"
83c9f4ca 23#include "hw/s390x/sclp.h"
477a72a1 24#include "hw/s390x/event-facility.h"
8cba80c3 25#include "hw/s390x/s390-pci-bus.h"
b038411d 26#include "hw/s390x/ipl.h"
f6c98f92 27
25a3c5af
DH
28static inline SCLPDevice *get_sclp_device(void)
29{
989fd865
CB
30 static SCLPDevice *sclp;
31
32 if (!sclp) {
33 sclp = SCLP(object_resolve_path_type("", TYPE_SCLP, NULL));
34 }
35 return sclp;
25a3c5af
DH
36}
37
026546e6
DH
38static void prepare_cpu_entries(SCLPDevice *sclp, CPUEntry *entry, int count)
39{
4dd4200e 40 uint8_t features[SCCB_CPU_FEATURE_LEN] = { 0 };
026546e6
DH
41 int i;
42
4dd4200e 43 s390_get_feat_block(S390_FEAT_TYPE_SCLP_CPU, features);
026546e6
DH
44 for (i = 0; i < count; i++) {
45 entry[i].address = i;
46 entry[i].type = 0;
4dd4200e 47 memcpy(entry[i].features, features, sizeof(entry[i].features));
026546e6
DH
48 }
49}
50
f6c98f92 51/* Provide information about the configuration, CPUs and storage */
25a3c5af 52static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
f6c98f92
HG
53{
54 ReadInfo *read_info = (ReadInfo *) sccb;
311467f7 55 MachineState *machine = MACHINE(qdev_get_machine());
1def6656 56 sclpMemoryHotplugDev *mhd = get_sclp_memory_hotplug_dev();
8cc3aecf 57 CPUState *cpu;
8cc3aecf 58 int cpu_count = 0;
1def6656 59 int rnsize, rnmax;
311467f7 60 int slots = MIN(machine->ram_slots, s390_get_memslot_count(kvm_state));
b038411d 61 IplParameterBlock *ipib = s390_ipl_get_iplb();
8cc3aecf
JH
62
63 CPU_FOREACH(cpu) {
64 cpu_count++;
65 }
66
67 /* CPU information */
68 read_info->entries_cpu = cpu_to_be16(cpu_count);
69 read_info->offset_cpu = cpu_to_be16(offsetof(ReadInfo, entries));
70 read_info->highest_cpu = cpu_to_be16(max_cpus);
71
059be520
DH
72 read_info->ibc_val = cpu_to_be32(s390_get_ibc_val());
73
4dd4200e
DH
74 /* Configuration Characteristic (Extension) */
75 s390_get_feat_block(S390_FEAT_TYPE_SCLP_CONF_CHAR,
76 read_info->conf_char);
77 s390_get_feat_block(S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT,
78 read_info->conf_char_ext);
79
026546e6 80 prepare_cpu_entries(sclp, read_info->entries, cpu_count);
8cc3aecf 81
8cba80c3
FB
82 read_info->facilities = cpu_to_be64(SCLP_HAS_CPU_INFO |
83 SCLP_HAS_PCI_RECONFIG);
f6c98f92 84
1def6656
MR
85 /* Memory Hotplug is only supported for the ccw machine type */
86 if (mhd) {
1def6656
MR
87 mhd->standby_subregion_size = MEM_SECTION_SIZE;
88 /* Deduct the memory slot already used for core */
89 if (slots > 0) {
90 while ((mhd->standby_subregion_size * (slots - 1)
91 < mhd->standby_mem_size)) {
92 mhd->standby_subregion_size = mhd->standby_subregion_size << 1;
93 }
94 }
95 /*
96 * Initialize mapping of guest standby memory sections indicating which
97 * are and are not online. Assume all standby memory begins offline.
98 */
99 if (mhd->standby_state_map == 0) {
100 if (mhd->standby_mem_size % mhd->standby_subregion_size) {
101 mhd->standby_state_map = g_malloc0((mhd->standby_mem_size /
102 mhd->standby_subregion_size + 1) *
103 (mhd->standby_subregion_size /
104 MEM_SECTION_SIZE));
105 } else {
106 mhd->standby_state_map = g_malloc0(mhd->standby_mem_size /
107 MEM_SECTION_SIZE);
108 }
109 }
110 mhd->padded_ram_size = ram_size + mhd->pad_size;
111 mhd->rzm = 1 << mhd->increment_size;
1def6656
MR
112
113 read_info->facilities |= cpu_to_be64(SCLP_FC_ASSIGN_ATTACH_READ_STOR);
114 }
3fad3252 115 read_info->mha_pow = s390_get_mha_pow();
a3669307 116 read_info->hmfai = cpu_to_be32(s390_get_hmfai());
1def6656 117
71a2fd35 118 rnsize = 1 << (sclp->increment_size - 20);
1def6656
MR
119 if (rnsize <= 128) {
120 read_info->rnsize = rnsize;
121 } else {
122 read_info->rnsize = 0;
123 read_info->rnsize2 = cpu_to_be32(rnsize);
124 }
125
bd80a8ad 126 rnmax = machine->maxram_size >> sclp->increment_size;
1def6656
MR
127 if (rnmax < 0x10000) {
128 read_info->rnmax = cpu_to_be16(rnmax);
129 } else {
130 read_info->rnmax = cpu_to_be16(0);
131 read_info->rnmax2 = cpu_to_be64(rnmax);
132 }
133
b038411d
FA
134 if (ipib && ipib->flags & DIAG308_FLAGS_LP_VALID) {
135 memcpy(&read_info->loadparm, &ipib->loadparm,
136 sizeof(read_info->loadparm));
137 } else {
138 s390_ipl_set_loadparm(read_info->loadparm);
139 }
140
1def6656
MR
141 sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_READ_COMPLETION);
142}
143
25a3c5af 144static void read_storage_element0_info(SCLPDevice *sclp, SCCB *sccb)
1def6656
MR
145{
146 int i, assigned;
147 int subincrement_id = SCLP_STARTING_SUBINCREMENT_ID;
148 ReadStorageElementInfo *storage_info = (ReadStorageElementInfo *) sccb;
149 sclpMemoryHotplugDev *mhd = get_sclp_memory_hotplug_dev();
150
b02ef3d9
DH
151 if (!mhd) {
152 sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
153 return;
154 }
1def6656
MR
155
156 if ((ram_size >> mhd->increment_size) >= 0x10000) {
157 sccb->h.response_code = cpu_to_be16(SCLP_RC_SCCB_BOUNDARY_VIOLATION);
158 return;
159 }
160
161 /* Return information regarding core memory */
162 storage_info->max_id = cpu_to_be16(mhd->standby_mem_size ? 1 : 0);
163 assigned = ram_size >> mhd->increment_size;
164 storage_info->assigned = cpu_to_be16(assigned);
165
166 for (i = 0; i < assigned; i++) {
167 storage_info->entries[i] = cpu_to_be32(subincrement_id);
168 subincrement_id += SCLP_INCREMENT_UNIT;
f6c98f92 169 }
f6c98f92
HG
170 sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_READ_COMPLETION);
171}
172
25a3c5af 173static void read_storage_element1_info(SCLPDevice *sclp, SCCB *sccb)
1def6656
MR
174{
175 ReadStorageElementInfo *storage_info = (ReadStorageElementInfo *) sccb;
176 sclpMemoryHotplugDev *mhd = get_sclp_memory_hotplug_dev();
177
b02ef3d9
DH
178 if (!mhd) {
179 sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
180 return;
181 }
1def6656
MR
182
183 if ((mhd->standby_mem_size >> mhd->increment_size) >= 0x10000) {
184 sccb->h.response_code = cpu_to_be16(SCLP_RC_SCCB_BOUNDARY_VIOLATION);
185 return;
186 }
187
188 /* Return information regarding standby memory */
189 storage_info->max_id = cpu_to_be16(mhd->standby_mem_size ? 1 : 0);
190 storage_info->assigned = cpu_to_be16(mhd->standby_mem_size >>
191 mhd->increment_size);
192 storage_info->standby = cpu_to_be16(mhd->standby_mem_size >>
193 mhd->increment_size);
194 sccb->h.response_code = cpu_to_be16(SCLP_RC_STANDBY_READ_COMPLETION);
195}
196
25a3c5af
DH
197static void attach_storage_element(SCLPDevice *sclp, SCCB *sccb,
198 uint16_t element)
1def6656
MR
199{
200 int i, assigned, subincrement_id;
201 AttachStorageElement *attach_info = (AttachStorageElement *) sccb;
202 sclpMemoryHotplugDev *mhd = get_sclp_memory_hotplug_dev();
203
b02ef3d9
DH
204 if (!mhd) {
205 sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
206 return;
207 }
1def6656
MR
208
209 if (element != 1) {
210 sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
211 return;
212 }
213
214 assigned = mhd->standby_mem_size >> mhd->increment_size;
215 attach_info->assigned = cpu_to_be16(assigned);
216 subincrement_id = ((ram_size >> mhd->increment_size) << 16)
217 + SCLP_STARTING_SUBINCREMENT_ID;
218 for (i = 0; i < assigned; i++) {
219 attach_info->entries[i] = cpu_to_be32(subincrement_id);
220 subincrement_id += SCLP_INCREMENT_UNIT;
221 }
222 sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_COMPLETION);
223}
224
25a3c5af 225static void assign_storage(SCLPDevice *sclp, SCCB *sccb)
1def6656
MR
226{
227 MemoryRegion *mr = NULL;
228 uint64_t this_subregion_size;
229 AssignStorage *assign_info = (AssignStorage *) sccb;
230 sclpMemoryHotplugDev *mhd = get_sclp_memory_hotplug_dev();
b02ef3d9 231 ram_addr_t assign_addr;
1def6656
MR
232 MemoryRegion *sysmem = get_system_memory();
233
b02ef3d9
DH
234 if (!mhd) {
235 sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
236 return;
237 }
238 assign_addr = (assign_info->rn - 1) * mhd->rzm;
239
1def6656
MR
240 if ((assign_addr % MEM_SECTION_SIZE == 0) &&
241 (assign_addr >= mhd->padded_ram_size)) {
242 /* Re-use existing memory region if found */
243 mr = memory_region_find(sysmem, assign_addr, 1).mr;
732bdd38 244 memory_region_unref(mr);
1def6656
MR
245 if (!mr) {
246
247 MemoryRegion *standby_ram = g_new(MemoryRegion, 1);
248
249 /* offset to align to standby_subregion_size for allocation */
250 ram_addr_t offset = assign_addr -
251 (assign_addr - mhd->padded_ram_size)
252 % mhd->standby_subregion_size;
253
254 /* strlen("standby.ram") + 4 (Max of KVM_MEMORY_SLOTS) + NULL */
255 char id[16];
256 snprintf(id, 16, "standby.ram%d",
257 (int)((offset - mhd->padded_ram_size) /
258 mhd->standby_subregion_size) + 1);
259
260 /* Allocate a subregion of the calculated standby_subregion_size */
261 if (offset + mhd->standby_subregion_size >
262 mhd->padded_ram_size + mhd->standby_mem_size) {
263 this_subregion_size = mhd->padded_ram_size +
264 mhd->standby_mem_size - offset;
265 } else {
266 this_subregion_size = mhd->standby_subregion_size;
267 }
268
f8ed85ac
MA
269 memory_region_init_ram(standby_ram, NULL, id, this_subregion_size,
270 &error_fatal);
732bdd38
DH
271 /* This is a hack to make memory hotunplug work again. Once we have
272 * subdevices, we have to unparent them when unassigning memory,
273 * instead of doing it via the ref count of the MemoryRegion. */
274 object_ref(OBJECT(standby_ram));
275 object_unparent(OBJECT(standby_ram));
1def6656
MR
276 vmstate_register_ram_global(standby_ram);
277 memory_region_add_subregion(sysmem, offset, standby_ram);
278 }
279 /* The specified subregion is no longer in standby */
280 mhd->standby_state_map[(assign_addr - mhd->padded_ram_size)
281 / MEM_SECTION_SIZE] = 1;
282 }
283 sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_COMPLETION);
284}
285
25a3c5af 286static void unassign_storage(SCLPDevice *sclp, SCCB *sccb)
1def6656
MR
287{
288 MemoryRegion *mr = NULL;
289 AssignStorage *assign_info = (AssignStorage *) sccb;
290 sclpMemoryHotplugDev *mhd = get_sclp_memory_hotplug_dev();
b02ef3d9 291 ram_addr_t unassign_addr;
1def6656
MR
292 MemoryRegion *sysmem = get_system_memory();
293
b02ef3d9
DH
294 if (!mhd) {
295 sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
296 return;
297 }
298 unassign_addr = (assign_info->rn - 1) * mhd->rzm;
299
1def6656
MR
300 /* if the addr is a multiple of 256 MB */
301 if ((unassign_addr % MEM_SECTION_SIZE == 0) &&
302 (unassign_addr >= mhd->padded_ram_size)) {
303 mhd->standby_state_map[(unassign_addr -
304 mhd->padded_ram_size) / MEM_SECTION_SIZE] = 0;
305
306 /* find the specified memory region and destroy it */
307 mr = memory_region_find(sysmem, unassign_addr, 1).mr;
732bdd38 308 memory_region_unref(mr);
1def6656
MR
309 if (mr) {
310 int i;
311 int is_removable = 1;
312 ram_addr_t map_offset = (unassign_addr - mhd->padded_ram_size -
313 (unassign_addr - mhd->padded_ram_size)
314 % mhd->standby_subregion_size);
315 /* Mark all affected subregions as 'standby' once again */
316 for (i = 0;
317 i < (mhd->standby_subregion_size / MEM_SECTION_SIZE);
318 i++) {
319
320 if (mhd->standby_state_map[i + map_offset / MEM_SECTION_SIZE]) {
321 is_removable = 0;
322 break;
323 }
324 }
325 if (is_removable) {
326 memory_region_del_subregion(sysmem, mr);
732bdd38 327 object_unref(OBJECT(mr));
1def6656
MR
328 }
329 }
330 }
331 sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_COMPLETION);
332}
333
8cc3aecf 334/* Provide information about the CPU */
25a3c5af 335static void sclp_read_cpu_info(SCLPDevice *sclp, SCCB *sccb)
8cc3aecf
JH
336{
337 ReadCpuInfo *cpu_info = (ReadCpuInfo *) sccb;
338 CPUState *cpu;
339 int cpu_count = 0;
8cc3aecf
JH
340
341 CPU_FOREACH(cpu) {
342 cpu_count++;
343 }
344
345 cpu_info->nr_configured = cpu_to_be16(cpu_count);
346 cpu_info->offset_configured = cpu_to_be16(offsetof(ReadCpuInfo, entries));
347 cpu_info->nr_standby = cpu_to_be16(0);
348
349 /* The standby offset is 16-byte for each CPU */
350 cpu_info->offset_standby = cpu_to_be16(cpu_info->offset_configured
351 + cpu_info->nr_configured*sizeof(CPUEntry));
352
026546e6 353 prepare_cpu_entries(sclp, cpu_info->entries, cpu_count);
8cc3aecf
JH
354
355 sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_READ_COMPLETION);
356}
357
25a3c5af 358static void sclp_execute(SCLPDevice *sclp, SCCB *sccb, uint32_t code)
f6c98f92 359{
25a3c5af
DH
360 SCLPDeviceClass *sclp_c = SCLP_GET_CLASS(sclp);
361 SCLPEventFacility *ef = sclp->event_facility;
477a72a1 362 SCLPEventFacilityClass *efc = EVENT_FACILITY_GET_CLASS(ef);
559a17a1 363
5f04c14a 364 switch (code & SCLP_CMD_CODE_MASK) {
f6c98f92
HG
365 case SCLP_CMDW_READ_SCP_INFO:
366 case SCLP_CMDW_READ_SCP_INFO_FORCED:
25a3c5af 367 sclp_c->read_SCP_info(sclp, sccb);
f6c98f92 368 break;
8cc3aecf 369 case SCLP_CMDW_READ_CPU_INFO:
25a3c5af 370 sclp_c->read_cpu_info(sclp, sccb);
8cc3aecf 371 break;
1def6656
MR
372 case SCLP_READ_STORAGE_ELEMENT_INFO:
373 if (code & 0xff00) {
25a3c5af 374 sclp_c->read_storage_element1_info(sclp, sccb);
1def6656 375 } else {
25a3c5af 376 sclp_c->read_storage_element0_info(sclp, sccb);
1def6656
MR
377 }
378 break;
379 case SCLP_ATTACH_STORAGE_ELEMENT:
25a3c5af 380 sclp_c->attach_storage_element(sclp, sccb, (code & 0xff00) >> 8);
1def6656
MR
381 break;
382 case SCLP_ASSIGN_STORAGE:
25a3c5af 383 sclp_c->assign_storage(sclp, sccb);
1def6656
MR
384 break;
385 case SCLP_UNASSIGN_STORAGE:
25a3c5af 386 sclp_c->unassign_storage(sclp, sccb);
1def6656 387 break;
8cba80c3 388 case SCLP_CMDW_CONFIGURE_PCI:
8f5cb693 389 s390_pci_sclp_configure(sccb);
8cba80c3
FB
390 break;
391 case SCLP_CMDW_DECONFIGURE_PCI:
8f5cb693 392 s390_pci_sclp_deconfigure(sccb);
8cba80c3 393 break;
f6c98f92 394 default:
477a72a1 395 efc->command_handler(ef, sccb, code);
f6c98f92
HG
396 break;
397 }
398}
399
6e252802 400int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code)
f6c98f92 401{
25a3c5af
DH
402 SCLPDevice *sclp = get_sclp_device();
403 SCLPDeviceClass *sclp_c = SCLP_GET_CLASS(sclp);
f6c98f92
HG
404 int r = 0;
405 SCCB work_sccb;
406
407 hwaddr sccb_len = sizeof(SCCB);
408
409 /* first some basic checks on program checks */
6e252802
TH
410 if (env->psw.mask & PSW_MASK_PSTATE) {
411 r = -PGM_PRIVILEGED;
412 goto out;
413 }
f6c98f92
HG
414 if (cpu_physical_memory_is_io(sccb)) {
415 r = -PGM_ADDRESSING;
416 goto out;
417 }
6e252802
TH
418 if ((sccb & ~0x1fffUL) == 0 || (sccb & ~0x1fffUL) == env->psa
419 || (sccb & ~0x7ffffff8UL) != 0) {
f6c98f92
HG
420 r = -PGM_SPECIFICATION;
421 goto out;
422 }
423
424 /*
425 * we want to work on a private copy of the sccb, to prevent guests
426 * from playing dirty tricks by modifying the memory content after
427 * the host has checked the values
428 */
429 cpu_physical_memory_read(sccb, &work_sccb, sccb_len);
430
431 /* Valid sccb sizes */
432 if (be16_to_cpu(work_sccb.h.length) < sizeof(SCCBHeader) ||
433 be16_to_cpu(work_sccb.h.length) > SCCB_SIZE) {
434 r = -PGM_SPECIFICATION;
435 goto out;
436 }
437
57ddd73e 438 sclp_c->execute(sclp, &work_sccb, code);
f6c98f92
HG
439
440 cpu_physical_memory_write(sccb, &work_sccb,
441 be16_to_cpu(work_sccb.h.length));
442
1723a1b6 443 sclp_c->service_interrupt(sclp, sccb);
f6c98f92
HG
444
445out:
446 return r;
447}
448
1723a1b6 449static void service_interrupt(SCLPDevice *sclp, uint32_t sccb)
f6c98f92 450{
1723a1b6 451 SCLPEventFacility *ef = sclp->event_facility;
477a72a1
HG
452 SCLPEventFacilityClass *efc = EVENT_FACILITY_GET_CLASS(ef);
453
559a17a1
HG
454 uint32_t param = sccb & ~3;
455
456 /* Indicate whether an event is still pending */
477a72a1 457 param |= efc->event_pending(ef) ? 1 : 0;
559a17a1
HG
458
459 if (!param) {
460 /* No need to send an interrupt, there's nothing to be notified about */
461 return;
462 }
463 s390_sclp_extint(param);
f6c98f92
HG
464}
465
1723a1b6
DH
466void sclp_service_interrupt(uint32_t sccb)
467{
468 SCLPDevice *sclp = get_sclp_device();
469 SCLPDeviceClass *sclp_c = SCLP_GET_CLASS(sclp);
470
471 sclp_c->service_interrupt(sclp, sccb);
472}
473
f6c98f92
HG
474/* qemu object creation and initialization functions */
475
559a17a1
HG
476void s390_sclp_init(void)
477{
515190d9 478 Object *new = object_new(TYPE_SCLP);
559a17a1 479
515190d9
DH
480 object_property_add_child(qdev_get_machine(), TYPE_SCLP, new,
481 NULL);
482 object_unref(OBJECT(new));
483 qdev_init_nofail(DEVICE(new));
559a17a1 484}
0844df77 485
515190d9
DH
486static void sclp_realize(DeviceState *dev, Error **errp)
487{
1cf065fb 488 MachineState *machine = MACHINE(qdev_get_machine());
515190d9 489 SCLPDevice *sclp = SCLP(dev);
e6da780d 490 Error *err = NULL;
1cf065fb
DH
491 uint64_t hw_limit;
492 int ret;
515190d9
DH
493
494 object_property_set_bool(OBJECT(sclp->event_facility), true, "realized",
e6da780d
MA
495 &err);
496 if (err) {
24da21f2 497 goto out;
515190d9 498 }
8b638c43
DH
499 /*
500 * qdev_device_add searches the sysbus for TYPE_SCLP_EVENTS_BUS. As long
501 * as we can't find a fitting bus via the qom tree, we have to add the
502 * event facility to the sysbus, so e.g. a sclp console can be created.
503 */
504 qdev_set_parent_bus(DEVICE(sclp->event_facility), sysbus_get_default());
1cf065fb
DH
505
506 ret = s390_set_memory_limit(machine->maxram_size, &hw_limit);
507 if (ret == -E2BIG) {
d0e31a10 508 error_setg(&err, "host supports a maximum of %" PRIu64 " GB",
1cf065fb 509 hw_limit >> 30);
1cf065fb 510 } else if (ret) {
d0e31a10 511 error_setg(&err, "setting the guest size failed");
1cf065fb 512 }
24da21f2
MA
513
514out:
e6da780d 515 error_propagate(errp, err);
515190d9
DH
516}
517
1cf065fb
DH
518static void sclp_memory_init(SCLPDevice *sclp)
519{
520 MachineState *machine = MACHINE(qdev_get_machine());
521 ram_addr_t initial_mem = machine->ram_size;
522 ram_addr_t max_mem = machine->maxram_size;
523 ram_addr_t standby_mem = max_mem - initial_mem;
524 ram_addr_t pad_mem = 0;
525 int increment_size = 20;
526
527 /* The storage increment size is a multiple of 1M and is a power of 2.
528 * The number of storage increments must be MAX_STORAGE_INCREMENTS or fewer.
529 * The variable 'increment_size' is an exponent of 2 that can be
530 * used to calculate the size (in bytes) of an increment. */
531 while ((initial_mem >> increment_size) > MAX_STORAGE_INCREMENTS) {
532 increment_size++;
533 }
534 if (machine->ram_slots) {
535 while ((standby_mem >> increment_size) > MAX_STORAGE_INCREMENTS) {
536 increment_size++;
537 }
538 }
71a2fd35 539 sclp->increment_size = increment_size;
1cf065fb
DH
540
541 /* The core and standby memory areas need to be aligned with
542 * the increment size. In effect, this can cause the
543 * user-specified memory size to be rounded down to align
544 * with the nearest increment boundary. */
545 initial_mem = initial_mem >> increment_size << increment_size;
546 standby_mem = standby_mem >> increment_size << increment_size;
547
548 /* If the size of ram is not on a MEM_SECTION_SIZE boundary,
549 calculate the pad size necessary to force this boundary. */
550 if (machine->ram_slots && standby_mem) {
551 sclpMemoryHotplugDev *mhd = init_sclp_memory_hotplug_dev();
552
553 if (initial_mem % MEM_SECTION_SIZE) {
554 pad_mem = MEM_SECTION_SIZE - initial_mem % MEM_SECTION_SIZE;
555 }
556 mhd->increment_size = increment_size;
557 mhd->pad_size = pad_mem;
558 mhd->standby_mem_size = standby_mem;
559 }
560 machine->ram_size = initial_mem;
561 machine->maxram_size = initial_mem + pad_mem + standby_mem;
562 /* let's propagate the changed ram size into the global variable. */
563 ram_size = initial_mem;
564}
565
515190d9
DH
566static void sclp_init(Object *obj)
567{
568 SCLPDevice *sclp = SCLP(obj);
569 Object *new;
570
571 new = object_new(TYPE_SCLP_EVENT_FACILITY);
572 object_property_add_child(obj, TYPE_SCLP_EVENT_FACILITY, new, NULL);
515190d9
DH
573 object_unref(new);
574 sclp->event_facility = EVENT_FACILITY(new);
1cf065fb
DH
575
576 sclp_memory_init(sclp);
515190d9
DH
577}
578
579static void sclp_class_init(ObjectClass *oc, void *data)
580{
25a3c5af 581 SCLPDeviceClass *sc = SCLP_CLASS(oc);
515190d9
DH
582 DeviceClass *dc = DEVICE_CLASS(oc);
583
584 dc->desc = "SCLP (Service-Call Logical Processor)";
585 dc->realize = sclp_realize;
586 dc->hotpluggable = false;
587 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
25a3c5af
DH
588
589 sc->read_SCP_info = read_SCP_info;
590 sc->read_storage_element0_info = read_storage_element0_info;
591 sc->read_storage_element1_info = read_storage_element1_info;
592 sc->attach_storage_element = attach_storage_element;
593 sc->assign_storage = assign_storage;
594 sc->unassign_storage = unassign_storage;
595 sc->read_cpu_info = sclp_read_cpu_info;
596 sc->execute = sclp_execute;
1723a1b6 597 sc->service_interrupt = service_interrupt;
515190d9
DH
598}
599
600static TypeInfo sclp_info = {
601 .name = TYPE_SCLP,
602 .parent = TYPE_DEVICE,
603 .instance_init = sclp_init,
604 .instance_size = sizeof(SCLPDevice),
605 .class_init = sclp_class_init,
606 .class_size = sizeof(SCLPDeviceClass),
607};
608
0844df77
MR
609sclpMemoryHotplugDev *init_sclp_memory_hotplug_dev(void)
610{
611 DeviceState *dev;
612 dev = qdev_create(NULL, TYPE_SCLP_MEMORY_HOTPLUG_DEV);
613 object_property_add_child(qdev_get_machine(),
614 TYPE_SCLP_MEMORY_HOTPLUG_DEV,
615 OBJECT(dev), NULL);
616 qdev_init_nofail(dev);
617 return SCLP_MEMORY_HOTPLUG_DEV(object_resolve_path(
618 TYPE_SCLP_MEMORY_HOTPLUG_DEV, NULL));
619}
620
621sclpMemoryHotplugDev *get_sclp_memory_hotplug_dev(void)
622{
623 return SCLP_MEMORY_HOTPLUG_DEV(object_resolve_path(
624 TYPE_SCLP_MEMORY_HOTPLUG_DEV, NULL));
625}
626
183f6b8d
CH
627static void sclp_memory_hotplug_dev_class_init(ObjectClass *klass,
628 void *data)
629{
630 DeviceClass *dc = DEVICE_CLASS(klass);
631
632 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
633}
634
0844df77
MR
635static TypeInfo sclp_memory_hotplug_dev_info = {
636 .name = TYPE_SCLP_MEMORY_HOTPLUG_DEV,
637 .parent = TYPE_SYS_BUS_DEVICE,
638 .instance_size = sizeof(sclpMemoryHotplugDev),
183f6b8d 639 .class_init = sclp_memory_hotplug_dev_class_init,
0844df77
MR
640};
641
642static void register_types(void)
643{
644 type_register_static(&sclp_memory_hotplug_dev_info);
515190d9 645 type_register_static(&sclp_info);
0844df77
MR
646}
647type_init(register_types);
This page took 0.376006 seconds and 4 git commands to generate.