blob: ba5cc134a7d3e954ec15c0b98fb54cbbc2878658 [file] [log] [blame]
Stefano Stabellini4c071ee2012-09-14 13:53:39 +00001#include <xen/xen.h>
Stefano Stabellini0ec53ec2012-09-14 13:37:32 +00002#include <xen/events.h>
Stefano Stabellinib3b52fd2012-09-13 12:06:52 +00003#include <xen/grant_table.h>
4#include <xen/hvm.h>
Stefano Stabellini4c071ee2012-09-14 13:53:39 +00005#include <xen/interface/xen.h>
6#include <xen/interface/memory.h>
Stefano Stabellinib3b52fd2012-09-13 12:06:52 +00007#include <xen/interface/hvm/params.h>
Stefano Stabellinief61ee0d2012-08-08 17:20:18 +00008#include <xen/features.h>
Stefano Stabellini4c071ee2012-09-14 13:53:39 +00009#include <xen/platform_pci.h>
Stefano Stabellinib3b52fd2012-09-13 12:06:52 +000010#include <xen/xenbus.h>
Ian Campbellc61ba722012-10-03 12:28:26 +010011#include <xen/page.h>
Stefano Stabellini4c071ee2012-09-14 13:53:39 +000012#include <asm/xen/hypervisor.h>
13#include <asm/xen/hypercall.h>
Stefano Stabellini0ec53ec2012-09-14 13:37:32 +000014#include <linux/interrupt.h>
15#include <linux/irqreturn.h>
Stefano Stabellini4c071ee2012-09-14 13:53:39 +000016#include <linux/module.h>
Stefano Stabellini2e01f162012-09-14 10:47:52 +000017#include <linux/of.h>
18#include <linux/of_irq.h>
19#include <linux/of_address.h>
Stefano Stabellini4c071ee2012-09-14 13:53:39 +000020
21struct start_info _xen_start_info;
22struct start_info *xen_start_info = &_xen_start_info;
23EXPORT_SYMBOL_GPL(xen_start_info);
24
25enum xen_domain_type xen_domain_type = XEN_NATIVE;
26EXPORT_SYMBOL_GPL(xen_domain_type);
27
28struct shared_info xen_dummy_shared_info;
29struct shared_info *HYPERVISOR_shared_info = (void *)&xen_dummy_shared_info;
30
31DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
32
Ian Campbellc61ba722012-10-03 12:28:26 +010033/* These are unused until we support booting "pre-ballooned" */
34unsigned long xen_released_pages;
35struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
36
Stefano Stabellini4c071ee2012-09-14 13:53:39 +000037/* TODO: to be removed */
38__read_mostly int xen_have_vector_callback;
39EXPORT_SYMBOL_GPL(xen_have_vector_callback);
40
41int xen_platform_pci_unplug = XEN_UNPLUG_ALL;
42EXPORT_SYMBOL_GPL(xen_platform_pci_unplug);
43
Stefano Stabellini0ec53ec2012-09-14 13:37:32 +000044static __read_mostly int xen_events_irq = -1;
45
Stefano Stabellini4c071ee2012-09-14 13:53:39 +000046int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
47 unsigned long addr,
48 unsigned long mfn, int nr,
49 pgprot_t prot, unsigned domid)
50{
51 return -ENOSYS;
52}
53EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
Stefano Stabellini2e01f162012-09-14 10:47:52 +000054
55/*
56 * see Documentation/devicetree/bindings/arm/xen.txt for the
57 * documentation of the Xen Device Tree format.
58 */
Stefano Stabellinib3b52fd2012-09-13 12:06:52 +000059#define GRANT_TABLE_PHYSADDR 0
Stefano Stabellini2e01f162012-09-14 10:47:52 +000060static int __init xen_guest_init(void)
61{
62 struct xen_add_to_physmap xatp;
63 static struct shared_info *shared_info_page = 0;
64 struct device_node *node;
65 int len;
66 const char *s = NULL;
67 const char *version = NULL;
68 const char *xen_prefix = "xen,xen-";
Stefano Stabellinib3b52fd2012-09-13 12:06:52 +000069 struct resource res;
Stefano Stabellini2e01f162012-09-14 10:47:52 +000070
71 node = of_find_compatible_node(NULL, NULL, "xen,xen");
72 if (!node) {
73 pr_debug("No Xen support\n");
74 return 0;
75 }
76 s = of_get_property(node, "compatible", &len);
77 if (strlen(xen_prefix) + 3 < len &&
78 !strncmp(xen_prefix, s, strlen(xen_prefix)))
79 version = s + strlen(xen_prefix);
80 if (version == NULL) {
81 pr_debug("Xen version not found\n");
82 return 0;
83 }
Stefano Stabellinib3b52fd2012-09-13 12:06:52 +000084 if (of_address_to_resource(node, GRANT_TABLE_PHYSADDR, &res))
85 return 0;
86 xen_hvm_resume_frames = res.start >> PAGE_SHIFT;
Stefano Stabellini0ec53ec2012-09-14 13:37:32 +000087 xen_events_irq = irq_of_parse_and_map(node, 0);
88 pr_info("Xen %s support found, events_irq=%d gnttab_frame_pfn=%lx\n",
89 version, xen_events_irq, xen_hvm_resume_frames);
Stefano Stabellini2e01f162012-09-14 10:47:52 +000090 xen_domain_type = XEN_HVM_DOMAIN;
91
Stefano Stabellinief61ee0d2012-08-08 17:20:18 +000092 xen_setup_features();
93 if (xen_feature(XENFEAT_dom0))
94 xen_start_info->flags |= SIF_INITDOMAIN|SIF_PRIVILEGED;
95 else
96 xen_start_info->flags &= ~(SIF_INITDOMAIN|SIF_PRIVILEGED);
97
Stefano Stabellini2e01f162012-09-14 10:47:52 +000098 if (!shared_info_page)
99 shared_info_page = (struct shared_info *)
100 get_zeroed_page(GFP_KERNEL);
101 if (!shared_info_page) {
102 pr_err("not enough memory\n");
103 return -ENOMEM;
104 }
105 xatp.domid = DOMID_SELF;
106 xatp.idx = 0;
107 xatp.space = XENMAPSPACE_shared_info;
108 xatp.gpfn = __pa(shared_info_page) >> PAGE_SHIFT;
109 if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
110 BUG();
111
112 HYPERVISOR_shared_info = (struct shared_info *)shared_info_page;
113
114 /* xen_vcpu is a pointer to the vcpu_info struct in the shared_info
115 * page, we use it in the event channel upcall and in some pvclock
116 * related functions. We don't need the vcpu_info placement
117 * optimizations because we don't use any pv_mmu or pv_irq op on
118 * HVM.
119 * The shared info contains exactly 1 CPU (the boot CPU). The guest
120 * is required to use VCPUOP_register_vcpu_info to place vcpu info
121 * for secondary CPUs as they are brought up. */
122 per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0];
Stefano Stabellinib3b52fd2012-09-13 12:06:52 +0000123
124 gnttab_init();
125 if (!xen_initial_domain())
126 xenbus_probe(NULL);
127
Stefano Stabellini2e01f162012-09-14 10:47:52 +0000128 return 0;
129}
130core_initcall(xen_guest_init);
Stefano Stabellini0ec53ec2012-09-14 13:37:32 +0000131
132static irqreturn_t xen_arm_callback(int irq, void *arg)
133{
134 xen_hvm_evtchn_do_upcall();
135 return IRQ_HANDLED;
136}
137
138static int __init xen_init_events(void)
139{
140 if (!xen_domain() || xen_events_irq < 0)
141 return -ENODEV;
142
143 xen_init_IRQ();
144
145 if (request_percpu_irq(xen_events_irq, xen_arm_callback,
146 "events", xen_vcpu)) {
147 pr_err("Error requesting IRQ %d\n", xen_events_irq);
148 return -EINVAL;
149 }
150
151 enable_percpu_irq(xen_events_irq, 0);
152
153 return 0;
154}
155postcore_initcall(xen_init_events);