Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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/parisc/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)  *  Copyright 1999 SuSE GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *    changed by Philipp Rumpf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Copyright 1999 Philipp Rumpf (prumpf@tux.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  Copyright 2004 Randolph Chung (tausq@debian.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  Copyright 2006-2007 Helge Deller (deller@gmx.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/initrd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/nodemask.h>	/* for node_online_map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/pagemap.h>	/* for release_pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <asm/pgalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <asm/tlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <asm/pdc_chassis.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <asm/mmzone.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <asm/msgbuf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <asm/sparsemem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) extern int  data_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) extern void parisc_kernel_start(void);	/* Kernel entry point in head.S */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #if CONFIG_PGTABLE_LEVELS == 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /* NOTE: This layout exactly conforms to the hybrid L2/L3 page table layout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * with the first pmd adjacent to the pgd and below it. gcc doesn't actually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * guarantee that global objects will be laid out in memory in the same order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * as the order of declaration, so put these in different sections and use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * the linker script to order them. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) pmd_t pmd0[PTRS_PER_PMD] __section(".data..vm0.pmd") __attribute__ ((aligned(PAGE_SIZE)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(".data..vm0.pgd") __attribute__ ((aligned(PAGE_SIZE)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) pte_t pg0[PT_INITIAL * PTRS_PER_PTE] __section(".data..vm0.pte") __attribute__ ((aligned(PAGE_SIZE)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static struct resource data_resource = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.name	= "Kernel data",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.flags	= IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static struct resource code_resource = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.name	= "Kernel code",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	.flags	= IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static struct resource pdcdata_resource = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	.name	= "PDC data (Page Zero)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	.start	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	.end	= 0x9ff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	.flags	= IORESOURCE_BUSY | IORESOURCE_MEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static struct resource sysram_resources[MAX_PHYSMEM_RANGES] __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) /* The following array is initialized from the firmware specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * information retrieved in kernel/inventory.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) physmem_range_t pmem_ranges[MAX_PHYSMEM_RANGES] __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) int npmem_ranges __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define MAX_MEM         (1UL << MAX_PHYSMEM_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #else /* !CONFIG_64BIT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #define MAX_MEM         (3584U*1024U*1024U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #endif /* !CONFIG_64BIT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static unsigned long mem_limit __read_mostly = MAX_MEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static void __init mem_limit_func(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	char *cp, *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	unsigned long limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	/* We need this before __setup() functions are called */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	limit = MAX_MEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	for (cp = boot_command_line; *cp; ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (memcmp(cp, "mem=", 4) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			cp += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			limit = memparse(cp, &end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			if (end != cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			cp = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			while (*cp != ' ' && *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 				++cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			while (*cp == ' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				++cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (limit < mem_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		mem_limit = limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define MAX_GAP (0x40000000UL >> PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static void __init setup_bootmem(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	unsigned long mem_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #ifndef CONFIG_SPARSEMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	physmem_range_t pmem_holes[MAX_PHYSMEM_RANGES - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	int npmem_holes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	int i, sysram_resource_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	disable_sr_hashing(); /* Turn off space register hashing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	 * Sort the ranges. Since the number of ranges is typically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	 * small, and performance is not an issue here, just do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	 * a simple insertion sort.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	for (i = 1; i < npmem_ranges; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		for (j = i; j > 0; j--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			physmem_range_t tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			if (pmem_ranges[j-1].start_pfn <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			    pmem_ranges[j].start_pfn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			tmp = pmem_ranges[j-1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			pmem_ranges[j-1] = pmem_ranges[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			pmem_ranges[j] = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #ifndef CONFIG_SPARSEMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	 * Throw out ranges that are too far apart (controlled by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	 * MAX_GAP).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	for (i = 1; i < npmem_ranges; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		if (pmem_ranges[i].start_pfn -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			(pmem_ranges[i-1].start_pfn +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			 pmem_ranges[i-1].pages) > MAX_GAP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			npmem_ranges = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			printk("Large gap in memory detected (%ld pages). "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			       "Consider turning on CONFIG_SPARSEMEM\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			       pmem_ranges[i].start_pfn -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			       (pmem_ranges[i-1].start_pfn +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			        pmem_ranges[i-1].pages));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/* Print the memory ranges */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	pr_info("Memory Ranges:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	for (i = 0; i < npmem_ranges; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		struct resource *res = &sysram_resources[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		unsigned long start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		size = (pmem_ranges[i].pages << PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		start = (pmem_ranges[i].start_pfn << PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		pr_info("%2d) Start 0x%016lx End 0x%016lx Size %6ld MB\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			i, start, start + (size - 1), size >> 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		/* request memory resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		res->name = "System RAM";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		res->start = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		res->end = start + size - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		request_resource(&iomem_resource, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	sysram_resource_count = npmem_ranges;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	 * For 32 bit kernels we limit the amount of memory we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	 * support, in order to preserve enough kernel address space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	 * for other purposes. For 64 bit kernels we don't normally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	 * limit the memory, but this mechanism can be used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	 * artificially limit the amount of memory (and it is written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	 * to work with multiple memory ranges).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	mem_limit_func();       /* check for "mem=" argument */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	mem_max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	for (i = 0; i < npmem_ranges; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		unsigned long rsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		rsize = pmem_ranges[i].pages << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		if ((mem_max + rsize) > mem_limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			printk(KERN_WARNING "Memory truncated to %ld MB\n", mem_limit >> 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			if (mem_max == mem_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 				npmem_ranges = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 				pmem_ranges[i].pages =   (mem_limit >> PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 						       - (mem_max >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 				npmem_ranges = i + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 				mem_max = mem_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		mem_max += rsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	printk(KERN_INFO "Total Memory: %ld MB\n",mem_max >> 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #ifndef CONFIG_SPARSEMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	/* Merge the ranges, keeping track of the holes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		unsigned long end_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		unsigned long hole_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		npmem_holes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		end_pfn = pmem_ranges[0].start_pfn + pmem_ranges[0].pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		for (i = 1; i < npmem_ranges; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			hole_pages = pmem_ranges[i].start_pfn - end_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			if (hole_pages) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 				pmem_holes[npmem_holes].start_pfn = end_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 				pmem_holes[npmem_holes++].pages = hole_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 				end_pfn += hole_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			end_pfn += pmem_ranges[i].pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		pmem_ranges[0].pages = end_pfn - pmem_ranges[0].start_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		npmem_ranges = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 * Initialize and free the full range of memory in each range.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	max_pfn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	for (i = 0; i < npmem_ranges; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		unsigned long start_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		unsigned long npages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		unsigned long start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		start_pfn = pmem_ranges[i].start_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		npages = pmem_ranges[i].pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		start = start_pfn << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		size = npages << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		/* add system RAM memblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		memblock_add(start, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		if ((start_pfn + npages) > max_pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			max_pfn = start_pfn + npages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	 * We can't use memblock top-down allocations because we only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	 * created the initial mapping up to KERNEL_INITIAL_SIZE in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	 * the assembly bootup code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	memblock_set_bottom_up(true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	/* IOMMU is always used to access "high mem" on those boxes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	 * that can support enough mem that a PCI device couldn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	 * directly DMA to any physical addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	 * ISA DMA support will need to revisit this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	max_low_pfn = max_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	/* reserve PAGE0 pdc memory, kernel text/data/bss & bootmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #define PDC_CONSOLE_IO_IODC_SIZE 32768
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	memblock_reserve(0UL, (unsigned long)(PAGE0->mem_free +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 				PDC_CONSOLE_IO_IODC_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	memblock_reserve(__pa(KERNEL_BINARY_TEXT_START),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			(unsigned long)(_end - KERNEL_BINARY_TEXT_START));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) #ifndef CONFIG_SPARSEMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	/* reserve the holes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	for (i = 0; i < npmem_holes; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		memblock_reserve((pmem_holes[i].start_pfn << PAGE_SHIFT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 				(pmem_holes[i].pages << PAGE_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #ifdef CONFIG_BLK_DEV_INITRD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	if (initrd_start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		printk(KERN_INFO "initrd: %08lx-%08lx\n", initrd_start, initrd_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		if (__pa(initrd_start) < mem_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			unsigned long initrd_reserve;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			if (__pa(initrd_end) > mem_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 				initrd_reserve = mem_max - __pa(initrd_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 				initrd_reserve = initrd_end - initrd_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			initrd_below_start_ok = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			printk(KERN_INFO "initrd: reserving %08lx-%08lx (mem_max %08lx)\n", __pa(initrd_start), __pa(initrd_start) + initrd_reserve, mem_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			memblock_reserve(__pa(initrd_start), initrd_reserve);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	data_resource.start =  virt_to_phys(&data_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	data_resource.end = virt_to_phys(_end) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	code_resource.start = virt_to_phys(_text);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	code_resource.end = virt_to_phys(&data_start)-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	/* We don't know which region the kernel will be in, so try
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	 * all of them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	for (i = 0; i < sysram_resource_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		struct resource *res = &sysram_resources[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		request_resource(res, &code_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		request_resource(res, &data_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	request_resource(&sysram_resources[0], &pdcdata_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	/* Initialize Page Deallocation Table (PDT) and check for bad memory. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	pdc_pdt_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	memblock_allow_resize();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	memblock_dump_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static bool kernel_set_to_readonly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static void __ref map_pages(unsigned long start_vaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 			    unsigned long start_paddr, unsigned long size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			    pgprot_t pgprot, int force)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	pmd_t *pmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	pte_t *pg_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	unsigned long end_paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	unsigned long start_pmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	unsigned long start_pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	unsigned long tmp1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	unsigned long tmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	unsigned long address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	unsigned long vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	unsigned long ro_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	unsigned long ro_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	unsigned long kernel_start, kernel_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	ro_start = __pa((unsigned long)_text);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	ro_end   = __pa((unsigned long)&data_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	kernel_start = __pa((unsigned long)&__init_begin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	kernel_end  = __pa((unsigned long)&_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	end_paddr = start_paddr + size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	/* for 2-level configuration PTRS_PER_PMD is 0 so start_pmd will be 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	start_pmd = ((start_vaddr >> PMD_SHIFT) & (PTRS_PER_PMD - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	start_pte = ((start_vaddr >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	address = start_paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	vaddr = start_vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	while (address < end_paddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		pgd_t *pgd = pgd_offset_k(vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		p4d_t *p4d = p4d_offset(pgd, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		pud_t *pud = pud_offset(p4d, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) #if CONFIG_PGTABLE_LEVELS == 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		if (pud_none(*pud)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 			pmd = memblock_alloc(PAGE_SIZE << PMD_ORDER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 					     PAGE_SIZE << PMD_ORDER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			if (!pmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 				panic("pmd allocation failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			pud_populate(NULL, pud, pmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		pmd = pmd_offset(pud, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		for (tmp1 = start_pmd; tmp1 < PTRS_PER_PMD; tmp1++, pmd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 			if (pmd_none(*pmd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 				pg_table = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 				if (!pg_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 					panic("page table allocation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 				pmd_populate_kernel(NULL, pmd, pg_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			pg_table = pte_offset_kernel(pmd, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			for (tmp2 = start_pte; tmp2 < PTRS_PER_PTE; tmp2++, pg_table++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 				pte_t pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 				pgprot_t prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 				bool huge = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 				if (force) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 					prot = pgprot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 				} else if (address < kernel_start || address >= kernel_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 					/* outside kernel memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 					prot = PAGE_KERNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 				} else if (!kernel_set_to_readonly) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 					/* still initializing, allow writing to RO memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 					prot = PAGE_KERNEL_RWX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 					huge = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 				} else if (address >= ro_start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 					/* Code (ro) and Data areas */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 					prot = (address < ro_end) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 						PAGE_KERNEL_EXEC : PAGE_KERNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 					huge = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 					prot = PAGE_KERNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 				pte = __mk_pte(address, prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 				if (huge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 					pte = pte_mkhuge(pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 				if (address >= end_paddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 				set_pte(pg_table, pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 				address += PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 				vaddr += PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 			start_pte = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 			if (address >= end_paddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 			    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		start_pmd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) void __init set_kernel_text_rw(int enable_read_write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	unsigned long start = (unsigned long) __init_begin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	unsigned long end   = (unsigned long) &data_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	map_pages(start, __pa(start), end-start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		PAGE_KERNEL_RWX, enable_read_write ? 1:0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	/* force the kernel to see the new page table entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	flush_cache_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	flush_tlb_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) void free_initmem(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	unsigned long init_begin = (unsigned long)__init_begin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	unsigned long init_end = (unsigned long)__init_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	unsigned long kernel_end  = (unsigned long)&_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	/* Remap kernel text and data, but do not touch init section yet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	kernel_set_to_readonly = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	map_pages(init_end, __pa(init_end), kernel_end - init_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		  PAGE_KERNEL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	/* The init text pages are marked R-X.  We have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	 * flush the icache and mark them RW-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	 * Do a dummy remap of the data section first (the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	 * section is already PAGE_KERNEL) to pull in the TLB entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	 * for map_kernel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	map_pages(init_begin, __pa(init_begin), init_end - init_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		  PAGE_KERNEL_RWX, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	/* now remap at PAGE_KERNEL since the TLB is pre-primed to execute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	 * map_pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	map_pages(init_begin, __pa(init_begin), init_end - init_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		  PAGE_KERNEL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	/* force the kernel to see the new TLB entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	__flush_tlb_range(0, init_begin, kernel_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	/* finally dump all the instructions which were cached, since the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	 * pages are no-longer executable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	flush_icache_range(init_begin, init_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	free_initmem_default(POISON_FREE_INITMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	/* set up a new led state on systems shipped LED State panel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	pdc_chassis_send_status(PDC_CHASSIS_DIRECT_BCOMPLETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) #ifdef CONFIG_STRICT_KERNEL_RWX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) void mark_rodata_ro(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	/* rodata memory was already mapped with KERNEL_RO access rights by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)            pagetable_init() and map_pages(). No need to do additional stuff here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	unsigned long roai_size = __end_ro_after_init - __start_ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	pr_info("Write protected read-only-after-init data: %luk\n", roai_size >> 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)  * Just an arbitrary offset to serve as a "hole" between mapping areas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)  * (between top of physical memory and a potential pcxl dma mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)  * area, and below the vmalloc mapping area).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)  * The current 32K value just means that there will be a 32K "hole"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)  * between mapping areas. That means that  any out-of-bounds memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)  * accesses will hopefully be caught. The vmalloc() routines leaves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)  * a hole of 4kB between each vmalloced area for the same reason.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)  /* Leave room for gateway page expansion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) #if KERNEL_MAP_START < GATEWAY_PAGE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) #error KERNEL_MAP_START is in gateway reserved region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) #define MAP_START (KERNEL_MAP_START)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) #define VM_MAP_OFFSET  (32*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) #define SET_MAP_OFFSET(x) ((void *)(((unsigned long)(x) + VM_MAP_OFFSET) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 				     & ~(VM_MAP_OFFSET-1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) void *parisc_vmalloc_start __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) EXPORT_SYMBOL(parisc_vmalloc_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) #ifdef CONFIG_PA11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) unsigned long pcxl_dma_start __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) void __init mem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	/* Do sanity checks on IPC (compat) structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	BUILD_BUG_ON(sizeof(struct ipc64_perm) != 48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) #ifndef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	BUILD_BUG_ON(sizeof(struct semid64_ds) != 80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	BUILD_BUG_ON(sizeof(struct msqid64_ds) != 104);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	BUILD_BUG_ON(sizeof(struct shmid64_ds) != 104);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	BUILD_BUG_ON(sizeof(struct compat_ipc64_perm) != sizeof(struct ipc64_perm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	BUILD_BUG_ON(sizeof(struct compat_semid64_ds) != 80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	BUILD_BUG_ON(sizeof(struct compat_msqid64_ds) != 104);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	BUILD_BUG_ON(sizeof(struct compat_shmid64_ds) != 104);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	/* Do sanity checks on page table constants */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	BUILD_BUG_ON(PTE_ENTRY_SIZE != sizeof(pte_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	BUILD_BUG_ON(PMD_ENTRY_SIZE != sizeof(pmd_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	BUILD_BUG_ON(PGD_ENTRY_SIZE != sizeof(pgd_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	BUILD_BUG_ON(PAGE_SHIFT + BITS_PER_PTE + BITS_PER_PMD + BITS_PER_PGD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 			> BITS_PER_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	high_memory = __va((max_pfn << PAGE_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	set_max_mapnr(max_low_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	memblock_free_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) #ifdef CONFIG_PA11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	if (boot_cpu_data.cpu_type == pcxl2 || boot_cpu_data.cpu_type == pcxl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		pcxl_dma_start = (unsigned long)SET_MAP_OFFSET(MAP_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		parisc_vmalloc_start = SET_MAP_OFFSET(pcxl_dma_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 						+ PCXL_DMA_MAP_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		parisc_vmalloc_start = SET_MAP_OFFSET(MAP_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	mem_init_print_info(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	 * Do not expose the virtual kernel memory layout to userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	 * But keep code for debugging purposes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	printk("virtual kernel memory layout:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	       "     vmalloc : 0x%px - 0x%px   (%4ld MB)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	       "     fixmap  : 0x%px - 0x%px   (%4ld kB)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	       "     memory  : 0x%px - 0x%px   (%4ld MB)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	       "       .init : 0x%px - 0x%px   (%4ld kB)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	       "       .data : 0x%px - 0x%px   (%4ld kB)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	       "       .text : 0x%px - 0x%px   (%4ld kB)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	       (void*)VMALLOC_START, (void*)VMALLOC_END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	       (VMALLOC_END - VMALLOC_START) >> 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	       (void *)FIXMAP_START, (void *)(FIXMAP_START + FIXMAP_SIZE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	       (unsigned long)(FIXMAP_SIZE / 1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	       __va(0), high_memory,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	       ((unsigned long)high_memory - (unsigned long)__va(0)) >> 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	       __init_begin, __init_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	       ((unsigned long)__init_end - (unsigned long)__init_begin) >> 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	       _etext, _edata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	       ((unsigned long)_edata - (unsigned long)_etext) >> 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	       _text, _etext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	       ((unsigned long)_etext - (unsigned long)_text) >> 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) unsigned long *empty_zero_page __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) EXPORT_SYMBOL(empty_zero_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)  * pagetable_init() sets up the page tables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)  * Note that gateway_init() places the Linux gateway page at page 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)  * Since gateway pages cannot be dereferenced this has the desirable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)  * side effect of trapping those pesky NULL-reference errors in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)  * kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) static void __init pagetable_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	int range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	/* Map each physical memory range to its kernel vaddr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	for (range = 0; range < npmem_ranges; range++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 		unsigned long start_paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		unsigned long end_paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 		unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		start_paddr = pmem_ranges[range].start_pfn << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		size = pmem_ranges[range].pages << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 		end_paddr = start_paddr + size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 		map_pages((unsigned long)__va(start_paddr), start_paddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 			  size, PAGE_KERNEL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) #ifdef CONFIG_BLK_DEV_INITRD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	if (initrd_end && initrd_end > mem_limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		printk(KERN_INFO "initrd: mapping %08lx-%08lx\n", initrd_start, initrd_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		map_pages(initrd_start, __pa(initrd_start),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 			  initrd_end - initrd_start, PAGE_KERNEL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	if (!empty_zero_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 		panic("zero page allocation failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) static void __init gateway_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	unsigned long linux_gateway_page_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	/* FIXME: This is 'const' in order to trick the compiler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	   into not treating it as DP-relative data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	extern void * const linux_gateway_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	linux_gateway_page_addr = LINUX_GATEWAY_ADDR & PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	 * Setup Linux Gateway page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	 * The Linux gateway page will reside in kernel space (on virtual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	 * page 0), so it doesn't need to be aliased into user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	map_pages(linux_gateway_page_addr, __pa(&linux_gateway_page),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 		  PAGE_SIZE, PAGE_GATEWAY, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) static void __init parisc_bootmem_free(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	max_zone_pfn[0] = memblock_end_of_DRAM();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	free_area_init(max_zone_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) void __init paging_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	setup_bootmem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	pagetable_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	gateway_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	flush_cache_all_local(); /* start with known state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	flush_tlb_all_local(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	sparse_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	parisc_bootmem_free();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) #ifdef CONFIG_PA20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)  * Currently, all PA20 chips have 18 bit protection IDs, which is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)  * limiting factor (space ids are 32 bits).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) #define NR_SPACE_IDS 262144
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)  * Currently we have a one-to-one relationship between space IDs and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)  * protection IDs. Older parisc chips (PCXS, PCXT, PCXL, PCXL2) only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)  * support 15 bit protection IDs, so that is the limiting factor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)  * PCXT' has 18 bit protection IDs, but only 16 bit spaceids, so it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)  * probably not worth the effort for a special case here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) #define NR_SPACE_IDS 32768
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) #endif  /* !CONFIG_PA20 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) #define RECYCLE_THRESHOLD (NR_SPACE_IDS / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) #define SID_ARRAY_SIZE  (NR_SPACE_IDS / (8 * sizeof(long)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) static unsigned long space_id[SID_ARRAY_SIZE] = { 1 }; /* disallow space 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) static unsigned long dirty_space_id[SID_ARRAY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) static unsigned long space_id_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) static unsigned long free_space_ids = NR_SPACE_IDS - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) static unsigned long dirty_space_ids = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) static DEFINE_SPINLOCK(sid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) unsigned long alloc_sid(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	spin_lock(&sid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	if (free_space_ids == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 		if (dirty_space_ids != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 			spin_unlock(&sid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 			flush_tlb_all(); /* flush_tlb_all() calls recycle_sids() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 			spin_lock(&sid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 		BUG_ON(free_space_ids == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	free_space_ids--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	index = find_next_zero_bit(space_id, NR_SPACE_IDS, space_id_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	space_id[BIT_WORD(index)] |= BIT_MASK(index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	space_id_index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	spin_unlock(&sid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	return index << SPACEID_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) void free_sid(unsigned long spaceid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 	unsigned long index = spaceid >> SPACEID_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	unsigned long *dirty_space_offset, mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 	dirty_space_offset = &dirty_space_id[BIT_WORD(index)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 	mask = BIT_MASK(index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	spin_lock(&sid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 	BUG_ON(*dirty_space_offset & mask); /* attempt to free space id twice */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 	*dirty_space_offset |= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	dirty_space_ids++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	spin_unlock(&sid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) static void get_dirty_sids(unsigned long *ndirtyptr,unsigned long *dirty_array)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	/* NOTE: sid_lock must be held upon entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 	*ndirtyptr = dirty_space_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	if (dirty_space_ids != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 	    for (i = 0; i < SID_ARRAY_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 		dirty_array[i] = dirty_space_id[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 		dirty_space_id[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 	    dirty_space_ids = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) static void recycle_sids(unsigned long ndirty,unsigned long *dirty_array)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	/* NOTE: sid_lock must be held upon entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 	if (ndirty != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 		for (i = 0; i < SID_ARRAY_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 			space_id[i] ^= dirty_array[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 		free_space_ids += ndirty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 		space_id_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) #else /* CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) static void recycle_sids(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	/* NOTE: sid_lock must be held upon entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	if (dirty_space_ids != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 		for (i = 0; i < SID_ARRAY_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 			space_id[i] ^= dirty_space_id[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 			dirty_space_id[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 		free_space_ids += dirty_space_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 		dirty_space_ids = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 		space_id_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)  * flush_tlb_all() calls recycle_sids(), since whenever the entire tlb is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)  * purged, we can safely reuse the space ids that were released but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)  * not flushed from the tlb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) static unsigned long recycle_ndirty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) static unsigned long recycle_dirty_array[SID_ARRAY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) static unsigned int recycle_inuse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) void flush_tlb_all(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	int do_recycle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 	do_recycle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 	spin_lock(&sid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	__inc_irq_stat(irq_tlb_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 	if (dirty_space_ids > RECYCLE_THRESHOLD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 	    BUG_ON(recycle_inuse);  /* FIXME: Use a semaphore/wait queue here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 	    get_dirty_sids(&recycle_ndirty,recycle_dirty_array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 	    recycle_inuse++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	    do_recycle++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 	spin_unlock(&sid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 	on_each_cpu(flush_tlb_all_local, NULL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 	if (do_recycle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 	    spin_lock(&sid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 	    recycle_sids(recycle_ndirty,recycle_dirty_array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 	    recycle_inuse = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 	    spin_unlock(&sid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) void flush_tlb_all(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 	spin_lock(&sid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 	__inc_irq_stat(irq_tlb_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 	flush_tlb_all_local(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 	recycle_sids();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 	spin_unlock(&sid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) #endif