1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
9 * ----------------------------------------------------------------------- */
12 * Memory detection code
16 #include <linux/kernel.h>
18 #define SMAP 0x534d4150 /* ASCII "SMAP" */
20 static int detect_memory_e820(void)
26 struct e820entry *desc = boot_params.e820_map;
29 size = sizeof(struct e820entry);
31 /* Important: %edx is clobbered by some BIOSes,
32 so it must be either used for the error output
33 or explicitly marked clobbered. */
34 asm("int $0x15; setc %0"
35 : "=d" (err), "+b" (next), "=a" (id), "+c" (size),
37 : "D" (desc), "d" (SMAP), "a" (0xe820));
39 /* BIOSes which terminate the chain with CF = 1 as opposed
40 to %ebx = 0 don't always report the SMAP signature on
41 the final, failing, probe. */
45 /* Some BIOSes stop returning SMAP in the middle of
46 the search loop. We don't know exactly how the BIOS
47 screwed up the map at that point, we might have a
48 partial map, the full map, or complete garbage, so
49 just return failure. */
57 } while (next && count < ARRAY_SIZE(boot_params.e820_map));
59 return boot_params.e820_entries = count;
62 static int detect_memory_e801(void)
69 asm("stc; int $0x15; setc %0"
70 : "=m" (err), "+a" (ax), "+b" (bx), "+c" (cx), "+d" (dx));
75 /* Do we really need to do this? */
82 return -1; /* Bogus! */
84 /* This ignores memory above 16MB if we have a memory hole
85 there. If someone actually finds a machine with a memory
86 hole at 16MB and no support for 0E820h they should probably
87 generate a fake e820 map. */
88 boot_params.alt_mem_k = (ax == 15*1024) ? (dx << 6)+ax : ax;
93 static int detect_memory_88(void)
99 asm("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
101 boot_params.screen_info.ext_mem_k = ax;
106 int detect_memory(void)
110 if (detect_memory_e820() > 0)
113 if (!detect_memory_e801())
116 if (!detect_memory_88())