xref: /openbmc/qemu/include/hw/s390x/s390_flic.h (revision 083fab02)
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 
20 /*
21  * Reserve enough gsis to accommodate all virtio devices.
22  * If any other user of adapter routes needs more of these,
23  * we need to bump the value; but virtio looks like the
24  * maximum right now.
25  */
26 #define ADAPTER_ROUTES_MAX_GSI VIRTIO_QUEUE_MAX
27 
28 typedef struct AdapterRoutes {
29     AdapterInfo adapter;
30     int num_routes;
31     int gsi[ADAPTER_ROUTES_MAX_GSI];
32 } AdapterRoutes;
33 
34 extern const VMStateDescription vmstate_adapter_routes;
35 
36 #define VMSTATE_ADAPTER_ROUTES(_f, _s) \
37     VMSTATE_STRUCT(_f, _s, 1, vmstate_adapter_routes, AdapterRoutes)
38 
39 #define TYPE_S390_FLIC_COMMON "s390-flic"
40 #define S390_FLIC_COMMON(obj) \
41     OBJECT_CHECK(S390FLICState, (obj), TYPE_S390_FLIC_COMMON)
42 
43 typedef struct S390FLICState {
44     SysBusDevice parent_obj;
45     /* to limit AdapterRoutes.num_routes for compat */
46     uint32_t adapter_routes_max_batch;
47     bool ais_supported;
48 } S390FLICState;
49 
50 #define S390_FLIC_COMMON_CLASS(klass) \
51     OBJECT_CLASS_CHECK(S390FLICStateClass, (klass), TYPE_S390_FLIC_COMMON)
52 #define S390_FLIC_COMMON_GET_CLASS(obj) \
53     OBJECT_GET_CLASS(S390FLICStateClass, (obj), TYPE_S390_FLIC_COMMON)
54 
55 typedef struct S390FLICStateClass {
56     DeviceClass parent_class;
57 
58     int (*register_io_adapter)(S390FLICState *fs, uint32_t id, uint8_t isc,
59                                bool swap, bool maskable, uint8_t flags);
60     int (*io_adapter_map)(S390FLICState *fs, uint32_t id, uint64_t map_addr,
61                           bool do_map);
62     int (*add_adapter_routes)(S390FLICState *fs, AdapterRoutes *routes);
63     void (*release_adapter_routes)(S390FLICState *fs, AdapterRoutes *routes);
64     int (*clear_io_irq)(S390FLICState *fs, uint16_t subchannel_id,
65                         uint16_t subchannel_nr);
66     int (*modify_ais_mode)(S390FLICState *fs, uint8_t isc, uint16_t mode);
67     int (*inject_airq)(S390FLICState *fs, uint8_t type, uint8_t isc,
68                        uint8_t flags);
69 } S390FLICStateClass;
70 
71 #define TYPE_KVM_S390_FLIC "s390-flic-kvm"
72 #define KVM_S390_FLIC(obj) \
73     OBJECT_CHECK(KVMS390FLICState, (obj), TYPE_KVM_S390_FLIC)
74 
75 #define TYPE_QEMU_S390_FLIC "s390-flic-qemu"
76 #define QEMU_S390_FLIC(obj) \
77     OBJECT_CHECK(QEMUS390FLICState, (obj), TYPE_QEMU_S390_FLIC)
78 
79 #define SIC_IRQ_MODE_ALL 0
80 #define SIC_IRQ_MODE_SINGLE 1
81 #define AIS_MODE_MASK(isc) (0x80 >> isc)
82 
83 typedef struct QEMUS390FLICState {
84     S390FLICState parent_obj;
85     uint8_t simm;
86     uint8_t nimm;
87 } QEMUS390FLICState;
88 
89 void s390_flic_init(void);
90 
91 S390FLICState *s390_get_flic(void);
92 bool ais_needed(void *opaque);
93 
94 #ifdef CONFIG_KVM
95 DeviceState *s390_flic_kvm_create(void);
96 #else
97 static inline DeviceState *s390_flic_kvm_create(void)
98 {
99     return NULL;
100 }
101 #endif
102 
103 #endif /* HW_S390_FLIC_H */
104