blob: eca1c46bb90abff694a901e8c593461f90c24ca1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
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>
Mike Rapoport57c8a662018-10-30 15:09:49 -070019#include <linux/memblock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include <asm/setup.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080022#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/page.h>
24#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/machdep.h>
26#include <asm/io.h>
27
28extern void mmu_emu_init (unsigned long bootmem_end);
29
30const char bad_pmd_string[] = "Bad pmd in pte_alloc: %08lx\n";
31
32extern unsigned long num_pages;
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034/* For the sun3 we try to follow the i386 paging_init() more closely */
35/* start_mem and end_mem have PAGE_OFFSET added already */
36/* now sets up tables using sun3 PTEs rather than i386 as before. --m */
37void __init paging_init(void)
38{
39 pgd_t * pg_dir;
40 pte_t * pg_table;
41 int i;
42 unsigned long address;
43 unsigned long next_pgtable;
44 unsigned long bootmem_end;
Roman Zippel2dcf15b2006-06-23 02:04:58 -070045 unsigned long zones_size[MAX_NR_ZONES] = { 0, };
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 unsigned long size;
47
Mike Rapoport15c3c112018-10-30 15:08:58 -070048 empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
Mike Rapoport8a7f97b2019-03-11 23:30:31 -070049 if (!empty_zero_page)
50 panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
51 __func__, PAGE_SIZE, PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 address = PAGE_OFFSET;
54 pg_dir = swapper_pg_dir;
55 memset (swapper_pg_dir, 0, sizeof (swapper_pg_dir));
56 memset (kernel_pg_dir, 0, sizeof (kernel_pg_dir));
57
58 size = num_pages * sizeof(pte_t);
59 size = (size + PAGE_SIZE) & ~(PAGE_SIZE-1);
60
Mike Rapoport15c3c112018-10-30 15:08:58 -070061 next_pgtable = (unsigned long)memblock_alloc(size, PAGE_SIZE);
Mike Rapoport8a7f97b2019-03-11 23:30:31 -070062 if (!next_pgtable)
63 panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
64 __func__, size, PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 bootmem_end = (next_pgtable + size + PAGE_SIZE) & PAGE_MASK;
66
67 /* Map whole memory from PAGE_OFFSET (0x0E000000) */
68 pg_dir += PAGE_OFFSET >> PGDIR_SHIFT;
69
70 while (address < (unsigned long)high_memory) {
71 pg_table = (pte_t *) __pa (next_pgtable);
72 next_pgtable += PTRS_PER_PTE * sizeof (pte_t);
73 pgd_val(*pg_dir) = (unsigned long) pg_table;
74 pg_dir++;
75
76 /* now change pg_table to kernel virtual addresses */
77 pg_table = (pte_t *) __va ((unsigned long) pg_table);
78 for (i=0; i<PTRS_PER_PTE; ++i, ++pg_table) {
79 pte_t pte = pfn_pte(virt_to_pfn(address), PAGE_INIT);
80 if (address >= (unsigned long)high_memory)
81 pte_val (pte) = 0;
82 set_pte (pg_table, pte);
83 address += PAGE_SIZE;
84 }
85 }
86
87 mmu_emu_init(bootmem_end);
88
89 current->mm = NULL;
90
91 /* memory sizing is a hack stolen from motorola.c.. hope it works for us */
Roman Zippel2dcf15b2006-06-23 02:04:58 -070092 zones_size[ZONE_DMA] = ((unsigned long)high_memory - PAGE_OFFSET) >> PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Sam Creaseya3a79bd2006-12-09 10:34:38 +010094 /* I really wish I knew why the following change made things better... -- Sam */
95/* free_area_init(zones_size); */
Johannes Weiner9109fb72008-07-23 21:27:20 -070096 free_area_init_node(0, zones_size,
Sam Creaseya3a79bd2006-12-09 10:34:38 +010097 (__pa(PAGE_OFFSET) >> PAGE_SHIFT) + 1, NULL);
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100}
101
102