master
c 109 lines 2.69 KB
Raw
1 /*
2 * Accelerated irqchip abstraction
3 *
4 * Copyright Microsoft, Corp. 2025
5 *
6 * Authors: Ziqiao Zhou <ziqiaozhou@microsoft.com>
7 * Magnus Kulke <magnuskulke@microsoft.com>
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 */
11
12 #include "qemu/osdep.h"
13 #include "qemu/error-report.h"
14 #include "hw/pci/msi.h"
15
16 #include "system/kvm.h"
17 #include "system/mshv.h"
18 #include "system/accel-irq.h"
19
20 int accel_irqchip_add_msi_route(AccelRouteChange *c, int vector, PCIDevice *dev)
21 {
22 if (mshv_msi_via_irqfd_enabled()) {
23 return mshv_irqchip_add_msi_route(c, vector, dev);
24 }
25 if (kvm_enabled()) {
26 return kvm_irqchip_add_msi_route(c, vector, dev);
27 }
28 return -ENOSYS;
29 }
30
31 int accel_irqchip_update_msi_route(int vector, MSIMessage msg, PCIDevice *dev)
32 {
33 if (mshv_msi_via_irqfd_enabled()) {
34 return mshv_irqchip_update_msi_route(vector, msg, dev);
35 }
36 if (kvm_enabled()) {
37 return kvm_irqchip_update_msi_route(kvm_state, vector, msg, dev);
38 }
39 return -ENOSYS;
40 }
41
42 void accel_irqchip_commit_route_changes(AccelRouteChange *c)
43 {
44 if (c->changes) {
45 accel_irqchip_commit_routes();
46 c->changes = 0;
47 }
48 }
49
50 void accel_irqchip_commit_routes(void)
51 {
52 if (mshv_msi_via_irqfd_enabled()) {
53 mshv_irqchip_commit_routes(mshv_state);
54 }
55 if (kvm_enabled()) {
56 kvm_irqchip_commit_routes(kvm_state);
57 }
58 }
59
60 void accel_irqchip_release_virq(int virq)
61 {
62 if (mshv_msi_via_irqfd_enabled()) {
63 mshv_irqchip_release_virq(mshv_state, virq);
64 }
65 if (kvm_enabled()) {
66 kvm_irqchip_release_virq(kvm_state, virq);
67 }
68 }
69
70 int accel_irqchip_add_irqfd_notifier_gsi(EventNotifier *n, EventNotifier *rn,
71 int virq)
72 {
73 if (mshv_msi_via_irqfd_enabled()) {
74 return mshv_irqchip_add_irqfd_notifier_gsi(n, rn, virq);
75 }
76 if (kvm_enabled()) {
77 return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, rn, virq);
78 }
79 return -ENOSYS;
80 }
81
82 int accel_irqchip_remove_irqfd_notifier_gsi(EventNotifier *n, int virq)
83 {
84 if (mshv_msi_via_irqfd_enabled()) {
85 return mshv_irqchip_remove_irqfd_notifier_gsi(n, virq);
86 }
87 if (kvm_enabled()) {
88 return kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, n, virq);
89 }
90 return -ENOSYS;
91 }
92
93 inline AccelRouteChange accel_irqchip_begin_route_changes(void)
94 {
95 if (mshv_msi_via_irqfd_enabled()) {
96 return (AccelRouteChange) {
97 .accel = ACCEL(mshv_state),
98 .changes = 0,
99 };
100 }
101 if (kvm_enabled()) {
102 return (AccelRouteChange) {
103 .accel = ACCEL(kvm_state),
104 .changes = 0,
105 };
106 }
107 error_report("can't initiate route change, no accel irqchip available");
108 abort();
109 }