init.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (C) 2013 Altera Corporation
  3. * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
  4. * Copyright (C) 2009 Wind River Systems Inc
  5. * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
  6. * Copyright (C) 2004 Microtronix Datacom Ltd
  7. *
  8. * based on arch/m68k/mm/init.c
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file "COPYING" in the main directory of this archive
  12. * for more details.
  13. */
  14. #include <linux/signal.h>
  15. #include <linux/sched.h>
  16. #include <linux/kernel.h>
  17. #include <linux/errno.h>
  18. #include <linux/string.h>
  19. #include <linux/types.h>
  20. #include <linux/ptrace.h>
  21. #include <linux/mman.h>
  22. #include <linux/mm.h>
  23. #include <linux/init.h>
  24. #include <linux/pagemap.h>
  25. #include <linux/bootmem.h>
  26. #include <linux/slab.h>
  27. #include <linux/binfmts.h>
  28. #include <asm/setup.h>
  29. #include <asm/page.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/sections.h>
  32. #include <asm/tlb.h>
  33. #include <asm/mmu_context.h>
  34. #include <asm/cpuinfo.h>
  35. #include <asm/processor.h>
  36. pgd_t *pgd_current;
  37. /*
  38. * paging_init() continues the virtual memory environment setup which
  39. * was begun by the code in arch/head.S.
  40. * The parameters are pointers to where to stick the starting and ending
  41. * addresses of available kernel virtual memory.
  42. */
  43. void __init paging_init(void)
  44. {
  45. unsigned long zones_size[MAX_NR_ZONES];
  46. memset(zones_size, 0, sizeof(zones_size));
  47. pagetable_init();
  48. pgd_current = swapper_pg_dir;
  49. zones_size[ZONE_NORMAL] = max_mapnr;
  50. /* pass the memory from the bootmem allocator to the main allocator */
  51. free_area_init(zones_size);
  52. flush_dcache_range((unsigned long)empty_zero_page,
  53. (unsigned long)empty_zero_page + PAGE_SIZE);
  54. }
  55. void __init mem_init(void)
  56. {
  57. unsigned long end_mem = memory_end; /* this must not include
  58. kernel stack at top */
  59. pr_debug("mem_init: start=%lx, end=%lx\n", memory_start, memory_end);
  60. end_mem &= PAGE_MASK;
  61. high_memory = __va(end_mem);
  62. /* this will put all memory onto the freelists */
  63. free_all_bootmem();
  64. mem_init_print_info(NULL);
  65. }
  66. void __init mmu_init(void)
  67. {
  68. flush_tlb_all();
  69. }
  70. #ifdef CONFIG_BLK_DEV_INITRD
  71. void __init free_initrd_mem(unsigned long start, unsigned long end)
  72. {
  73. free_reserved_area((void *)start, (void *)end, -1, "initrd");
  74. }
  75. #endif
  76. void __init_refok free_initmem(void)
  77. {
  78. free_initmem_default(-1);
  79. }
  80. #define __page_aligned(order) __aligned(PAGE_SIZE << (order))
  81. pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned(PGD_ORDER);
  82. pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned(PTE_ORDER);
  83. static struct page *kuser_page[1];
  84. static int alloc_kuser_page(void)
  85. {
  86. extern char __kuser_helper_start[], __kuser_helper_end[];
  87. int kuser_sz = __kuser_helper_end - __kuser_helper_start;
  88. unsigned long vpage;
  89. vpage = get_zeroed_page(GFP_ATOMIC);
  90. if (!vpage)
  91. return -ENOMEM;
  92. /* Copy kuser helpers */
  93. memcpy((void *)vpage, __kuser_helper_start, kuser_sz);
  94. flush_icache_range(vpage, vpage + KUSER_SIZE);
  95. kuser_page[0] = virt_to_page(vpage);
  96. return 0;
  97. }
  98. arch_initcall(alloc_kuser_page);
  99. int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  100. {
  101. struct mm_struct *mm = current->mm;
  102. int ret;
  103. down_write(&mm->mmap_sem);
  104. /* Map kuser helpers to user space address */
  105. ret = install_special_mapping(mm, KUSER_BASE, KUSER_SIZE,
  106. VM_READ | VM_EXEC | VM_MAYREAD |
  107. VM_MAYEXEC, kuser_page);
  108. up_write(&mm->mmap_sem);
  109. return ret;
  110. }
  111. const char *arch_vma_name(struct vm_area_struct *vma)
  112. {
  113. return (vma->vm_start == KUSER_BASE) ? "[kuser]" : NULL;
  114. }