Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Mike Rapoport | 57c8a66 | 2018-10-30 15:09:49 -0700 | [diff] [blame] | 19 | #include <linux/memblock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | #include <asm/setup.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 22 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/machdep.h> |
| 25 | #include <asm/io.h> |
| 26 | |
| 27 | extern void mmu_emu_init (unsigned long bootmem_end); |
| 28 | |
| 29 | const char bad_pmd_string[] = "Bad pmd in pte_alloc: %08lx\n"; |
| 30 | |
| 31 | extern unsigned long num_pages; |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Mike Rapoport | 5d2ee1a | 2020-06-03 15:57:32 -0700 | [diff] [blame] | 44 | unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | unsigned long size; |
| 46 | |
Mike Rapoport | 15c3c11 | 2018-10-30 15:08:58 -0700 | [diff] [blame] | 47 | empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE); |
Mike Rapoport | 8a7f97b | 2019-03-11 23:30:31 -0700 | [diff] [blame] | 48 | if (!empty_zero_page) |
| 49 | panic("%s: Failed to allocate %lu bytes align=0x%lx\n", |
| 50 | __func__, PAGE_SIZE, PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | address = PAGE_OFFSET; |
| 53 | pg_dir = swapper_pg_dir; |
| 54 | memset (swapper_pg_dir, 0, sizeof (swapper_pg_dir)); |
| 55 | memset (kernel_pg_dir, 0, sizeof (kernel_pg_dir)); |
| 56 | |
| 57 | size = num_pages * sizeof(pte_t); |
| 58 | size = (size + PAGE_SIZE) & ~(PAGE_SIZE-1); |
| 59 | |
Mike Rapoport | 15c3c11 | 2018-10-30 15:08:58 -0700 | [diff] [blame] | 60 | next_pgtable = (unsigned long)memblock_alloc(size, PAGE_SIZE); |
Mike Rapoport | 8a7f97b | 2019-03-11 23:30:31 -0700 | [diff] [blame] | 61 | if (!next_pgtable) |
| 62 | panic("%s: Failed to allocate %lu bytes align=0x%lx\n", |
| 63 | __func__, size, PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | bootmem_end = (next_pgtable + size + PAGE_SIZE) & PAGE_MASK; |
| 65 | |
| 66 | /* Map whole memory from PAGE_OFFSET (0x0E000000) */ |
| 67 | pg_dir += PAGE_OFFSET >> PGDIR_SHIFT; |
| 68 | |
| 69 | while (address < (unsigned long)high_memory) { |
| 70 | pg_table = (pte_t *) __pa (next_pgtable); |
| 71 | next_pgtable += PTRS_PER_PTE * sizeof (pte_t); |
| 72 | pgd_val(*pg_dir) = (unsigned long) pg_table; |
| 73 | pg_dir++; |
| 74 | |
| 75 | /* now change pg_table to kernel virtual addresses */ |
| 76 | pg_table = (pte_t *) __va ((unsigned long) pg_table); |
| 77 | for (i=0; i<PTRS_PER_PTE; ++i, ++pg_table) { |
| 78 | pte_t pte = pfn_pte(virt_to_pfn(address), PAGE_INIT); |
| 79 | if (address >= (unsigned long)high_memory) |
| 80 | pte_val (pte) = 0; |
| 81 | set_pte (pg_table, pte); |
| 82 | address += PAGE_SIZE; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | mmu_emu_init(bootmem_end); |
| 87 | |
| 88 | current->mm = NULL; |
| 89 | |
| 90 | /* memory sizing is a hack stolen from motorola.c.. hope it works for us */ |
Mike Rapoport | 5d2ee1a | 2020-06-03 15:57:32 -0700 | [diff] [blame] | 91 | max_zone_pfn[ZONE_DMA] = ((unsigned long)high_memory) >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Sam Creasey | a3a79bd | 2006-12-09 10:34:38 +0100 | [diff] [blame] | 93 | /* I really wish I knew why the following change made things better... -- Sam */ |
Mike Rapoport | 5d2ee1a | 2020-06-03 15:57:32 -0700 | [diff] [blame] | 94 | free_area_init(max_zone_pfn); |
Sam Creasey | a3a79bd | 2006-12-09 10:34:38 +0100 | [diff] [blame] | 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
| 97 | } |