xref: /openbmc/qemu/include/hw/s390x/s390_flic.h (revision 67abc3dd)
1 /*
2  * QEMU S390x floating interrupt controller (flic)
3  *
4  * Copyright 2014 IBM Corp.
5  * Author(s): Jens Freimann <jfrei@linux.vnet.ibm.com>
6  *            Cornelia Huck <cornelia.huck@de.ibm.com>
7  *
8  * This work is licensed under the terms of the GNU GPL, version 2 or (at
9  * your option) any later version. See the COPYING file in the top-level
10  * directory.
11  */
12 
13 #ifndef HW_S390_FLIC_H
14 #define HW_S390_FLIC_H
15 
16 #include "hw/sysbus.h"
17 #include "hw/s390x/adapter.h"
18 #include "hw/virtio/virtio.h"
19 #include "qemu/queue.h"
20 
21 /*
22  * Reserve enough gsis to accommodate all virtio devices.
23  * If any other user of adapter routes needs more of these,
24  * we need to bump the value; but virtio looks like the
25  * maximum right now.
26  */
27 #define ADAPTER_ROUTES_MAX_GSI VIRTIO_QUEUE_MAX
28 
29 typedef struct AdapterRoutes {
30     AdapterInfo adapter;
31     int num_routes;
32     int gsi[ADAPTER_ROUTES_MAX_GSI];
33 } AdapterRoutes;
34 
35 extern const VMStateDescription vmstate_adapter_routes;
36 
37 #define VMSTATE_ADAPTER_ROUTES(_f, _s) \
38     VMSTATE_STRUCT(_f, _s, 1, vmstate_adapter_routes, AdapterRoutes)
39 
40 #define TYPE_S390_FLIC_COMMON "s390-flic"
41 #define S390_FLIC_COMMON(obj) \
42     OBJECT_CHECK(S390FLICState, (obj), TYPE_S390_FLIC_COMMON)
43 
44 typedef struct S390FLICState {
45     SysBusDevice parent_obj;
46     /* to limit AdapterRoutes.num_routes for compat */
47     uint32_t adapter_routes_max_batch;
48     bool ais_supported;
49 } S390FLICState;
50 
51 #define S390_FLIC_COMMON_CLASS(klass) \
52     OBJECT_CLASS_CHECK(S390FLICStateClass, (klass), TYPE_S390_FLIC_COMMON)
53 #define S390_FLIC_COMMON_GET_CLASS(obj) \
54     OBJECT_GET_CLASS(S390FLICStateClass, (obj), TYPE_S390_FLIC_COMMON)
55 
56 typedef struct S390FLICStateClass {
57     DeviceClass parent_class;
58 
59     int (*register_io_adapter)(S390FLICState *fs, uint32_t id, uint8_t isc,
60                                bool swap, bool maskable, uint8_t flags);
61     int (*io_adapter_map)(S390FLICState *fs, uint32_t id, uint64_t map_addr,
62                           bool do_map);
63     int (*add_adapter_routes)(S390FLICState *fs, AdapterRoutes *routes);
64     void (*release_adapter_routes)(S390FLICState *fs, AdapterRoutes *routes);
65     int (*clear_io_irq)(S390FLICState *fs, uint16_t subchannel_id,
66                         uint16_t subchannel_nr);
67     int (*modify_ais_mode)(S390FLICState *fs, uint8_t isc, uint16_t mode);
68     int (*inject_airq)(S390FLICState *fs, uint8_t type, uint8_t isc,
69                        uint8_t flags);
70     void (*inject_service)(S390FLICState *fs, uint32_t parm);
71     void (*inject_io)(S390FLICState *fs, uint16_t subchannel_id,
72                       uint16_t subchannel_nr, uint32_t io_int_parm,
73                       uint32_t io_int_word);
74     void (*inject_crw_mchk)(S390FLICState *fs);
75 } S390FLICStateClass;
76 
77 #define TYPE_KVM_S390_FLIC "s390-flic-kvm"
78 typedef struct KVMS390FLICState KVMS390FLICState;
79 #define KVM_S390_FLIC(obj) \
80     OBJECT_CHECK(KVMS390FLICState, (obj), TYPE_KVM_S390_FLIC)
81 
82 #define TYPE_QEMU_S390_FLIC "s390-flic-qemu"
83 #define QEMU_S390_FLIC(obj) \
84     OBJECT_CHECK(QEMUS390FLICState, (obj), TYPE_QEMU_S390_FLIC)
85 
86 #define SIC_IRQ_MODE_ALL 0
87 #define SIC_IRQ_MODE_SINGLE 1
88 #define AIS_MODE_MASK(isc) (0x80 >> isc)
89 
90 #define ISC_TO_PENDING_IO(_isc) (0x80 >> (_isc))
91 #define CR6_TO_PENDING_IO(_cr6) (((_cr6) >> 24) & 0xff)
92 
93 /* organize the ISC bits so that the macros above work */
94 #define FLIC_PENDING_IO_ISC7            (1 << 0)
95 #define FLIC_PENDING_IO_ISC6            (1 << 1)
96 #define FLIC_PENDING_IO_ISC5            (1 << 2)
97 #define FLIC_PENDING_IO_ISC4            (1 << 3)
98 #define FLIC_PENDING_IO_ISC3            (1 << 4)
99 #define FLIC_PENDING_IO_ISC2            (1 << 5)
100 #define FLIC_PENDING_IO_ISC1            (1 << 6)
101 #define FLIC_PENDING_IO_ISC0            (1 << 7)
102 #define FLIC_PENDING_SERVICE            (1 << 8)
103 #define FLIC_PENDING_MCHK_CR            (1 << 9)
104 
105 #define FLIC_PENDING_IO (FLIC_PENDING_IO_ISC0 | FLIC_PENDING_IO_ISC1 | \
106                          FLIC_PENDING_IO_ISC2 | FLIC_PENDING_IO_ISC3 | \
107                          FLIC_PENDING_IO_ISC4 | FLIC_PENDING_IO_ISC5 | \
108                          FLIC_PENDING_IO_ISC6 | FLIC_PENDING_IO_ISC7)
109 
110 typedef struct QEMUS390FlicIO {
111     uint16_t id;
112     uint16_t nr;
113     uint32_t parm;
114     uint32_t word;
115     QLIST_ENTRY(QEMUS390FlicIO) next;
116 } QEMUS390FlicIO;
117 
118 typedef struct QEMUS390FLICState {
119     S390FLICState parent_obj;
120     uint32_t pending;
121     uint32_t service_param;
122     uint8_t simm;
123     uint8_t nimm;
124     QLIST_HEAD(, QEMUS390FlicIO) io[8];
125 } QEMUS390FLICState;
126 
127 uint32_t qemu_s390_flic_dequeue_service(QEMUS390FLICState *flic);
128 QEMUS390FlicIO *qemu_s390_flic_dequeue_io(QEMUS390FLICState *flic,
129                                           uint64_t cr6);
130 void qemu_s390_flic_dequeue_crw_mchk(QEMUS390FLICState *flic);
131 bool qemu_s390_flic_has_service(QEMUS390FLICState *flic);
132 bool qemu_s390_flic_has_io(QEMUS390FLICState *fs, uint64_t cr6);
133 bool qemu_s390_flic_has_crw_mchk(QEMUS390FLICState *flic);
134 bool qemu_s390_flic_has_any(QEMUS390FLICState *flic);
135 
136 void s390_flic_init(void);
137 
138 S390FLICState *s390_get_flic(void);
139 QEMUS390FLICState *s390_get_qemu_flic(S390FLICState *fs);
140 S390FLICStateClass *s390_get_flic_class(S390FLICState *fs);
141 bool ais_needed(void *opaque);
142 
143 #endif /* HW_S390_FLIC_H */
144