enlighten_pvh.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include <linux/acpi.h>
  2. #include <xen/hvc-console.h>
  3. #include <asm/io_apic.h>
  4. #include <asm/hypervisor.h>
  5. #include <asm/e820/api.h>
  6. #include <asm/xen/interface.h>
  7. #include <asm/xen/hypercall.h>
  8. #include <xen/interface/memory.h>
  9. #include <xen/interface/hvm/start_info.h>
  10. /*
  11. * PVH variables.
  12. *
  13. * xen_pvh and pvh_bootparams need to live in data segment since they
  14. * are used after startup_{32|64}, which clear .bss, are invoked.
  15. */
  16. bool xen_pvh __attribute__((section(".data"))) = 0;
  17. struct boot_params pvh_bootparams __attribute__((section(".data")));
  18. struct hvm_start_info pvh_start_info;
  19. unsigned int pvh_start_info_sz = sizeof(pvh_start_info);
  20. static void xen_pvh_arch_setup(void)
  21. {
  22. /* Make sure we don't fall back to (default) ACPI_IRQ_MODEL_PIC. */
  23. if (nr_ioapics == 0)
  24. acpi_irq_model = ACPI_IRQ_MODEL_PLATFORM;
  25. }
  26. static void __init init_pvh_bootparams(void)
  27. {
  28. struct xen_memory_map memmap;
  29. int rc;
  30. memset(&pvh_bootparams, 0, sizeof(pvh_bootparams));
  31. memmap.nr_entries = ARRAY_SIZE(pvh_bootparams.e820_table);
  32. set_xen_guest_handle(memmap.buffer, pvh_bootparams.e820_table);
  33. rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
  34. if (rc) {
  35. xen_raw_printk("XENMEM_memory_map failed (%d)\n", rc);
  36. BUG();
  37. }
  38. pvh_bootparams.e820_entries = memmap.nr_entries;
  39. if (pvh_bootparams.e820_entries < E820_MAX_ENTRIES_ZEROPAGE - 1) {
  40. pvh_bootparams.e820_table[pvh_bootparams.e820_entries].addr =
  41. ISA_START_ADDRESS;
  42. pvh_bootparams.e820_table[pvh_bootparams.e820_entries].size =
  43. ISA_END_ADDRESS - ISA_START_ADDRESS;
  44. pvh_bootparams.e820_table[pvh_bootparams.e820_entries].type =
  45. E820_TYPE_RESERVED;
  46. pvh_bootparams.e820_entries++;
  47. } else
  48. xen_raw_printk("Warning: Can fit ISA range into e820\n");
  49. pvh_bootparams.hdr.cmd_line_ptr =
  50. pvh_start_info.cmdline_paddr;
  51. /* The first module is always ramdisk. */
  52. if (pvh_start_info.nr_modules) {
  53. struct hvm_modlist_entry *modaddr =
  54. __va(pvh_start_info.modlist_paddr);
  55. pvh_bootparams.hdr.ramdisk_image = modaddr->paddr;
  56. pvh_bootparams.hdr.ramdisk_size = modaddr->size;
  57. }
  58. /*
  59. * See Documentation/x86/boot.txt.
  60. *
  61. * Version 2.12 supports Xen entry point but we will use default x86/PC
  62. * environment (i.e. hardware_subarch 0).
  63. */
  64. pvh_bootparams.hdr.version = 0x212;
  65. pvh_bootparams.hdr.type_of_loader = (9 << 4) | 0; /* Xen loader */
  66. }
  67. /*
  68. * This routine (and those that it might call) should not use
  69. * anything that lives in .bss since that segment will be cleared later.
  70. */
  71. void __init xen_prepare_pvh(void)
  72. {
  73. u32 msr;
  74. u64 pfn;
  75. if (pvh_start_info.magic != XEN_HVM_START_MAGIC_VALUE) {
  76. xen_raw_printk("Error: Unexpected magic value (0x%08x)\n",
  77. pvh_start_info.magic);
  78. BUG();
  79. }
  80. xen_pvh = 1;
  81. msr = cpuid_ebx(xen_cpuid_base() + 2);
  82. pfn = __pa(hypercall_page);
  83. wrmsr_safe(msr, (u32)pfn, (u32)(pfn >> 32));
  84. init_pvh_bootparams();
  85. x86_init.oem.arch_setup = xen_pvh_arch_setup;
  86. }