setup.c 3.2 KB

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