xref: /openbmc/linux/arch/x86/include/asm/boot.h (revision 8ebc80a25f9d9bf7a8e368b266d5b740c485c362)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21965aae3SH. Peter Anvin #ifndef _ASM_X86_BOOT_H
31965aae3SH. Peter Anvin #define _ASM_X86_BOOT_H
4bb898558SAl Viro 
595c4bff0SCyrill Gorcunov 
6658dbfebSH. Peter Anvin #include <asm/pgtable_types.h>
7af170c50SDavid Howells #include <uapi/asm/boot.h>
837ba7ab5SH. Peter Anvin 
9bb898558SAl Viro /* Physical address where kernel should be loaded. */
10bb898558SAl Viro #define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11bb898558SAl Viro 				+ (CONFIG_PHYSICAL_ALIGN - 1)) \
12bb898558SAl Viro 				& ~(CONFIG_PHYSICAL_ALIGN - 1))
13bb898558SAl Viro 
1437ba7ab5SH. Peter Anvin /* Minimum kernel alignment, as a power of two */
1522f4319dSRobert P. J. Day #ifdef CONFIG_X86_64
1637ba7ab5SH. Peter Anvin # define MIN_KERNEL_ALIGN_LG2	PMD_SHIFT
1737ba7ab5SH. Peter Anvin #else
1838e7c572SThomas Gleixner # define MIN_KERNEL_ALIGN_LG2	(PAGE_SHIFT + THREAD_SIZE_ORDER)
1937ba7ab5SH. Peter Anvin #endif
2037ba7ab5SH. Peter Anvin #define MIN_KERNEL_ALIGN	(_AC(1, UL) << MIN_KERNEL_ALIGN_LG2)
2137ba7ab5SH. Peter Anvin 
2237ba7ab5SH. Peter Anvin #if (CONFIG_PHYSICAL_ALIGN & (CONFIG_PHYSICAL_ALIGN-1)) || \
236fc108a0SJan Beulich 	(CONFIG_PHYSICAL_ALIGN < MIN_KERNEL_ALIGN)
2437ba7ab5SH. Peter Anvin # error "Invalid value for CONFIG_PHYSICAL_ALIGN"
2537ba7ab5SH. Peter Anvin #endif
2637ba7ab5SH. Peter Anvin 
27fb46d057SNick Terrell #if defined(CONFIG_KERNEL_BZIP2)
28ae03c499SAlain Knaff # define BOOT_HEAP_SIZE		0x400000
29fb46d057SNick Terrell #elif defined(CONFIG_KERNEL_ZSTD)
30fb46d057SNick Terrell /*
31fb46d057SNick Terrell  * Zstd needs to allocate the ZSTD_DCtx in order to decompress the kernel.
32fb46d057SNick Terrell  * The ZSTD_DCtx is ~160KB, so set the heap size to 192KB because it is a
33fb46d057SNick Terrell  * round number and to allow some slack.
34fb46d057SNick Terrell  */
35fb46d057SNick Terrell # define BOOT_HEAP_SIZE		 0x30000
36fb46d057SNick Terrell #else
378c31902cSH.J. Lu # define BOOT_HEAP_SIZE		 0x10000
388665e6ffSKees Cook #endif
39ae03c499SAlain Knaff 
40ae03c499SAlain Knaff #ifdef CONFIG_X86_64
41ae03c499SAlain Knaff # define BOOT_STACK_SIZE	0x4000
423a94707dSKees Cook 
433a94707dSKees Cook /*
44f530ee95SKirill A. Shutemov  * Used by decompressor's startup_32() to allocate page tables for identity
45f530ee95SKirill A. Shutemov  * mapping of the 4G of RAM in 4-level paging mode:
46f530ee95SKirill A. Shutemov  * - 1 level4 table;
47f530ee95SKirill A. Shutemov  * - 1 level3 table;
48f530ee95SKirill A. Shutemov  * - 4 level2 table that maps everything with 2M pages;
49f530ee95SKirill A. Shutemov  *
50f530ee95SKirill A. Shutemov  * The additional level5 table needed for 5-level paging is allocated from
51f530ee95SKirill A. Shutemov  * trampoline_32bit memory.
523a94707dSKees Cook  */
53f530ee95SKirill A. Shutemov # define BOOT_INIT_PGT_SIZE	(6*4096)
54f530ee95SKirill A. Shutemov 
55f530ee95SKirill A. Shutemov /*
56f530ee95SKirill A. Shutemov  * Total number of page tables kernel_add_identity_map() can allocate,
57f530ee95SKirill A. Shutemov  * including page tables consumed by startup_32().
58f530ee95SKirill A. Shutemov  *
59f530ee95SKirill A. Shutemov  * Worst-case scenario:
60f530ee95SKirill A. Shutemov  *  - 5-level paging needs 1 level5 table;
61f530ee95SKirill A. Shutemov  *  - KASLR needs to map kernel, boot_params, cmdline and randomized kernel,
62f530ee95SKirill A. Shutemov  *    assuming all of them cross 256T boundary:
63f530ee95SKirill A. Shutemov  *    + 4*2 level4 table;
64f530ee95SKirill A. Shutemov  *    + 4*2 level3 table;
65f530ee95SKirill A. Shutemov  *    + 4*2 level2 table;
66f530ee95SKirill A. Shutemov  *  - X86_VERBOSE_BOOTUP needs to map the first 2M (video RAM):
67f530ee95SKirill A. Shutemov  *    + 1 level4 table;
68f530ee95SKirill A. Shutemov  *    + 1 level3 table;
69f530ee95SKirill A. Shutemov  *    + 1 level2 table;
70f530ee95SKirill A. Shutemov  * Total: 28 tables
71f530ee95SKirill A. Shutemov  *
72f530ee95SKirill A. Shutemov  * Add 4 spare table in case decompressor touches anything beyond what is
73f530ee95SKirill A. Shutemov  * accounted above. Warn if it happens.
74f530ee95SKirill A. Shutemov  */
75f530ee95SKirill A. Shutemov # define BOOT_PGT_SIZE_WARN	(28*4096)
76f530ee95SKirill A. Shutemov # define BOOT_PGT_SIZE		(32*4096)
773a94707dSKees Cook 
788665e6ffSKees Cook #else /* !CONFIG_X86_64 */
79bb898558SAl Viro # define BOOT_STACK_SIZE	0x1000
80bb898558SAl Viro #endif
81bb898558SAl Viro 
8283381519SArd Biesheuvel #ifndef __ASSEMBLY__
8383381519SArd Biesheuvel extern unsigned int output_len;
84ccde70aaSArd Biesheuvel extern const unsigned long kernel_text_size;
8583381519SArd Biesheuvel extern const unsigned long kernel_total_size;
8683381519SArd Biesheuvel 
8783381519SArd Biesheuvel unsigned long decompress_kernel(unsigned char *outbuf, unsigned long virt_addr,
8883381519SArd Biesheuvel 				void (*error)(char *x));
89*c59843e8SArd Biesheuvel 
90*c59843e8SArd Biesheuvel extern struct boot_params *boot_params_ptr;
9183381519SArd Biesheuvel #endif
9283381519SArd Biesheuvel 
931965aae3SH. Peter Anvin #endif /* _ASM_X86_BOOT_H */
94