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