]> git.proxmox.com Git - mirror_qemu.git/blob - hw/intc/xive.c
ppc/xive: introduce the XIVE Event Notification Descriptors
[mirror_qemu.git] / hw / intc / xive.c
1 /*
2 * QEMU PowerPC XIVE interrupt controller model
3 *
4 * Copyright (c) 2017-2018, IBM Corporation.
5 *
6 * This code is licensed under the GPL version 2 or later. See the
7 * COPYING file in the top-level directory.
8 */
9
10 #include "qemu/osdep.h"
11 #include "qemu/log.h"
12 #include "qapi/error.h"
13 #include "target/ppc/cpu.h"
14 #include "sysemu/cpus.h"
15 #include "sysemu/dma.h"
16 #include "hw/qdev-properties.h"
17 #include "monitor/monitor.h"
18 #include "hw/ppc/xive.h"
19
20 /*
21 * XIVE ESB helpers
22 */
23
24 static uint8_t xive_esb_set(uint8_t *pq, uint8_t value)
25 {
26 uint8_t old_pq = *pq & 0x3;
27
28 *pq &= ~0x3;
29 *pq |= value & 0x3;
30
31 return old_pq;
32 }
33
34 static bool xive_esb_trigger(uint8_t *pq)
35 {
36 uint8_t old_pq = *pq & 0x3;
37
38 switch (old_pq) {
39 case XIVE_ESB_RESET:
40 xive_esb_set(pq, XIVE_ESB_PENDING);
41 return true;
42 case XIVE_ESB_PENDING:
43 case XIVE_ESB_QUEUED:
44 xive_esb_set(pq, XIVE_ESB_QUEUED);
45 return false;
46 case XIVE_ESB_OFF:
47 xive_esb_set(pq, XIVE_ESB_OFF);
48 return false;
49 default:
50 g_assert_not_reached();
51 }
52 }
53
54 static bool xive_esb_eoi(uint8_t *pq)
55 {
56 uint8_t old_pq = *pq & 0x3;
57
58 switch (old_pq) {
59 case XIVE_ESB_RESET:
60 case XIVE_ESB_PENDING:
61 xive_esb_set(pq, XIVE_ESB_RESET);
62 return false;
63 case XIVE_ESB_QUEUED:
64 xive_esb_set(pq, XIVE_ESB_PENDING);
65 return true;
66 case XIVE_ESB_OFF:
67 xive_esb_set(pq, XIVE_ESB_OFF);
68 return false;
69 default:
70 g_assert_not_reached();
71 }
72 }
73
74 /*
75 * XIVE Interrupt Source (or IVSE)
76 */
77
78 uint8_t xive_source_esb_get(XiveSource *xsrc, uint32_t srcno)
79 {
80 assert(srcno < xsrc->nr_irqs);
81
82 return xsrc->status[srcno] & 0x3;
83 }
84
85 uint8_t xive_source_esb_set(XiveSource *xsrc, uint32_t srcno, uint8_t pq)
86 {
87 assert(srcno < xsrc->nr_irqs);
88
89 return xive_esb_set(&xsrc->status[srcno], pq);
90 }
91
92 /*
93 * Returns whether the event notification should be forwarded.
94 */
95 static bool xive_source_lsi_trigger(XiveSource *xsrc, uint32_t srcno)
96 {
97 uint8_t old_pq = xive_source_esb_get(xsrc, srcno);
98
99 xsrc->status[srcno] |= XIVE_STATUS_ASSERTED;
100
101 switch (old_pq) {
102 case XIVE_ESB_RESET:
103 xive_source_esb_set(xsrc, srcno, XIVE_ESB_PENDING);
104 return true;
105 default:
106 return false;
107 }
108 }
109
110 /*
111 * Returns whether the event notification should be forwarded.
112 */
113 static bool xive_source_esb_trigger(XiveSource *xsrc, uint32_t srcno)
114 {
115 bool ret;
116
117 assert(srcno < xsrc->nr_irqs);
118
119 ret = xive_esb_trigger(&xsrc->status[srcno]);
120
121 if (xive_source_irq_is_lsi(xsrc, srcno) &&
122 xive_source_esb_get(xsrc, srcno) == XIVE_ESB_QUEUED) {
123 qemu_log_mask(LOG_GUEST_ERROR,
124 "XIVE: queued an event on LSI IRQ %d\n", srcno);
125 }
126
127 return ret;
128 }
129
130 /*
131 * Returns whether the event notification should be forwarded.
132 */
133 static bool xive_source_esb_eoi(XiveSource *xsrc, uint32_t srcno)
134 {
135 bool ret;
136
137 assert(srcno < xsrc->nr_irqs);
138
139 ret = xive_esb_eoi(&xsrc->status[srcno]);
140
141 /*
142 * LSI sources do not set the Q bit but they can still be
143 * asserted, in which case we should forward a new event
144 * notification
145 */
146 if (xive_source_irq_is_lsi(xsrc, srcno) &&
147 xsrc->status[srcno] & XIVE_STATUS_ASSERTED) {
148 ret = xive_source_lsi_trigger(xsrc, srcno);
149 }
150
151 return ret;
152 }
153
154 /*
155 * Forward the source event notification to the Router
156 */
157 static void xive_source_notify(XiveSource *xsrc, int srcno)
158 {
159 XiveNotifierClass *xnc = XIVE_NOTIFIER_GET_CLASS(xsrc->xive);
160
161 if (xnc->notify) {
162 xnc->notify(xsrc->xive, srcno);
163 }
164 }
165
166 /*
167 * In a two pages ESB MMIO setting, even page is the trigger page, odd
168 * page is for management
169 */
170 static inline bool addr_is_even(hwaddr addr, uint32_t shift)
171 {
172 return !((addr >> shift) & 1);
173 }
174
175 static inline bool xive_source_is_trigger_page(XiveSource *xsrc, hwaddr addr)
176 {
177 return xive_source_esb_has_2page(xsrc) &&
178 addr_is_even(addr, xsrc->esb_shift - 1);
179 }
180
181 /*
182 * ESB MMIO loads
183 * Trigger page Management/EOI page
184 *
185 * ESB MMIO setting 2 pages 1 or 2 pages
186 *
187 * 0x000 .. 0x3FF -1 EOI and return 0|1
188 * 0x400 .. 0x7FF -1 EOI and return 0|1
189 * 0x800 .. 0xBFF -1 return PQ
190 * 0xC00 .. 0xCFF -1 return PQ and atomically PQ=00
191 * 0xD00 .. 0xDFF -1 return PQ and atomically PQ=01
192 * 0xE00 .. 0xDFF -1 return PQ and atomically PQ=10
193 * 0xF00 .. 0xDFF -1 return PQ and atomically PQ=11
194 */
195 static uint64_t xive_source_esb_read(void *opaque, hwaddr addr, unsigned size)
196 {
197 XiveSource *xsrc = XIVE_SOURCE(opaque);
198 uint32_t offset = addr & 0xFFF;
199 uint32_t srcno = addr >> xsrc->esb_shift;
200 uint64_t ret = -1;
201
202 /* In a two pages ESB MMIO setting, trigger page should not be read */
203 if (xive_source_is_trigger_page(xsrc, addr)) {
204 qemu_log_mask(LOG_GUEST_ERROR,
205 "XIVE: invalid load on IRQ %d trigger page at "
206 "0x%"HWADDR_PRIx"\n", srcno, addr);
207 return -1;
208 }
209
210 switch (offset) {
211 case XIVE_ESB_LOAD_EOI ... XIVE_ESB_LOAD_EOI + 0x7FF:
212 ret = xive_source_esb_eoi(xsrc, srcno);
213
214 /* Forward the source event notification for routing */
215 if (ret) {
216 xive_source_notify(xsrc, srcno);
217 }
218 break;
219
220 case XIVE_ESB_GET ... XIVE_ESB_GET + 0x3FF:
221 ret = xive_source_esb_get(xsrc, srcno);
222 break;
223
224 case XIVE_ESB_SET_PQ_00 ... XIVE_ESB_SET_PQ_00 + 0x0FF:
225 case XIVE_ESB_SET_PQ_01 ... XIVE_ESB_SET_PQ_01 + 0x0FF:
226 case XIVE_ESB_SET_PQ_10 ... XIVE_ESB_SET_PQ_10 + 0x0FF:
227 case XIVE_ESB_SET_PQ_11 ... XIVE_ESB_SET_PQ_11 + 0x0FF:
228 ret = xive_source_esb_set(xsrc, srcno, (offset >> 8) & 0x3);
229 break;
230 default:
231 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid ESB load addr %x\n",
232 offset);
233 }
234
235 return ret;
236 }
237
238 /*
239 * ESB MMIO stores
240 * Trigger page Management/EOI page
241 *
242 * ESB MMIO setting 2 pages 1 or 2 pages
243 *
244 * 0x000 .. 0x3FF Trigger Trigger
245 * 0x400 .. 0x7FF Trigger EOI
246 * 0x800 .. 0xBFF Trigger undefined
247 * 0xC00 .. 0xCFF Trigger PQ=00
248 * 0xD00 .. 0xDFF Trigger PQ=01
249 * 0xE00 .. 0xDFF Trigger PQ=10
250 * 0xF00 .. 0xDFF Trigger PQ=11
251 */
252 static void xive_source_esb_write(void *opaque, hwaddr addr,
253 uint64_t value, unsigned size)
254 {
255 XiveSource *xsrc = XIVE_SOURCE(opaque);
256 uint32_t offset = addr & 0xFFF;
257 uint32_t srcno = addr >> xsrc->esb_shift;
258 bool notify = false;
259
260 /* In a two pages ESB MMIO setting, trigger page only triggers */
261 if (xive_source_is_trigger_page(xsrc, addr)) {
262 notify = xive_source_esb_trigger(xsrc, srcno);
263 goto out;
264 }
265
266 switch (offset) {
267 case 0 ... 0x3FF:
268 notify = xive_source_esb_trigger(xsrc, srcno);
269 break;
270
271 case XIVE_ESB_STORE_EOI ... XIVE_ESB_STORE_EOI + 0x3FF:
272 if (!(xsrc->esb_flags & XIVE_SRC_STORE_EOI)) {
273 qemu_log_mask(LOG_GUEST_ERROR,
274 "XIVE: invalid Store EOI for IRQ %d\n", srcno);
275 return;
276 }
277
278 notify = xive_source_esb_eoi(xsrc, srcno);
279 break;
280
281 case XIVE_ESB_SET_PQ_00 ... XIVE_ESB_SET_PQ_00 + 0x0FF:
282 case XIVE_ESB_SET_PQ_01 ... XIVE_ESB_SET_PQ_01 + 0x0FF:
283 case XIVE_ESB_SET_PQ_10 ... XIVE_ESB_SET_PQ_10 + 0x0FF:
284 case XIVE_ESB_SET_PQ_11 ... XIVE_ESB_SET_PQ_11 + 0x0FF:
285 xive_source_esb_set(xsrc, srcno, (offset >> 8) & 0x3);
286 break;
287
288 default:
289 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid ESB write addr %x\n",
290 offset);
291 return;
292 }
293
294 out:
295 /* Forward the source event notification for routing */
296 if (notify) {
297 xive_source_notify(xsrc, srcno);
298 }
299 }
300
301 static const MemoryRegionOps xive_source_esb_ops = {
302 .read = xive_source_esb_read,
303 .write = xive_source_esb_write,
304 .endianness = DEVICE_BIG_ENDIAN,
305 .valid = {
306 .min_access_size = 8,
307 .max_access_size = 8,
308 },
309 .impl = {
310 .min_access_size = 8,
311 .max_access_size = 8,
312 },
313 };
314
315 static void xive_source_set_irq(void *opaque, int srcno, int val)
316 {
317 XiveSource *xsrc = XIVE_SOURCE(opaque);
318 bool notify = false;
319
320 if (xive_source_irq_is_lsi(xsrc, srcno)) {
321 if (val) {
322 notify = xive_source_lsi_trigger(xsrc, srcno);
323 } else {
324 xsrc->status[srcno] &= ~XIVE_STATUS_ASSERTED;
325 }
326 } else {
327 if (val) {
328 notify = xive_source_esb_trigger(xsrc, srcno);
329 }
330 }
331
332 /* Forward the source event notification for routing */
333 if (notify) {
334 xive_source_notify(xsrc, srcno);
335 }
336 }
337
338 void xive_source_pic_print_info(XiveSource *xsrc, uint32_t offset, Monitor *mon)
339 {
340 int i;
341
342 for (i = 0; i < xsrc->nr_irqs; i++) {
343 uint8_t pq = xive_source_esb_get(xsrc, i);
344
345 if (pq == XIVE_ESB_OFF) {
346 continue;
347 }
348
349 monitor_printf(mon, " %08x %s %c%c%c\n", i + offset,
350 xive_source_irq_is_lsi(xsrc, i) ? "LSI" : "MSI",
351 pq & XIVE_ESB_VAL_P ? 'P' : '-',
352 pq & XIVE_ESB_VAL_Q ? 'Q' : '-',
353 xsrc->status[i] & XIVE_STATUS_ASSERTED ? 'A' : ' ');
354 }
355 }
356
357 static void xive_source_reset(void *dev)
358 {
359 XiveSource *xsrc = XIVE_SOURCE(dev);
360
361 /* Do not clear the LSI bitmap */
362
363 /* PQs are initialized to 0b01 (Q=1) which corresponds to "ints off" */
364 memset(xsrc->status, XIVE_ESB_OFF, xsrc->nr_irqs);
365 }
366
367 static void xive_source_realize(DeviceState *dev, Error **errp)
368 {
369 XiveSource *xsrc = XIVE_SOURCE(dev);
370 Object *obj;
371 Error *local_err = NULL;
372
373 obj = object_property_get_link(OBJECT(dev), "xive", &local_err);
374 if (!obj) {
375 error_propagate(errp, local_err);
376 error_prepend(errp, "required link 'xive' not found: ");
377 return;
378 }
379
380 xsrc->xive = XIVE_NOTIFIER(obj);
381
382 if (!xsrc->nr_irqs) {
383 error_setg(errp, "Number of interrupt needs to be greater than 0");
384 return;
385 }
386
387 if (xsrc->esb_shift != XIVE_ESB_4K &&
388 xsrc->esb_shift != XIVE_ESB_4K_2PAGE &&
389 xsrc->esb_shift != XIVE_ESB_64K &&
390 xsrc->esb_shift != XIVE_ESB_64K_2PAGE) {
391 error_setg(errp, "Invalid ESB shift setting");
392 return;
393 }
394
395 xsrc->status = g_malloc0(xsrc->nr_irqs);
396 xsrc->lsi_map = bitmap_new(xsrc->nr_irqs);
397
398 memory_region_init_io(&xsrc->esb_mmio, OBJECT(xsrc),
399 &xive_source_esb_ops, xsrc, "xive.esb",
400 (1ull << xsrc->esb_shift) * xsrc->nr_irqs);
401
402 xsrc->qirqs = qemu_allocate_irqs(xive_source_set_irq, xsrc,
403 xsrc->nr_irqs);
404
405 qemu_register_reset(xive_source_reset, dev);
406 }
407
408 static const VMStateDescription vmstate_xive_source = {
409 .name = TYPE_XIVE_SOURCE,
410 .version_id = 1,
411 .minimum_version_id = 1,
412 .fields = (VMStateField[]) {
413 VMSTATE_UINT32_EQUAL(nr_irqs, XiveSource, NULL),
414 VMSTATE_VBUFFER_UINT32(status, XiveSource, 1, NULL, nr_irqs),
415 VMSTATE_END_OF_LIST()
416 },
417 };
418
419 /*
420 * The default XIVE interrupt source setting for the ESB MMIOs is two
421 * 64k pages without Store EOI, to be in sync with KVM.
422 */
423 static Property xive_source_properties[] = {
424 DEFINE_PROP_UINT64("flags", XiveSource, esb_flags, 0),
425 DEFINE_PROP_UINT32("nr-irqs", XiveSource, nr_irqs, 0),
426 DEFINE_PROP_UINT32("shift", XiveSource, esb_shift, XIVE_ESB_64K_2PAGE),
427 DEFINE_PROP_END_OF_LIST(),
428 };
429
430 static void xive_source_class_init(ObjectClass *klass, void *data)
431 {
432 DeviceClass *dc = DEVICE_CLASS(klass);
433
434 dc->desc = "XIVE Interrupt Source";
435 dc->props = xive_source_properties;
436 dc->realize = xive_source_realize;
437 dc->vmsd = &vmstate_xive_source;
438 }
439
440 static const TypeInfo xive_source_info = {
441 .name = TYPE_XIVE_SOURCE,
442 .parent = TYPE_DEVICE,
443 .instance_size = sizeof(XiveSource),
444 .class_init = xive_source_class_init,
445 };
446
447 /*
448 * XiveEND helpers
449 */
450
451 void xive_end_queue_pic_print_info(XiveEND *end, uint32_t width, Monitor *mon)
452 {
453 uint64_t qaddr_base = (uint64_t) be32_to_cpu(end->w2 & 0x0fffffff) << 32
454 | be32_to_cpu(end->w3);
455 uint32_t qsize = xive_get_field32(END_W0_QSIZE, end->w0);
456 uint32_t qindex = xive_get_field32(END_W1_PAGE_OFF, end->w1);
457 uint32_t qentries = 1 << (qsize + 10);
458 int i;
459
460 /*
461 * print out the [ (qindex - (width - 1)) .. (qindex + 1)] window
462 */
463 monitor_printf(mon, " [ ");
464 qindex = (qindex - (width - 1)) & (qentries - 1);
465 for (i = 0; i < width; i++) {
466 uint64_t qaddr = qaddr_base + (qindex << 2);
467 uint32_t qdata = -1;
468
469 if (dma_memory_read(&address_space_memory, qaddr, &qdata,
470 sizeof(qdata))) {
471 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: failed to read EQ @0x%"
472 HWADDR_PRIx "\n", qaddr);
473 return;
474 }
475 monitor_printf(mon, "%s%08x ", i == width - 1 ? "^" : "",
476 be32_to_cpu(qdata));
477 qindex = (qindex + 1) & (qentries - 1);
478 }
479 }
480
481 void xive_end_pic_print_info(XiveEND *end, uint32_t end_idx, Monitor *mon)
482 {
483 uint64_t qaddr_base = (uint64_t) be32_to_cpu(end->w2 & 0x0fffffff) << 32
484 | be32_to_cpu(end->w3);
485 uint32_t qindex = xive_get_field32(END_W1_PAGE_OFF, end->w1);
486 uint32_t qgen = xive_get_field32(END_W1_GENERATION, end->w1);
487 uint32_t qsize = xive_get_field32(END_W0_QSIZE, end->w0);
488 uint32_t qentries = 1 << (qsize + 10);
489
490 uint32_t nvt = xive_get_field32(END_W6_NVT_INDEX, end->w6);
491 uint8_t priority = xive_get_field32(END_W7_F0_PRIORITY, end->w7);
492
493 if (!xive_end_is_valid(end)) {
494 return;
495 }
496
497 monitor_printf(mon, " %08x %c%c%c%c%c prio:%d nvt:%04x eq:@%08"PRIx64
498 "% 6d/%5d ^%d", end_idx,
499 xive_end_is_valid(end) ? 'v' : '-',
500 xive_end_is_enqueue(end) ? 'q' : '-',
501 xive_end_is_notify(end) ? 'n' : '-',
502 xive_end_is_backlog(end) ? 'b' : '-',
503 xive_end_is_escalate(end) ? 'e' : '-',
504 priority, nvt, qaddr_base, qindex, qentries, qgen);
505
506 xive_end_queue_pic_print_info(end, 6, mon);
507 monitor_printf(mon, "]\n");
508 }
509
510 static void xive_end_enqueue(XiveEND *end, uint32_t data)
511 {
512 uint64_t qaddr_base = (uint64_t) be32_to_cpu(end->w2 & 0x0fffffff) << 32
513 | be32_to_cpu(end->w3);
514 uint32_t qsize = xive_get_field32(END_W0_QSIZE, end->w0);
515 uint32_t qindex = xive_get_field32(END_W1_PAGE_OFF, end->w1);
516 uint32_t qgen = xive_get_field32(END_W1_GENERATION, end->w1);
517
518 uint64_t qaddr = qaddr_base + (qindex << 2);
519 uint32_t qdata = cpu_to_be32((qgen << 31) | (data & 0x7fffffff));
520 uint32_t qentries = 1 << (qsize + 10);
521
522 if (dma_memory_write(&address_space_memory, qaddr, &qdata, sizeof(qdata))) {
523 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: failed to write END data @0x%"
524 HWADDR_PRIx "\n", qaddr);
525 return;
526 }
527
528 qindex = (qindex + 1) & (qentries - 1);
529 if (qindex == 0) {
530 qgen ^= 1;
531 end->w1 = xive_set_field32(END_W1_GENERATION, end->w1, qgen);
532 }
533 end->w1 = xive_set_field32(END_W1_PAGE_OFF, end->w1, qindex);
534 }
535
536 /*
537 * XIVE Router (aka. Virtualization Controller or IVRE)
538 */
539
540 int xive_router_get_eas(XiveRouter *xrtr, uint8_t eas_blk, uint32_t eas_idx,
541 XiveEAS *eas)
542 {
543 XiveRouterClass *xrc = XIVE_ROUTER_GET_CLASS(xrtr);
544
545 return xrc->get_eas(xrtr, eas_blk, eas_idx, eas);
546 }
547
548 int xive_router_get_end(XiveRouter *xrtr, uint8_t end_blk, uint32_t end_idx,
549 XiveEND *end)
550 {
551 XiveRouterClass *xrc = XIVE_ROUTER_GET_CLASS(xrtr);
552
553 return xrc->get_end(xrtr, end_blk, end_idx, end);
554 }
555
556 int xive_router_write_end(XiveRouter *xrtr, uint8_t end_blk, uint32_t end_idx,
557 XiveEND *end, uint8_t word_number)
558 {
559 XiveRouterClass *xrc = XIVE_ROUTER_GET_CLASS(xrtr);
560
561 return xrc->write_end(xrtr, end_blk, end_idx, end, word_number);
562 }
563
564 /*
565 * An END trigger can come from an event trigger (IPI or HW) or from
566 * another chip. We don't model the PowerBus but the END trigger
567 * message has the same parameters than in the function below.
568 */
569 static void xive_router_end_notify(XiveRouter *xrtr, uint8_t end_blk,
570 uint32_t end_idx, uint32_t end_data)
571 {
572 XiveEND end;
573 uint8_t priority;
574 uint8_t format;
575
576 /* END cache lookup */
577 if (xive_router_get_end(xrtr, end_blk, end_idx, &end)) {
578 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: No END %x/%x\n", end_blk,
579 end_idx);
580 return;
581 }
582
583 if (!xive_end_is_valid(&end)) {
584 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: END %x/%x is invalid\n",
585 end_blk, end_idx);
586 return;
587 }
588
589 if (xive_end_is_enqueue(&end)) {
590 xive_end_enqueue(&end, end_data);
591 /* Enqueuing event data modifies the EQ toggle and index */
592 xive_router_write_end(xrtr, end_blk, end_idx, &end, 1);
593 }
594
595 /*
596 * The W7 format depends on the F bit in W6. It defines the type
597 * of the notification :
598 *
599 * F=0 : single or multiple NVT notification
600 * F=1 : User level Event-Based Branch (EBB) notification, no
601 * priority
602 */
603 format = xive_get_field32(END_W6_FORMAT_BIT, end.w6);
604 priority = xive_get_field32(END_W7_F0_PRIORITY, end.w7);
605
606 /* The END is masked */
607 if (format == 0 && priority == 0xff) {
608 return;
609 }
610
611 /*
612 * Check the END ESn (Event State Buffer for notification) for
613 * even futher coalescing in the Router
614 */
615 if (!xive_end_is_notify(&end)) {
616 qemu_log_mask(LOG_UNIMP, "XIVE: !UCOND_NOTIFY not implemented\n");
617 return;
618 }
619
620 /*
621 * Follows IVPE notification
622 */
623 }
624
625 static void xive_router_notify(XiveNotifier *xn, uint32_t lisn)
626 {
627 XiveRouter *xrtr = XIVE_ROUTER(xn);
628 uint8_t eas_blk = XIVE_SRCNO_BLOCK(lisn);
629 uint32_t eas_idx = XIVE_SRCNO_INDEX(lisn);
630 XiveEAS eas;
631
632 /* EAS cache lookup */
633 if (xive_router_get_eas(xrtr, eas_blk, eas_idx, &eas)) {
634 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Unknown LISN %x\n", lisn);
635 return;
636 }
637
638 /*
639 * The IVRE checks the State Bit Cache at this point. We skip the
640 * SBC lookup because the state bits of the sources are modeled
641 * internally in QEMU.
642 */
643
644 if (!xive_eas_is_valid(&eas)) {
645 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid LISN %x\n", lisn);
646 return;
647 }
648
649 if (xive_eas_is_masked(&eas)) {
650 /* Notification completed */
651 return;
652 }
653
654 /*
655 * The event trigger becomes an END trigger
656 */
657 xive_router_end_notify(xrtr,
658 xive_get_field64(EAS_END_BLOCK, eas.w),
659 xive_get_field64(EAS_END_INDEX, eas.w),
660 xive_get_field64(EAS_END_DATA, eas.w));
661 }
662
663 static void xive_router_class_init(ObjectClass *klass, void *data)
664 {
665 DeviceClass *dc = DEVICE_CLASS(klass);
666 XiveNotifierClass *xnc = XIVE_NOTIFIER_CLASS(klass);
667
668 dc->desc = "XIVE Router Engine";
669 xnc->notify = xive_router_notify;
670 }
671
672 static const TypeInfo xive_router_info = {
673 .name = TYPE_XIVE_ROUTER,
674 .parent = TYPE_SYS_BUS_DEVICE,
675 .abstract = true,
676 .class_size = sizeof(XiveRouterClass),
677 .class_init = xive_router_class_init,
678 .interfaces = (InterfaceInfo[]) {
679 { TYPE_XIVE_NOTIFIER },
680 { }
681 }
682 };
683
684 void xive_eas_pic_print_info(XiveEAS *eas, uint32_t lisn, Monitor *mon)
685 {
686 if (!xive_eas_is_valid(eas)) {
687 return;
688 }
689
690 monitor_printf(mon, " %08x %s end:%02x/%04x data:%08x\n",
691 lisn, xive_eas_is_masked(eas) ? "M" : " ",
692 (uint8_t) xive_get_field64(EAS_END_BLOCK, eas->w),
693 (uint32_t) xive_get_field64(EAS_END_INDEX, eas->w),
694 (uint32_t) xive_get_field64(EAS_END_DATA, eas->w));
695 }
696
697 /*
698 * XIVE Fabric
699 */
700 static const TypeInfo xive_fabric_info = {
701 .name = TYPE_XIVE_NOTIFIER,
702 .parent = TYPE_INTERFACE,
703 .class_size = sizeof(XiveNotifierClass),
704 };
705
706 static void xive_register_types(void)
707 {
708 type_register_static(&xive_source_info);
709 type_register_static(&xive_fabric_info);
710 type_register_static(&xive_router_info);
711 }
712
713 type_init(xive_register_types)