init.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 <asm/early_printk.h>
  36. #include "blackfin_sram.h"
  37. /*
  38. * BAD_PAGE is the page that is used for page faults when linux
  39. * is out-of-memory. Older versions of linux just did a
  40. * do_exit(), but using this instead means there is less risk
  41. * for a process dying in kernel mode, possibly leaving a inode
  42. * unused etc..
  43. *
  44. * BAD_PAGETABLE is the accompanying page-table: it is initialized
  45. * to point to BAD_PAGE entries.
  46. *
  47. * ZERO_PAGE is a special page that is used for zero-initialized
  48. * data and COW.
  49. */
  50. static unsigned long empty_bad_page_table;
  51. static unsigned long empty_bad_page;
  52. static unsigned long empty_zero_page;
  53. #ifndef CONFIG_EXCEPTION_L1_SCRATCH
  54. #if defined CONFIG_SYSCALL_TAB_L1
  55. __attribute__((l1_data))
  56. #endif
  57. static unsigned long exception_stack[NR_CPUS][1024];
  58. #endif
  59. struct blackfin_pda cpu_pda[NR_CPUS];
  60. EXPORT_SYMBOL(cpu_pda);
  61. /*
  62. * paging_init() continues the virtual memory environment setup which
  63. * was begun by the code in arch/head.S.
  64. * The parameters are pointers to where to stick the starting and ending
  65. * addresses of available kernel virtual memory.
  66. */
  67. void __init paging_init(void)
  68. {
  69. /*
  70. * make sure start_mem is page aligned, otherwise bootmem and
  71. * page_alloc get different views og the world
  72. */
  73. unsigned long end_mem = memory_end & PAGE_MASK;
  74. pr_debug("start_mem is %#lx virtual_end is %#lx\n", PAGE_ALIGN(memory_start), end_mem);
  75. /*
  76. * initialize the bad page table and bad page to point
  77. * to a couple of allocated pages
  78. */
  79. empty_bad_page_table = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  80. empty_bad_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  81. empty_zero_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  82. memset((void *)empty_zero_page, 0, PAGE_SIZE);
  83. /*
  84. * Set up SFC/DFC registers (user data space)
  85. */
  86. set_fs(KERNEL_DS);
  87. pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n",
  88. PAGE_ALIGN(memory_start), end_mem);
  89. {
  90. unsigned long zones_size[MAX_NR_ZONES] = { 0, };
  91. zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT;
  92. zones_size[ZONE_NORMAL] = 0;
  93. #ifdef CONFIG_HIGHMEM
  94. zones_size[ZONE_HIGHMEM] = 0;
  95. #endif
  96. free_area_init(zones_size);
  97. }
  98. }
  99. asmlinkage void __init init_pda(void)
  100. {
  101. unsigned int cpu = raw_smp_processor_id();
  102. early_shadow_stamp();
  103. /* Initialize the PDA fields holding references to other parts
  104. of the memory. The content of such memory is still
  105. undefined at the time of the call, we are only setting up
  106. valid pointers to it. */
  107. memset(&cpu_pda[cpu], 0, sizeof(cpu_pda[cpu]));
  108. cpu_pda[0].next = &cpu_pda[1];
  109. cpu_pda[1].next = &cpu_pda[0];
  110. #ifdef CONFIG_EXCEPTION_L1_SCRATCH
  111. cpu_pda[cpu].ex_stack = (unsigned long *)(L1_SCRATCH_START + \
  112. L1_SCRATCH_LENGTH);
  113. #else
  114. cpu_pda[cpu].ex_stack = exception_stack[cpu + 1];
  115. #endif
  116. #ifdef CONFIG_SMP
  117. cpu_pda[cpu].imask = 0x1f;
  118. #endif
  119. }
  120. void __init mem_init(void)
  121. {
  122. unsigned int codek = 0, datak = 0, initk = 0;
  123. unsigned int reservedpages = 0, freepages = 0;
  124. unsigned long tmp;
  125. unsigned long start_mem = memory_start;
  126. unsigned long end_mem = memory_end;
  127. end_mem &= PAGE_MASK;
  128. high_memory = (void *)end_mem;
  129. start_mem = PAGE_ALIGN(start_mem);
  130. max_mapnr = num_physpages = MAP_NR(high_memory);
  131. printk(KERN_DEBUG "Kernel managed physical pages: %lu\n", num_physpages);
  132. /* This will put all memory onto the freelists. */
  133. totalram_pages = free_all_bootmem();
  134. reservedpages = 0;
  135. for (tmp = 0; tmp < max_mapnr; tmp++)
  136. if (PageReserved(pfn_to_page(tmp)))
  137. reservedpages++;
  138. freepages = max_mapnr - reservedpages;
  139. /* do not count in kernel image between _rambase and _ramstart */
  140. reservedpages -= (_ramstart - _rambase) >> PAGE_SHIFT;
  141. #if (defined(CONFIG_BFIN_EXTMEM_ICACHEABLE) && ANOMALY_05000263)
  142. reservedpages += (_ramend - memory_end - DMA_UNCACHED_REGION) >> PAGE_SHIFT;
  143. #endif
  144. codek = (_etext - _stext) >> 10;
  145. initk = (__init_end - __init_begin) >> 10;
  146. datak = ((_ramstart - _rambase) >> 10) - codek - initk;
  147. printk(KERN_INFO
  148. "Memory available: %luk/%luk RAM, "
  149. "(%uk init code, %uk kernel code, %uk data, %uk dma, %uk reserved)\n",
  150. (unsigned long) freepages << (PAGE_SHIFT-10), _ramend >> 10,
  151. initk, codek, datak, DMA_UNCACHED_REGION >> 10, (reservedpages << (PAGE_SHIFT-10)));
  152. }
  153. static void __init free_init_pages(const char *what, unsigned long begin, unsigned long end)
  154. {
  155. unsigned long addr;
  156. /* next to check that the page we free is not a partial page */
  157. for (addr = begin; addr + PAGE_SIZE <= end; addr += PAGE_SIZE) {
  158. ClearPageReserved(virt_to_page(addr));
  159. init_page_count(virt_to_page(addr));
  160. free_page(addr);
  161. totalram_pages++;
  162. }
  163. printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
  164. }
  165. #ifdef CONFIG_BLK_DEV_INITRD
  166. void __init free_initrd_mem(unsigned long start, unsigned long end)
  167. {
  168. #ifndef CONFIG_MPU
  169. free_init_pages("initrd memory", start, end);
  170. #endif
  171. }
  172. #endif
  173. void __init_refok free_initmem(void)
  174. {
  175. #if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU
  176. free_init_pages("unused kernel memory",
  177. (unsigned long)(&__init_begin),
  178. (unsigned long)(&__init_end));
  179. #endif
  180. }