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 "qemu/module.h"
13 #include "qapi/error.h"
14 #include "qemu/error-report.h"
15 #include "target/ppc/cpu.h"
16 #include "sysemu/cpus.h"
17 #include "sysemu/reset.h"
18 #include "migration/vmstate.h"
19 #include "monitor/monitor.h"
20 #include "hw/ppc/fdt.h"
21 #include "hw/ppc/spapr.h"
22 #include "hw/ppc/spapr_cpu_core.h"
23 #include "hw/ppc/spapr_xive.h"
24 #include "hw/ppc/xive.h"
25 #include "hw/ppc/xive_regs.h"
26 #include "hw/qdev-properties.h"
29 * XIVE Virtualization Controller BAR and Thread Managment BAR that we
30 * use for the ESB pages and the TIMA pages
32 #define SPAPR_XIVE_VC_BASE 0x0006010000000000ull
33 #define SPAPR_XIVE_TM_BASE 0x0006030203180000ull
36 * The allocation of VP blocks is a complex operation in OPAL and the
37 * VP identifiers have a relation with the number of HW chips, the
38 * size of the VP blocks, VP grouping, etc. The QEMU sPAPR XIVE
39 * controller model does not have the same constraints and can use a
40 * simple mapping scheme of the CPU vcpu_id
42 * These identifiers are never returned to the OS.
45 #define SPAPR_XIVE_NVT_BASE 0x400
48 * sPAPR NVT and END indexing helpers
50 static uint32_t spapr_xive_nvt_to_target(uint8_t nvt_blk
, uint32_t nvt_idx
)
52 return nvt_idx
- SPAPR_XIVE_NVT_BASE
;
55 static void spapr_xive_cpu_to_nvt(PowerPCCPU
*cpu
,
56 uint8_t *out_nvt_blk
, uint32_t *out_nvt_idx
)
61 *out_nvt_blk
= SPAPR_XIVE_BLOCK_ID
;
65 *out_nvt_idx
= SPAPR_XIVE_NVT_BASE
+ cpu
->vcpu_id
;
69 static int spapr_xive_target_to_nvt(uint32_t target
,
70 uint8_t *out_nvt_blk
, uint32_t *out_nvt_idx
)
72 PowerPCCPU
*cpu
= spapr_find_cpu(target
);
78 spapr_xive_cpu_to_nvt(cpu
, out_nvt_blk
, out_nvt_idx
);
83 * sPAPR END indexing uses a simple mapping of the CPU vcpu_id, 8
86 int spapr_xive_end_to_target(uint8_t end_blk
, uint32_t end_idx
,
87 uint32_t *out_server
, uint8_t *out_prio
)
90 assert(end_blk
== SPAPR_XIVE_BLOCK_ID
);
93 *out_server
= end_idx
>> 3;
97 *out_prio
= end_idx
& 0x7;
102 static void spapr_xive_cpu_to_end(PowerPCCPU
*cpu
, uint8_t prio
,
103 uint8_t *out_end_blk
, uint32_t *out_end_idx
)
108 *out_end_blk
= SPAPR_XIVE_BLOCK_ID
;
112 *out_end_idx
= (cpu
->vcpu_id
<< 3) + prio
;
116 static int spapr_xive_target_to_end(uint32_t target
, uint8_t prio
,
117 uint8_t *out_end_blk
, uint32_t *out_end_idx
)
119 PowerPCCPU
*cpu
= spapr_find_cpu(target
);
125 spapr_xive_cpu_to_end(cpu
, prio
, out_end_blk
, out_end_idx
);
130 * On sPAPR machines, use a simplified output for the XIVE END
131 * structure dumping only the information related to the OS EQ.
133 static void spapr_xive_end_pic_print_info(SpaprXive
*xive
, XiveEND
*end
,
136 uint64_t qaddr_base
= xive_end_qaddr(end
);
137 uint32_t qindex
= xive_get_field32(END_W1_PAGE_OFF
, end
->w1
);
138 uint32_t qgen
= xive_get_field32(END_W1_GENERATION
, end
->w1
);
139 uint32_t qsize
= xive_get_field32(END_W0_QSIZE
, end
->w0
);
140 uint32_t qentries
= 1 << (qsize
+ 10);
141 uint32_t nvt
= xive_get_field32(END_W6_NVT_INDEX
, end
->w6
);
142 uint8_t priority
= xive_get_field32(END_W7_F0_PRIORITY
, end
->w7
);
144 monitor_printf(mon
, "%3d/%d % 6d/%5d @%"PRIx64
" ^%d",
145 spapr_xive_nvt_to_target(0, nvt
),
146 priority
, qindex
, qentries
, qaddr_base
, qgen
);
148 xive_end_queue_pic_print_info(end
, 6, mon
);
151 void spapr_xive_pic_print_info(SpaprXive
*xive
, Monitor
*mon
)
153 XiveSource
*xsrc
= &xive
->source
;
156 if (kvm_irqchip_in_kernel()) {
157 Error
*local_err
= NULL
;
159 kvmppc_xive_synchronize_state(xive
, &local_err
);
161 error_report_err(local_err
);
166 monitor_printf(mon
, " LISN PQ EISN CPU/PRIO EQ\n");
168 for (i
= 0; i
< xive
->nr_irqs
; i
++) {
169 uint8_t pq
= xive_source_esb_get(xsrc
, i
);
170 XiveEAS
*eas
= &xive
->eat
[i
];
172 if (!xive_eas_is_valid(eas
)) {
176 monitor_printf(mon
, " %08x %s %c%c%c %s %08x ", i
,
177 xive_source_irq_is_lsi(xsrc
, i
) ? "LSI" : "MSI",
178 pq
& XIVE_ESB_VAL_P
? 'P' : '-',
179 pq
& XIVE_ESB_VAL_Q
? 'Q' : '-',
180 xsrc
->status
[i
] & XIVE_STATUS_ASSERTED
? 'A' : ' ',
181 xive_eas_is_masked(eas
) ? "M" : " ",
182 (int) xive_get_field64(EAS_END_DATA
, eas
->w
));
184 if (!xive_eas_is_masked(eas
)) {
185 uint32_t end_idx
= xive_get_field64(EAS_END_INDEX
, eas
->w
);
188 assert(end_idx
< xive
->nr_ends
);
189 end
= &xive
->endt
[end_idx
];
191 if (xive_end_is_valid(end
)) {
192 spapr_xive_end_pic_print_info(xive
, end
, mon
);
195 monitor_printf(mon
, "\n");
199 void spapr_xive_mmio_set_enabled(SpaprXive
*xive
, bool enable
)
201 memory_region_set_enabled(&xive
->source
.esb_mmio
, enable
);
202 memory_region_set_enabled(&xive
->tm_mmio
, enable
);
204 /* Disable the END ESBs until a guest OS makes use of them */
205 memory_region_set_enabled(&xive
->end_source
.esb_mmio
, false);
208 static void spapr_xive_tm_write(void *opaque
, hwaddr offset
,
209 uint64_t value
, unsigned size
)
211 XiveTCTX
*tctx
= spapr_cpu_state(POWERPC_CPU(current_cpu
))->tctx
;
213 xive_tctx_tm_write(XIVE_PRESENTER(opaque
), tctx
, offset
, value
, size
);
216 static uint64_t spapr_xive_tm_read(void *opaque
, hwaddr offset
, unsigned size
)
218 XiveTCTX
*tctx
= spapr_cpu_state(POWERPC_CPU(current_cpu
))->tctx
;
220 return xive_tctx_tm_read(XIVE_PRESENTER(opaque
), tctx
, offset
, size
);
223 const MemoryRegionOps spapr_xive_tm_ops
= {
224 .read
= spapr_xive_tm_read
,
225 .write
= spapr_xive_tm_write
,
226 .endianness
= DEVICE_BIG_ENDIAN
,
228 .min_access_size
= 1,
229 .max_access_size
= 8,
232 .min_access_size
= 1,
233 .max_access_size
= 8,
237 static void spapr_xive_end_reset(XiveEND
*end
)
239 memset(end
, 0, sizeof(*end
));
241 /* switch off the escalation and notification ESBs */
242 end
->w1
= cpu_to_be32(END_W1_ESe_Q
| END_W1_ESn_Q
);
245 static void spapr_xive_reset(void *dev
)
247 SpaprXive
*xive
= SPAPR_XIVE(dev
);
251 * The XiveSource has its own reset handler, which mask off all
255 /* Mask all valid EASs in the IRQ number space. */
256 for (i
= 0; i
< xive
->nr_irqs
; i
++) {
257 XiveEAS
*eas
= &xive
->eat
[i
];
258 if (xive_eas_is_valid(eas
)) {
259 eas
->w
= cpu_to_be64(EAS_VALID
| EAS_MASKED
);
266 for (i
= 0; i
< xive
->nr_ends
; i
++) {
267 spapr_xive_end_reset(&xive
->endt
[i
]);
271 static void spapr_xive_instance_init(Object
*obj
)
273 SpaprXive
*xive
= SPAPR_XIVE(obj
);
275 object_initialize_child(obj
, "source", &xive
->source
, TYPE_XIVE_SOURCE
);
277 object_initialize_child(obj
, "end_source", &xive
->end_source
,
278 TYPE_XIVE_END_SOURCE
);
280 /* Not connected to the KVM XIVE device */
284 static void spapr_xive_realize(DeviceState
*dev
, Error
**errp
)
286 SpaprXive
*xive
= SPAPR_XIVE(dev
);
287 SpaprXiveClass
*sxc
= SPAPR_XIVE_GET_CLASS(xive
);
288 XiveSource
*xsrc
= &xive
->source
;
289 XiveENDSource
*end_xsrc
= &xive
->end_source
;
290 Error
*local_err
= NULL
;
292 sxc
->parent_realize(dev
, &local_err
);
294 error_propagate(errp
, local_err
);
298 if (!xive
->nr_irqs
) {
299 error_setg(errp
, "Number of interrupt needs to be greater 0");
303 if (!xive
->nr_ends
) {
304 error_setg(errp
, "Number of interrupt needs to be greater 0");
309 * Initialize the internal sources, for IPIs and virtual devices.
311 object_property_set_int(OBJECT(xsrc
), "nr-irqs", xive
->nr_irqs
,
313 object_property_set_link(OBJECT(xsrc
), "xive", OBJECT(xive
), &error_abort
);
314 if (!qdev_realize(DEVICE(xsrc
), NULL
, &local_err
)) {
315 error_propagate(errp
, local_err
);
318 sysbus_init_mmio(SYS_BUS_DEVICE(xive
), &xsrc
->esb_mmio
);
321 * Initialize the END ESB source
323 object_property_set_int(OBJECT(end_xsrc
), "nr-ends", xive
->nr_irqs
,
325 object_property_set_link(OBJECT(end_xsrc
), "xive", OBJECT(xive
),
327 if (!qdev_realize(DEVICE(end_xsrc
), NULL
, &local_err
)) {
328 error_propagate(errp
, local_err
);
331 sysbus_init_mmio(SYS_BUS_DEVICE(xive
), &end_xsrc
->esb_mmio
);
333 /* Set the mapping address of the END ESB pages after the source ESBs */
334 xive
->end_base
= xive
->vc_base
+ (1ull << xsrc
->esb_shift
) * xsrc
->nr_irqs
;
337 * Allocate the routing tables
339 xive
->eat
= g_new0(XiveEAS
, xive
->nr_irqs
);
340 xive
->endt
= g_new0(XiveEND
, xive
->nr_ends
);
342 xive
->nodename
= g_strdup_printf("interrupt-controller@%" PRIx64
,
343 xive
->tm_base
+ XIVE_TM_USER_PAGE
* (1 << TM_SHIFT
));
345 qemu_register_reset(spapr_xive_reset
, dev
);
347 /* TIMA initialization */
348 memory_region_init_io(&xive
->tm_mmio
, OBJECT(xive
), &spapr_xive_tm_ops
,
349 xive
, "xive.tima", 4ull << TM_SHIFT
);
350 sysbus_init_mmio(SYS_BUS_DEVICE(xive
), &xive
->tm_mmio
);
353 * Map all regions. These will be enabled or disabled at reset and
354 * can also be overridden by KVM memory regions if active
356 sysbus_mmio_map(SYS_BUS_DEVICE(xive
), 0, xive
->vc_base
);
357 sysbus_mmio_map(SYS_BUS_DEVICE(xive
), 1, xive
->end_base
);
358 sysbus_mmio_map(SYS_BUS_DEVICE(xive
), 2, xive
->tm_base
);
361 static int spapr_xive_get_eas(XiveRouter
*xrtr
, uint8_t eas_blk
,
362 uint32_t eas_idx
, XiveEAS
*eas
)
364 SpaprXive
*xive
= SPAPR_XIVE(xrtr
);
366 if (eas_idx
>= xive
->nr_irqs
) {
370 *eas
= xive
->eat
[eas_idx
];
374 static int spapr_xive_get_end(XiveRouter
*xrtr
,
375 uint8_t end_blk
, uint32_t end_idx
, XiveEND
*end
)
377 SpaprXive
*xive
= SPAPR_XIVE(xrtr
);
379 if (end_idx
>= xive
->nr_ends
) {
383 memcpy(end
, &xive
->endt
[end_idx
], sizeof(XiveEND
));
387 static int spapr_xive_write_end(XiveRouter
*xrtr
, uint8_t end_blk
,
388 uint32_t end_idx
, XiveEND
*end
,
391 SpaprXive
*xive
= SPAPR_XIVE(xrtr
);
393 if (end_idx
>= xive
->nr_ends
) {
397 memcpy(&xive
->endt
[end_idx
], end
, sizeof(XiveEND
));
401 static int spapr_xive_get_nvt(XiveRouter
*xrtr
,
402 uint8_t nvt_blk
, uint32_t nvt_idx
, XiveNVT
*nvt
)
404 uint32_t vcpu_id
= spapr_xive_nvt_to_target(nvt_blk
, nvt_idx
);
405 PowerPCCPU
*cpu
= spapr_find_cpu(vcpu_id
);
408 /* TODO: should we assert() if we can find a NVT ? */
413 * sPAPR does not maintain a NVT table. Return that the NVT is
414 * valid if we have found a matching CPU
416 nvt
->w0
= cpu_to_be32(NVT_W0_VALID
);
420 static int spapr_xive_write_nvt(XiveRouter
*xrtr
, uint8_t nvt_blk
,
421 uint32_t nvt_idx
, XiveNVT
*nvt
,
425 * We don't need to write back to the NVTs because the sPAPR
426 * machine should never hit a non-scheduled NVT. It should never
429 g_assert_not_reached();
432 static int spapr_xive_match_nvt(XivePresenter
*xptr
, uint8_t format
,
433 uint8_t nvt_blk
, uint32_t nvt_idx
,
434 bool cam_ignore
, uint8_t priority
,
435 uint32_t logic_serv
, XiveTCTXMatch
*match
)
441 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
442 XiveTCTX
*tctx
= spapr_cpu_state(cpu
)->tctx
;
446 * Skip partially initialized vCPUs. This can happen when
447 * vCPUs are hotplugged.
454 * Check the thread context CAM lines and record matches.
456 ring
= xive_presenter_tctx_match(xptr
, tctx
, format
, nvt_blk
, nvt_idx
,
457 cam_ignore
, logic_serv
);
459 * Save the matching thread interrupt context and follow on to
460 * check for duplicates which are invalid.
464 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: already found a thread "
465 "context NVT %x/%x\n", nvt_blk
, nvt_idx
);
478 static uint8_t spapr_xive_get_block_id(XiveRouter
*xrtr
)
480 return SPAPR_XIVE_BLOCK_ID
;
483 static const VMStateDescription vmstate_spapr_xive_end
= {
484 .name
= TYPE_SPAPR_XIVE
"/end",
486 .minimum_version_id
= 1,
487 .fields
= (VMStateField
[]) {
488 VMSTATE_UINT32(w0
, XiveEND
),
489 VMSTATE_UINT32(w1
, XiveEND
),
490 VMSTATE_UINT32(w2
, XiveEND
),
491 VMSTATE_UINT32(w3
, XiveEND
),
492 VMSTATE_UINT32(w4
, XiveEND
),
493 VMSTATE_UINT32(w5
, XiveEND
),
494 VMSTATE_UINT32(w6
, XiveEND
),
495 VMSTATE_UINT32(w7
, XiveEND
),
496 VMSTATE_END_OF_LIST()
500 static const VMStateDescription vmstate_spapr_xive_eas
= {
501 .name
= TYPE_SPAPR_XIVE
"/eas",
503 .minimum_version_id
= 1,
504 .fields
= (VMStateField
[]) {
505 VMSTATE_UINT64(w
, XiveEAS
),
506 VMSTATE_END_OF_LIST()
510 static int vmstate_spapr_xive_pre_save(void *opaque
)
512 if (kvm_irqchip_in_kernel()) {
513 return kvmppc_xive_pre_save(SPAPR_XIVE(opaque
));
520 * Called by the sPAPR IRQ backend 'post_load' method at the machine
523 static int spapr_xive_post_load(SpaprInterruptController
*intc
, int version_id
)
525 if (kvm_irqchip_in_kernel()) {
526 return kvmppc_xive_post_load(SPAPR_XIVE(intc
), version_id
);
532 static const VMStateDescription vmstate_spapr_xive
= {
533 .name
= TYPE_SPAPR_XIVE
,
535 .minimum_version_id
= 1,
536 .pre_save
= vmstate_spapr_xive_pre_save
,
537 .post_load
= NULL
, /* handled at the machine level */
538 .fields
= (VMStateField
[]) {
539 VMSTATE_UINT32_EQUAL(nr_irqs
, SpaprXive
, NULL
),
540 VMSTATE_STRUCT_VARRAY_POINTER_UINT32(eat
, SpaprXive
, nr_irqs
,
541 vmstate_spapr_xive_eas
, XiveEAS
),
542 VMSTATE_STRUCT_VARRAY_POINTER_UINT32(endt
, SpaprXive
, nr_ends
,
543 vmstate_spapr_xive_end
, XiveEND
),
544 VMSTATE_END_OF_LIST()
548 static int spapr_xive_claim_irq(SpaprInterruptController
*intc
, int lisn
,
549 bool lsi
, Error
**errp
)
551 SpaprXive
*xive
= SPAPR_XIVE(intc
);
552 XiveSource
*xsrc
= &xive
->source
;
554 assert(lisn
< xive
->nr_irqs
);
556 if (xive_eas_is_valid(&xive
->eat
[lisn
])) {
557 error_setg(errp
, "IRQ %d is not free", lisn
);
562 * Set default values when allocating an IRQ number
564 xive
->eat
[lisn
].w
|= cpu_to_be64(EAS_VALID
| EAS_MASKED
);
566 xive_source_irq_set_lsi(xsrc
, lisn
);
569 if (kvm_irqchip_in_kernel()) {
570 return kvmppc_xive_source_reset_one(xsrc
, lisn
, errp
);
576 static void spapr_xive_free_irq(SpaprInterruptController
*intc
, int lisn
)
578 SpaprXive
*xive
= SPAPR_XIVE(intc
);
579 assert(lisn
< xive
->nr_irqs
);
581 xive
->eat
[lisn
].w
&= cpu_to_be64(~EAS_VALID
);
584 static Property spapr_xive_properties
[] = {
585 DEFINE_PROP_UINT32("nr-irqs", SpaprXive
, nr_irqs
, 0),
586 DEFINE_PROP_UINT32("nr-ends", SpaprXive
, nr_ends
, 0),
587 DEFINE_PROP_UINT64("vc-base", SpaprXive
, vc_base
, SPAPR_XIVE_VC_BASE
),
588 DEFINE_PROP_UINT64("tm-base", SpaprXive
, tm_base
, SPAPR_XIVE_TM_BASE
),
589 DEFINE_PROP_END_OF_LIST(),
592 static int spapr_xive_cpu_intc_create(SpaprInterruptController
*intc
,
593 PowerPCCPU
*cpu
, Error
**errp
)
595 SpaprXive
*xive
= SPAPR_XIVE(intc
);
597 SpaprCpuState
*spapr_cpu
= spapr_cpu_state(cpu
);
599 obj
= xive_tctx_create(OBJECT(cpu
), XIVE_PRESENTER(xive
), errp
);
604 spapr_cpu
->tctx
= XIVE_TCTX(obj
);
608 static void xive_tctx_set_os_cam(XiveTCTX
*tctx
, uint32_t os_cam
)
610 uint32_t qw1w2
= cpu_to_be32(TM_QW1W2_VO
| os_cam
);
611 memcpy(&tctx
->regs
[TM_QW1_OS
+ TM_WORD2
], &qw1w2
, 4);
614 static void spapr_xive_cpu_intc_reset(SpaprInterruptController
*intc
,
617 XiveTCTX
*tctx
= spapr_cpu_state(cpu
)->tctx
;
621 xive_tctx_reset(tctx
);
624 * When a Virtual Processor is scheduled to run on a HW thread,
625 * the hypervisor pushes its identifier in the OS CAM line.
626 * Emulate the same behavior under QEMU.
628 spapr_xive_cpu_to_nvt(cpu
, &nvt_blk
, &nvt_idx
);
630 xive_tctx_set_os_cam(tctx
, xive_nvt_cam_line(nvt_blk
, nvt_idx
));
633 static void spapr_xive_cpu_intc_destroy(SpaprInterruptController
*intc
,
636 SpaprCpuState
*spapr_cpu
= spapr_cpu_state(cpu
);
638 xive_tctx_destroy(spapr_cpu
->tctx
);
639 spapr_cpu
->tctx
= NULL
;
642 static void spapr_xive_set_irq(SpaprInterruptController
*intc
, int irq
, int val
)
644 SpaprXive
*xive
= SPAPR_XIVE(intc
);
646 if (kvm_irqchip_in_kernel()) {
647 kvmppc_xive_source_set_irq(&xive
->source
, irq
, val
);
649 xive_source_set_irq(&xive
->source
, irq
, val
);
653 static void spapr_xive_print_info(SpaprInterruptController
*intc
, Monitor
*mon
)
655 SpaprXive
*xive
= SPAPR_XIVE(intc
);
659 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
661 xive_tctx_pic_print_info(spapr_cpu_state(cpu
)->tctx
, mon
);
664 spapr_xive_pic_print_info(xive
, mon
);
667 static void spapr_xive_dt(SpaprInterruptController
*intc
, uint32_t nr_servers
,
668 void *fdt
, uint32_t phandle
)
670 SpaprXive
*xive
= SPAPR_XIVE(intc
);
672 uint64_t timas
[2 * 2];
673 /* Interrupt number ranges for the IPIs */
674 uint32_t lisn_ranges
[] = {
675 cpu_to_be32(SPAPR_IRQ_IPI
),
676 cpu_to_be32(SPAPR_IRQ_IPI
+ nr_servers
),
679 * EQ size - the sizes of pages supported by the system 4K, 64K,
680 * 2M, 16M. We only advertise 64K for the moment.
682 uint32_t eq_sizes
[] = {
683 cpu_to_be32(16), /* 64K */
686 * The following array is in sync with the reserved priorities
687 * defined by the 'spapr_xive_priority_is_reserved' routine.
689 uint32_t plat_res_int_priorities
[] = {
690 cpu_to_be32(7), /* start */
691 cpu_to_be32(0xf8), /* count */
694 /* Thread Interrupt Management Area : User (ring 3) and OS (ring 2) */
695 timas
[0] = cpu_to_be64(xive
->tm_base
+
696 XIVE_TM_USER_PAGE
* (1ull << TM_SHIFT
));
697 timas
[1] = cpu_to_be64(1ull << TM_SHIFT
);
698 timas
[2] = cpu_to_be64(xive
->tm_base
+
699 XIVE_TM_OS_PAGE
* (1ull << TM_SHIFT
));
700 timas
[3] = cpu_to_be64(1ull << TM_SHIFT
);
702 _FDT(node
= fdt_add_subnode(fdt
, 0, xive
->nodename
));
704 _FDT(fdt_setprop_string(fdt
, node
, "device_type", "power-ivpe"));
705 _FDT(fdt_setprop(fdt
, node
, "reg", timas
, sizeof(timas
)));
707 _FDT(fdt_setprop_string(fdt
, node
, "compatible", "ibm,power-ivpe"));
708 _FDT(fdt_setprop(fdt
, node
, "ibm,xive-eq-sizes", eq_sizes
,
710 _FDT(fdt_setprop(fdt
, node
, "ibm,xive-lisn-ranges", lisn_ranges
,
711 sizeof(lisn_ranges
)));
713 /* For Linux to link the LSIs to the interrupt controller. */
714 _FDT(fdt_setprop(fdt
, node
, "interrupt-controller", NULL
, 0));
715 _FDT(fdt_setprop_cell(fdt
, node
, "#interrupt-cells", 2));
718 _FDT(fdt_setprop_cell(fdt
, node
, "linux,phandle", phandle
));
719 _FDT(fdt_setprop_cell(fdt
, node
, "phandle", phandle
));
722 * The "ibm,plat-res-int-priorities" property defines the priority
723 * ranges reserved by the hypervisor
725 _FDT(fdt_setprop(fdt
, 0, "ibm,plat-res-int-priorities",
726 plat_res_int_priorities
, sizeof(plat_res_int_priorities
)));
729 static int spapr_xive_activate(SpaprInterruptController
*intc
,
730 uint32_t nr_servers
, Error
**errp
)
732 SpaprXive
*xive
= SPAPR_XIVE(intc
);
735 int rc
= spapr_irq_init_kvm(kvmppc_xive_connect
, intc
, nr_servers
,
742 /* Activate the XIVE MMIOs */
743 spapr_xive_mmio_set_enabled(xive
, true);
748 static void spapr_xive_deactivate(SpaprInterruptController
*intc
)
750 SpaprXive
*xive
= SPAPR_XIVE(intc
);
752 spapr_xive_mmio_set_enabled(xive
, false);
754 if (kvm_irqchip_in_kernel()) {
755 kvmppc_xive_disconnect(intc
);
759 static void spapr_xive_class_init(ObjectClass
*klass
, void *data
)
761 DeviceClass
*dc
= DEVICE_CLASS(klass
);
762 XiveRouterClass
*xrc
= XIVE_ROUTER_CLASS(klass
);
763 SpaprInterruptControllerClass
*sicc
= SPAPR_INTC_CLASS(klass
);
764 XivePresenterClass
*xpc
= XIVE_PRESENTER_CLASS(klass
);
765 SpaprXiveClass
*sxc
= SPAPR_XIVE_CLASS(klass
);
767 dc
->desc
= "sPAPR XIVE Interrupt Controller";
768 device_class_set_props(dc
, spapr_xive_properties
);
769 device_class_set_parent_realize(dc
, spapr_xive_realize
,
770 &sxc
->parent_realize
);
771 dc
->vmsd
= &vmstate_spapr_xive
;
773 xrc
->get_eas
= spapr_xive_get_eas
;
774 xrc
->get_end
= spapr_xive_get_end
;
775 xrc
->write_end
= spapr_xive_write_end
;
776 xrc
->get_nvt
= spapr_xive_get_nvt
;
777 xrc
->write_nvt
= spapr_xive_write_nvt
;
778 xrc
->get_block_id
= spapr_xive_get_block_id
;
780 sicc
->activate
= spapr_xive_activate
;
781 sicc
->deactivate
= spapr_xive_deactivate
;
782 sicc
->cpu_intc_create
= spapr_xive_cpu_intc_create
;
783 sicc
->cpu_intc_reset
= spapr_xive_cpu_intc_reset
;
784 sicc
->cpu_intc_destroy
= spapr_xive_cpu_intc_destroy
;
785 sicc
->claim_irq
= spapr_xive_claim_irq
;
786 sicc
->free_irq
= spapr_xive_free_irq
;
787 sicc
->set_irq
= spapr_xive_set_irq
;
788 sicc
->print_info
= spapr_xive_print_info
;
789 sicc
->dt
= spapr_xive_dt
;
790 sicc
->post_load
= spapr_xive_post_load
;
792 xpc
->match_nvt
= spapr_xive_match_nvt
;
795 static const TypeInfo spapr_xive_info
= {
796 .name
= TYPE_SPAPR_XIVE
,
797 .parent
= TYPE_XIVE_ROUTER
,
798 .instance_init
= spapr_xive_instance_init
,
799 .instance_size
= sizeof(SpaprXive
),
800 .class_init
= spapr_xive_class_init
,
801 .class_size
= sizeof(SpaprXiveClass
),
802 .interfaces
= (InterfaceInfo
[]) {
808 static void spapr_xive_register_types(void)
810 type_register_static(&spapr_xive_info
);
813 type_init(spapr_xive_register_types
)
818 * The terminology used by the XIVE hcalls is the following :
821 * EQ Event Queue assigned by OS to receive event data
822 * ESB page for source interrupt management
823 * LISN Logical Interrupt Source Number identifying a source in the
825 * EISN Effective Interrupt Source Number used by guest OS to
826 * identify source in the guest
828 * The EAS, END, NVT structures are not exposed.
832 * Linux hosts under OPAL reserve priority 7 for their own escalation
833 * interrupts (DD2.X POWER9). So we only allow the guest to use
836 static bool spapr_xive_priority_is_reserved(uint8_t priority
)
841 case 7: /* OPAL escalation queue */
848 * The H_INT_GET_SOURCE_INFO hcall() is used to obtain the logical
849 * real address of the MMIO page through which the Event State Buffer
850 * entry associated with the value of the "lisn" parameter is managed.
856 * - R5: "lisn" is per "interrupts", "interrupt-map", or
857 * "ibm,xive-lisn-ranges" properties, or as returned by the
858 * ibm,query-interrupt-source-number RTAS call, or as returned
859 * by the H_ALLOCATE_VAS_WINDOW hcall
863 * Bits 0-59: Reserved
864 * Bit 60: H_INT_ESB must be used for Event State Buffer
866 * Bit 61: 1 == LSI 0 == MSI
867 * Bit 62: the full function page supports trigger
868 * Bit 63: Store EOI Supported
869 * - R5: Logical Real address of full function Event State Buffer
870 * management page, -1 if H_INT_ESB hcall flag is set to 1.
871 * - R6: Logical Real Address of trigger only Event State Buffer
872 * management page or -1.
873 * - R7: Power of 2 page size for the ESB management pages returned in
877 #define SPAPR_XIVE_SRC_H_INT_ESB PPC_BIT(60) /* ESB manage with H_INT_ESB */
878 #define SPAPR_XIVE_SRC_LSI PPC_BIT(61) /* Virtual LSI type */
879 #define SPAPR_XIVE_SRC_TRIGGER PPC_BIT(62) /* Trigger and management
881 #define SPAPR_XIVE_SRC_STORE_EOI PPC_BIT(63) /* Store EOI support */
883 static target_ulong
h_int_get_source_info(PowerPCCPU
*cpu
,
884 SpaprMachineState
*spapr
,
888 SpaprXive
*xive
= spapr
->xive
;
889 XiveSource
*xsrc
= &xive
->source
;
890 target_ulong flags
= args
[0];
891 target_ulong lisn
= args
[1];
893 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
901 if (lisn
>= xive
->nr_irqs
) {
902 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
907 if (!xive_eas_is_valid(&xive
->eat
[lisn
])) {
908 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
914 * All sources are emulated under the main XIVE object and share
915 * the same characteristics.
918 if (!xive_source_esb_has_2page(xsrc
)) {
919 args
[0] |= SPAPR_XIVE_SRC_TRIGGER
;
921 if (xsrc
->esb_flags
& XIVE_SRC_STORE_EOI
) {
922 args
[0] |= SPAPR_XIVE_SRC_STORE_EOI
;
926 * Force the use of the H_INT_ESB hcall in case of an LSI
927 * interrupt. This is necessary under KVM to re-trigger the
928 * interrupt if the level is still asserted
930 if (xive_source_irq_is_lsi(xsrc
, lisn
)) {
931 args
[0] |= SPAPR_XIVE_SRC_H_INT_ESB
| SPAPR_XIVE_SRC_LSI
;
934 if (!(args
[0] & SPAPR_XIVE_SRC_H_INT_ESB
)) {
935 args
[1] = xive
->vc_base
+ xive_source_esb_mgmt(xsrc
, lisn
);
940 if (xive_source_esb_has_2page(xsrc
) &&
941 !(args
[0] & SPAPR_XIVE_SRC_H_INT_ESB
)) {
942 args
[2] = xive
->vc_base
+ xive_source_esb_page(xsrc
, lisn
);
947 if (xive_source_esb_has_2page(xsrc
)) {
948 args
[3] = xsrc
->esb_shift
- 1;
950 args
[3] = xsrc
->esb_shift
;
957 * The H_INT_SET_SOURCE_CONFIG hcall() is used to assign a Logical
958 * Interrupt Source to a target. The Logical Interrupt Source is
959 * designated with the "lisn" parameter and the target is designated
960 * with the "target" and "priority" parameters. Upon return from the
961 * hcall(), no additional interrupts will be directed to the old EQ.
966 * Bits 0-61: Reserved
967 * Bit 62: set the "eisn" in the EAS
968 * Bit 63: masks the interrupt source in the hardware interrupt
969 * control structure. An interrupt masked by this mechanism will
970 * be dropped, but it's source state bits will still be
971 * set. There is no race-free way of unmasking and restoring the
972 * source. Thus this should only be used in interrupts that are
973 * also masked at the source, and only in cases where the
974 * interrupt is not meant to be used for a large amount of time
975 * because no valid target exists for it for example
976 * - R5: "lisn" is per "interrupts", "interrupt-map", or
977 * "ibm,xive-lisn-ranges" properties, or as returned by the
978 * ibm,query-interrupt-source-number RTAS call, or as returned by
979 * the H_ALLOCATE_VAS_WINDOW hcall
980 * - R6: "target" is per "ibm,ppc-interrupt-server#s" or
981 * "ibm,ppc-interrupt-gserver#s"
982 * - R7: "priority" is a valid priority not in
983 * "ibm,plat-res-int-priorities"
984 * - R8: "eisn" is the guest EISN associated with the "lisn"
990 #define SPAPR_XIVE_SRC_SET_EISN PPC_BIT(62)
991 #define SPAPR_XIVE_SRC_MASK PPC_BIT(63)
993 static target_ulong
h_int_set_source_config(PowerPCCPU
*cpu
,
994 SpaprMachineState
*spapr
,
998 SpaprXive
*xive
= spapr
->xive
;
999 XiveEAS eas
, new_eas
;
1000 target_ulong flags
= args
[0];
1001 target_ulong lisn
= args
[1];
1002 target_ulong target
= args
[2];
1003 target_ulong priority
= args
[3];
1004 target_ulong eisn
= args
[4];
1008 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1012 if (flags
& ~(SPAPR_XIVE_SRC_SET_EISN
| SPAPR_XIVE_SRC_MASK
)) {
1016 if (lisn
>= xive
->nr_irqs
) {
1017 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
1022 eas
= xive
->eat
[lisn
];
1023 if (!xive_eas_is_valid(&eas
)) {
1024 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
1029 /* priority 0xff is used to reset the EAS */
1030 if (priority
== 0xff) {
1031 new_eas
.w
= cpu_to_be64(EAS_VALID
| EAS_MASKED
);
1035 if (flags
& SPAPR_XIVE_SRC_MASK
) {
1036 new_eas
.w
= eas
.w
| cpu_to_be64(EAS_MASKED
);
1038 new_eas
.w
= eas
.w
& cpu_to_be64(~EAS_MASKED
);
1041 if (spapr_xive_priority_is_reserved(priority
)) {
1042 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: priority " TARGET_FMT_ld
1043 " is reserved\n", priority
);
1048 * Validate that "target" is part of the list of threads allocated
1049 * to the partition. For that, find the END corresponding to the
1052 if (spapr_xive_target_to_end(target
, priority
, &end_blk
, &end_idx
)) {
1056 new_eas
.w
= xive_set_field64(EAS_END_BLOCK
, new_eas
.w
, end_blk
);
1057 new_eas
.w
= xive_set_field64(EAS_END_INDEX
, new_eas
.w
, end_idx
);
1059 if (flags
& SPAPR_XIVE_SRC_SET_EISN
) {
1060 new_eas
.w
= xive_set_field64(EAS_END_DATA
, new_eas
.w
, eisn
);
1063 if (kvm_irqchip_in_kernel()) {
1064 Error
*local_err
= NULL
;
1066 kvmppc_xive_set_source_config(xive
, lisn
, &new_eas
, &local_err
);
1068 error_report_err(local_err
);
1074 xive
->eat
[lisn
] = new_eas
;
1079 * The H_INT_GET_SOURCE_CONFIG hcall() is used to determine to which
1080 * target/priority pair is assigned to the specified Logical Interrupt
1086 * Bits 0-63 Reserved
1087 * - R5: "lisn" is per "interrupts", "interrupt-map", or
1088 * "ibm,xive-lisn-ranges" properties, or as returned by the
1089 * ibm,query-interrupt-source-number RTAS call, or as
1090 * returned by the H_ALLOCATE_VAS_WINDOW hcall
1093 * - R4: Target to which the specified Logical Interrupt Source is
1095 * - R5: Priority to which the specified Logical Interrupt Source is
1097 * - R6: EISN for the specified Logical Interrupt Source (this will be
1098 * equivalent to the LISN if not changed by H_INT_SET_SOURCE_CONFIG)
1100 static target_ulong
h_int_get_source_config(PowerPCCPU
*cpu
,
1101 SpaprMachineState
*spapr
,
1102 target_ulong opcode
,
1105 SpaprXive
*xive
= spapr
->xive
;
1106 target_ulong flags
= args
[0];
1107 target_ulong lisn
= args
[1];
1111 uint32_t end_idx
, nvt_idx
;
1113 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1121 if (lisn
>= xive
->nr_irqs
) {
1122 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
1127 eas
= xive
->eat
[lisn
];
1128 if (!xive_eas_is_valid(&eas
)) {
1129 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
1134 /* EAS_END_BLOCK is unused on sPAPR */
1135 end_idx
= xive_get_field64(EAS_END_INDEX
, eas
.w
);
1137 assert(end_idx
< xive
->nr_ends
);
1138 end
= &xive
->endt
[end_idx
];
1140 nvt_blk
= xive_get_field32(END_W6_NVT_BLOCK
, end
->w6
);
1141 nvt_idx
= xive_get_field32(END_W6_NVT_INDEX
, end
->w6
);
1142 args
[0] = spapr_xive_nvt_to_target(nvt_blk
, nvt_idx
);
1144 if (xive_eas_is_masked(&eas
)) {
1147 args
[1] = xive_get_field32(END_W7_F0_PRIORITY
, end
->w7
);
1150 args
[2] = xive_get_field64(EAS_END_DATA
, eas
.w
);
1156 * The H_INT_GET_QUEUE_INFO hcall() is used to get the logical real
1157 * address of the notification management page associated with the
1158 * specified target and priority.
1163 * Bits 0-63 Reserved
1164 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
1165 * "ibm,ppc-interrupt-gserver#s"
1166 * - R6: "priority" is a valid priority not in
1167 * "ibm,plat-res-int-priorities"
1170 * - R4: Logical real address of notification page
1171 * - R5: Power of 2 page size of the notification page
1173 static target_ulong
h_int_get_queue_info(PowerPCCPU
*cpu
,
1174 SpaprMachineState
*spapr
,
1175 target_ulong opcode
,
1178 SpaprXive
*xive
= spapr
->xive
;
1179 XiveENDSource
*end_xsrc
= &xive
->end_source
;
1180 target_ulong flags
= args
[0];
1181 target_ulong target
= args
[1];
1182 target_ulong priority
= args
[2];
1187 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1196 * H_STATE should be returned if a H_INT_RESET is in progress.
1197 * This is not needed when running the emulation under QEMU
1200 if (spapr_xive_priority_is_reserved(priority
)) {
1201 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: priority " TARGET_FMT_ld
1202 " is reserved\n", priority
);
1207 * Validate that "target" is part of the list of threads allocated
1208 * to the partition. For that, find the END corresponding to the
1211 if (spapr_xive_target_to_end(target
, priority
, &end_blk
, &end_idx
)) {
1215 assert(end_idx
< xive
->nr_ends
);
1216 end
= &xive
->endt
[end_idx
];
1218 args
[0] = xive
->end_base
+ (1ull << (end_xsrc
->esb_shift
+ 1)) * end_idx
;
1219 if (xive_end_is_enqueue(end
)) {
1220 args
[1] = xive_get_field32(END_W0_QSIZE
, end
->w0
) + 12;
1229 * The H_INT_SET_QUEUE_CONFIG hcall() is used to set or reset a EQ for
1230 * a given "target" and "priority". It is also used to set the
1231 * notification config associated with the EQ. An EQ size of 0 is
1232 * used to reset the EQ config for a given target and priority. If
1233 * resetting the EQ config, the END associated with the given "target"
1234 * and "priority" will be changed to disable queueing.
1236 * Upon return from the hcall(), no additional interrupts will be
1237 * directed to the old EQ (if one was set). The old EQ (if one was
1238 * set) should be investigated for interrupts that occurred prior to
1239 * or during the hcall().
1244 * Bits 0-62: Reserved
1245 * Bit 63: Unconditional Notify (n) per the XIVE spec
1246 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
1247 * "ibm,ppc-interrupt-gserver#s"
1248 * - R6: "priority" is a valid priority not in
1249 * "ibm,plat-res-int-priorities"
1250 * - R7: "eventQueue": The logical real address of the start of the EQ
1251 * - R8: "eventQueueSize": The power of 2 EQ size per "ibm,xive-eq-sizes"
1257 #define SPAPR_XIVE_END_ALWAYS_NOTIFY PPC_BIT(63)
1259 static target_ulong
h_int_set_queue_config(PowerPCCPU
*cpu
,
1260 SpaprMachineState
*spapr
,
1261 target_ulong opcode
,
1264 SpaprXive
*xive
= spapr
->xive
;
1265 target_ulong flags
= args
[0];
1266 target_ulong target
= args
[1];
1267 target_ulong priority
= args
[2];
1268 target_ulong qpage
= args
[3];
1269 target_ulong qsize
= args
[4];
1271 uint8_t end_blk
, nvt_blk
;
1272 uint32_t end_idx
, nvt_idx
;
1274 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1278 if (flags
& ~SPAPR_XIVE_END_ALWAYS_NOTIFY
) {
1283 * H_STATE should be returned if a H_INT_RESET is in progress.
1284 * This is not needed when running the emulation under QEMU
1287 if (spapr_xive_priority_is_reserved(priority
)) {
1288 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: priority " TARGET_FMT_ld
1289 " is reserved\n", priority
);
1294 * Validate that "target" is part of the list of threads allocated
1295 * to the partition. For that, find the END corresponding to the
1299 if (spapr_xive_target_to_end(target
, priority
, &end_blk
, &end_idx
)) {
1303 assert(end_idx
< xive
->nr_ends
);
1304 memcpy(&end
, &xive
->endt
[end_idx
], sizeof(XiveEND
));
1311 if (!QEMU_IS_ALIGNED(qpage
, 1ul << qsize
)) {
1312 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: EQ @0x%" HWADDR_PRIx
1313 " is not naturally aligned with %" HWADDR_PRIx
"\n",
1314 qpage
, (hwaddr
)1 << qsize
);
1317 end
.w2
= cpu_to_be32((qpage
>> 32) & 0x0fffffff);
1318 end
.w3
= cpu_to_be32(qpage
& 0xffffffff);
1319 end
.w0
|= cpu_to_be32(END_W0_ENQUEUE
);
1320 end
.w0
= xive_set_field32(END_W0_QSIZE
, end
.w0
, qsize
- 12);
1323 /* reset queue and disable queueing */
1324 spapr_xive_end_reset(&end
);
1328 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: invalid EQ size %"PRIx64
"\n",
1334 hwaddr plen
= 1 << qsize
;
1338 * Validate the guest EQ. We should also check that the queue
1339 * has been zeroed by the OS.
1341 eq
= address_space_map(CPU(cpu
)->as
, qpage
, &plen
, true,
1342 MEMTXATTRS_UNSPECIFIED
);
1343 if (plen
!= 1 << qsize
) {
1344 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: failed to map EQ @0x%"
1345 HWADDR_PRIx
"\n", qpage
);
1348 address_space_unmap(CPU(cpu
)->as
, eq
, plen
, true, plen
);
1351 /* "target" should have been validated above */
1352 if (spapr_xive_target_to_nvt(target
, &nvt_blk
, &nvt_idx
)) {
1353 g_assert_not_reached();
1357 * Ensure the priority and target are correctly set (they will not
1358 * be right after allocation)
1360 end
.w6
= xive_set_field32(END_W6_NVT_BLOCK
, 0ul, nvt_blk
) |
1361 xive_set_field32(END_W6_NVT_INDEX
, 0ul, nvt_idx
);
1362 end
.w7
= xive_set_field32(END_W7_F0_PRIORITY
, 0ul, priority
);
1364 if (flags
& SPAPR_XIVE_END_ALWAYS_NOTIFY
) {
1365 end
.w0
|= cpu_to_be32(END_W0_UCOND_NOTIFY
);
1367 end
.w0
&= cpu_to_be32((uint32_t)~END_W0_UCOND_NOTIFY
);
1371 * The generation bit for the END starts at 1 and The END page
1372 * offset counter starts at 0.
1374 end
.w1
= cpu_to_be32(END_W1_GENERATION
) |
1375 xive_set_field32(END_W1_PAGE_OFF
, 0ul, 0ul);
1376 end
.w0
|= cpu_to_be32(END_W0_VALID
);
1379 * TODO: issue syncs required to ensure all in-flight interrupts
1380 * are complete on the old END
1384 if (kvm_irqchip_in_kernel()) {
1385 Error
*local_err
= NULL
;
1387 kvmppc_xive_set_queue_config(xive
, end_blk
, end_idx
, &end
, &local_err
);
1389 error_report_err(local_err
);
1395 memcpy(&xive
->endt
[end_idx
], &end
, sizeof(XiveEND
));
1400 * The H_INT_GET_QUEUE_CONFIG hcall() is used to get a EQ for a given
1401 * target and priority.
1406 * Bits 0-62: Reserved
1407 * Bit 63: Debug: Return debug data
1408 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
1409 * "ibm,ppc-interrupt-gserver#s"
1410 * - R6: "priority" is a valid priority not in
1411 * "ibm,plat-res-int-priorities"
1415 * Bits 0-61: Reserved
1416 * Bit 62: The value of Event Queue Generation Number (g) per
1417 * the XIVE spec if "Debug" = 1
1418 * Bit 63: The value of Unconditional Notify (n) per the XIVE spec
1419 * - R5: The logical real address of the start of the EQ
1420 * - R6: The power of 2 EQ size per "ibm,xive-eq-sizes"
1421 * - R7: The value of Event Queue Offset Counter per XIVE spec
1422 * if "Debug" = 1, else 0
1426 #define SPAPR_XIVE_END_DEBUG PPC_BIT(63)
1428 static target_ulong
h_int_get_queue_config(PowerPCCPU
*cpu
,
1429 SpaprMachineState
*spapr
,
1430 target_ulong opcode
,
1433 SpaprXive
*xive
= spapr
->xive
;
1434 target_ulong flags
= args
[0];
1435 target_ulong target
= args
[1];
1436 target_ulong priority
= args
[2];
1441 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1445 if (flags
& ~SPAPR_XIVE_END_DEBUG
) {
1450 * H_STATE should be returned if a H_INT_RESET is in progress.
1451 * This is not needed when running the emulation under QEMU
1454 if (spapr_xive_priority_is_reserved(priority
)) {
1455 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: priority " TARGET_FMT_ld
1456 " is reserved\n", priority
);
1461 * Validate that "target" is part of the list of threads allocated
1462 * to the partition. For that, find the END corresponding to the
1465 if (spapr_xive_target_to_end(target
, priority
, &end_blk
, &end_idx
)) {
1469 assert(end_idx
< xive
->nr_ends
);
1470 end
= &xive
->endt
[end_idx
];
1473 if (xive_end_is_notify(end
)) {
1474 args
[0] |= SPAPR_XIVE_END_ALWAYS_NOTIFY
;
1477 if (xive_end_is_enqueue(end
)) {
1478 args
[1] = xive_end_qaddr(end
);
1479 args
[2] = xive_get_field32(END_W0_QSIZE
, end
->w0
) + 12;
1485 if (kvm_irqchip_in_kernel()) {
1486 Error
*local_err
= NULL
;
1488 kvmppc_xive_get_queue_config(xive
, end_blk
, end_idx
, end
, &local_err
);
1490 error_report_err(local_err
);
1495 /* TODO: do we need any locking on the END ? */
1496 if (flags
& SPAPR_XIVE_END_DEBUG
) {
1497 /* Load the event queue generation number into the return flags */
1498 args
[0] |= (uint64_t)xive_get_field32(END_W1_GENERATION
, end
->w1
) << 62;
1500 /* Load R7 with the event queue offset counter */
1501 args
[3] = xive_get_field32(END_W1_PAGE_OFF
, end
->w1
);
1510 * The H_INT_SET_OS_REPORTING_LINE hcall() is used to set the
1511 * reporting cache line pair for the calling thread. The reporting
1512 * cache lines will contain the OS interrupt context when the OS
1513 * issues a CI store byte to @TIMA+0xC10 to acknowledge the OS
1514 * interrupt. The reporting cache lines can be reset by inputting -1
1515 * in "reportingLine". Issuing the CI store byte without reporting
1516 * cache lines registered will result in the data not being accessible
1522 * Bits 0-63: Reserved
1523 * - R5: "reportingLine": The logical real address of the reporting cache
1529 static target_ulong
h_int_set_os_reporting_line(PowerPCCPU
*cpu
,
1530 SpaprMachineState
*spapr
,
1531 target_ulong opcode
,
1534 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1539 * H_STATE should be returned if a H_INT_RESET is in progress.
1540 * This is not needed when running the emulation under QEMU
1543 /* TODO: H_INT_SET_OS_REPORTING_LINE */
1548 * The H_INT_GET_OS_REPORTING_LINE hcall() is used to get the logical
1549 * real address of the reporting cache line pair set for the input
1550 * "target". If no reporting cache line pair has been set, -1 is
1556 * Bits 0-63: Reserved
1557 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
1558 * "ibm,ppc-interrupt-gserver#s"
1559 * - R6: "reportingLine": The logical real address of the reporting
1563 * - R4: The logical real address of the reporting line if set, else -1
1565 static target_ulong
h_int_get_os_reporting_line(PowerPCCPU
*cpu
,
1566 SpaprMachineState
*spapr
,
1567 target_ulong opcode
,
1570 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1575 * H_STATE should be returned if a H_INT_RESET is in progress.
1576 * This is not needed when running the emulation under QEMU
1579 /* TODO: H_INT_GET_OS_REPORTING_LINE */
1584 * The H_INT_ESB hcall() is used to issue a load or store to the ESB
1585 * page for the input "lisn". This hcall is only supported for LISNs
1586 * that have the ESB hcall flag set to 1 when returned from hcall()
1587 * H_INT_GET_SOURCE_INFO.
1592 * Bits 0-62: Reserved
1593 * bit 63: Store: Store=1, store operation, else load operation
1594 * - R5: "lisn" is per "interrupts", "interrupt-map", or
1595 * "ibm,xive-lisn-ranges" properties, or as returned by the
1596 * ibm,query-interrupt-source-number RTAS call, or as
1597 * returned by the H_ALLOCATE_VAS_WINDOW hcall
1598 * - R6: "esbOffset" is the offset into the ESB page for the load or
1600 * - R7: "storeData" is the data to write for a store operation
1603 * - R4: The value of the load if load operation, else -1
1606 #define SPAPR_XIVE_ESB_STORE PPC_BIT(63)
1608 static target_ulong
h_int_esb(PowerPCCPU
*cpu
,
1609 SpaprMachineState
*spapr
,
1610 target_ulong opcode
,
1613 SpaprXive
*xive
= spapr
->xive
;
1615 target_ulong flags
= args
[0];
1616 target_ulong lisn
= args
[1];
1617 target_ulong offset
= args
[2];
1618 target_ulong data
= args
[3];
1620 XiveSource
*xsrc
= &xive
->source
;
1622 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1626 if (flags
& ~SPAPR_XIVE_ESB_STORE
) {
1630 if (lisn
>= xive
->nr_irqs
) {
1631 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
1636 eas
= xive
->eat
[lisn
];
1637 if (!xive_eas_is_valid(&eas
)) {
1638 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
1643 if (offset
> (1ull << xsrc
->esb_shift
)) {
1647 if (kvm_irqchip_in_kernel()) {
1648 args
[0] = kvmppc_xive_esb_rw(xsrc
, lisn
, offset
, data
,
1649 flags
& SPAPR_XIVE_ESB_STORE
);
1651 mmio_addr
= xive
->vc_base
+ xive_source_esb_mgmt(xsrc
, lisn
) + offset
;
1653 if (dma_memory_rw(&address_space_memory
, mmio_addr
, &data
, 8,
1654 (flags
& SPAPR_XIVE_ESB_STORE
))) {
1655 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: failed to access ESB @0x%"
1656 HWADDR_PRIx
"\n", mmio_addr
);
1659 args
[0] = (flags
& SPAPR_XIVE_ESB_STORE
) ? -1 : data
;
1665 * The H_INT_SYNC hcall() is used to issue hardware syncs that will
1666 * ensure any in flight events for the input lisn are in the event
1672 * Bits 0-63: Reserved
1673 * - R5: "lisn" is per "interrupts", "interrupt-map", or
1674 * "ibm,xive-lisn-ranges" properties, or as returned by the
1675 * ibm,query-interrupt-source-number RTAS call, or as
1676 * returned by the H_ALLOCATE_VAS_WINDOW hcall
1681 static target_ulong
h_int_sync(PowerPCCPU
*cpu
,
1682 SpaprMachineState
*spapr
,
1683 target_ulong opcode
,
1686 SpaprXive
*xive
= spapr
->xive
;
1688 target_ulong flags
= args
[0];
1689 target_ulong lisn
= args
[1];
1691 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1699 if (lisn
>= xive
->nr_irqs
) {
1700 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
1705 eas
= xive
->eat
[lisn
];
1706 if (!xive_eas_is_valid(&eas
)) {
1707 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
1713 * H_STATE should be returned if a H_INT_RESET is in progress.
1714 * This is not needed when running the emulation under QEMU
1718 * This is not real hardware. Nothing to be done unless when
1722 if (kvm_irqchip_in_kernel()) {
1723 Error
*local_err
= NULL
;
1725 kvmppc_xive_sync_source(xive
, lisn
, &local_err
);
1727 error_report_err(local_err
);
1735 * The H_INT_RESET hcall() is used to reset all of the partition's
1736 * interrupt exploitation structures to their initial state. This
1737 * means losing all previously set interrupt state set via
1738 * H_INT_SET_SOURCE_CONFIG and H_INT_SET_QUEUE_CONFIG.
1743 * Bits 0-63: Reserved
1748 static target_ulong
h_int_reset(PowerPCCPU
*cpu
,
1749 SpaprMachineState
*spapr
,
1750 target_ulong opcode
,
1753 SpaprXive
*xive
= spapr
->xive
;
1754 target_ulong flags
= args
[0];
1756 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1764 device_legacy_reset(DEVICE(xive
));
1766 if (kvm_irqchip_in_kernel()) {
1767 Error
*local_err
= NULL
;
1769 kvmppc_xive_reset(xive
, &local_err
);
1771 error_report_err(local_err
);
1778 void spapr_xive_hcall_init(SpaprMachineState
*spapr
)
1780 spapr_register_hypercall(H_INT_GET_SOURCE_INFO
, h_int_get_source_info
);
1781 spapr_register_hypercall(H_INT_SET_SOURCE_CONFIG
, h_int_set_source_config
);
1782 spapr_register_hypercall(H_INT_GET_SOURCE_CONFIG
, h_int_get_source_config
);
1783 spapr_register_hypercall(H_INT_GET_QUEUE_INFO
, h_int_get_queue_info
);
1784 spapr_register_hypercall(H_INT_SET_QUEUE_CONFIG
, h_int_set_queue_config
);
1785 spapr_register_hypercall(H_INT_GET_QUEUE_CONFIG
, h_int_get_queue_config
);
1786 spapr_register_hypercall(H_INT_SET_OS_REPORTING_LINE
,
1787 h_int_set_os_reporting_line
);
1788 spapr_register_hypercall(H_INT_GET_OS_REPORTING_LINE
,
1789 h_int_get_os_reporting_line
);
1790 spapr_register_hypercall(H_INT_ESB
, h_int_esb
);
1791 spapr_register_hypercall(H_INT_SYNC
, h_int_sync
);
1792 spapr_register_hypercall(H_INT_RESET
, h_int_reset
);