head.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <linux/kernel.h>
  2. #include <linux/init.h>
  3. #include <linux/memblock.h>
  4. #include <asm/setup.h>
  5. #include <asm/bios_ebda.h>
  6. /*
  7. * The BIOS places the EBDA/XBDA at the top of conventional
  8. * memory, and usually decreases the reported amount of
  9. * conventional memory (int 0x12) too. This also contains a
  10. * workaround for Dell systems that neglect to reserve EBDA.
  11. * The same workaround also avoids a problem with the AMD768MPX
  12. * chipset: reserve a page before VGA to prevent PCI prefetch
  13. * into it (errata #56). Usually the page is reserved anyways,
  14. * unless you have no PS/2 mouse plugged in.
  15. *
  16. * This functions is deliberately very conservative. Losing
  17. * memory in the bottom megabyte is rarely a problem, as long
  18. * as we have enough memory to install the trampoline. Using
  19. * memory that is in use by the BIOS or by some DMA device
  20. * the BIOS didn't shut down *is* a big problem.
  21. */
  22. #define BIOS_LOWMEM_KILOBYTES 0x413
  23. #define LOWMEM_CAP 0x9f000U /* Absolute maximum */
  24. #define INSANE_CUTOFF 0x20000U /* Less than this = insane */
  25. void __init reserve_ebda_region(void)
  26. {
  27. unsigned int lowmem, ebda_addr;
  28. /*
  29. * To determine the position of the EBDA and the
  30. * end of conventional memory, we need to look at
  31. * the BIOS data area. In a paravirtual environment
  32. * that area is absent. We'll just have to assume
  33. * that the paravirt case can handle memory setup
  34. * correctly, without our help.
  35. */
  36. if (paravirt_enabled())
  37. return;
  38. /* end of low (conventional) memory */
  39. lowmem = *(unsigned short *)__va(BIOS_LOWMEM_KILOBYTES);
  40. lowmem <<= 10;
  41. /* start of EBDA area */
  42. ebda_addr = get_bios_ebda();
  43. /*
  44. * Note: some old Dells seem to need 4k EBDA without
  45. * reporting so, so just consider the memory above 0x9f000
  46. * to be off limits (bugzilla 2990).
  47. */
  48. /* If the EBDA address is below 128K, assume it is bogus */
  49. if (ebda_addr < INSANE_CUTOFF)
  50. ebda_addr = LOWMEM_CAP;
  51. /* If lowmem is less than 128K, assume it is bogus */
  52. if (lowmem < INSANE_CUTOFF)
  53. lowmem = LOWMEM_CAP;
  54. /* Use the lower of the lowmem and EBDA markers as the cutoff */
  55. lowmem = min(lowmem, ebda_addr);
  56. lowmem = min(lowmem, LOWMEM_CAP); /* Absolute cap */
  57. /* reserve all memory between lowmem and the 1MB mark */
  58. memblock_reserve(lowmem, 0x100000 - lowmem);
  59. }