Commit | Line | Data |
---|---|---|
449f2ab9 PA |
1 | /* -*- linux-c -*- ------------------------------------------------------- * |
2 | * | |
3 | * Copyright (C) 1991, 1992 Linus Torvalds | |
4 | * Copyright 2007 rPath, Inc. - All Rights Reserved | |
c549e71d | 5 | * Copyright 2009 Intel Corporation; author H. Peter Anvin |
449f2ab9 PA |
6 | * |
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. | |
9 | * | |
10 | * ----------------------------------------------------------------------- */ | |
11 | ||
12 | /* | |
449f2ab9 PA |
13 | * Memory detection code |
14 | */ | |
15 | ||
16 | #include "boot.h" | |
17 | ||
18 | #define SMAP 0x534d4150 /* ASCII "SMAP" */ | |
19 | ||
e8eeb3c8 | 20 | static void detect_memory_e820(void) |
449f2ab9 | 21 | { |
2efa33f8 | 22 | int count = 0; |
df7699c5 | 23 | struct biosregs ireg, oreg; |
7410aa1c IM |
24 | struct boot_e820_entry *desc = boot_params.e820_table; |
25 | static struct boot_e820_entry buf; /* static so it is zeroed */ | |
449f2ab9 | 26 | |
df7699c5 PA |
27 | initregs(&ireg); |
28 | ireg.ax = 0xe820; | |
0e96f31e | 29 | ireg.cx = sizeof(buf); |
df7699c5 PA |
30 | ireg.edx = SMAP; |
31 | ireg.di = (size_t)&buf; | |
32 | ||
cd670599 | 33 | /* |
bca23dba PA |
34 | * Note: at least one BIOS is known which assumes that the |
35 | * buffer pointed to by one e820 call is the same one as | |
36 | * the previous call, and only changes modified fields. Therefore, | |
37 | * we use a temporary buffer and copy the results entry by entry. | |
38 | * | |
39 | * This routine deliberately does not try to account for | |
40 | * ACPI 3+ extended attributes. This is because there are | |
41 | * BIOSes in the field which report zero for the valid bit for | |
42 | * all ranges, and we don't currently make any use of the | |
43 | * other attribute bits. Revisit this if we see the extended | |
44 | * attribute bits deployed in a meaningful way in the future. | |
cd670599 | 45 | */ |
cd670599 | 46 | |
449f2ab9 | 47 | do { |
df7699c5 PA |
48 | intcall(0x15, &ireg, &oreg); |
49 | ireg.ebx = oreg.ebx; /* for next iteration... */ | |
449f2ab9 | 50 | |
829157be PA |
51 | /* BIOSes which terminate the chain with CF = 1 as opposed |
52 | to %ebx = 0 don't always report the SMAP signature on | |
53 | the final, failing, probe. */ | |
df7699c5 | 54 | if (oreg.eflags & X86_EFLAGS_CF) |
829157be PA |
55 | break; |
56 | ||
2efa33f8 PA |
57 | /* Some BIOSes stop returning SMAP in the middle of |
58 | the search loop. We don't know exactly how the BIOS | |
59 | screwed up the map at that point, we might have a | |
60 | partial map, the full map, or complete garbage, so | |
61 | just return failure. */ | |
df7699c5 | 62 | if (oreg.eax != SMAP) { |
2efa33f8 | 63 | count = 0; |
449f2ab9 | 64 | break; |
2efa33f8 | 65 | } |
449f2ab9 | 66 | |
bca23dba | 67 | *desc++ = buf; |
2efa33f8 | 68 | count++; |
61a50101 | 69 | } while (ireg.ebx && count < ARRAY_SIZE(boot_params.e820_table)); |
449f2ab9 | 70 | |
e8eeb3c8 | 71 | boot_params.e820_entries = count; |
449f2ab9 PA |
72 | } |
73 | ||
e8eeb3c8 | 74 | static void detect_memory_e801(void) |
449f2ab9 | 75 | { |
df7699c5 | 76 | struct biosregs ireg, oreg; |
449f2ab9 | 77 | |
df7699c5 PA |
78 | initregs(&ireg); |
79 | ireg.ax = 0xe801; | |
80 | intcall(0x15, &ireg, &oreg); | |
449f2ab9 | 81 | |
df7699c5 | 82 | if (oreg.eflags & X86_EFLAGS_CF) |
e8eeb3c8 | 83 | return; |
449f2ab9 PA |
84 | |
85 | /* Do we really need to do this? */ | |
df7699c5 PA |
86 | if (oreg.cx || oreg.dx) { |
87 | oreg.ax = oreg.cx; | |
88 | oreg.bx = oreg.dx; | |
449f2ab9 PA |
89 | } |
90 | ||
df7699c5 | 91 | if (oreg.ax > 15*1024) { |
e8eeb3c8 | 92 | return; /* Bogus! */ |
df7699c5 | 93 | } else if (oreg.ax == 15*1024) { |
39b68976 | 94 | boot_params.alt_mem_k = (oreg.bx << 6) + oreg.ax; |
df7699c5 PA |
95 | } else { |
96 | /* | |
97 | * This ignores memory above 16MB if we have a memory | |
98 | * hole there. If someone actually finds a machine | |
99 | * with a memory hole at 16MB and no support for | |
100 | * 0E820h they should probably generate a fake e820 | |
101 | * map. | |
102 | */ | |
103 | boot_params.alt_mem_k = oreg.ax; | |
104 | } | |
449f2ab9 PA |
105 | } |
106 | ||
e8eeb3c8 | 107 | static void detect_memory_88(void) |
449f2ab9 | 108 | { |
df7699c5 | 109 | struct biosregs ireg, oreg; |
449f2ab9 | 110 | |
df7699c5 PA |
111 | initregs(&ireg); |
112 | ireg.ah = 0x88; | |
113 | intcall(0x15, &ireg, &oreg); | |
449f2ab9 | 114 | |
df7699c5 | 115 | boot_params.screen_info.ext_mem_k = oreg.ax; |
449f2ab9 PA |
116 | } |
117 | ||
e8eeb3c8 | 118 | void detect_memory(void) |
449f2ab9 | 119 | { |
e8eeb3c8 | 120 | detect_memory_e820(); |
2efa33f8 | 121 | |
e8eeb3c8 | 122 | detect_memory_e801(); |
449f2ab9 | 123 | |
e8eeb3c8 | 124 | detect_memory_88(); |
449f2ab9 | 125 | } |