enlighten_pvh.c 2.9 KB

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