memory.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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/config.h>
  22. #include <linux/init.h>
  23. #include <linux/mm.h>
  24. #include <linux/bootmem.h>
  25. #include <linux/pfn.h>
  26. #include <linux/string.h>
  27. #include <asm/bootinfo.h>
  28. #include <asm/page.h>
  29. #include <asm/sections.h>
  30. #include <asm/mips-boards/prom.h>
  31. /*#define DEBUG*/
  32. enum yamon_memtypes {
  33. yamon_dontuse,
  34. yamon_prom,
  35. yamon_free,
  36. };
  37. struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
  38. #ifdef DEBUG
  39. static char *mtypes[3] = {
  40. "Dont use memory",
  41. "YAMON PROM memory",
  42. "Free memmory",
  43. };
  44. #endif
  45. struct prom_pmemblock * __init prom_getmdesc(void)
  46. {
  47. char *memsize_str;
  48. unsigned int memsize;
  49. char cmdline[CL_SIZE], *ptr;
  50. /* Check the command line first for a memsize directive */
  51. strcpy(cmdline, arcs_cmdline);
  52. ptr = strstr(cmdline, "memsize=");
  53. if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
  54. ptr = strstr(ptr, " memsize=");
  55. if (ptr) {
  56. memsize = memparse(ptr + 8, &ptr);
  57. }
  58. else {
  59. /* otherwise look in the environment */
  60. memsize_str = prom_getenv("memsize");
  61. if (!memsize_str) {
  62. prom_printf("memsize not set in boot prom, set to default (32Mb)\n");
  63. memsize = 0x02000000;
  64. } else {
  65. #ifdef DEBUG
  66. prom_printf("prom_memsize = %s\n", memsize_str);
  67. #endif
  68. memsize = simple_strtol(memsize_str, NULL, 0);
  69. }
  70. }
  71. memset(mdesc, 0, sizeof(mdesc));
  72. mdesc[0].type = yamon_dontuse;
  73. mdesc[0].base = 0x00000000;
  74. mdesc[0].size = 0x00001000;
  75. mdesc[1].type = yamon_prom;
  76. mdesc[1].base = 0x00001000;
  77. mdesc[1].size = 0x000ef000;
  78. #ifdef CONFIG_MIPS_MALTA
  79. /*
  80. * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
  81. * south bridge and PCI access always forwarded to the ISA Bus and
  82. * BIOSCS# is always generated.
  83. * This mean that this area can't be used as DMA memory for PCI
  84. * devices.
  85. */
  86. mdesc[2].type = yamon_dontuse;
  87. mdesc[2].base = 0x000f0000;
  88. mdesc[2].size = 0x00010000;
  89. #else
  90. mdesc[2].type = yamon_prom;
  91. mdesc[2].base = 0x000f0000;
  92. mdesc[2].size = 0x00010000;
  93. #endif
  94. mdesc[3].type = yamon_dontuse;
  95. mdesc[3].base = 0x00100000;
  96. mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) - mdesc[3].base;
  97. mdesc[4].type = yamon_free;
  98. mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
  99. mdesc[4].size = memsize - mdesc[4].base;
  100. return &mdesc[0];
  101. }
  102. static int __init prom_memtype_classify (unsigned int type)
  103. {
  104. switch (type) {
  105. case yamon_free:
  106. return BOOT_MEM_RAM;
  107. case yamon_prom:
  108. return BOOT_MEM_ROM_DATA;
  109. default:
  110. return BOOT_MEM_RESERVED;
  111. }
  112. }
  113. void __init prom_meminit(void)
  114. {
  115. struct prom_pmemblock *p;
  116. #ifdef DEBUG
  117. prom_printf("YAMON MEMORY DESCRIPTOR dump:\n");
  118. p = prom_getmdesc();
  119. while (p->size) {
  120. int i = 0;
  121. prom_printf("[%d,%p]: base<%08lx> size<%08lx> type<%s>\n",
  122. i, p, p->base, p->size, mtypes[p->type]);
  123. p++;
  124. i++;
  125. }
  126. #endif
  127. p = prom_getmdesc();
  128. while (p->size) {
  129. long type;
  130. unsigned long base, size;
  131. type = prom_memtype_classify (p->type);
  132. base = p->base;
  133. size = p->size;
  134. add_memory_region(base, size, type);
  135. p++;
  136. }
  137. }
  138. unsigned long __init prom_free_prom_memory(void)
  139. {
  140. unsigned long freed = 0;
  141. unsigned long addr;
  142. int i;
  143. for (i = 0; i < boot_mem_map.nr_map; i++) {
  144. if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
  145. continue;
  146. addr = boot_mem_map.map[i].addr;
  147. while (addr < boot_mem_map.map[i].addr
  148. + boot_mem_map.map[i].size) {
  149. ClearPageReserved(virt_to_page(__va(addr)));
  150. init_page_count(virt_to_page(__va(addr)));
  151. free_page((unsigned long)__va(addr));
  152. addr += PAGE_SIZE;
  153. freed += PAGE_SIZE;
  154. }
  155. }
  156. printk("Freeing prom memory: %ldkb freed\n", freed >> 10);
  157. return freed;
  158. }