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