setup.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. /**
  27. * machine_specific_memory_setup - Hook for machine specific memory setup.
  28. **/
  29. char * __init xen_memory_setup(void)
  30. {
  31. unsigned long max_pfn = xen_start_info->nr_pages;
  32. max_pfn = min(MAX_DOMAIN_PAGES, max_pfn);
  33. e820.nr_map = 0;
  34. e820_add_region(0, PFN_PHYS((u64)max_pfn), E820_RAM);
  35. /*
  36. * Even though this is normal, usable memory under Xen, reserve
  37. * ISA memory anyway because too many things think they can poke
  38. * about in there.
  39. */
  40. e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
  41. E820_RESERVED);
  42. /*
  43. * Reserve Xen bits:
  44. * - mfn_list
  45. * - xen_start_info
  46. * See comment above "struct start_info" in <xen/interface/xen.h>
  47. */
  48. e820_add_region(__pa(xen_start_info->mfn_list),
  49. xen_start_info->pt_base - xen_start_info->mfn_list,
  50. E820_RESERVED);
  51. sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
  52. return "Xen";
  53. }
  54. static void xen_idle(void)
  55. {
  56. local_irq_disable();
  57. if (need_resched())
  58. local_irq_enable();
  59. else {
  60. current_thread_info()->status &= ~TS_POLLING;
  61. smp_mb__after_clear_bit();
  62. safe_halt();
  63. current_thread_info()->status |= TS_POLLING;
  64. }
  65. }
  66. /*
  67. * Set the bit indicating "nosegneg" library variants should be used.
  68. * We only need to bother in pure 32-bit mode; compat 32-bit processes
  69. * can have un-truncated segments, so wrapping around is allowed.
  70. */
  71. static void __init fiddle_vdso(void)
  72. {
  73. #ifdef CONFIG_X86_32
  74. u32 *mask;
  75. mask = VDSO32_SYMBOL(&vdso32_int80_start, NOTE_MASK);
  76. *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
  77. mask = VDSO32_SYMBOL(&vdso32_sysenter_start, NOTE_MASK);
  78. *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
  79. #endif
  80. }
  81. static __cpuinit int register_callback(unsigned type, const void *func)
  82. {
  83. struct callback_register callback = {
  84. .type = type,
  85. .address = XEN_CALLBACK(__KERNEL_CS, func),
  86. .flags = CALLBACKF_mask_events,
  87. };
  88. return HYPERVISOR_callback_op(CALLBACKOP_register, &callback);
  89. }
  90. void __cpuinit xen_enable_sysenter(void)
  91. {
  92. extern void xen_sysenter_target(void);
  93. int ret;
  94. unsigned sysenter_feature;
  95. #ifdef CONFIG_X86_32
  96. sysenter_feature = X86_FEATURE_SEP;
  97. #else
  98. sysenter_feature = X86_FEATURE_SYSENTER32;
  99. #endif
  100. if (!boot_cpu_has(sysenter_feature))
  101. return;
  102. ret = register_callback(CALLBACKTYPE_sysenter, xen_sysenter_target);
  103. if(ret != 0)
  104. setup_clear_cpu_cap(sysenter_feature);
  105. }
  106. void __cpuinit xen_enable_syscall(void)
  107. {
  108. #ifdef CONFIG_X86_64
  109. int ret;
  110. extern void xen_syscall_target(void);
  111. extern void xen_syscall32_target(void);
  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, VMASST_TYPE_pae_extended_cr3);
  134. if (register_callback(CALLBACKTYPE_event, xen_hypervisor_callback) ||
  135. register_callback(CALLBACKTYPE_failsafe, xen_failsafe_callback))
  136. BUG();
  137. xen_enable_sysenter();
  138. xen_enable_syscall();
  139. set_iopl.iopl = 1;
  140. rc = HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
  141. if (rc != 0)
  142. printk(KERN_INFO "physdev_op failed %d\n", rc);
  143. #ifdef CONFIG_ACPI
  144. if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
  145. printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
  146. disable_acpi();
  147. }
  148. #endif
  149. memcpy(boot_command_line, xen_start_info->cmd_line,
  150. MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ?
  151. COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE);
  152. pm_idle = xen_idle;
  153. paravirt_disable_iospace();
  154. fiddle_vdso();
  155. }