enlighten.c 4.6 KB

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