1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _XEN_XEN_H
3 #define _XEN_XEN_H
4
5 #include <linux/types.h>
6
7 enum xen_domain_type {
8 XEN_NATIVE, /* running on bare hardware */
9 XEN_PV_DOMAIN, /* running in a PV domain */
10 XEN_HVM_DOMAIN, /* running in a Xen hvm domain */
11 };
12
13 #ifdef CONFIG_XEN
14 extern enum xen_domain_type xen_domain_type;
15 #else
16 #define xen_domain_type XEN_NATIVE
17 #endif
18
19 #ifdef CONFIG_XEN_PVH
20 extern bool xen_pvh;
21 #else
22 #define xen_pvh 0
23 #endif
24
25 #ifdef CONFIG_X86
26 #include <asm/cpufeature.h>
27
28 #define xen_pv_domain() (cpu_feature_enabled(X86_FEATURE_XENPV))
29 #else
30 #define xen_pv_domain() 0
31 #endif
32
33 #define xen_domain() (xen_domain_type != XEN_NATIVE)
34 #define xen_hvm_domain() (xen_domain_type == XEN_HVM_DOMAIN)
35 #define xen_pvh_domain() (xen_pvh)
36
37 extern uint32_t xen_start_flags;
38
39 #ifdef CONFIG_XEN_PV
40 extern bool xen_pv_pci_possible;
41 #else
42 #define xen_pv_pci_possible 0
43 #endif
44
45 #include <xen/interface/hvm/start_info.h>
46 extern struct hvm_start_info pvh_start_info;
47 void xen_prepare_pvh(void);
48 struct pt_regs;
49 void xen_pv_evtchn_do_upcall(struct pt_regs *regs);
50
51 #ifdef CONFIG_XEN_DOM0
52 #include <xen/interface/xen.h>
53 #include <asm/xen/hypervisor.h>
54
55 #define xen_initial_domain() (xen_domain() && \
56 (xen_start_flags & SIF_INITDOMAIN))
57 #else /* !CONFIG_XEN_DOM0 */
58 #define xen_initial_domain() (0)
59 #endif /* CONFIG_XEN_DOM0 */
60
61 struct bio_vec;
62 struct page;
63
64 bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
65 const struct page *page);
66
67 #if defined(CONFIG_MEMORY_HOTPLUG) && defined(CONFIG_XEN_BALLOON)
68 extern u64 xen_saved_max_mem_size;
69 #endif
70
71 #ifdef CONFIG_XEN_UNPOPULATED_ALLOC
72 int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages);
73 void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages);
74 #include <linux/ioport.h>
75 int arch_xen_unpopulated_init(struct resource **res);
76 #else
77 #include <xen/balloon.h>
xen_alloc_unpopulated_pages(unsigned int nr_pages,struct page ** pages)78 static inline int xen_alloc_unpopulated_pages(unsigned int nr_pages,
79 struct page **pages)
80 {
81 return xen_alloc_ballooned_pages(nr_pages, pages);
82 }
xen_free_unpopulated_pages(unsigned int nr_pages,struct page ** pages)83 static inline void xen_free_unpopulated_pages(unsigned int nr_pages,
84 struct page **pages)
85 {
86 xen_free_ballooned_pages(nr_pages, pages);
87 }
88 #endif
89
90 #if defined(CONFIG_XEN_DOM0) && defined(CONFIG_ACPI) && defined(CONFIG_X86)
91 bool __init xen_processor_present(uint32_t acpi_id);
92 #else
93 #include <linux/bug.h>
xen_processor_present(uint32_t acpi_id)94 static inline bool xen_processor_present(uint32_t acpi_id)
95 {
96 BUG();
97 return false;
98 }
99 #endif
100
101 #endif /* _XEN_XEN_H */
102