blob: fd18c974a6194b24712c961f45d66667e2ceb80c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Isaku Yamahatae04d0d02008-04-02 10:53:55 -07002#ifndef INCLUDE_XEN_OPS_H
3#define INCLUDE_XEN_OPS_H
4
5#include <linux/percpu.h>
Stanislaw Gruszkacd979882014-02-26 11:30:30 +01006#include <linux/notifier.h>
Daniel Kiperbe81c8a2014-06-30 19:53:02 +02007#include <linux/efi.h>
Ian Campbell7892f692012-10-16 17:19:15 +01008#include <asm/xen/interface.h>
Stefano Stabellini4ccefbe2015-11-05 15:15:07 +00009#include <xen/interface/vcpu.h>
Isaku Yamahatae04d0d02008-04-02 10:53:55 -070010
11DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu);
12
Vitaly Kuznetsov55467de2016-07-29 11:06:48 +020013DECLARE_PER_CPU(uint32_t, xen_vcpu_id);
14static inline uint32_t xen_vcpu_nr(int cpu)
Vitaly Kuznetsov88e957d2016-06-30 17:56:37 +020015{
16 return per_cpu(xen_vcpu_id, cpu);
17}
18
Ankur Arora0b64ffb2017-06-02 17:05:59 -070019#define XEN_VCPU_ID_INVALID U32_MAX
20
Ian Campbell03c81422011-02-17 11:04:20 +000021void xen_arch_pre_suspend(void);
22void xen_arch_post_suspend(int suspend_cancelled);
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +010023
Isaku Yamahataad55db92008-07-08 15:06:32 -070024void xen_timer_resume(void);
25void xen_arch_resume(void);
Boris Ostrovsky2b953a52015-04-28 18:46:20 -040026void xen_arch_suspend(void);
Isaku Yamahataad55db92008-07-08 15:06:32 -070027
Julien Grall5d9404e2017-04-24 18:58:37 +010028void xen_reboot(int reason);
29
Stanislaw Gruszkacd979882014-02-26 11:30:30 +010030void xen_resume_notifier_register(struct notifier_block *nb);
31void xen_resume_notifier_unregister(struct notifier_block *nb);
32
Stefano Stabellini4ccefbe2015-11-05 15:15:07 +000033bool xen_vcpu_stolen(int vcpu);
34void xen_setup_runstate_info(int cpu);
Juergen Grossecb23dc2016-05-20 09:26:48 +020035void xen_time_setup_guest(void);
Dongli Zhang5e25f5d2017-11-01 09:46:33 +080036void xen_manage_runstate_time(int action);
Stefano Stabellini4ccefbe2015-11-05 15:15:07 +000037void xen_get_runstate_snapshot(struct vcpu_runstate_info *res);
Juergen Grossd34c30c2016-07-26 14:15:11 +020038u64 xen_steal_clock(int cpu);
Stefano Stabellini4ccefbe2015-11-05 15:15:07 +000039
Stefano Stabellini016b6f52010-05-14 12:45:07 +010040int xen_setup_shutdown_event(void);
41
Alex Nixon08bbc9d2009-02-09 12:05:46 -080042extern unsigned long *xen_contiguous_bitmap;
Vitaly Kuznetsov16624392017-03-14 18:35:54 +010043
44#ifdef CONFIG_XEN_PV
Stefano Stabellini1b65c4e2013-10-10 13:41:10 +000045int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
Stefano Stabellini699089072013-10-09 16:56:32 +000046 unsigned int address_bits,
47 dma_addr_t *dma_handle);
Alex Nixon08bbc9d2009-02-09 12:05:46 -080048
Stefano Stabellini1b65c4e2013-10-10 13:41:10 +000049void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order);
Vitaly Kuznetsov16624392017-03-14 18:35:54 +010050#else
51static inline int xen_create_contiguous_region(phys_addr_t pstart,
52 unsigned int order,
53 unsigned int address_bits,
54 dma_addr_t *dma_handle)
55{
56 return 0;
57}
58
59static inline void xen_destroy_contiguous_region(phys_addr_t pstart,
60 unsigned int order) { }
61#endif
Alex Nixon08bbc9d2009-02-09 12:05:46 -080062
David Howellsc140d872012-03-28 18:30:02 +010063struct vm_area_struct;
David Vrabel4e8c0c82015-03-11 14:49:57 +000064
65/*
Paul Durrant3ad08762018-05-09 14:16:12 +010066 * xen_remap_domain_gfn_array() - map an array of foreign frames by gfn
David Vrabel4e8c0c82015-03-11 14:49:57 +000067 * @vma: VMA to map the pages into
68 * @addr: Address at which to map the pages
69 * @gfn: Array of GFNs to map
70 * @nr: Number entries in the GFN array
71 * @err_ptr: Returns per-GFN error status.
72 * @prot: page protection mask
73 * @domid: Domain owning the pages
74 * @pages: Array of pages if this domain has an auto-translated physmap
75 *
76 * @gfn and @err_ptr may point to the same buffer, the GFNs will be
77 * overwritten by the error codes after they are mapped.
78 *
79 * Returns the number of successfully mapped frames, or a -ve error
80 * code.
81 */
Julien Gralla13d7202015-08-07 17:34:41 +010082int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
David Vrabel4e8c0c82015-03-11 14:49:57 +000083 unsigned long addr,
84 xen_pfn_t *gfn, int nr,
85 int *err_ptr, pgprot_t prot,
86 unsigned domid,
87 struct page **pages);
88
Paul Durrant3ad08762018-05-09 14:16:12 +010089/*
90 * xen_remap_domain_mfn_array() - map an array of foreign frames by mfn
91 * @vma: VMA to map the pages into
92 * @addr: Address at which to map the pages
93 * @mfn: Array of MFNs to map
94 * @nr: Number entries in the MFN array
95 * @err_ptr: Returns per-MFN error status.
96 * @prot: page protection mask
97 * @domid: Domain owning the pages
98 * @pages: Array of pages if this domain has an auto-translated physmap
99 *
100 * @mfn and @err_ptr may point to the same buffer, the MFNs will be
101 * overwritten by the error codes after they are mapped.
102 *
103 * Returns the number of successfully mapped frames, or a -ve error
104 * code.
105 */
106int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
107 unsigned long addr, xen_pfn_t *mfn, int nr,
108 int *err_ptr, pgprot_t prot,
109 unsigned int domid, struct page **pages);
110
Julien Gralla13d7202015-08-07 17:34:41 +0100111/* xen_remap_domain_gfn_range() - map a range of foreign frames
David Vrabel4e8c0c82015-03-11 14:49:57 +0000112 * @vma: VMA to map the pages into
113 * @addr: Address at which to map the pages
114 * @gfn: First GFN to map.
115 * @nr: Number frames to map
116 * @prot: page protection mask
117 * @domid: Domain owning the pages
118 * @pages: Array of pages if this domain has an auto-translated physmap
119 *
120 * Returns the number of successfully mapped frames, or a -ve error
121 * code.
122 */
Julien Gralla13d7202015-08-07 17:34:41 +0100123int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
Ian Campbellde1ef202009-05-21 10:09:46 +0100124 unsigned long addr,
David Vrabel4e8c0c82015-03-11 14:49:57 +0000125 xen_pfn_t gfn, int nr,
Ian Campbell9a032e392012-10-17 13:37:49 -0700126 pgprot_t prot, unsigned domid,
127 struct page **pages);
Julien Gralla13d7202015-08-07 17:34:41 +0100128int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
Ian Campbell9a032e392012-10-17 13:37:49 -0700129 int numpgs, struct page **pages);
Paul Durrantec4001c2017-11-03 17:04:11 +0000130
131#ifdef CONFIG_XEN_AUTO_XLATE
David Vrabel4e8c0c82015-03-11 14:49:57 +0000132int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
David Vrabel628c28e2015-03-11 14:49:56 +0000133 unsigned long addr,
David Vrabel4e8c0c82015-03-11 14:49:57 +0000134 xen_pfn_t *gfn, int nr,
135 int *err_ptr, pgprot_t prot,
David Vrabel628c28e2015-03-11 14:49:56 +0000136 unsigned domid,
137 struct page **pages);
138int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma,
139 int nr, struct page **pages);
Paul Durrantec4001c2017-11-03 17:04:11 +0000140#else
141/*
142 * These two functions are called from arch/x86/xen/mmu.c and so stubs
143 * are needed for a configuration not specifying CONFIG_XEN_AUTO_XLATE.
144 */
145static inline int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
146 unsigned long addr,
147 xen_pfn_t *gfn, int nr,
148 int *err_ptr, pgprot_t prot,
149 unsigned int domid,
150 struct page **pages)
151{
152 return -EOPNOTSUPP;
153}
154
155static inline int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma,
156 int nr, struct page **pages)
157{
158 return -EOPNOTSUPP;
159}
160#endif
161
Shannon Zhao243848f2016-04-07 20:03:19 +0800162int xen_xlate_map_ballooned_pages(xen_pfn_t **pfns, void **vaddr,
163 unsigned long nr_grant_frames);
Ian Campbellde1ef202009-05-21 10:09:46 +0100164
Konrad Rzeszutek Wilk394b40f2012-11-27 11:39:40 -0500165bool xen_running_on_version_or_later(unsigned int major, unsigned int minor);
Daniel Kiperbe81c8a2014-06-30 19:53:02 +0200166
Shannon Zhaoa62ed502016-04-07 20:03:31 +0800167efi_status_t xen_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc);
168efi_status_t xen_efi_set_time(efi_time_t *tm);
169efi_status_t xen_efi_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
170 efi_time_t *tm);
171efi_status_t xen_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm);
172efi_status_t xen_efi_get_variable(efi_char16_t *name, efi_guid_t *vendor,
173 u32 *attr, unsigned long *data_size,
174 void *data);
175efi_status_t xen_efi_get_next_variable(unsigned long *name_size,
176 efi_char16_t *name, efi_guid_t *vendor);
177efi_status_t xen_efi_set_variable(efi_char16_t *name, efi_guid_t *vendor,
178 u32 attr, unsigned long data_size,
179 void *data);
180efi_status_t xen_efi_query_variable_info(u32 attr, u64 *storage_space,
181 u64 *remaining_space,
182 u64 *max_variable_size);
183efi_status_t xen_efi_get_next_high_mono_count(u32 *count);
184efi_status_t xen_efi_update_capsule(efi_capsule_header_t **capsules,
185 unsigned long count, unsigned long sg_list);
186efi_status_t xen_efi_query_capsule_caps(efi_capsule_header_t **capsules,
187 unsigned long count, u64 *max_size,
188 int *reset_type);
Julien Gralle371fd72017-04-24 18:58:39 +0100189void xen_efi_reset_system(int reset_type, efi_status_t status,
190 unsigned long data_size, efi_char16_t *data);
191
Daniel Kiperbe81c8a2014-06-30 19:53:02 +0200192
David Vrabelfdfd8112015-02-19 15:23:17 +0000193#ifdef CONFIG_PREEMPT
194
195static inline void xen_preemptible_hcall_begin(void)
196{
197}
198
199static inline void xen_preemptible_hcall_end(void)
200{
201}
202
203#else
204
205DECLARE_PER_CPU(bool, xen_in_preemptible_hcall);
206
207static inline void xen_preemptible_hcall_begin(void)
208{
209 __this_cpu_write(xen_in_preemptible_hcall, true);
210}
211
212static inline void xen_preemptible_hcall_end(void)
213{
214 __this_cpu_write(xen_in_preemptible_hcall, false);
215}
216
217#endif /* CONFIG_PREEMPT */
218
Isaku Yamahatae04d0d02008-04-02 10:53:55 -0700219#endif /* INCLUDE_XEN_OPS_H */