1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
5 * Copyright 2009 Intel Corporation; author H. Peter Anvin
7 * This file is part of the Linux kernel, and is made available under
8 * the terms of the GNU General Public License version 2.
10 * ----------------------------------------------------------------------- */
13 * Memory detection code
18 #define SMAP 0x534d4150 /* ASCII "SMAP" */
20 static int detect_memory_e820(void)
26 struct e820entry *desc = boot_params.e820_map;
27 static struct e820entry buf; /* static so it is zeroed */
30 * Note: at least one BIOS is known which assumes that the
31 * buffer pointed to by one e820 call is the same one as
32 * the previous call, and only changes modified fields. Therefore,
33 * we use a temporary buffer and copy the results entry by entry.
35 * This routine deliberately does not try to account for
36 * ACPI 3+ extended attributes. This is because there are
37 * BIOSes in the field which report zero for the valid bit for
38 * all ranges, and we don't currently make any use of the
39 * other attribute bits. Revisit this if we see the extended
40 * attribute bits deployed in a meaningful way in the future.
46 /* Important: %edx and %esi are clobbered by some BIOSes,
47 so they must be either used for the error output
48 or explicitly marked clobbered. Given that, assume there
49 is something out there clobbering %ebp and %edi, too. */
50 asm("pushl %%ebp; int $0x15; popl %%ebp; setc %0"
51 : "=d" (err), "+b" (next), "=a" (id), "+c" (size),
52 "=D" (edi), "+m" (buf)
53 : "D" (&buf), "d" (SMAP), "a" (0xe820)
56 /* BIOSes which terminate the chain with CF = 1 as opposed
57 to %ebx = 0 don't always report the SMAP signature on
58 the final, failing, probe. */
62 /* Some BIOSes stop returning SMAP in the middle of
63 the search loop. We don't know exactly how the BIOS
64 screwed up the map at that point, we might have a
65 partial map, the full map, or complete garbage, so
66 just return failure. */
74 } while (next && count < ARRAY_SIZE(boot_params.e820_map));
76 return boot_params.e820_entries = count;
79 static int detect_memory_e801(void)
86 asm("stc; int $0x15; setc %0"
87 : "=m" (err), "+a" (ax), "+b" (bx), "+c" (cx), "+d" (dx));
92 /* Do we really need to do this? */
99 return -1; /* Bogus! */
101 /* This ignores memory above 16MB if we have a memory hole
102 there. If someone actually finds a machine with a memory
103 hole at 16MB and no support for 0E820h they should probably
104 generate a fake e820 map. */
105 boot_params.alt_mem_k = (ax == 15*1024) ? (dx << 6)+ax : ax;
110 static int detect_memory_88(void)
116 asm("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
118 boot_params.screen_info.ext_mem_k = ax;
123 int detect_memory(void)
127 if (detect_memory_e820() > 0)
130 if (!detect_memory_e801())
133 if (!detect_memory_88())