root / hw / xics.c @ 8e9f18b6
History | View | Annotate | Download (14.1 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 | d07fee7e | David Gibson | enum xics_irq_type type;
|
169 | d07fee7e | David Gibson | int asserted:1; |
170 | d07fee7e | David Gibson | int sent:1; |
171 | b5cec4c5 | David Gibson | int rejected:1; |
172 | b5cec4c5 | David Gibson | int masked_pending:1; |
173 | b5cec4c5 | David Gibson | }; |
174 | b5cec4c5 | David Gibson | |
175 | b5cec4c5 | David Gibson | struct ics_state {
|
176 | b5cec4c5 | David Gibson | int nr_irqs;
|
177 | b5cec4c5 | David Gibson | int offset;
|
178 | b5cec4c5 | David Gibson | qemu_irq *qirqs; |
179 | b5cec4c5 | David Gibson | struct ics_irq_state *irqs;
|
180 | b5cec4c5 | David Gibson | struct icp_state *icp;
|
181 | b5cec4c5 | David Gibson | }; |
182 | b5cec4c5 | David Gibson | |
183 | b5cec4c5 | David Gibson | static int ics_valid_irq(struct ics_state *ics, uint32_t nr) |
184 | b5cec4c5 | David Gibson | { |
185 | b5cec4c5 | David Gibson | return (nr >= ics->offset)
|
186 | b5cec4c5 | David Gibson | && (nr < (ics->offset + ics->nr_irqs)); |
187 | b5cec4c5 | David Gibson | } |
188 | b5cec4c5 | David Gibson | |
189 | d07fee7e | David Gibson | static void resend_msi(struct ics_state *ics, int srcno) |
190 | d07fee7e | David Gibson | { |
191 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
192 | d07fee7e | David Gibson | |
193 | d07fee7e | David Gibson | /* FIXME: filter by server#? */
|
194 | d07fee7e | David Gibson | if (irq->rejected) {
|
195 | d07fee7e | David Gibson | irq->rejected = 0;
|
196 | d07fee7e | David Gibson | if (irq->priority != 0xff) { |
197 | d07fee7e | David Gibson | icp_irq(ics->icp, irq->server, srcno + ics->offset, |
198 | d07fee7e | David Gibson | irq->priority); |
199 | d07fee7e | David Gibson | } |
200 | d07fee7e | David Gibson | } |
201 | d07fee7e | David Gibson | } |
202 | d07fee7e | David Gibson | |
203 | d07fee7e | David Gibson | static void resend_lsi(struct ics_state *ics, int srcno) |
204 | d07fee7e | David Gibson | { |
205 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
206 | d07fee7e | David Gibson | |
207 | d07fee7e | David Gibson | if ((irq->priority != 0xff) && irq->asserted && !irq->sent) { |
208 | d07fee7e | David Gibson | irq->sent = 1;
|
209 | d07fee7e | David Gibson | icp_irq(ics->icp, irq->server, srcno + ics->offset, irq->priority); |
210 | d07fee7e | David Gibson | } |
211 | d07fee7e | David Gibson | } |
212 | d07fee7e | David Gibson | |
213 | d07fee7e | David Gibson | static void set_irq_msi(struct ics_state *ics, int srcno, int val) |
214 | b5cec4c5 | David Gibson | { |
215 | cc67b9c8 | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
216 | b5cec4c5 | David Gibson | |
217 | b5cec4c5 | David Gibson | if (val) {
|
218 | b5cec4c5 | David Gibson | if (irq->priority == 0xff) { |
219 | b5cec4c5 | David Gibson | irq->masked_pending = 1;
|
220 | b5cec4c5 | David Gibson | /* masked pending */ ;
|
221 | b5cec4c5 | David Gibson | } else {
|
222 | cc67b9c8 | David Gibson | icp_irq(ics->icp, irq->server, srcno + ics->offset, irq->priority); |
223 | b5cec4c5 | David Gibson | } |
224 | b5cec4c5 | David Gibson | } |
225 | b5cec4c5 | David Gibson | } |
226 | b5cec4c5 | David Gibson | |
227 | d07fee7e | David Gibson | static void set_irq_lsi(struct ics_state *ics, int srcno, int val) |
228 | b5cec4c5 | David Gibson | { |
229 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
230 | b5cec4c5 | David Gibson | |
231 | d07fee7e | David Gibson | irq->asserted = val; |
232 | d07fee7e | David Gibson | resend_lsi(ics, srcno); |
233 | b5cec4c5 | David Gibson | } |
234 | b5cec4c5 | David Gibson | |
235 | d07fee7e | David Gibson | static void ics_set_irq(void *opaque, int srcno, int val) |
236 | b5cec4c5 | David Gibson | { |
237 | d07fee7e | David Gibson | struct ics_state *ics = (struct ics_state *)opaque; |
238 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
239 | b5cec4c5 | David Gibson | |
240 | d07fee7e | David Gibson | if (irq->type == XICS_LSI) {
|
241 | d07fee7e | David Gibson | set_irq_lsi(ics, srcno, val); |
242 | d07fee7e | David Gibson | } else {
|
243 | d07fee7e | David Gibson | set_irq_msi(ics, srcno, val); |
244 | d07fee7e | David Gibson | } |
245 | d07fee7e | David Gibson | } |
246 | b5cec4c5 | David Gibson | |
247 | d07fee7e | David Gibson | static void write_xive_msi(struct ics_state *ics, int srcno) |
248 | d07fee7e | David Gibson | { |
249 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
250 | d07fee7e | David Gibson | |
251 | d07fee7e | David Gibson | if (!irq->masked_pending || (irq->priority == 0xff)) { |
252 | d07fee7e | David Gibson | return;
|
253 | b5cec4c5 | David Gibson | } |
254 | d07fee7e | David Gibson | |
255 | d07fee7e | David Gibson | irq->masked_pending = 0;
|
256 | d07fee7e | David Gibson | icp_irq(ics->icp, irq->server, srcno + ics->offset, irq->priority); |
257 | b5cec4c5 | David Gibson | } |
258 | b5cec4c5 | David Gibson | |
259 | d07fee7e | David Gibson | static void write_xive_lsi(struct ics_state *ics, int srcno) |
260 | b5cec4c5 | David Gibson | { |
261 | d07fee7e | David Gibson | resend_lsi(ics, srcno); |
262 | d07fee7e | David Gibson | } |
263 | d07fee7e | David Gibson | |
264 | d07fee7e | David Gibson | static void ics_write_xive(struct ics_state *ics, int nr, int server, |
265 | d07fee7e | David Gibson | uint8_t priority) |
266 | d07fee7e | David Gibson | { |
267 | d07fee7e | David Gibson | int srcno = nr - ics->offset;
|
268 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
269 | b5cec4c5 | David Gibson | |
270 | b5cec4c5 | David Gibson | irq->server = server; |
271 | b5cec4c5 | David Gibson | irq->priority = priority; |
272 | b5cec4c5 | David Gibson | |
273 | d07fee7e | David Gibson | if (irq->type == XICS_LSI) {
|
274 | d07fee7e | David Gibson | write_xive_lsi(ics, srcno); |
275 | d07fee7e | David Gibson | } else {
|
276 | d07fee7e | David Gibson | write_xive_msi(ics, srcno); |
277 | b5cec4c5 | David Gibson | } |
278 | b5cec4c5 | David Gibson | } |
279 | b5cec4c5 | David Gibson | |
280 | b5cec4c5 | David Gibson | static void ics_reject(struct ics_state *ics, int nr) |
281 | b5cec4c5 | David Gibson | { |
282 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + nr - ics->offset;
|
283 | d07fee7e | David Gibson | |
284 | d07fee7e | David Gibson | irq->rejected = 1; /* Irrelevant but harmless for LSI */ |
285 | d07fee7e | David Gibson | irq->sent = 0; /* Irrelevant but harmless for MSI */ |
286 | b5cec4c5 | David Gibson | } |
287 | b5cec4c5 | David Gibson | |
288 | b5cec4c5 | David Gibson | static void ics_resend(struct ics_state *ics) |
289 | b5cec4c5 | David Gibson | { |
290 | d07fee7e | David Gibson | int i;
|
291 | d07fee7e | David Gibson | |
292 | d07fee7e | David Gibson | for (i = 0; i < ics->nr_irqs; i++) { |
293 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + i;
|
294 | d07fee7e | David Gibson | |
295 | d07fee7e | David Gibson | /* FIXME: filter by server#? */
|
296 | d07fee7e | David Gibson | if (irq->type == XICS_LSI) {
|
297 | d07fee7e | David Gibson | resend_lsi(ics, i); |
298 | d07fee7e | David Gibson | } else {
|
299 | d07fee7e | David Gibson | resend_msi(ics, i); |
300 | d07fee7e | David Gibson | } |
301 | d07fee7e | David Gibson | } |
302 | b5cec4c5 | David Gibson | } |
303 | b5cec4c5 | David Gibson | |
304 | b5cec4c5 | David Gibson | static void ics_eoi(struct ics_state *ics, int nr) |
305 | b5cec4c5 | David Gibson | { |
306 | d07fee7e | David Gibson | int srcno = nr - ics->offset;
|
307 | d07fee7e | David Gibson | struct ics_irq_state *irq = ics->irqs + srcno;
|
308 | d07fee7e | David Gibson | |
309 | d07fee7e | David Gibson | if (irq->type == XICS_LSI) {
|
310 | d07fee7e | David Gibson | irq->sent = 0;
|
311 | d07fee7e | David Gibson | } |
312 | b5cec4c5 | David Gibson | } |
313 | b5cec4c5 | David Gibson | |
314 | b5cec4c5 | David Gibson | /*
|
315 | b5cec4c5 | David Gibson | * Exported functions
|
316 | b5cec4c5 | David Gibson | */
|
317 | b5cec4c5 | David Gibson | |
318 | a307d594 | Alexey Kardashevskiy | qemu_irq xics_get_qirq(struct icp_state *icp, int irq) |
319 | b5cec4c5 | David Gibson | { |
320 | b5cec4c5 | David Gibson | if ((irq < icp->ics->offset)
|
321 | b5cec4c5 | David Gibson | || (irq >= (icp->ics->offset + icp->ics->nr_irqs))) { |
322 | b5cec4c5 | David Gibson | return NULL; |
323 | b5cec4c5 | David Gibson | } |
324 | b5cec4c5 | David Gibson | |
325 | a307d594 | Alexey Kardashevskiy | return icp->ics->qirqs[irq - icp->ics->offset];
|
326 | a307d594 | Alexey Kardashevskiy | } |
327 | a307d594 | Alexey Kardashevskiy | |
328 | a307d594 | Alexey Kardashevskiy | void xics_set_irq_type(struct icp_state *icp, int irq, |
329 | a307d594 | Alexey Kardashevskiy | enum xics_irq_type type)
|
330 | a307d594 | Alexey Kardashevskiy | { |
331 | a307d594 | Alexey Kardashevskiy | assert((irq >= icp->ics->offset) |
332 | a307d594 | Alexey Kardashevskiy | && (irq < (icp->ics->offset + icp->ics->nr_irqs))); |
333 | d07fee7e | David Gibson | assert((type == XICS_MSI) || (type == XICS_LSI)); |
334 | d07fee7e | David Gibson | |
335 | d07fee7e | David Gibson | icp->ics->irqs[irq - icp->ics->offset].type = type; |
336 | b5cec4c5 | David Gibson | } |
337 | b5cec4c5 | David Gibson | |
338 | e2684c0b | Andreas Färber | static target_ulong h_cppr(CPUPPCState *env, sPAPREnvironment *spapr,
|
339 | b5cec4c5 | David Gibson | target_ulong opcode, target_ulong *args) |
340 | b5cec4c5 | David Gibson | { |
341 | b5cec4c5 | David Gibson | target_ulong cppr = args[0];
|
342 | b5cec4c5 | David Gibson | |
343 | b5cec4c5 | David Gibson | icp_set_cppr(spapr->icp, env->cpu_index, cppr); |
344 | b5cec4c5 | David Gibson | return H_SUCCESS;
|
345 | b5cec4c5 | David Gibson | } |
346 | b5cec4c5 | David Gibson | |
347 | e2684c0b | Andreas Färber | static target_ulong h_ipi(CPUPPCState *env, sPAPREnvironment *spapr,
|
348 | b5cec4c5 | David Gibson | target_ulong opcode, target_ulong *args) |
349 | b5cec4c5 | David Gibson | { |
350 | b5cec4c5 | David Gibson | target_ulong server = args[0];
|
351 | b5cec4c5 | David Gibson | target_ulong mfrr = args[1];
|
352 | b5cec4c5 | David Gibson | |
353 | b5cec4c5 | David Gibson | if (server >= spapr->icp->nr_servers) {
|
354 | b5cec4c5 | David Gibson | return H_PARAMETER;
|
355 | b5cec4c5 | David Gibson | } |
356 | b5cec4c5 | David Gibson | |
357 | b5cec4c5 | David Gibson | icp_set_mfrr(spapr->icp, server, mfrr); |
358 | b5cec4c5 | David Gibson | return H_SUCCESS;
|
359 | b5cec4c5 | David Gibson | |
360 | b5cec4c5 | David Gibson | } |
361 | b5cec4c5 | David Gibson | |
362 | e2684c0b | Andreas Färber | static target_ulong h_xirr(CPUPPCState *env, sPAPREnvironment *spapr,
|
363 | b5cec4c5 | David Gibson | target_ulong opcode, target_ulong *args) |
364 | b5cec4c5 | David Gibson | { |
365 | b5cec4c5 | David Gibson | uint32_t xirr = icp_accept(spapr->icp->ss + env->cpu_index); |
366 | b5cec4c5 | David Gibson | |
367 | b5cec4c5 | David Gibson | args[0] = xirr;
|
368 | b5cec4c5 | David Gibson | return H_SUCCESS;
|
369 | b5cec4c5 | David Gibson | } |
370 | b5cec4c5 | David Gibson | |
371 | e2684c0b | Andreas Färber | static target_ulong h_eoi(CPUPPCState *env, sPAPREnvironment *spapr,
|
372 | b5cec4c5 | David Gibson | target_ulong opcode, target_ulong *args) |
373 | b5cec4c5 | David Gibson | { |
374 | b5cec4c5 | David Gibson | target_ulong xirr = args[0];
|
375 | b5cec4c5 | David Gibson | |
376 | b5cec4c5 | David Gibson | icp_eoi(spapr->icp, env->cpu_index, xirr); |
377 | b5cec4c5 | David Gibson | return H_SUCCESS;
|
378 | b5cec4c5 | David Gibson | } |
379 | b5cec4c5 | David Gibson | |
380 | b5cec4c5 | David Gibson | static void rtas_set_xive(sPAPREnvironment *spapr, uint32_t token, |
381 | b5cec4c5 | David Gibson | uint32_t nargs, target_ulong args, |
382 | b5cec4c5 | David Gibson | uint32_t nret, target_ulong rets) |
383 | b5cec4c5 | David Gibson | { |
384 | b5cec4c5 | David Gibson | struct ics_state *ics = spapr->icp->ics;
|
385 | b5cec4c5 | David Gibson | uint32_t nr, server, priority; |
386 | b5cec4c5 | David Gibson | |
387 | b5cec4c5 | David Gibson | if ((nargs != 3) || (nret != 1)) { |
388 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
389 | b5cec4c5 | David Gibson | return;
|
390 | b5cec4c5 | David Gibson | } |
391 | b5cec4c5 | David Gibson | |
392 | b5cec4c5 | David Gibson | nr = rtas_ld(args, 0);
|
393 | b5cec4c5 | David Gibson | server = rtas_ld(args, 1);
|
394 | b5cec4c5 | David Gibson | priority = rtas_ld(args, 2);
|
395 | b5cec4c5 | David Gibson | |
396 | b5cec4c5 | David Gibson | if (!ics_valid_irq(ics, nr) || (server >= ics->icp->nr_servers)
|
397 | b5cec4c5 | David Gibson | || (priority > 0xff)) {
|
398 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
399 | b5cec4c5 | David Gibson | return;
|
400 | b5cec4c5 | David Gibson | } |
401 | b5cec4c5 | David Gibson | |
402 | d07fee7e | David Gibson | ics_write_xive(ics, nr, server, priority); |
403 | b5cec4c5 | David Gibson | |
404 | b5cec4c5 | David Gibson | rtas_st(rets, 0, 0); /* Success */ |
405 | b5cec4c5 | David Gibson | } |
406 | b5cec4c5 | David Gibson | |
407 | b5cec4c5 | David Gibson | static void rtas_get_xive(sPAPREnvironment *spapr, uint32_t token, |
408 | b5cec4c5 | David Gibson | uint32_t nargs, target_ulong args, |
409 | b5cec4c5 | David Gibson | uint32_t nret, target_ulong rets) |
410 | b5cec4c5 | David Gibson | { |
411 | b5cec4c5 | David Gibson | struct ics_state *ics = spapr->icp->ics;
|
412 | b5cec4c5 | David Gibson | uint32_t nr; |
413 | b5cec4c5 | David Gibson | |
414 | b5cec4c5 | David Gibson | if ((nargs != 1) || (nret != 3)) { |
415 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
416 | b5cec4c5 | David Gibson | return;
|
417 | b5cec4c5 | David Gibson | } |
418 | b5cec4c5 | David Gibson | |
419 | b5cec4c5 | David Gibson | nr = rtas_ld(args, 0);
|
420 | b5cec4c5 | David Gibson | |
421 | b5cec4c5 | David Gibson | if (!ics_valid_irq(ics, nr)) {
|
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 | rtas_st(rets, 0, 0); /* Success */ |
427 | b5cec4c5 | David Gibson | rtas_st(rets, 1, ics->irqs[nr - ics->offset].server);
|
428 | b5cec4c5 | David Gibson | rtas_st(rets, 2, ics->irqs[nr - ics->offset].priority);
|
429 | b5cec4c5 | David Gibson | } |
430 | b5cec4c5 | David Gibson | |
431 | b5cec4c5 | David Gibson | static void rtas_int_off(sPAPREnvironment *spapr, uint32_t token, |
432 | b5cec4c5 | David Gibson | uint32_t nargs, target_ulong args, |
433 | b5cec4c5 | David Gibson | uint32_t nret, target_ulong rets) |
434 | b5cec4c5 | David Gibson | { |
435 | b5cec4c5 | David Gibson | struct ics_state *ics = spapr->icp->ics;
|
436 | b5cec4c5 | David Gibson | uint32_t nr; |
437 | b5cec4c5 | David Gibson | |
438 | b5cec4c5 | David Gibson | if ((nargs != 1) || (nret != 1)) { |
439 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
440 | b5cec4c5 | David Gibson | return;
|
441 | b5cec4c5 | David Gibson | } |
442 | b5cec4c5 | David Gibson | |
443 | b5cec4c5 | David Gibson | nr = rtas_ld(args, 0);
|
444 | b5cec4c5 | David Gibson | |
445 | b5cec4c5 | David Gibson | if (!ics_valid_irq(ics, nr)) {
|
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 | /* This is a NOP for now, since the described PAPR semantics don't
|
451 | b5cec4c5 | David Gibson | * seem to gel with what Linux does */
|
452 | b5cec4c5 | David Gibson | #if 0
|
453 | b5cec4c5 | David Gibson | struct ics_irq_state *irq = xics->irqs + (nr - xics->offset);
|
454 | b5cec4c5 | David Gibson | |
455 | b5cec4c5 | David Gibson | irq->saved_priority = irq->priority;
|
456 | cc67b9c8 | David Gibson | ics_write_xive_msi(xics, nr, irq->server, 0xff);
|
457 | b5cec4c5 | David Gibson | #endif
|
458 | b5cec4c5 | David Gibson | |
459 | b5cec4c5 | David Gibson | rtas_st(rets, 0, 0); /* Success */ |
460 | b5cec4c5 | David Gibson | } |
461 | b5cec4c5 | David Gibson | |
462 | b5cec4c5 | David Gibson | static void rtas_int_on(sPAPREnvironment *spapr, uint32_t token, |
463 | b5cec4c5 | David Gibson | uint32_t nargs, target_ulong args, |
464 | b5cec4c5 | David Gibson | uint32_t nret, target_ulong rets) |
465 | b5cec4c5 | David Gibson | { |
466 | b5cec4c5 | David Gibson | struct ics_state *ics = spapr->icp->ics;
|
467 | b5cec4c5 | David Gibson | uint32_t nr; |
468 | b5cec4c5 | David Gibson | |
469 | b5cec4c5 | David Gibson | if ((nargs != 1) || (nret != 1)) { |
470 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
471 | b5cec4c5 | David Gibson | return;
|
472 | b5cec4c5 | David Gibson | } |
473 | b5cec4c5 | David Gibson | |
474 | b5cec4c5 | David Gibson | nr = rtas_ld(args, 0);
|
475 | b5cec4c5 | David Gibson | |
476 | b5cec4c5 | David Gibson | if (!ics_valid_irq(ics, nr)) {
|
477 | b5cec4c5 | David Gibson | rtas_st(rets, 0, -3); |
478 | b5cec4c5 | David Gibson | return;
|
479 | b5cec4c5 | David Gibson | } |
480 | b5cec4c5 | David Gibson | |
481 | b5cec4c5 | David Gibson | /* This is a NOP for now, since the described PAPR semantics don't
|
482 | b5cec4c5 | David Gibson | * seem to gel with what Linux does */
|
483 | b5cec4c5 | David Gibson | #if 0
|
484 | b5cec4c5 | David Gibson | struct ics_irq_state *irq = xics->irqs + (nr - xics->offset);
|
485 | b5cec4c5 | David Gibson | |
486 | cc67b9c8 | David Gibson | ics_write_xive_msi(xics, nr, irq->server, irq->saved_priority);
|
487 | b5cec4c5 | David Gibson | #endif
|
488 | b5cec4c5 | David Gibson | |
489 | b5cec4c5 | David Gibson | rtas_st(rets, 0, 0); /* Success */ |
490 | b5cec4c5 | David Gibson | } |
491 | b5cec4c5 | David Gibson | |
492 | c7a5c0c9 | David Gibson | struct icp_state *xics_system_init(int nr_irqs) |
493 | b5cec4c5 | David Gibson | { |
494 | e2684c0b | Andreas Färber | CPUPPCState *env; |
495 | c7a5c0c9 | David Gibson | int max_server_num;
|
496 | b5cec4c5 | David Gibson | int i;
|
497 | b5cec4c5 | David Gibson | struct icp_state *icp;
|
498 | b5cec4c5 | David Gibson | struct ics_state *ics;
|
499 | b5cec4c5 | David Gibson | |
500 | c7a5c0c9 | David Gibson | max_server_num = -1;
|
501 | c7a5c0c9 | David Gibson | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
502 | c7a5c0c9 | David Gibson | if (env->cpu_index > max_server_num) {
|
503 | c7a5c0c9 | David Gibson | max_server_num = env->cpu_index; |
504 | c7a5c0c9 | David Gibson | } |
505 | c7a5c0c9 | David Gibson | } |
506 | c7a5c0c9 | David Gibson | |
507 | 7267c094 | Anthony Liguori | icp = g_malloc0(sizeof(*icp));
|
508 | c7a5c0c9 | David Gibson | icp->nr_servers = max_server_num + 1;
|
509 | 7267c094 | Anthony Liguori | icp->ss = g_malloc0(icp->nr_servers*sizeof(struct icp_server_state)); |
510 | c7a5c0c9 | David Gibson | |
511 | c7a5c0c9 | David Gibson | for (i = 0; i < icp->nr_servers; i++) { |
512 | c7a5c0c9 | David Gibson | icp->ss[i].mfrr = 0xff;
|
513 | c7a5c0c9 | David Gibson | } |
514 | b5cec4c5 | David Gibson | |
515 | c7a5c0c9 | David Gibson | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
516 | c7a5c0c9 | David Gibson | struct icp_server_state *ss = &icp->ss[env->cpu_index];
|
517 | b5cec4c5 | David Gibson | |
518 | c7a5c0c9 | David Gibson | switch (PPC_INPUT(env)) {
|
519 | b5cec4c5 | David Gibson | case PPC_FLAGS_INPUT_POWER7:
|
520 | c7a5c0c9 | David Gibson | ss->output = env->irq_inputs[POWER7_INPUT_INT]; |
521 | b5cec4c5 | David Gibson | break;
|
522 | b5cec4c5 | David Gibson | |
523 | b5cec4c5 | David Gibson | case PPC_FLAGS_INPUT_970:
|
524 | c7a5c0c9 | David Gibson | ss->output = env->irq_inputs[PPC970_INPUT_INT]; |
525 | b5cec4c5 | David Gibson | break;
|
526 | b5cec4c5 | David Gibson | |
527 | b5cec4c5 | David Gibson | default:
|
528 | b5cec4c5 | David Gibson | hw_error("XICS interrupt model does not support this CPU bus "
|
529 | b5cec4c5 | David Gibson | "model\n");
|
530 | b5cec4c5 | David Gibson | exit(1);
|
531 | b5cec4c5 | David Gibson | } |
532 | b5cec4c5 | David Gibson | } |
533 | b5cec4c5 | David Gibson | |
534 | 7267c094 | Anthony Liguori | ics = g_malloc0(sizeof(*ics));
|
535 | b5cec4c5 | David Gibson | ics->nr_irqs = nr_irqs; |
536 | b5cec4c5 | David Gibson | ics->offset = 16;
|
537 | 7267c094 | Anthony Liguori | ics->irqs = g_malloc0(nr_irqs * sizeof(struct ics_irq_state)); |
538 | b5cec4c5 | David Gibson | |
539 | b5cec4c5 | David Gibson | icp->ics = ics; |
540 | b5cec4c5 | David Gibson | ics->icp = icp; |
541 | b5cec4c5 | David Gibson | |
542 | b5cec4c5 | David Gibson | for (i = 0; i < nr_irqs; i++) { |
543 | b5cec4c5 | David Gibson | ics->irqs[i].priority = 0xff;
|
544 | b5cec4c5 | David Gibson | ics->irqs[i].saved_priority = 0xff;
|
545 | b5cec4c5 | David Gibson | } |
546 | b5cec4c5 | David Gibson | |
547 | d07fee7e | David Gibson | ics->qirqs = qemu_allocate_irqs(ics_set_irq, ics, nr_irqs); |
548 | b5cec4c5 | David Gibson | |
549 | b5cec4c5 | David Gibson | spapr_register_hypercall(H_CPPR, h_cppr); |
550 | b5cec4c5 | David Gibson | spapr_register_hypercall(H_IPI, h_ipi); |
551 | b5cec4c5 | David Gibson | spapr_register_hypercall(H_XIRR, h_xirr); |
552 | b5cec4c5 | David Gibson | spapr_register_hypercall(H_EOI, h_eoi); |
553 | b5cec4c5 | David Gibson | |
554 | b5cec4c5 | David Gibson | spapr_rtas_register("ibm,set-xive", rtas_set_xive);
|
555 | b5cec4c5 | David Gibson | spapr_rtas_register("ibm,get-xive", rtas_get_xive);
|
556 | b5cec4c5 | David Gibson | spapr_rtas_register("ibm,int-off", rtas_int_off);
|
557 | b5cec4c5 | David Gibson | spapr_rtas_register("ibm,int-on", rtas_int_on);
|
558 | b5cec4c5 | David Gibson | |
559 | b5cec4c5 | David Gibson | return icp;
|
560 | b5cec4c5 | David Gibson | } |