init.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. void show_mem(void)
  52. {
  53. unsigned long i;
  54. int free = 0, total = 0, reserved = 0, shared = 0;
  55. int cached = 0;
  56. printk(KERN_INFO "Mem-info:\n");
  57. show_free_areas();
  58. i = max_mapnr;
  59. while (i-- > 0) {
  60. total++;
  61. if (PageReserved(mem_map + i))
  62. reserved++;
  63. else if (PageSwapCache(mem_map + i))
  64. cached++;
  65. else if (!page_count(mem_map + i))
  66. free++;
  67. else
  68. shared += page_count(mem_map + i) - 1;
  69. }
  70. printk(KERN_INFO "%d pages of RAM\n", total);
  71. printk(KERN_INFO "%d free pages\n", free);
  72. printk(KERN_INFO "%d reserved pages\n", reserved);
  73. printk(KERN_INFO "%d pages shared\n", shared);
  74. printk(KERN_INFO "%d pages swap cached\n", cached);
  75. }
  76. /*
  77. * paging_init() continues the virtual memory environment setup which
  78. * was begun by the code in arch/head.S.
  79. * The parameters are pointers to where to stick the starting and ending
  80. * addresses of available kernel virtual memory.
  81. */
  82. void __init paging_init(void)
  83. {
  84. /*
  85. * make sure start_mem is page aligned, otherwise bootmem and
  86. * page_alloc get different views og the world
  87. */
  88. unsigned long end_mem = memory_end & PAGE_MASK;
  89. pr_debug("start_mem is %#lx virtual_end is %#lx\n", PAGE_ALIGN(memory_start), end_mem);
  90. /*
  91. * initialize the bad page table and bad page to point
  92. * to a couple of allocated pages
  93. */
  94. empty_bad_page_table = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  95. empty_bad_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  96. empty_zero_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  97. memset((void *)empty_zero_page, 0, PAGE_SIZE);
  98. /*
  99. * Set up SFC/DFC registers (user data space)
  100. */
  101. set_fs(KERNEL_DS);
  102. pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n",
  103. PAGE_ALIGN(memory_start), end_mem);
  104. {
  105. unsigned long zones_size[MAX_NR_ZONES] = { 0, };
  106. zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT;
  107. zones_size[ZONE_NORMAL] = 0;
  108. #ifdef CONFIG_HIGHMEM
  109. zones_size[ZONE_HIGHMEM] = 0;
  110. #endif
  111. free_area_init(zones_size);
  112. }
  113. }
  114. void __init mem_init(void)
  115. {
  116. unsigned int codek = 0, datak = 0, initk = 0;
  117. unsigned long tmp;
  118. unsigned int len = _ramend - _rambase;
  119. unsigned long start_mem = memory_start;
  120. unsigned long end_mem = memory_end;
  121. end_mem &= PAGE_MASK;
  122. high_memory = (void *)end_mem;
  123. start_mem = PAGE_ALIGN(start_mem);
  124. max_mapnr = num_physpages = MAP_NR(high_memory);
  125. printk(KERN_INFO "Physical pages: %lx\n", num_physpages);
  126. /* This will put all memory onto the freelists. */
  127. totalram_pages = free_all_bootmem();
  128. codek = (_etext - _stext) >> 10;
  129. datak = (__bss_stop - __bss_start) >> 10;
  130. initk = (__init_end - __init_begin) >> 10;
  131. tmp = nr_free_pages() << PAGE_SHIFT;
  132. printk(KERN_INFO
  133. "Memory available: %luk/%uk RAM, (%uk init code, %uk kernel code, %uk data, %uk dma)\n",
  134. tmp >> 10, len >> 10, initk, codek, datak, DMA_UNCACHED_REGION >> 10);
  135. /* Initialize the blackfin L1 Memory. */
  136. l1sram_init();
  137. l1_data_sram_init();
  138. l1_inst_sram_init();
  139. /* Allocate this once; never free it. We assume this gives us a
  140. pointer to the start of L1 scratchpad memory; panic if it
  141. doesn't. */
  142. tmp = (unsigned long)l1sram_alloc(sizeof(struct l1_scratch_task_info));
  143. if (tmp != (unsigned long)L1_SCRATCH_TASK_INFO) {
  144. printk(KERN_EMERG "mem_init(): Did not get the right address from l1sram_alloc: %08lx != %08lx\n",
  145. tmp, (unsigned long)L1_SCRATCH_TASK_INFO);
  146. panic("No L1, time to give up\n");
  147. }
  148. }
  149. static __init void free_init_pages(const char *what, unsigned long begin, unsigned long end)
  150. {
  151. unsigned long addr;
  152. /* next to check that the page we free is not a partial page */
  153. for (addr = begin; addr + PAGE_SIZE <= end; addr += PAGE_SIZE) {
  154. ClearPageReserved(virt_to_page(addr));
  155. init_page_count(virt_to_page(addr));
  156. free_page(addr);
  157. totalram_pages++;
  158. }
  159. printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
  160. }
  161. #ifdef CONFIG_BLK_DEV_INITRD
  162. void __init free_initrd_mem(unsigned long start, unsigned long end)
  163. {
  164. free_init_pages("initrd memory", start, end);
  165. }
  166. #endif
  167. void __init free_initmem(void)
  168. {
  169. #ifdef CONFIG_RAMKERNEL
  170. free_init_pages("unused kernel memory",
  171. (unsigned long)(&__init_begin),
  172. (unsigned long)(&__init_end));
  173. #endif
  174. }