xref: /qemu/hw/s390x/sclpcpu.c (revision 416e34bd)
1 /*
2  * SCLP event type
3  *    Signal CPU - Trigger SCLP interrupt for system CPU configure or
4  *    de-configure
5  *
6  * Copyright IBM, Corp. 2013
7  *
8  * Authors:
9  *  Thang Pham <thang.pham@us.ibm.com>
10  *
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.
13  *
14  */
15 
16 #include "qemu/osdep.h"
17 #include "sysemu/sysemu.h"
18 #include "hw/s390x/sclp.h"
19 #include "qemu/module.h"
20 #include "hw/s390x/event-facility.h"
21 #include "cpu.h"
22 #include "sysemu/cpus.h"
23 
24 typedef struct ConfigMgtData {
25     EventBufferHeader ebh;
26     uint8_t reserved;
27     uint8_t event_qualifier;
28 } QEMU_PACKED ConfigMgtData;
29 
30 #define EVENT_QUAL_CPU_CHANGE  1
31 
32 void raise_irq_cpu_hotplug(void)
33 {
34     Object *obj = object_resolve_path_type("", TYPE_SCLP_CPU_HOTPLUG, NULL);
35 
36     SCLP_EVENT(obj)->event_pending = true;
37 
38     /* Trigger SCLP read operation */
39     sclp_service_interrupt(0);
40 }
41 
42 static sccb_mask_t send_mask(void)
43 {
44     return SCLP_EVENT_MASK_CONFIG_MGT_DATA;
45 }
46 
47 static sccb_mask_t receive_mask(void)
48 {
49     return 0;
50 }
51 
52 static int read_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr,
53                            int *slen)
54 {
55     ConfigMgtData *cdata = (ConfigMgtData *) evt_buf_hdr;
56     if (*slen < sizeof(ConfigMgtData)) {
57         return 0;
58     }
59 
60     /* Event is no longer pending */
61     if (!event->event_pending) {
62         return 0;
63     }
64     event->event_pending = false;
65 
66     /* Event header data */
67     cdata->ebh.length = cpu_to_be16(sizeof(ConfigMgtData));
68     cdata->ebh.type = SCLP_EVENT_CONFIG_MGT_DATA;
69     cdata->ebh.flags |= SCLP_EVENT_BUFFER_ACCEPTED;
70 
71     /* Trigger a rescan of CPUs by setting event qualifier */
72     cdata->event_qualifier = EVENT_QUAL_CPU_CHANGE;
73     *slen -= sizeof(ConfigMgtData);
74 
75     return 1;
76 }
77 
78 static void cpu_class_init(ObjectClass *oc, void *data)
79 {
80     SCLPEventClass *k = SCLP_EVENT_CLASS(oc);
81     DeviceClass *dc = DEVICE_CLASS(oc);
82 
83     k->get_send_mask = send_mask;
84     k->get_receive_mask = receive_mask;
85     k->read_event_data = read_event_data;
86     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
87     /*
88      * Reason: raise_irq_cpu_hotplug() depends on an unique
89      * TYPE_SCLP_CPU_HOTPLUG device, which is already created
90      * by the sclp event facility
91      */
92     dc->user_creatable = false;
93 }
94 
95 static const TypeInfo sclp_cpu_info = {
96     .name          = TYPE_SCLP_CPU_HOTPLUG,
97     .parent        = TYPE_SCLP_EVENT,
98     .instance_size = sizeof(SCLPEvent),
99     .class_init    = cpu_class_init,
100     .class_size    = sizeof(SCLPEventClass),
101 };
102 
103 static void sclp_cpu_register_types(void)
104 {
105     type_register_static(&sclp_cpu_info);
106 }
107 
108 type_init(sclp_cpu_register_types)
109