xref: /openbmc/qemu/include/hw/s390x/s390_flic.h (revision c1991c09)
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 #include "qom/object.h"
21 
22 /*
23  * Reserve enough gsis to accommodate all virtio devices.
24  * If any other user of adapter routes needs more of these,
25  * we need to bump the value; but virtio looks like the
26  * maximum right now.
27  */
28 #define ADAPTER_ROUTES_MAX_GSI VIRTIO_QUEUE_MAX
29 
30 typedef struct AdapterRoutes {
31     AdapterInfo adapter;
32     int num_routes;
33     int gsi[ADAPTER_ROUTES_MAX_GSI];
34 } AdapterRoutes;
35 
36 extern const VMStateDescription vmstate_adapter_routes;
37 
38 #define TYPE_S390_FLIC_COMMON "s390-flic"
39 OBJECT_DECLARE_TYPE(S390FLICState, S390FLICStateClass,
40                     S390_FLIC_COMMON)
41 
42 struct S390FLICState {
43     SysBusDevice parent_obj;
44     /* to limit AdapterRoutes.num_routes for compat */
45     uint32_t adapter_routes_max_batch;
46     bool ais_supported;
47     bool migration_enabled;
48 };
49 
50 
51 struct S390FLICStateClass {
52     DeviceClass parent_class;
53 
54     int (*register_io_adapter)(S390FLICState *fs, uint32_t id, uint8_t isc,
55                                bool swap, bool maskable, uint8_t flags);
56     int (*io_adapter_map)(S390FLICState *fs, uint32_t id, uint64_t map_addr,
57                           bool do_map);
58     int (*add_adapter_routes)(S390FLICState *fs, AdapterRoutes *routes);
59     void (*release_adapter_routes)(S390FLICState *fs, AdapterRoutes *routes);
60     int (*clear_io_irq)(S390FLICState *fs, uint16_t subchannel_id,
61                         uint16_t subchannel_nr);
62     int (*modify_ais_mode)(S390FLICState *fs, uint8_t isc, uint16_t mode);
63     int (*inject_airq)(S390FLICState *fs, uint8_t type, uint8_t isc,
64                        uint8_t flags);
65     void (*inject_service)(S390FLICState *fs, uint32_t parm);
66     void (*inject_io)(S390FLICState *fs, uint16_t subchannel_id,
67                       uint16_t subchannel_nr, uint32_t io_int_parm,
68                       uint32_t io_int_word);
69     void (*inject_crw_mchk)(S390FLICState *fs);
70 };
71 
72 #define TYPE_KVM_S390_FLIC "s390-flic-kvm"
73 typedef struct KVMS390FLICState KVMS390FLICState;
74 DECLARE_INSTANCE_CHECKER(KVMS390FLICState, KVM_S390_FLIC,
75                          TYPE_KVM_S390_FLIC)
76 
77 #define TYPE_QEMU_S390_FLIC "s390-flic-qemu"
78 OBJECT_DECLARE_SIMPLE_TYPE(QEMUS390FLICState, QEMU_S390_FLIC)
79 
80 #define SIC_IRQ_MODE_ALL 0
81 #define SIC_IRQ_MODE_SINGLE 1
82 #define AIS_MODE_MASK(isc) (0x80 >> isc)
83 
84 #define ISC_TO_PENDING_IO(_isc) (0x80 >> (_isc))
85 #define CR6_TO_PENDING_IO(_cr6) (((_cr6) >> 24) & 0xff)
86 
87 /* organize the ISC bits so that the macros above work */
88 #define FLIC_PENDING_IO_ISC7            (1 << 0)
89 #define FLIC_PENDING_IO_ISC6            (1 << 1)
90 #define FLIC_PENDING_IO_ISC5            (1 << 2)
91 #define FLIC_PENDING_IO_ISC4            (1 << 3)
92 #define FLIC_PENDING_IO_ISC3            (1 << 4)
93 #define FLIC_PENDING_IO_ISC2            (1 << 5)
94 #define FLIC_PENDING_IO_ISC1            (1 << 6)
95 #define FLIC_PENDING_IO_ISC0            (1 << 7)
96 #define FLIC_PENDING_SERVICE            (1 << 8)
97 #define FLIC_PENDING_MCHK_CR            (1 << 9)
98 
99 #define FLIC_PENDING_IO (FLIC_PENDING_IO_ISC0 | FLIC_PENDING_IO_ISC1 | \
100                          FLIC_PENDING_IO_ISC2 | FLIC_PENDING_IO_ISC3 | \
101                          FLIC_PENDING_IO_ISC4 | FLIC_PENDING_IO_ISC5 | \
102                          FLIC_PENDING_IO_ISC6 | FLIC_PENDING_IO_ISC7)
103 
104 typedef struct QEMUS390FlicIO {
105     uint16_t id;
106     uint16_t nr;
107     uint32_t parm;
108     uint32_t word;
109     QLIST_ENTRY(QEMUS390FlicIO) next;
110 } QEMUS390FlicIO;
111 
112 struct QEMUS390FLICState {
113     S390FLICState parent_obj;
114     uint32_t pending;
115     uint32_t service_param;
116     uint8_t simm;
117     uint8_t nimm;
118     QLIST_HEAD(, QEMUS390FlicIO) io[8];
119     bool migrate_all_state;
120 };
121 
122 uint32_t qemu_s390_flic_dequeue_service(QEMUS390FLICState *flic);
123 QEMUS390FlicIO *qemu_s390_flic_dequeue_io(QEMUS390FLICState *flic,
124                                           uint64_t cr6);
125 void qemu_s390_flic_dequeue_crw_mchk(QEMUS390FLICState *flic);
126 bool qemu_s390_flic_has_service(QEMUS390FLICState *flic);
127 bool qemu_s390_flic_has_io(QEMUS390FLICState *fs, uint64_t cr6);
128 bool qemu_s390_flic_has_crw_mchk(QEMUS390FLICState *flic);
129 bool qemu_s390_flic_has_any(QEMUS390FLICState *flic);
130 
131 void s390_flic_init(void);
132 
133 S390FLICState *s390_get_flic(void);
134 QEMUS390FLICState *s390_get_qemu_flic(S390FLICState *fs);
135 S390FLICStateClass *s390_get_flic_class(S390FLICState *fs);
136 void s390_crw_mchk(void);
137 void s390_io_interrupt(uint16_t subchannel_id, uint16_t subchannel_nr,
138                        uint32_t io_int_parm, uint32_t io_int_word);
139 bool ais_needed(void *opaque);
140 
141 #endif /* HW_S390_FLIC_H */
142