enlighten.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include <xen/xen.h>
  2. #include <xen/events.h>
  3. #include <xen/grant_table.h>
  4. #include <xen/hvm.h>
  5. #include <xen/interface/xen.h>
  6. #include <xen/interface/memory.h>
  7. #include <xen/interface/hvm/params.h>
  8. #include <xen/features.h>
  9. #include <xen/platform_pci.h>
  10. #include <xen/xenbus.h>
  11. #include <xen/page.h>
  12. #include <asm/xen/hypervisor.h>
  13. #include <asm/xen/hypercall.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/irqreturn.h>
  16. #include <linux/module.h>
  17. #include <linux/of.h>
  18. #include <linux/of_irq.h>
  19. #include <linux/of_address.h>
  20. struct start_info _xen_start_info;
  21. struct start_info *xen_start_info = &_xen_start_info;
  22. EXPORT_SYMBOL_GPL(xen_start_info);
  23. enum xen_domain_type xen_domain_type = XEN_NATIVE;
  24. EXPORT_SYMBOL_GPL(xen_domain_type);
  25. struct shared_info xen_dummy_shared_info;
  26. struct shared_info *HYPERVISOR_shared_info = (void *)&xen_dummy_shared_info;
  27. DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
  28. /* These are unused until we support booting "pre-ballooned" */
  29. unsigned long xen_released_pages;
  30. struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
  31. /* TODO: to be removed */
  32. __read_mostly int xen_have_vector_callback;
  33. EXPORT_SYMBOL_GPL(xen_have_vector_callback);
  34. int xen_platform_pci_unplug = XEN_UNPLUG_ALL;
  35. EXPORT_SYMBOL_GPL(xen_platform_pci_unplug);
  36. static __read_mostly int xen_events_irq = -1;
  37. int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
  38. unsigned long addr,
  39. unsigned long mfn, int nr,
  40. pgprot_t prot, unsigned domid)
  41. {
  42. return -ENOSYS;
  43. }
  44. EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
  45. /*
  46. * see Documentation/devicetree/bindings/arm/xen.txt for the
  47. * documentation of the Xen Device Tree format.
  48. */
  49. #define GRANT_TABLE_PHYSADDR 0
  50. static int __init xen_guest_init(void)
  51. {
  52. struct xen_add_to_physmap xatp;
  53. static struct shared_info *shared_info_page = 0;
  54. struct device_node *node;
  55. int len;
  56. const char *s = NULL;
  57. const char *version = NULL;
  58. const char *xen_prefix = "xen,xen-";
  59. struct resource res;
  60. node = of_find_compatible_node(NULL, NULL, "xen,xen");
  61. if (!node) {
  62. pr_debug("No Xen support\n");
  63. return 0;
  64. }
  65. s = of_get_property(node, "compatible", &len);
  66. if (strlen(xen_prefix) + 3 < len &&
  67. !strncmp(xen_prefix, s, strlen(xen_prefix)))
  68. version = s + strlen(xen_prefix);
  69. if (version == NULL) {
  70. pr_debug("Xen version not found\n");
  71. return 0;
  72. }
  73. if (of_address_to_resource(node, GRANT_TABLE_PHYSADDR, &res))
  74. return 0;
  75. xen_hvm_resume_frames = res.start >> PAGE_SHIFT;
  76. xen_events_irq = irq_of_parse_and_map(node, 0);
  77. pr_info("Xen %s support found, events_irq=%d gnttab_frame_pfn=%lx\n",
  78. version, xen_events_irq, xen_hvm_resume_frames);
  79. xen_domain_type = XEN_HVM_DOMAIN;
  80. xen_setup_features();
  81. if (xen_feature(XENFEAT_dom0))
  82. xen_start_info->flags |= SIF_INITDOMAIN|SIF_PRIVILEGED;
  83. else
  84. xen_start_info->flags &= ~(SIF_INITDOMAIN|SIF_PRIVILEGED);
  85. if (!shared_info_page)
  86. shared_info_page = (struct shared_info *)
  87. get_zeroed_page(GFP_KERNEL);
  88. if (!shared_info_page) {
  89. pr_err("not enough memory\n");
  90. return -ENOMEM;
  91. }
  92. xatp.domid = DOMID_SELF;
  93. xatp.idx = 0;
  94. xatp.space = XENMAPSPACE_shared_info;
  95. xatp.gpfn = __pa(shared_info_page) >> PAGE_SHIFT;
  96. if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
  97. BUG();
  98. HYPERVISOR_shared_info = (struct shared_info *)shared_info_page;
  99. /* xen_vcpu is a pointer to the vcpu_info struct in the shared_info
  100. * page, we use it in the event channel upcall and in some pvclock
  101. * related functions. We don't need the vcpu_info placement
  102. * optimizations because we don't use any pv_mmu or pv_irq op on
  103. * HVM.
  104. * The shared info contains exactly 1 CPU (the boot CPU). The guest
  105. * is required to use VCPUOP_register_vcpu_info to place vcpu info
  106. * for secondary CPUs as they are brought up. */
  107. per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0];
  108. gnttab_init();
  109. if (!xen_initial_domain())
  110. xenbus_probe(NULL);
  111. return 0;
  112. }
  113. core_initcall(xen_guest_init);
  114. static irqreturn_t xen_arm_callback(int irq, void *arg)
  115. {
  116. xen_hvm_evtchn_do_upcall();
  117. return IRQ_HANDLED;
  118. }
  119. static int __init xen_init_events(void)
  120. {
  121. if (!xen_domain() || xen_events_irq < 0)
  122. return -ENODEV;
  123. xen_init_IRQ();
  124. if (request_percpu_irq(xen_events_irq, xen_arm_callback,
  125. "events", xen_vcpu)) {
  126. pr_err("Error requesting IRQ %d\n", xen_events_irq);
  127. return -EINVAL;
  128. }
  129. enable_percpu_irq(xen_events_irq, 0);
  130. return 0;
  131. }
  132. postcore_initcall(xen_init_events);