malta-memory.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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/fw/fw.h>
  30. #include <asm/mips-boards/prom.h>
  31. static fw_memblock_t mdesc[FW_MAX_MEMBLOCKS];
  32. /* determined physical memory size, not overridden by command line args */
  33. unsigned long physical_memsize = 0L;
  34. fw_memblock_t * __init fw_getmdesc(void)
  35. {
  36. char *memsize_str;
  37. unsigned int memsize;
  38. char *ptr;
  39. static char cmdline[COMMAND_LINE_SIZE] __initdata;
  40. /* otherwise look in the environment */
  41. memsize_str = fw_getenv("memsize");
  42. if (!memsize_str) {
  43. printk(KERN_WARNING
  44. "memsize not set in boot prom, set to default (32Mb)\n");
  45. physical_memsize = 0x02000000;
  46. } else {
  47. physical_memsize = simple_strtol(memsize_str, NULL, 0);
  48. }
  49. #ifdef CONFIG_CPU_BIG_ENDIAN
  50. /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
  51. word of physical memory */
  52. physical_memsize -= PAGE_SIZE;
  53. #endif
  54. /* Check the command line for a memsize directive that overrides
  55. the physical/default amount */
  56. strcpy(cmdline, arcs_cmdline);
  57. ptr = strstr(cmdline, "memsize=");
  58. if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
  59. ptr = strstr(ptr, " memsize=");
  60. if (ptr)
  61. memsize = memparse(ptr + 8, &ptr);
  62. else
  63. memsize = physical_memsize;
  64. memset(mdesc, 0, sizeof(mdesc));
  65. mdesc[0].type = fw_dontuse;
  66. mdesc[0].base = 0x00000000;
  67. mdesc[0].size = 0x00001000;
  68. mdesc[1].type = fw_code;
  69. mdesc[1].base = 0x00001000;
  70. mdesc[1].size = 0x000ef000;
  71. /*
  72. * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
  73. * south bridge and PCI access always forwarded to the ISA Bus and
  74. * BIOSCS# is always generated.
  75. * This mean that this area can't be used as DMA memory for PCI
  76. * devices.
  77. */
  78. mdesc[2].type = fw_dontuse;
  79. mdesc[2].base = 0x000f0000;
  80. mdesc[2].size = 0x00010000;
  81. mdesc[3].type = fw_dontuse;
  82. mdesc[3].base = 0x00100000;
  83. mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) - mdesc[3].base;
  84. mdesc[4].type = fw_free;
  85. mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
  86. mdesc[4].size = memsize - mdesc[4].base;
  87. return &mdesc[0];
  88. }
  89. static int __init fw_memtype_classify(unsigned int type)
  90. {
  91. switch (type) {
  92. case fw_free:
  93. return BOOT_MEM_RAM;
  94. case fw_code:
  95. return BOOT_MEM_ROM_DATA;
  96. default:
  97. return BOOT_MEM_RESERVED;
  98. }
  99. }
  100. void __init fw_meminit(void)
  101. {
  102. fw_memblock_t *p;
  103. p = fw_getmdesc();
  104. while (p->size) {
  105. long type;
  106. unsigned long base, size;
  107. type = fw_memtype_classify(p->type);
  108. base = p->base;
  109. size = p->size;
  110. add_memory_region(base, size, type);
  111. p++;
  112. }
  113. }
  114. void __init prom_free_prom_memory(void)
  115. {
  116. unsigned long addr;
  117. int i;
  118. for (i = 0; i < boot_mem_map.nr_map; i++) {
  119. if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
  120. continue;
  121. addr = boot_mem_map.map[i].addr;
  122. free_init_pages("prom memory",
  123. addr, addr + boot_mem_map.map[i].size);
  124. }
  125. }