misc.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef BOOT_COMPRESSED_MISC_H
  3. #define BOOT_COMPRESSED_MISC_H
  4. /*
  5. * Special hack: we have to be careful, because no indirections are allowed here,
  6. * and paravirt_ops is a kind of one. As it will only run in baremetal anyway,
  7. * we just keep it from happening. (This list needs to be extended when new
  8. * paravirt and debugging variants are added.)
  9. */
  10. #undef CONFIG_PARAVIRT
  11. #undef CONFIG_PARAVIRT_XXL
  12. #undef CONFIG_PARAVIRT_SPINLOCKS
  13. #undef CONFIG_KASAN
  14. #undef CONFIG_KASAN_GENERIC
  15. #define __NO_FORTIFY
  16. /* cpu_feature_enabled() cannot be used this early */
  17. #define USE_EARLY_PGTABLE_L5
  18. #include <linux/linkage.h>
  19. #include <linux/screen_info.h>
  20. #include <linux/elf.h>
  21. #include <asm/page.h>
  22. #include <asm/boot.h>
  23. #include <asm/bootparam.h>
  24. #include <asm/desc_defs.h>
  25. #include "tdx.h"
  26. #define BOOT_CTYPE_H
  27. #include <linux/acpi.h>
  28. #define BOOT_BOOT_H
  29. #include "../ctype.h"
  30. #include "../io.h"
  31. #include "efi.h"
  32. #ifdef CONFIG_X86_64
  33. #define memptr long
  34. #else
  35. #define memptr unsigned
  36. #endif
  37. /* boot/compressed/vmlinux start and end markers */
  38. extern char _head[], _end[];
  39. /* misc.c */
  40. extern memptr free_mem_ptr;
  41. extern memptr free_mem_end_ptr;
  42. void *malloc(int size);
  43. void free(void *where);
  44. extern struct boot_params *boot_params;
  45. void __putstr(const char *s);
  46. void __puthex(unsigned long value);
  47. #define error_putstr(__x) __putstr(__x)
  48. #define error_puthex(__x) __puthex(__x)
  49. #ifdef CONFIG_X86_VERBOSE_BOOTUP
  50. #define debug_putstr(__x) __putstr(__x)
  51. #define debug_puthex(__x) __puthex(__x)
  52. #define debug_putaddr(__x) { \
  53. debug_putstr(#__x ": 0x"); \
  54. debug_puthex((unsigned long)(__x)); \
  55. debug_putstr("\n"); \
  56. }
  57. #else
  58. static inline void debug_putstr(const char *s)
  59. { }
  60. static inline void debug_puthex(unsigned long value)
  61. { }
  62. #define debug_putaddr(x) /* */
  63. #endif
  64. /* cmdline.c */
  65. int cmdline_find_option(const char *option, char *buffer, int bufsize);
  66. int cmdline_find_option_bool(const char *option);
  67. struct mem_vector {
  68. u64 start;
  69. u64 size;
  70. };
  71. #ifdef CONFIG_RANDOMIZE_BASE
  72. /* kaslr.c */
  73. void choose_random_location(unsigned long input,
  74. unsigned long input_size,
  75. unsigned long *output,
  76. unsigned long output_size,
  77. unsigned long *virt_addr);
  78. #else
  79. static inline void choose_random_location(unsigned long input,
  80. unsigned long input_size,
  81. unsigned long *output,
  82. unsigned long output_size,
  83. unsigned long *virt_addr)
  84. {
  85. }
  86. #endif
  87. /* cpuflags.c */
  88. bool has_cpuflag(int flag);
  89. #ifdef CONFIG_X86_64
  90. extern int set_page_decrypted(unsigned long address);
  91. extern int set_page_encrypted(unsigned long address);
  92. extern int set_page_non_present(unsigned long address);
  93. extern unsigned char _pgtable[];
  94. #endif
  95. #ifdef CONFIG_EARLY_PRINTK
  96. /* early_serial_console.c */
  97. extern int early_serial_base;
  98. void console_init(void);
  99. #else
  100. static const int early_serial_base;
  101. static inline void console_init(void)
  102. { }
  103. #endif
  104. #ifdef CONFIG_AMD_MEM_ENCRYPT
  105. void sev_enable(struct boot_params *bp);
  106. void snp_check_features(void);
  107. void sev_es_shutdown_ghcb(void);
  108. extern bool sev_es_check_ghcb_fault(unsigned long address);
  109. void snp_set_page_private(unsigned long paddr);
  110. void snp_set_page_shared(unsigned long paddr);
  111. void sev_prep_identity_maps(unsigned long top_level_pgt);
  112. #else
  113. static inline void sev_enable(struct boot_params *bp)
  114. {
  115. /*
  116. * bp->cc_blob_address should only be set by boot/compressed kernel.
  117. * Initialize it to 0 unconditionally (thus here in this stub too) to
  118. * ensure that uninitialized values from buggy bootloaders aren't
  119. * propagated.
  120. */
  121. if (bp)
  122. bp->cc_blob_address = 0;
  123. }
  124. static inline void snp_check_features(void) { }
  125. static inline void sev_es_shutdown_ghcb(void) { }
  126. static inline bool sev_es_check_ghcb_fault(unsigned long address)
  127. {
  128. return false;
  129. }
  130. static inline void snp_set_page_private(unsigned long paddr) { }
  131. static inline void snp_set_page_shared(unsigned long paddr) { }
  132. static inline void sev_prep_identity_maps(unsigned long top_level_pgt) { }
  133. #endif
  134. /* acpi.c */
  135. #ifdef CONFIG_ACPI
  136. acpi_physical_address get_rsdp_addr(void);
  137. #else
  138. static inline acpi_physical_address get_rsdp_addr(void) { return 0; }
  139. #endif
  140. #if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI)
  141. extern struct mem_vector immovable_mem[MAX_NUMNODES*2];
  142. int count_immovable_mem_regions(void);
  143. #else
  144. static inline int count_immovable_mem_regions(void) { return 0; }
  145. #endif
  146. /* ident_map_64.c */
  147. #ifdef CONFIG_X86_5LEVEL
  148. extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d;
  149. #endif
  150. extern void kernel_add_identity_map(unsigned long start, unsigned long end);
  151. /* Used by PAGE_KERN* macros: */
  152. extern pteval_t __default_kernel_pte_mask;
  153. /* idt_64.c */
  154. extern gate_desc boot_idt[BOOT_IDT_ENTRIES];
  155. extern struct desc_ptr boot_idt_desc;
  156. #ifdef CONFIG_X86_64
  157. void cleanup_exception_handling(void);
  158. #else
  159. static inline void cleanup_exception_handling(void) { }
  160. #endif
  161. /* IDT Entry Points */
  162. void boot_page_fault(void);
  163. void boot_stage1_vc(void);
  164. void boot_stage2_vc(void);
  165. unsigned long sev_verify_cbit(unsigned long cr3);
  166. enum efi_type {
  167. EFI_TYPE_64,
  168. EFI_TYPE_32,
  169. EFI_TYPE_NONE,
  170. };
  171. #ifdef CONFIG_EFI
  172. /* helpers for early EFI config table access */
  173. enum efi_type efi_get_type(struct boot_params *bp);
  174. unsigned long efi_get_system_table(struct boot_params *bp);
  175. int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa,
  176. unsigned int *cfg_tbl_len);
  177. unsigned long efi_find_vendor_table(struct boot_params *bp,
  178. unsigned long cfg_tbl_pa,
  179. unsigned int cfg_tbl_len,
  180. efi_guid_t guid);
  181. #else
  182. static inline enum efi_type efi_get_type(struct boot_params *bp)
  183. {
  184. return EFI_TYPE_NONE;
  185. }
  186. static inline unsigned long efi_get_system_table(struct boot_params *bp)
  187. {
  188. return 0;
  189. }
  190. static inline int efi_get_conf_table(struct boot_params *bp,
  191. unsigned long *cfg_tbl_pa,
  192. unsigned int *cfg_tbl_len)
  193. {
  194. return -ENOENT;
  195. }
  196. static inline unsigned long efi_find_vendor_table(struct boot_params *bp,
  197. unsigned long cfg_tbl_pa,
  198. unsigned int cfg_tbl_len,
  199. efi_guid_t guid)
  200. {
  201. return 0;
  202. }
  203. #endif /* CONFIG_EFI */
  204. #endif /* BOOT_COMPRESSED_MISC_H */