init.c 6.0 KB

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