init.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * File: arch/blackfin/mm/init.c
  3. * Based on:
  4. * Author:
  5. *
  6. * Created:
  7. * Description:
  8. *
  9. * Modified:
  10. * Copyright 2004-2007 Analog Devices Inc.
  11. *
  12. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, see the file COPYING, or write
  26. * to the Free Software Foundation, Inc.,
  27. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #include <linux/swap.h>
  30. #include <linux/bootmem.h>
  31. #include <linux/uaccess.h>
  32. #include <asm/bfin-global.h>
  33. #include <asm/pda.h>
  34. #include <asm/cplbinit.h>
  35. #include "blackfin_sram.h"
  36. /*
  37. * BAD_PAGE is the page that is used for page faults when linux
  38. * is out-of-memory. Older versions of linux just did a
  39. * do_exit(), but using this instead means there is less risk
  40. * for a process dying in kernel mode, possibly leaving a inode
  41. * unused etc..
  42. *
  43. * BAD_PAGETABLE is the accompanying page-table: it is initialized
  44. * to point to BAD_PAGE entries.
  45. *
  46. * ZERO_PAGE is a special page that is used for zero-initialized
  47. * data and COW.
  48. */
  49. static unsigned long empty_bad_page_table;
  50. static unsigned long empty_bad_page;
  51. unsigned long empty_zero_page;
  52. extern unsigned long exception_stack[NR_CPUS][1024];
  53. struct blackfin_pda cpu_pda[NR_CPUS];
  54. EXPORT_SYMBOL(cpu_pda);
  55. /*
  56. * paging_init() continues the virtual memory environment setup which
  57. * was begun by the code in arch/head.S.
  58. * The parameters are pointers to where to stick the starting and ending
  59. * addresses of available kernel virtual memory.
  60. */
  61. void __init paging_init(void)
  62. {
  63. /*
  64. * make sure start_mem is page aligned, otherwise bootmem and
  65. * page_alloc get different views og the world
  66. */
  67. unsigned long end_mem = memory_end & PAGE_MASK;
  68. pr_debug("start_mem is %#lx virtual_end is %#lx\n", PAGE_ALIGN(memory_start), end_mem);
  69. /*
  70. * initialize the bad page table and bad page to point
  71. * to a couple of allocated pages
  72. */
  73. empty_bad_page_table = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  74. empty_bad_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  75. empty_zero_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  76. memset((void *)empty_zero_page, 0, PAGE_SIZE);
  77. /*
  78. * Set up SFC/DFC registers (user data space)
  79. */
  80. set_fs(KERNEL_DS);
  81. pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n",
  82. PAGE_ALIGN(memory_start), end_mem);
  83. {
  84. unsigned long zones_size[MAX_NR_ZONES] = { 0, };
  85. zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT;
  86. zones_size[ZONE_NORMAL] = 0;
  87. #ifdef CONFIG_HIGHMEM
  88. zones_size[ZONE_HIGHMEM] = 0;
  89. #endif
  90. free_area_init(zones_size);
  91. }
  92. }
  93. asmlinkage void __init init_pda(void)
  94. {
  95. unsigned int cpu = raw_smp_processor_id();
  96. /* Initialize the PDA fields holding references to other parts
  97. of the memory. The content of such memory is still
  98. undefined at the time of the call, we are only setting up
  99. valid pointers to it. */
  100. memset(&cpu_pda[cpu], 0, sizeof(cpu_pda[cpu]));
  101. cpu_pda[0].next = &cpu_pda[1];
  102. cpu_pda[1].next = &cpu_pda[0];
  103. cpu_pda[cpu].ex_stack = exception_stack[cpu + 1];
  104. #ifdef CONFIG_SMP
  105. cpu_pda[cpu].imask = 0x1f;
  106. #endif
  107. }
  108. void __cpuinit reserve_pda(void)
  109. {
  110. printk(KERN_INFO "PDA for CPU%u reserved at %p\n", smp_processor_id(),
  111. &cpu_pda[smp_processor_id()]);
  112. }
  113. void __init mem_init(void)
  114. {
  115. unsigned int codek = 0, datak = 0, initk = 0;
  116. unsigned int reservedpages = 0, freepages = 0;
  117. unsigned long tmp;
  118. unsigned long start_mem = memory_start;
  119. unsigned long end_mem = memory_end;
  120. end_mem &= PAGE_MASK;
  121. high_memory = (void *)end_mem;
  122. start_mem = PAGE_ALIGN(start_mem);
  123. max_mapnr = num_physpages = MAP_NR(high_memory);
  124. printk(KERN_DEBUG "Kernel managed physical pages: %lu\n", num_physpages);
  125. /* This will put all memory onto the freelists. */
  126. totalram_pages = free_all_bootmem();
  127. reservedpages = 0;
  128. for (tmp = 0; tmp < max_mapnr; tmp++)
  129. if (PageReserved(pfn_to_page(tmp)))
  130. reservedpages++;
  131. freepages = max_mapnr - reservedpages;
  132. /* do not count in kernel image between _rambase and _ramstart */
  133. reservedpages -= (_ramstart - _rambase) >> PAGE_SHIFT;
  134. #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
  135. reservedpages += (_ramend - memory_end - DMA_UNCACHED_REGION) >> PAGE_SHIFT;
  136. #endif
  137. codek = (_etext - _stext) >> 10;
  138. initk = (__init_end - __init_begin) >> 10;
  139. datak = ((_ramstart - _rambase) >> 10) - codek - initk;
  140. printk(KERN_INFO
  141. "Memory available: %luk/%luk RAM, "
  142. "(%uk init code, %uk kernel code, %uk data, %uk dma, %uk reserved)\n",
  143. (unsigned long) freepages << (PAGE_SHIFT-10), _ramend >> 10,
  144. initk, codek, datak, DMA_UNCACHED_REGION >> 10, (reservedpages << (PAGE_SHIFT-10)));
  145. }
  146. static int __init sram_init(void)
  147. {
  148. /* Initialize the blackfin L1 Memory. */
  149. bfin_sram_init();
  150. /* Reserve the PDA space for the boot CPU right after we
  151. * initialized the scratch memory allocator.
  152. */
  153. reserve_pda();
  154. return 0;
  155. }
  156. pure_initcall(sram_init);
  157. static void __init free_init_pages(const char *what, unsigned long begin, unsigned long end)
  158. {
  159. unsigned long addr;
  160. /* next to check that the page we free is not a partial page */
  161. for (addr = begin; addr + PAGE_SIZE <= end; addr += PAGE_SIZE) {
  162. ClearPageReserved(virt_to_page(addr));
  163. init_page_count(virt_to_page(addr));
  164. free_page(addr);
  165. totalram_pages++;
  166. }
  167. printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
  168. }
  169. #ifdef CONFIG_BLK_DEV_INITRD
  170. void __init free_initrd_mem(unsigned long start, unsigned long end)
  171. {
  172. #ifndef CONFIG_MPU
  173. free_init_pages("initrd memory", start, end);
  174. #endif
  175. }
  176. #endif
  177. void __init_refok free_initmem(void)
  178. {
  179. #if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU
  180. free_init_pages("unused kernel memory",
  181. (unsigned long)(&__init_begin),
  182. (unsigned long)(&__init_end));
  183. #endif
  184. }