init.c 5.7 KB

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