sim_mem.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 <linux/pfn.h>
  22. #include <asm/bootinfo.h>
  23. #include <asm/page.h>
  24. #include <asm/sections.h>
  25. #include <asm/mips-boards/prom.h>
  26. /*#define DEBUG*/
  27. enum simmem_memtypes {
  28. simmem_reserved = 0,
  29. simmem_free,
  30. };
  31. struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
  32. #ifdef DEBUG
  33. static char *mtypes[3] = {
  34. "SIM reserved memory",
  35. "SIM free memory",
  36. };
  37. #endif
  38. struct prom_pmemblock * __init prom_getmdesc(void)
  39. {
  40. unsigned int memsize;
  41. memsize = 0x02000000;
  42. pr_info("Setting default memory size 0x%08x\n", memsize);
  43. memset(mdesc, 0, sizeof(mdesc));
  44. mdesc[0].type = simmem_reserved;
  45. mdesc[0].base = 0x00000000;
  46. mdesc[0].size = 0x00001000;
  47. mdesc[1].type = simmem_free;
  48. mdesc[1].base = 0x00001000;
  49. mdesc[1].size = 0x000ff000;
  50. mdesc[2].type = simmem_reserved;
  51. mdesc[2].base = 0x00100000;
  52. mdesc[2].size = CPHYSADDR(PFN_ALIGN(&_end)) - mdesc[2].base;
  53. mdesc[3].type = simmem_free;
  54. mdesc[3].base = CPHYSADDR(PFN_ALIGN(&_end));
  55. mdesc[3].size = memsize - mdesc[3].base;
  56. return &mdesc[0];
  57. }
  58. static int __init prom_memtype_classify(unsigned int type)
  59. {
  60. switch (type) {
  61. case simmem_free:
  62. return BOOT_MEM_RAM;
  63. case simmem_reserved:
  64. default:
  65. return BOOT_MEM_RESERVED;
  66. }
  67. }
  68. void __init prom_meminit(void)
  69. {
  70. struct prom_pmemblock *p;
  71. p = prom_getmdesc();
  72. while (p->size) {
  73. long type;
  74. unsigned long base, size;
  75. type = prom_memtype_classify(p->type);
  76. base = p->base;
  77. size = p->size;
  78. add_memory_region(base, size, type);
  79. p++;
  80. }
  81. }
  82. void __init prom_free_prom_memory(void)
  83. {
  84. int i;
  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. free_init_pages("prom memory",
  91. addr, addr + boot_mem_map.map[i].size);
  92. }
  93. }