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