^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/alpha/mm/init.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1995 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) /* 2.3.x zone allocator, 1999 Andrea Arcangeli <andrea@suse.de> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/pagemap.h>
^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/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/mman.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/memblock.h> /* max_low_pfn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/pgalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <asm/hwrpb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <asm/dma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <asm/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <asm/tlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) extern void die_if_kernel(char *,struct pt_regs *,long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static struct pcb_struct original_pcb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) pgd_t *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) pgd_alloc(struct mm_struct *mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) pgd_t *ret, *init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ret = (pgd_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) init = pgd_offset(&init_mm, 0UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #ifdef CONFIG_ALPHA_LARGE_VMALLOC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) memcpy (ret + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) (PTRS_PER_PGD - USER_PTRS_PER_PGD - 1)*sizeof(pgd_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) pgd_val(ret[PTRS_PER_PGD-2]) = pgd_val(init[PTRS_PER_PGD-2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* The last PGD entry is the VPTB self-map. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) pgd_val(ret[PTRS_PER_PGD-1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) = pte_val(mk_pte(virt_to_page(ret), PAGE_KERNEL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * BAD_PAGE is the page that is used for page faults when linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * is out-of-memory. Older versions of linux just did a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * do_exit(), but using this instead means there is less risk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * for a process dying in kernel mode, possibly leaving an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * unused etc..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * BAD_PAGETABLE is the accompanying page-table: it is initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * to point to BAD_PAGE entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * ZERO_PAGE is a special page that is used for zero-initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * data and COW.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) pmd_t *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) __bad_pagetable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) memset((void *) EMPTY_PGT, 0, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return (pmd_t *) EMPTY_PGT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) pte_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) __bad_page(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) memset((void *) EMPTY_PGE, 0, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return pte_mkdirty(mk_pte(virt_to_page(EMPTY_PGE), PAGE_SHARED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static inline unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) load_PCB(struct pcb_struct *pcb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) register unsigned long sp __asm__("$30");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) pcb->ksp = sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return __reload_thread(pcb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* Set up initial PCB, VPTB, and other such nicities. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) switch_to_system_map(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) unsigned long newptbr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) unsigned long original_pcb_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* Initialize the kernel's page tables. Linux puts the vptb in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) the last slot of the L1 page table. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) memset(swapper_pg_dir, 0, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) newptbr = ((unsigned long) swapper_pg_dir - PAGE_OFFSET) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) pgd_val(swapper_pg_dir[1023]) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) (newptbr << 32) | pgprot_val(PAGE_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* Set the vptb. This is often done by the bootloader, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) shouldn't be required. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (hwrpb->vptb != 0xfffffffe00000000UL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) wrvptptr(0xfffffffe00000000UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) hwrpb->vptb = 0xfffffffe00000000UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) hwrpb_update_checksum(hwrpb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* Also set up the real kernel PCB while we're at it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) init_thread_info.pcb.ptbr = newptbr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) init_thread_info.pcb.flags = 1; /* set FEN, clear everything else */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) original_pcb_ptr = load_PCB(&init_thread_info.pcb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) tbia();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* Save off the contents of the original PCB so that we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) restore the original console's page tables for a clean reboot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) Note that the PCB is supposed to be a physical address, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) since KSEG values also happen to work, folks get confused.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) Check this here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (original_pcb_ptr < PAGE_OFFSET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) original_pcb_ptr = (unsigned long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) phys_to_virt(original_pcb_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) original_pcb = *(struct pcb_struct *) original_pcb_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int callback_init_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) void * __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) callback_init(void * kernel_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct crb_struct * crb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) pgd_t *pgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) p4d_t *p4d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) pud_t *pud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) pmd_t *pmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) void *two_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /* Starting at the HWRPB, locate the CRB. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) crb = (struct crb_struct *)((char *)hwrpb + hwrpb->crb_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (alpha_using_srm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /* Tell the console whither it is to be remapped. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (srm_fixup(VMALLOC_START, (unsigned long)hwrpb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) __halt(); /* "We're boned." --Bender */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* Edit the procedure descriptors for DISPATCH and FIXUP. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) crb->dispatch_va = (struct procdesc_struct *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) (VMALLOC_START + (unsigned long)crb->dispatch_va
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) - crb->map[0].va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) crb->fixup_va = (struct procdesc_struct *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) (VMALLOC_START + (unsigned long)crb->fixup_va
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) - crb->map[0].va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) switch_to_system_map();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* Allocate one PGD and one PMD. In the case of SRM, we'll need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) these to actually remap the console. There is an assumption
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) here that only one of each is needed, and this allows for 8MB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) On systems with larger consoles, additional pages will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) allocated as needed during the mapping process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) In the case of not SRM, but not CONFIG_ALPHA_LARGE_VMALLOC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) we need to allocate the PGD we use for vmalloc before we start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) forking other tasks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) two_pages = (void *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) (((unsigned long)kernel_end + ~PAGE_MASK) & PAGE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) kernel_end = two_pages + 2*PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) memset(two_pages, 0, 2*PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) pgd = pgd_offset_k(VMALLOC_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) p4d = p4d_offset(pgd, VMALLOC_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) pud = pud_offset(p4d, VMALLOC_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) pud_set(pud, (pmd_t *)two_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) pmd = pmd_offset(pud, VMALLOC_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) pmd_set(pmd, (pte_t *)(two_pages + PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (alpha_using_srm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static struct vm_struct console_remap_vm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) unsigned long nr_pages = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) unsigned long vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) unsigned long i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /* calculate needed size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) for (i = 0; i < crb->map_entries; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) nr_pages += crb->map[i].count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* register the vm area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) console_remap_vm.flags = VM_ALLOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) console_remap_vm.size = nr_pages << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) vm_area_register_early(&console_remap_vm, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) vaddr = (unsigned long)console_remap_vm.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /* Set up the third level PTEs and update the virtual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) addresses of the CRB entries. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) for (i = 0; i < crb->map_entries; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) unsigned long pfn = crb->map[i].pa >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) crb->map[i].va = vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) for (j = 0; j < crb->map[i].count; ++j) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* Newer consoles (especially on larger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) systems) may require more pages of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) PTEs. Grab additional pages as needed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (pmd != pmd_offset(pud, vaddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) memset(kernel_end, 0, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) pmd = pmd_offset(pud, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) pmd_set(pmd, (pte_t *)kernel_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) kernel_end += PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) set_pte(pte_offset_kernel(pmd, vaddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) pfn_pte(pfn, PAGE_KERNEL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) pfn++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) vaddr += PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) callback_init_done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return kernel_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) #ifndef CONFIG_DISCONTIGMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * paging_init() sets up the memory map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) void __init paging_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) unsigned long max_zone_pfn[MAX_NR_ZONES] = {0, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) unsigned long dma_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) dma_pfn = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) max_pfn = max_low_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) max_zone_pfn[ZONE_DMA] = dma_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) max_zone_pfn[ZONE_NORMAL] = max_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* Initialize mem_map[]. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) free_area_init(max_zone_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) /* Initialize the kernel's ZERO_PGE. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) memset((void *)ZERO_PGE, 0, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) #endif /* CONFIG_DISCONTIGMEM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_SRM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) srm_paging_stop (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* Move the vptb back to where the SRM console expects it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) swapper_pg_dir[1] = swapper_pg_dir[1023];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) tbia();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) wrvptptr(0x200000000UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) hwrpb->vptb = 0x200000000UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) hwrpb_update_checksum(hwrpb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* Reload the page tables that the console had in use. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) load_PCB(&original_pcb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) tbia();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) mem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) set_max_mapnr(max_low_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) memblock_free_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) mem_init_print_info(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }