init.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* MN10300 Memory management initialisation
  2. *
  3. * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
  4. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  5. * Modified by David Howells (dhowells@redhat.com)
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public Licence
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the Licence, or (at your option) any later version.
  11. */
  12. #include <linux/signal.h>
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/errno.h>
  16. #include <linux/string.h>
  17. #include <linux/types.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/mman.h>
  20. #include <linux/fs.h>
  21. #include <linux/mm.h>
  22. #include <linux/swap.h>
  23. #include <linux/smp.h>
  24. #include <linux/init.h>
  25. #include <linux/initrd.h>
  26. #include <linux/highmem.h>
  27. #include <linux/pagemap.h>
  28. #include <linux/bootmem.h>
  29. #include <linux/gfp.h>
  30. #include <asm/processor.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/pgalloc.h>
  34. #include <asm/dma.h>
  35. #include <asm/tlb.h>
  36. #include <asm/sections.h>
  37. unsigned long highstart_pfn, highend_pfn;
  38. #ifdef CONFIG_MN10300_HAS_ATOMIC_OPS_UNIT
  39. static struct vm_struct user_iomap_vm;
  40. #endif
  41. /*
  42. * set up paging
  43. */
  44. void __init paging_init(void)
  45. {
  46. unsigned long zones_size[MAX_NR_ZONES] = {0,};
  47. pte_t *ppte;
  48. int loop;
  49. /* main kernel space -> RAM mapping is handled as 1:1 transparent by
  50. * the MMU */
  51. memset(swapper_pg_dir, 0, sizeof(swapper_pg_dir));
  52. memset(kernel_vmalloc_ptes, 0, sizeof(kernel_vmalloc_ptes));
  53. /* load the VMALLOC area PTE table addresses into the kernel PGD */
  54. ppte = kernel_vmalloc_ptes;
  55. for (loop = VMALLOC_START / (PAGE_SIZE * PTRS_PER_PTE);
  56. loop < VMALLOC_END / (PAGE_SIZE * PTRS_PER_PTE);
  57. loop++
  58. ) {
  59. set_pgd(swapper_pg_dir + loop, __pgd(__pa(ppte) | _PAGE_TABLE));
  60. ppte += PAGE_SIZE / sizeof(pte_t);
  61. }
  62. /* declare the sizes of the RAM zones (only use the normal zone) */
  63. zones_size[ZONE_NORMAL] =
  64. contig_page_data.bdata->node_low_pfn -
  65. contig_page_data.bdata->node_min_pfn;
  66. /* pass the memory from the bootmem allocator to the main allocator */
  67. free_area_init(zones_size);
  68. #ifdef CONFIG_MN10300_HAS_ATOMIC_OPS_UNIT
  69. /* The Atomic Operation Unit registers need to be mapped to userspace
  70. * for all processes. The following uses vm_area_register_early() to
  71. * reserve the first page of the vmalloc area and sets the pte for that
  72. * page.
  73. *
  74. * glibc hardcodes this virtual mapping, so we're pretty much stuck with
  75. * it from now on.
  76. */
  77. user_iomap_vm.flags = VM_USERMAP;
  78. user_iomap_vm.size = 1 << PAGE_SHIFT;
  79. vm_area_register_early(&user_iomap_vm, PAGE_SIZE);
  80. ppte = kernel_vmalloc_ptes;
  81. set_pte(ppte, pfn_pte(USER_ATOMIC_OPS_PAGE_ADDR >> PAGE_SHIFT,
  82. PAGE_USERIO));
  83. #endif
  84. local_flush_tlb_all();
  85. }
  86. /*
  87. * transfer all the memory from the bootmem allocator to the runtime allocator
  88. */
  89. void __init mem_init(void)
  90. {
  91. BUG_ON(!mem_map);
  92. #define START_PFN (contig_page_data.bdata->node_min_pfn)
  93. #define MAX_LOW_PFN (contig_page_data.bdata->node_low_pfn)
  94. max_mapnr = MAX_LOW_PFN - START_PFN;
  95. high_memory = (void *) __va(MAX_LOW_PFN * PAGE_SIZE);
  96. /* clear the zero-page */
  97. memset(empty_zero_page, 0, PAGE_SIZE);
  98. /* this will put all low memory onto the freelists */
  99. free_all_bootmem();
  100. mem_init_print_info(NULL);
  101. }
  102. /*
  103. * recycle memory containing stuff only required for initialisation
  104. */
  105. void free_initmem(void)
  106. {
  107. free_initmem_default(POISON_FREE_INITMEM);
  108. }
  109. /*
  110. * dispose of the memory on which the initial ramdisk resided
  111. */
  112. #ifdef CONFIG_BLK_DEV_INITRD
  113. void free_initrd_mem(unsigned long start, unsigned long end)
  114. {
  115. free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
  116. "initrd");
  117. }
  118. #endif