init.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (C) 2013 Altera Corporation
  3. * Copyright (C) 2010 Tobias Klauser <[email protected]>
  4. * Copyright (C) 2009 Wind River Systems Inc
  5. * Implemented by [email protected] and [email protected]
  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/memblock.h>
  26. #include <linux/slab.h>
  27. #include <linux/binfmts.h>
  28. #include <asm/setup.h>
  29. #include <asm/page.h>
  30. #include <asm/sections.h>
  31. #include <asm/tlb.h>
  32. #include <asm/mmu_context.h>
  33. #include <asm/cpuinfo.h>
  34. #include <asm/processor.h>
  35. pgd_t *pgd_current;
  36. /*
  37. * paging_init() continues the virtual memory environment setup which
  38. * was begun by the code in arch/head.S.
  39. * The parameters are pointers to where to stick the starting and ending
  40. * addresses of available kernel virtual memory.
  41. */
  42. void __init paging_init(void)
  43. {
  44. unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
  45. pagetable_init();
  46. pgd_current = swapper_pg_dir;
  47. max_zone_pfn[ZONE_NORMAL] = max_mapnr;
  48. /* pass the memory from the bootmem allocator to the main allocator */
  49. free_area_init(max_zone_pfn);
  50. flush_dcache_range((unsigned long)empty_zero_page,
  51. (unsigned long)empty_zero_page + PAGE_SIZE);
  52. }
  53. void __init mem_init(void)
  54. {
  55. unsigned long end_mem = memory_end; /* this must not include
  56. kernel stack at top */
  57. pr_debug("mem_init: start=%lx, end=%lx\n", memory_start, memory_end);
  58. end_mem &= PAGE_MASK;
  59. high_memory = __va(end_mem);
  60. /* this will put all memory onto the freelists */
  61. memblock_free_all();
  62. }
  63. void __init mmu_init(void)
  64. {
  65. flush_tlb_all();
  66. }
  67. pgd_t swapper_pg_dir[PTRS_PER_PGD] __aligned(PAGE_SIZE);
  68. pte_t invalid_pte_table[PTRS_PER_PTE] __aligned(PAGE_SIZE);
  69. static struct page *kuser_page[1];
  70. static int alloc_kuser_page(void)
  71. {
  72. extern char __kuser_helper_start[], __kuser_helper_end[];
  73. int kuser_sz = __kuser_helper_end - __kuser_helper_start;
  74. unsigned long vpage;
  75. vpage = get_zeroed_page(GFP_ATOMIC);
  76. if (!vpage)
  77. return -ENOMEM;
  78. /* Copy kuser helpers */
  79. memcpy((void *)vpage, __kuser_helper_start, kuser_sz);
  80. flush_icache_range(vpage, vpage + KUSER_SIZE);
  81. kuser_page[0] = virt_to_page(vpage);
  82. return 0;
  83. }
  84. arch_initcall(alloc_kuser_page);
  85. int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  86. {
  87. struct mm_struct *mm = current->mm;
  88. int ret;
  89. mmap_write_lock(mm);
  90. /* Map kuser helpers to user space address */
  91. ret = install_special_mapping(mm, KUSER_BASE, KUSER_SIZE,
  92. VM_READ | VM_EXEC | VM_MAYREAD |
  93. VM_MAYEXEC, kuser_page);
  94. mmap_write_unlock(mm);
  95. return ret;
  96. }
  97. const char *arch_vma_name(struct vm_area_struct *vma)
  98. {
  99. return (vma->vm_start == KUSER_BASE) ? "[kuser]" : NULL;
  100. }
  101. static const pgprot_t protection_map[16] = {
  102. [VM_NONE] = MKP(0, 0, 0),
  103. [VM_READ] = MKP(0, 0, 1),
  104. [VM_WRITE] = MKP(0, 0, 0),
  105. [VM_WRITE | VM_READ] = MKP(0, 0, 1),
  106. [VM_EXEC] = MKP(1, 0, 0),
  107. [VM_EXEC | VM_READ] = MKP(1, 0, 1),
  108. [VM_EXEC | VM_WRITE] = MKP(1, 0, 0),
  109. [VM_EXEC | VM_WRITE | VM_READ] = MKP(1, 0, 1),
  110. [VM_SHARED] = MKP(0, 0, 0),
  111. [VM_SHARED | VM_READ] = MKP(0, 0, 1),
  112. [VM_SHARED | VM_WRITE] = MKP(0, 1, 0),
  113. [VM_SHARED | VM_WRITE | VM_READ] = MKP(0, 1, 1),
  114. [VM_SHARED | VM_EXEC] = MKP(1, 0, 0),
  115. [VM_SHARED | VM_EXEC | VM_READ] = MKP(1, 0, 1),
  116. [VM_SHARED | VM_EXEC | VM_WRITE] = MKP(1, 1, 0),
  117. [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] = MKP(1, 1, 1)
  118. };
  119. DECLARE_VM_GET_PAGE_PROT