init.c 5.2 KB

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