2 * QEMU PowerPC sPAPR XIVE interrupt controller model
4 * Copyright (c) 2017-2019, 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/error-report.h"
13 #include "qapi/error.h"
14 #include "target/ppc/cpu.h"
15 #include "sysemu/cpus.h"
16 #include "sysemu/kvm.h"
17 #include "sysemu/runstate.h"
18 #include "hw/ppc/spapr.h"
19 #include "hw/ppc/spapr_cpu_core.h"
20 #include "hw/ppc/spapr_xive.h"
21 #include "hw/ppc/xive.h"
24 #include <sys/ioctl.h>
27 * Helpers for CPU hotplug
29 * TODO: make a common KVMEnabledCPU layer for XICS and XIVE
31 typedef struct KVMEnabledCPU
{
32 unsigned long vcpu_id
;
33 QLIST_ENTRY(KVMEnabledCPU
) node
;
36 static QLIST_HEAD(, KVMEnabledCPU
)
37 kvm_enabled_cpus
= QLIST_HEAD_INITIALIZER(&kvm_enabled_cpus
);
39 static bool kvm_cpu_is_enabled(CPUState
*cs
)
41 KVMEnabledCPU
*enabled_cpu
;
42 unsigned long vcpu_id
= kvm_arch_vcpu_id(cs
);
44 QLIST_FOREACH(enabled_cpu
, &kvm_enabled_cpus
, node
) {
45 if (enabled_cpu
->vcpu_id
== vcpu_id
) {
52 static void kvm_cpu_enable(CPUState
*cs
)
54 KVMEnabledCPU
*enabled_cpu
;
55 unsigned long vcpu_id
= kvm_arch_vcpu_id(cs
);
57 enabled_cpu
= g_malloc(sizeof(*enabled_cpu
));
58 enabled_cpu
->vcpu_id
= vcpu_id
;
59 QLIST_INSERT_HEAD(&kvm_enabled_cpus
, enabled_cpu
, node
);
62 static void kvm_cpu_disable_all(void)
64 KVMEnabledCPU
*enabled_cpu
, *next
;
66 QLIST_FOREACH_SAFE(enabled_cpu
, &kvm_enabled_cpus
, node
, next
) {
67 QLIST_REMOVE(enabled_cpu
, node
);
73 * XIVE Thread Interrupt Management context (KVM)
76 int kvmppc_xive_cpu_set_state(XiveTCTX
*tctx
, Error
**errp
)
78 SpaprXive
*xive
= SPAPR_XIVE(tctx
->xptr
);
82 assert(xive
->fd
!= -1);
84 /* word0 and word1 of the OS ring. */
85 state
[0] = *((uint64_t *) &tctx
->regs
[TM_QW1_OS
]);
87 ret
= kvm_set_one_reg(tctx
->cs
, KVM_REG_PPC_VP_STATE
, state
);
89 error_setg_errno(errp
, -ret
,
90 "XIVE: could not restore KVM state of CPU %ld",
91 kvm_arch_vcpu_id(tctx
->cs
));
98 int kvmppc_xive_cpu_get_state(XiveTCTX
*tctx
, Error
**errp
)
100 SpaprXive
*xive
= SPAPR_XIVE(tctx
->xptr
);
101 uint64_t state
[2] = { 0 };
104 assert(xive
->fd
!= -1);
106 ret
= kvm_get_one_reg(tctx
->cs
, KVM_REG_PPC_VP_STATE
, state
);
108 error_setg_errno(errp
, -ret
,
109 "XIVE: could not capture KVM state of CPU %ld",
110 kvm_arch_vcpu_id(tctx
->cs
));
114 /* word0 and word1 of the OS ring. */
115 *((uint64_t *) &tctx
->regs
[TM_QW1_OS
]) = state
[0];
125 static void kvmppc_xive_cpu_do_synchronize_state(CPUState
*cpu
,
128 XiveCpuGetState
*s
= arg
.host_ptr
;
130 kvmppc_xive_cpu_get_state(s
->tctx
, &s
->err
);
133 void kvmppc_xive_cpu_synchronize_state(XiveTCTX
*tctx
, Error
**errp
)
135 XiveCpuGetState s
= {
141 * Kick the vCPU to make sure they are available for the KVM ioctl.
143 run_on_cpu(tctx
->cs
, kvmppc_xive_cpu_do_synchronize_state
,
144 RUN_ON_CPU_HOST_PTR(&s
));
147 error_propagate(errp
, s
.err
);
152 int kvmppc_xive_cpu_connect(XiveTCTX
*tctx
, Error
**errp
)
155 SpaprXive
*xive
= SPAPR_XIVE(tctx
->xptr
);
156 unsigned long vcpu_id
;
159 assert(xive
->fd
!= -1);
161 /* Check if CPU was hot unplugged and replugged. */
162 if (kvm_cpu_is_enabled(tctx
->cs
)) {
166 vcpu_id
= kvm_arch_vcpu_id(tctx
->cs
);
168 ret
= kvm_vcpu_enable_cap(tctx
->cs
, KVM_CAP_PPC_IRQ_XIVE
, 0, xive
->fd
,
171 error_setg_errno(errp
, -ret
,
172 "XIVE: unable to connect CPU%ld to KVM device",
174 if (ret
== -ENOSPC
) {
175 error_append_hint(errp
, "Try -smp maxcpus=N with N < %u\n",
176 MACHINE(qdev_get_machine())->smp
.max_cpus
);
181 kvm_cpu_enable(tctx
->cs
);
186 * XIVE Interrupt Source (KVM)
189 void kvmppc_xive_set_source_config(SpaprXive
*xive
, uint32_t lisn
, XiveEAS
*eas
,
199 Error
*local_err
= NULL
;
201 assert(xive_eas_is_valid(eas
));
203 end_idx
= xive_get_field64(EAS_END_INDEX
, eas
->w
);
204 end_blk
= xive_get_field64(EAS_END_BLOCK
, eas
->w
);
205 eisn
= xive_get_field64(EAS_END_DATA
, eas
->w
);
206 masked
= xive_eas_is_masked(eas
);
208 spapr_xive_end_to_target(end_blk
, end_idx
, &server
, &priority
);
210 kvm_src
= priority
<< KVM_XIVE_SOURCE_PRIORITY_SHIFT
&
211 KVM_XIVE_SOURCE_PRIORITY_MASK
;
212 kvm_src
|= server
<< KVM_XIVE_SOURCE_SERVER_SHIFT
&
213 KVM_XIVE_SOURCE_SERVER_MASK
;
214 kvm_src
|= ((uint64_t) masked
<< KVM_XIVE_SOURCE_MASKED_SHIFT
) &
215 KVM_XIVE_SOURCE_MASKED_MASK
;
216 kvm_src
|= ((uint64_t)eisn
<< KVM_XIVE_SOURCE_EISN_SHIFT
) &
217 KVM_XIVE_SOURCE_EISN_MASK
;
219 kvm_device_access(xive
->fd
, KVM_DEV_XIVE_GRP_SOURCE_CONFIG
, lisn
,
220 &kvm_src
, true, &local_err
);
222 error_propagate(errp
, local_err
);
227 void kvmppc_xive_sync_source(SpaprXive
*xive
, uint32_t lisn
, Error
**errp
)
229 kvm_device_access(xive
->fd
, KVM_DEV_XIVE_GRP_SOURCE_SYNC
, lisn
,
234 * At reset, the interrupt sources are simply created and MASKED. We
235 * only need to inform the KVM XIVE device about their type: LSI or
238 int kvmppc_xive_source_reset_one(XiveSource
*xsrc
, int srcno
, Error
**errp
)
240 SpaprXive
*xive
= SPAPR_XIVE(xsrc
->xive
);
243 assert(xive
->fd
!= -1);
245 if (xive_source_irq_is_lsi(xsrc
, srcno
)) {
246 state
|= KVM_XIVE_LEVEL_SENSITIVE
;
247 if (xsrc
->status
[srcno
] & XIVE_STATUS_ASSERTED
) {
248 state
|= KVM_XIVE_LEVEL_ASSERTED
;
252 return kvm_device_access(xive
->fd
, KVM_DEV_XIVE_GRP_SOURCE
, srcno
, &state
,
256 static int kvmppc_xive_source_reset(XiveSource
*xsrc
, Error
**errp
)
258 SpaprXive
*xive
= SPAPR_XIVE(xsrc
->xive
);
261 for (i
= 0; i
< xsrc
->nr_irqs
; i
++) {
264 if (!xive_eas_is_valid(&xive
->eat
[i
])) {
268 ret
= kvmppc_xive_source_reset_one(xsrc
, i
, errp
);
278 * This is used to perform the magic loads on the ESB pages, described
281 * Memory barriers should not be needed for loads (no store for now).
283 static uint64_t xive_esb_rw(XiveSource
*xsrc
, int srcno
, uint32_t offset
,
284 uint64_t data
, bool write
)
286 uint64_t *addr
= xsrc
->esb_mmap
+ xive_source_esb_mgmt(xsrc
, srcno
) +
290 *addr
= cpu_to_be64(data
);
293 /* Prevent the compiler from optimizing away the load */
294 volatile uint64_t value
= be64_to_cpu(*addr
);
299 static uint8_t xive_esb_read(XiveSource
*xsrc
, int srcno
, uint32_t offset
)
301 return xive_esb_rw(xsrc
, srcno
, offset
, 0, 0) & 0x3;
304 static void xive_esb_trigger(XiveSource
*xsrc
, int srcno
)
306 uint64_t *addr
= xsrc
->esb_mmap
+ xive_source_esb_page(xsrc
, srcno
);
311 uint64_t kvmppc_xive_esb_rw(XiveSource
*xsrc
, int srcno
, uint32_t offset
,
312 uint64_t data
, bool write
)
315 return xive_esb_rw(xsrc
, srcno
, offset
, data
, 1);
319 * Special Load EOI handling for LSI sources. Q bit is never set
320 * and the interrupt should be re-triggered if the level is still
323 if (xive_source_irq_is_lsi(xsrc
, srcno
) &&
324 offset
== XIVE_ESB_LOAD_EOI
) {
325 xive_esb_read(xsrc
, srcno
, XIVE_ESB_SET_PQ_00
);
326 if (xsrc
->status
[srcno
] & XIVE_STATUS_ASSERTED
) {
327 xive_esb_trigger(xsrc
, srcno
);
331 return xive_esb_rw(xsrc
, srcno
, offset
, 0, 0);
335 static void kvmppc_xive_source_get_state(XiveSource
*xsrc
)
337 SpaprXive
*xive
= SPAPR_XIVE(xsrc
->xive
);
340 for (i
= 0; i
< xsrc
->nr_irqs
; i
++) {
343 if (!xive_eas_is_valid(&xive
->eat
[i
])) {
347 /* Perform a load without side effect to retrieve the PQ bits */
348 pq
= xive_esb_read(xsrc
, i
, XIVE_ESB_GET
);
350 /* and save PQ locally */
351 xive_source_esb_set(xsrc
, i
, pq
);
355 void kvmppc_xive_source_set_irq(void *opaque
, int srcno
, int val
)
357 XiveSource
*xsrc
= opaque
;
359 if (!xive_source_irq_is_lsi(xsrc
, srcno
)) {
365 xsrc
->status
[srcno
] |= XIVE_STATUS_ASSERTED
;
367 xsrc
->status
[srcno
] &= ~XIVE_STATUS_ASSERTED
;
371 xive_esb_trigger(xsrc
, srcno
);
375 * sPAPR XIVE interrupt controller (KVM)
377 int kvmppc_xive_get_queue_config(SpaprXive
*xive
, uint8_t end_blk
,
378 uint32_t end_idx
, XiveEND
*end
,
381 struct kvm_ppc_xive_eq kvm_eq
= { 0 };
387 assert(xive_end_is_valid(end
));
389 /* Encode the tuple (server, prio) as a KVM EQ index */
390 spapr_xive_end_to_target(end_blk
, end_idx
, &server
, &priority
);
392 kvm_eq_idx
= priority
<< KVM_XIVE_EQ_PRIORITY_SHIFT
&
393 KVM_XIVE_EQ_PRIORITY_MASK
;
394 kvm_eq_idx
|= server
<< KVM_XIVE_EQ_SERVER_SHIFT
&
395 KVM_XIVE_EQ_SERVER_MASK
;
397 ret
= kvm_device_access(xive
->fd
, KVM_DEV_XIVE_GRP_EQ_CONFIG
, kvm_eq_idx
,
398 &kvm_eq
, false, errp
);
404 * The EQ index and toggle bit are updated by HW. These are the
405 * only fields from KVM we want to update QEMU with. The other END
406 * fields should already be in the QEMU END table.
408 end
->w1
= xive_set_field32(END_W1_GENERATION
, 0ul, kvm_eq
.qtoggle
) |
409 xive_set_field32(END_W1_PAGE_OFF
, 0ul, kvm_eq
.qindex
);
414 int kvmppc_xive_set_queue_config(SpaprXive
*xive
, uint8_t end_blk
,
415 uint32_t end_idx
, XiveEND
*end
,
418 struct kvm_ppc_xive_eq kvm_eq
= { 0 };
424 * Build the KVM state from the local END structure.
428 if (xive_get_field32(END_W0_UCOND_NOTIFY
, end
->w0
)) {
429 kvm_eq
.flags
|= KVM_XIVE_EQ_ALWAYS_NOTIFY
;
433 * If the hcall is disabling the EQ, set the size and page address
434 * to zero. When migrating, only valid ENDs are taken into
437 if (xive_end_is_valid(end
)) {
438 kvm_eq
.qshift
= xive_get_field32(END_W0_QSIZE
, end
->w0
) + 12;
439 kvm_eq
.qaddr
= xive_end_qaddr(end
);
441 * The EQ toggle bit and index should only be relevant when
442 * restoring the EQ state
444 kvm_eq
.qtoggle
= xive_get_field32(END_W1_GENERATION
, end
->w1
);
445 kvm_eq
.qindex
= xive_get_field32(END_W1_PAGE_OFF
, end
->w1
);
451 /* Encode the tuple (server, prio) as a KVM EQ index */
452 spapr_xive_end_to_target(end_blk
, end_idx
, &server
, &priority
);
454 kvm_eq_idx
= priority
<< KVM_XIVE_EQ_PRIORITY_SHIFT
&
455 KVM_XIVE_EQ_PRIORITY_MASK
;
456 kvm_eq_idx
|= server
<< KVM_XIVE_EQ_SERVER_SHIFT
&
457 KVM_XIVE_EQ_SERVER_MASK
;
460 kvm_device_access(xive
->fd
, KVM_DEV_XIVE_GRP_EQ_CONFIG
, kvm_eq_idx
,
461 &kvm_eq
, true, errp
);
464 void kvmppc_xive_reset(SpaprXive
*xive
, Error
**errp
)
466 kvm_device_access(xive
->fd
, KVM_DEV_XIVE_GRP_CTRL
, KVM_DEV_XIVE_RESET
,
470 static int kvmppc_xive_get_queues(SpaprXive
*xive
, Error
**errp
)
475 for (i
= 0; i
< xive
->nr_ends
; i
++) {
476 if (!xive_end_is_valid(&xive
->endt
[i
])) {
480 ret
= kvmppc_xive_get_queue_config(xive
, SPAPR_XIVE_BLOCK_ID
, i
,
481 &xive
->endt
[i
], errp
);
491 * The primary goal of the XIVE VM change handler is to mark the EQ
492 * pages dirty when all XIVE event notifications have stopped.
494 * Whenever the VM is stopped, the VM change handler sets the source
495 * PQs to PENDING to stop the flow of events and to possibly catch a
496 * triggered interrupt occuring while the VM is stopped. The previous
497 * state is saved in anticipation of a migration. The XIVE controller
498 * is then synced through KVM to flush any in-flight event
499 * notification and stabilize the EQs.
501 * At this stage, we can mark the EQ page dirty and let a migration
502 * sequence transfer the EQ pages to the destination, which is done
503 * just after the stop state.
505 * The previous configuration of the sources is restored when the VM
506 * runs again. If an interrupt was queued while the VM was stopped,
507 * simply generate a trigger.
509 static void kvmppc_xive_change_state_handler(void *opaque
, int running
,
512 SpaprXive
*xive
= opaque
;
513 XiveSource
*xsrc
= &xive
->source
;
514 Error
*local_err
= NULL
;
518 * Restore the sources to their initial state. This is called when
519 * the VM resumes after a stop or a migration.
522 for (i
= 0; i
< xsrc
->nr_irqs
; i
++) {
526 if (!xive_eas_is_valid(&xive
->eat
[i
])) {
530 pq
= xive_source_esb_get(xsrc
, i
);
531 old_pq
= xive_esb_read(xsrc
, i
, XIVE_ESB_SET_PQ_00
+ (pq
<< 8));
534 * An interrupt was queued while the VM was stopped,
535 * generate a trigger.
537 if (pq
== XIVE_ESB_RESET
&& old_pq
== XIVE_ESB_QUEUED
) {
538 xive_esb_trigger(xsrc
, i
);
546 * Mask the sources, to stop the flow of event notifications, and
547 * save the PQs locally in the XiveSource object. The XiveSource
548 * state will be collected later on by its vmstate handler if a
549 * migration is in progress.
551 for (i
= 0; i
< xsrc
->nr_irqs
; i
++) {
554 if (!xive_eas_is_valid(&xive
->eat
[i
])) {
558 pq
= xive_esb_read(xsrc
, i
, XIVE_ESB_GET
);
561 * PQ is set to PENDING to possibly catch a triggered
562 * interrupt occuring while the VM is stopped (hotplug event
565 if (pq
!= XIVE_ESB_OFF
) {
566 pq
= xive_esb_read(xsrc
, i
, XIVE_ESB_SET_PQ_10
);
568 xive_source_esb_set(xsrc
, i
, pq
);
572 * Sync the XIVE controller in KVM, to flush in-flight event
573 * notification that should be enqueued in the EQs and mark the
574 * XIVE EQ pages dirty to collect all updates.
576 kvm_device_access(xive
->fd
, KVM_DEV_XIVE_GRP_CTRL
,
577 KVM_DEV_XIVE_EQ_SYNC
, NULL
, true, &local_err
);
579 error_report_err(local_err
);
584 void kvmppc_xive_synchronize_state(SpaprXive
*xive
, Error
**errp
)
586 assert(xive
->fd
!= -1);
589 * When the VM is stopped, the sources are masked and the previous
590 * state is saved in anticipation of a migration. We should not
591 * synchronize the source state in that case else we will override
594 if (runstate_is_running()) {
595 kvmppc_xive_source_get_state(&xive
->source
);
598 /* EAT: there is no extra state to query from KVM */
601 kvmppc_xive_get_queues(xive
, errp
);
605 * The SpaprXive 'pre_save' method is called by the vmstate handler of
606 * the SpaprXive model, after the XIVE controller is synced in the VM
609 int kvmppc_xive_pre_save(SpaprXive
*xive
)
611 Error
*local_err
= NULL
;
613 assert(xive
->fd
!= -1);
615 /* EAT: there is no extra state to query from KVM */
618 kvmppc_xive_get_queues(xive
, &local_err
);
620 error_report_err(local_err
);
628 * The SpaprXive 'post_load' method is not called by a vmstate
629 * handler. It is called at the sPAPR machine level at the end of the
630 * migration sequence by the sPAPR IRQ backend 'post_load' method,
631 * when all XIVE states have been transferred and loaded.
633 int kvmppc_xive_post_load(SpaprXive
*xive
, int version_id
)
635 Error
*local_err
= NULL
;
639 /* The KVM XIVE device should be in use */
640 assert(xive
->fd
!= -1);
642 /* Restore the ENDT first. The targetting depends on it. */
643 for (i
= 0; i
< xive
->nr_ends
; i
++) {
644 if (!xive_end_is_valid(&xive
->endt
[i
])) {
648 kvmppc_xive_set_queue_config(xive
, SPAPR_XIVE_BLOCK_ID
, i
,
649 &xive
->endt
[i
], &local_err
);
651 error_report_err(local_err
);
656 /* Restore the EAT */
657 for (i
= 0; i
< xive
->nr_irqs
; i
++) {
658 if (!xive_eas_is_valid(&xive
->eat
[i
])) {
663 * We can only restore the source config if the source has been
664 * previously set in KVM. Since we don't do that for all interrupts
665 * at reset time anymore, let's do it now.
667 kvmppc_xive_source_reset_one(&xive
->source
, i
, &local_err
);
669 error_report_err(local_err
);
673 kvmppc_xive_set_source_config(xive
, i
, &xive
->eat
[i
], &local_err
);
675 error_report_err(local_err
);
681 * Restore the thread interrupt contexts of initial CPUs.
683 * The context of hotplugged CPUs is restored later, by the
684 * 'post_load' handler of the XiveTCTX model because they are not
685 * available at the time the SpaprXive 'post_load' method is
686 * called. We can not restore the context of all CPUs in the
687 * 'post_load' handler of XiveTCTX because the machine is not
688 * necessarily connected to the KVM device at that time.
691 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
693 kvmppc_xive_cpu_set_state(spapr_cpu_state(cpu
)->tctx
, &local_err
);
695 error_report_err(local_err
);
700 /* The source states will be restored when the machine starts running */
704 /* Returns MAP_FAILED on error and sets errno */
705 static void *kvmppc_xive_mmap(SpaprXive
*xive
, int pgoff
, size_t len
,
709 uint32_t page_shift
= 16; /* TODO: fix page_shift */
711 addr
= mmap(NULL
, len
, PROT_WRITE
| PROT_READ
, MAP_SHARED
, xive
->fd
,
712 pgoff
<< page_shift
);
713 if (addr
== MAP_FAILED
) {
714 error_setg_errno(errp
, errno
, "XIVE: unable to set memory mapping");
721 * All the XIVE memory regions are now backed by mappings from the KVM
724 int kvmppc_xive_connect(SpaprInterruptController
*intc
, uint32_t nr_servers
,
727 SpaprXive
*xive
= SPAPR_XIVE(intc
);
728 XiveSource
*xsrc
= &xive
->source
;
729 Error
*local_err
= NULL
;
730 size_t esb_len
= xive_source_esb_len(xsrc
);
731 size_t tima_len
= 4ull << TM_SHIFT
;
737 * The KVM XIVE device already in use. This is the case when
738 * rebooting under the XIVE-only interrupt mode.
740 if (xive
->fd
!= -1) {
744 if (!kvmppc_has_cap_xive()) {
745 error_setg(errp
, "IRQ_XIVE capability must be present for KVM");
749 /* First, create the KVM XIVE device */
750 fd
= kvm_create_device(kvm_state
, KVM_DEV_TYPE_XIVE
, false);
752 error_setg_errno(errp
, -fd
, "XIVE: error creating KVM device");
757 /* Tell KVM about the # of VCPUs we may have */
758 if (kvm_device_check_attr(xive
->fd
, KVM_DEV_XIVE_GRP_CTRL
,
759 KVM_DEV_XIVE_NR_SERVERS
)) {
760 if (kvm_device_access(xive
->fd
, KVM_DEV_XIVE_GRP_CTRL
,
761 KVM_DEV_XIVE_NR_SERVERS
, &nr_servers
, true,
768 * 1. Source ESB pages - KVM mapping
770 addr
= kvmppc_xive_mmap(xive
, KVM_XIVE_ESB_PAGE_OFFSET
, esb_len
,
772 if (addr
== MAP_FAILED
) {
775 xsrc
->esb_mmap
= addr
;
777 memory_region_init_ram_device_ptr(&xsrc
->esb_mmio_kvm
, OBJECT(xsrc
),
778 "xive.esb-kvm", esb_len
, xsrc
->esb_mmap
);
779 memory_region_add_subregion_overlap(&xsrc
->esb_mmio
, 0,
780 &xsrc
->esb_mmio_kvm
, 1);
783 * 2. END ESB pages (No KVM support yet)
787 * 3. TIMA pages - KVM mapping
789 addr
= kvmppc_xive_mmap(xive
, KVM_XIVE_TIMA_PAGE_OFFSET
, tima_len
,
791 if (addr
== MAP_FAILED
) {
794 xive
->tm_mmap
= addr
;
796 memory_region_init_ram_device_ptr(&xive
->tm_mmio_kvm
, OBJECT(xive
),
797 "xive.tima", tima_len
, xive
->tm_mmap
);
798 memory_region_add_subregion_overlap(&xive
->tm_mmio
, 0,
799 &xive
->tm_mmio_kvm
, 1);
801 xive
->change
= qemu_add_vm_change_state_handler(
802 kvmppc_xive_change_state_handler
, xive
);
804 /* Connect the presenters to the initial VCPUs of the machine */
806 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
808 kvmppc_xive_cpu_connect(spapr_cpu_state(cpu
)->tctx
, &local_err
);
814 /* Update the KVM sources */
815 kvmppc_xive_source_reset(xsrc
, &local_err
);
820 kvm_kernel_irqchip
= true;
821 kvm_msi_via_irqfd_allowed
= true;
822 kvm_gsi_direct_mapping
= true;
826 error_propagate(errp
, local_err
);
827 kvmppc_xive_disconnect(intc
);
831 void kvmppc_xive_disconnect(SpaprInterruptController
*intc
)
833 SpaprXive
*xive
= SPAPR_XIVE(intc
);
837 assert(xive
->fd
!= -1);
839 /* Clear the KVM mapping */
840 xsrc
= &xive
->source
;
841 esb_len
= (1ull << xsrc
->esb_shift
) * xsrc
->nr_irqs
;
843 if (xsrc
->esb_mmap
) {
844 memory_region_del_subregion(&xsrc
->esb_mmio
, &xsrc
->esb_mmio_kvm
);
845 object_unparent(OBJECT(&xsrc
->esb_mmio_kvm
));
846 munmap(xsrc
->esb_mmap
, esb_len
);
847 xsrc
->esb_mmap
= NULL
;
851 memory_region_del_subregion(&xive
->tm_mmio
, &xive
->tm_mmio_kvm
);
852 object_unparent(OBJECT(&xive
->tm_mmio_kvm
));
853 munmap(xive
->tm_mmap
, 4ull << TM_SHIFT
);
854 xive
->tm_mmap
= NULL
;
858 * When the KVM device fd is closed, the KVM device is destroyed
859 * and removed from the list of devices of the VM. The VCPU
860 * presenters are also detached from the device.
865 kvm_kernel_irqchip
= false;
866 kvm_msi_via_irqfd_allowed
= false;
867 kvm_gsi_direct_mapping
= false;
869 /* Clear the local list of presenter (hotplug) */
870 kvm_cpu_disable_all();
872 /* VM Change state handler is not needed anymore */
874 qemu_del_vm_change_state_handler(xive
->change
);