aboutsummaryrefslogtreecommitdiffstats
path: root/arch/i386/kernel/setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/i386/kernel/setup.c')
-rw-r--r--arch/i386/kernel/setup.c240
1 files changed, 0 insertions, 240 deletions
diff --git a/arch/i386/kernel/setup.c b/arch/i386/kernel/setup.c
index acd2d9392abb..b7509aec0eb1 100644
--- a/arch/i386/kernel/setup.c
+++ b/arch/i386/kernel/setup.c
@@ -191,26 +191,6 @@ static void __init limit_regions(unsigned long long size)
191 } 191 }
192} 192}
193 193
194void __init add_memory_region(unsigned long long start,
195 unsigned long long size, int type)
196{
197 int x;
198
199 if (!efi_enabled) {
200 x = e820.nr_map;
201
202 if (x == E820MAX) {
203 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
204 return;
205 }
206
207 e820.map[x].addr = start;
208 e820.map[x].size = size;
209 e820.map[x].type = type;
210 e820.nr_map++;
211 }
212} /* add_memory_region */
213
214#define E820_DEBUG 1 194#define E820_DEBUG 1
215 195
216static void __init print_memory_map(char *who) 196static void __init print_memory_map(char *who)
@@ -239,226 +219,6 @@ static void __init print_memory_map(char *who)
239 } 219 }
240} 220}
241 221
242/*
243 * Sanitize the BIOS e820 map.
244 *
245 * Some e820 responses include overlapping entries. The following
246 * replaces the original e820 map with a new one, removing overlaps.
247 *
248 */
249struct change_member {
250 struct e820entry *pbios; /* pointer to original bios entry */
251 unsigned long long addr; /* address for this change point */
252};
253static struct change_member change_point_list[2*E820MAX] __initdata;
254static struct change_member *change_point[2*E820MAX] __initdata;
255static struct e820entry *overlap_list[E820MAX] __initdata;
256static struct e820entry new_bios[E820MAX] __initdata;
257
258int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
259{
260 struct change_member *change_tmp;
261 unsigned long current_type, last_type;
262 unsigned long long last_addr;
263 int chgidx, still_changing;
264 int overlap_entries;
265 int new_bios_entry;
266 int old_nr, new_nr, chg_nr;
267 int i;
268
269 /*
270 Visually we're performing the following (1,2,3,4 = memory types)...
271
272 Sample memory map (w/overlaps):
273 ____22__________________
274 ______________________4_
275 ____1111________________
276 _44_____________________
277 11111111________________
278 ____________________33__
279 ___________44___________
280 __________33333_________
281 ______________22________
282 ___________________2222_
283 _________111111111______
284 _____________________11_
285 _________________4______
286
287 Sanitized equivalent (no overlap):
288 1_______________________
289 _44_____________________
290 ___1____________________
291 ____22__________________
292 ______11________________
293 _________1______________
294 __________3_____________
295 ___________44___________
296 _____________33_________
297 _______________2________
298 ________________1_______
299 _________________4______
300 ___________________2____
301 ____________________33__
302 ______________________4_
303 */
304
305 /* if there's only one memory region, don't bother */
306 if (*pnr_map < 2)
307 return -1;
308
309 old_nr = *pnr_map;
310
311 /* bail out if we find any unreasonable addresses in bios map */
312 for (i=0; i<old_nr; i++)
313 if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
314 return -1;
315
316 /* create pointers for initial change-point information (for sorting) */
317 for (i=0; i < 2*old_nr; i++)
318 change_point[i] = &change_point_list[i];
319
320 /* record all known change-points (starting and ending addresses),
321 omitting those that are for empty memory regions */
322 chgidx = 0;
323 for (i=0; i < old_nr; i++) {
324 if (biosmap[i].size != 0) {
325 change_point[chgidx]->addr = biosmap[i].addr;
326 change_point[chgidx++]->pbios = &biosmap[i];
327 change_point[chgidx]->addr = biosmap[i].addr + biosmap[i].size;
328 change_point[chgidx++]->pbios = &biosmap[i];
329 }
330 }
331 chg_nr = chgidx; /* true number of change-points */
332
333 /* sort change-point list by memory addresses (low -> high) */
334 still_changing = 1;
335 while (still_changing) {
336 still_changing = 0;
337 for (i=1; i < chg_nr; i++) {
338 /* if <current_addr> > <last_addr>, swap */
339 /* or, if current=<start_addr> & last=<end_addr>, swap */
340 if ((change_point[i]->addr < change_point[i-1]->addr) ||
341 ((change_point[i]->addr == change_point[i-1]->addr) &&
342 (change_point[i]->addr == change_point[i]->pbios->addr) &&
343 (change_point[i-1]->addr != change_point[i-1]->pbios->addr))
344 )
345 {
346 change_tmp = change_point[i];
347 change_point[i] = change_point[i-1];
348 change_point[i-1] = change_tmp;
349 still_changing=1;
350 }
351 }
352 }
353
354 /* create a new bios memory map, removing overlaps */
355 overlap_entries=0; /* number of entries in the overlap table */
356 new_bios_entry=0; /* index for creating new bios map entries */
357 last_type = 0; /* start with undefined memory type */
358 last_addr = 0; /* start with 0 as last starting address */
359 /* loop through change-points, determining affect on the new bios map */
360 for (chgidx=0; chgidx < chg_nr; chgidx++)
361 {
362 /* keep track of all overlapping bios entries */
363 if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr)
364 {
365 /* add map entry to overlap list (> 1 entry implies an overlap) */
366 overlap_list[overlap_entries++]=change_point[chgidx]->pbios;
367 }
368 else
369 {
370 /* remove entry from list (order independent, so swap with last) */
371 for (i=0; i<overlap_entries; i++)
372 {
373 if (overlap_list[i] == change_point[chgidx]->pbios)
374 overlap_list[i] = overlap_list[overlap_entries-1];
375 }
376 overlap_entries--;
377 }
378 /* if there are overlapping entries, decide which "type" to use */
379 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
380 current_type = 0;
381 for (i=0; i<overlap_entries; i++)
382 if (overlap_list[i]->type > current_type)
383 current_type = overlap_list[i]->type;
384 /* continue building up new bios map based on this information */
385 if (current_type != last_type) {
386 if (last_type != 0) {
387 new_bios[new_bios_entry].size =
388 change_point[chgidx]->addr - last_addr;
389 /* move forward only if the new size was non-zero */
390 if (new_bios[new_bios_entry].size != 0)
391 if (++new_bios_entry >= E820MAX)
392 break; /* no more space left for new bios entries */
393 }
394 if (current_type != 0) {
395 new_bios[new_bios_entry].addr = change_point[chgidx]->addr;
396 new_bios[new_bios_entry].type = current_type;
397 last_addr=change_point[chgidx]->addr;
398 }
399 last_type = current_type;
400 }
401 }
402 new_nr = new_bios_entry; /* retain count for new bios entries */
403
404 /* copy new bios mapping into original location */
405 memcpy(biosmap, new_bios, new_nr*sizeof(struct e820entry));
406 *pnr_map = new_nr;
407
408 return 0;
409}
410
411/*
412 * Copy the BIOS e820 map into a safe place.
413 *
414 * Sanity-check it while we're at it..
415 *
416 * If we're lucky and live on a modern system, the setup code
417 * will have given us a memory map that we can use to properly
418 * set up memory. If we aren't, we'll fake a memory map.
419 *
420 * We check to see that the memory map contains at least 2 elements
421 * before we'll use it, because the detection code in setup.S may
422 * not be perfect and most every PC known to man has two memory
423 * regions: one from 0 to 640k, and one from 1mb up. (The IBM
424 * thinkpad 560x, for example, does not cooperate with the memory
425 * detection code.)
426 */
427int __init copy_e820_map(struct e820entry * biosmap, int nr_map)
428{
429 /* Only one memory region (or negative)? Ignore it */
430 if (nr_map < 2)
431 return -1;
432
433 do {
434 unsigned long long start = biosmap->addr;
435 unsigned long long size = biosmap->size;
436 unsigned long long end = start + size;
437 unsigned long type = biosmap->type;
438
439 /* Overflow in 64 bits? Ignore the memory map. */
440 if (start > end)
441 return -1;
442
443 /*
444 * Some BIOSes claim RAM in the 640k - 1M region.
445 * Not right. Fix it up.
446 */
447 if (type == E820_RAM) {
448 if (start < 0x100000ULL && end > 0xA0000ULL) {
449 if (start < 0xA0000ULL)
450 add_memory_region(start, 0xA0000ULL-start, type);
451 if (end <= 0x100000ULL)
452 continue;
453 start = 0x100000ULL;
454 size = end - start;
455 }
456 }
457 add_memory_region(start, size, type);
458 } while (biosmap++,--nr_map);
459 return 0;
460}
461
462#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) 222#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
463struct edd edd; 223struct edd edd;
464#ifdef CONFIG_EDD_MODULE 224#ifdef CONFIG_EDD_MODULE