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 "hw/ppc/fdt.h"
20 #include "hw/ppc/spapr.h"
21 #include "hw/ppc/spapr_cpu_core.h"
22 #include "hw/ppc/spapr_xive.h"
23 #include "hw/ppc/xive.h"
24 #include "hw/ppc/xive_regs.h"
25 #include "hw/qdev-properties.h"
29 * XIVE Virtualization Controller BAR and Thread Management 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 g_string_append_printf(buf
, "%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, buf
);
152 * kvm_irqchip_in_kernel() will cause the compiler to turn this
153 * info a nop if CONFIG_KVM isn't defined.
155 #define spapr_xive_in_kernel(xive) \
156 (kvm_irqchip_in_kernel() && (xive)->fd != -1)
158 static void spapr_xive_pic_print_info(SpaprXive
*xive
, GString
*buf
)
160 XiveSource
*xsrc
= &xive
->source
;
163 if (spapr_xive_in_kernel(xive
)) {
164 Error
*local_err
= NULL
;
166 kvmppc_xive_synchronize_state(xive
, &local_err
);
168 error_report_err(local_err
);
173 g_string_append_printf(buf
, " LISN PQ EISN CPU/PRIO EQ\n");
175 for (i
= 0; i
< xive
->nr_irqs
; i
++) {
176 uint8_t pq
= xive_source_esb_get(xsrc
, i
);
177 XiveEAS
*eas
= &xive
->eat
[i
];
179 if (!xive_eas_is_valid(eas
)) {
183 g_string_append_printf(buf
, " %08x %s %c%c%c %s %08x ", i
,
184 xive_source_irq_is_lsi(xsrc
, i
) ? "LSI" : "MSI",
185 pq
& XIVE_ESB_VAL_P
? 'P' : '-',
186 pq
& XIVE_ESB_VAL_Q
? 'Q' : '-',
187 xive_source_is_asserted(xsrc
, i
) ? 'A' : ' ',
188 xive_eas_is_masked(eas
) ? "M" : " ",
189 (int) xive_get_field64(EAS_END_DATA
, eas
->w
));
191 if (!xive_eas_is_masked(eas
)) {
192 uint32_t end_idx
= xive_get_field64(EAS_END_INDEX
, eas
->w
);
195 assert(end_idx
< xive
->nr_ends
);
196 end
= &xive
->endt
[end_idx
];
198 if (xive_end_is_valid(end
)) {
199 spapr_xive_end_pic_print_info(xive
, end
, buf
);
203 g_string_append_c(buf
, '\n');
207 void spapr_xive_mmio_set_enabled(SpaprXive
*xive
, bool enable
)
209 memory_region_set_enabled(&xive
->source
.esb_mmio
, enable
);
210 memory_region_set_enabled(&xive
->tm_mmio
, enable
);
212 /* Disable the END ESBs until a guest OS makes use of them */
213 memory_region_set_enabled(&xive
->end_source
.esb_mmio
, false);
216 static void spapr_xive_tm_write(void *opaque
, hwaddr offset
,
217 uint64_t value
, unsigned size
)
219 XiveTCTX
*tctx
= spapr_cpu_state(POWERPC_CPU(current_cpu
))->tctx
;
221 xive_tctx_tm_write(XIVE_PRESENTER(opaque
), tctx
, offset
, value
, size
);
224 static uint64_t spapr_xive_tm_read(void *opaque
, hwaddr offset
, unsigned size
)
226 XiveTCTX
*tctx
= spapr_cpu_state(POWERPC_CPU(current_cpu
))->tctx
;
228 return xive_tctx_tm_read(XIVE_PRESENTER(opaque
), tctx
, offset
, size
);
231 const MemoryRegionOps spapr_xive_tm_ops
= {
232 .read
= spapr_xive_tm_read
,
233 .write
= spapr_xive_tm_write
,
234 .endianness
= DEVICE_BIG_ENDIAN
,
236 .min_access_size
= 1,
237 .max_access_size
= 8,
240 .min_access_size
= 1,
241 .max_access_size
= 8,
245 static void spapr_xive_end_reset(XiveEND
*end
)
247 memset(end
, 0, sizeof(*end
));
249 /* switch off the escalation and notification ESBs */
250 end
->w1
= cpu_to_be32(END_W1_ESe_Q
| END_W1_ESn_Q
);
253 static void spapr_xive_reset(void *dev
)
255 SpaprXive
*xive
= SPAPR_XIVE(dev
);
259 * The XiveSource has its own reset handler, which mask off all
263 /* Mask all valid EASs in the IRQ number space. */
264 for (i
= 0; i
< xive
->nr_irqs
; i
++) {
265 XiveEAS
*eas
= &xive
->eat
[i
];
266 if (xive_eas_is_valid(eas
)) {
267 eas
->w
= cpu_to_be64(EAS_VALID
| EAS_MASKED
);
274 for (i
= 0; i
< xive
->nr_ends
; i
++) {
275 spapr_xive_end_reset(&xive
->endt
[i
]);
279 static void spapr_xive_instance_init(Object
*obj
)
281 SpaprXive
*xive
= SPAPR_XIVE(obj
);
283 object_initialize_child(obj
, "source", &xive
->source
, TYPE_XIVE_SOURCE
);
285 object_initialize_child(obj
, "end_source", &xive
->end_source
,
286 TYPE_XIVE_END_SOURCE
);
288 /* Not connected to the KVM XIVE device */
292 static void spapr_xive_realize(DeviceState
*dev
, Error
**errp
)
294 SpaprXive
*xive
= SPAPR_XIVE(dev
);
295 SpaprXiveClass
*sxc
= SPAPR_XIVE_GET_CLASS(xive
);
296 XiveSource
*xsrc
= &xive
->source
;
297 XiveENDSource
*end_xsrc
= &xive
->end_source
;
298 Error
*local_err
= NULL
;
300 /* Set by spapr_irq_init() */
301 g_assert(xive
->nr_irqs
);
302 g_assert(xive
->nr_ends
);
304 sxc
->parent_realize(dev
, &local_err
);
306 error_propagate(errp
, local_err
);
311 * Initialize the internal sources, for IPIs and virtual devices.
313 object_property_set_int(OBJECT(xsrc
), "nr-irqs", xive
->nr_irqs
,
315 object_property_set_link(OBJECT(xsrc
), "xive", OBJECT(xive
), &error_abort
);
316 if (!qdev_realize(DEVICE(xsrc
), NULL
, errp
)) {
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
, errp
)) {
331 /* Set the mapping address of the END ESB pages after the source ESBs */
332 xive
->end_base
= xive
->vc_base
+ xive_source_esb_len(xsrc
);
335 * Allocate the routing tables
337 xive
->eat
= g_new0(XiveEAS
, xive
->nr_irqs
);
338 xive
->endt
= g_new0(XiveEND
, xive
->nr_ends
);
340 xive
->nodename
= g_strdup_printf("interrupt-controller@%" PRIx64
,
341 xive
->tm_base
+ XIVE_TM_USER_PAGE
* (1 << TM_SHIFT
));
343 qemu_register_reset(spapr_xive_reset
, dev
);
345 /* TIMA initialization */
346 memory_region_init_io(&xive
->tm_mmio
, OBJECT(xive
), &spapr_xive_tm_ops
,
347 xive
, "xive.tima", 4ull << TM_SHIFT
);
350 * Map all regions. These will be enabled or disabled at reset and
351 * can also be overridden by KVM memory regions if active
353 memory_region_add_subregion(get_system_memory(), xive
->vc_base
,
355 memory_region_add_subregion(get_system_memory(), xive
->end_base
,
356 &end_xsrc
->esb_mmio
);
357 memory_region_add_subregion(get_system_memory(), 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 uint32_t spapr_xive_presenter_get_config(XivePresenter
*xptr
)
483 * Let's claim GEN1 TIMA format. If running with KVM on P10, the
484 * correct answer is deep in the hardware and not accessible to
485 * us. But it shouldn't matter as it only affects the presenter
486 * as seen by a guest OS.
488 cfg
|= XIVE_PRESENTER_GEN1_TIMA_OS
;
493 static uint8_t spapr_xive_get_block_id(XiveRouter
*xrtr
)
495 return SPAPR_XIVE_BLOCK_ID
;
498 static int spapr_xive_get_pq(XiveRouter
*xrtr
, uint8_t blk
, uint32_t idx
,
501 SpaprXive
*xive
= SPAPR_XIVE(xrtr
);
503 assert(SPAPR_XIVE_BLOCK_ID
== blk
);
505 *pq
= xive_source_esb_get(&xive
->source
, idx
);
509 static int spapr_xive_set_pq(XiveRouter
*xrtr
, uint8_t blk
, uint32_t idx
,
512 SpaprXive
*xive
= SPAPR_XIVE(xrtr
);
514 assert(SPAPR_XIVE_BLOCK_ID
== blk
);
516 *pq
= xive_source_esb_set(&xive
->source
, idx
, *pq
);
521 static const VMStateDescription vmstate_spapr_xive_end
= {
522 .name
= TYPE_SPAPR_XIVE
"/end",
524 .minimum_version_id
= 1,
525 .fields
= (const VMStateField
[]) {
526 VMSTATE_UINT32(w0
, XiveEND
),
527 VMSTATE_UINT32(w1
, XiveEND
),
528 VMSTATE_UINT32(w2
, XiveEND
),
529 VMSTATE_UINT32(w3
, XiveEND
),
530 VMSTATE_UINT32(w4
, XiveEND
),
531 VMSTATE_UINT32(w5
, XiveEND
),
532 VMSTATE_UINT32(w6
, XiveEND
),
533 VMSTATE_UINT32(w7
, XiveEND
),
534 VMSTATE_END_OF_LIST()
538 static const VMStateDescription vmstate_spapr_xive_eas
= {
539 .name
= TYPE_SPAPR_XIVE
"/eas",
541 .minimum_version_id
= 1,
542 .fields
= (const VMStateField
[]) {
543 VMSTATE_UINT64(w
, XiveEAS
),
544 VMSTATE_END_OF_LIST()
548 static int vmstate_spapr_xive_pre_save(void *opaque
)
550 SpaprXive
*xive
= SPAPR_XIVE(opaque
);
552 if (spapr_xive_in_kernel(xive
)) {
553 return kvmppc_xive_pre_save(xive
);
560 * Called by the sPAPR IRQ backend 'post_load' method at the machine
563 static int spapr_xive_post_load(SpaprInterruptController
*intc
, int version_id
)
565 SpaprXive
*xive
= SPAPR_XIVE(intc
);
567 if (spapr_xive_in_kernel(xive
)) {
568 return kvmppc_xive_post_load(xive
, version_id
);
574 static const VMStateDescription vmstate_spapr_xive
= {
575 .name
= TYPE_SPAPR_XIVE
,
577 .minimum_version_id
= 1,
578 .pre_save
= vmstate_spapr_xive_pre_save
,
579 .post_load
= NULL
, /* handled at the machine level */
580 .fields
= (const VMStateField
[]) {
581 VMSTATE_UINT32_EQUAL(nr_irqs
, SpaprXive
, NULL
),
582 VMSTATE_STRUCT_VARRAY_POINTER_UINT32(eat
, SpaprXive
, nr_irqs
,
583 vmstate_spapr_xive_eas
, XiveEAS
),
584 VMSTATE_STRUCT_VARRAY_POINTER_UINT32(endt
, SpaprXive
, nr_ends
,
585 vmstate_spapr_xive_end
, XiveEND
),
586 VMSTATE_END_OF_LIST()
590 static int spapr_xive_claim_irq(SpaprInterruptController
*intc
, int lisn
,
591 bool lsi
, Error
**errp
)
593 SpaprXive
*xive
= SPAPR_XIVE(intc
);
594 XiveSource
*xsrc
= &xive
->source
;
596 assert(lisn
< xive
->nr_irqs
);
598 trace_spapr_xive_claim_irq(lisn
, lsi
);
600 if (xive_eas_is_valid(&xive
->eat
[lisn
])) {
601 error_setg(errp
, "IRQ %d is not free", lisn
);
606 * Set default values when allocating an IRQ number
608 xive
->eat
[lisn
].w
|= cpu_to_be64(EAS_VALID
| EAS_MASKED
);
610 xive_source_irq_set_lsi(xsrc
, lisn
);
613 if (spapr_xive_in_kernel(xive
)) {
614 return kvmppc_xive_source_reset_one(xsrc
, lisn
, errp
);
620 static void spapr_xive_free_irq(SpaprInterruptController
*intc
, int lisn
)
622 SpaprXive
*xive
= SPAPR_XIVE(intc
);
623 assert(lisn
< xive
->nr_irqs
);
625 trace_spapr_xive_free_irq(lisn
);
627 xive
->eat
[lisn
].w
&= cpu_to_be64(~EAS_VALID
);
630 static Property spapr_xive_properties
[] = {
631 DEFINE_PROP_UINT32("nr-irqs", SpaprXive
, nr_irqs
, 0),
632 DEFINE_PROP_UINT32("nr-ends", SpaprXive
, nr_ends
, 0),
633 DEFINE_PROP_UINT64("vc-base", SpaprXive
, vc_base
, SPAPR_XIVE_VC_BASE
),
634 DEFINE_PROP_UINT64("tm-base", SpaprXive
, tm_base
, SPAPR_XIVE_TM_BASE
),
635 DEFINE_PROP_UINT8("hv-prio", SpaprXive
, hv_prio
, 7),
636 DEFINE_PROP_END_OF_LIST(),
639 static int spapr_xive_cpu_intc_create(SpaprInterruptController
*intc
,
640 PowerPCCPU
*cpu
, Error
**errp
)
642 SpaprXive
*xive
= SPAPR_XIVE(intc
);
644 SpaprCpuState
*spapr_cpu
= spapr_cpu_state(cpu
);
646 obj
= xive_tctx_create(OBJECT(cpu
), XIVE_PRESENTER(xive
), errp
);
651 spapr_cpu
->tctx
= XIVE_TCTX(obj
);
655 static void xive_tctx_set_os_cam(XiveTCTX
*tctx
, uint32_t os_cam
)
657 uint32_t qw1w2
= cpu_to_be32(TM_QW1W2_VO
| os_cam
);
658 memcpy(&tctx
->regs
[TM_QW1_OS
+ TM_WORD2
], &qw1w2
, 4);
661 static void spapr_xive_cpu_intc_reset(SpaprInterruptController
*intc
,
664 XiveTCTX
*tctx
= spapr_cpu_state(cpu
)->tctx
;
668 xive_tctx_reset(tctx
);
671 * When a Virtual Processor is scheduled to run on a HW thread,
672 * the hypervisor pushes its identifier in the OS CAM line.
673 * Emulate the same behavior under QEMU.
675 spapr_xive_cpu_to_nvt(cpu
, &nvt_blk
, &nvt_idx
);
677 xive_tctx_set_os_cam(tctx
, xive_nvt_cam_line(nvt_blk
, nvt_idx
));
680 static void spapr_xive_cpu_intc_destroy(SpaprInterruptController
*intc
,
683 SpaprCpuState
*spapr_cpu
= spapr_cpu_state(cpu
);
685 xive_tctx_destroy(spapr_cpu
->tctx
);
686 spapr_cpu
->tctx
= NULL
;
689 static void spapr_xive_set_irq(SpaprInterruptController
*intc
, int irq
, int val
)
691 SpaprXive
*xive
= SPAPR_XIVE(intc
);
693 trace_spapr_xive_set_irq(irq
, val
);
695 if (spapr_xive_in_kernel(xive
)) {
696 kvmppc_xive_source_set_irq(&xive
->source
, irq
, val
);
698 xive_source_set_irq(&xive
->source
, irq
, val
);
702 static void spapr_xive_print_info(SpaprInterruptController
*intc
, GString
*buf
)
704 SpaprXive
*xive
= SPAPR_XIVE(intc
);
708 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
710 xive_tctx_pic_print_info(spapr_cpu_state(cpu
)->tctx
, buf
);
712 spapr_xive_pic_print_info(xive
, buf
);
715 static void spapr_xive_dt(SpaprInterruptController
*intc
, uint32_t nr_servers
,
716 void *fdt
, uint32_t phandle
)
718 SpaprXive
*xive
= SPAPR_XIVE(intc
);
720 uint64_t timas
[2 * 2];
721 /* Interrupt number ranges for the IPIs */
722 uint32_t lisn_ranges
[] = {
723 cpu_to_be32(SPAPR_IRQ_IPI
),
724 cpu_to_be32(SPAPR_IRQ_IPI
+ nr_servers
),
727 * EQ size - the sizes of pages supported by the system 4K, 64K,
728 * 2M, 16M. We only advertise 64K for the moment.
730 uint32_t eq_sizes
[] = {
731 cpu_to_be32(16), /* 64K */
734 * QEMU/KVM only needs to define a single range to reserve the
735 * escalation priority. A priority bitmask would have been more
738 uint32_t plat_res_int_priorities
[] = {
739 cpu_to_be32(xive
->hv_prio
), /* start */
740 cpu_to_be32(0xff - xive
->hv_prio
), /* count */
743 /* Thread Interrupt Management Area : User (ring 3) and OS (ring 2) */
744 timas
[0] = cpu_to_be64(xive
->tm_base
+
745 XIVE_TM_USER_PAGE
* (1ull << TM_SHIFT
));
746 timas
[1] = cpu_to_be64(1ull << TM_SHIFT
);
747 timas
[2] = cpu_to_be64(xive
->tm_base
+
748 XIVE_TM_OS_PAGE
* (1ull << TM_SHIFT
));
749 timas
[3] = cpu_to_be64(1ull << TM_SHIFT
);
751 _FDT(node
= fdt_add_subnode(fdt
, 0, xive
->nodename
));
753 _FDT(fdt_setprop_string(fdt
, node
, "device_type", "power-ivpe"));
754 _FDT(fdt_setprop(fdt
, node
, "reg", timas
, sizeof(timas
)));
756 _FDT(fdt_setprop_string(fdt
, node
, "compatible", "ibm,power-ivpe"));
757 _FDT(fdt_setprop(fdt
, node
, "ibm,xive-eq-sizes", eq_sizes
,
759 _FDT(fdt_setprop(fdt
, node
, "ibm,xive-lisn-ranges", lisn_ranges
,
760 sizeof(lisn_ranges
)));
762 /* For Linux to link the LSIs to the interrupt controller. */
763 _FDT(fdt_setprop(fdt
, node
, "interrupt-controller", NULL
, 0));
764 _FDT(fdt_setprop_cell(fdt
, node
, "#interrupt-cells", 2));
767 _FDT(fdt_setprop_cell(fdt
, node
, "linux,phandle", phandle
));
768 _FDT(fdt_setprop_cell(fdt
, node
, "phandle", phandle
));
771 * The "ibm,plat-res-int-priorities" property defines the priority
772 * ranges reserved by the hypervisor
774 _FDT(fdt_setprop(fdt
, 0, "ibm,plat-res-int-priorities",
775 plat_res_int_priorities
, sizeof(plat_res_int_priorities
)));
778 static int spapr_xive_activate(SpaprInterruptController
*intc
,
779 uint32_t nr_servers
, Error
**errp
)
781 SpaprXive
*xive
= SPAPR_XIVE(intc
);
784 int rc
= spapr_irq_init_kvm(kvmppc_xive_connect
, intc
, nr_servers
,
791 /* Activate the XIVE MMIOs */
792 spapr_xive_mmio_set_enabled(xive
, true);
797 static void spapr_xive_deactivate(SpaprInterruptController
*intc
)
799 SpaprXive
*xive
= SPAPR_XIVE(intc
);
801 spapr_xive_mmio_set_enabled(xive
, false);
803 if (spapr_xive_in_kernel(xive
)) {
804 kvmppc_xive_disconnect(intc
);
808 static bool spapr_xive_in_kernel_xptr(const XivePresenter
*xptr
)
810 return spapr_xive_in_kernel(SPAPR_XIVE(xptr
));
813 static void spapr_xive_class_init(ObjectClass
*klass
, void *data
)
815 DeviceClass
*dc
= DEVICE_CLASS(klass
);
816 XiveRouterClass
*xrc
= XIVE_ROUTER_CLASS(klass
);
817 SpaprInterruptControllerClass
*sicc
= SPAPR_INTC_CLASS(klass
);
818 XivePresenterClass
*xpc
= XIVE_PRESENTER_CLASS(klass
);
819 SpaprXiveClass
*sxc
= SPAPR_XIVE_CLASS(klass
);
821 dc
->desc
= "sPAPR XIVE Interrupt Controller";
822 device_class_set_props(dc
, spapr_xive_properties
);
823 device_class_set_parent_realize(dc
, spapr_xive_realize
,
824 &sxc
->parent_realize
);
825 dc
->vmsd
= &vmstate_spapr_xive
;
827 xrc
->get_eas
= spapr_xive_get_eas
;
828 xrc
->get_pq
= spapr_xive_get_pq
;
829 xrc
->set_pq
= spapr_xive_set_pq
;
830 xrc
->get_end
= spapr_xive_get_end
;
831 xrc
->write_end
= spapr_xive_write_end
;
832 xrc
->get_nvt
= spapr_xive_get_nvt
;
833 xrc
->write_nvt
= spapr_xive_write_nvt
;
834 xrc
->get_block_id
= spapr_xive_get_block_id
;
836 sicc
->activate
= spapr_xive_activate
;
837 sicc
->deactivate
= spapr_xive_deactivate
;
838 sicc
->cpu_intc_create
= spapr_xive_cpu_intc_create
;
839 sicc
->cpu_intc_reset
= spapr_xive_cpu_intc_reset
;
840 sicc
->cpu_intc_destroy
= spapr_xive_cpu_intc_destroy
;
841 sicc
->claim_irq
= spapr_xive_claim_irq
;
842 sicc
->free_irq
= spapr_xive_free_irq
;
843 sicc
->set_irq
= spapr_xive_set_irq
;
844 sicc
->print_info
= spapr_xive_print_info
;
845 sicc
->dt
= spapr_xive_dt
;
846 sicc
->post_load
= spapr_xive_post_load
;
848 xpc
->match_nvt
= spapr_xive_match_nvt
;
849 xpc
->get_config
= spapr_xive_presenter_get_config
;
850 xpc
->in_kernel
= spapr_xive_in_kernel_xptr
;
853 static const TypeInfo spapr_xive_info
= {
854 .name
= TYPE_SPAPR_XIVE
,
855 .parent
= TYPE_XIVE_ROUTER
,
856 .instance_init
= spapr_xive_instance_init
,
857 .instance_size
= sizeof(SpaprXive
),
858 .class_init
= spapr_xive_class_init
,
859 .class_size
= sizeof(SpaprXiveClass
),
860 .interfaces
= (InterfaceInfo
[]) {
866 static void spapr_xive_register_types(void)
868 type_register_static(&spapr_xive_info
);
871 type_init(spapr_xive_register_types
)
876 * The terminology used by the XIVE hcalls is the following :
879 * EQ Event Queue assigned by OS to receive event data
880 * ESB page for source interrupt management
881 * LISN Logical Interrupt Source Number identifying a source in the
883 * EISN Effective Interrupt Source Number used by guest OS to
884 * identify source in the guest
886 * The EAS, END, NVT structures are not exposed.
890 * On POWER9, the KVM XIVE device uses priority 7 for the escalation
891 * interrupts. So we only allow the guest to use priorities [0..6].
893 static bool spapr_xive_priority_is_reserved(SpaprXive
*xive
, uint8_t priority
)
895 return priority
>= xive
->hv_prio
;
899 * The H_INT_GET_SOURCE_INFO hcall() is used to obtain the logical
900 * real address of the MMIO page through which the Event State Buffer
901 * entry associated with the value of the "lisn" parameter is managed.
907 * - R5: "lisn" is per "interrupts", "interrupt-map", or
908 * "ibm,xive-lisn-ranges" properties, or as returned by the
909 * ibm,query-interrupt-source-number RTAS call, or as returned
910 * by the H_ALLOCATE_VAS_WINDOW hcall
914 * Bits 0-59: Reserved
915 * Bit 60: H_INT_ESB must be used for Event State Buffer
917 * Bit 61: 1 == LSI 0 == MSI
918 * Bit 62: the full function page supports trigger
919 * Bit 63: Store EOI Supported
920 * - R5: Logical Real address of full function Event State Buffer
921 * management page, -1 if H_INT_ESB hcall flag is set to 1.
922 * - R6: Logical Real Address of trigger only Event State Buffer
923 * management page or -1.
924 * - R7: Power of 2 page size for the ESB management pages returned in
928 #define SPAPR_XIVE_SRC_H_INT_ESB PPC_BIT(60) /* ESB manage with H_INT_ESB */
929 #define SPAPR_XIVE_SRC_LSI PPC_BIT(61) /* Virtual LSI type */
930 #define SPAPR_XIVE_SRC_TRIGGER PPC_BIT(62) /* Trigger and management
932 #define SPAPR_XIVE_SRC_STORE_EOI PPC_BIT(63) /* Store EOI support */
934 static target_ulong
h_int_get_source_info(PowerPCCPU
*cpu
,
935 SpaprMachineState
*spapr
,
939 SpaprXive
*xive
= spapr
->xive
;
940 XiveSource
*xsrc
= &xive
->source
;
941 target_ulong flags
= args
[0];
942 target_ulong lisn
= args
[1];
944 trace_spapr_xive_get_source_info(flags
, lisn
);
946 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
954 if (lisn
>= xive
->nr_irqs
) {
955 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
960 if (!xive_eas_is_valid(&xive
->eat
[lisn
])) {
961 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
967 * All sources are emulated under the main XIVE object and share
968 * the same characteristics.
971 if (!xive_source_esb_has_2page(xsrc
)) {
972 args
[0] |= SPAPR_XIVE_SRC_TRIGGER
;
974 if (xsrc
->esb_flags
& XIVE_SRC_STORE_EOI
) {
975 args
[0] |= SPAPR_XIVE_SRC_STORE_EOI
;
979 * Force the use of the H_INT_ESB hcall in case of an LSI
980 * interrupt. This is necessary under KVM to re-trigger the
981 * interrupt if the level is still asserted
983 if (xive_source_irq_is_lsi(xsrc
, lisn
)) {
984 args
[0] |= SPAPR_XIVE_SRC_H_INT_ESB
| SPAPR_XIVE_SRC_LSI
;
987 if (!(args
[0] & SPAPR_XIVE_SRC_H_INT_ESB
)) {
988 args
[1] = xive
->vc_base
+ xive_source_esb_mgmt(xsrc
, lisn
);
993 if (xive_source_esb_has_2page(xsrc
) &&
994 !(args
[0] & SPAPR_XIVE_SRC_H_INT_ESB
)) {
995 args
[2] = xive
->vc_base
+ xive_source_esb_page(xsrc
, lisn
);
1000 if (xive_source_esb_has_2page(xsrc
)) {
1001 args
[3] = xsrc
->esb_shift
- 1;
1003 args
[3] = xsrc
->esb_shift
;
1010 * The H_INT_SET_SOURCE_CONFIG hcall() is used to assign a Logical
1011 * Interrupt Source to a target. The Logical Interrupt Source is
1012 * designated with the "lisn" parameter and the target is designated
1013 * with the "target" and "priority" parameters. Upon return from the
1014 * hcall(), no additional interrupts will be directed to the old EQ.
1019 * Bits 0-61: Reserved
1020 * Bit 62: set the "eisn" in the EAS
1021 * Bit 63: masks the interrupt source in the hardware interrupt
1022 * control structure. An interrupt masked by this mechanism will
1023 * be dropped, but it's source state bits will still be
1024 * set. There is no race-free way of unmasking and restoring the
1025 * source. Thus this should only be used in interrupts that are
1026 * also masked at the source, and only in cases where the
1027 * interrupt is not meant to be used for a large amount of time
1028 * because no valid target exists for it for example
1029 * - R5: "lisn" is per "interrupts", "interrupt-map", or
1030 * "ibm,xive-lisn-ranges" properties, or as returned by the
1031 * ibm,query-interrupt-source-number RTAS call, or as returned by
1032 * the H_ALLOCATE_VAS_WINDOW hcall
1033 * - R6: "target" is per "ibm,ppc-interrupt-server#s" or
1034 * "ibm,ppc-interrupt-gserver#s"
1035 * - R7: "priority" is a valid priority not in
1036 * "ibm,plat-res-int-priorities"
1037 * - R8: "eisn" is the guest EISN associated with the "lisn"
1043 #define SPAPR_XIVE_SRC_SET_EISN PPC_BIT(62)
1044 #define SPAPR_XIVE_SRC_MASK PPC_BIT(63)
1046 static target_ulong
h_int_set_source_config(PowerPCCPU
*cpu
,
1047 SpaprMachineState
*spapr
,
1048 target_ulong opcode
,
1051 SpaprXive
*xive
= spapr
->xive
;
1052 XiveEAS eas
, new_eas
;
1053 target_ulong flags
= args
[0];
1054 target_ulong lisn
= args
[1];
1055 target_ulong target
= args
[2];
1056 target_ulong priority
= args
[3];
1057 target_ulong eisn
= args
[4];
1061 trace_spapr_xive_set_source_config(flags
, lisn
, target
, priority
, eisn
);
1063 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1067 if (flags
& ~(SPAPR_XIVE_SRC_SET_EISN
| SPAPR_XIVE_SRC_MASK
)) {
1071 if (lisn
>= xive
->nr_irqs
) {
1072 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
1077 eas
= xive
->eat
[lisn
];
1078 if (!xive_eas_is_valid(&eas
)) {
1079 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
1084 /* priority 0xff is used to reset the EAS */
1085 if (priority
== 0xff) {
1086 new_eas
.w
= cpu_to_be64(EAS_VALID
| EAS_MASKED
);
1090 if (flags
& SPAPR_XIVE_SRC_MASK
) {
1091 new_eas
.w
= eas
.w
| cpu_to_be64(EAS_MASKED
);
1093 new_eas
.w
= eas
.w
& cpu_to_be64(~EAS_MASKED
);
1096 if (spapr_xive_priority_is_reserved(xive
, priority
)) {
1097 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: priority " TARGET_FMT_ld
1098 " is reserved\n", priority
);
1103 * Validate that "target" is part of the list of threads allocated
1104 * to the partition. For that, find the END corresponding to the
1107 if (spapr_xive_target_to_end(target
, priority
, &end_blk
, &end_idx
)) {
1111 new_eas
.w
= xive_set_field64(EAS_END_BLOCK
, new_eas
.w
, end_blk
);
1112 new_eas
.w
= xive_set_field64(EAS_END_INDEX
, new_eas
.w
, end_idx
);
1114 if (flags
& SPAPR_XIVE_SRC_SET_EISN
) {
1115 new_eas
.w
= xive_set_field64(EAS_END_DATA
, new_eas
.w
, eisn
);
1118 if (spapr_xive_in_kernel(xive
)) {
1119 Error
*local_err
= NULL
;
1121 kvmppc_xive_set_source_config(xive
, lisn
, &new_eas
, &local_err
);
1123 error_report_err(local_err
);
1129 xive
->eat
[lisn
] = new_eas
;
1134 * The H_INT_GET_SOURCE_CONFIG hcall() is used to determine to which
1135 * target/priority pair is assigned to the specified Logical Interrupt
1141 * Bits 0-63 Reserved
1142 * - R5: "lisn" is per "interrupts", "interrupt-map", or
1143 * "ibm,xive-lisn-ranges" properties, or as returned by the
1144 * ibm,query-interrupt-source-number RTAS call, or as
1145 * returned by the H_ALLOCATE_VAS_WINDOW hcall
1148 * - R4: Target to which the specified Logical Interrupt Source is
1150 * - R5: Priority to which the specified Logical Interrupt Source is
1152 * - R6: EISN for the specified Logical Interrupt Source (this will be
1153 * equivalent to the LISN if not changed by H_INT_SET_SOURCE_CONFIG)
1155 static target_ulong
h_int_get_source_config(PowerPCCPU
*cpu
,
1156 SpaprMachineState
*spapr
,
1157 target_ulong opcode
,
1160 SpaprXive
*xive
= spapr
->xive
;
1161 target_ulong flags
= args
[0];
1162 target_ulong lisn
= args
[1];
1166 uint32_t end_idx
, nvt_idx
;
1168 trace_spapr_xive_get_source_config(flags
, lisn
);
1170 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1178 if (lisn
>= xive
->nr_irqs
) {
1179 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
1184 eas
= xive
->eat
[lisn
];
1185 if (!xive_eas_is_valid(&eas
)) {
1186 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
1191 /* EAS_END_BLOCK is unused on sPAPR */
1192 end_idx
= xive_get_field64(EAS_END_INDEX
, eas
.w
);
1194 assert(end_idx
< xive
->nr_ends
);
1195 end
= &xive
->endt
[end_idx
];
1197 nvt_blk
= xive_get_field32(END_W6_NVT_BLOCK
, end
->w6
);
1198 nvt_idx
= xive_get_field32(END_W6_NVT_INDEX
, end
->w6
);
1199 args
[0] = spapr_xive_nvt_to_target(nvt_blk
, nvt_idx
);
1201 if (xive_eas_is_masked(&eas
)) {
1204 args
[1] = xive_get_field32(END_W7_F0_PRIORITY
, end
->w7
);
1207 args
[2] = xive_get_field64(EAS_END_DATA
, eas
.w
);
1213 * The H_INT_GET_QUEUE_INFO hcall() is used to get the logical real
1214 * address of the notification management page associated with the
1215 * specified target and priority.
1220 * Bits 0-63 Reserved
1221 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
1222 * "ibm,ppc-interrupt-gserver#s"
1223 * - R6: "priority" is a valid priority not in
1224 * "ibm,plat-res-int-priorities"
1227 * - R4: Logical real address of notification page
1228 * - R5: Power of 2 page size of the notification page
1230 static target_ulong
h_int_get_queue_info(PowerPCCPU
*cpu
,
1231 SpaprMachineState
*spapr
,
1232 target_ulong opcode
,
1235 SpaprXive
*xive
= spapr
->xive
;
1236 XiveENDSource
*end_xsrc
= &xive
->end_source
;
1237 target_ulong flags
= args
[0];
1238 target_ulong target
= args
[1];
1239 target_ulong priority
= args
[2];
1244 trace_spapr_xive_get_queue_info(flags
, target
, priority
);
1246 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1255 * H_STATE should be returned if a H_INT_RESET is in progress.
1256 * This is not needed when running the emulation under QEMU
1259 if (spapr_xive_priority_is_reserved(xive
, priority
)) {
1260 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: priority " TARGET_FMT_ld
1261 " is reserved\n", priority
);
1266 * Validate that "target" is part of the list of threads allocated
1267 * to the partition. For that, find the END corresponding to the
1270 if (spapr_xive_target_to_end(target
, priority
, &end_blk
, &end_idx
)) {
1274 assert(end_idx
< xive
->nr_ends
);
1275 end
= &xive
->endt
[end_idx
];
1277 args
[0] = xive
->end_base
+ (1ull << (end_xsrc
->esb_shift
+ 1)) * end_idx
;
1278 if (xive_end_is_enqueue(end
)) {
1279 args
[1] = xive_get_field32(END_W0_QSIZE
, end
->w0
) + 12;
1288 * The H_INT_SET_QUEUE_CONFIG hcall() is used to set or reset a EQ for
1289 * a given "target" and "priority". It is also used to set the
1290 * notification config associated with the EQ. An EQ size of 0 is
1291 * used to reset the EQ config for a given target and priority. If
1292 * resetting the EQ config, the END associated with the given "target"
1293 * and "priority" will be changed to disable queueing.
1295 * Upon return from the hcall(), no additional interrupts will be
1296 * directed to the old EQ (if one was set). The old EQ (if one was
1297 * set) should be investigated for interrupts that occurred prior to
1298 * or during the hcall().
1303 * Bits 0-62: Reserved
1304 * Bit 63: Unconditional Notify (n) per the XIVE spec
1305 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
1306 * "ibm,ppc-interrupt-gserver#s"
1307 * - R6: "priority" is a valid priority not in
1308 * "ibm,plat-res-int-priorities"
1309 * - R7: "eventQueue": The logical real address of the start of the EQ
1310 * - R8: "eventQueueSize": The power of 2 EQ size per "ibm,xive-eq-sizes"
1316 #define SPAPR_XIVE_END_ALWAYS_NOTIFY PPC_BIT(63)
1318 static target_ulong
h_int_set_queue_config(PowerPCCPU
*cpu
,
1319 SpaprMachineState
*spapr
,
1320 target_ulong opcode
,
1323 SpaprXive
*xive
= spapr
->xive
;
1324 target_ulong flags
= args
[0];
1325 target_ulong target
= args
[1];
1326 target_ulong priority
= args
[2];
1327 target_ulong qpage
= args
[3];
1328 target_ulong qsize
= args
[4];
1330 uint8_t end_blk
, nvt_blk
;
1331 uint32_t end_idx
, nvt_idx
;
1333 trace_spapr_xive_set_queue_config(flags
, target
, priority
, qpage
, qsize
);
1335 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1339 if (flags
& ~SPAPR_XIVE_END_ALWAYS_NOTIFY
) {
1344 * H_STATE should be returned if a H_INT_RESET is in progress.
1345 * This is not needed when running the emulation under QEMU
1348 if (spapr_xive_priority_is_reserved(xive
, priority
)) {
1349 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: priority " TARGET_FMT_ld
1350 " is reserved\n", priority
);
1355 * Validate that "target" is part of the list of threads allocated
1356 * to the partition. For that, find the END corresponding to the
1360 if (spapr_xive_target_to_end(target
, priority
, &end_blk
, &end_idx
)) {
1364 assert(end_idx
< xive
->nr_ends
);
1365 memcpy(&end
, &xive
->endt
[end_idx
], sizeof(XiveEND
));
1372 if (!QEMU_IS_ALIGNED(qpage
, 1ul << qsize
)) {
1373 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: EQ @0x%" HWADDR_PRIx
1374 " is not naturally aligned with %" HWADDR_PRIx
"\n",
1375 qpage
, (hwaddr
)1 << qsize
);
1378 end
.w2
= cpu_to_be32((qpage
>> 32) & 0x0fffffff);
1379 end
.w3
= cpu_to_be32(qpage
& 0xffffffff);
1380 end
.w0
|= cpu_to_be32(END_W0_ENQUEUE
);
1381 end
.w0
= xive_set_field32(END_W0_QSIZE
, end
.w0
, qsize
- 12);
1384 /* reset queue and disable queueing */
1385 spapr_xive_end_reset(&end
);
1389 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: invalid EQ size %"PRIx64
"\n",
1395 hwaddr plen
= 1 << qsize
;
1399 * Validate the guest EQ. We should also check that the queue
1400 * has been zeroed by the OS.
1402 eq
= address_space_map(CPU(cpu
)->as
, qpage
, &plen
, true,
1403 MEMTXATTRS_UNSPECIFIED
);
1404 if (plen
!= 1 << qsize
) {
1405 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: failed to map EQ @0x%"
1406 HWADDR_PRIx
"\n", qpage
);
1409 address_space_unmap(CPU(cpu
)->as
, eq
, plen
, true, plen
);
1412 /* "target" should have been validated above */
1413 if (spapr_xive_target_to_nvt(target
, &nvt_blk
, &nvt_idx
)) {
1414 g_assert_not_reached();
1418 * Ensure the priority and target are correctly set (they will not
1419 * be right after allocation)
1421 end
.w6
= xive_set_field32(END_W6_NVT_BLOCK
, 0ul, nvt_blk
) |
1422 xive_set_field32(END_W6_NVT_INDEX
, 0ul, nvt_idx
);
1423 end
.w7
= xive_set_field32(END_W7_F0_PRIORITY
, 0ul, priority
);
1425 if (flags
& SPAPR_XIVE_END_ALWAYS_NOTIFY
) {
1426 end
.w0
|= cpu_to_be32(END_W0_UCOND_NOTIFY
);
1428 end
.w0
&= cpu_to_be32((uint32_t)~END_W0_UCOND_NOTIFY
);
1432 * The generation bit for the END starts at 1 and The END page
1433 * offset counter starts at 0.
1435 end
.w1
= cpu_to_be32(END_W1_GENERATION
) |
1436 xive_set_field32(END_W1_PAGE_OFF
, 0ul, 0ul);
1437 end
.w0
|= cpu_to_be32(END_W0_VALID
);
1440 * TODO: issue syncs required to ensure all in-flight interrupts
1441 * are complete on the old END
1445 if (spapr_xive_in_kernel(xive
)) {
1446 Error
*local_err
= NULL
;
1448 kvmppc_xive_set_queue_config(xive
, end_blk
, end_idx
, &end
, &local_err
);
1450 error_report_err(local_err
);
1456 memcpy(&xive
->endt
[end_idx
], &end
, sizeof(XiveEND
));
1461 * The H_INT_GET_QUEUE_CONFIG hcall() is used to get a EQ for a given
1462 * target and priority.
1467 * Bits 0-62: Reserved
1468 * Bit 63: Debug: Return debug data
1469 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
1470 * "ibm,ppc-interrupt-gserver#s"
1471 * - R6: "priority" is a valid priority not in
1472 * "ibm,plat-res-int-priorities"
1476 * Bits 0-61: Reserved
1477 * Bit 62: The value of Event Queue Generation Number (g) per
1478 * the XIVE spec if "Debug" = 1
1479 * Bit 63: The value of Unconditional Notify (n) per the XIVE spec
1480 * - R5: The logical real address of the start of the EQ
1481 * - R6: The power of 2 EQ size per "ibm,xive-eq-sizes"
1482 * - R7: The value of Event Queue Offset Counter per XIVE spec
1483 * if "Debug" = 1, else 0
1487 #define SPAPR_XIVE_END_DEBUG PPC_BIT(63)
1489 static target_ulong
h_int_get_queue_config(PowerPCCPU
*cpu
,
1490 SpaprMachineState
*spapr
,
1491 target_ulong opcode
,
1494 SpaprXive
*xive
= spapr
->xive
;
1495 target_ulong flags
= args
[0];
1496 target_ulong target
= args
[1];
1497 target_ulong priority
= args
[2];
1502 trace_spapr_xive_get_queue_config(flags
, target
, priority
);
1504 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1508 if (flags
& ~SPAPR_XIVE_END_DEBUG
) {
1513 * H_STATE should be returned if a H_INT_RESET is in progress.
1514 * This is not needed when running the emulation under QEMU
1517 if (spapr_xive_priority_is_reserved(xive
, priority
)) {
1518 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: priority " TARGET_FMT_ld
1519 " is reserved\n", priority
);
1524 * Validate that "target" is part of the list of threads allocated
1525 * to the partition. For that, find the END corresponding to the
1528 if (spapr_xive_target_to_end(target
, priority
, &end_blk
, &end_idx
)) {
1532 assert(end_idx
< xive
->nr_ends
);
1533 end
= &xive
->endt
[end_idx
];
1536 if (xive_end_is_notify(end
)) {
1537 args
[0] |= SPAPR_XIVE_END_ALWAYS_NOTIFY
;
1540 if (xive_end_is_enqueue(end
)) {
1541 args
[1] = xive_end_qaddr(end
);
1542 args
[2] = xive_get_field32(END_W0_QSIZE
, end
->w0
) + 12;
1548 if (spapr_xive_in_kernel(xive
)) {
1549 Error
*local_err
= NULL
;
1551 kvmppc_xive_get_queue_config(xive
, end_blk
, end_idx
, end
, &local_err
);
1553 error_report_err(local_err
);
1558 /* TODO: do we need any locking on the END ? */
1559 if (flags
& SPAPR_XIVE_END_DEBUG
) {
1560 /* Load the event queue generation number into the return flags */
1561 args
[0] |= (uint64_t)xive_get_field32(END_W1_GENERATION
, end
->w1
) << 62;
1563 /* Load R7 with the event queue offset counter */
1564 args
[3] = xive_get_field32(END_W1_PAGE_OFF
, end
->w1
);
1573 * The H_INT_SET_OS_REPORTING_LINE hcall() is used to set the
1574 * reporting cache line pair for the calling thread. The reporting
1575 * cache lines will contain the OS interrupt context when the OS
1576 * issues a CI store byte to @TIMA+0xC10 to acknowledge the OS
1577 * interrupt. The reporting cache lines can be reset by inputting -1
1578 * in "reportingLine". Issuing the CI store byte without reporting
1579 * cache lines registered will result in the data not being accessible
1585 * Bits 0-63: Reserved
1586 * - R5: "reportingLine": The logical real address of the reporting cache
1592 static target_ulong
h_int_set_os_reporting_line(PowerPCCPU
*cpu
,
1593 SpaprMachineState
*spapr
,
1594 target_ulong opcode
,
1597 target_ulong flags
= args
[0];
1599 trace_spapr_xive_set_os_reporting_line(flags
);
1601 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1606 * H_STATE should be returned if a H_INT_RESET is in progress.
1607 * This is not needed when running the emulation under QEMU
1610 /* TODO: H_INT_SET_OS_REPORTING_LINE */
1615 * The H_INT_GET_OS_REPORTING_LINE hcall() is used to get the logical
1616 * real address of the reporting cache line pair set for the input
1617 * "target". If no reporting cache line pair has been set, -1 is
1623 * Bits 0-63: Reserved
1624 * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
1625 * "ibm,ppc-interrupt-gserver#s"
1626 * - R6: "reportingLine": The logical real address of the reporting
1630 * - R4: The logical real address of the reporting line if set, else -1
1632 static target_ulong
h_int_get_os_reporting_line(PowerPCCPU
*cpu
,
1633 SpaprMachineState
*spapr
,
1634 target_ulong opcode
,
1637 target_ulong flags
= args
[0];
1639 trace_spapr_xive_get_os_reporting_line(flags
);
1641 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1646 * H_STATE should be returned if a H_INT_RESET is in progress.
1647 * This is not needed when running the emulation under QEMU
1650 /* TODO: H_INT_GET_OS_REPORTING_LINE */
1655 * The H_INT_ESB hcall() is used to issue a load or store to the ESB
1656 * page for the input "lisn". This hcall is only supported for LISNs
1657 * that have the ESB hcall flag set to 1 when returned from hcall()
1658 * H_INT_GET_SOURCE_INFO.
1663 * Bits 0-62: Reserved
1664 * bit 63: Store: Store=1, store operation, else load operation
1665 * - R5: "lisn" is per "interrupts", "interrupt-map", or
1666 * "ibm,xive-lisn-ranges" properties, or as returned by the
1667 * ibm,query-interrupt-source-number RTAS call, or as
1668 * returned by the H_ALLOCATE_VAS_WINDOW hcall
1669 * - R6: "esbOffset" is the offset into the ESB page for the load or
1671 * - R7: "storeData" is the data to write for a store operation
1674 * - R4: The value of the load if load operation, else -1
1677 #define SPAPR_XIVE_ESB_STORE PPC_BIT(63)
1679 static target_ulong
h_int_esb(PowerPCCPU
*cpu
,
1680 SpaprMachineState
*spapr
,
1681 target_ulong opcode
,
1684 SpaprXive
*xive
= spapr
->xive
;
1686 target_ulong flags
= args
[0];
1687 target_ulong lisn
= args
[1];
1688 target_ulong offset
= args
[2];
1689 target_ulong data
= args
[3];
1691 XiveSource
*xsrc
= &xive
->source
;
1693 trace_spapr_xive_esb(flags
, lisn
, offset
, data
);
1695 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1699 if (flags
& ~SPAPR_XIVE_ESB_STORE
) {
1703 if (lisn
>= xive
->nr_irqs
) {
1704 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
1709 eas
= xive
->eat
[lisn
];
1710 if (!xive_eas_is_valid(&eas
)) {
1711 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
1716 if (offset
> (1ull << xsrc
->esb_shift
)) {
1720 if (spapr_xive_in_kernel(xive
)) {
1721 args
[0] = kvmppc_xive_esb_rw(xsrc
, lisn
, offset
, data
,
1722 flags
& SPAPR_XIVE_ESB_STORE
);
1724 mmio_addr
= xive
->vc_base
+ xive_source_esb_mgmt(xsrc
, lisn
) + offset
;
1726 if (dma_memory_rw(&address_space_memory
, mmio_addr
, &data
, 8,
1727 (flags
& SPAPR_XIVE_ESB_STORE
),
1728 MEMTXATTRS_UNSPECIFIED
)) {
1729 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: failed to access ESB @0x%"
1730 HWADDR_PRIx
"\n", mmio_addr
);
1733 args
[0] = (flags
& SPAPR_XIVE_ESB_STORE
) ? -1 : data
;
1739 * The H_INT_SYNC hcall() is used to issue hardware syncs that will
1740 * ensure any in flight events for the input lisn are in the event
1746 * Bits 0-63: Reserved
1747 * - R5: "lisn" is per "interrupts", "interrupt-map", or
1748 * "ibm,xive-lisn-ranges" properties, or as returned by the
1749 * ibm,query-interrupt-source-number RTAS call, or as
1750 * returned by the H_ALLOCATE_VAS_WINDOW hcall
1755 static target_ulong
h_int_sync(PowerPCCPU
*cpu
,
1756 SpaprMachineState
*spapr
,
1757 target_ulong opcode
,
1760 SpaprXive
*xive
= spapr
->xive
;
1762 target_ulong flags
= args
[0];
1763 target_ulong lisn
= args
[1];
1765 trace_spapr_xive_sync(flags
, lisn
);
1767 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1775 if (lisn
>= xive
->nr_irqs
) {
1776 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Unknown LISN " TARGET_FMT_lx
"\n",
1781 eas
= xive
->eat
[lisn
];
1782 if (!xive_eas_is_valid(&eas
)) {
1783 qemu_log_mask(LOG_GUEST_ERROR
, "XIVE: Invalid LISN " TARGET_FMT_lx
"\n",
1789 * H_STATE should be returned if a H_INT_RESET is in progress.
1790 * This is not needed when running the emulation under QEMU
1794 * This is not real hardware. Nothing to be done unless when
1798 if (spapr_xive_in_kernel(xive
)) {
1799 Error
*local_err
= NULL
;
1801 kvmppc_xive_sync_source(xive
, lisn
, &local_err
);
1803 error_report_err(local_err
);
1811 * The H_INT_RESET hcall() is used to reset all of the partition's
1812 * interrupt exploitation structures to their initial state. This
1813 * means losing all previously set interrupt state set via
1814 * H_INT_SET_SOURCE_CONFIG and H_INT_SET_QUEUE_CONFIG.
1819 * Bits 0-63: Reserved
1824 static target_ulong
h_int_reset(PowerPCCPU
*cpu
,
1825 SpaprMachineState
*spapr
,
1826 target_ulong opcode
,
1829 SpaprXive
*xive
= spapr
->xive
;
1830 target_ulong flags
= args
[0];
1832 trace_spapr_xive_reset(flags
);
1834 if (!spapr_ovec_test(spapr
->ov5_cas
, OV5_XIVE_EXPLOIT
)) {
1842 device_cold_reset(DEVICE(xive
));
1844 if (spapr_xive_in_kernel(xive
)) {
1845 Error
*local_err
= NULL
;
1847 kvmppc_xive_reset(xive
, &local_err
);
1849 error_report_err(local_err
);
1856 void spapr_xive_hcall_init(SpaprMachineState
*spapr
)
1858 spapr_register_hypercall(H_INT_GET_SOURCE_INFO
, h_int_get_source_info
);
1859 spapr_register_hypercall(H_INT_SET_SOURCE_CONFIG
, h_int_set_source_config
);
1860 spapr_register_hypercall(H_INT_GET_SOURCE_CONFIG
, h_int_get_source_config
);
1861 spapr_register_hypercall(H_INT_GET_QUEUE_INFO
, h_int_get_queue_info
);
1862 spapr_register_hypercall(H_INT_SET_QUEUE_CONFIG
, h_int_set_queue_config
);
1863 spapr_register_hypercall(H_INT_GET_QUEUE_CONFIG
, h_int_get_queue_config
);
1864 spapr_register_hypercall(H_INT_SET_OS_REPORTING_LINE
,
1865 h_int_set_os_reporting_line
);
1866 spapr_register_hypercall(H_INT_GET_OS_REPORTING_LINE
,
1867 h_int_get_os_reporting_line
);
1868 spapr_register_hypercall(H_INT_ESB
, h_int_esb
);
1869 spapr_register_hypercall(H_INT_SYNC
, h_int_sync
);
1870 spapr_register_hypercall(H_INT_RESET
, h_int_reset
);