sun3mmu.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/m68k/mm/sun3mmu.c
  4. *
  5. * Implementations of mm routines specific to the sun3 MMU.
  6. *
  7. * Moved here 8/20/1999 Sam Creasey
  8. *
  9. */
  10. #include <linux/signal.h>
  11. #include <linux/sched.h>
  12. #include <linux/mm.h>
  13. #include <linux/swap.h>
  14. #include <linux/kernel.h>
  15. #include <linux/string.h>
  16. #include <linux/types.h>
  17. #include <linux/init.h>
  18. #include <linux/memblock.h>
  19. #include <asm/setup.h>
  20. #include <linux/uaccess.h>
  21. #include <asm/page.h>
  22. #include <asm/machdep.h>
  23. #include <asm/io.h>
  24. extern void mmu_emu_init (unsigned long bootmem_end);
  25. const char bad_pmd_string[] = "Bad pmd in pte_alloc: %08lx\n";
  26. extern unsigned long num_pages;
  27. /* For the sun3 we try to follow the i386 paging_init() more closely */
  28. /* start_mem and end_mem have PAGE_OFFSET added already */
  29. /* now sets up tables using sun3 PTEs rather than i386 as before. --m */
  30. void __init paging_init(void)
  31. {
  32. pgd_t * pg_dir;
  33. pte_t * pg_table;
  34. int i;
  35. unsigned long address;
  36. unsigned long next_pgtable;
  37. unsigned long bootmem_end;
  38. unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0, };
  39. unsigned long size;
  40. empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
  41. if (!empty_zero_page)
  42. panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
  43. __func__, PAGE_SIZE, PAGE_SIZE);
  44. address = PAGE_OFFSET;
  45. pg_dir = swapper_pg_dir;
  46. memset (swapper_pg_dir, 0, sizeof (swapper_pg_dir));
  47. memset (kernel_pg_dir, 0, sizeof (kernel_pg_dir));
  48. size = num_pages * sizeof(pte_t);
  49. size = (size + PAGE_SIZE) & ~(PAGE_SIZE-1);
  50. next_pgtable = (unsigned long)memblock_alloc(size, PAGE_SIZE);
  51. if (!next_pgtable)
  52. panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
  53. __func__, size, PAGE_SIZE);
  54. bootmem_end = (next_pgtable + size + PAGE_SIZE) & PAGE_MASK;
  55. /* Map whole memory from PAGE_OFFSET (0x0E000000) */
  56. pg_dir += PAGE_OFFSET >> PGDIR_SHIFT;
  57. while (address < (unsigned long)high_memory) {
  58. pg_table = (pte_t *) __pa (next_pgtable);
  59. next_pgtable += PTRS_PER_PTE * sizeof (pte_t);
  60. pgd_val(*pg_dir) = (unsigned long) pg_table;
  61. pg_dir++;
  62. /* now change pg_table to kernel virtual addresses */
  63. pg_table = (pte_t *) __va ((unsigned long) pg_table);
  64. for (i=0; i<PTRS_PER_PTE; ++i, ++pg_table) {
  65. pte_t pte = pfn_pte(virt_to_pfn(address), PAGE_INIT);
  66. if (address >= (unsigned long)high_memory)
  67. pte_val (pte) = 0;
  68. set_pte (pg_table, pte);
  69. address += PAGE_SIZE;
  70. }
  71. }
  72. mmu_emu_init(bootmem_end);
  73. current->mm = NULL;
  74. /* memory sizing is a hack stolen from motorola.c.. hope it works for us */
  75. max_zone_pfn[ZONE_DMA] = ((unsigned long)high_memory) >> PAGE_SHIFT;
  76. /* I really wish I knew why the following change made things better... -- Sam */
  77. free_area_init(max_zone_pfn);
  78. }
  79. static const pgprot_t protection_map[16] = {
  80. [VM_NONE] = PAGE_NONE,
  81. [VM_READ] = PAGE_READONLY,
  82. [VM_WRITE] = PAGE_COPY,
  83. [VM_WRITE | VM_READ] = PAGE_COPY,
  84. [VM_EXEC] = PAGE_READONLY,
  85. [VM_EXEC | VM_READ] = PAGE_READONLY,
  86. [VM_EXEC | VM_WRITE] = PAGE_COPY,
  87. [VM_EXEC | VM_WRITE | VM_READ] = PAGE_COPY,
  88. [VM_SHARED] = PAGE_NONE,
  89. [VM_SHARED | VM_READ] = PAGE_READONLY,
  90. [VM_SHARED | VM_WRITE] = PAGE_SHARED,
  91. [VM_SHARED | VM_WRITE | VM_READ] = PAGE_SHARED,
  92. [VM_SHARED | VM_EXEC] = PAGE_READONLY,
  93. [VM_SHARED | VM_EXEC | VM_READ] = PAGE_READONLY,
  94. [VM_SHARED | VM_EXEC | VM_WRITE] = PAGE_SHARED,
  95. [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] = PAGE_SHARED
  96. };
  97. DECLARE_VM_GET_PAGE_PROT