setup.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Machine specific setup for xen
  3. *
  4. * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007
  5. */
  6. #include <linux/module.h>
  7. #include <linux/sched.h>
  8. #include <linux/mm.h>
  9. #include <linux/pm.h>
  10. #include <linux/memblock.h>
  11. #include <asm/elf.h>
  12. #include <asm/vdso.h>
  13. #include <asm/e820.h>
  14. #include <asm/setup.h>
  15. #include <asm/acpi.h>
  16. #include <asm/xen/hypervisor.h>
  17. #include <asm/xen/hypercall.h>
  18. #include <xen/page.h>
  19. #include <xen/interface/callback.h>
  20. #include <xen/interface/physdev.h>
  21. #include <xen/features.h>
  22. #include "xen-ops.h"
  23. #include "vdso.h"
  24. /* These are code, but not functions. Defined in entry.S */
  25. extern const char xen_hypervisor_callback[];
  26. extern const char xen_failsafe_callback[];
  27. extern void xen_sysenter_target(void);
  28. extern void xen_syscall_target(void);
  29. extern void xen_syscall32_target(void);
  30. /**
  31. * machine_specific_memory_setup - Hook for machine specific memory setup.
  32. **/
  33. char * __init xen_memory_setup(void)
  34. {
  35. unsigned long max_pfn = xen_start_info->nr_pages;
  36. max_pfn = min(MAX_DOMAIN_PAGES, max_pfn);
  37. e820.nr_map = 0;
  38. e820_add_region(0, PFN_PHYS((u64)max_pfn), E820_RAM);
  39. /*
  40. * Even though this is normal, usable memory under Xen, reserve
  41. * ISA memory anyway because too many things think they can poke
  42. * about in there.
  43. */
  44. e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
  45. E820_RESERVED);
  46. /*
  47. * Reserve Xen bits:
  48. * - mfn_list
  49. * - xen_start_info
  50. * See comment above "struct start_info" in <xen/interface/xen.h>
  51. */
  52. memblock_x86_reserve_range(__pa(xen_start_info->mfn_list),
  53. __pa(xen_start_info->pt_base),
  54. "XEN START INFO");
  55. sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
  56. return "Xen";
  57. }
  58. static void xen_idle(void)
  59. {
  60. local_irq_disable();
  61. if (need_resched())
  62. local_irq_enable();
  63. else {
  64. current_thread_info()->status &= ~TS_POLLING;
  65. smp_mb__after_clear_bit();
  66. safe_halt();
  67. current_thread_info()->status |= TS_POLLING;
  68. }
  69. }
  70. /*
  71. * Set the bit indicating "nosegneg" library variants should be used.
  72. * We only need to bother in pure 32-bit mode; compat 32-bit processes
  73. * can have un-truncated segments, so wrapping around is allowed.
  74. */
  75. static void __init fiddle_vdso(void)
  76. {
  77. #ifdef CONFIG_X86_32
  78. u32 *mask;
  79. mask = VDSO32_SYMBOL(&vdso32_int80_start, NOTE_MASK);
  80. *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
  81. mask = VDSO32_SYMBOL(&vdso32_sysenter_start, NOTE_MASK);
  82. *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
  83. #endif
  84. }
  85. static __cpuinit int register_callback(unsigned type, const void *func)
  86. {
  87. struct callback_register callback = {
  88. .type = type,
  89. .address = XEN_CALLBACK(__KERNEL_CS, func),
  90. .flags = CALLBACKF_mask_events,
  91. };
  92. return HYPERVISOR_callback_op(CALLBACKOP_register, &callback);
  93. }
  94. void __cpuinit xen_enable_sysenter(void)
  95. {
  96. int ret;
  97. unsigned sysenter_feature;
  98. #ifdef CONFIG_X86_32
  99. sysenter_feature = X86_FEATURE_SEP;
  100. #else
  101. sysenter_feature = X86_FEATURE_SYSENTER32;
  102. #endif
  103. if (!boot_cpu_has(sysenter_feature))
  104. return;
  105. ret = register_callback(CALLBACKTYPE_sysenter, xen_sysenter_target);
  106. if(ret != 0)
  107. setup_clear_cpu_cap(sysenter_feature);
  108. }
  109. void __cpuinit xen_enable_syscall(void)
  110. {
  111. #ifdef CONFIG_X86_64
  112. int ret;
  113. ret = register_callback(CALLBACKTYPE_syscall, xen_syscall_target);
  114. if (ret != 0) {
  115. printk(KERN_ERR "Failed to set syscall callback: %d\n", ret);
  116. /* Pretty fatal; 64-bit userspace has no other
  117. mechanism for syscalls. */
  118. }
  119. if (boot_cpu_has(X86_FEATURE_SYSCALL32)) {
  120. ret = register_callback(CALLBACKTYPE_syscall32,
  121. xen_syscall32_target);
  122. if (ret != 0)
  123. setup_clear_cpu_cap(X86_FEATURE_SYSCALL32);
  124. }
  125. #endif /* CONFIG_X86_64 */
  126. }
  127. void __init xen_arch_setup(void)
  128. {
  129. struct physdev_set_iopl set_iopl;
  130. int rc;
  131. HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments);
  132. HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
  133. if (!xen_feature(XENFEAT_auto_translated_physmap))
  134. HYPERVISOR_vm_assist(VMASST_CMD_enable,
  135. VMASST_TYPE_pae_extended_cr3);
  136. if (register_callback(CALLBACKTYPE_event, xen_hypervisor_callback) ||
  137. register_callback(CALLBACKTYPE_failsafe, xen_failsafe_callback))
  138. BUG();
  139. xen_enable_sysenter();
  140. xen_enable_syscall();
  141. set_iopl.iopl = 1;
  142. rc = HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
  143. if (rc != 0)
  144. printk(KERN_INFO "physdev_op failed %d\n", rc);
  145. #ifdef CONFIG_ACPI
  146. if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
  147. printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
  148. disable_acpi();
  149. }
  150. #endif
  151. memcpy(boot_command_line, xen_start_info->cmd_line,
  152. MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ?
  153. COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE);
  154. pm_idle = xen_idle;
  155. paravirt_disable_iospace();
  156. fiddle_vdso();
  157. }