3 * Signal CPU - Trigger SCLP interrupt for system CPU configure or
6 * Copyright IBM, Corp. 2013
9 * Thang Pham <thang.pham@us.ibm.com>
11 * This work is licensed under the terms of the GNU GPL, version 2 or (at your
12 * option) any later version. See the COPYING file in the top-level directory.
15 #include "sysemu/sysemu.h"
16 #include "hw/s390x/sclp.h"
17 #include "hw/s390x/event-facility.h"
19 #include "sysemu/cpus.h"
20 #include "sysemu/kvm.h"
22 typedef struct ConfigMgtData
{
23 EventBufferHeader ebh
;
25 uint8_t event_qualifier
;
26 } QEMU_PACKED ConfigMgtData
;
28 static qemu_irq
*irq_cpu_hotplug
; /* Only used in this file */
30 #define EVENT_QUAL_CPU_CHANGE 1
32 void raise_irq_cpu_hotplug(void)
34 qemu_irq_raise(*irq_cpu_hotplug
);
37 static unsigned int send_mask(void)
39 return SCLP_EVENT_MASK_CONFIG_MGT_DATA
;
42 static unsigned int receive_mask(void)
47 static int read_event_data(SCLPEvent
*event
, EventBufferHeader
*evt_buf_hdr
,
50 ConfigMgtData
*cdata
= (ConfigMgtData
*) evt_buf_hdr
;
51 if (*slen
< sizeof(ConfigMgtData
)) {
55 /* Event is no longer pending */
56 if (!event
->event_pending
) {
59 event
->event_pending
= false;
61 /* Event header data */
62 cdata
->ebh
.length
= cpu_to_be16(sizeof(ConfigMgtData
));
63 cdata
->ebh
.type
= SCLP_EVENT_CONFIG_MGT_DATA
;
64 cdata
->ebh
.flags
|= SCLP_EVENT_BUFFER_ACCEPTED
;
66 /* Trigger a rescan of CPUs by setting event qualifier */
67 cdata
->event_qualifier
= EVENT_QUAL_CPU_CHANGE
;
68 *slen
-= sizeof(ConfigMgtData
);
73 static void trigger_signal(void *opaque
, int n
, int level
)
75 SCLPEvent
*event
= opaque
;
76 event
->event_pending
= true;
78 /* Trigger SCLP read operation */
79 sclp_service_interrupt(0);
82 static int irq_cpu_hotplug_init(SCLPEvent
*event
)
84 irq_cpu_hotplug
= qemu_allocate_irqs(trigger_signal
, event
, 1);
88 static void cpu_class_init(ObjectClass
*oc
, void *data
)
90 SCLPEventClass
*k
= SCLP_EVENT_CLASS(oc
);
91 DeviceClass
*dc
= DEVICE_CLASS(oc
);
93 k
->init
= irq_cpu_hotplug_init
;
94 k
->get_send_mask
= send_mask
;
95 k
->get_receive_mask
= receive_mask
;
96 k
->read_event_data
= read_event_data
;
97 k
->write_event_data
= NULL
;
98 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
101 static const TypeInfo sclp_cpu_info
= {
102 .name
= "sclp-cpu-hotplug",
103 .parent
= TYPE_SCLP_EVENT
,
104 .instance_size
= sizeof(SCLPEvent
),
105 .class_init
= cpu_class_init
,
106 .class_size
= sizeof(SCLPEventClass
),
109 static void sclp_cpu_register_types(void)
111 type_register_static(&sclp_cpu_info
);
114 type_init(sclp_cpu_register_types
)