162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef _ASM_X86_BOOT_H 362306a36Sopenharmony_ci#define _ASM_X86_BOOT_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#include <asm/pgtable_types.h> 762306a36Sopenharmony_ci#include <uapi/asm/boot.h> 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci/* Physical address where kernel should be loaded. */ 1062306a36Sopenharmony_ci#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \ 1162306a36Sopenharmony_ci + (CONFIG_PHYSICAL_ALIGN - 1)) \ 1262306a36Sopenharmony_ci & ~(CONFIG_PHYSICAL_ALIGN - 1)) 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci/* Minimum kernel alignment, as a power of two */ 1562306a36Sopenharmony_ci#ifdef CONFIG_X86_64 1662306a36Sopenharmony_ci# define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT 1762306a36Sopenharmony_ci#else 1862306a36Sopenharmony_ci# define MIN_KERNEL_ALIGN_LG2 (PAGE_SHIFT + THREAD_SIZE_ORDER) 1962306a36Sopenharmony_ci#endif 2062306a36Sopenharmony_ci#define MIN_KERNEL_ALIGN (_AC(1, UL) << MIN_KERNEL_ALIGN_LG2) 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#if (CONFIG_PHYSICAL_ALIGN & (CONFIG_PHYSICAL_ALIGN-1)) || \ 2362306a36Sopenharmony_ci (CONFIG_PHYSICAL_ALIGN < MIN_KERNEL_ALIGN) 2462306a36Sopenharmony_ci# error "Invalid value for CONFIG_PHYSICAL_ALIGN" 2562306a36Sopenharmony_ci#endif 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#if defined(CONFIG_KERNEL_BZIP2) 2862306a36Sopenharmony_ci# define BOOT_HEAP_SIZE 0x400000 2962306a36Sopenharmony_ci#elif defined(CONFIG_KERNEL_ZSTD) 3062306a36Sopenharmony_ci/* 3162306a36Sopenharmony_ci * Zstd needs to allocate the ZSTD_DCtx in order to decompress the kernel. 3262306a36Sopenharmony_ci * The ZSTD_DCtx is ~160KB, so set the heap size to 192KB because it is a 3362306a36Sopenharmony_ci * round number and to allow some slack. 3462306a36Sopenharmony_ci */ 3562306a36Sopenharmony_ci# define BOOT_HEAP_SIZE 0x30000 3662306a36Sopenharmony_ci#else 3762306a36Sopenharmony_ci# define BOOT_HEAP_SIZE 0x10000 3862306a36Sopenharmony_ci#endif 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#ifdef CONFIG_X86_64 4162306a36Sopenharmony_ci# define BOOT_STACK_SIZE 0x4000 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci/* 4462306a36Sopenharmony_ci * Used by decompressor's startup_32() to allocate page tables for identity 4562306a36Sopenharmony_ci * mapping of the 4G of RAM in 4-level paging mode: 4662306a36Sopenharmony_ci * - 1 level4 table; 4762306a36Sopenharmony_ci * - 1 level3 table; 4862306a36Sopenharmony_ci * - 4 level2 table that maps everything with 2M pages; 4962306a36Sopenharmony_ci * 5062306a36Sopenharmony_ci * The additional level5 table needed for 5-level paging is allocated from 5162306a36Sopenharmony_ci * trampoline_32bit memory. 5262306a36Sopenharmony_ci */ 5362306a36Sopenharmony_ci# define BOOT_INIT_PGT_SIZE (6*4096) 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/* 5662306a36Sopenharmony_ci * Total number of page tables kernel_add_identity_map() can allocate, 5762306a36Sopenharmony_ci * including page tables consumed by startup_32(). 5862306a36Sopenharmony_ci * 5962306a36Sopenharmony_ci * Worst-case scenario: 6062306a36Sopenharmony_ci * - 5-level paging needs 1 level5 table; 6162306a36Sopenharmony_ci * - KASLR needs to map kernel, boot_params, cmdline and randomized kernel, 6262306a36Sopenharmony_ci * assuming all of them cross 256T boundary: 6362306a36Sopenharmony_ci * + 4*2 level4 table; 6462306a36Sopenharmony_ci * + 4*2 level3 table; 6562306a36Sopenharmony_ci * + 4*2 level2 table; 6662306a36Sopenharmony_ci * - X86_VERBOSE_BOOTUP needs to map the first 2M (video RAM): 6762306a36Sopenharmony_ci * + 1 level4 table; 6862306a36Sopenharmony_ci * + 1 level3 table; 6962306a36Sopenharmony_ci * + 1 level2 table; 7062306a36Sopenharmony_ci * Total: 28 tables 7162306a36Sopenharmony_ci * 7262306a36Sopenharmony_ci * Add 4 spare table in case decompressor touches anything beyond what is 7362306a36Sopenharmony_ci * accounted above. Warn if it happens. 7462306a36Sopenharmony_ci */ 7562306a36Sopenharmony_ci# define BOOT_PGT_SIZE_WARN (28*4096) 7662306a36Sopenharmony_ci# define BOOT_PGT_SIZE (32*4096) 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci#else /* !CONFIG_X86_64 */ 7962306a36Sopenharmony_ci# define BOOT_STACK_SIZE 0x1000 8062306a36Sopenharmony_ci#endif 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 8362306a36Sopenharmony_ciextern unsigned int output_len; 8462306a36Sopenharmony_ciextern const unsigned long kernel_total_size; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ciunsigned long decompress_kernel(unsigned char *outbuf, unsigned long virt_addr, 8762306a36Sopenharmony_ci void (*error)(char *x)); 8862306a36Sopenharmony_ci#endif 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci#endif /* _ASM_X86_BOOT_H */ 91