sim_mem.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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/mips-boards/prom.h>
  24. /*#define DEBUG*/
  25. enum simmem_memtypes {
  26. simmem_reserved = 0,
  27. simmem_free,
  28. };
  29. struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
  30. #ifdef DEBUG
  31. static char *mtypes[3] = {
  32. "SIM reserved memory",
  33. "SIM free memory",
  34. };
  35. #endif
  36. /* References to section boundaries */
  37. extern char _end;
  38. #define PFN_ALIGN(x) (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK)
  39. struct prom_pmemblock * __init prom_getmdesc(void)
  40. {
  41. unsigned int memsize;
  42. memsize = 0x02000000;
  43. prom_printf("Setting default memory size 0x%08x\n", memsize);
  44. memset(mdesc, 0, sizeof(mdesc));
  45. mdesc[0].type = simmem_reserved;
  46. mdesc[0].base = 0x00000000;
  47. mdesc[0].size = 0x00001000;
  48. mdesc[1].type = simmem_free;
  49. mdesc[1].base = 0x00001000;
  50. mdesc[1].size = 0x000ff000;
  51. mdesc[2].type = simmem_reserved;
  52. mdesc[2].base = 0x00100000;
  53. mdesc[2].size = CPHYSADDR(PFN_ALIGN(&_end)) - mdesc[2].base;
  54. mdesc[3].type = simmem_free;
  55. mdesc[3].base = CPHYSADDR(PFN_ALIGN(&_end));
  56. mdesc[3].size = memsize - mdesc[3].base;
  57. return &mdesc[0];
  58. }
  59. static int __init prom_memtype_classify (unsigned int type)
  60. {
  61. switch (type) {
  62. case simmem_free:
  63. return BOOT_MEM_RAM;
  64. case simmem_reserved:
  65. default:
  66. return BOOT_MEM_RESERVED;
  67. }
  68. }
  69. void __init prom_meminit(void)
  70. {
  71. struct prom_pmemblock *p;
  72. p = prom_getmdesc();
  73. while (p->size) {
  74. long type;
  75. unsigned long base, size;
  76. type = prom_memtype_classify (p->type);
  77. base = p->base;
  78. size = p->size;
  79. add_memory_region(base, size, type);
  80. p++;
  81. }
  82. }
  83. unsigned long __init prom_free_prom_memory(void)
  84. {
  85. int i;
  86. unsigned long freed = 0;
  87. unsigned long addr;
  88. for (i = 0; i < boot_mem_map.nr_map; i++) {
  89. if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
  90. continue;
  91. addr = boot_mem_map.map[i].addr;
  92. while (addr < boot_mem_map.map[i].addr
  93. + boot_mem_map.map[i].size) {
  94. ClearPageReserved(virt_to_page(__va(addr)));
  95. set_page_count(virt_to_page(__va(addr)), 1);
  96. free_page((unsigned long)__va(addr));
  97. addr += PAGE_SIZE;
  98. freed += PAGE_SIZE;
  99. }
  100. }
  101. printk("Freeing prom memory: %ldkb freed\n", freed >> 10);
  102. return freed;
  103. }