sim_mem.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.
  3. *
  4. * This program is free software; you can distribute it and/or modify it
  5. * under the terms of the GNU General Public License (Version 2) as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. * for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  16. *
  17. */
  18. #include <linux/init.h>
  19. #include <linux/mm.h>
  20. #include <linux/bootmem.h>
  21. #include <asm/bootinfo.h>
  22. #include <asm/page.h>
  23. #include <asm/sections.h>
  24. #include <asm/mips-boards/prom.h>
  25. /*#define DEBUG*/
  26. enum simmem_memtypes {
  27. simmem_reserved = 0,
  28. simmem_free,
  29. };
  30. struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
  31. #ifdef DEBUG
  32. static char *mtypes[3] = {
  33. "SIM reserved memory",
  34. "SIM free memory",
  35. };
  36. #endif
  37. struct prom_pmemblock * __init prom_getmdesc(void)
  38. {
  39. unsigned int memsize;
  40. memsize = 0x02000000;
  41. prom_printf("Setting default memory size 0x%08x\n", memsize);
  42. memset(mdesc, 0, sizeof(mdesc));
  43. mdesc[0].type = simmem_reserved;
  44. mdesc[0].base = 0x00000000;
  45. mdesc[0].size = 0x00001000;
  46. mdesc[1].type = simmem_free;
  47. mdesc[1].base = 0x00001000;
  48. mdesc[1].size = 0x000ff000;
  49. mdesc[2].type = simmem_reserved;
  50. mdesc[2].base = 0x00100000;
  51. mdesc[2].size = CPHYSADDR(PAGE_ALIGN(&_end)) - mdesc[2].base;
  52. mdesc[3].type = simmem_free;
  53. mdesc[3].base = CPHYSADDR(PAGE_ALIGN(&_end));
  54. mdesc[3].size = memsize - mdesc[3].base;
  55. return &mdesc[0];
  56. }
  57. static int __init prom_memtype_classify (unsigned int type)
  58. {
  59. switch (type) {
  60. case simmem_free:
  61. return BOOT_MEM_RAM;
  62. case simmem_reserved:
  63. default:
  64. return BOOT_MEM_RESERVED;
  65. }
  66. }
  67. void __init prom_meminit(void)
  68. {
  69. struct prom_pmemblock *p;
  70. p = prom_getmdesc();
  71. while (p->size) {
  72. long type;
  73. unsigned long base, size;
  74. type = prom_memtype_classify (p->type);
  75. base = p->base;
  76. size = p->size;
  77. add_memory_region(base, size, type);
  78. p++;
  79. }
  80. }
  81. unsigned long __init prom_free_prom_memory(void)
  82. {
  83. int i;
  84. unsigned long freed = 0;
  85. unsigned long addr;
  86. for (i = 0; i < boot_mem_map.nr_map; i++) {
  87. if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
  88. continue;
  89. addr = boot_mem_map.map[i].addr;
  90. while (addr < boot_mem_map.map[i].addr
  91. + boot_mem_map.map[i].size) {
  92. ClearPageReserved(virt_to_page(__va(addr)));
  93. init_page_count(virt_to_page(__va(addr)));
  94. free_page((unsigned long)__va(addr));
  95. addr += PAGE_SIZE;
  96. freed += PAGE_SIZE;
  97. }
  98. }
  99. printk("Freeing prom memory: %ldkb freed\n", freed >> 10);
  100. return freed;
  101. }