setup.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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/xen/hypervisor.h>
  15. #include <asm/xen/hypercall.h>
  16. #include <xen/page.h>
  17. #include <xen/interface/callback.h>
  18. #include <xen/interface/physdev.h>
  19. #include <xen/features.h>
  20. #include "xen-ops.h"
  21. #include "vdso.h"
  22. /* These are code, but not functions. Defined in entry.S */
  23. extern const char xen_hypervisor_callback[];
  24. extern const char xen_failsafe_callback[];
  25. /**
  26. * machine_specific_memory_setup - Hook for machine specific memory setup.
  27. **/
  28. char * __init xen_memory_setup(void)
  29. {
  30. unsigned long max_pfn = xen_start_info->nr_pages;
  31. max_pfn = min(MAX_DOMAIN_PAGES, max_pfn);
  32. e820.nr_map = 0;
  33. e820_add_region(0, LOWMEMSIZE(), E820_RAM);
  34. e820_add_region(HIGH_MEMORY, PFN_PHYS(max_pfn)-HIGH_MEMORY, E820_RAM);
  35. /*
  36. * Reserve Xen bits:
  37. * - mfn_list
  38. * - xen_start_info
  39. * See comment above "struct start_info" in <xen/interface/xen.h>
  40. */
  41. e820_add_region(__pa(xen_start_info->mfn_list),
  42. xen_start_info->pt_base - xen_start_info->mfn_list,
  43. E820_RESERVED);
  44. sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
  45. return "Xen";
  46. }
  47. static void xen_idle(void)
  48. {
  49. local_irq_disable();
  50. if (need_resched())
  51. local_irq_enable();
  52. else {
  53. current_thread_info()->status &= ~TS_POLLING;
  54. smp_mb__after_clear_bit();
  55. safe_halt();
  56. current_thread_info()->status |= TS_POLLING;
  57. }
  58. }
  59. /*
  60. * Set the bit indicating "nosegneg" library variants should be used.
  61. */
  62. static void __init fiddle_vdso(void)
  63. {
  64. extern const char vdso32_default_start;
  65. u32 *mask = VDSO32_SYMBOL(&vdso32_default_start, NOTE_MASK);
  66. *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
  67. }
  68. void xen_enable_sysenter(void)
  69. {
  70. int cpu = smp_processor_id();
  71. extern void xen_sysenter_target(void);
  72. /* Mask events on entry, even though they get enabled immediately */
  73. static struct callback_register sysenter = {
  74. .type = CALLBACKTYPE_sysenter,
  75. .address = { __KERNEL_CS, (unsigned long)xen_sysenter_target },
  76. .flags = CALLBACKF_mask_events,
  77. };
  78. if (!boot_cpu_has(X86_FEATURE_SEP) ||
  79. HYPERVISOR_callback_op(CALLBACKOP_register, &sysenter) != 0) {
  80. clear_cpu_cap(&cpu_data(cpu), X86_FEATURE_SEP);
  81. clear_cpu_cap(&boot_cpu_data, X86_FEATURE_SEP);
  82. }
  83. }
  84. void __init xen_arch_setup(void)
  85. {
  86. struct physdev_set_iopl set_iopl;
  87. int rc;
  88. HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments);
  89. HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
  90. if (!xen_feature(XENFEAT_auto_translated_physmap))
  91. HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_pae_extended_cr3);
  92. HYPERVISOR_set_callbacks(__KERNEL_CS, (unsigned long)xen_hypervisor_callback,
  93. __KERNEL_CS, (unsigned long)xen_failsafe_callback);
  94. xen_enable_sysenter();
  95. set_iopl.iopl = 1;
  96. rc = HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
  97. if (rc != 0)
  98. printk(KERN_INFO "physdev_op failed %d\n", rc);
  99. #ifdef CONFIG_ACPI
  100. if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
  101. printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
  102. disable_acpi();
  103. }
  104. #endif
  105. memcpy(boot_command_line, xen_start_info->cmd_line,
  106. MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ?
  107. COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE);
  108. pm_idle = xen_idle;
  109. #ifdef CONFIG_SMP
  110. /* fill cpus_possible with all available cpus */
  111. xen_fill_possible_map();
  112. #endif
  113. paravirt_disable_iospace();
  114. fiddle_vdso();
  115. }