init.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. * ZERO_PAGE is a special page that is used for zero-initialized data and COW.
  17. * Let the bss do its zero-init magic so we don't have to do it ourselves.
  18. */
  19. char empty_zero_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
  20. EXPORT_SYMBOL(empty_zero_page);
  21. #ifndef CONFIG_EXCEPTION_L1_SCRATCH
  22. #if defined CONFIG_SYSCALL_TAB_L1
  23. __attribute__((l1_data))
  24. #endif
  25. static unsigned long exception_stack[NR_CPUS][1024];
  26. #endif
  27. struct blackfin_pda cpu_pda[NR_CPUS];
  28. EXPORT_SYMBOL(cpu_pda);
  29. /*
  30. * paging_init() continues the virtual memory environment setup which
  31. * was begun by the code in arch/head.S.
  32. * The parameters are pointers to where to stick the starting and ending
  33. * addresses of available kernel virtual memory.
  34. */
  35. void __init paging_init(void)
  36. {
  37. /*
  38. * make sure start_mem is page aligned, otherwise bootmem and
  39. * page_alloc get different views og the world
  40. */
  41. unsigned long end_mem = memory_end & PAGE_MASK;
  42. pr_debug("start_mem is %#lx virtual_end is %#lx\n", PAGE_ALIGN(memory_start), end_mem);
  43. /*
  44. * Set up SFC/DFC registers (user data space)
  45. */
  46. set_fs(KERNEL_DS);
  47. pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n",
  48. PAGE_ALIGN(memory_start), end_mem);
  49. {
  50. unsigned long zones_size[MAX_NR_ZONES] = { 0, };
  51. zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT;
  52. zones_size[ZONE_NORMAL] = 0;
  53. #ifdef CONFIG_HIGHMEM
  54. zones_size[ZONE_HIGHMEM] = 0;
  55. #endif
  56. free_area_init(zones_size);
  57. }
  58. }
  59. asmlinkage void __init init_pda(void)
  60. {
  61. unsigned int cpu = raw_smp_processor_id();
  62. early_shadow_stamp();
  63. /* Initialize the PDA fields holding references to other parts
  64. of the memory. The content of such memory is still
  65. undefined at the time of the call, we are only setting up
  66. valid pointers to it. */
  67. memset(&cpu_pda[cpu], 0, sizeof(cpu_pda[cpu]));
  68. cpu_pda[0].next = &cpu_pda[1];
  69. cpu_pda[1].next = &cpu_pda[0];
  70. #ifdef CONFIG_EXCEPTION_L1_SCRATCH
  71. cpu_pda[cpu].ex_stack = (unsigned long *)(L1_SCRATCH_START + \
  72. L1_SCRATCH_LENGTH);
  73. #else
  74. cpu_pda[cpu].ex_stack = exception_stack[cpu + 1];
  75. #endif
  76. #ifdef CONFIG_SMP
  77. cpu_pda[cpu].imask = 0x1f;
  78. #endif
  79. }
  80. void __init mem_init(void)
  81. {
  82. unsigned int codek = 0, datak = 0, initk = 0;
  83. unsigned int reservedpages = 0, freepages = 0;
  84. unsigned long tmp;
  85. unsigned long start_mem = memory_start;
  86. unsigned long end_mem = memory_end;
  87. end_mem &= PAGE_MASK;
  88. high_memory = (void *)end_mem;
  89. start_mem = PAGE_ALIGN(start_mem);
  90. max_mapnr = num_physpages = MAP_NR(high_memory);
  91. printk(KERN_DEBUG "Kernel managed physical pages: %lu\n", num_physpages);
  92. /* This will put all memory onto the freelists. */
  93. totalram_pages = free_all_bootmem();
  94. reservedpages = 0;
  95. for (tmp = 0; tmp < max_mapnr; tmp++)
  96. if (PageReserved(pfn_to_page(tmp)))
  97. reservedpages++;
  98. freepages = max_mapnr - reservedpages;
  99. /* do not count in kernel image between _rambase and _ramstart */
  100. reservedpages -= (_ramstart - _rambase) >> PAGE_SHIFT;
  101. #if (defined(CONFIG_BFIN_EXTMEM_ICACHEABLE) && ANOMALY_05000263)
  102. reservedpages += (_ramend - memory_end - DMA_UNCACHED_REGION) >> PAGE_SHIFT;
  103. #endif
  104. codek = (_etext - _stext) >> 10;
  105. initk = (__init_end - __init_begin) >> 10;
  106. datak = ((_ramstart - _rambase) >> 10) - codek - initk;
  107. printk(KERN_INFO
  108. "Memory available: %luk/%luk RAM, "
  109. "(%uk init code, %uk kernel code, %uk data, %uk dma, %uk reserved)\n",
  110. (unsigned long) freepages << (PAGE_SHIFT-10), _ramend >> 10,
  111. initk, codek, datak, DMA_UNCACHED_REGION >> 10, (reservedpages << (PAGE_SHIFT-10)));
  112. }
  113. static void __init free_init_pages(const char *what, unsigned long begin, unsigned long end)
  114. {
  115. unsigned long addr;
  116. /* next to check that the page we free is not a partial page */
  117. for (addr = begin; addr + PAGE_SIZE <= end; addr += PAGE_SIZE) {
  118. ClearPageReserved(virt_to_page(addr));
  119. init_page_count(virt_to_page(addr));
  120. free_page(addr);
  121. totalram_pages++;
  122. }
  123. printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
  124. }
  125. #ifdef CONFIG_BLK_DEV_INITRD
  126. void __init free_initrd_mem(unsigned long start, unsigned long end)
  127. {
  128. #ifndef CONFIG_MPU
  129. free_init_pages("initrd memory", start, end);
  130. #endif
  131. }
  132. #endif
  133. void __init_refok free_initmem(void)
  134. {
  135. #if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU
  136. free_init_pages("unused kernel memory",
  137. (unsigned long)(&__init_begin),
  138. (unsigned long)(&__init_end));
  139. #endif
  140. }