block/commit: use QEMU_IOVEC_INIT_BUF
[qemu/ar7.git] / hw / intc / spapr_xive.c
blob290a290e43a54d20215174c325b5e0ce7c48aebf
1 /*
2 * QEMU PowerPC sPAPR XIVE interrupt controller model
4 * Copyright (c) 2017-2018, IBM Corporation.
6 * This code is licensed under the GPL version 2 or later. See the
7 * COPYING file in the top-level directory.
8 */
10 #include "qemu/osdep.h"
11 #include "qemu/log.h"
12 #include "qapi/error.h"
13 #include "qemu/error-report.h"
14 #include "target/ppc/cpu.h"
15 #include "sysemu/cpus.h"
16 #include "monitor/monitor.h"
17 #include "hw/ppc/fdt.h"
18 #include "hw/ppc/spapr.h"
19 #include "hw/ppc/spapr_cpu_core.h"
20 #include "hw/ppc/spapr_xive.h"
21 #include "hw/ppc/xive.h"
22 #include "hw/ppc/xive_regs.h"
25 * XIVE Virtualization Controller BAR and Thread Managment BAR that we
26 * use for the ESB pages and the TIMA pages
28 #define SPAPR_XIVE_VC_BASE 0x0006010000000000ull
29 #define SPAPR_XIVE_TM_BASE 0x0006030203180000ull
32 * The allocation of VP blocks is a complex operation in OPAL and the
33 * VP identifiers have a relation with the number of HW chips, the
34 * size of the VP blocks, VP grouping, etc. The QEMU sPAPR XIVE
35 * controller model does not have the same constraints and can use a
36 * simple mapping scheme of the CPU vcpu_id
38 * These identifiers are never returned to the OS.
41 #define SPAPR_XIVE_NVT_BASE 0x400
44 * The sPAPR machine has a unique XIVE IC device. Assign a fixed value
45 * to the controller block id value. It can nevertheless be changed
46 * for testing purpose.
48 #define SPAPR_XIVE_BLOCK_ID 0x0
51 * sPAPR NVT and END indexing helpers
53 static uint32_t spapr_xive_nvt_to_target(uint8_t nvt_blk, uint32_t nvt_idx)
55 return nvt_idx - SPAPR_XIVE_NVT_BASE;
58 static void spapr_xive_cpu_to_nvt(PowerPCCPU *cpu,
59 uint8_t *out_nvt_blk, uint32_t *out_nvt_idx)
61 assert(cpu);
63 if (out_nvt_blk) {
64 *out_nvt_blk = SPAPR_XIVE_BLOCK_ID;
67 if (out_nvt_blk) {
68 *out_nvt_idx = SPAPR_XIVE_NVT_BASE + cpu->vcpu_id;
72 static int spapr_xive_target_to_nvt(uint32_t target,
73 uint8_t *out_nvt_blk, uint32_t *out_nvt_idx)
75 PowerPCCPU *cpu = spapr_find_cpu(target);
77 if (!cpu) {
78 return -1;
81 spapr_xive_cpu_to_nvt(cpu, out_nvt_blk, out_nvt_idx);
82 return 0;
86 * sPAPR END indexing uses a simple mapping of the CPU vcpu_id, 8
87 * priorities per CPU
89 static void spapr_xive_cpu_to_end(PowerPCCPU *cpu, uint8_t prio,
90 uint8_t *out_end_blk, uint32_t *out_end_idx)
92 assert(cpu);
94 if (out_end_blk) {
95 *out_end_blk = SPAPR_XIVE_BLOCK_ID;
98 if (out_end_idx) {
99 *out_end_idx = (cpu->vcpu_id << 3) + prio;
103 static int spapr_xive_target_to_end(uint32_t target, uint8_t prio,
104 uint8_t *out_end_blk, uint32_t *out_end_idx)
106 PowerPCCPU *cpu = spapr_find_cpu(target);
108 if (!cpu) {
109 return -1;
112 spapr_xive_cpu_to_end(cpu, prio, out_end_blk, out_end_idx);
113 return 0;
117 * On sPAPR machines, use a simplified output for the XIVE END
118 * structure dumping only the information related to the OS EQ.
120 static void spapr_xive_end_pic_print_info(sPAPRXive *xive, XiveEND *end,
121 Monitor *mon)
123 uint32_t qindex = xive_get_field32(END_W1_PAGE_OFF, end->w1);
124 uint32_t qgen = xive_get_field32(END_W1_GENERATION, end->w1);
125 uint32_t qsize = xive_get_field32(END_W0_QSIZE, end->w0);
126 uint32_t qentries = 1 << (qsize + 10);
127 uint32_t nvt = xive_get_field32(END_W6_NVT_INDEX, end->w6);
128 uint8_t priority = xive_get_field32(END_W7_F0_PRIORITY, end->w7);
130 monitor_printf(mon, "%3d/%d % 6d/%5d ^%d",
131 spapr_xive_nvt_to_target(0, nvt),
132 priority, qindex, qentries, qgen);
134 xive_end_queue_pic_print_info(end, 6, mon);
135 monitor_printf(mon, "]");
138 void spapr_xive_pic_print_info(sPAPRXive *xive, Monitor *mon)
140 XiveSource *xsrc = &xive->source;
141 int i;
143 monitor_printf(mon, " LSIN PQ EISN CPU/PRIO EQ\n");
145 for (i = 0; i < xive->nr_irqs; i++) {
146 uint8_t pq = xive_source_esb_get(xsrc, i);
147 XiveEAS *eas = &xive->eat[i];
149 if (!xive_eas_is_valid(eas)) {
150 continue;
153 monitor_printf(mon, " %08x %s %c%c%c %s %08x ", i,
154 xive_source_irq_is_lsi(xsrc, i) ? "LSI" : "MSI",
155 pq & XIVE_ESB_VAL_P ? 'P' : '-',
156 pq & XIVE_ESB_VAL_Q ? 'Q' : '-',
157 xsrc->status[i] & XIVE_STATUS_ASSERTED ? 'A' : ' ',
158 xive_eas_is_masked(eas) ? "M" : " ",
159 (int) xive_get_field64(EAS_END_DATA, eas->w));
161 if (!xive_eas_is_masked(eas)) {
162 uint32_t end_idx = xive_get_field64(EAS_END_INDEX, eas->w);
163 XiveEND *end;
165 assert(end_idx < xive->nr_ends);
166 end = &xive->endt[end_idx];
168 if (xive_end_is_valid(end)) {
169 spapr_xive_end_pic_print_info(xive, end, mon);
172 monitor_printf(mon, "\n");
176 static void spapr_xive_map_mmio(sPAPRXive *xive)
178 sysbus_mmio_map(SYS_BUS_DEVICE(xive), 0, xive->vc_base);
179 sysbus_mmio_map(SYS_BUS_DEVICE(xive), 1, xive->end_base);
180 sysbus_mmio_map(SYS_BUS_DEVICE(xive), 2, xive->tm_base);
183 void spapr_xive_mmio_set_enabled(sPAPRXive *xive, bool enable)
185 memory_region_set_enabled(&xive->source.esb_mmio, enable);
186 memory_region_set_enabled(&xive->tm_mmio, enable);
188 /* Disable the END ESBs until a guest OS makes use of them */
189 memory_region_set_enabled(&xive->end_source.esb_mmio, false);
193 * When a Virtual Processor is scheduled to run on a HW thread, the
194 * hypervisor pushes its identifier in the OS CAM line. Emulate the
195 * same behavior under QEMU.
197 void spapr_xive_set_tctx_os_cam(XiveTCTX *tctx)
199 uint8_t nvt_blk;
200 uint32_t nvt_idx;
201 uint32_t nvt_cam;
203 spapr_xive_cpu_to_nvt(POWERPC_CPU(tctx->cs), &nvt_blk, &nvt_idx);
205 nvt_cam = cpu_to_be32(TM_QW1W2_VO | xive_nvt_cam_line(nvt_blk, nvt_idx));
206 memcpy(&tctx->regs[TM_QW1_OS + TM_WORD2], &nvt_cam, 4);
209 static void spapr_xive_end_reset(XiveEND *end)
211 memset(end, 0, sizeof(*end));
213 /* switch off the escalation and notification ESBs */
214 end->w1 = cpu_to_be32(END_W1_ESe_Q | END_W1_ESn_Q);
217 static void spapr_xive_reset(void *dev)
219 sPAPRXive *xive = SPAPR_XIVE(dev);
220 int i;
223 * The XiveSource has its own reset handler, which mask off all
224 * IRQs (!P|Q)
227 /* Mask all valid EASs in the IRQ number space. */
228 for (i = 0; i < xive->nr_irqs; i++) {
229 XiveEAS *eas = &xive->eat[i];
230 if (xive_eas_is_valid(eas)) {
231 eas->w = cpu_to_be64(EAS_VALID | EAS_MASKED);
232 } else {
233 eas->w = 0;
237 /* Clear all ENDs */
238 for (i = 0; i < xive->nr_ends; i++) {
239 spapr_xive_end_reset(&xive->endt[i]);
243 static void spapr_xive_instance_init(Object *obj)
245 sPAPRXive *xive = SPAPR_XIVE(obj);
247 object_initialize(&xive->source, sizeof(xive->source), TYPE_XIVE_SOURCE);
248 object_property_add_child(obj, "source", OBJECT(&xive->source), NULL);
250 object_initialize(&xive->end_source, sizeof(xive->end_source),
251 TYPE_XIVE_END_SOURCE);
252 object_property_add_child(obj, "end_source", OBJECT(&xive->end_source),
253 NULL);
256 static void spapr_xive_realize(DeviceState *dev, Error **errp)
258 sPAPRXive *xive = SPAPR_XIVE(dev);
259 XiveSource *xsrc = &xive->source;
260 XiveENDSource *end_xsrc = &xive->end_source;
261 Error *local_err = NULL;
263 if (!xive->nr_irqs) {
264 error_setg(errp, "Number of interrupt needs to be greater 0");
265 return;
268 if (!xive->nr_ends) {
269 error_setg(errp, "Number of interrupt needs to be greater 0");
270 return;
274 * Initialize the internal sources, for IPIs and virtual devices.
276 object_property_set_int(OBJECT(xsrc), xive->nr_irqs, "nr-irqs",
277 &error_fatal);
278 object_property_add_const_link(OBJECT(xsrc), "xive", OBJECT(xive),
279 &error_fatal);
280 object_property_set_bool(OBJECT(xsrc), true, "realized", &local_err);
281 if (local_err) {
282 error_propagate(errp, local_err);
283 return;
287 * Initialize the END ESB source
289 object_property_set_int(OBJECT(end_xsrc), xive->nr_irqs, "nr-ends",
290 &error_fatal);
291 object_property_add_const_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
292 &error_fatal);
293 object_property_set_bool(OBJECT(end_xsrc), true, "realized", &local_err);
294 if (local_err) {
295 error_propagate(errp, local_err);
296 return;
299 /* Set the mapping address of the END ESB pages after the source ESBs */
300 xive->end_base = xive->vc_base + (1ull << xsrc->esb_shift) * xsrc->nr_irqs;
303 * Allocate the routing tables
305 xive->eat = g_new0(XiveEAS, xive->nr_irqs);
306 xive->endt = g_new0(XiveEND, xive->nr_ends);
308 /* TIMA initialization */
309 memory_region_init_io(&xive->tm_mmio, OBJECT(xive), &xive_tm_ops, xive,
310 "xive.tima", 4ull << TM_SHIFT);
312 /* Define all XIVE MMIO regions on SysBus */
313 sysbus_init_mmio(SYS_BUS_DEVICE(xive), &xsrc->esb_mmio);
314 sysbus_init_mmio(SYS_BUS_DEVICE(xive), &end_xsrc->esb_mmio);
315 sysbus_init_mmio(SYS_BUS_DEVICE(xive), &xive->tm_mmio);
317 /* Map all regions */
318 spapr_xive_map_mmio(xive);
320 qemu_register_reset(spapr_xive_reset, dev);
323 static int spapr_xive_get_eas(XiveRouter *xrtr, uint8_t eas_blk,
324 uint32_t eas_idx, XiveEAS *eas)
326 sPAPRXive *xive = SPAPR_XIVE(xrtr);
328 if (eas_idx >= xive->nr_irqs) {
329 return -1;
332 *eas = xive->eat[eas_idx];
333 return 0;
336 static int spapr_xive_get_end(XiveRouter *xrtr,
337 uint8_t end_blk, uint32_t end_idx, XiveEND *end)
339 sPAPRXive *xive = SPAPR_XIVE(xrtr);
341 if (end_idx >= xive->nr_ends) {
342 return -1;
345 memcpy(end, &xive->endt[end_idx], sizeof(XiveEND));
346 return 0;
349 static int spapr_xive_write_end(XiveRouter *xrtr, uint8_t end_blk,
350 uint32_t end_idx, XiveEND *end,
351 uint8_t word_number)
353 sPAPRXive *xive = SPAPR_XIVE(xrtr);
355 if (end_idx >= xive->nr_ends) {
356 return -1;
359 memcpy(&xive->endt[end_idx], end, sizeof(XiveEND));
360 return 0;
363 static int spapr_xive_get_nvt(XiveRouter *xrtr,
364 uint8_t nvt_blk, uint32_t nvt_idx, XiveNVT *nvt)
366 uint32_t vcpu_id = spapr_xive_nvt_to_target(nvt_blk, nvt_idx);
367 PowerPCCPU *cpu = spapr_find_cpu(vcpu_id);
369 if (!cpu) {
370 /* TODO: should we assert() if we can find a NVT ? */
371 return -1;
375 * sPAPR does not maintain a NVT table. Return that the NVT is
376 * valid if we have found a matching CPU
378 nvt->w0 = cpu_to_be32(NVT_W0_VALID);
379 return 0;
382 static int spapr_xive_write_nvt(XiveRouter *xrtr, uint8_t nvt_blk,
383 uint32_t nvt_idx, XiveNVT *nvt,
384 uint8_t word_number)
387 * We don't need to write back to the NVTs because the sPAPR
388 * machine should never hit a non-scheduled NVT. It should never
389 * get called.
391 g_assert_not_reached();
394 static XiveTCTX *spapr_xive_get_tctx(XiveRouter *xrtr, CPUState *cs)
396 PowerPCCPU *cpu = POWERPC_CPU(cs);
398 return spapr_cpu_state(cpu)->tctx;
401 static const VMStateDescription vmstate_spapr_xive_end = {
402 .name = TYPE_SPAPR_XIVE "/end",
403 .version_id = 1,
404 .minimum_version_id = 1,
405 .fields = (VMStateField []) {
406 VMSTATE_UINT32(w0, XiveEND),
407 VMSTATE_UINT32(w1, XiveEND),
408 VMSTATE_UINT32(w2, XiveEND),
409 VMSTATE_UINT32(w3, XiveEND),
410 VMSTATE_UINT32(w4, XiveEND),
411 VMSTATE_UINT32(w5, XiveEND),
412 VMSTATE_UINT32(w6, XiveEND),
413 VMSTATE_UINT32(w7, XiveEND),
414 VMSTATE_END_OF_LIST()
418 static const VMStateDescription vmstate_spapr_xive_eas = {
419 .name = TYPE_SPAPR_XIVE "/eas",
420 .version_id = 1,
421 .minimum_version_id = 1,
422 .fields = (VMStateField []) {
423 VMSTATE_UINT64(w, XiveEAS),
424 VMSTATE_END_OF_LIST()
428 static const VMStateDescription vmstate_spapr_xive = {
429 .name = TYPE_SPAPR_XIVE,
430 .version_id = 1,
431 .minimum_version_id = 1,
432 .fields = (VMStateField[]) {
433 VMSTATE_UINT32_EQUAL(nr_irqs, sPAPRXive, NULL),
434 VMSTATE_STRUCT_VARRAY_POINTER_UINT32(eat, sPAPRXive, nr_irqs,
435 vmstate_spapr_xive_eas, XiveEAS),
436 VMSTATE_STRUCT_VARRAY_POINTER_UINT32(endt, sPAPRXive, nr_ends,
437 vmstate_spapr_xive_end, XiveEND),
438 VMSTATE_END_OF_LIST()
442 static Property spapr_xive_properties[] = {
443 DEFINE_PROP_UINT32("nr-irqs", sPAPRXive, nr_irqs, 0),
444 DEFINE_PROP_UINT32("nr-ends", sPAPRXive, nr_ends, 0),
445 DEFINE_PROP_UINT64("vc-base", sPAPRXive, vc_base, SPAPR_XIVE_VC_BASE),
446 DEFINE_PROP_UINT64("tm-base", sPAPRXive, tm_base, SPAPR_XIVE_TM_BASE),
447 DEFINE_PROP_END_OF_LIST(),
450 static void spapr_xive_class_init(ObjectClass *klass, void *data)
452 DeviceClass *dc = DEVICE_CLASS(klass);
453 XiveRouterClass *xrc = XIVE_ROUTER_CLASS(klass);
455 dc->desc = "sPAPR XIVE Interrupt Controller";
456 dc->props = spapr_xive_properties;
457 dc->realize = spapr_xive_realize;
458 dc->vmsd = &vmstate_spapr_xive;
460 xrc->get_eas = spapr_xive_get_eas;
461 xrc->get_end = spapr_xive_get_end;
462 xrc->write_end = spapr_xive_write_end;
463 xrc->get_nvt = spapr_xive_get_nvt;
464 xrc->write_nvt = spapr_xive_write_nvt;
465 xrc->get_tctx = spapr_xive_get_tctx;
468 static const TypeInfo spapr_xive_info = {
469 .name = TYPE_SPAPR_XIVE,
470 .parent = TYPE_XIVE_ROUTER,
471 .instance_init = spapr_xive_instance_init,
472 .instance_size = sizeof(sPAPRXive),
473 .class_init = spapr_xive_class_init,
476 static void spapr_xive_register_types(void)
478 type_register_static(&spapr_xive_info);
481 type_init(spapr_xive_register_types)
483 bool spapr_xive_irq_claim(sPAPRXive *xive, uint32_t lisn, bool lsi)
485 XiveSource *xsrc = &xive->source;
487 if (lisn >= xive->nr_irqs) {
488 return false;
491 xive->eat[lisn].w |= cpu_to_be64(EAS_VALID);
492 if (lsi) {
493 xive_source_irq_set_lsi(xsrc, lisn);
495 return true;
498 bool spapr_xive_irq_free(sPAPRXive *xive, uint32_t lisn)
500 if (lisn >= xive->nr_irqs) {
501 return false;
504 xive->eat[lisn].w &= cpu_to_be64(~EAS_VALID);
505 return true;
509 * XIVE hcalls
511 * The terminology used by the XIVE hcalls is the following :
513 * TARGET vCPU number
514 * EQ Event Queue assigned by OS to receive event data
515 * ESB page for source interrupt management
516 * LISN Logical Interrupt Source Number identifying a source in the
517 * machine
518 * EISN Effective Interrupt Source Number used by guest OS to
519 * identify source in the guest
521 * The EAS, END, NVT structures are not exposed.
525 * Linux hosts under OPAL reserve priority 7 for their own escalation
526 * interrupts (DD2.X POWER9). So we only allow the guest to use
527 * priorities [0..6].
529 static bool spapr_xive_priority_is_reserved(uint8_t priority)
531 switch (priority) {
532 case 0 ... 6:
533 return false;
534 case 7: /* OPAL escalation queue */
535 default:
536 return true;
541 * The H_INT_GET_SOURCE_INFO hcall() is used to obtain the logical
542 * real address of the MMIO page through which the Event State Buffer
543 * entry associated with the value of the "lisn" parameter is managed.
545 * Parameters:
546 * Input
547 * - R4: "flags"
548 * Bits 0-63 reserved
549 * - R5: "lisn" is per "interrupts", "interrupt-map", or
550 * "ibm,xive-lisn-ranges" properties, or as returned by the
551 * ibm,query-interrupt-source-number RTAS call, or as returned
552 * by the H_ALLOCATE_VAS_WINDOW hcall
554 * Output
555 * - R4: "flags"
556 * Bits 0-59: Reserved
557 * Bit 60: H_INT_ESB must be used for Event State Buffer
558 * management
559 * Bit 61: 1 == LSI 0 == MSI
560 * Bit 62: the full function page supports trigger
561 * Bit 63: Store EOI Supported
562 * - R5: Logical Real address of full function Event State Buffer
563 * management page, -1 if H_INT_ESB hcall flag is set to 1.
564 * - R6: Logical Real Address of trigger only Event State Buffer
565 * management page or -1.
566 * - R7: Power of 2 page size for the ESB management pages returned in
567 * R5 and R6.
570 #define SPAPR_XIVE_SRC_H_INT_ESB PPC_BIT(60) /* ESB manage with H_INT_ESB */
571 #define SPAPR_XIVE_SRC_LSI PPC_BIT(61) /* Virtual LSI type */
572 #define SPAPR_XIVE_SRC_TRIGGER PPC_BIT(62) /* Trigger and management
573 on same page */
574 #define SPAPR_XIVE_SRC_STORE_EOI PPC_BIT(63) /* Store EOI support */
576 static target_ulong h_int_get_source_info(PowerPCCPU *cpu,
577 sPAPRMachineState *spapr,
578 target_ulong opcode,
579 target_ulong *args)
581 sPAPRXive *xive = spapr->xive;
582 XiveSource *xsrc = &xive->source;
583 target_ulong flags = args[0];
584 target_ulong lisn = args[1];
586 if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
587 return H_FUNCTION;
590 if (flags) {
591 return H_PARAMETER;
594 if (lisn >= xive->nr_irqs) {
595 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Unknown LISN " TARGET_FMT_lx "\n",
596 lisn);
597 return H_P2;
600 if (!xive_eas_is_valid(&xive->eat[lisn])) {
601 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid LISN " TARGET_FMT_lx "\n",
602 lisn);
603 return H_P2;
607 * All sources are emulated under the main XIVE object and share
608 * the same characteristics.
610 args[0] = 0;
611 if (!xive_source_esb_has_2page(xsrc)) {
612 args[0] |= SPAPR_XIVE_SRC_TRIGGER;
614 if (xsrc->esb_flags & XIVE_SRC_STORE_EOI) {
615 args[0] |= SPAPR_XIVE_SRC_STORE_EOI;
619 * Force the use of the H_INT_ESB hcall in case of an LSI
620 * interrupt. This is necessary under KVM to re-trigger the
621 * interrupt if the level is still asserted
623 if (xive_source_irq_is_lsi(xsrc, lisn)) {
624 args[0] |= SPAPR_XIVE_SRC_H_INT_ESB | SPAPR_XIVE_SRC_LSI;
627 if (!(args[0] & SPAPR_XIVE_SRC_H_INT_ESB)) {
628 args[1] = xive->vc_base + xive_source_esb_mgmt(xsrc, lisn);
629 } else {
630 args[1] = -1;
633 if (xive_source_esb_has_2page(xsrc) &&
634 !(args[0] & SPAPR_XIVE_SRC_H_INT_ESB)) {
635 args[2] = xive->vc_base + xive_source_esb_page(xsrc, lisn);
636 } else {
637 args[2] = -1;
640 if (xive_source_esb_has_2page(xsrc)) {
641 args[3] = xsrc->esb_shift - 1;
642 } else {
643 args[3] = xsrc->esb_shift;
646 return H_SUCCESS;
650 * The H_INT_SET_SOURCE_CONFIG hcall() is used to assign a Logical
651 * Interrupt Source to a target. The Logical Interrupt Source is
652 * designated with the "lisn" parameter and the target is designated
653 * with the "target" and "priority" parameters. Upon return from the
654 * hcall(), no additional interrupts will be directed to the old EQ.
656 * Parameters:
657 * Input:
658 * - R4: "flags"
659 * Bits 0-61: Reserved
660 * Bit 62: set the "eisn" in the EAS
661 * Bit 63: masks the interrupt source in the hardware interrupt
662 * control structure. An interrupt masked by this mechanism will
663 * be dropped, but it's source state bits will still be
664 * set. There is no race-free way of unmasking and restoring the
665 * source. Thus this should only be used in interrupts that are
666 * also masked at the source, and only in cases where the
667 * interrupt is not meant to be used for a large amount of time
668 * because no valid target exists for it for example
669 * - R5: "lisn" is per "interrupts", "interrupt-map", or
670 * "ibm,xive-lisn-ranges" properties, or as returned by the
671 * ibm,query-interrupt-source-number RTAS call, or as returned by
672 * the H_ALLOCATE_VAS_WINDOW hcall
673 * - R6: "target" is per "ibm,ppc-interrupt-server#s" or
674 * "ibm,ppc-interrupt-gserver#s"
675 * - R7: "priority" is a valid priority not in
676 * "ibm,plat-res-int-priorities"
677 * - R8: "eisn" is the guest EISN associated with the "lisn"
679 * Output:
680 * - None
683 #define SPAPR_XIVE_SRC_SET_EISN PPC_BIT(62)
684 #define SPAPR_XIVE_SRC_MASK PPC_BIT(63)
686 static target_ulong h_int_set_source_config(PowerPCCPU *cpu,
687 sPAPRMachineState *spapr,
688 target_ulong opcode,
689 target_ulong *args)
691 sPAPRXive *xive = spapr->xive;
692 XiveEAS eas, new_eas;
693 target_ulong flags = args[0];
694 target_ulong lisn = args[1];
695 target_ulong target = args[2];
696 target_ulong priority = args[3];
697 target_ulong eisn = args[4];
698 uint8_t end_blk;
699 uint32_t end_idx;
701 if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
702 return H_FUNCTION;
705 if (flags & ~(SPAPR_XIVE_SRC_SET_EISN | SPAPR_XIVE_SRC_MASK)) {
706 return H_PARAMETER;
709 if (lisn >= xive->nr_irqs) {
710 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Unknown LISN " TARGET_FMT_lx "\n",
711 lisn);
712 return H_P2;
715 eas = xive->eat[lisn];
716 if (!xive_eas_is_valid(&eas)) {
717 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid LISN " TARGET_FMT_lx "\n",
718 lisn);
719 return H_P2;
722 /* priority 0xff is used to reset the EAS */
723 if (priority == 0xff) {
724 new_eas.w = cpu_to_be64(EAS_VALID | EAS_MASKED);
725 goto out;
728 if (flags & SPAPR_XIVE_SRC_MASK) {
729 new_eas.w = eas.w | cpu_to_be64(EAS_MASKED);
730 } else {
731 new_eas.w = eas.w & cpu_to_be64(~EAS_MASKED);
734 if (spapr_xive_priority_is_reserved(priority)) {
735 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: priority " TARGET_FMT_ld
736 " is reserved\n", priority);
737 return H_P4;
741 * Validate that "target" is part of the list of threads allocated
742 * to the partition. For that, find the END corresponding to the
743 * target.
745 if (spapr_xive_target_to_end(target, priority, &end_blk, &end_idx)) {
746 return H_P3;
749 new_eas.w = xive_set_field64(EAS_END_BLOCK, new_eas.w, end_blk);
750 new_eas.w = xive_set_field64(EAS_END_INDEX, new_eas.w, end_idx);
752 if (flags & SPAPR_XIVE_SRC_SET_EISN) {
753 new_eas.w = xive_set_field64(EAS_END_DATA, new_eas.w, eisn);
756 out:
757 xive->eat[lisn] = new_eas;
758 return H_SUCCESS;
762 * The H_INT_GET_SOURCE_CONFIG hcall() is used to determine to which
763 * target/priority pair is assigned to the specified Logical Interrupt
764 * Source.
766 * Parameters:
767 * Input:
768 * - R4: "flags"
769 * Bits 0-63 Reserved
770 * - R5: "lisn" is per "interrupts", "interrupt-map", or
771 * "ibm,xive-lisn-ranges" properties, or as returned by the
772 * ibm,query-interrupt-source-number RTAS call, or as
773 * returned by the H_ALLOCATE_VAS_WINDOW hcall
775 * Output:
776 * - R4: Target to which the specified Logical Interrupt Source is
777 * assigned
778 * - R5: Priority to which the specified Logical Interrupt Source is
779 * assigned
780 * - R6: EISN for the specified Logical Interrupt Source (this will be
781 * equivalent to the LISN if not changed by H_INT_SET_SOURCE_CONFIG)
783 static target_ulong h_int_get_source_config(PowerPCCPU *cpu,
784 sPAPRMachineState *spapr,
785 target_ulong opcode,
786 target_ulong *args)
788 sPAPRXive *xive = spapr->xive;
789 target_ulong flags = args[0];
790 target_ulong lisn = args[1];
791 XiveEAS eas;
792 XiveEND *end;
793 uint8_t nvt_blk;
794 uint32_t end_idx, nvt_idx;
796 if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
797 return H_FUNCTION;
800 if (flags) {
801 return H_PARAMETER;
804 if (lisn >= xive->nr_irqs) {
805 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Unknown LISN " TARGET_FMT_lx "\n",
806 lisn);
807 return H_P2;
810 eas = xive->eat[lisn];
811 if (!xive_eas_is_valid(&eas)) {
812 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid LISN " TARGET_FMT_lx "\n",
813 lisn);
814 return H_P2;
817 /* EAS_END_BLOCK is unused on sPAPR */
818 end_idx = xive_get_field64(EAS_END_INDEX, eas.w);
820 assert(end_idx < xive->nr_ends);
821 end = &xive->endt[end_idx];
823 nvt_blk = xive_get_field32(END_W6_NVT_BLOCK, end->w6);
824 nvt_idx = xive_get_field32(END_W6_NVT_INDEX, end->w6);
825 args[0] = spapr_xive_nvt_to_target(nvt_blk, nvt_idx);
827 if (xive_eas_is_masked(&eas)) {
828 args[1] = 0xff;
829 } else {
830 args[1] = xive_get_field32(END_W7_F0_PRIORITY, end->w7);
833 args[2] = xive_get_field64(EAS_END_DATA, eas.w);
835 return H_SUCCESS;
839 * The H_INT_GET_QUEUE_INFO hcall() is used to get the logical real
840 * address of the notification management page associated with the
841 * specified target and priority.
843 * Parameters:
844 * Input:
845 * - R4: "flags"
846 * Bits 0-63 Reserved
847 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
848 * "ibm,ppc-interrupt-gserver#s"
849 * - R6: "priority" is a valid priority not in
850 * "ibm,plat-res-int-priorities"
852 * Output:
853 * - R4: Logical real address of notification page
854 * - R5: Power of 2 page size of the notification page
856 static target_ulong h_int_get_queue_info(PowerPCCPU *cpu,
857 sPAPRMachineState *spapr,
858 target_ulong opcode,
859 target_ulong *args)
861 sPAPRXive *xive = spapr->xive;
862 XiveENDSource *end_xsrc = &xive->end_source;
863 target_ulong flags = args[0];
864 target_ulong target = args[1];
865 target_ulong priority = args[2];
866 XiveEND *end;
867 uint8_t end_blk;
868 uint32_t end_idx;
870 if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
871 return H_FUNCTION;
874 if (flags) {
875 return H_PARAMETER;
879 * H_STATE should be returned if a H_INT_RESET is in progress.
880 * This is not needed when running the emulation under QEMU
883 if (spapr_xive_priority_is_reserved(priority)) {
884 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: priority " TARGET_FMT_ld
885 " is reserved\n", priority);
886 return H_P3;
890 * Validate that "target" is part of the list of threads allocated
891 * to the partition. For that, find the END corresponding to the
892 * target.
894 if (spapr_xive_target_to_end(target, priority, &end_blk, &end_idx)) {
895 return H_P2;
898 assert(end_idx < xive->nr_ends);
899 end = &xive->endt[end_idx];
901 args[0] = xive->end_base + (1ull << (end_xsrc->esb_shift + 1)) * end_idx;
902 if (xive_end_is_enqueue(end)) {
903 args[1] = xive_get_field32(END_W0_QSIZE, end->w0) + 12;
904 } else {
905 args[1] = 0;
908 return H_SUCCESS;
912 * The H_INT_SET_QUEUE_CONFIG hcall() is used to set or reset a EQ for
913 * a given "target" and "priority". It is also used to set the
914 * notification config associated with the EQ. An EQ size of 0 is
915 * used to reset the EQ config for a given target and priority. If
916 * resetting the EQ config, the END associated with the given "target"
917 * and "priority" will be changed to disable queueing.
919 * Upon return from the hcall(), no additional interrupts will be
920 * directed to the old EQ (if one was set). The old EQ (if one was
921 * set) should be investigated for interrupts that occurred prior to
922 * or during the hcall().
924 * Parameters:
925 * Input:
926 * - R4: "flags"
927 * Bits 0-62: Reserved
928 * Bit 63: Unconditional Notify (n) per the XIVE spec
929 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
930 * "ibm,ppc-interrupt-gserver#s"
931 * - R6: "priority" is a valid priority not in
932 * "ibm,plat-res-int-priorities"
933 * - R7: "eventQueue": The logical real address of the start of the EQ
934 * - R8: "eventQueueSize": The power of 2 EQ size per "ibm,xive-eq-sizes"
936 * Output:
937 * - None
940 #define SPAPR_XIVE_END_ALWAYS_NOTIFY PPC_BIT(63)
942 static target_ulong h_int_set_queue_config(PowerPCCPU *cpu,
943 sPAPRMachineState *spapr,
944 target_ulong opcode,
945 target_ulong *args)
947 sPAPRXive *xive = spapr->xive;
948 target_ulong flags = args[0];
949 target_ulong target = args[1];
950 target_ulong priority = args[2];
951 target_ulong qpage = args[3];
952 target_ulong qsize = args[4];
953 XiveEND end;
954 uint8_t end_blk, nvt_blk;
955 uint32_t end_idx, nvt_idx;
957 if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
958 return H_FUNCTION;
961 if (flags & ~SPAPR_XIVE_END_ALWAYS_NOTIFY) {
962 return H_PARAMETER;
966 * H_STATE should be returned if a H_INT_RESET is in progress.
967 * This is not needed when running the emulation under QEMU
970 if (spapr_xive_priority_is_reserved(priority)) {
971 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: priority " TARGET_FMT_ld
972 " is reserved\n", priority);
973 return H_P3;
977 * Validate that "target" is part of the list of threads allocated
978 * to the partition. For that, find the END corresponding to the
979 * target.
982 if (spapr_xive_target_to_end(target, priority, &end_blk, &end_idx)) {
983 return H_P2;
986 assert(end_idx < xive->nr_ends);
987 memcpy(&end, &xive->endt[end_idx], sizeof(XiveEND));
989 switch (qsize) {
990 case 12:
991 case 16:
992 case 21:
993 case 24:
994 end.w2 = cpu_to_be32((qpage >> 32) & 0x0fffffff);
995 end.w3 = cpu_to_be32(qpage & 0xffffffff);
996 end.w0 |= cpu_to_be32(END_W0_ENQUEUE);
997 end.w0 = xive_set_field32(END_W0_QSIZE, end.w0, qsize - 12);
998 break;
999 case 0:
1000 /* reset queue and disable queueing */
1001 spapr_xive_end_reset(&end);
1002 goto out;
1004 default:
1005 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid EQ size %"PRIx64"\n",
1006 qsize);
1007 return H_P5;
1010 if (qsize) {
1011 hwaddr plen = 1 << qsize;
1012 void *eq;
1015 * Validate the guest EQ. We should also check that the queue
1016 * has been zeroed by the OS.
1018 eq = address_space_map(CPU(cpu)->as, qpage, &plen, true,
1019 MEMTXATTRS_UNSPECIFIED);
1020 if (plen != 1 << qsize) {
1021 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: failed to map EQ @0x%"
1022 HWADDR_PRIx "\n", qpage);
1023 return H_P4;
1025 address_space_unmap(CPU(cpu)->as, eq, plen, true, plen);
1028 /* "target" should have been validated above */
1029 if (spapr_xive_target_to_nvt(target, &nvt_blk, &nvt_idx)) {
1030 g_assert_not_reached();
1034 * Ensure the priority and target are correctly set (they will not
1035 * be right after allocation)
1037 end.w6 = xive_set_field32(END_W6_NVT_BLOCK, 0ul, nvt_blk) |
1038 xive_set_field32(END_W6_NVT_INDEX, 0ul, nvt_idx);
1039 end.w7 = xive_set_field32(END_W7_F0_PRIORITY, 0ul, priority);
1041 if (flags & SPAPR_XIVE_END_ALWAYS_NOTIFY) {
1042 end.w0 |= cpu_to_be32(END_W0_UCOND_NOTIFY);
1043 } else {
1044 end.w0 &= cpu_to_be32((uint32_t)~END_W0_UCOND_NOTIFY);
1048 * The generation bit for the END starts at 1 and The END page
1049 * offset counter starts at 0.
1051 end.w1 = cpu_to_be32(END_W1_GENERATION) |
1052 xive_set_field32(END_W1_PAGE_OFF, 0ul, 0ul);
1053 end.w0 |= cpu_to_be32(END_W0_VALID);
1056 * TODO: issue syncs required to ensure all in-flight interrupts
1057 * are complete on the old END
1060 out:
1061 /* Update END */
1062 memcpy(&xive->endt[end_idx], &end, sizeof(XiveEND));
1063 return H_SUCCESS;
1067 * The H_INT_GET_QUEUE_CONFIG hcall() is used to get a EQ for a given
1068 * target and priority.
1070 * Parameters:
1071 * Input:
1072 * - R4: "flags"
1073 * Bits 0-62: Reserved
1074 * Bit 63: Debug: Return debug data
1075 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
1076 * "ibm,ppc-interrupt-gserver#s"
1077 * - R6: "priority" is a valid priority not in
1078 * "ibm,plat-res-int-priorities"
1080 * Output:
1081 * - R4: "flags":
1082 * Bits 0-61: Reserved
1083 * Bit 62: The value of Event Queue Generation Number (g) per
1084 * the XIVE spec if "Debug" = 1
1085 * Bit 63: The value of Unconditional Notify (n) per the XIVE spec
1086 * - R5: The logical real address of the start of the EQ
1087 * - R6: The power of 2 EQ size per "ibm,xive-eq-sizes"
1088 * - R7: The value of Event Queue Offset Counter per XIVE spec
1089 * if "Debug" = 1, else 0
1093 #define SPAPR_XIVE_END_DEBUG PPC_BIT(63)
1095 static target_ulong h_int_get_queue_config(PowerPCCPU *cpu,
1096 sPAPRMachineState *spapr,
1097 target_ulong opcode,
1098 target_ulong *args)
1100 sPAPRXive *xive = spapr->xive;
1101 target_ulong flags = args[0];
1102 target_ulong target = args[1];
1103 target_ulong priority = args[2];
1104 XiveEND *end;
1105 uint8_t end_blk;
1106 uint32_t end_idx;
1108 if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
1109 return H_FUNCTION;
1112 if (flags & ~SPAPR_XIVE_END_DEBUG) {
1113 return H_PARAMETER;
1117 * H_STATE should be returned if a H_INT_RESET is in progress.
1118 * This is not needed when running the emulation under QEMU
1121 if (spapr_xive_priority_is_reserved(priority)) {
1122 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: priority " TARGET_FMT_ld
1123 " is reserved\n", priority);
1124 return H_P3;
1128 * Validate that "target" is part of the list of threads allocated
1129 * to the partition. For that, find the END corresponding to the
1130 * target.
1132 if (spapr_xive_target_to_end(target, priority, &end_blk, &end_idx)) {
1133 return H_P2;
1136 assert(end_idx < xive->nr_ends);
1137 end = &xive->endt[end_idx];
1139 args[0] = 0;
1140 if (xive_end_is_notify(end)) {
1141 args[0] |= SPAPR_XIVE_END_ALWAYS_NOTIFY;
1144 if (xive_end_is_enqueue(end)) {
1145 args[1] = (uint64_t) be32_to_cpu(end->w2 & 0x0fffffff) << 32
1146 | be32_to_cpu(end->w3);
1147 args[2] = xive_get_field32(END_W0_QSIZE, end->w0) + 12;
1148 } else {
1149 args[1] = 0;
1150 args[2] = 0;
1153 /* TODO: do we need any locking on the END ? */
1154 if (flags & SPAPR_XIVE_END_DEBUG) {
1155 /* Load the event queue generation number into the return flags */
1156 args[0] |= (uint64_t)xive_get_field32(END_W1_GENERATION, end->w1) << 62;
1158 /* Load R7 with the event queue offset counter */
1159 args[3] = xive_get_field32(END_W1_PAGE_OFF, end->w1);
1160 } else {
1161 args[3] = 0;
1164 return H_SUCCESS;
1168 * The H_INT_SET_OS_REPORTING_LINE hcall() is used to set the
1169 * reporting cache line pair for the calling thread. The reporting
1170 * cache lines will contain the OS interrupt context when the OS
1171 * issues a CI store byte to @TIMA+0xC10 to acknowledge the OS
1172 * interrupt. The reporting cache lines can be reset by inputting -1
1173 * in "reportingLine". Issuing the CI store byte without reporting
1174 * cache lines registered will result in the data not being accessible
1175 * to the OS.
1177 * Parameters:
1178 * Input:
1179 * - R4: "flags"
1180 * Bits 0-63: Reserved
1181 * - R5: "reportingLine": The logical real address of the reporting cache
1182 * line pair
1184 * Output:
1185 * - None
1187 static target_ulong h_int_set_os_reporting_line(PowerPCCPU *cpu,
1188 sPAPRMachineState *spapr,
1189 target_ulong opcode,
1190 target_ulong *args)
1192 if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
1193 return H_FUNCTION;
1197 * H_STATE should be returned if a H_INT_RESET is in progress.
1198 * This is not needed when running the emulation under QEMU
1201 /* TODO: H_INT_SET_OS_REPORTING_LINE */
1202 return H_FUNCTION;
1206 * The H_INT_GET_OS_REPORTING_LINE hcall() is used to get the logical
1207 * real address of the reporting cache line pair set for the input
1208 * "target". If no reporting cache line pair has been set, -1 is
1209 * returned.
1211 * Parameters:
1212 * Input:
1213 * - R4: "flags"
1214 * Bits 0-63: Reserved
1215 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
1216 * "ibm,ppc-interrupt-gserver#s"
1217 * - R6: "reportingLine": The logical real address of the reporting
1218 * cache line pair
1220 * Output:
1221 * - R4: The logical real address of the reporting line if set, else -1
1223 static target_ulong h_int_get_os_reporting_line(PowerPCCPU *cpu,
1224 sPAPRMachineState *spapr,
1225 target_ulong opcode,
1226 target_ulong *args)
1228 if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
1229 return H_FUNCTION;
1233 * H_STATE should be returned if a H_INT_RESET is in progress.
1234 * This is not needed when running the emulation under QEMU
1237 /* TODO: H_INT_GET_OS_REPORTING_LINE */
1238 return H_FUNCTION;
1242 * The H_INT_ESB hcall() is used to issue a load or store to the ESB
1243 * page for the input "lisn". This hcall is only supported for LISNs
1244 * that have the ESB hcall flag set to 1 when returned from hcall()
1245 * H_INT_GET_SOURCE_INFO.
1247 * Parameters:
1248 * Input:
1249 * - R4: "flags"
1250 * Bits 0-62: Reserved
1251 * bit 63: Store: Store=1, store operation, else load operation
1252 * - R5: "lisn" is per "interrupts", "interrupt-map", or
1253 * "ibm,xive-lisn-ranges" properties, or as returned by the
1254 * ibm,query-interrupt-source-number RTAS call, or as
1255 * returned by the H_ALLOCATE_VAS_WINDOW hcall
1256 * - R6: "esbOffset" is the offset into the ESB page for the load or
1257 * store operation
1258 * - R7: "storeData" is the data to write for a store operation
1260 * Output:
1261 * - R4: The value of the load if load operation, else -1
1264 #define SPAPR_XIVE_ESB_STORE PPC_BIT(63)
1266 static target_ulong h_int_esb(PowerPCCPU *cpu,
1267 sPAPRMachineState *spapr,
1268 target_ulong opcode,
1269 target_ulong *args)
1271 sPAPRXive *xive = spapr->xive;
1272 XiveEAS eas;
1273 target_ulong flags = args[0];
1274 target_ulong lisn = args[1];
1275 target_ulong offset = args[2];
1276 target_ulong data = args[3];
1277 hwaddr mmio_addr;
1278 XiveSource *xsrc = &xive->source;
1280 if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
1281 return H_FUNCTION;
1284 if (flags & ~SPAPR_XIVE_ESB_STORE) {
1285 return H_PARAMETER;
1288 if (lisn >= xive->nr_irqs) {
1289 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Unknown LISN " TARGET_FMT_lx "\n",
1290 lisn);
1291 return H_P2;
1294 eas = xive->eat[lisn];
1295 if (!xive_eas_is_valid(&eas)) {
1296 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid LISN " TARGET_FMT_lx "\n",
1297 lisn);
1298 return H_P2;
1301 if (offset > (1ull << xsrc->esb_shift)) {
1302 return H_P3;
1305 mmio_addr = xive->vc_base + xive_source_esb_mgmt(xsrc, lisn) + offset;
1307 if (dma_memory_rw(&address_space_memory, mmio_addr, &data, 8,
1308 (flags & SPAPR_XIVE_ESB_STORE))) {
1309 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: failed to access ESB @0x%"
1310 HWADDR_PRIx "\n", mmio_addr);
1311 return H_HARDWARE;
1313 args[0] = (flags & SPAPR_XIVE_ESB_STORE) ? -1 : data;
1314 return H_SUCCESS;
1318 * The H_INT_SYNC hcall() is used to issue hardware syncs that will
1319 * ensure any in flight events for the input lisn are in the event
1320 * queue.
1322 * Parameters:
1323 * Input:
1324 * - R4: "flags"
1325 * Bits 0-63: Reserved
1326 * - R5: "lisn" is per "interrupts", "interrupt-map", or
1327 * "ibm,xive-lisn-ranges" properties, or as returned by the
1328 * ibm,query-interrupt-source-number RTAS call, or as
1329 * returned by the H_ALLOCATE_VAS_WINDOW hcall
1331 * Output:
1332 * - None
1334 static target_ulong h_int_sync(PowerPCCPU *cpu,
1335 sPAPRMachineState *spapr,
1336 target_ulong opcode,
1337 target_ulong *args)
1339 sPAPRXive *xive = spapr->xive;
1340 XiveEAS eas;
1341 target_ulong flags = args[0];
1342 target_ulong lisn = args[1];
1344 if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
1345 return H_FUNCTION;
1348 if (flags) {
1349 return H_PARAMETER;
1352 if (lisn >= xive->nr_irqs) {
1353 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Unknown LISN " TARGET_FMT_lx "\n",
1354 lisn);
1355 return H_P2;
1358 eas = xive->eat[lisn];
1359 if (!xive_eas_is_valid(&eas)) {
1360 qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid LISN " TARGET_FMT_lx "\n",
1361 lisn);
1362 return H_P2;
1366 * H_STATE should be returned if a H_INT_RESET is in progress.
1367 * This is not needed when running the emulation under QEMU
1370 /* This is not real hardware. Nothing to be done */
1371 return H_SUCCESS;
1375 * The H_INT_RESET hcall() is used to reset all of the partition's
1376 * interrupt exploitation structures to their initial state. This
1377 * means losing all previously set interrupt state set via
1378 * H_INT_SET_SOURCE_CONFIG and H_INT_SET_QUEUE_CONFIG.
1380 * Parameters:
1381 * Input:
1382 * - R4: "flags"
1383 * Bits 0-63: Reserved
1385 * Output:
1386 * - None
1388 static target_ulong h_int_reset(PowerPCCPU *cpu,
1389 sPAPRMachineState *spapr,
1390 target_ulong opcode,
1391 target_ulong *args)
1393 sPAPRXive *xive = spapr->xive;
1394 target_ulong flags = args[0];
1396 if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
1397 return H_FUNCTION;
1400 if (flags) {
1401 return H_PARAMETER;
1404 device_reset(DEVICE(xive));
1405 return H_SUCCESS;
1408 void spapr_xive_hcall_init(sPAPRMachineState *spapr)
1410 spapr_register_hypercall(H_INT_GET_SOURCE_INFO, h_int_get_source_info);
1411 spapr_register_hypercall(H_INT_SET_SOURCE_CONFIG, h_int_set_source_config);
1412 spapr_register_hypercall(H_INT_GET_SOURCE_CONFIG, h_int_get_source_config);
1413 spapr_register_hypercall(H_INT_GET_QUEUE_INFO, h_int_get_queue_info);
1414 spapr_register_hypercall(H_INT_SET_QUEUE_CONFIG, h_int_set_queue_config);
1415 spapr_register_hypercall(H_INT_GET_QUEUE_CONFIG, h_int_get_queue_config);
1416 spapr_register_hypercall(H_INT_SET_OS_REPORTING_LINE,
1417 h_int_set_os_reporting_line);
1418 spapr_register_hypercall(H_INT_GET_OS_REPORTING_LINE,
1419 h_int_get_os_reporting_line);
1420 spapr_register_hypercall(H_INT_ESB, h_int_esb);
1421 spapr_register_hypercall(H_INT_SYNC, h_int_sync);
1422 spapr_register_hypercall(H_INT_RESET, h_int_reset);
1425 void spapr_dt_xive(sPAPRMachineState *spapr, uint32_t nr_servers, void *fdt,
1426 uint32_t phandle)
1428 sPAPRXive *xive = spapr->xive;
1429 int node;
1430 uint64_t timas[2 * 2];
1431 /* Interrupt number ranges for the IPIs */
1432 uint32_t lisn_ranges[] = {
1433 cpu_to_be32(0),
1434 cpu_to_be32(nr_servers),
1437 * EQ size - the sizes of pages supported by the system 4K, 64K,
1438 * 2M, 16M. We only advertise 64K for the moment.
1440 uint32_t eq_sizes[] = {
1441 cpu_to_be32(16), /* 64K */
1444 * The following array is in sync with the reserved priorities
1445 * defined by the 'spapr_xive_priority_is_reserved' routine.
1447 uint32_t plat_res_int_priorities[] = {
1448 cpu_to_be32(7), /* start */
1449 cpu_to_be32(0xf8), /* count */
1451 gchar *nodename;
1453 /* Thread Interrupt Management Area : User (ring 3) and OS (ring 2) */
1454 timas[0] = cpu_to_be64(xive->tm_base +
1455 XIVE_TM_USER_PAGE * (1ull << TM_SHIFT));
1456 timas[1] = cpu_to_be64(1ull << TM_SHIFT);
1457 timas[2] = cpu_to_be64(xive->tm_base +
1458 XIVE_TM_OS_PAGE * (1ull << TM_SHIFT));
1459 timas[3] = cpu_to_be64(1ull << TM_SHIFT);
1461 nodename = g_strdup_printf("interrupt-controller@%" PRIx64,
1462 xive->tm_base + XIVE_TM_USER_PAGE * (1 << TM_SHIFT));
1463 _FDT(node = fdt_add_subnode(fdt, 0, nodename));
1464 g_free(nodename);
1466 _FDT(fdt_setprop_string(fdt, node, "device_type", "power-ivpe"));
1467 _FDT(fdt_setprop(fdt, node, "reg", timas, sizeof(timas)));
1469 _FDT(fdt_setprop_string(fdt, node, "compatible", "ibm,power-ivpe"));
1470 _FDT(fdt_setprop(fdt, node, "ibm,xive-eq-sizes", eq_sizes,
1471 sizeof(eq_sizes)));
1472 _FDT(fdt_setprop(fdt, node, "ibm,xive-lisn-ranges", lisn_ranges,
1473 sizeof(lisn_ranges)));
1475 /* For Linux to link the LSIs to the interrupt controller. */
1476 _FDT(fdt_setprop(fdt, node, "interrupt-controller", NULL, 0));
1477 _FDT(fdt_setprop_cell(fdt, node, "#interrupt-cells", 2));
1479 /* For SLOF */
1480 _FDT(fdt_setprop_cell(fdt, node, "linux,phandle", phandle));
1481 _FDT(fdt_setprop_cell(fdt, node, "phandle", phandle));
1484 * The "ibm,plat-res-int-priorities" property defines the priority
1485 * ranges reserved by the hypervisor
1487 _FDT(fdt_setprop(fdt, 0, "ibm,plat-res-int-priorities",
1488 plat_res_int_priorities, sizeof(plat_res_int_priorities)));