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