Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / x86 / boot / memory.c
blob65eb917b8cbb4225ecb2a0678d8923069ce380f2
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 * arch/i386/boot/memory.c
14 * Memory detection code
17 #include "boot.h"
19 #define SMAP 0x534d4150 /* ASCII "SMAP" */
21 static int detect_memory_e820(void)
23 int count = 0;
24 u32 next = 0;
25 u32 size, id;
26 u8 err;
27 struct e820entry *desc = boot_params.e820_map;
29 do {
30 size = sizeof(struct e820entry);
32 /* Important: %edx is clobbered by some BIOSes,
33 so it must be either used for the error output
34 or explicitly marked clobbered. */
35 asm("int $0x15; setc %0"
36 : "=d" (err), "+b" (next), "=a" (id), "+c" (size),
37 "=m" (*desc)
38 : "D" (desc), "d" (SMAP), "a" (0xe820));
40 <<<<<<< HEAD:arch/x86/boot/memory.c
41 =======
42 /* BIOSes which terminate the chain with CF = 1 as opposed
43 to %ebx = 0 don't always report the SMAP signature on
44 the final, failing, probe. */
45 if (err)
46 break;
48 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/x86/boot/memory.c
49 /* Some BIOSes stop returning SMAP in the middle of
50 the search loop. We don't know exactly how the BIOS
51 screwed up the map at that point, we might have a
52 partial map, the full map, or complete garbage, so
53 just return failure. */
54 if (id != SMAP) {
55 count = 0;
56 break;
59 <<<<<<< HEAD:arch/x86/boot/memory.c
60 if (err)
61 break;
63 =======
64 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/x86/boot/memory.c
65 count++;
66 desc++;
67 } while (next && count < E820MAX);
69 return boot_params.e820_entries = count;
72 static int detect_memory_e801(void)
74 u16 ax, bx, cx, dx;
75 u8 err;
77 bx = cx = dx = 0;
78 ax = 0xe801;
79 asm("stc; int $0x15; setc %0"
80 : "=m" (err), "+a" (ax), "+b" (bx), "+c" (cx), "+d" (dx));
82 if (err)
83 return -1;
85 /* Do we really need to do this? */
86 if (cx || dx) {
87 ax = cx;
88 bx = dx;
91 if (ax > 15*1024)
92 return -1; /* Bogus! */
94 /* This ignores memory above 16MB if we have a memory hole
95 there. If someone actually finds a machine with a memory
96 hole at 16MB and no support for 0E820h they should probably
97 generate a fake e820 map. */
98 boot_params.alt_mem_k = (ax == 15*1024) ? (dx << 6)+ax : ax;
100 return 0;
103 static int detect_memory_88(void)
105 u16 ax;
106 u8 err;
108 ax = 0x8800;
109 asm("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
111 boot_params.screen_info.ext_mem_k = ax;
113 return -err;
116 int detect_memory(void)
118 int err = -1;
120 if (detect_memory_e820() > 0)
121 err = 0;
123 if (!detect_memory_e801())
124 err = 0;
126 if (!detect_memory_88())
127 err = 0;
129 return err;