root / hw / xics.c @ a1bc20df
History | View | Annotate | Download (14.7 kB)
1 | b5cec4c5 | David Gibson | /*
|
---|---|---|---|
2 | b5cec4c5 | David Gibson | * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator
|
3 | b5cec4c5 | David Gibson | *
|
4 | b5cec4c5 | David Gibson | * PAPR Virtualized Interrupt System, aka ICS/ICP aka xics
|
5 | b5cec4c5 | David Gibson | *
|
6 | b5cec4c5 | David Gibson | * Copyright (c) 2010,2011 David Gibson, IBM Corporation.
|
7 | b5cec4c5 | David Gibson | *
|
8 | b5cec4c5 | David Gibson | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 | b5cec4c5 | David Gibson | * of this software and associated documentation files (the "Software"), to deal
|
10 | b5cec4c5 | David Gibson | * in the Software without restriction, including without limitation the rights
|
11 | b5cec4c5 | David Gibson | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12 | b5cec4c5 | David Gibson | * copies of the Software, and to permit persons to whom the Software is
|
13 | b5cec4c5 | David Gibson | * furnished to do so, subject to the following conditions:
|
14 | b5cec4c5 | David Gibson | *
|
15 | b5cec4c5 | David Gibson | * The above copyright notice and this permission notice shall be included in
|
16 | b5cec4c5 | David Gibson | * all copies or substantial portions of the Software.
|
17 | b5cec4c5 | David Gibson | *
|
18 | b5cec4c5 | David Gibson | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19 | b5cec4c5 | David Gibson | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20 | b5cec4c5 | David Gibson | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
21 | b5cec4c5 | David Gibson | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22 | b5cec4c5 | David Gibson | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23 | b5cec4c5 | David Gibson | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24 | b5cec4c5 | David Gibson | * THE SOFTWARE.
|
25 | b5cec4c5 | David Gibson | *
|
26 | b5cec4c5 | David Gibson | */
|
27 | b5cec4c5 | David Gibson | |
28 | b5cec4c5 | David Gibson | #include "hw.h" |
29 | b5cec4c5 | David Gibson | #include "hw/spapr.h" |
30 | b5cec4c5 | David Gibson | #include "hw/xics.h" |
31 | b5cec4c5 | David Gibson | |
32 | b5cec4c5 | David Gibson | /*
|
33 | b5cec4c5 | David Gibson | * ICP: Presentation layer
|
34 | b5cec4c5 | David Gibson | */
|
35 | b5cec4c5 | David Gibson | |
36 | b5cec4c5 | David Gibson | struct icp_server_state {
|
37 | b5cec4c5 | David Gibson | uint32_t xirr; |
38 | b5cec4c5 | David Gibson | uint8_t pending_priority; |
39 | b5cec4c5 | David Gibson | uint8_t mfrr; |
40 | b5cec4c5 | David Gibson | qemu_irq output; |
41 | b5cec4c5 | David Gibson | }; |
42 | b5cec4c5 | David Gibson | |
43 | b5cec4c5 | David Gibson | #define XISR_MASK 0x00ffffff |
44 | b5cec4c5 | David Gibson | #define CPPR_MASK 0xff000000 |
45 | b5cec4c5 | David Gibson | |
46 | b5cec4c5 | David Gibson | #define XISR(ss) (((ss)->xirr) & XISR_MASK)
|
47 | b5cec4c5 | David Gibson | #define CPPR(ss) (((ss)->xirr) >> 24) |
48 | b5cec4c5 | David Gibson | |
49 | b5cec4c5 | David Gibson | struct ics_state;
|
50 | b5cec4c5 | David Gibson | |
51 | b5cec4c5 | David Gibson | struct icp_state {
|
52 | b5cec4c5 | David Gibson | long nr_servers;
|
53 | b5cec4c5 | David Gibson | struct icp_server_state *ss;
|
54 | b5cec4c5 | David Gibson | struct ics_state *ics;
|
55 | b5cec4c5 | David Gibson | }; |
56 | b5cec4c5 | David Gibson | |
57 | b5cec4c5 | David Gibson | static void ics_reject(struct ics_state *ics, int nr); |
58 | b5cec4c5 | David Gibson | static void ics_resend(struct ics_state *ics); |
59 | b5cec4c5 | David Gibson | static void ics_eoi(struct ics_state *ics, int nr); |
60 | b5cec4c5 | David Gibson | |
61 | b5cec4c5 | David Gibson | static void icp_check_ipi(struct icp_state *icp, int server) |
62 | b5cec4c5 | David Gibson | { |
63 | b5cec4c5 | David Gibson | struct icp_server_state *ss = icp->ss + server;
|
64 | b5cec4c5 | David Gibson | |
65 | b5cec4c5 | David Gibson | if (XISR(ss) && (ss->pending_priority <= ss->mfrr)) {
|
66 | b5cec4c5 | David Gibson | return;
|
67 | b5cec4c5 | David Gibson | } |
68 | b5cec4c5 | David Gibson | |
69 | b5cec4c5 | David Gibson | if (XISR(ss)) {
|
70 | b5cec4c5 | David Gibson | ics_reject(icp->ics, XISR(ss)); |
71 | b5cec4c5 | David Gibson | } |
72 | b5cec4c5 | David Gibson | |
73 | b5cec4c5 | David Gibson | ss->xirr = (ss->xirr & ~XISR_MASK) | XICS_IPI; |
74 | b5cec4c5 | David Gibson | ss->pending_priority = ss->mfrr; |
75 | b5cec4c5 | David Gibson | qemu_irq_raise(ss->output); |
76 | b5cec4c5 | David Gibson | } |
77 | b5cec4c5 | David Gibson | |
78 | b5cec4c5 | David Gibson | static void icp_resend(struct icp_state *icp, int server) |
79 | b5cec4c5 | David Gibson | { |
80 | b5cec4c5 | David Gibson | struct icp_server_state *ss = icp->ss + server;
|
81 | b5cec4c5 | David Gibson | |
82 | b5cec4c5 | David Gibson | if (ss->mfrr < CPPR(ss)) {
|
83 | b5cec4c5 | David Gibson | icp_check_ipi(icp, server); |
84 | b5cec4c5 | David Gibson | } |
85 | b5cec4c5 | David Gibson | ics_resend(icp->ics); |
86 | b5cec4c5 | David Gibson | } |
87 | b5cec4c5 | David Gibson | |
88 | b5cec4c5 | David Gibson | static void icp_set_cppr(struct icp_state *icp, int server, uint8_t cppr) |
89 | b5cec4c5 | David Gibson | { |
90 | b5cec4c5 | David Gibson | struct icp_server_state *ss = icp->ss + server;
|
91 | b5cec4c5 | David Gibson | uint8_t old_cppr; |
92 | b5cec4c5 | David Gibson | uint32_t old_xisr; |
93 | b5cec4c5 | David Gibson | |
94 | b5cec4c5 | David Gibson | old_cppr = CPPR(ss); |
95 | b5cec4c5 | David Gibson | ss->xirr = (ss->xirr & ~CPPR_MASK) | (cppr << 24);
|
96 | b5cec4c5 | David Gibson | |
97 | b5cec4c5 | David Gibson | if (cppr < old_cppr) {
|
98 | b5cec4c5 | David Gibson | if (XISR(ss) && (cppr <= ss->pending_priority)) {
|
99 | b5cec4c5 | David Gibson | old_xisr = XISR(ss); |
100 | b5cec4c5 | David Gibson | ss->xirr &= ~XISR_MASK; /* Clear XISR */
|
101 | b5cec4c5 | David Gibson | qemu_irq_lower(ss->output); |
102 | b5cec4c5 | David Gibson | ics_reject(icp->ics, old_xisr); |
103 | b5cec4c5 | David Gibson | } |
104 | b5cec4c5 | David Gibson | } else {
|
105 | b5cec4c5 | David Gibson | if (!XISR(ss)) {
|
106 | b5cec4c5 | David Gibson | icp_resend(icp, server); |
107 | b5cec4c5 | David Gibson | } |
108 | b5cec4c5 | David Gibson | } |
109 | b5cec4c5 | David Gibson | } |
110 | b5cec4c5 | David Gibson | |
111 | b5cec4c5 | David Gibson | static void icp_set_mfrr(struct icp_state *icp, int nr, uint8_t mfrr) |
112 | b5cec4c5 | David Gibson | { |
113 | b5cec4c5 | David Gibson | struct icp_server_state *ss = icp->ss + nr;
|
114 | b5cec4c5 | David Gibson | |
115 | b5cec4c5 | David Gibson | ss->mfrr = mfrr; |
116 | b5cec4c5 | David Gibson | if (mfrr < CPPR(ss)) {
|
117 | b5cec4c5 | David Gibson | icp_check_ipi(icp, nr); |
118 | b5cec4c5 | David Gibson | } |
119 | b5cec4c5 | David Gibson | } |
120 | b5cec4c5 | David Gibson | |
121 | b5cec4c5 | David Gibson | static uint32_t icp_accept(struct icp_server_state *ss) |
122 | b5cec4c5 | David Gibson | { |
123 | b5cec4c5 | David Gibson | uint32_t xirr; |
124 | b5cec4c5 | David Gibson | |
125 | b5cec4c5 | David Gibson | qemu_irq_lower(ss->output); |
126 | b5cec4c5 | David Gibson | xirr = ss->xirr; |
127 | b5cec4c5 | David Gibson | ss->xirr = ss->pending_priority << 24;
|
128 | b5cec4c5 | David Gibson | return xirr;
|
129 | b5cec4c5 | David Gibson | } |
130 | b5cec4c5 | David Gibson | |
131 | b5cec4c5 | David Gibson | static void icp_eoi(struct icp_state *icp, int server, uint32_t xirr) |
132 | b5cec4c5 | David Gibson | { |
133 | b5cec4c5 | David Gibson | struct icp_server_state *ss = icp->ss + server;
|
134 | b5cec4c5 | David Gibson | |
135 | b5cec4c5 | David Gibson | /* Send EOI -> ICS */
|
136 | b5cec4c5 | David Gibson | ss->xirr = (ss->xirr & ~CPPR_MASK) | (xirr & CPPR_MASK); |
137 | d07fee7e | David Gibson | ics_eoi(icp->ics, xirr & XISR_MASK); |
138 | b5cec4c5 | David Gibson | if (!XISR(ss)) {
|
139 | b5cec4c5 | David Gibson | icp_resend(icp, server); |
140 | b5cec4c5 | David Gibson | } |
141 | b5cec4c5 | David Gibson | } |
142 | b5cec4c5 | David Gibson | |
143 | b5cec4c5 | David Gibson | static void icp_irq(struct icp_state *icp, int server, int nr, uint8_t priority) |
144 | b5cec4c5 | David Gibson | { |
145 | b5cec4c5 | David Gibson | struct icp_server_state *ss = icp->ss + server;
|
146 | b5cec4c5 | David Gibson | |
147 | b5cec4c5 | David Gibson | if ((priority >= CPPR(ss))
|
148 | b5cec4c5 | David Gibson | || (XISR(ss) && (ss->pending_priority <= priority))) { |
149 | b5cec4c5 | David Gibson | ics_reject(icp->ics, nr); |
150 | b5cec4c5 | David Gibson | } else {
|
151 | b5cec4c5 | David Gibson | if (XISR(ss)) {
|
152 | b5cec4c5 | David Gibson | ics_reject(icp->ics, XISR(ss)); |
153 | b5cec4c5 | David Gibson | } |
154 | b5cec4c5 | David Gibson | ss->xirr = (ss->xirr & ~XISR_MASK) | (nr & XISR_MASK); |
155 | b5cec4c5 | David Gibson | ss->pending_priority = priority; |
156 | b5cec4c5 | David Gibson | qemu_irq_raise(ss->output); |
157 | b5cec4c5 | David Gibson | } |
158 | b5cec4c5 | David Gibson | } |
159 | b5cec4c5 | David Gibson | |
160 | b5cec4c5 | David Gibson | /*
|
161 | b5cec4c5 | David Gibson | * ICS: Source layer
|
162 | b5cec4c5 | David Gibson | */
|
163 | b5cec4c5 | David Gibson | |
164 | b5cec4c5 | David Gibson | struct ics_irq_state {
|
165 | b5cec4c5 | David Gibson | int server;
|
166 | b5cec4c5 | David Gibson | uint8_t priority; |
167 | b5cec4c5 | David Gibson | uint8_t saved_priority; |
168 | 98ca8c02 | David Gibson | #define XICS_STATUS_ASSERTED 0x1 |
169 | 98ca8c02 | David Gibson | #define XICS_STATUS_SENT 0x2 |
170 | 98ca8c02 | David Gibson | #define XICS_STATUS_REJECTED 0x4 |
171 | 98ca8c02 | David Gibson | #define XICS_STATUS_MASKED_PENDING 0x8 |
172 | 98ca8c02 | David Gibson | uint8_t status; |
173 | ff9d2afa | David Gibson | bool lsi;
|
174 | b5cec4c5 | David Gibson | }; |
175 | b5cec4c5 | David Gibson | |
176 | b5cec4c5 | David Gibson | struct ics_state {
|
177 | b5cec4c5 | David Gibson | int nr_irqs;
|
178 | b5cec4c5 | David Gibson | int offset;
|
179 | b5cec4c5 | David Gibson | qemu_irq *qirqs; |
180 | b5cec4c5 | David Gibson | struct ics_irq_state *irqs;
|
181 | b5cec4c5 | David Gibson | struct icp_state *icp;
|
182 | b5cec4c5 | David Gibson | }; |
183 | b5cec4c5 | David Gibson | |
184 | b5cec4c5 | David Gibson | static int ics_valid_irq(struct ics_state *ics, uint32_t nr) |
185 | b5cec4c5 | David Gibson | { |
186 | b5cec4c5 | David Gibson | return (nr >= ics->offset)
|
187 | b5cec4c5 | David Gibson | && (nr < (ics->offset + ics->nr_irqs)); |
188 | b5cec4c5 | David Gibson | } |
189 | b5cec4c5 | David Gibson | |
190 | d07fee7e | David Gibson | static void resend_msi(struct ics_state *ics, int srcno) |
191 | d07fee7e | David Gibson | { |
192 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
193 | d07fee7e | David Gibson | |
194 | d07fee7e | David Gibson | /* FIXME: filter by server#? */
|
195 | 98ca8c02 | David Gibson | if (irq->status & XICS_STATUS_REJECTED) {
|
196 | 98ca8c02 | David Gibson | irq->status &= ~XICS_STATUS_REJECTED; |
197 | d07fee7e | David Gibson | if (irq->priority != 0xff) { |
198 | d07fee7e | David Gibson | icp_irq(ics->icp, irq->server, srcno + ics->offset, |
199 | d07fee7e | David Gibson | irq->priority); |
200 | d07fee7e | David Gibson | } |
201 | d07fee7e | David Gibson | } |
202 | d07fee7e | David Gibson | } |
203 | d07fee7e | David Gibson | |
204 | d07fee7e | David Gibson | static void resend_lsi(struct ics_state *ics, int srcno) |
205 | d07fee7e | David Gibson | { |
206 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
207 | d07fee7e | David Gibson | |
208 | 98ca8c02 | David Gibson | if ((irq->priority != 0xff) |
209 | 98ca8c02 | David Gibson | && (irq->status & XICS_STATUS_ASSERTED) |
210 | 98ca8c02 | David Gibson | && !(irq->status & XICS_STATUS_SENT)) { |
211 | 98ca8c02 | David Gibson | irq->status |= XICS_STATUS_SENT; |
212 | d07fee7e | David Gibson | icp_irq(ics->icp, irq->server, srcno + ics->offset, irq->priority); |
213 | d07fee7e | David Gibson | } |
214 | d07fee7e | David Gibson | } |
215 | d07fee7e | David Gibson | |
216 | d07fee7e | David Gibson | static void set_irq_msi(struct ics_state *ics, int srcno, int val) |
217 | b5cec4c5 | David Gibson | { |
218 | cc67b9c8 | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
219 | b5cec4c5 | David Gibson | |
220 | b5cec4c5 | David Gibson | if (val) {
|
221 | b5cec4c5 | David Gibson | if (irq->priority == 0xff) { |
222 | 98ca8c02 | David Gibson | irq->status |= XICS_STATUS_MASKED_PENDING; |
223 | b5cec4c5 | David Gibson | /* masked pending */ ;
|
224 | b5cec4c5 | David Gibson | } else {
|
225 | cc67b9c8 | David Gibson | icp_irq(ics->icp, irq->server, srcno + ics->offset, irq->priority); |
226 | b5cec4c5 | David Gibson | } |
227 | b5cec4c5 | David Gibson | } |
228 | b5cec4c5 | David Gibson | } |
229 | b5cec4c5 | David Gibson | |
230 | d07fee7e | David Gibson | static void set_irq_lsi(struct ics_state *ics, int srcno, int val) |
231 | b5cec4c5 | David Gibson | { |
232 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
233 | b5cec4c5 | David Gibson | |
234 | 98ca8c02 | David Gibson | if (val) {
|
235 | 98ca8c02 | David Gibson | irq->status |= XICS_STATUS_ASSERTED; |
236 | 98ca8c02 | David Gibson | } else {
|
237 | 98ca8c02 | David Gibson | irq->status &= ~XICS_STATUS_ASSERTED; |
238 | 98ca8c02 | David Gibson | } |
239 | d07fee7e | David Gibson | resend_lsi(ics, srcno); |
240 | b5cec4c5 | David Gibson | } |
241 | b5cec4c5 | David Gibson | |
242 | d07fee7e | David Gibson | static void ics_set_irq(void *opaque, int srcno, int val) |
243 | b5cec4c5 | David Gibson | { |
244 | d07fee7e | David Gibson | struct ics_state *ics = (struct ics_state *)opaque; |
245 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
246 | b5cec4c5 | David Gibson | |
247 | ff9d2afa | David Gibson | if (irq->lsi) {
|
248 | d07fee7e | David Gibson | set_irq_lsi(ics, srcno, val); |
249 | d07fee7e | David Gibson | } else {
|
250 | d07fee7e | David Gibson | set_irq_msi(ics, srcno, val); |
251 | d07fee7e | David Gibson | } |
252 | d07fee7e | David Gibson | } |
253 | b5cec4c5 | David Gibson | |
254 | d07fee7e | David Gibson | static void write_xive_msi(struct ics_state *ics, int srcno) |
255 | d07fee7e | David Gibson | { |
256 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
257 | d07fee7e | David Gibson | |
258 | 98ca8c02 | David Gibson | if (!(irq->status & XICS_STATUS_MASKED_PENDING)
|
259 | 98ca8c02 | David Gibson | || (irq->priority == 0xff)) {
|
260 | d07fee7e | David Gibson | return;
|
261 | b5cec4c5 | David Gibson | } |
262 | d07fee7e | David Gibson | |
263 | 98ca8c02 | David Gibson | irq->status &= ~XICS_STATUS_MASKED_PENDING; |
264 | d07fee7e | David Gibson | icp_irq(ics->icp, irq->server, srcno + ics->offset, irq->priority); |
265 | b5cec4c5 | David Gibson | } |
266 | b5cec4c5 | David Gibson | |
267 | d07fee7e | David Gibson | static void write_xive_lsi(struct ics_state *ics, int srcno) |
268 | b5cec4c5 | David Gibson | { |
269 | d07fee7e | David Gibson | resend_lsi(ics, srcno); |
270 | d07fee7e | David Gibson | } |
271 | d07fee7e | David Gibson | |
272 | d07fee7e | David Gibson | static void ics_write_xive(struct ics_state *ics, int nr, int server, |
273 | 3fe719f4 | David Gibson | uint8_t priority, uint8_t saved_priority) |
274 | d07fee7e | David Gibson | { |
275 | d07fee7e | David Gibson | int srcno = nr - ics->offset;
|
276 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
277 | b5cec4c5 | David Gibson | |
278 | b5cec4c5 | David Gibson | irq->server = server; |
279 | b5cec4c5 | David Gibson | irq->priority = priority; |
280 | 3fe719f4 | David Gibson | irq->saved_priority = saved_priority; |
281 | b5cec4c5 | David Gibson | |
282 | ff9d2afa | David Gibson | if (irq->lsi) {
|
283 | d07fee7e | David Gibson | write_xive_lsi(ics, srcno); |
284 | d07fee7e | David Gibson | } else {
|
285 | d07fee7e | David Gibson | write_xive_msi(ics, srcno); |
286 | b5cec4c5 | David Gibson | } |
287 | b5cec4c5 | David Gibson | } |
288 | b5cec4c5 | David Gibson | |
289 | b5cec4c5 | David Gibson | static void ics_reject(struct ics_state *ics, int nr) |
290 | b5cec4c5 | David Gibson | { |
291 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + nr - ics->offset;
|
292 | d07fee7e | David Gibson | |
293 | 98ca8c02 | David Gibson | irq->status |= XICS_STATUS_REJECTED; /* Irrelevant but harmless for LSI */
|
294 | 98ca8c02 | David Gibson | irq->status &= ~XICS_STATUS_SENT; /* Irrelevant but harmless for MSI */
|
295 | b5cec4c5 | David Gibson | } |
296 | b5cec4c5 | David Gibson | |
297 | b5cec4c5 | David Gibson | static void ics_resend(struct ics_state *ics) |
298 | b5cec4c5 | David Gibson | { |
299 | d07fee7e | David Gibson | int i;
|
300 | d07fee7e | David Gibson | |
301 | d07fee7e | David Gibson | for (i = 0; i < ics->nr_irqs; i++) { |
302 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + i;
|
303 | d07fee7e | David Gibson | |
304 | d07fee7e | David Gibson | /* FIXME: filter by server#? */
|
305 | ff9d2afa | David Gibson | if (irq->lsi) {
|
306 | d07fee7e | David Gibson | resend_lsi(ics, i); |
307 | d07fee7e | David Gibson | } else {
|
308 | d07fee7e | David Gibson | resend_msi(ics, i); |
309 | d07fee7e | David Gibson | } |
310 | d07fee7e | David Gibson | } |
311 | b5cec4c5 | David Gibson | } |
312 | b5cec4c5 | David Gibson | |
313 | b5cec4c5 | David Gibson | static void ics_eoi(struct ics_state *ics, int nr) |
314 | b5cec4c5 | David Gibson | { |
315 | d07fee7e | David Gibson | int srcno = nr - ics->offset;
|
316 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
317 | d07fee7e | David Gibson | |
318 | ff9d2afa | David Gibson | if (irq->lsi) {
|
319 | 98ca8c02 | David Gibson | irq->status &= ~XICS_STATUS_SENT; |
320 | d07fee7e | David Gibson | } |
321 | b5cec4c5 | David Gibson | } |
322 | b5cec4c5 | David Gibson | |
323 | b5cec4c5 | David Gibson | /*
|
324 | b5cec4c5 | David Gibson | * Exported functions
|
325 | b5cec4c5 | David Gibson | */
|
326 | b5cec4c5 | David Gibson | |
327 | a307d594 | Alexey Kardashevskiy | qemu_irq xics_get_qirq(struct icp_state *icp, int irq) |
328 | b5cec4c5 | David Gibson | { |
329 | b5cec4c5 | David Gibson | if ((irq < icp->ics->offset)
|
330 | b5cec4c5 | David Gibson | || (irq >= (icp->ics->offset + icp->ics->nr_irqs))) { |
331 | b5cec4c5 | David Gibson | return NULL; |
332 | b5cec4c5 | David Gibson | } |
333 | b5cec4c5 | David Gibson | |
334 | a307d594 | Alexey Kardashevskiy | return icp->ics->qirqs[irq - icp->ics->offset];
|
335 | a307d594 | Alexey Kardashevskiy | } |
336 | a307d594 | Alexey Kardashevskiy | |
337 | ff9d2afa | David Gibson | void xics_set_irq_type(struct icp_state *icp, int irq, bool lsi) |
338 | a307d594 | Alexey Kardashevskiy | { |
339 | a307d594 | Alexey Kardashevskiy | assert((irq >= icp->ics->offset) |
340 | a307d594 | Alexey Kardashevskiy | && (irq < (icp->ics->offset + icp->ics->nr_irqs))); |
341 | d07fee7e | David Gibson | |
342 | ff9d2afa | David Gibson | icp->ics->irqs[irq - icp->ics->offset].lsi = lsi; |
343 | b5cec4c5 | David Gibson | } |
344 | b5cec4c5 | David Gibson | |
345 | e2684c0b | Andreas Färber | static target_ulong h_cppr(CPUPPCState *env, sPAPREnvironment *spapr,
|
346 | b5cec4c5 | David Gibson | target_ulong opcode, target_ulong *args) |
347 | b5cec4c5 | David Gibson | { |
348 | b5cec4c5 | David Gibson | target_ulong cppr = args[0];
|
349 | b5cec4c5 | David Gibson | |
350 | b5cec4c5 | David Gibson | icp_set_cppr(spapr->icp, env->cpu_index, cppr); |
351 | b5cec4c5 | David Gibson | return H_SUCCESS;
|
352 | b5cec4c5 | David Gibson | } |
353 | b5cec4c5 | David Gibson | |
354 | e2684c0b | Andreas Färber | static target_ulong h_ipi(CPUPPCState *env, sPAPREnvironment *spapr,
|
355 | b5cec4c5 | David Gibson | target_ulong opcode, target_ulong *args) |
356 | b5cec4c5 | David Gibson | { |
357 | b5cec4c5 | David Gibson | target_ulong server = args[0];
|
358 | b5cec4c5 | David Gibson | target_ulong mfrr = args[1];
|
359 | b5cec4c5 | David Gibson | |
360 | b5cec4c5 | David Gibson | if (server >= spapr->icp->nr_servers) {
|
361 | b5cec4c5 | David Gibson | return H_PARAMETER;
|
362 | b5cec4c5 | David Gibson | } |
363 | b5cec4c5 | David Gibson | |
364 | b5cec4c5 | David Gibson | icp_set_mfrr(spapr->icp, server, mfrr); |
365 | b5cec4c5 | David Gibson | return H_SUCCESS;
|
366 | b5cec4c5 | David Gibson | |
367 | b5cec4c5 | David Gibson | } |
368 | b5cec4c5 | David Gibson | |
369 | e2684c0b | Andreas Färber | static target_ulong h_xirr(CPUPPCState *env, sPAPREnvironment *spapr,
|
370 | b5cec4c5 | David Gibson | target_ulong opcode, target_ulong *args) |
371 | b5cec4c5 | David Gibson | { |
372 | b5cec4c5 | David Gibson | uint32_t xirr = icp_accept(spapr->icp->ss + env->cpu_index); |
373 | b5cec4c5 | David Gibson | |
374 | b5cec4c5 | David Gibson | args[0] = xirr;
|
375 | b5cec4c5 | David Gibson | return H_SUCCESS;
|
376 | b5cec4c5 | David Gibson | } |
377 | b5cec4c5 | David Gibson | |
378 | e2684c0b | Andreas Färber | static target_ulong h_eoi(CPUPPCState *env, sPAPREnvironment *spapr,
|
379 | b5cec4c5 | David Gibson | target_ulong opcode, target_ulong *args) |
380 | b5cec4c5 | David Gibson | { |
381 | b5cec4c5 | David Gibson | target_ulong xirr = args[0];
|
382 | b5cec4c5 | David Gibson | |
383 | b5cec4c5 | David Gibson | icp_eoi(spapr->icp, env->cpu_index, xirr); |
384 | b5cec4c5 | David Gibson | return H_SUCCESS;
|
385 | b5cec4c5 | David Gibson | } |
386 | b5cec4c5 | David Gibson | |
387 | b5cec4c5 | David Gibson | static void rtas_set_xive(sPAPREnvironment *spapr, uint32_t token, |
388 | b5cec4c5 | David Gibson | uint32_t nargs, target_ulong args, |
389 | b5cec4c5 | David Gibson | uint32_t nret, target_ulong rets) |
390 | b5cec4c5 | David Gibson | { |
391 | b5cec4c5 | David Gibson | struct ics_state *ics = spapr->icp->ics;
|
392 | b5cec4c5 | David Gibson | uint32_t nr, server, priority; |
393 | b5cec4c5 | David Gibson | |
394 | b5cec4c5 | David Gibson | if ((nargs != 3) || (nret != 1)) { |
395 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
396 | b5cec4c5 | David Gibson | return;
|
397 | b5cec4c5 | David Gibson | } |
398 | b5cec4c5 | David Gibson | |
399 | b5cec4c5 | David Gibson | nr = rtas_ld(args, 0);
|
400 | b5cec4c5 | David Gibson | server = rtas_ld(args, 1);
|
401 | b5cec4c5 | David Gibson | priority = rtas_ld(args, 2);
|
402 | b5cec4c5 | David Gibson | |
403 | b5cec4c5 | David Gibson | if (!ics_valid_irq(ics, nr) || (server >= ics->icp->nr_servers)
|
404 | b5cec4c5 | David Gibson | || (priority > 0xff)) {
|
405 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
406 | b5cec4c5 | David Gibson | return;
|
407 | b5cec4c5 | David Gibson | } |
408 | b5cec4c5 | David Gibson | |
409 | 3fe719f4 | David Gibson | ics_write_xive(ics, nr, server, priority, priority); |
410 | b5cec4c5 | David Gibson | |
411 | b5cec4c5 | David Gibson | rtas_st(rets, 0, 0); /* Success */ |
412 | b5cec4c5 | David Gibson | } |
413 | b5cec4c5 | David Gibson | |
414 | b5cec4c5 | David Gibson | static void rtas_get_xive(sPAPREnvironment *spapr, uint32_t token, |
415 | b5cec4c5 | David Gibson | uint32_t nargs, target_ulong args, |
416 | b5cec4c5 | David Gibson | uint32_t nret, target_ulong rets) |
417 | b5cec4c5 | David Gibson | { |
418 | b5cec4c5 | David Gibson | struct ics_state *ics = spapr->icp->ics;
|
419 | b5cec4c5 | David Gibson | uint32_t nr; |
420 | b5cec4c5 | David Gibson | |
421 | b5cec4c5 | David Gibson | if ((nargs != 1) || (nret != 3)) { |
422 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
423 | b5cec4c5 | David Gibson | return;
|
424 | b5cec4c5 | David Gibson | } |
425 | b5cec4c5 | David Gibson | |
426 | b5cec4c5 | David Gibson | nr = rtas_ld(args, 0);
|
427 | b5cec4c5 | David Gibson | |
428 | b5cec4c5 | David Gibson | if (!ics_valid_irq(ics, nr)) {
|
429 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
430 | b5cec4c5 | David Gibson | return;
|
431 | b5cec4c5 | David Gibson | } |
432 | b5cec4c5 | David Gibson | |
433 | b5cec4c5 | David Gibson | rtas_st(rets, 0, 0); /* Success */ |
434 | b5cec4c5 | David Gibson | rtas_st(rets, 1, ics->irqs[nr - ics->offset].server);
|
435 | b5cec4c5 | David Gibson | rtas_st(rets, 2, ics->irqs[nr - ics->offset].priority);
|
436 | b5cec4c5 | David Gibson | } |
437 | b5cec4c5 | David Gibson | |
438 | b5cec4c5 | David Gibson | static void rtas_int_off(sPAPREnvironment *spapr, uint32_t token, |
439 | b5cec4c5 | David Gibson | uint32_t nargs, target_ulong args, |
440 | b5cec4c5 | David Gibson | uint32_t nret, target_ulong rets) |
441 | b5cec4c5 | David Gibson | { |
442 | b5cec4c5 | David Gibson | struct ics_state *ics = spapr->icp->ics;
|
443 | b5cec4c5 | David Gibson | uint32_t nr; |
444 | b5cec4c5 | David Gibson | |
445 | b5cec4c5 | David Gibson | if ((nargs != 1) || (nret != 1)) { |
446 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
447 | b5cec4c5 | David Gibson | return;
|
448 | b5cec4c5 | David Gibson | } |
449 | b5cec4c5 | David Gibson | |
450 | b5cec4c5 | David Gibson | nr = rtas_ld(args, 0);
|
451 | b5cec4c5 | David Gibson | |
452 | b5cec4c5 | David Gibson | if (!ics_valid_irq(ics, nr)) {
|
453 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
454 | b5cec4c5 | David Gibson | return;
|
455 | b5cec4c5 | David Gibson | } |
456 | b5cec4c5 | David Gibson | |
457 | 3fe719f4 | David Gibson | ics_write_xive(ics, nr, ics->irqs[nr - ics->offset].server, 0xff,
|
458 | 3fe719f4 | David Gibson | ics->irqs[nr - ics->offset].priority); |
459 | b5cec4c5 | David Gibson | |
460 | b5cec4c5 | David Gibson | rtas_st(rets, 0, 0); /* Success */ |
461 | b5cec4c5 | David Gibson | } |
462 | b5cec4c5 | David Gibson | |
463 | b5cec4c5 | David Gibson | static void rtas_int_on(sPAPREnvironment *spapr, uint32_t token, |
464 | b5cec4c5 | David Gibson | uint32_t nargs, target_ulong args, |
465 | b5cec4c5 | David Gibson | uint32_t nret, target_ulong rets) |
466 | b5cec4c5 | David Gibson | { |
467 | b5cec4c5 | David Gibson | struct ics_state *ics = spapr->icp->ics;
|
468 | b5cec4c5 | David Gibson | uint32_t nr; |
469 | b5cec4c5 | David Gibson | |
470 | b5cec4c5 | David Gibson | if ((nargs != 1) || (nret != 1)) { |
471 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
472 | b5cec4c5 | David Gibson | return;
|
473 | b5cec4c5 | David Gibson | } |
474 | b5cec4c5 | David Gibson | |
475 | b5cec4c5 | David Gibson | nr = rtas_ld(args, 0);
|
476 | b5cec4c5 | David Gibson | |
477 | b5cec4c5 | David Gibson | if (!ics_valid_irq(ics, nr)) {
|
478 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
479 | b5cec4c5 | David Gibson | return;
|
480 | b5cec4c5 | David Gibson | } |
481 | b5cec4c5 | David Gibson | |
482 | 3fe719f4 | David Gibson | ics_write_xive(ics, nr, ics->irqs[nr - ics->offset].server, |
483 | 3fe719f4 | David Gibson | ics->irqs[nr - ics->offset].saved_priority, |
484 | 3fe719f4 | David Gibson | ics->irqs[nr - ics->offset].saved_priority); |
485 | b5cec4c5 | David Gibson | |
486 | b5cec4c5 | David Gibson | rtas_st(rets, 0, 0); /* Success */ |
487 | b5cec4c5 | David Gibson | } |
488 | b5cec4c5 | David Gibson | |
489 | 256b408a | David Gibson | static void xics_reset(void *opaque) |
490 | 256b408a | David Gibson | { |
491 | 256b408a | David Gibson | struct icp_state *icp = (struct icp_state *)opaque; |
492 | 256b408a | David Gibson | struct ics_state *ics = icp->ics;
|
493 | 256b408a | David Gibson | int i;
|
494 | 256b408a | David Gibson | |
495 | 256b408a | David Gibson | for (i = 0; i < icp->nr_servers; i++) { |
496 | 256b408a | David Gibson | icp->ss[i].xirr = 0;
|
497 | 256b408a | David Gibson | icp->ss[i].pending_priority = 0;
|
498 | 256b408a | David Gibson | icp->ss[i].mfrr = 0xff;
|
499 | 256b408a | David Gibson | /* Make all outputs are deasserted */
|
500 | 256b408a | David Gibson | qemu_set_irq(icp->ss[i].output, 0);
|
501 | 256b408a | David Gibson | } |
502 | 256b408a | David Gibson | |
503 | 256b408a | David Gibson | for (i = 0; i < ics->nr_irqs; i++) { |
504 | 256b408a | David Gibson | /* Reset everything *except* the type */
|
505 | 256b408a | David Gibson | ics->irqs[i].server = 0;
|
506 | 98ca8c02 | David Gibson | ics->irqs[i].status = 0;
|
507 | 256b408a | David Gibson | ics->irqs[i].priority = 0xff;
|
508 | 256b408a | David Gibson | ics->irqs[i].saved_priority = 0xff;
|
509 | 256b408a | David Gibson | } |
510 | 256b408a | David Gibson | } |
511 | 256b408a | David Gibson | |
512 | c7a5c0c9 | David Gibson | struct icp_state *xics_system_init(int nr_irqs) |
513 | b5cec4c5 | David Gibson | { |
514 | e2684c0b | Andreas Färber | CPUPPCState *env; |
515 | c7a5c0c9 | David Gibson | int max_server_num;
|
516 | b5cec4c5 | David Gibson | struct icp_state *icp;
|
517 | b5cec4c5 | David Gibson | struct ics_state *ics;
|
518 | b5cec4c5 | David Gibson | |
519 | c7a5c0c9 | David Gibson | max_server_num = -1;
|
520 | c7a5c0c9 | David Gibson | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
521 | c7a5c0c9 | David Gibson | if (env->cpu_index > max_server_num) {
|
522 | c7a5c0c9 | David Gibson | max_server_num = env->cpu_index; |
523 | c7a5c0c9 | David Gibson | } |
524 | c7a5c0c9 | David Gibson | } |
525 | c7a5c0c9 | David Gibson | |
526 | 7267c094 | Anthony Liguori | icp = g_malloc0(sizeof(*icp));
|
527 | c7a5c0c9 | David Gibson | icp->nr_servers = max_server_num + 1;
|
528 | 7267c094 | Anthony Liguori | icp->ss = g_malloc0(icp->nr_servers*sizeof(struct icp_server_state)); |
529 | c7a5c0c9 | David Gibson | |
530 | c7a5c0c9 | David Gibson | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
531 | c7a5c0c9 | David Gibson | struct icp_server_state *ss = &icp->ss[env->cpu_index];
|
532 | b5cec4c5 | David Gibson | |
533 | c7a5c0c9 | David Gibson | switch (PPC_INPUT(env)) {
|
534 | b5cec4c5 | David Gibson | case PPC_FLAGS_INPUT_POWER7:
|
535 | c7a5c0c9 | David Gibson | ss->output = env->irq_inputs[POWER7_INPUT_INT]; |
536 | b5cec4c5 | David Gibson | break;
|
537 | b5cec4c5 | David Gibson | |
538 | b5cec4c5 | David Gibson | case PPC_FLAGS_INPUT_970:
|
539 | c7a5c0c9 | David Gibson | ss->output = env->irq_inputs[PPC970_INPUT_INT]; |
540 | b5cec4c5 | David Gibson | break;
|
541 | b5cec4c5 | David Gibson | |
542 | b5cec4c5 | David Gibson | default:
|
543 | b5cec4c5 | David Gibson | hw_error("XICS interrupt model does not support this CPU bus "
|
544 | b5cec4c5 | David Gibson | "model\n");
|
545 | b5cec4c5 | David Gibson | exit(1);
|
546 | b5cec4c5 | David Gibson | } |
547 | b5cec4c5 | David Gibson | } |
548 | b5cec4c5 | David Gibson | |
549 | 7267c094 | Anthony Liguori | ics = g_malloc0(sizeof(*ics));
|
550 | b5cec4c5 | David Gibson | ics->nr_irqs = nr_irqs; |
551 | b5cec4c5 | David Gibson | ics->offset = 16;
|
552 | 7267c094 | Anthony Liguori | ics->irqs = g_malloc0(nr_irqs * sizeof(struct ics_irq_state)); |
553 | b5cec4c5 | David Gibson | |
554 | b5cec4c5 | David Gibson | icp->ics = ics; |
555 | b5cec4c5 | David Gibson | ics->icp = icp; |
556 | b5cec4c5 | David Gibson | |
557 | d07fee7e | David Gibson | ics->qirqs = qemu_allocate_irqs(ics_set_irq, ics, nr_irqs); |
558 | b5cec4c5 | David Gibson | |
559 | b5cec4c5 | David Gibson | spapr_register_hypercall(H_CPPR, h_cppr); |
560 | b5cec4c5 | David Gibson | spapr_register_hypercall(H_IPI, h_ipi); |
561 | b5cec4c5 | David Gibson | spapr_register_hypercall(H_XIRR, h_xirr); |
562 | b5cec4c5 | David Gibson | spapr_register_hypercall(H_EOI, h_eoi); |
563 | b5cec4c5 | David Gibson | |
564 | b5cec4c5 | David Gibson | spapr_rtas_register("ibm,set-xive", rtas_set_xive);
|
565 | b5cec4c5 | David Gibson | spapr_rtas_register("ibm,get-xive", rtas_get_xive);
|
566 | b5cec4c5 | David Gibson | spapr_rtas_register("ibm,int-off", rtas_int_off);
|
567 | b5cec4c5 | David Gibson | spapr_rtas_register("ibm,int-on", rtas_int_on);
|
568 | b5cec4c5 | David Gibson | |
569 | 256b408a | David Gibson | qemu_register_reset(xics_reset, icp); |
570 | 256b408a | David Gibson | |
571 | b5cec4c5 | David Gibson | return icp;
|
572 | b5cec4c5 | David Gibson | } |