memory.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  4. *
  5. * This program is free software; you can distribute it and/or modify it
  6. * under the terms of the GNU General Public License (Version 2) as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  17. *
  18. * PROM library functions for acquiring/using memory descriptors given to
  19. * us from the YAMON.
  20. */
  21. #include <linux/init.h>
  22. #include <linux/mm.h>
  23. #include <linux/bootmem.h>
  24. #include <linux/pfn.h>
  25. #include <linux/string.h>
  26. #include <asm/bootinfo.h>
  27. #include <asm/page.h>
  28. #include <asm/sections.h>
  29. #include <asm/mips-boards/prom.h>
  30. /*#define DEBUG*/
  31. enum yamon_memtypes {
  32. yamon_dontuse,
  33. yamon_prom,
  34. yamon_free,
  35. };
  36. struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
  37. #ifdef DEBUG
  38. static char *mtypes[3] = {
  39. "Dont use memory",
  40. "YAMON PROM memory",
  41. "Free memmory",
  42. };
  43. #endif
  44. /* determined physical memory size, not overridden by command line args */
  45. unsigned long physical_memsize = 0L;
  46. struct prom_pmemblock * __init prom_getmdesc(void)
  47. {
  48. char *memsize_str;
  49. unsigned int memsize;
  50. char cmdline[CL_SIZE], *ptr;
  51. /* otherwise look in the environment */
  52. memsize_str = prom_getenv("memsize");
  53. if (!memsize_str) {
  54. printk(KERN_WARNING
  55. "memsize not set in boot prom, set to default (32Mb)\n");
  56. physical_memsize = 0x02000000;
  57. } else {
  58. #ifdef DEBUG
  59. pr_debug("prom_memsize = %s\n", memsize_str);
  60. #endif
  61. physical_memsize = simple_strtol(memsize_str, NULL, 0);
  62. }
  63. #ifdef CONFIG_CPU_BIG_ENDIAN
  64. /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
  65. word of physical memory */
  66. physical_memsize -= PAGE_SIZE;
  67. #endif
  68. /* Check the command line for a memsize directive that overrides
  69. the physical/default amount */
  70. strcpy(cmdline, arcs_cmdline);
  71. ptr = strstr(cmdline, "memsize=");
  72. if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
  73. ptr = strstr(ptr, " memsize=");
  74. if (ptr)
  75. memsize = memparse(ptr + 8, &ptr);
  76. else
  77. memsize = physical_memsize;
  78. memset(mdesc, 0, sizeof(mdesc));
  79. mdesc[0].type = yamon_dontuse;
  80. mdesc[0].base = 0x00000000;
  81. mdesc[0].size = 0x00001000;
  82. mdesc[1].type = yamon_prom;
  83. mdesc[1].base = 0x00001000;
  84. mdesc[1].size = 0x000ef000;
  85. #ifdef CONFIG_MIPS_MALTA
  86. /*
  87. * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
  88. * south bridge and PCI access always forwarded to the ISA Bus and
  89. * BIOSCS# is always generated.
  90. * This mean that this area can't be used as DMA memory for PCI
  91. * devices.
  92. */
  93. mdesc[2].type = yamon_dontuse;
  94. mdesc[2].base = 0x000f0000;
  95. mdesc[2].size = 0x00010000;
  96. #else
  97. mdesc[2].type = yamon_prom;
  98. mdesc[2].base = 0x000f0000;
  99. mdesc[2].size = 0x00010000;
  100. #endif
  101. mdesc[3].type = yamon_dontuse;
  102. mdesc[3].base = 0x00100000;
  103. mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) - mdesc[3].base;
  104. mdesc[4].type = yamon_free;
  105. mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
  106. mdesc[4].size = memsize - mdesc[4].base;
  107. return &mdesc[0];
  108. }
  109. static int __init prom_memtype_classify(unsigned int type)
  110. {
  111. switch (type) {
  112. case yamon_free:
  113. return BOOT_MEM_RAM;
  114. case yamon_prom:
  115. return BOOT_MEM_ROM_DATA;
  116. default:
  117. return BOOT_MEM_RESERVED;
  118. }
  119. }
  120. void __init prom_meminit(void)
  121. {
  122. struct prom_pmemblock *p;
  123. #ifdef DEBUG
  124. pr_debug("YAMON MEMORY DESCRIPTOR dump:\n");
  125. p = prom_getmdesc();
  126. while (p->size) {
  127. int i = 0;
  128. pr_debug("[%d,%p]: base<%08lx> size<%08lx> type<%s>\n",
  129. i, p, p->base, p->size, mtypes[p->type]);
  130. p++;
  131. i++;
  132. }
  133. #endif
  134. p = prom_getmdesc();
  135. while (p->size) {
  136. long type;
  137. unsigned long base, size;
  138. type = prom_memtype_classify(p->type);
  139. base = p->base;
  140. size = p->size;
  141. add_memory_region(base, size, type);
  142. p++;
  143. }
  144. }
  145. void __init prom_free_prom_memory(void)
  146. {
  147. unsigned long addr;
  148. int i;
  149. for (i = 0; i < boot_mem_map.nr_map; i++) {
  150. if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
  151. continue;
  152. addr = boot_mem_map.map[i].addr;
  153. free_init_pages("prom memory",
  154. addr, addr + boot_mem_map.map[i].size);
  155. }
  156. }