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.
10 #include "qemu/osdep.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/spapr.h"
18 #include "hw/ppc/spapr_xive.h"
19 #include "hw/ppc/xive.h"
20 #include "hw/ppc/xive_regs.h"
23 * XIVE Virtualization Controller BAR and Thread Managment BAR that we
24 * use for the ESB pages and the TIMA pages
26 #define SPAPR_XIVE_VC_BASE 0x0006010000000000ull
27 #define SPAPR_XIVE_TM_BASE 0x0006030203180000ull
30 * The allocation of VP blocks is a complex operation in OPAL and the
31 * VP identifiers have a relation with the number of HW chips, the
32 * size of the VP blocks, VP grouping, etc. The QEMU sPAPR XIVE
33 * controller model does not have the same constraints and can use a
34 * simple mapping scheme of the CPU vcpu_id
36 * These identifiers are never returned to the OS.
39 #define SPAPR_XIVE_NVT_BASE 0x400
42 * The sPAPR machine has a unique XIVE IC device. Assign a fixed value
43 * to the controller block id value. It can nevertheless be changed
44 * for testing purpose.
46 #define SPAPR_XIVE_BLOCK_ID 0x0
49 * sPAPR NVT and END indexing helpers
51 static uint32_t spapr_xive_nvt_to_target(uint8_t nvt_blk
, uint32_t nvt_idx
)
53 return nvt_idx
- SPAPR_XIVE_NVT_BASE
;
56 static void spapr_xive_cpu_to_nvt(PowerPCCPU
*cpu
,
57 uint8_t *out_nvt_blk
, uint32_t *out_nvt_idx
)
62 *out_nvt_blk
= SPAPR_XIVE_BLOCK_ID
;
66 *out_nvt_idx
= SPAPR_XIVE_NVT_BASE
+ cpu
->vcpu_id
;
70 static int spapr_xive_target_to_nvt(uint32_t target
,
71 uint8_t *out_nvt_blk
, uint32_t *out_nvt_idx
)
73 PowerPCCPU
*cpu
= spapr_find_cpu(target
);
79 spapr_xive_cpu_to_nvt(cpu
, out_nvt_blk
, out_nvt_idx
);
84 * sPAPR END indexing uses a simple mapping of the CPU vcpu_id, 8
87 static void spapr_xive_cpu_to_end(PowerPCCPU
*cpu
, uint8_t prio
,
88 uint8_t *out_end_blk
, uint32_t *out_end_idx
)
93 *out_end_blk
= SPAPR_XIVE_BLOCK_ID
;
97 *out_end_idx
= (cpu
->vcpu_id
<< 3) + prio
;
101 static int spapr_xive_target_to_end(uint32_t target
, uint8_t prio
,
102 uint8_t *out_end_blk
, uint32_t *out_end_idx
)
104 PowerPCCPU
*cpu
= spapr_find_cpu(target
);
110 spapr_xive_cpu_to_end(cpu
, prio
, out_end_blk
, out_end_idx
);
115 * On sPAPR machines, use a simplified output for the XIVE END
116 * structure dumping only the information related to the OS EQ.
118 static void spapr_xive_end_pic_print_info(sPAPRXive
*xive
, XiveEND
*end
,
121 uint32_t qindex
= xive_get_field32(END_W1_PAGE_OFF
, end
->w1
);
122 uint32_t qgen
= xive_get_field32(END_W1_GENERATION
, end
->w1
);
123 uint32_t qsize
= xive_get_field32(END_W0_QSIZE
, end
->w0
);
124 uint32_t qentries
= 1 << (qsize
+ 10);
125 uint32_t nvt
= xive_get_field32(END_W6_NVT_INDEX
, end
->w6
);
126 uint8_t priority
= xive_get_field32(END_W7_F0_PRIORITY
, end
->w7
);
128 monitor_printf(mon
, "%3d/%d % 6d/%5d ^%d",
129 spapr_xive_nvt_to_target(0, nvt
),
130 priority
, qindex
, qentries
, qgen
);
132 xive_end_queue_pic_print_info(end
, 6, mon
);
133 monitor_printf(mon
, "]");
136 void spapr_xive_pic_print_info(sPAPRXive
*xive
, Monitor
*mon
)
138 XiveSource
*xsrc
= &xive
->source
;
141 monitor_printf(mon
, " LSIN PQ EISN CPU/PRIO EQ\n");
143 for (i
= 0; i
< xive
->nr_irqs
; i
++) {
144 uint8_t pq
= xive_source_esb_get(xsrc
, i
);
145 XiveEAS
*eas
= &xive
->eat
[i
];
147 if (!xive_eas_is_valid(eas
)) {
151 monitor_printf(mon
, " %08x %s %c%c%c %s %08x ", i
,
152 xive_source_irq_is_lsi(xsrc
, i
) ? "LSI" : "MSI",
153 pq
& XIVE_ESB_VAL_P
? 'P' : '-',
154 pq
& XIVE_ESB_VAL_Q
? 'Q' : '-',
155 xsrc
->status
[i
] & XIVE_STATUS_ASSERTED
? 'A' : ' ',
156 xive_eas_is_masked(eas
) ? "M" : " ",
157 (int) xive_get_field64(EAS_END_DATA
, eas
->w
));
159 if (!xive_eas_is_masked(eas
)) {
160 uint32_t end_idx
= xive_get_field64(EAS_END_INDEX
, eas
->w
);
163 assert(end_idx
< xive
->nr_ends
);
164 end
= &xive
->endt
[end_idx
];
166 if (xive_end_is_valid(end
)) {
167 spapr_xive_end_pic_print_info(xive
, end
, mon
);
170 monitor_printf(mon
, "\n");
174 static void spapr_xive_map_mmio(sPAPRXive
*xive
)
176 sysbus_mmio_map(SYS_BUS_DEVICE(xive
), 0, xive
->vc_base
);
177 sysbus_mmio_map(SYS_BUS_DEVICE(xive
), 1, xive
->end_base
);
178 sysbus_mmio_map(SYS_BUS_DEVICE(xive
), 2, xive
->tm_base
);
181 static void spapr_xive_end_reset(XiveEND
*end
)
183 memset(end
, 0, sizeof(*end
));
185 /* switch off the escalation and notification ESBs */
186 end
->w1
= cpu_to_be32(END_W1_ESe_Q
| END_W1_ESn_Q
);
189 static void spapr_xive_reset(void *dev
)
191 sPAPRXive
*xive
= SPAPR_XIVE(dev
);
195 * The XiveSource has its own reset handler, which mask off all
199 /* Mask all valid EASs in the IRQ number space. */
200 for (i
= 0; i
< xive
->nr_irqs
; i
++) {
201 XiveEAS
*eas
= &xive
->eat
[i
];
202 if (xive_eas_is_valid(eas
)) {
203 eas
->w
= cpu_to_be64(EAS_VALID
| EAS_MASKED
);
210 for (i
= 0; i
< xive
->nr_ends
; i
++) {
211 spapr_xive_end_reset(&xive
->endt
[i
]);
215 static void spapr_xive_instance_init(Object
*obj
)
217 sPAPRXive
*xive
= SPAPR_XIVE(obj
);
219 object_initialize(&xive
->source
, sizeof(xive
->source
), TYPE_XIVE_SOURCE
);
220 object_property_add_child(obj
, "source", OBJECT(&xive
->source
), NULL
);
222 object_initialize(&xive
->end_source
, sizeof(xive
->end_source
),
223 TYPE_XIVE_END_SOURCE
);
224 object_property_add_child(obj
, "end_source", OBJECT(&xive
->end_source
),
228 static void spapr_xive_realize(DeviceState
*dev
, Error
**errp
)
230 sPAPRXive
*xive
= SPAPR_XIVE(dev
);
231 XiveSource
*xsrc
= &xive
->source
;
232 XiveENDSource
*end_xsrc
= &xive
->end_source
;
233 Error
*local_err
= NULL
;
235 if (!xive
->nr_irqs
) {
236 error_setg(errp
, "Number of interrupt needs to be greater 0");
240 if (!xive
->nr_ends
) {
241 error_setg(errp
, "Number of interrupt needs to be greater 0");
246 * Initialize the internal sources, for IPIs and virtual devices.
248 object_property_set_int(OBJECT(xsrc
), xive
->nr_irqs
, "nr-irqs",
250 object_property_add_const_link(OBJECT(xsrc
), "xive", OBJECT(xive
),
252 object_property_set_bool(OBJECT(xsrc
), true, "realized", &local_err
);
254 error_propagate(errp
, local_err
);
259 * Initialize the END ESB source
261 object_property_set_int(OBJECT(end_xsrc
), xive
->nr_irqs
, "nr-ends",
263 object_property_add_const_link(OBJECT(end_xsrc
), "xive", OBJECT(xive
),
265 object_property_set_bool(OBJECT(end_xsrc
), true, "realized", &local_err
);
267 error_propagate(errp
, local_err
);
271 /* Set the mapping address of the END ESB pages after the source ESBs */
272 xive
->end_base
= xive
->vc_base
+ (1ull << xsrc
->esb_shift
) * xsrc
->nr_irqs
;
275 * Allocate the routing tables
277 xive
->eat
= g_new0(XiveEAS
, xive
->nr_irqs
);
278 xive
->endt
= g_new0(XiveEND
, xive
->nr_ends
);
280 /* TIMA initialization */
281 memory_region_init_io(&xive
->tm_mmio
, OBJECT(xive
), &xive_tm_ops
, xive
,
282 "xive.tima", 4ull << TM_SHIFT
);
284 /* Define all XIVE MMIO regions on SysBus */
285 sysbus_init_mmio(SYS_BUS_DEVICE(xive
), &xsrc
->esb_mmio
);
286 sysbus_init_mmio(SYS_BUS_DEVICE(xive
), &end_xsrc
->esb_mmio
);
287 sysbus_init_mmio(SYS_BUS_DEVICE(xive
), &xive
->tm_mmio
);
289 /* Map all regions */
290 spapr_xive_map_mmio(xive
);
292 qemu_register_reset(spapr_xive_reset
, dev
);
295 static int spapr_xive_get_eas(XiveRouter
*xrtr
, uint8_t eas_blk
,
296 uint32_t eas_idx
, XiveEAS
*eas
)
298 sPAPRXive
*xive
= SPAPR_XIVE(xrtr
);
300 if (eas_idx
>= xive
->nr_irqs
) {
304 *eas
= xive
->eat
[eas_idx
];
308 static int spapr_xive_get_end(XiveRouter
*xrtr
,
309 uint8_t end_blk
, uint32_t end_idx
, XiveEND
*end
)
311 sPAPRXive
*xive
= SPAPR_XIVE(xrtr
);
313 if (end_idx
>= xive
->nr_ends
) {
317 memcpy(end
, &xive
->endt
[end_idx
], sizeof(XiveEND
));
321 static int spapr_xive_write_end(XiveRouter
*xrtr
, uint8_t end_blk
,
322 uint32_t end_idx
, XiveEND
*end
,
325 sPAPRXive
*xive
= SPAPR_XIVE(xrtr
);
327 if (end_idx
>= xive
->nr_ends
) {
331 memcpy(&xive
->endt
[end_idx
], end
, sizeof(XiveEND
));
335 static int spapr_xive_get_nvt(XiveRouter
*xrtr
,
336 uint8_t nvt_blk
, uint32_t nvt_idx
, XiveNVT
*nvt
)
338 uint32_t vcpu_id
= spapr_xive_nvt_to_target(nvt_blk
, nvt_idx
);
339 PowerPCCPU
*cpu
= spapr_find_cpu(vcpu_id
);
342 /* TODO: should we assert() if we can find a NVT ? */
347 * sPAPR does not maintain a NVT table. Return that the NVT is
348 * valid if we have found a matching CPU
350 nvt
->w0
= cpu_to_be32(NVT_W0_VALID
);
354 static int spapr_xive_write_nvt(XiveRouter
*xrtr
, uint8_t nvt_blk
,
355 uint32_t nvt_idx
, XiveNVT
*nvt
,
359 * We don't need to write back to the NVTs because the sPAPR
360 * machine should never hit a non-scheduled NVT. It should never
363 g_assert_not_reached();
366 static const VMStateDescription vmstate_spapr_xive_end
= {
367 .name
= TYPE_SPAPR_XIVE
"/end",
369 .minimum_version_id
= 1,
370 .fields
= (VMStateField
[]) {
371 VMSTATE_UINT32(w0
, XiveEND
),
372 VMSTATE_UINT32(w1
, XiveEND
),
373 VMSTATE_UINT32(w2
, XiveEND
),
374 VMSTATE_UINT32(w3
, XiveEND
),
375 VMSTATE_UINT32(w4
, XiveEND
),
376 VMSTATE_UINT32(w5
, XiveEND
),
377 VMSTATE_UINT32(w6
, XiveEND
),
378 VMSTATE_UINT32(w7
, XiveEND
),
379 VMSTATE_END_OF_LIST()
383 static const VMStateDescription vmstate_spapr_xive_eas
= {
384 .name
= TYPE_SPAPR_XIVE
"/eas",
386 .minimum_version_id
= 1,
387 .fields
= (VMStateField
[]) {
388 VMSTATE_UINT64(w
, XiveEAS
),
389 VMSTATE_END_OF_LIST()
393 static const VMStateDescription vmstate_spapr_xive
= {
394 .name
= TYPE_SPAPR_XIVE
,
396 .minimum_version_id
= 1,
397 .fields
= (VMStateField
[]) {
398 VMSTATE_UINT32_EQUAL(nr_irqs
, sPAPRXive
, NULL
),
399 VMSTATE_STRUCT_VARRAY_POINTER_UINT32(eat
, sPAPRXive
, nr_irqs
,
400 vmstate_spapr_xive_eas
, XiveEAS
),
401 VMSTATE_STRUCT_VARRAY_POINTER_UINT32(endt
, sPAPRXive
, nr_ends
,
402 vmstate_spapr_xive_end
, XiveEND
),
403 VMSTATE_END_OF_LIST()
407 static Property spapr_xive_properties
[] = {
408 DEFINE_PROP_UINT32("nr-irqs", sPAPRXive
, nr_irqs
, 0),
409 DEFINE_PROP_UINT32("nr-ends", sPAPRXive
, nr_ends
, 0),
410 DEFINE_PROP_UINT64("vc-base", sPAPRXive
, vc_base
, SPAPR_XIVE_VC_BASE
),
411 DEFINE_PROP_UINT64("tm-base", sPAPRXive
, tm_base
, SPAPR_XIVE_TM_BASE
),
412 DEFINE_PROP_END_OF_LIST(),
415 static void spapr_xive_class_init(ObjectClass
*klass
, void *data
)
417 DeviceClass
*dc
= DEVICE_CLASS(klass
);
418 XiveRouterClass
*xrc
= XIVE_ROUTER_CLASS(klass
);
420 dc
->desc
= "sPAPR XIVE Interrupt Controller";
421 dc
->props
= spapr_xive_properties
;
422 dc
->realize
= spapr_xive_realize
;
423 dc
->vmsd
= &vmstate_spapr_xive
;
425 xrc
->get_eas
= spapr_xive_get_eas
;
426 xrc
->get_end
= spapr_xive_get_end
;
427 xrc
->write_end
= spapr_xive_write_end
;
428 xrc
->get_nvt
= spapr_xive_get_nvt
;
429 xrc
->write_nvt
= spapr_xive_write_nvt
;
432 static const TypeInfo spapr_xive_info
= {
433 .name
= TYPE_SPAPR_XIVE
,
434 .parent
= TYPE_XIVE_ROUTER
,
435 .instance_init
= spapr_xive_instance_init
,
436 .instance_size
= sizeof(sPAPRXive
),
437 .class_init
= spapr_xive_class_init
,
440 static void spapr_xive_register_types(void)
442 type_register_static(&spapr_xive_info
);
445 type_init(spapr_xive_register_types
)
447 bool spapr_xive_irq_claim(sPAPRXive
*xive
, uint32_t lisn
, bool lsi
)
449 XiveSource
*xsrc
= &xive
->source
;
451 if (lisn
>= xive
->nr_irqs
) {
455 xive
->eat
[lisn
].w
|= cpu_to_be64(EAS_VALID
);
456 xive_source_irq_set(xsrc
, lisn
, lsi
);
460 bool spapr_xive_irq_free(sPAPRXive
*xive
, uint32_t lisn
)
462 XiveSource
*xsrc
= &xive
->source
;
464 if (lisn
>= xive
->nr_irqs
) {
468 xive
->eat
[lisn
].w
&= cpu_to_be64(~EAS_VALID
);
469 xive_source_irq_set(xsrc
, lisn
, false);
473 qemu_irq
spapr_xive_qirq(sPAPRXive
*xive
, uint32_t lisn
)
475 XiveSource
*xsrc
= &xive
->source
;
477 if (lisn
>= xive
->nr_irqs
) {
481 /* The sPAPR machine/device should have claimed the IRQ before */
482 assert(xive_eas_is_valid(&xive
->eat
[lisn
]));
484 return xive_source_qirq(xsrc
, lisn
);
490 * The terminology used by the XIVE hcalls is the following :
493 * EQ Event Queue assigned by OS to receive event data
494 * ESB page for source interrupt management
495 * LISN Logical Interrupt Source Number identifying a source in the
497 * EISN Effective Interrupt Source Number used by guest OS to
498 * identify source in the guest
500 * The EAS, END, NVT structures are not exposed.
504 * Linux hosts under OPAL reserve priority 7 for their own escalation
505 * interrupts (DD2.X POWER9). So we only allow the guest to use
508 static bool spapr_xive_priority_is_reserved(uint8_t priority
)
513 case 7: /* OPAL escalation queue */
520 * The H_INT_GET_SOURCE_INFO hcall() is used to obtain the logical
521 * real address of the MMIO page through which the Event State Buffer
522 * entry associated with the value of the "lisn" parameter is managed.
528 * - R5: "lisn" is per "interrupts", "interrupt-map", or
529 * "ibm,xive-lisn-ranges" properties, or as returned by the
530 * ibm,query-interrupt-source-number RTAS call, or as returned
531 * by the H_ALLOCATE_VAS_WINDOW hcall
535 * Bits 0-59: Reserved
536 * Bit 60: H_INT_ESB must be used for Event State Buffer
538 * Bit 61: 1 == LSI 0 == MSI
539 * Bit 62: the full function page supports trigger
540 * Bit 63: Store EOI Supported
541 * - R5: Logical Real address of full function Event State Buffer
542 * management page, -1 if H_INT_ESB hcall flag is set to 1.
543 * - R6: Logical Real Address of trigger only Event State Buffer
544 * management page or -1.
545 * - R7: Power of 2 page size for the ESB management pages returned in
549 #define SPAPR_XIVE_SRC_H_INT_ESB PPC_BIT(60) /* ESB manage with H_INT_ESB */
550 #define SPAPR_XIVE_SRC_LSI PPC_BIT(61) /* Virtual LSI type */
551 #define SPAPR_XIVE_SRC_TRIGGER PPC_BIT(62) /* Trigger and management
553 #define SPAPR_XIVE_SRC_STORE_EOI PPC_BIT(63) /* Store EOI support */
555 static target_ulong
h_int_get_source_info(PowerPCCPU
*cpu
,
556 sPAPRMachineState
*spapr
,
560 sPAPRXive
*xive
= spapr
->xive
;
561 XiveSource
*xsrc
= &xive
->source
;
562 target_ulong flags
= args
[0];
563 target_ulong lisn
= args
[1];
565 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
573 if (lisn
>= xive
->nr_irqs
) {
574 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
579 if (!xive_eas_is_valid(&xive
->eat
[lisn
])) {
580 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
586 * All sources are emulated under the main XIVE object and share
587 * the same characteristics.
590 if (!xive_source_esb_has_2page(xsrc
)) {
591 args
[0] |= SPAPR_XIVE_SRC_TRIGGER
;
593 if (xsrc
->esb_flags
& XIVE_SRC_STORE_EOI
) {
594 args
[0] |= SPAPR_XIVE_SRC_STORE_EOI
;
598 * Force the use of the H_INT_ESB hcall in case of an LSI
599 * interrupt. This is necessary under KVM to re-trigger the
600 * interrupt if the level is still asserted
602 if (xive_source_irq_is_lsi(xsrc
, lisn
)) {
603 args
[0] |= SPAPR_XIVE_SRC_H_INT_ESB
| SPAPR_XIVE_SRC_LSI
;
606 if (!(args
[0] & SPAPR_XIVE_SRC_H_INT_ESB
)) {
607 args
[1] = xive
->vc_base
+ xive_source_esb_mgmt(xsrc
, lisn
);
612 if (xive_source_esb_has_2page(xsrc
) &&
613 !(args
[0] & SPAPR_XIVE_SRC_H_INT_ESB
)) {
614 args
[2] = xive
->vc_base
+ xive_source_esb_page(xsrc
, lisn
);
619 if (xive_source_esb_has_2page(xsrc
)) {
620 args
[3] = xsrc
->esb_shift
- 1;
622 args
[3] = xsrc
->esb_shift
;
629 * The H_INT_SET_SOURCE_CONFIG hcall() is used to assign a Logical
630 * Interrupt Source to a target. The Logical Interrupt Source is
631 * designated with the "lisn" parameter and the target is designated
632 * with the "target" and "priority" parameters. Upon return from the
633 * hcall(), no additional interrupts will be directed to the old EQ.
638 * Bits 0-61: Reserved
639 * Bit 62: set the "eisn" in the EAS
640 * Bit 63: masks the interrupt source in the hardware interrupt
641 * control structure. An interrupt masked by this mechanism will
642 * be dropped, but it's source state bits will still be
643 * set. There is no race-free way of unmasking and restoring the
644 * source. Thus this should only be used in interrupts that are
645 * also masked at the source, and only in cases where the
646 * interrupt is not meant to be used for a large amount of time
647 * because no valid target exists for it for example
648 * - R5: "lisn" is per "interrupts", "interrupt-map", or
649 * "ibm,xive-lisn-ranges" properties, or as returned by the
650 * ibm,query-interrupt-source-number RTAS call, or as returned by
651 * the H_ALLOCATE_VAS_WINDOW hcall
652 * - R6: "target" is per "ibm,ppc-interrupt-server#s" or
653 * "ibm,ppc-interrupt-gserver#s"
654 * - R7: "priority" is a valid priority not in
655 * "ibm,plat-res-int-priorities"
656 * - R8: "eisn" is the guest EISN associated with the "lisn"
662 #define SPAPR_XIVE_SRC_SET_EISN PPC_BIT(62)
663 #define SPAPR_XIVE_SRC_MASK PPC_BIT(63)
665 static target_ulong
h_int_set_source_config(PowerPCCPU
*cpu
,
666 sPAPRMachineState
*spapr
,
670 sPAPRXive
*xive
= spapr
->xive
;
671 XiveEAS eas
, new_eas
;
672 target_ulong flags
= args
[0];
673 target_ulong lisn
= args
[1];
674 target_ulong target
= args
[2];
675 target_ulong priority
= args
[3];
676 target_ulong eisn
= args
[4];
680 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
684 if (flags
& ~(SPAPR_XIVE_SRC_SET_EISN
| SPAPR_XIVE_SRC_MASK
)) {
688 if (lisn
>= xive
->nr_irqs
) {
689 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
694 eas
= xive
->eat
[lisn
];
695 if (!xive_eas_is_valid(&eas
)) {
696 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
701 /* priority 0xff is used to reset the EAS */
702 if (priority
== 0xff) {
703 new_eas
.w
= cpu_to_be64(EAS_VALID
| EAS_MASKED
);
707 if (flags
& SPAPR_XIVE_SRC_MASK
) {
708 new_eas
.w
= eas
.w
| cpu_to_be64(EAS_MASKED
);
710 new_eas
.w
= eas
.w
& cpu_to_be64(~EAS_MASKED
);
713 if (spapr_xive_priority_is_reserved(priority
)) {
714 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: priority " TARGET_FMT_ld
715 " is reserved\n", priority
);
720 * Validate that "target" is part of the list of threads allocated
721 * to the partition. For that, find the END corresponding to the
724 if (spapr_xive_target_to_end(target
, priority
, &end_blk
, &end_idx
)) {
728 new_eas
.w
= xive_set_field64(EAS_END_BLOCK
, new_eas
.w
, end_blk
);
729 new_eas
.w
= xive_set_field64(EAS_END_INDEX
, new_eas
.w
, end_idx
);
731 if (flags
& SPAPR_XIVE_SRC_SET_EISN
) {
732 new_eas
.w
= xive_set_field64(EAS_END_DATA
, new_eas
.w
, eisn
);
736 xive
->eat
[lisn
] = new_eas
;
741 * The H_INT_GET_SOURCE_CONFIG hcall() is used to determine to which
742 * target/priority pair is assigned to the specified Logical Interrupt
749 * - R5: "lisn" is per "interrupts", "interrupt-map", or
750 * "ibm,xive-lisn-ranges" properties, or as returned by the
751 * ibm,query-interrupt-source-number RTAS call, or as
752 * returned by the H_ALLOCATE_VAS_WINDOW hcall
755 * - R4: Target to which the specified Logical Interrupt Source is
757 * - R5: Priority to which the specified Logical Interrupt Source is
759 * - R6: EISN for the specified Logical Interrupt Source (this will be
760 * equivalent to the LISN if not changed by H_INT_SET_SOURCE_CONFIG)
762 static target_ulong
h_int_get_source_config(PowerPCCPU
*cpu
,
763 sPAPRMachineState
*spapr
,
767 sPAPRXive
*xive
= spapr
->xive
;
768 target_ulong flags
= args
[0];
769 target_ulong lisn
= args
[1];
773 uint32_t end_idx
, nvt_idx
;
775 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
783 if (lisn
>= xive
->nr_irqs
) {
784 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
789 eas
= xive
->eat
[lisn
];
790 if (!xive_eas_is_valid(&eas
)) {
791 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
796 /* EAS_END_BLOCK is unused on sPAPR */
797 end_idx
= xive_get_field64(EAS_END_INDEX
, eas
.w
);
799 assert(end_idx
< xive
->nr_ends
);
800 end
= &xive
->endt
[end_idx
];
802 nvt_blk
= xive_get_field32(END_W6_NVT_BLOCK
, end
->w6
);
803 nvt_idx
= xive_get_field32(END_W6_NVT_INDEX
, end
->w6
);
804 args
[0] = spapr_xive_nvt_to_target(nvt_blk
, nvt_idx
);
806 if (xive_eas_is_masked(&eas
)) {
809 args
[1] = xive_get_field32(END_W7_F0_PRIORITY
, end
->w7
);
812 args
[2] = xive_get_field64(EAS_END_DATA
, eas
.w
);
818 * The H_INT_GET_QUEUE_INFO hcall() is used to get the logical real
819 * address of the notification management page associated with the
820 * specified target and priority.
826 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
827 * "ibm,ppc-interrupt-gserver#s"
828 * - R6: "priority" is a valid priority not in
829 * "ibm,plat-res-int-priorities"
832 * - R4: Logical real address of notification page
833 * - R5: Power of 2 page size of the notification page
835 static target_ulong
h_int_get_queue_info(PowerPCCPU
*cpu
,
836 sPAPRMachineState
*spapr
,
840 sPAPRXive
*xive
= spapr
->xive
;
841 XiveENDSource
*end_xsrc
= &xive
->end_source
;
842 target_ulong flags
= args
[0];
843 target_ulong target
= args
[1];
844 target_ulong priority
= args
[2];
849 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
858 * H_STATE should be returned if a H_INT_RESET is in progress.
859 * This is not needed when running the emulation under QEMU
862 if (spapr_xive_priority_is_reserved(priority
)) {
863 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: priority " TARGET_FMT_ld
864 " is reserved\n", priority
);
869 * Validate that "target" is part of the list of threads allocated
870 * to the partition. For that, find the END corresponding to the
873 if (spapr_xive_target_to_end(target
, priority
, &end_blk
, &end_idx
)) {
877 assert(end_idx
< xive
->nr_ends
);
878 end
= &xive
->endt
[end_idx
];
880 args
[0] = xive
->end_base
+ (1ull << (end_xsrc
->esb_shift
+ 1)) * end_idx
;
881 if (xive_end_is_enqueue(end
)) {
882 args
[1] = xive_get_field32(END_W0_QSIZE
, end
->w0
) + 12;
891 * The H_INT_SET_QUEUE_CONFIG hcall() is used to set or reset a EQ for
892 * a given "target" and "priority". It is also used to set the
893 * notification config associated with the EQ. An EQ size of 0 is
894 * used to reset the EQ config for a given target and priority. If
895 * resetting the EQ config, the END associated with the given "target"
896 * and "priority" will be changed to disable queueing.
898 * Upon return from the hcall(), no additional interrupts will be
899 * directed to the old EQ (if one was set). The old EQ (if one was
900 * set) should be investigated for interrupts that occurred prior to
901 * or during the hcall().
906 * Bits 0-62: Reserved
907 * Bit 63: Unconditional Notify (n) per the XIVE spec
908 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
909 * "ibm,ppc-interrupt-gserver#s"
910 * - R6: "priority" is a valid priority not in
911 * "ibm,plat-res-int-priorities"
912 * - R7: "eventQueue": The logical real address of the start of the EQ
913 * - R8: "eventQueueSize": The power of 2 EQ size per "ibm,xive-eq-sizes"
919 #define SPAPR_XIVE_END_ALWAYS_NOTIFY PPC_BIT(63)
921 static target_ulong
h_int_set_queue_config(PowerPCCPU
*cpu
,
922 sPAPRMachineState
*spapr
,
926 sPAPRXive
*xive
= spapr
->xive
;
927 target_ulong flags
= args
[0];
928 target_ulong target
= args
[1];
929 target_ulong priority
= args
[2];
930 target_ulong qpage
= args
[3];
931 target_ulong qsize
= args
[4];
933 uint8_t end_blk
, nvt_blk
;
934 uint32_t end_idx
, nvt_idx
;
936 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
940 if (flags
& ~SPAPR_XIVE_END_ALWAYS_NOTIFY
) {
945 * H_STATE should be returned if a H_INT_RESET is in progress.
946 * This is not needed when running the emulation under QEMU
949 if (spapr_xive_priority_is_reserved(priority
)) {
950 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: priority " TARGET_FMT_ld
951 " is reserved\n", priority
);
956 * Validate that "target" is part of the list of threads allocated
957 * to the partition. For that, find the END corresponding to the
961 if (spapr_xive_target_to_end(target
, priority
, &end_blk
, &end_idx
)) {
965 assert(end_idx
< xive
->nr_ends
);
966 memcpy(&end
, &xive
->endt
[end_idx
], sizeof(XiveEND
));
973 end
.w2
= cpu_to_be32((qpage
>> 32) & 0x0fffffff);
974 end
.w3
= cpu_to_be32(qpage
& 0xffffffff);
975 end
.w0
|= cpu_to_be32(END_W0_ENQUEUE
);
976 end
.w0
= xive_set_field32(END_W0_QSIZE
, end
.w0
, qsize
- 12);
979 /* reset queue and disable queueing */
980 spapr_xive_end_reset(&end
);
984 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: invalid EQ size %"PRIx64
"\n",
990 hwaddr plen
= 1 << qsize
;
994 * Validate the guest EQ. We should also check that the queue
995 * has been zeroed by the OS.
997 eq
= address_space_map(CPU(cpu
)->as
, qpage
, &plen
, true,
998 MEMTXATTRS_UNSPECIFIED
);
999 if (plen
!= 1 << qsize
) {
1000 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: failed to map EQ @0x%"
1001 HWADDR_PRIx
"\n", qpage
);
1004 address_space_unmap(CPU(cpu
)->as
, eq
, plen
, true, plen
);
1007 /* "target" should have been validated above */
1008 if (spapr_xive_target_to_nvt(target
, &nvt_blk
, &nvt_idx
)) {
1009 g_assert_not_reached();
1013 * Ensure the priority and target are correctly set (they will not
1014 * be right after allocation)
1016 end
.w6
= xive_set_field32(END_W6_NVT_BLOCK
, 0ul, nvt_blk
) |
1017 xive_set_field32(END_W6_NVT_INDEX
, 0ul, nvt_idx
);
1018 end
.w7
= xive_set_field32(END_W7_F0_PRIORITY
, 0ul, priority
);
1020 if (flags
& SPAPR_XIVE_END_ALWAYS_NOTIFY
) {
1021 end
.w0
|= cpu_to_be32(END_W0_UCOND_NOTIFY
);
1023 end
.w0
&= cpu_to_be32((uint32_t)~END_W0_UCOND_NOTIFY
);
1027 * The generation bit for the END starts at 1 and The END page
1028 * offset counter starts at 0.
1030 end
.w1
= cpu_to_be32(END_W1_GENERATION
) |
1031 xive_set_field32(END_W1_PAGE_OFF
, 0ul, 0ul);
1032 end
.w0
|= cpu_to_be32(END_W0_VALID
);
1035 * TODO: issue syncs required to ensure all in-flight interrupts
1036 * are complete on the old END
1041 memcpy(&xive
->endt
[end_idx
], &end
, sizeof(XiveEND
));
1046 * The H_INT_GET_QUEUE_CONFIG hcall() is used to get a EQ for a given
1047 * target and priority.
1052 * Bits 0-62: Reserved
1053 * Bit 63: Debug: Return debug data
1054 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
1055 * "ibm,ppc-interrupt-gserver#s"
1056 * - R6: "priority" is a valid priority not in
1057 * "ibm,plat-res-int-priorities"
1061 * Bits 0-61: Reserved
1062 * Bit 62: The value of Event Queue Generation Number (g) per
1063 * the XIVE spec if "Debug" = 1
1064 * Bit 63: The value of Unconditional Notify (n) per the XIVE spec
1065 * - R5: The logical real address of the start of the EQ
1066 * - R6: The power of 2 EQ size per "ibm,xive-eq-sizes"
1067 * - R7: The value of Event Queue Offset Counter per XIVE spec
1068 * if "Debug" = 1, else 0
1072 #define SPAPR_XIVE_END_DEBUG PPC_BIT(63)
1074 static target_ulong
h_int_get_queue_config(PowerPCCPU
*cpu
,
1075 sPAPRMachineState
*spapr
,
1076 target_ulong opcode
,
1079 sPAPRXive
*xive
= spapr
->xive
;
1080 target_ulong flags
= args
[0];
1081 target_ulong target
= args
[1];
1082 target_ulong priority
= args
[2];
1087 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1091 if (flags
& ~SPAPR_XIVE_END_DEBUG
) {
1096 * H_STATE should be returned if a H_INT_RESET is in progress.
1097 * This is not needed when running the emulation under QEMU
1100 if (spapr_xive_priority_is_reserved(priority
)) {
1101 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: priority " TARGET_FMT_ld
1102 " is reserved\n", priority
);
1107 * Validate that "target" is part of the list of threads allocated
1108 * to the partition. For that, find the END corresponding to the
1111 if (spapr_xive_target_to_end(target
, priority
, &end_blk
, &end_idx
)) {
1115 assert(end_idx
< xive
->nr_ends
);
1116 end
= &xive
->endt
[end_idx
];
1119 if (xive_end_is_notify(end
)) {
1120 args
[0] |= SPAPR_XIVE_END_ALWAYS_NOTIFY
;
1123 if (xive_end_is_enqueue(end
)) {
1124 args
[1] = (uint64_t) be32_to_cpu(end
->w2
& 0x0fffffff) << 32
1125 | be32_to_cpu(end
->w3
);
1126 args
[2] = xive_get_field32(END_W0_QSIZE
, end
->w0
) + 12;
1132 /* TODO: do we need any locking on the END ? */
1133 if (flags
& SPAPR_XIVE_END_DEBUG
) {
1134 /* Load the event queue generation number into the return flags */
1135 args
[0] |= (uint64_t)xive_get_field32(END_W1_GENERATION
, end
->w1
) << 62;
1137 /* Load R7 with the event queue offset counter */
1138 args
[3] = xive_get_field32(END_W1_PAGE_OFF
, end
->w1
);
1147 * The H_INT_SET_OS_REPORTING_LINE hcall() is used to set the
1148 * reporting cache line pair for the calling thread. The reporting
1149 * cache lines will contain the OS interrupt context when the OS
1150 * issues a CI store byte to @TIMA+0xC10 to acknowledge the OS
1151 * interrupt. The reporting cache lines can be reset by inputting -1
1152 * in "reportingLine". Issuing the CI store byte without reporting
1153 * cache lines registered will result in the data not being accessible
1159 * Bits 0-63: Reserved
1160 * - R5: "reportingLine": The logical real address of the reporting cache
1166 static target_ulong
h_int_set_os_reporting_line(PowerPCCPU
*cpu
,
1167 sPAPRMachineState
*spapr
,
1168 target_ulong opcode
,
1171 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1176 * H_STATE should be returned if a H_INT_RESET is in progress.
1177 * This is not needed when running the emulation under QEMU
1180 /* TODO: H_INT_SET_OS_REPORTING_LINE */
1185 * The H_INT_GET_OS_REPORTING_LINE hcall() is used to get the logical
1186 * real address of the reporting cache line pair set for the input
1187 * "target". If no reporting cache line pair has been set, -1 is
1193 * Bits 0-63: Reserved
1194 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
1195 * "ibm,ppc-interrupt-gserver#s"
1196 * - R6: "reportingLine": The logical real address of the reporting
1200 * - R4: The logical real address of the reporting line if set, else -1
1202 static target_ulong
h_int_get_os_reporting_line(PowerPCCPU
*cpu
,
1203 sPAPRMachineState
*spapr
,
1204 target_ulong opcode
,
1207 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1212 * H_STATE should be returned if a H_INT_RESET is in progress.
1213 * This is not needed when running the emulation under QEMU
1216 /* TODO: H_INT_GET_OS_REPORTING_LINE */
1221 * The H_INT_ESB hcall() is used to issue a load or store to the ESB
1222 * page for the input "lisn". This hcall is only supported for LISNs
1223 * that have the ESB hcall flag set to 1 when returned from hcall()
1224 * H_INT_GET_SOURCE_INFO.
1229 * Bits 0-62: Reserved
1230 * bit 63: Store: Store=1, store operation, else load operation
1231 * - R5: "lisn" is per "interrupts", "interrupt-map", or
1232 * "ibm,xive-lisn-ranges" properties, or as returned by the
1233 * ibm,query-interrupt-source-number RTAS call, or as
1234 * returned by the H_ALLOCATE_VAS_WINDOW hcall
1235 * - R6: "esbOffset" is the offset into the ESB page for the load or
1237 * - R7: "storeData" is the data to write for a store operation
1240 * - R4: The value of the load if load operation, else -1
1243 #define SPAPR_XIVE_ESB_STORE PPC_BIT(63)
1245 static target_ulong
h_int_esb(PowerPCCPU
*cpu
,
1246 sPAPRMachineState
*spapr
,
1247 target_ulong opcode
,
1250 sPAPRXive
*xive
= spapr
->xive
;
1252 target_ulong flags
= args
[0];
1253 target_ulong lisn
= args
[1];
1254 target_ulong offset
= args
[2];
1255 target_ulong data
= args
[3];
1257 XiveSource
*xsrc
= &xive
->source
;
1259 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1263 if (flags
& ~SPAPR_XIVE_ESB_STORE
) {
1267 if (lisn
>= xive
->nr_irqs
) {
1268 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
1273 eas
= xive
->eat
[lisn
];
1274 if (!xive_eas_is_valid(&eas
)) {
1275 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
1280 if (offset
> (1ull << xsrc
->esb_shift
)) {
1284 mmio_addr
= xive
->vc_base
+ xive_source_esb_mgmt(xsrc
, lisn
) + offset
;
1286 if (dma_memory_rw(&address_space_memory
, mmio_addr
, &data
, 8,
1287 (flags
& SPAPR_XIVE_ESB_STORE
))) {
1288 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: failed to access ESB @0x%"
1289 HWADDR_PRIx
"\n", mmio_addr
);
1292 args
[0] = (flags
& SPAPR_XIVE_ESB_STORE
) ? -1 : data
;
1297 * The H_INT_SYNC hcall() is used to issue hardware syncs that will
1298 * ensure any in flight events for the input lisn are in the event
1304 * Bits 0-63: Reserved
1305 * - R5: "lisn" is per "interrupts", "interrupt-map", or
1306 * "ibm,xive-lisn-ranges" properties, or as returned by the
1307 * ibm,query-interrupt-source-number RTAS call, or as
1308 * returned by the H_ALLOCATE_VAS_WINDOW hcall
1313 static target_ulong
h_int_sync(PowerPCCPU
*cpu
,
1314 sPAPRMachineState
*spapr
,
1315 target_ulong opcode
,
1318 sPAPRXive
*xive
= spapr
->xive
;
1320 target_ulong flags
= args
[0];
1321 target_ulong lisn
= args
[1];
1323 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1331 if (lisn
>= xive
->nr_irqs
) {
1332 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
1337 eas
= xive
->eat
[lisn
];
1338 if (!xive_eas_is_valid(&eas
)) {
1339 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
1345 * H_STATE should be returned if a H_INT_RESET is in progress.
1346 * This is not needed when running the emulation under QEMU
1349 /* This is not real hardware. Nothing to be done */
1354 * The H_INT_RESET hcall() is used to reset all of the partition's
1355 * interrupt exploitation structures to their initial state. This
1356 * means losing all previously set interrupt state set via
1357 * H_INT_SET_SOURCE_CONFIG and H_INT_SET_QUEUE_CONFIG.
1362 * Bits 0-63: Reserved
1367 static target_ulong
h_int_reset(PowerPCCPU
*cpu
,
1368 sPAPRMachineState
*spapr
,
1369 target_ulong opcode
,
1372 sPAPRXive
*xive
= spapr
->xive
;
1373 target_ulong flags
= args
[0];
1375 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1383 device_reset(DEVICE(xive
));
1387 void spapr_xive_hcall_init(sPAPRMachineState
*spapr
)
1389 spapr_register_hypercall(H_INT_GET_SOURCE_INFO
, h_int_get_source_info
);
1390 spapr_register_hypercall(H_INT_SET_SOURCE_CONFIG
, h_int_set_source_config
);
1391 spapr_register_hypercall(H_INT_GET_SOURCE_CONFIG
, h_int_get_source_config
);
1392 spapr_register_hypercall(H_INT_GET_QUEUE_INFO
, h_int_get_queue_info
);
1393 spapr_register_hypercall(H_INT_SET_QUEUE_CONFIG
, h_int_set_queue_config
);
1394 spapr_register_hypercall(H_INT_GET_QUEUE_CONFIG
, h_int_get_queue_config
);
1395 spapr_register_hypercall(H_INT_SET_OS_REPORTING_LINE
,
1396 h_int_set_os_reporting_line
);
1397 spapr_register_hypercall(H_INT_GET_OS_REPORTING_LINE
,
1398 h_int_get_os_reporting_line
);
1399 spapr_register_hypercall(H_INT_ESB
, h_int_esb
);
1400 spapr_register_hypercall(H_INT_SYNC
, h_int_sync
);
1401 spapr_register_hypercall(H_INT_RESET
, h_int_reset
);