xen: introduce xen_vcpu_id mapping
[cascardo/linux.git] / include / xen / xen-ops.h
1 #ifndef INCLUDE_XEN_OPS_H
2 #define INCLUDE_XEN_OPS_H
3
4 #include <linux/percpu.h>
5 #include <linux/notifier.h>
6 #include <linux/efi.h>
7 #include <asm/xen/interface.h>
8 #include <xen/interface/vcpu.h>
9
10 DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu);
11
12 DECLARE_PER_CPU(int, xen_vcpu_id);
13 static inline int xen_vcpu_nr(int cpu)
14 {
15         return per_cpu(xen_vcpu_id, cpu);
16 }
17
18 void xen_arch_pre_suspend(void);
19 void xen_arch_post_suspend(int suspend_cancelled);
20
21 void xen_timer_resume(void);
22 void xen_arch_resume(void);
23 void xen_arch_suspend(void);
24
25 void xen_resume_notifier_register(struct notifier_block *nb);
26 void xen_resume_notifier_unregister(struct notifier_block *nb);
27
28 bool xen_vcpu_stolen(int vcpu);
29 void xen_setup_runstate_info(int cpu);
30 void xen_time_setup_guest(void);
31 void xen_get_runstate_snapshot(struct vcpu_runstate_info *res);
32
33 int xen_setup_shutdown_event(void);
34
35 extern unsigned long *xen_contiguous_bitmap;
36 int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
37                                 unsigned int address_bits,
38                                 dma_addr_t *dma_handle);
39
40 void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order);
41
42 struct vm_area_struct;
43
44 /*
45  * xen_remap_domain_gfn_array() - map an array of foreign frames
46  * @vma:     VMA to map the pages into
47  * @addr:    Address at which to map the pages
48  * @gfn:     Array of GFNs to map
49  * @nr:      Number entries in the GFN array
50  * @err_ptr: Returns per-GFN error status.
51  * @prot:    page protection mask
52  * @domid:   Domain owning the pages
53  * @pages:   Array of pages if this domain has an auto-translated physmap
54  *
55  * @gfn and @err_ptr may point to the same buffer, the GFNs will be
56  * overwritten by the error codes after they are mapped.
57  *
58  * Returns the number of successfully mapped frames, or a -ve error
59  * code.
60  */
61 int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
62                                unsigned long addr,
63                                xen_pfn_t *gfn, int nr,
64                                int *err_ptr, pgprot_t prot,
65                                unsigned domid,
66                                struct page **pages);
67
68 /* xen_remap_domain_gfn_range() - map a range of foreign frames
69  * @vma:     VMA to map the pages into
70  * @addr:    Address at which to map the pages
71  * @gfn:     First GFN to map.
72  * @nr:      Number frames to map
73  * @prot:    page protection mask
74  * @domid:   Domain owning the pages
75  * @pages:   Array of pages if this domain has an auto-translated physmap
76  *
77  * Returns the number of successfully mapped frames, or a -ve error
78  * code.
79  */
80 int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
81                                unsigned long addr,
82                                xen_pfn_t gfn, int nr,
83                                pgprot_t prot, unsigned domid,
84                                struct page **pages);
85 int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
86                                int numpgs, struct page **pages);
87 int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
88                               unsigned long addr,
89                               xen_pfn_t *gfn, int nr,
90                               int *err_ptr, pgprot_t prot,
91                               unsigned domid,
92                               struct page **pages);
93 int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma,
94                               int nr, struct page **pages);
95 int xen_xlate_map_ballooned_pages(xen_pfn_t **pfns, void **vaddr,
96                                   unsigned long nr_grant_frames);
97
98 bool xen_running_on_version_or_later(unsigned int major, unsigned int minor);
99
100 efi_status_t xen_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc);
101 efi_status_t xen_efi_set_time(efi_time_t *tm);
102 efi_status_t xen_efi_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
103                                      efi_time_t *tm);
104 efi_status_t xen_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm);
105 efi_status_t xen_efi_get_variable(efi_char16_t *name, efi_guid_t *vendor,
106                                   u32 *attr, unsigned long *data_size,
107                                   void *data);
108 efi_status_t xen_efi_get_next_variable(unsigned long *name_size,
109                                        efi_char16_t *name, efi_guid_t *vendor);
110 efi_status_t xen_efi_set_variable(efi_char16_t *name, efi_guid_t *vendor,
111                                   u32 attr, unsigned long data_size,
112                                   void *data);
113 efi_status_t xen_efi_query_variable_info(u32 attr, u64 *storage_space,
114                                          u64 *remaining_space,
115                                          u64 *max_variable_size);
116 efi_status_t xen_efi_get_next_high_mono_count(u32 *count);
117 efi_status_t xen_efi_update_capsule(efi_capsule_header_t **capsules,
118                                     unsigned long count, unsigned long sg_list);
119 efi_status_t xen_efi_query_capsule_caps(efi_capsule_header_t **capsules,
120                                         unsigned long count, u64 *max_size,
121                                         int *reset_type);
122
123 #ifdef CONFIG_PREEMPT
124
125 static inline void xen_preemptible_hcall_begin(void)
126 {
127 }
128
129 static inline void xen_preemptible_hcall_end(void)
130 {
131 }
132
133 #else
134
135 DECLARE_PER_CPU(bool, xen_in_preemptible_hcall);
136
137 static inline void xen_preemptible_hcall_begin(void)
138 {
139         __this_cpu_write(xen_in_preemptible_hcall, true);
140 }
141
142 static inline void xen_preemptible_hcall_end(void)
143 {
144         __this_cpu_write(xen_in_preemptible_hcall, false);
145 }
146
147 #endif /* CONFIG_PREEMPT */
148
149 #endif /* INCLUDE_XEN_OPS_H */