xref: /openbmc/linux/arch/x86/kernel/head32.c (revision f0d43100)
1 /*
2  *  linux/arch/i386/kernel/head32.c -- prepare to run common code
3  *
4  *  Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
5  *  Copyright (C) 2007 Eric Biederman <ebiederm@xmission.com>
6  */
7 
8 #include <linux/init.h>
9 #include <linux/start_kernel.h>
10 
11 #include <asm/setup.h>
12 #include <asm/sections.h>
13 #include <asm/e820.h>
14 #include <asm/bios_ebda.h>
15 
16 #define BIOS_LOWMEM_KILOBYTES 0x413
17 
18 /*
19  * The BIOS places the EBDA/XBDA at the top of conventional
20  * memory, and usually decreases the reported amount of
21  * conventional memory (int 0x12) too. This also contains a
22  * workaround for Dell systems that neglect to reserve EBDA.
23  * The same workaround also avoids a problem with the AMD768MPX
24  * chipset: reserve a page before VGA to prevent PCI prefetch
25  * into it (errata #56). Usually the page is reserved anyways,
26  * unless you have no PS/2 mouse plugged in.
27  */
28 static void __init reserve_ebda_region(void)
29 {
30 	unsigned int lowmem, ebda_addr;
31 
32 	/* To determine the position of the EBDA and the */
33 	/* end of conventional memory, we need to look at */
34 	/* the BIOS data area. In a paravirtual environment */
35 	/* that area is absent. We'll just have to assume */
36 	/* that the paravirt case can handle memory setup */
37 	/* correctly, without our help. */
38 	if (paravirt_enabled())
39 		return;
40 
41 	/* end of low (conventional) memory */
42 	lowmem = *(unsigned short *)__va(BIOS_LOWMEM_KILOBYTES);
43 	lowmem <<= 10;
44 
45 	/* start of EBDA area */
46 	ebda_addr = get_bios_ebda();
47 
48 	/* Fixup: bios puts an EBDA in the top 64K segment */
49 	/* of conventional memory, but does not adjust lowmem. */
50 	if ((lowmem - ebda_addr) <= 0x10000)
51 		lowmem = ebda_addr;
52 
53 	/* Fixup: bios does not report an EBDA at all. */
54 	/* Some old Dells seem to need 4k anyhow (bugzilla 2990) */
55 	if ((ebda_addr == 0) && (lowmem >= 0x9f000))
56 		lowmem = 0x9f000;
57 
58 	/* Paranoia: should never happen, but... */
59 	if ((lowmem == 0) || (lowmem >= 0x100000))
60 		lowmem = 0x9f000;
61 
62 	/* reserve all memory between lowmem and the 1MB mark */
63 	reserve_early(lowmem, 0x100000, "BIOS reserved");
64 }
65 
66 void __init i386_start_kernel(void)
67 {
68 	reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS");
69 
70 #ifdef CONFIG_BLK_DEV_INITRD
71 	/* Reserve INITRD */
72 	if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
73 		u64 ramdisk_image = boot_params.hdr.ramdisk_image;
74 		u64 ramdisk_size  = boot_params.hdr.ramdisk_size;
75 		u64 ramdisk_end   = ramdisk_image + ramdisk_size;
76 		reserve_early(ramdisk_image, ramdisk_end, "RAMDISK");
77 	}
78 #endif
79 	reserve_early(init_pg_tables_start, init_pg_tables_end,
80 			"INIT_PG_TABLE");
81 
82 	reserve_ebda_region();
83 
84 	/*
85 	 * At this point everything still needed from the boot loader
86 	 * or BIOS or kernel text should be early reserved or marked not
87 	 * RAM in e820. All other memory is free game.
88 	 */
89 
90 	start_kernel();
91 }
92