18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_SETUP_H 38c2ecf20Sopenharmony_ci#define _ASM_X86_SETUP_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <uapi/asm/setup.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#define COMMAND_LINE_SIZE 2048 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/linkage.h> 108c2ecf20Sopenharmony_ci#include <asm/page_types.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifdef __i386__ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/pfn.h> 158c2ecf20Sopenharmony_ci/* 168c2ecf20Sopenharmony_ci * Reserved space for vmalloc and iomap - defined in asm/page.h 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_ci#define MAXMEM_PFN PFN_DOWN(MAXMEM) 198c2ecf20Sopenharmony_ci#define MAX_NONPAE_PFN (1 << 20) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#endif /* __i386__ */ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define PARAM_SIZE 4096 /* sizeof(struct boot_params) */ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define OLD_CL_MAGIC 0xA33F 268c2ecf20Sopenharmony_ci#define OLD_CL_ADDRESS 0x020 /* Relative to real mode data */ 278c2ecf20Sopenharmony_ci#define NEW_CL_POINTER 0x228 /* Relative to real mode data */ 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 308c2ecf20Sopenharmony_ci#include <asm/bootparam.h> 318c2ecf20Sopenharmony_ci#include <asm/x86_init.h> 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ciextern u64 relocated_ramdisk; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* Interrupt control for vSMPowered x86_64 systems */ 368c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_64 378c2ecf20Sopenharmony_civoid vsmp_init(void); 388c2ecf20Sopenharmony_ci#else 398c2ecf20Sopenharmony_cistatic inline void vsmp_init(void) { } 408c2ecf20Sopenharmony_ci#endif 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistruct pt_regs; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_civoid setup_bios_corruption_check(void); 458c2ecf20Sopenharmony_civoid early_platform_quirks(void); 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciextern unsigned long saved_video_mode; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ciextern void reserve_standard_io_resources(void); 508c2ecf20Sopenharmony_ciextern void i386_reserve_resources(void); 518c2ecf20Sopenharmony_ciextern unsigned long __startup_64(unsigned long physaddr, struct boot_params *bp); 528c2ecf20Sopenharmony_ciextern unsigned long __startup_secondary_64(void); 538c2ecf20Sopenharmony_ciextern void startup_64_setup_env(unsigned long physbase); 548c2ecf20Sopenharmony_ciextern void early_setup_idt(void); 558c2ecf20Sopenharmony_ciextern void __init do_early_exception(struct pt_regs *regs, int trapnr); 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_INTEL_MID 588c2ecf20Sopenharmony_ciextern void x86_intel_mid_early_setup(void); 598c2ecf20Sopenharmony_ci#else 608c2ecf20Sopenharmony_cistatic inline void x86_intel_mid_early_setup(void) { } 618c2ecf20Sopenharmony_ci#endif 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_INTEL_CE 648c2ecf20Sopenharmony_ciextern void x86_ce4100_early_setup(void); 658c2ecf20Sopenharmony_ci#else 668c2ecf20Sopenharmony_cistatic inline void x86_ce4100_early_setup(void) { } 678c2ecf20Sopenharmony_ci#endif 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#ifndef _SETUP 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#include <asm/espfix.h> 728c2ecf20Sopenharmony_ci#include <linux/kernel.h> 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/* 758c2ecf20Sopenharmony_ci * This is set up by the setup-routine at boot-time 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_ciextern struct boot_params boot_params; 788c2ecf20Sopenharmony_ciextern char _text[]; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistatic inline bool kaslr_enabled(void) 818c2ecf20Sopenharmony_ci{ 828c2ecf20Sopenharmony_ci return IS_ENABLED(CONFIG_RANDOMIZE_MEMORY) && 838c2ecf20Sopenharmony_ci !!(boot_params.hdr.loadflags & KASLR_FLAG); 848c2ecf20Sopenharmony_ci} 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* 878c2ecf20Sopenharmony_ci * Apply no randomization if KASLR was disabled at boot or if KASAN 888c2ecf20Sopenharmony_ci * is enabled. KASAN shadow mappings rely on regions being PGD aligned. 898c2ecf20Sopenharmony_ci */ 908c2ecf20Sopenharmony_cistatic inline bool kaslr_memory_enabled(void) 918c2ecf20Sopenharmony_ci{ 928c2ecf20Sopenharmony_ci return kaslr_enabled() && !IS_ENABLED(CONFIG_KASAN); 938c2ecf20Sopenharmony_ci} 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_cistatic inline unsigned long kaslr_offset(void) 968c2ecf20Sopenharmony_ci{ 978c2ecf20Sopenharmony_ci return (unsigned long)&_text - __START_KERNEL; 988c2ecf20Sopenharmony_ci} 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci/* 1018c2ecf20Sopenharmony_ci * Do NOT EVER look at the BIOS memory size location. 1028c2ecf20Sopenharmony_ci * It does not work on many machines. 1038c2ecf20Sopenharmony_ci */ 1048c2ecf20Sopenharmony_ci#define LOWMEMSIZE() (0x9f000) 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci/* exceedingly early brk-like allocator */ 1078c2ecf20Sopenharmony_ciextern unsigned long _brk_end; 1088c2ecf20Sopenharmony_civoid *extend_brk(size_t size, size_t align); 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci/* 1118c2ecf20Sopenharmony_ci * Reserve space in the .brk section, which is a block of memory from which the 1128c2ecf20Sopenharmony_ci * caller is allowed to allocate very early (before even memblock is available) 1138c2ecf20Sopenharmony_ci * by calling extend_brk(). All allocated memory will be eventually converted 1148c2ecf20Sopenharmony_ci * to memblock. Any leftover unallocated memory will be freed. 1158c2ecf20Sopenharmony_ci * 1168c2ecf20Sopenharmony_ci * The size is in bytes. 1178c2ecf20Sopenharmony_ci */ 1188c2ecf20Sopenharmony_ci#define RESERVE_BRK(name, size) \ 1198c2ecf20Sopenharmony_ci __section(".bss..brk") __aligned(1) __used \ 1208c2ecf20Sopenharmony_ci static char __brk_##name[size] 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/* Helper for reserving space for arrays of things */ 1238c2ecf20Sopenharmony_ci#define RESERVE_BRK_ARRAY(type, name, entries) \ 1248c2ecf20Sopenharmony_ci type *name; \ 1258c2ecf20Sopenharmony_ci RESERVE_BRK(name, sizeof(type) * entries) 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ciextern void probe_roms(void); 1288c2ecf20Sopenharmony_ci#ifdef __i386__ 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ciasmlinkage void __init i386_start_kernel(void); 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci#else 1338c2ecf20Sopenharmony_ciasmlinkage void __init x86_64_start_kernel(char *real_mode); 1348c2ecf20Sopenharmony_ciasmlinkage void __init x86_64_start_reservations(char *real_mode_data); 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#endif /* __i386__ */ 1378c2ecf20Sopenharmony_ci#endif /* _SETUP */ 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci#else /* __ASSEMBLY */ 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci.macro __RESERVE_BRK name, size 1428c2ecf20Sopenharmony_ci .pushsection .bss..brk, "aw" 1438c2ecf20Sopenharmony_ciSYM_DATA_START(__brk_\name) 1448c2ecf20Sopenharmony_ci .skip \size 1458c2ecf20Sopenharmony_ciSYM_DATA_END(__brk_\name) 1468c2ecf20Sopenharmony_ci .popsection 1478c2ecf20Sopenharmony_ci.endm 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci#define RESERVE_BRK(name, size) __RESERVE_BRK name, size 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */ 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci#endif /* _ASM_X86_SETUP_H */ 154