/src/qemu/accel/accel-irq.c
Line | Count | Source |
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 | 0 | { |
22 | 0 | if (mshv_msi_via_irqfd_enabled()) { |
23 | 0 | return mshv_irqchip_add_msi_route(c, vector, dev); |
24 | 0 | } |
25 | 0 | if (kvm_enabled()) { |
26 | 0 | return kvm_irqchip_add_msi_route(c, vector, dev); |
27 | 0 | } |
28 | 0 | return -ENOSYS; |
29 | 0 | } |
30 | | |
31 | | int accel_irqchip_update_msi_route(int vector, MSIMessage msg, PCIDevice *dev) |
32 | 0 | { |
33 | 0 | if (mshv_msi_via_irqfd_enabled()) { |
34 | 0 | return mshv_irqchip_update_msi_route(vector, msg, dev); |
35 | 0 | } |
36 | 0 | if (kvm_enabled()) { |
37 | 0 | return kvm_irqchip_update_msi_route(kvm_state, vector, msg, dev); |
38 | 0 | } |
39 | 0 | return -ENOSYS; |
40 | 0 | } |
41 | | |
42 | | void accel_irqchip_commit_route_changes(AccelRouteChange *c) |
43 | 0 | { |
44 | 0 | if (c->changes) { |
45 | 0 | accel_irqchip_commit_routes(); |
46 | 0 | c->changes = 0; |
47 | 0 | } |
48 | 0 | } |
49 | | |
50 | | void accel_irqchip_commit_routes(void) |
51 | 0 | { |
52 | 0 | if (mshv_msi_via_irqfd_enabled()) { |
53 | 0 | mshv_irqchip_commit_routes(mshv_state); |
54 | 0 | } |
55 | 0 | if (kvm_enabled()) { |
56 | 0 | kvm_irqchip_commit_routes(kvm_state); |
57 | 0 | } |
58 | 0 | } |
59 | | |
60 | | void accel_irqchip_release_virq(int virq) |
61 | 0 | { |
62 | 0 | if (mshv_msi_via_irqfd_enabled()) { |
63 | 0 | mshv_irqchip_release_virq(mshv_state, virq); |
64 | 0 | } |
65 | 0 | if (kvm_enabled()) { |
66 | 0 | kvm_irqchip_release_virq(kvm_state, virq); |
67 | 0 | } |
68 | 0 | } |
69 | | |
70 | | int accel_irqchip_add_irqfd_notifier_gsi(EventNotifier *n, EventNotifier *rn, |
71 | | int virq) |
72 | 0 | { |
73 | 0 | if (mshv_msi_via_irqfd_enabled()) { |
74 | 0 | return mshv_irqchip_add_irqfd_notifier_gsi(n, rn, virq); |
75 | 0 | } |
76 | 0 | if (kvm_enabled()) { |
77 | 0 | return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, rn, virq); |
78 | 0 | } |
79 | 0 | return -ENOSYS; |
80 | 0 | } |
81 | | |
82 | | int accel_irqchip_remove_irqfd_notifier_gsi(EventNotifier *n, int virq) |
83 | 0 | { |
84 | 0 | if (mshv_msi_via_irqfd_enabled()) { |
85 | 0 | return mshv_irqchip_remove_irqfd_notifier_gsi(n, virq); |
86 | 0 | } |
87 | 0 | if (kvm_enabled()) { |
88 | 0 | return kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, n, virq); |
89 | 0 | } |
90 | 0 | return -ENOSYS; |
91 | 0 | } |
92 | | |
93 | | inline AccelRouteChange accel_irqchip_begin_route_changes(void) |
94 | 0 | { |
95 | 0 | if (mshv_msi_via_irqfd_enabled()) { |
96 | 0 | return (AccelRouteChange) { |
97 | 0 | .accel = ACCEL(mshv_state), |
98 | 0 | .changes = 0, |
99 | 0 | }; |
100 | 0 | } |
101 | 0 | if (kvm_enabled()) { |
102 | 0 | return (AccelRouteChange) { |
103 | 0 | .accel = ACCEL(kvm_state), |
104 | 0 | .changes = 0, |
105 | 0 | }; |
106 | 0 | } |
107 | 0 | error_report("can't initiate route change, no accel irqchip available"); |
108 | 0 | abort(); |
109 | 0 | } |