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