master
h 80 lines 2.27 KB
Raw
1 /*
2 * QEMU MSHV support
3 *
4 * Copyright Microsoft, Corp. 2025
5 *
6 * Authors: Ziqiao Zhou <ziqiaozhou@microsoft.com>
7 * Magnus Kulke <magnuskulke@microsoft.com>
8 * Jinank Jain <jinankjain@microsoft.com>
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 *
12 */
13
14 #ifndef QEMU_MSHV_H
15 #define QEMU_MSHV_H
16
17 #include "qemu/accel.h"
18 #include "hw/hyperv/hyperv-proto.h"
19 #include "hw/hyperv/hvhdk.h"
20 #include "hw/hyperv/hvgdk_mini.h"
21 #include "qapi/qapi-types-common.h"
22 #include "system/memory.h"
23 #include "accel/accel-ops.h"
24 #include "accel/accel-route.h"
25
26 #ifdef COMPILING_PER_TARGET
27 #ifdef CONFIG_MSHV
28 #include <linux/mshv.h>
29 #define CONFIG_MSHV_IS_POSSIBLE
30 #endif
31 #else
32 #define CONFIG_MSHV_IS_POSSIBLE
33 #endif
34
35 #define MSHV_MAX_MSI_ROUTES 4096
36 #define MSHV_MIN_ALLOCATED_MSI_ROUTES 64
37
38 #define MSHV_PAGE_SHIFT 12
39
40 #ifdef CONFIG_MSHV_IS_POSSIBLE
41 extern bool mshv_allowed;
42 #define mshv_enabled() (mshv_allowed)
43 #define mshv_msi_via_irqfd_enabled() mshv_enabled()
44 #define mshv_irqchip_in_kernel() mshv_enabled()
45 #else /* CONFIG_MSHV_IS_POSSIBLE */
46 #define mshv_enabled() false
47 #define mshv_msi_via_irqfd_enabled() mshv_enabled()
48 #define mshv_irqchip_in_kernel() mshv_enabled()
49 #endif
50
51 #define TYPE_MSHV_ACCEL ACCEL_CLASS_NAME("mshv")
52
53 typedef struct MshvState MshvState;
54
55 DECLARE_INSTANCE_CHECKER(MshvState, MSHV_STATE,
56 TYPE_MSHV_ACCEL)
57
58 extern MshvState *mshv_state;
59
60 /* clock (partition reference time) */
61 void mshv_clock_init(void);
62
63 /* interrupt */
64 int mshv_request_interrupt(MshvState *mshv_state, uint32_t interrupt_type, uint32_t vector,
65 uint32_t vp_index, bool logical_destination_mode,
66 bool level_triggered);
67
68 int mshv_irqchip_add_msi_route(AccelRouteChange *c, int vector, PCIDevice *dev);
69 int mshv_irqchip_update_msi_route(int virq, MSIMessage msg, PCIDevice *dev);
70 void mshv_irqchip_release_virq(MshvState *s, int virq);
71 void mshv_irqchip_commit_routes(MshvState *s);
72 int mshv_irqchip_add_irqfd_notifier_gsi(const EventNotifier *n,
73 const EventNotifier *rn, int virq);
74 int mshv_irqchip_remove_irqfd_notifier_gsi(const EventNotifier *n, int virq);
75 void mshv_init_irq_routing(MshvState *s);
76
77 /* cpuid */
78 uint32_t mshv_get_supported_cpuid(uint32_t func, uint32_t idx, int reg);
79
80 #endif