malta-memory.c 3.7 KB

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