sead3-memory.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
  7. */
  8. #include <linux/bootmem.h>
  9. #include <asm/bootinfo.h>
  10. #include <asm/sections.h>
  11. #include <asm/mips-boards/prom.h>
  12. enum yamon_memtypes {
  13. yamon_dontuse,
  14. yamon_prom,
  15. yamon_free,
  16. };
  17. static struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
  18. /* determined physical memory size, not overridden by command line args */
  19. unsigned long physical_memsize = 0L;
  20. struct prom_pmemblock * __init prom_getmdesc(void)
  21. {
  22. char *memsize_str, *ptr;
  23. unsigned int memsize;
  24. static char cmdline[COMMAND_LINE_SIZE] __initdata;
  25. long val;
  26. int tmp;
  27. /* otherwise look in the environment */
  28. memsize_str = prom_getenv("memsize");
  29. if (!memsize_str) {
  30. pr_warn("memsize not set in boot prom, set to default 32Mb\n");
  31. physical_memsize = 0x02000000;
  32. } else {
  33. tmp = kstrtol(memsize_str, 0, &val);
  34. physical_memsize = (unsigned long)val;
  35. }
  36. #ifdef CONFIG_CPU_BIG_ENDIAN
  37. /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
  38. word of physical memory */
  39. physical_memsize -= PAGE_SIZE;
  40. #endif
  41. /* Check the command line for a memsize directive that overrides
  42. the physical/default amount */
  43. strcpy(cmdline, arcs_cmdline);
  44. ptr = strstr(cmdline, "memsize=");
  45. if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
  46. ptr = strstr(ptr, " memsize=");
  47. if (ptr)
  48. memsize = memparse(ptr + 8, &ptr);
  49. else
  50. memsize = physical_memsize;
  51. memset(mdesc, 0, sizeof(mdesc));
  52. mdesc[0].type = yamon_dontuse;
  53. mdesc[0].base = 0x00000000;
  54. mdesc[0].size = 0x00001000;
  55. mdesc[1].type = yamon_prom;
  56. mdesc[1].base = 0x00001000;
  57. mdesc[1].size = 0x000ef000;
  58. /*
  59. * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
  60. * south bridge and PCI access always forwarded to the ISA Bus and
  61. * BIOSCS# is always generated.
  62. * This mean that this area can't be used as DMA memory for PCI
  63. * devices.
  64. */
  65. mdesc[2].type = yamon_dontuse;
  66. mdesc[2].base = 0x000f0000;
  67. mdesc[2].size = 0x00010000;
  68. mdesc[3].type = yamon_dontuse;
  69. mdesc[3].base = 0x00100000;
  70. mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) -
  71. mdesc[3].base;
  72. mdesc[4].type = yamon_free;
  73. mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
  74. mdesc[4].size = memsize - mdesc[4].base;
  75. return &mdesc[0];
  76. }
  77. static int __init prom_memtype_classify(unsigned int type)
  78. {
  79. switch (type) {
  80. case yamon_free:
  81. return BOOT_MEM_RAM;
  82. case yamon_prom:
  83. return BOOT_MEM_ROM_DATA;
  84. default:
  85. return BOOT_MEM_RESERVED;
  86. }
  87. }
  88. void __init prom_meminit(void)
  89. {
  90. struct prom_pmemblock *p;
  91. p = prom_getmdesc();
  92. while (p->size) {
  93. long type;
  94. unsigned long base, size;
  95. type = prom_memtype_classify(p->type);
  96. base = p->base;
  97. size = p->size;
  98. add_memory_region(base, size, type);
  99. p++;
  100. }
  101. }
  102. void __init prom_free_prom_memory(void)
  103. {
  104. unsigned long addr;
  105. int i;
  106. for (i = 0; i < boot_mem_map.nr_map; i++) {
  107. if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
  108. continue;
  109. addr = boot_mem_map.map[i].addr;
  110. free_init_pages("prom memory",
  111. addr, addr + boot_mem_map.map[i].size);
  112. }
  113. }