blob: 6a0217d4e6620a6b5ae630d55a169de9df222b34 [file] [log] [blame]
Stefano Stabellini4c071ee2012-09-14 13:53:39 +00001#include <xen/xen.h>
2#include <xen/interface/xen.h>
3#include <xen/interface/memory.h>
4#include <xen/platform_pci.h>
5#include <asm/xen/hypervisor.h>
6#include <asm/xen/hypercall.h>
7#include <linux/module.h>
Stefano Stabellini2e01f162012-09-14 10:47:52 +00008#include <linux/of.h>
9#include <linux/of_irq.h>
10#include <linux/of_address.h>
Stefano Stabellini4c071ee2012-09-14 13:53:39 +000011
12struct start_info _xen_start_info;
13struct start_info *xen_start_info = &_xen_start_info;
14EXPORT_SYMBOL_GPL(xen_start_info);
15
16enum xen_domain_type xen_domain_type = XEN_NATIVE;
17EXPORT_SYMBOL_GPL(xen_domain_type);
18
19struct shared_info xen_dummy_shared_info;
20struct shared_info *HYPERVISOR_shared_info = (void *)&xen_dummy_shared_info;
21
22DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
23
24/* TODO: to be removed */
25__read_mostly int xen_have_vector_callback;
26EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27
28int xen_platform_pci_unplug = XEN_UNPLUG_ALL;
29EXPORT_SYMBOL_GPL(xen_platform_pci_unplug);
30
31int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
32 unsigned long addr,
33 unsigned long mfn, int nr,
34 pgprot_t prot, unsigned domid)
35{
36 return -ENOSYS;
37}
38EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
Stefano Stabellini2e01f162012-09-14 10:47:52 +000039
40/*
41 * see Documentation/devicetree/bindings/arm/xen.txt for the
42 * documentation of the Xen Device Tree format.
43 */
44static int __init xen_guest_init(void)
45{
46 struct xen_add_to_physmap xatp;
47 static struct shared_info *shared_info_page = 0;
48 struct device_node *node;
49 int len;
50 const char *s = NULL;
51 const char *version = NULL;
52 const char *xen_prefix = "xen,xen-";
53
54 node = of_find_compatible_node(NULL, NULL, "xen,xen");
55 if (!node) {
56 pr_debug("No Xen support\n");
57 return 0;
58 }
59 s = of_get_property(node, "compatible", &len);
60 if (strlen(xen_prefix) + 3 < len &&
61 !strncmp(xen_prefix, s, strlen(xen_prefix)))
62 version = s + strlen(xen_prefix);
63 if (version == NULL) {
64 pr_debug("Xen version not found\n");
65 return 0;
66 }
67 xen_domain_type = XEN_HVM_DOMAIN;
68
69 if (!shared_info_page)
70 shared_info_page = (struct shared_info *)
71 get_zeroed_page(GFP_KERNEL);
72 if (!shared_info_page) {
73 pr_err("not enough memory\n");
74 return -ENOMEM;
75 }
76 xatp.domid = DOMID_SELF;
77 xatp.idx = 0;
78 xatp.space = XENMAPSPACE_shared_info;
79 xatp.gpfn = __pa(shared_info_page) >> PAGE_SHIFT;
80 if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
81 BUG();
82
83 HYPERVISOR_shared_info = (struct shared_info *)shared_info_page;
84
85 /* xen_vcpu is a pointer to the vcpu_info struct in the shared_info
86 * page, we use it in the event channel upcall and in some pvclock
87 * related functions. We don't need the vcpu_info placement
88 * optimizations because we don't use any pv_mmu or pv_irq op on
89 * HVM.
90 * The shared info contains exactly 1 CPU (the boot CPU). The guest
91 * is required to use VCPUOP_register_vcpu_info to place vcpu info
92 * for secondary CPUs as they are brought up. */
93 per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0];
94 return 0;
95}
96core_initcall(xen_guest_init);