dram.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
  4. */
  5. #include <common.h>
  6. #include <init.h>
  7. #include <asm/post.h>
  8. #include <asm/arch/qemu.h>
  9. DECLARE_GLOBAL_DATA_PTR;
  10. u32 qemu_get_low_memory_size(void)
  11. {
  12. u32 ram;
  13. outb(HIGH_RAM_ADDR, CMOS_ADDR_PORT);
  14. ram = ((u32)inb(CMOS_DATA_PORT)) << 14;
  15. outb(LOW_RAM_ADDR, CMOS_ADDR_PORT);
  16. ram |= ((u32)inb(CMOS_DATA_PORT)) << 6;
  17. ram += 16 * 1024;
  18. return ram * 1024;
  19. }
  20. u64 qemu_get_high_memory_size(void)
  21. {
  22. u64 ram;
  23. outb(HIGH_HIGHRAM_ADDR, CMOS_ADDR_PORT);
  24. ram = ((u64)inb(CMOS_DATA_PORT)) << 22;
  25. outb(MID_HIGHRAM_ADDR, CMOS_ADDR_PORT);
  26. ram |= ((u64)inb(CMOS_DATA_PORT)) << 14;
  27. outb(LOW_HIGHRAM_ADDR, CMOS_ADDR_PORT);
  28. ram |= ((u64)inb(CMOS_DATA_PORT)) << 6;
  29. return ram * 1024;
  30. }
  31. int dram_init(void)
  32. {
  33. gd->ram_size = qemu_get_low_memory_size();
  34. gd->ram_size += qemu_get_high_memory_size();
  35. post_code(POST_DRAM);
  36. return 0;
  37. }
  38. int dram_init_banksize(void)
  39. {
  40. u64 high_mem_size;
  41. gd->bd->bi_dram[0].start = 0;
  42. gd->bd->bi_dram[0].size = qemu_get_low_memory_size();
  43. high_mem_size = qemu_get_high_memory_size();
  44. if (high_mem_size) {
  45. gd->bd->bi_dram[1].start = SZ_4G;
  46. gd->bd->bi_dram[1].size = high_mem_size;
  47. }
  48. return 0;
  49. }
  50. /*
  51. * This function looks for the highest region of memory lower than 4GB which
  52. * has enough space for U-Boot where U-Boot is aligned on a page boundary.
  53. * It overrides the default implementation found elsewhere which simply
  54. * picks the end of ram, wherever that may be. The location of the stack,
  55. * the relocation address, and how far U-Boot is moved by relocation are
  56. * set in the global data structure.
  57. */
  58. ulong board_get_usable_ram_top(ulong total_size)
  59. {
  60. return qemu_get_low_memory_size();
  61. }