2 * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator
4 * PAPR Virtualized Interrupt System, aka ICS/ICP aka xics
6 * Copyright (c) 2010,2011 David Gibson, IBM Corporation.
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31 #include "hw/sysbus.h"
33 #define TYPE_XICS_COMMON "xics-common"
34 #define XICS_COMMON(obj) OBJECT_CHECK(XICSState, (obj), TYPE_XICS_COMMON)
37 * Retain xics as the type name to be compatible for migration. Rest all the
38 * functions, class and variables are renamed as xics_spapr.
40 #define TYPE_XICS_SPAPR "xics"
41 #define XICS_SPAPR(obj) OBJECT_CHECK(XICSState, (obj), TYPE_XICS_SPAPR)
43 #define TYPE_XICS_SPAPR_KVM "xics-spapr-kvm"
44 #define XICS_SPAPR_KVM(obj) \
45 OBJECT_CHECK(KVMXICSState, (obj), TYPE_XICS_SPAPR_KVM)
47 #define XICS_COMMON_CLASS(klass) \
48 OBJECT_CLASS_CHECK(XICSStateClass, (klass), TYPE_XICS_COMMON)
49 #define XICS_SPAPR_CLASS(klass) \
50 OBJECT_CLASS_CHECK(XICSStateClass, (klass), TYPE_XICS_SPAPR)
51 #define XICS_COMMON_GET_CLASS(obj) \
52 OBJECT_GET_CLASS(XICSStateClass, (obj), TYPE_XICS_COMMON)
53 #define XICS_SPAPR_GET_CLASS(obj) \
54 OBJECT_GET_CLASS(XICSStateClass, (obj), TYPE_XICS_SPAPR)
58 #define XICS_IRQ_BASE (XICS_BUID << 12)
61 * We currently only support one BUID which is our interrupt base
62 * (the kernel implementation supports more but we don't exploit
65 typedef struct XICSStateClass XICSStateClass
;
66 typedef struct XICSState XICSState
;
67 typedef struct ICPStateClass ICPStateClass
;
68 typedef struct ICPState ICPState
;
69 typedef struct ICSStateClass ICSStateClass
;
70 typedef struct ICSState ICSState
;
71 typedef struct ICSIRQState ICSIRQState
;
72 typedef struct XICSFabric XICSFabric
;
74 struct XICSStateClass
{
75 DeviceClass parent_class
;
77 void (*cpu_setup
)(XICSState
*icp
, PowerPCCPU
*cpu
);
82 DeviceState parent_obj
;
88 #define TYPE_ICP "icp"
89 #define ICP(obj) OBJECT_CHECK(ICPState, (obj), TYPE_ICP)
91 #define TYPE_KVM_ICP "icp-kvm"
92 #define KVM_ICP(obj) OBJECT_CHECK(ICPState, (obj), TYPE_KVM_ICP)
94 #define ICP_CLASS(klass) \
95 OBJECT_CLASS_CHECK(ICPStateClass, (klass), TYPE_ICP)
96 #define ICP_GET_CLASS(obj) \
97 OBJECT_GET_CLASS(ICPStateClass, (obj), TYPE_ICP)
99 struct ICPStateClass
{
100 DeviceClass parent_class
;
102 void (*pre_save
)(ICPState
*s
);
103 int (*post_load
)(ICPState
*s
, int version_id
);
108 DeviceState parent_obj
;
111 ICSState
*xirr_owner
;
113 uint8_t pending_priority
;
116 bool cap_irq_xics_enabled
;
121 #define TYPE_ICS_BASE "ics-base"
122 #define ICS_BASE(obj) OBJECT_CHECK(ICSState, (obj), TYPE_ICS_BASE)
124 /* Retain ics for sPAPR for migration from existing sPAPR guests */
125 #define TYPE_ICS_SIMPLE "ics"
126 #define ICS_SIMPLE(obj) OBJECT_CHECK(ICSState, (obj), TYPE_ICS_SIMPLE)
128 #define TYPE_ICS_KVM "icskvm"
129 #define ICS_KVM(obj) OBJECT_CHECK(ICSState, (obj), TYPE_ICS_KVM)
131 #define ICS_BASE_CLASS(klass) \
132 OBJECT_CLASS_CHECK(ICSStateClass, (klass), TYPE_ICS_BASE)
133 #define ICS_BASE_GET_CLASS(obj) \
134 OBJECT_GET_CLASS(ICSStateClass, (obj), TYPE_ICS_BASE)
136 struct ICSStateClass
{
137 DeviceClass parent_class
;
139 void (*realize
)(DeviceState
*dev
, Error
**errp
);
140 void (*pre_save
)(ICSState
*s
);
141 int (*post_load
)(ICSState
*s
, int version_id
);
142 void (*reject
)(ICSState
*s
, uint32_t irq
);
143 void (*resend
)(ICSState
*s
);
144 void (*eoi
)(ICSState
*s
, uint32_t irq
);
149 DeviceState parent_obj
;
158 static inline bool ics_valid_irq(ICSState
*ics
, uint32_t nr
)
160 return (ics
->offset
!= 0) && (nr
>= ics
->offset
)
161 && (nr
< (ics
->offset
+ ics
->nr_irqs
));
167 uint8_t saved_priority
;
168 #define XICS_STATUS_ASSERTED 0x1
169 #define XICS_STATUS_SENT 0x2
170 #define XICS_STATUS_REJECTED 0x4
171 #define XICS_STATUS_MASKED_PENDING 0x8
173 /* (flags & XICS_FLAGS_IRQ_MASK) == 0 means the interrupt is not allocated */
174 #define XICS_FLAGS_IRQ_LSI 0x1
175 #define XICS_FLAGS_IRQ_MSI 0x2
176 #define XICS_FLAGS_IRQ_MASK 0x3
180 typedef struct XICSFabric
{
184 #define TYPE_XICS_FABRIC "xics-fabric"
185 #define XICS_FABRIC(obj) \
186 OBJECT_CHECK(XICSFabric, (obj), TYPE_XICS_FABRIC)
187 #define XICS_FABRIC_CLASS(klass) \
188 OBJECT_CLASS_CHECK(XICSFabricClass, (klass), TYPE_XICS_FABRIC)
189 #define XICS_FABRIC_GET_CLASS(obj) \
190 OBJECT_GET_CLASS(XICSFabricClass, (obj), TYPE_XICS_FABRIC)
192 typedef struct XICSFabricClass
{
193 InterfaceClass parent
;
194 ICSState
*(*ics_get
)(XICSFabric
*xi
, int irq
);
195 void (*ics_resend
)(XICSFabric
*xi
);
196 ICPState
*(*icp_get
)(XICSFabric
*xi
, int server
);
197 void (*icp_resend
)(XICSFabric
*xi
);
200 #define XICS_IRQS_SPAPR 1024
202 qemu_irq
xics_get_qirq(XICSFabric
*xi
, int irq
);
204 int spapr_ics_alloc(ICSState
*ics
, int irq_hint
, bool lsi
, Error
**errp
);
205 int spapr_ics_alloc_block(ICSState
*ics
, int num
, bool lsi
, bool align
,
207 void spapr_ics_free(ICSState
*ics
, int irq
, int num
);
208 void spapr_dt_xics(XICSState
*xics
, void *fdt
, uint32_t phandle
);
210 void xics_cpu_setup(XICSState
*icp
, PowerPCCPU
*cpu
);
211 void xics_cpu_destroy(XICSState
*icp
, PowerPCCPU
*cpu
);
213 /* Internal XICS interfaces */
214 int xics_get_cpu_index_by_dt_id(int cpu_dt_id
);
216 void icp_set_cppr(ICPState
*icp
, uint8_t cppr
);
217 void icp_set_mfrr(ICPState
*icp
, uint8_t mfrr
);
218 uint32_t icp_accept(ICPState
*ss
);
219 uint32_t icp_ipoll(ICPState
*ss
, uint32_t *mfrr
);
220 void icp_eoi(ICPState
*icp
, uint32_t xirr
);
222 void ics_simple_write_xive(ICSState
*ics
, int nr
, int server
,
223 uint8_t priority
, uint8_t saved_priority
);
225 void ics_set_irq_type(ICSState
*ics
, int srcno
, bool lsi
);
227 void ics_resend(ICSState
*ics
);
228 void icp_resend(ICPState
*ss
);