]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/arm/xen/enlighten.c
arm: extend pvclock_wall_clock with sec_hi
[mirror_ubuntu-artful-kernel.git] / arch / arm / xen / enlighten.c
CommitLineData
4c071ee5 1#include <xen/xen.h>
0ec53ecf 2#include <xen/events.h>
b3b52fd8
SS
3#include <xen/grant_table.h>
4#include <xen/hvm.h>
9a9ab3cc 5#include <xen/interface/vcpu.h>
4c071ee5
SS
6#include <xen/interface/xen.h>
7#include <xen/interface/memory.h>
b3b52fd8 8#include <xen/interface/hvm/params.h>
ef61ee0d 9#include <xen/features.h>
4c071ee5 10#include <xen/platform_pci.h>
b3b52fd8 11#include <xen/xenbus.h>
c61ba729 12#include <xen/page.h>
6abb749e 13#include <xen/interface/sched.h>
f832da06 14#include <xen/xen-ops.h>
34e38523 15#include <asm/paravirt.h>
4c071ee5
SS
16#include <asm/xen/hypervisor.h>
17#include <asm/xen/hypercall.h>
6abb749e 18#include <asm/system_misc.h>
0ec53ecf
SS
19#include <linux/interrupt.h>
20#include <linux/irqreturn.h>
4c071ee5 21#include <linux/module.h>
2e01f166
SS
22#include <linux/of.h>
23#include <linux/of_irq.h>
24#include <linux/of_address.h>
e1a9c16b
JG
25#include <linux/cpuidle.h>
26#include <linux/cpufreq.h>
8b271d57 27#include <linux/cpu.h>
f1dddd11 28#include <linux/console.h>
4c071ee5 29
f832da06
IC
30#include <linux/mm.h>
31
4c071ee5
SS
32struct start_info _xen_start_info;
33struct start_info *xen_start_info = &_xen_start_info;
35c8ab4c 34EXPORT_SYMBOL(xen_start_info);
4c071ee5
SS
35
36enum xen_domain_type xen_domain_type = XEN_NATIVE;
35c8ab4c 37EXPORT_SYMBOL(xen_domain_type);
4c071ee5
SS
38
39struct shared_info xen_dummy_shared_info;
40struct shared_info *HYPERVISOR_shared_info = (void *)&xen_dummy_shared_info;
41
42DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
9a9ab3cc 43static struct vcpu_info __percpu *xen_vcpu_info;
4c071ee5 44
c61ba729
IC
45/* These are unused until we support booting "pre-ballooned" */
46unsigned long xen_released_pages;
47struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
48
81e863c3 49static __read_mostly unsigned int xen_events_irq;
0ec53ecf 50
5882bfef
SS
51static __initdata struct device_node *xen_node;
52
a13d7201 53int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
4c071ee5 54 unsigned long addr,
a13d7201 55 xen_pfn_t *gfn, int nr,
4e8c0c8c
DV
56 int *err_ptr, pgprot_t prot,
57 unsigned domid,
f832da06 58 struct page **pages)
4c071ee5 59{
a13d7201 60 return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
628c28ee 61 prot, domid, pages);
4c071ee5 62}
a13d7201 63EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_array);
4e8c0c8c
DV
64
65/* Not used by XENFEAT_auto_translated guests. */
a13d7201 66int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
4e8c0c8c 67 unsigned long addr,
a13d7201 68 xen_pfn_t gfn, int nr,
4e8c0c8c
DV
69 pgprot_t prot, unsigned domid,
70 struct page **pages)
71{
72 return -ENOSYS;
73}
a13d7201 74EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range);
2e01f166 75
a13d7201 76int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
f832da06
IC
77 int nr, struct page **pages)
78{
628c28ee 79 return xen_xlate_unmap_gfn_range(vma, nr, pages);
f832da06 80}
a13d7201 81EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range);
f832da06 82
34e38523
SS
83static unsigned long long xen_stolen_accounting(int cpu)
84{
85 struct vcpu_runstate_info state;
86
87 BUG_ON(cpu != smp_processor_id());
88
89 xen_get_runstate_snapshot(&state);
90
91 WARN_ON(state.state != RUNSTATE_running);
92
93 return state.time[RUNSTATE_runnable] + state.time[RUNSTATE_offline];
94}
95
8b271d57 96static void xen_percpu_init(void)
9a9ab3cc
SS
97{
98 struct vcpu_register_vcpu_info info;
99 struct vcpu_info *vcpup;
100 int err;
3cc8e40e 101 int cpu = get_cpu();
9a9ab3cc 102
cb9644bf
SS
103 /*
104 * VCPUOP_register_vcpu_info cannot be called twice for the same
105 * vcpu, so if vcpu_info is already registered, just get out. This
106 * can happen with cpu-hotplug.
107 */
108 if (per_cpu(xen_vcpu, cpu) != NULL)
109 goto after_register_vcpu_info;
110
9a9ab3cc
SS
111 pr_info("Xen: initializing cpu%d\n", cpu);
112 vcpup = per_cpu_ptr(xen_vcpu_info, cpu);
113
250c9af3
JG
114 info.mfn = virt_to_gfn(vcpup);
115 info.offset = xen_offset_in_page(vcpup);
9a9ab3cc
SS
116
117 err = HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_info, cpu, &info);
d7266d78
SS
118 BUG_ON(err);
119 per_cpu(xen_vcpu, cpu) = vcpup;
120
34e38523
SS
121 xen_setup_runstate_info(cpu);
122
cb9644bf 123after_register_vcpu_info:
3cc8e40e 124 enable_percpu_irq(xen_events_irq, 0);
0d7febe5 125 put_cpu();
9a9ab3cc
SS
126}
127
2451ade0 128static void xen_restart(enum reboot_mode reboot_mode, const char *cmd)
6abb749e
SS
129{
130 struct sched_shutdown r = { .reason = SHUTDOWN_reboot };
131 int rc;
132 rc = HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
a91c7775 133 BUG_ON(rc);
6abb749e
SS
134}
135
136static void xen_power_off(void)
137{
138 struct sched_shutdown r = { .reason = SHUTDOWN_poweroff };
139 int rc;
140 rc = HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
a91c7775 141 BUG_ON(rc);
6abb749e
SS
142}
143
8b271d57
JG
144static int xen_cpu_notification(struct notifier_block *self,
145 unsigned long action,
146 void *hcpu)
147{
148 switch (action) {
149 case CPU_STARTING:
150 xen_percpu_init();
151 break;
cb9644bf
SS
152 case CPU_DYING:
153 disable_percpu_irq(xen_events_irq);
154 break;
8b271d57
JG
155 default:
156 break;
157 }
158
159 return NOTIFY_OK;
160}
161
162static struct notifier_block xen_cpu_notifier = {
163 .notifier_call = xen_cpu_notification,
164};
165
166static irqreturn_t xen_arm_callback(int irq, void *arg)
167{
168 xen_hvm_evtchn_do_upcall();
169 return IRQ_HANDLED;
170}
171
2e01f166
SS
172/*
173 * see Documentation/devicetree/bindings/arm/xen.txt for the
174 * documentation of the Xen Device Tree format.
175 */
b3b52fd8 176#define GRANT_TABLE_PHYSADDR 0
5882bfef 177void __init xen_early_init(void)
2e01f166 178{
2e01f166
SS
179 int len;
180 const char *s = NULL;
181 const char *version = NULL;
182 const char *xen_prefix = "xen,xen-";
183
5882bfef
SS
184 xen_node = of_find_compatible_node(NULL, NULL, "xen,xen");
185 if (!xen_node) {
2e01f166 186 pr_debug("No Xen support\n");
5882bfef 187 return;
2e01f166 188 }
5882bfef 189 s = of_get_property(xen_node, "compatible", &len);
2e01f166
SS
190 if (strlen(xen_prefix) + 3 < len &&
191 !strncmp(xen_prefix, s, strlen(xen_prefix)))
192 version = s + strlen(xen_prefix);
193 if (version == NULL) {
194 pr_debug("Xen version not found\n");
5882bfef 195 return;
81e863c3
JG
196 }
197
5882bfef 198 pr_info("Xen %s support found\n", version);
8b271d57 199
2e01f166
SS
200 xen_domain_type = XEN_HVM_DOMAIN;
201
ef61ee0d 202 xen_setup_features();
5ebc77de 203
ef61ee0d
SS
204 if (xen_feature(XENFEAT_dom0))
205 xen_start_info->flags |= SIF_INITDOMAIN|SIF_PRIVILEGED;
206 else
207 xen_start_info->flags &= ~(SIF_INITDOMAIN|SIF_PRIVILEGED);
f1dddd11
AB
208
209 if (!console_set_on_cmdline && !xen_initial_domain())
210 add_preferred_console("hvc", 0, NULL);
5882bfef
SS
211}
212
213static int __init xen_guest_init(void)
214{
215 struct xen_add_to_physmap xatp;
216 struct shared_info *shared_info_page = NULL;
217 struct resource res;
218 phys_addr_t grant_frames;
219
220 if (!xen_domain())
221 return 0;
222
223 if (of_address_to_resource(xen_node, GRANT_TABLE_PHYSADDR, &res)) {
224 pr_err("Xen grant table base address not found\n");
225 return -ENODEV;
226 }
227 grant_frames = res.start;
228
229 xen_events_irq = irq_of_parse_and_map(xen_node, 0);
230 if (!xen_events_irq) {
231 pr_err("Xen event channel interrupt not found\n");
232 return -ENODEV;
233 }
234
235 shared_info_page = (struct shared_info *)get_zeroed_page(GFP_KERNEL);
ef61ee0d 236
2e01f166
SS
237 if (!shared_info_page) {
238 pr_err("not enough memory\n");
239 return -ENOMEM;
240 }
241 xatp.domid = DOMID_SELF;
242 xatp.idx = 0;
243 xatp.space = XENMAPSPACE_shared_info;
250c9af3 244 xatp.gpfn = virt_to_gfn(shared_info_page);
2e01f166
SS
245 if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
246 BUG();
247
248 HYPERVISOR_shared_info = (struct shared_info *)shared_info_page;
249
250 /* xen_vcpu is a pointer to the vcpu_info struct in the shared_info
251 * page, we use it in the event channel upcall and in some pvclock
9a9ab3cc 252 * related functions.
2e01f166
SS
253 * The shared info contains exactly 1 CPU (the boot CPU). The guest
254 * is required to use VCPUOP_register_vcpu_info to place vcpu info
9a9ab3cc
SS
255 * for secondary CPUs as they are brought up.
256 * For uniformity we use VCPUOP_register_vcpu_info even on cpu0.
257 */
258 xen_vcpu_info = __alloc_percpu(sizeof(struct vcpu_info),
259 sizeof(struct vcpu_info));
260 if (xen_vcpu_info == NULL)
261 return -ENOMEM;
b3b52fd8 262
efaf30a3
KRW
263 if (gnttab_setup_auto_xlat_frames(grant_frames)) {
264 free_percpu(xen_vcpu_info);
265 return -ENOMEM;
266 }
b3b52fd8
SS
267 gnttab_init();
268 if (!xen_initial_domain())
269 xenbus_probe(NULL);
270
e1a9c16b
JG
271 /*
272 * Making sure board specific code will not set up ops for
273 * cpu idle and cpu freq.
274 */
275 disable_cpuidle();
276 disable_cpufreq();
277
8b271d57
JG
278 xen_init_IRQ();
279
280 if (request_percpu_irq(xen_events_irq, xen_arm_callback,
281 "events", &xen_vcpu)) {
282 pr_err("Error request IRQ %d\n", xen_events_irq);
283 return -EINVAL;
284 }
285
286 xen_percpu_init();
287
288 register_cpu_notifier(&xen_cpu_notifier);
289
34e38523
SS
290 pv_time_ops.steal_clock = xen_stolen_accounting;
291 static_key_slow_inc(&paravirt_steal_enabled);
292
1aa3d8d9
SS
293 return 0;
294}
8b271d57 295early_initcall(xen_guest_init);
1aa3d8d9
SS
296
297static int __init xen_pm_init(void)
298{
9dd4b294
RH
299 if (!xen_domain())
300 return -ENODEV;
301
6abb749e
SS
302 pm_power_off = xen_power_off;
303 arm_pm_restart = xen_restart;
304
2e01f166
SS
305 return 0;
306}
9dd4b294 307late_initcall(xen_pm_init);
0ec53ecf 308
79390289
SS
309
310/* empty stubs */
311void xen_arch_pre_suspend(void) { }
312void xen_arch_post_suspend(int suspend_cancelled) { }
313void xen_timer_resume(void) { }
314void xen_arch_resume(void) { }
ffb7dbed 315void xen_arch_suspend(void) { }
79390289
SS
316
317
d5f985c8 318/* In the hypercall.S file. */
911dec0d
KRW
319EXPORT_SYMBOL_GPL(HYPERVISOR_event_channel_op);
320EXPORT_SYMBOL_GPL(HYPERVISOR_grant_table_op);
ab277bbf
SS
321EXPORT_SYMBOL_GPL(HYPERVISOR_xen_version);
322EXPORT_SYMBOL_GPL(HYPERVISOR_console_io);
323EXPORT_SYMBOL_GPL(HYPERVISOR_sched_op);
324EXPORT_SYMBOL_GPL(HYPERVISOR_hvm_op);
325EXPORT_SYMBOL_GPL(HYPERVISOR_memory_op);
326EXPORT_SYMBOL_GPL(HYPERVISOR_physdev_op);
ea0af613 327EXPORT_SYMBOL_GPL(HYPERVISOR_vcpu_op);
176455e9 328EXPORT_SYMBOL_GPL(HYPERVISOR_tmem_op);
72d39c69 329EXPORT_SYMBOL_GPL(HYPERVISOR_platform_op);
9f1d3414 330EXPORT_SYMBOL_GPL(HYPERVISOR_multicall);
911dec0d 331EXPORT_SYMBOL_GPL(privcmd_call);