init.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 of the world
  40. */
  41. unsigned long end_mem = memory_end & PAGE_MASK;
  42. unsigned long zones_size[MAX_NR_ZONES] = {
  43. [0] = 0,
  44. [ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT,
  45. [ZONE_NORMAL] = 0,
  46. #ifdef CONFIG_HIGHMEM
  47. [ZONE_HIGHMEM] = 0,
  48. #endif
  49. };
  50. /* Set up SFC/DFC registers (user data space) */
  51. set_fs(KERNEL_DS);
  52. pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n",
  53. PAGE_ALIGN(memory_start), end_mem);
  54. free_area_init(zones_size);
  55. }
  56. asmlinkage void __init init_pda(void)
  57. {
  58. unsigned int cpu = raw_smp_processor_id();
  59. early_shadow_stamp();
  60. /* Initialize the PDA fields holding references to other parts
  61. of the memory. The content of such memory is still
  62. undefined at the time of the call, we are only setting up
  63. valid pointers to it. */
  64. memset(&cpu_pda[cpu], 0, sizeof(cpu_pda[cpu]));
  65. cpu_pda[0].next = &cpu_pda[1];
  66. cpu_pda[1].next = &cpu_pda[0];
  67. #ifdef CONFIG_EXCEPTION_L1_SCRATCH
  68. cpu_pda[cpu].ex_stack = (unsigned long *)(L1_SCRATCH_START + \
  69. L1_SCRATCH_LENGTH);
  70. #else
  71. cpu_pda[cpu].ex_stack = exception_stack[cpu + 1];
  72. #endif
  73. #ifdef CONFIG_SMP
  74. cpu_pda[cpu].imask = 0x1f;
  75. #endif
  76. }
  77. void __init mem_init(void)
  78. {
  79. unsigned int codek = 0, datak = 0, initk = 0;
  80. unsigned int reservedpages = 0, freepages = 0;
  81. unsigned long tmp;
  82. unsigned long start_mem = memory_start;
  83. unsigned long end_mem = memory_end;
  84. end_mem &= PAGE_MASK;
  85. high_memory = (void *)end_mem;
  86. start_mem = PAGE_ALIGN(start_mem);
  87. max_mapnr = num_physpages = MAP_NR(high_memory);
  88. printk(KERN_DEBUG "Kernel managed physical pages: %lu\n", num_physpages);
  89. /* This will put all memory onto the freelists. */
  90. totalram_pages = free_all_bootmem();
  91. reservedpages = 0;
  92. for (tmp = 0; tmp < max_mapnr; tmp++)
  93. if (PageReserved(pfn_to_page(tmp)))
  94. reservedpages++;
  95. freepages = max_mapnr - reservedpages;
  96. /* do not count in kernel image between _rambase and _ramstart */
  97. reservedpages -= (_ramstart - _rambase) >> PAGE_SHIFT;
  98. #if (defined(CONFIG_BFIN_EXTMEM_ICACHEABLE) && ANOMALY_05000263)
  99. reservedpages += (_ramend - memory_end - DMA_UNCACHED_REGION) >> PAGE_SHIFT;
  100. #endif
  101. codek = (_etext - _stext) >> 10;
  102. initk = (__init_end - __init_begin) >> 10;
  103. datak = ((_ramstart - _rambase) >> 10) - codek - initk;
  104. printk(KERN_INFO
  105. "Memory available: %luk/%luk RAM, "
  106. "(%uk init code, %uk kernel code, %uk data, %uk dma, %uk reserved)\n",
  107. (unsigned long) freepages << (PAGE_SHIFT-10), _ramend >> 10,
  108. initk, codek, datak, DMA_UNCACHED_REGION >> 10, (reservedpages << (PAGE_SHIFT-10)));
  109. }
  110. static void __init free_init_pages(const char *what, unsigned long begin, unsigned long end)
  111. {
  112. unsigned long addr;
  113. /* next to check that the page we free is not a partial page */
  114. for (addr = begin; addr + PAGE_SIZE <= end; addr += PAGE_SIZE) {
  115. ClearPageReserved(virt_to_page(addr));
  116. init_page_count(virt_to_page(addr));
  117. free_page(addr);
  118. totalram_pages++;
  119. }
  120. printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
  121. }
  122. #ifdef CONFIG_BLK_DEV_INITRD
  123. void __init free_initrd_mem(unsigned long start, unsigned long end)
  124. {
  125. #ifndef CONFIG_MPU
  126. free_init_pages("initrd memory", start, end);
  127. #endif
  128. }
  129. #endif
  130. void __init_refok free_initmem(void)
  131. {
  132. #if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU
  133. free_init_pages("unused kernel memory",
  134. (unsigned long)(&__init_begin),
  135. (unsigned long)(&__init_end));
  136. if (memory_start == (unsigned long)(&__init_end))
  137. memory_start = (unsigned long)(&__init_begin);
  138. #endif
  139. }