malta-memory.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * PROM library functions for acquiring/using memory descriptors given to
  7. * us from the YAMON.
  8. *
  9. * Copyright (C) 1999,2000,2012 MIPS Technologies, Inc.
  10. * All rights reserved.
  11. * Authors: Carsten Langgaard <carstenl@mips.com>
  12. * Steven J. Hill <sjhill@mips.com>
  13. */
  14. #include <linux/init.h>
  15. #include <linux/bootmem.h>
  16. #include <linux/string.h>
  17. #include <asm/bootinfo.h>
  18. #include <asm/maar.h>
  19. #include <asm/sections.h>
  20. #include <asm/fw/fw.h>
  21. static fw_memblock_t mdesc[FW_MAX_MEMBLOCKS];
  22. /* determined physical memory size, not overridden by command line args */
  23. unsigned long physical_memsize = 0L;
  24. fw_memblock_t * __init fw_getmdesc(int eva)
  25. {
  26. char *memsize_str, *ememsize_str = NULL, *ptr;
  27. unsigned long memsize = 0, ememsize = 0;
  28. static char cmdline[COMMAND_LINE_SIZE] __initdata;
  29. int tmp;
  30. /* otherwise look in the environment */
  31. memsize_str = fw_getenv("memsize");
  32. if (memsize_str) {
  33. tmp = kstrtoul(memsize_str, 0, &memsize);
  34. if (tmp)
  35. pr_warn("Failed to read the 'memsize' env variable.\n");
  36. }
  37. if (eva) {
  38. /* Look for ememsize for EVA */
  39. ememsize_str = fw_getenv("ememsize");
  40. if (ememsize_str) {
  41. tmp = kstrtoul(ememsize_str, 0, &ememsize);
  42. if (tmp)
  43. pr_warn("Failed to read the 'ememsize' env variable.\n");
  44. }
  45. }
  46. if (!memsize && !ememsize) {
  47. pr_warn("memsize not set in YAMON, set to default (32Mb)\n");
  48. physical_memsize = 0x02000000;
  49. } else {
  50. if (memsize > (256 << 20)) { /* memsize should be capped to 256M */
  51. pr_warn("Unsupported memsize value (0x%lx) detected! "
  52. "Using 0x10000000 (256M) instead\n",
  53. memsize);
  54. memsize = 256 << 20;
  55. }
  56. /* If ememsize is set, then set physical_memsize to that */
  57. physical_memsize = ememsize ? : memsize;
  58. }
  59. #ifdef CONFIG_CPU_BIG_ENDIAN
  60. /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
  61. word of physical memory */
  62. physical_memsize -= PAGE_SIZE;
  63. #endif
  64. /* Check the command line for a memsize directive that overrides
  65. the physical/default amount */
  66. strcpy(cmdline, arcs_cmdline);
  67. ptr = strstr(cmdline, "memsize=");
  68. if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
  69. ptr = strstr(ptr, " memsize=");
  70. /* And now look for ememsize */
  71. if (eva) {
  72. ptr = strstr(cmdline, "ememsize=");
  73. if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
  74. ptr = strstr(ptr, " ememsize=");
  75. }
  76. if (ptr)
  77. memsize = memparse(ptr + 8 + (eva ? 1 : 0), &ptr);
  78. else
  79. memsize = physical_memsize;
  80. /* Last 64K for HIGHMEM arithmetics */
  81. if (memsize > 0x7fff0000)
  82. memsize = 0x7fff0000;
  83. memset(mdesc, 0, sizeof(mdesc));
  84. mdesc[0].type = fw_dontuse;
  85. mdesc[0].base = PHYS_OFFSET;
  86. mdesc[0].size = 0x00001000;
  87. mdesc[1].type = fw_code;
  88. mdesc[1].base = mdesc[0].base + 0x00001000UL;
  89. mdesc[1].size = 0x000ef000;
  90. /*
  91. * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
  92. * south bridge and PCI access always forwarded to the ISA Bus and
  93. * BIOSCS# is always generated.
  94. * This mean that this area can't be used as DMA memory for PCI
  95. * devices.
  96. */
  97. mdesc[2].type = fw_dontuse;
  98. mdesc[2].base = mdesc[0].base + 0x000f0000UL;
  99. mdesc[2].size = 0x00010000;
  100. mdesc[3].type = fw_dontuse;
  101. mdesc[3].base = mdesc[0].base + 0x00100000UL;
  102. mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) -
  103. 0x00100000UL;
  104. mdesc[4].type = fw_free;
  105. mdesc[4].base = mdesc[0].base + CPHYSADDR(PFN_ALIGN(&_end));
  106. mdesc[4].size = memsize - CPHYSADDR(mdesc[4].base);
  107. return &mdesc[0];
  108. }
  109. static void free_init_pages_eva_malta(void *begin, void *end)
  110. {
  111. free_init_pages("unused kernel", __pa_symbol((unsigned long *)begin),
  112. __pa_symbol((unsigned long *)end));
  113. }
  114. static int __init fw_memtype_classify(unsigned int type)
  115. {
  116. switch (type) {
  117. case fw_free:
  118. return BOOT_MEM_RAM;
  119. case fw_code:
  120. return BOOT_MEM_ROM_DATA;
  121. default:
  122. return BOOT_MEM_RESERVED;
  123. }
  124. }
  125. void __init fw_meminit(void)
  126. {
  127. fw_memblock_t *p;
  128. p = fw_getmdesc(config_enabled(CONFIG_EVA));
  129. free_init_pages_eva = (config_enabled(CONFIG_EVA) ?
  130. free_init_pages_eva_malta : NULL);
  131. while (p->size) {
  132. long type;
  133. unsigned long base, size;
  134. type = fw_memtype_classify(p->type);
  135. base = p->base;
  136. size = p->size;
  137. add_memory_region(base, size, type);
  138. p++;
  139. }
  140. }
  141. void __init prom_free_prom_memory(void)
  142. {
  143. unsigned long addr;
  144. int i;
  145. for (i = 0; i < boot_mem_map.nr_map; i++) {
  146. if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
  147. continue;
  148. addr = boot_mem_map.map[i].addr;
  149. free_init_pages("YAMON memory",
  150. addr, addr + boot_mem_map.map[i].size);
  151. }
  152. }
  153. unsigned platform_maar_init(unsigned num_pairs)
  154. {
  155. phys_addr_t mem_end = (physical_memsize & ~0xffffull) - 1;
  156. struct maar_config cfg[] = {
  157. /* DRAM preceding I/O */
  158. { 0x00000000, 0x0fffffff, MIPS_MAAR_S },
  159. /* DRAM following I/O */
  160. { 0x20000000, mem_end, MIPS_MAAR_S },
  161. /* DRAM alias in upper half of physical */
  162. { 0x80000000, 0x80000000 + mem_end, MIPS_MAAR_S },
  163. };
  164. unsigned i, num_cfg = ARRAY_SIZE(cfg);
  165. /* If DRAM fits before I/O, drop the region following it */
  166. if (physical_memsize <= 0x10000000) {
  167. num_cfg--;
  168. for (i = 1; i < num_cfg; i++)
  169. cfg[i] = cfg[i + 1];
  170. }
  171. return maar_config(cfg, num_cfg, num_pairs);
  172. }