1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _XEN_XEN_H
3 #define _XEN_XEN_H
4 
5 enum xen_domain_type {
6 	XEN_NATIVE,		/* running on bare hardware    */
7 	XEN_PV_DOMAIN,		/* running in a PV domain      */
8 	XEN_HVM_DOMAIN,		/* running in a Xen hvm domain */
9 };
10 
11 #ifdef CONFIG_XEN
12 extern enum xen_domain_type xen_domain_type;
13 #else
14 #define xen_domain_type		XEN_NATIVE
15 #endif
16 
17 #ifdef CONFIG_XEN_PVH
18 extern bool xen_pvh;
19 #else
20 #define xen_pvh			0
21 #endif
22 
23 #define xen_domain()		(xen_domain_type != XEN_NATIVE)
24 #define xen_pv_domain()		(xen_domain_type == XEN_PV_DOMAIN)
25 #define xen_hvm_domain()	(xen_domain_type == XEN_HVM_DOMAIN)
26 #define xen_pvh_domain()	(xen_pvh)
27 
28 #include <linux/types.h>
29 
30 extern uint32_t xen_start_flags;
31 
32 #include <xen/interface/hvm/start_info.h>
33 extern struct hvm_start_info pvh_start_info;
34 
35 #ifdef CONFIG_XEN_DOM0
36 #include <xen/interface/xen.h>
37 #include <asm/xen/hypervisor.h>
38 
39 #define xen_initial_domain()	(xen_domain() && \
40 				 (xen_start_flags & SIF_INITDOMAIN))
41 #else  /* !CONFIG_XEN_DOM0 */
42 #define xen_initial_domain()	(0)
43 #endif	/* CONFIG_XEN_DOM0 */
44 
45 struct bio_vec;
46 struct page;
47 
48 bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
49 		const struct page *page);
50 
51 #if defined(CONFIG_MEMORY_HOTPLUG) && defined(CONFIG_XEN_BALLOON)
52 extern u64 xen_saved_max_mem_size;
53 #endif
54 
55 #ifdef CONFIG_XEN_UNPOPULATED_ALLOC
56 int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages);
57 void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages);
58 #include <linux/ioport.h>
59 int arch_xen_unpopulated_init(struct resource **res);
60 #else
61 #include <xen/balloon.h>
xen_alloc_unpopulated_pages(unsigned int nr_pages,struct page ** pages)62 static inline int xen_alloc_unpopulated_pages(unsigned int nr_pages,
63 		struct page **pages)
64 {
65 	return xen_alloc_ballooned_pages(nr_pages, pages);
66 }
xen_free_unpopulated_pages(unsigned int nr_pages,struct page ** pages)67 static inline void xen_free_unpopulated_pages(unsigned int nr_pages,
68 		struct page **pages)
69 {
70 	xen_free_ballooned_pages(nr_pages, pages);
71 }
72 #endif
73 
74 #endif	/* _XEN_XEN_H */
75