enlighten.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/acpi.h>
  3. #include <xen/hvc-console.h>
  4. #include <asm/bootparam.h>
  5. #include <asm/io_apic.h>
  6. #include <asm/hypervisor.h>
  7. #include <asm/e820/api.h>
  8. #include <asm/x86_init.h>
  9. #include <asm/xen/interface.h>
  10. #include <xen/xen.h>
  11. #include <xen/interface/hvm/start_info.h>
  12. /*
  13. * PVH variables.
  14. *
  15. * pvh_bootparams and pvh_start_info need to live in a data segment since
  16. * they are used after startup_{32|64}, which clear .bss, are invoked.
  17. */
  18. struct boot_params __initdata pvh_bootparams;
  19. struct hvm_start_info __initdata pvh_start_info;
  20. const unsigned int __initconst pvh_start_info_sz = sizeof(pvh_start_info);
  21. static u64 __init pvh_get_root_pointer(void)
  22. {
  23. return pvh_start_info.rsdp_paddr;
  24. }
  25. /*
  26. * Xen guests are able to obtain the memory map from the hypervisor via the
  27. * HYPERVISOR_memory_op hypercall.
  28. * If we are trying to boot a Xen PVH guest, it is expected that the kernel
  29. * will have been configured to provide an override for this routine to do
  30. * just that.
  31. */
  32. void __init __weak mem_map_via_hcall(struct boot_params *ptr __maybe_unused)
  33. {
  34. xen_raw_printk("Error: Could not find memory map\n");
  35. BUG();
  36. }
  37. static void __init init_pvh_bootparams(bool xen_guest)
  38. {
  39. if ((pvh_start_info.version > 0) && (pvh_start_info.memmap_entries)) {
  40. struct hvm_memmap_table_entry *ep;
  41. int i;
  42. ep = __va(pvh_start_info.memmap_paddr);
  43. pvh_bootparams.e820_entries = pvh_start_info.memmap_entries;
  44. for (i = 0; i < pvh_bootparams.e820_entries ; i++, ep++) {
  45. pvh_bootparams.e820_table[i].addr = ep->addr;
  46. pvh_bootparams.e820_table[i].size = ep->size;
  47. pvh_bootparams.e820_table[i].type = ep->type;
  48. }
  49. } else if (xen_guest) {
  50. mem_map_via_hcall(&pvh_bootparams);
  51. } else {
  52. /* Non-xen guests are not supported by version 0 */
  53. BUG();
  54. }
  55. if (pvh_bootparams.e820_entries < E820_MAX_ENTRIES_ZEROPAGE - 1) {
  56. pvh_bootparams.e820_table[pvh_bootparams.e820_entries].addr =
  57. ISA_START_ADDRESS;
  58. pvh_bootparams.e820_table[pvh_bootparams.e820_entries].size =
  59. ISA_END_ADDRESS - ISA_START_ADDRESS;
  60. pvh_bootparams.e820_table[pvh_bootparams.e820_entries].type =
  61. E820_TYPE_RESERVED;
  62. pvh_bootparams.e820_entries++;
  63. } else
  64. xen_raw_printk("Warning: Can fit ISA range into e820\n");
  65. pvh_bootparams.hdr.cmd_line_ptr =
  66. pvh_start_info.cmdline_paddr;
  67. /* The first module is always ramdisk. */
  68. if (pvh_start_info.nr_modules) {
  69. struct hvm_modlist_entry *modaddr =
  70. __va(pvh_start_info.modlist_paddr);
  71. pvh_bootparams.hdr.ramdisk_image = modaddr->paddr;
  72. pvh_bootparams.hdr.ramdisk_size = modaddr->size;
  73. }
  74. /*
  75. * See Documentation/arch/x86/boot.rst.
  76. *
  77. * Version 2.12 supports Xen entry point but we will use default x86/PC
  78. * environment (i.e. hardware_subarch 0).
  79. */
  80. pvh_bootparams.hdr.version = (2 << 8) | 12;
  81. pvh_bootparams.hdr.type_of_loader = ((xen_guest ? 0x9 : 0xb) << 4) | 0;
  82. x86_init.acpi.get_root_pointer = pvh_get_root_pointer;
  83. }
  84. /*
  85. * If we are trying to boot a Xen PVH guest, it is expected that the kernel
  86. * will have been configured to provide the required override for this routine.
  87. */
  88. void __init __weak xen_pvh_init(struct boot_params *boot_params)
  89. {
  90. xen_raw_printk("Error: Missing xen PVH initialization\n");
  91. BUG();
  92. }
  93. static void __init hypervisor_specific_init(bool xen_guest)
  94. {
  95. if (xen_guest)
  96. xen_pvh_init(&pvh_bootparams);
  97. }
  98. /*
  99. * This routine (and those that it might call) should not use
  100. * anything that lives in .bss since that segment will be cleared later.
  101. */
  102. void __init xen_prepare_pvh(void)
  103. {
  104. u32 msr = xen_cpuid_base();
  105. bool xen_guest = !!msr;
  106. if (pvh_start_info.magic != XEN_HVM_START_MAGIC_VALUE) {
  107. xen_raw_printk("Error: Unexpected magic value (0x%08x)\n",
  108. pvh_start_info.magic);
  109. BUG();
  110. }
  111. /*
  112. * This must not compile to "call memset" because memset() may be
  113. * instrumented.
  114. */
  115. __builtin_memset(&pvh_bootparams, 0, sizeof(pvh_bootparams));
  116. hypervisor_specific_init(xen_guest);
  117. init_pvh_bootparams(xen_guest);
  118. }