^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef _ASM_X86_SETUP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _ASM_X86_SETUP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <uapi/asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define COMMAND_LINE_SIZE 2048
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/linkage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/page_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #ifdef __i386__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/pfn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Reserved space for vmalloc and iomap - defined in asm/page.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define MAXMEM_PFN PFN_DOWN(MAXMEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define MAX_NONPAE_PFN (1 << 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #endif /* __i386__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define PARAM_SIZE 4096 /* sizeof(struct boot_params) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define OLD_CL_MAGIC 0xA33F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define OLD_CL_ADDRESS 0x020 /* Relative to real mode data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define NEW_CL_POINTER 0x228 /* Relative to real mode data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #ifndef __ASSEMBLY__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <asm/bootparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <asm/x86_init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) extern u64 relocated_ramdisk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* Interrupt control for vSMPowered x86_64 systems */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) void vsmp_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static inline void vsmp_init(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct pt_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void setup_bios_corruption_check(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) void early_platform_quirks(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) extern unsigned long saved_video_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) extern void reserve_standard_io_resources(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) extern void i386_reserve_resources(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) extern unsigned long __startup_64(unsigned long physaddr, struct boot_params *bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) extern unsigned long __startup_secondary_64(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) extern void startup_64_setup_env(unsigned long physbase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) extern void early_setup_idt(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) extern void __init do_early_exception(struct pt_regs *regs, int trapnr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #ifdef CONFIG_X86_INTEL_MID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) extern void x86_intel_mid_early_setup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static inline void x86_intel_mid_early_setup(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #ifdef CONFIG_X86_INTEL_CE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) extern void x86_ce4100_early_setup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static inline void x86_ce4100_early_setup(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #ifndef _SETUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #include <asm/espfix.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * This is set up by the setup-routine at boot-time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) extern struct boot_params boot_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) extern char _text[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static inline bool kaslr_enabled(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return IS_ENABLED(CONFIG_RANDOMIZE_MEMORY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) !!(boot_params.hdr.loadflags & KASLR_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * Apply no randomization if KASLR was disabled at boot or if KASAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * is enabled. KASAN shadow mappings rely on regions being PGD aligned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static inline bool kaslr_memory_enabled(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return kaslr_enabled() && !IS_ENABLED(CONFIG_KASAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static inline unsigned long kaslr_offset(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return (unsigned long)&_text - __START_KERNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * Do NOT EVER look at the BIOS memory size location.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * It does not work on many machines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define LOWMEMSIZE() (0x9f000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* exceedingly early brk-like allocator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) extern unsigned long _brk_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) void *extend_brk(size_t size, size_t align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * Reserve space in the brk section. The name must be unique within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * the file, and somewhat descriptive. The size is in bytes. Must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * used at file scope.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * (This uses a temp function to wrap the asm so we can pass it the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * size parameter; otherwise we wouldn't be able to. We can't use a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * "section" attribute on a normal variable because it always ends up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * being @progbits, which ends up allocating space in the vmlinux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * executable.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define RESERVE_BRK(name,sz) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static void __section(".discard.text") __used notrace \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) __brk_reservation_fn_##name##__(void) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) asm volatile ( \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) ".pushsection .brk_reservation,\"aw\",@nobits;" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ".brk." #name ":" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) " 1:.skip %c0;" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) " .size .brk." #name ", . - 1b;" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) " .popsection" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) : : "i" (sz)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* Helper for reserving space for arrays of things */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #define RESERVE_BRK_ARRAY(type, name, entries) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) type *name; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) RESERVE_BRK(name, sizeof(type) * entries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) extern void probe_roms(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #ifdef __i386__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) asmlinkage void __init i386_start_kernel(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) asmlinkage void __init x86_64_start_kernel(char *real_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) asmlinkage void __init x86_64_start_reservations(char *real_mode_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #endif /* __i386__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #endif /* _SETUP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #define RESERVE_BRK(name,sz) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .pushsection .brk_reservation,"aw",@nobits; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .brk.name: \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 1: .skip sz; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .size .brk.name,.-1b; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) .popsection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #endif /* __ASSEMBLY__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #endif /* _ASM_X86_SETUP_H */