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