memory.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  4. * Portions copyright (C) 2009 Cisco Systems, Inc.
  5. *
  6. * This program is free software; you can distribute it and/or modify it
  7. * under the terms of the GNU General Public License (Version 2) as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  18. *
  19. * Apparently originally from arch/mips/malta-memory.c. Modified to work
  20. * with the PowerTV bootloader.
  21. */
  22. #include <linux/init.h>
  23. #include <linux/mm.h>
  24. #include <linux/bootmem.h>
  25. #include <linux/pfn.h>
  26. #include <linux/string.h>
  27. #include <asm/bootinfo.h>
  28. #include <asm/page.h>
  29. #include <asm/sections.h>
  30. #include <asm/mips-boards/prom.h>
  31. #include "init.h"
  32. /* Memory constants */
  33. #define KIBIBYTE(n) ((n) * 1024) /* Number of kibibytes */
  34. #define MEBIBYTE(n) ((n) * KIBIBYTE(1024)) /* Number of mebibytes */
  35. #define DEFAULT_MEMSIZE MEBIBYTE(256) /* If no memsize provided */
  36. #define LOW_MEM_MAX MEBIBYTE(252) /* Max usable low mem */
  37. #define RES_BOOTLDR_MEMSIZE MEBIBYTE(1) /* Memory reserved for bldr */
  38. #define BOOT_MEM_SIZE KIBIBYTE(256) /* Memory reserved for bldr */
  39. #define PHYS_MEM_START 0x10000000 /* Start of physical memory */
  40. char __initdata cmdline[COMMAND_LINE_SIZE];
  41. void __init prom_meminit(void)
  42. {
  43. char *memsize_str;
  44. unsigned long memsize = 0;
  45. unsigned int physend;
  46. char *ptr;
  47. int low_mem;
  48. int high_mem;
  49. /* Check the command line first for a memsize directive */
  50. strcpy(cmdline, arcs_cmdline);
  51. ptr = strstr(cmdline, "memsize=");
  52. if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
  53. ptr = strstr(ptr, " memsize=");
  54. if (ptr) {
  55. memsize = memparse(ptr + 8, &ptr);
  56. } else {
  57. /* otherwise look in the environment */
  58. memsize_str = prom_getenv("memsize");
  59. if (memsize_str != NULL) {
  60. pr_info("prom memsize = %s\n", memsize_str);
  61. memsize = simple_strtol(memsize_str, NULL, 0);
  62. }
  63. if (memsize == 0) {
  64. if (_prom_memsize != 0) {
  65. memsize = _prom_memsize;
  66. pr_info("_prom_memsize = 0x%lx\n", memsize);
  67. /* add in memory that the bootloader doesn't
  68. * report */
  69. memsize += BOOT_MEM_SIZE;
  70. } else {
  71. memsize = DEFAULT_MEMSIZE;
  72. pr_info("Memsize not passed by bootloader, "
  73. "defaulting to 0x%lx\n", memsize);
  74. }
  75. }
  76. }
  77. physend = PFN_ALIGN(&_end) - 0x80000000;
  78. if (memsize > LOW_MEM_MAX) {
  79. low_mem = LOW_MEM_MAX;
  80. high_mem = memsize - low_mem;
  81. } else {
  82. low_mem = memsize;
  83. high_mem = 0;
  84. }
  85. /*
  86. * TODO: We will use the hard code for memory configuration until
  87. * the bootloader releases their device tree to us.
  88. */
  89. /*
  90. * Add the memory reserved for use by the bootloader to the
  91. * memory map.
  92. */
  93. add_memory_region(PHYS_MEM_START, RES_BOOTLDR_MEMSIZE,
  94. BOOT_MEM_RESERVED);
  95. #ifdef CONFIG_HIGHMEM_256_128
  96. /*
  97. * Add memory in low for general use by the kernel and its friends
  98. * (like drivers, applications, etc).
  99. */
  100. add_memory_region(PHYS_MEM_START + RES_BOOTLDR_MEMSIZE,
  101. LOW_MEM_MAX - RES_BOOTLDR_MEMSIZE, BOOT_MEM_RAM);
  102. /*
  103. * Add the memory reserved for reset vector.
  104. */
  105. add_memory_region(0x1fc00000, MEBIBYTE(4), BOOT_MEM_RESERVED);
  106. /*
  107. * Add the memory reserved.
  108. */
  109. add_memory_region(0x20000000, MEBIBYTE(1024 + 75), BOOT_MEM_RESERVED);
  110. /*
  111. * Add memory in high for general use by the kernel and its friends
  112. * (like drivers, applications, etc).
  113. *
  114. * 75MB is reserved for devices which are using the memory in high.
  115. */
  116. add_memory_region(0x60000000 + MEBIBYTE(75), MEBIBYTE(128 - 75),
  117. BOOT_MEM_RAM);
  118. #elif defined CONFIG_HIGHMEM_128_128
  119. /*
  120. * Add memory in low for general use by the kernel and its friends
  121. * (like drivers, applications, etc).
  122. */
  123. add_memory_region(PHYS_MEM_START + RES_BOOTLDR_MEMSIZE,
  124. MEBIBYTE(128) - RES_BOOTLDR_MEMSIZE, BOOT_MEM_RAM);
  125. /*
  126. * Add the memory reserved.
  127. */
  128. add_memory_region(PHYS_MEM_START + MEBIBYTE(128),
  129. MEBIBYTE(128 + 1024 + 75), BOOT_MEM_RESERVED);
  130. /*
  131. * Add memory in high for general use by the kernel and its friends
  132. * (like drivers, applications, etc).
  133. *
  134. * 75MB is reserved for devices which are using the memory in high.
  135. */
  136. add_memory_region(0x60000000 + MEBIBYTE(75), MEBIBYTE(128 - 75),
  137. BOOT_MEM_RAM);
  138. #else
  139. /* Add low memory regions for either:
  140. * - no-highmemory configuration case -OR-
  141. * - highmemory "HIGHMEM_LOWBANK_ONLY" case
  142. */
  143. /*
  144. * Add memory for general use by the kernel and its friends
  145. * (like drivers, applications, etc).
  146. */
  147. add_memory_region(PHYS_MEM_START + RES_BOOTLDR_MEMSIZE,
  148. low_mem - RES_BOOTLDR_MEMSIZE, BOOT_MEM_RAM);
  149. /*
  150. * Add the memory reserved for reset vector.
  151. */
  152. add_memory_region(0x1fc00000, MEBIBYTE(4), BOOT_MEM_RESERVED);
  153. #endif
  154. }
  155. void __init prom_free_prom_memory(void)
  156. {
  157. unsigned long addr;
  158. int i;
  159. for (i = 0; i < boot_mem_map.nr_map; i++) {
  160. if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
  161. continue;
  162. addr = boot_mem_map.map[i].addr;
  163. free_init_pages("prom memory",
  164. addr, addr + boot_mem_map.map[i].size);
  165. }
  166. }