setup.c 4.6 KB

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