init.c 5.2 KB

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