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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Copyright (C) 2007-2008 Michal Simek <monstr@monstr.eu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2006 Atmark Techno, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * License. See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * for more details.
^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) #include <linux/dma-map-ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.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/mm.h> /* mem_init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/initrd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/pfn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/pgalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <asm/tlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <asm/fixmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /* Use for MMU and noMMU because of PCI generic code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) int mem_init_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #ifndef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) unsigned int __page_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) EXPORT_SYMBOL(__page_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #endif /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) char *klimit = _end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * Initialize the bootmem system and give it all the memory we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * have available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) unsigned long memory_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) EXPORT_SYMBOL(memory_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) unsigned long memory_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) EXPORT_SYMBOL(memory_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) unsigned long lowmem_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) EXPORT_SYMBOL(min_low_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) EXPORT_SYMBOL(max_low_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) pte_t *kmap_pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) EXPORT_SYMBOL(kmap_pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static void __init highmem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	pr_debug("%x\n", (u32)PKMAP_BASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	map_page(PKMAP_BASE, 0, 0);	/* XXX gross */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	pkmap_page_table = virt_to_kpte(PKMAP_BASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	kmap_pte = virt_to_kpte(__fix_to_virt(FIX_KMAP_BEGIN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static void highmem_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	unsigned long pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	for (pfn = max_low_pfn; pfn < max_pfn; ++pfn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		struct page *page = pfn_to_page(pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		/* FIXME not sure about */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		if (!memblock_is_reserved(pfn << PAGE_SHIFT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			free_highmem_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #endif /* CONFIG_HIGHMEM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * paging_init() sets up the page tables - in fact we've already done this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static void __init paging_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	unsigned long zones_size[MAX_NR_ZONES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	/* Setup fixmaps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	for (idx = 0; idx < __end_of_fixed_addresses; idx++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		clear_fixmap(idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	/* Clean every zones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	memset(zones_size, 0, sizeof(zones_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	highmem_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	zones_size[ZONE_DMA] = max_low_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	zones_size[ZONE_HIGHMEM] = max_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	zones_size[ZONE_DMA] = max_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	/* We don't have holes in memory map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	free_area_init(zones_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void __init setup_memory(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #ifndef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	u32 kernel_align_start, kernel_align_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	phys_addr_t start, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	u64 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	/* Find main memory where is the kernel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	for_each_mem_range(i, &start, &end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		memory_start = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		lowmem_size = end - start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		if ((memory_start <= (u32)_text) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			((u32)_text <= (memory_start + lowmem_size - 1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			memory_size = lowmem_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			PAGE_OFFSET = memory_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			pr_info("%s: Main mem: 0x%x, size 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 				__func__, (u32) memory_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 					(u32) memory_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		}
^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) 	if (!memory_start || !memory_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		panic("%s: Missing memory setting 0x%08x, size=0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			__func__, (u32) memory_start, (u32) memory_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	/* reservation of region where is the kernel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	kernel_align_start = PAGE_DOWN((u32)_text);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	/* ALIGN can be remove because _end in vmlinux.lds.S is align */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	kernel_align_size = PAGE_UP((u32)klimit) - kernel_align_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	pr_info("%s: kernel addr:0x%08x-0x%08x size=0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		__func__, kernel_align_start, kernel_align_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			+ kernel_align_size, kernel_align_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	memblock_reserve(kernel_align_start, kernel_align_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	 * Kernel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	 * start: base phys address of kernel - page align
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	 * end: base phys address of kernel - page align
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	 * min_low_pfn - the first page (mm/bootmem.c - node_boot_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	 * max_low_pfn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	 * max_mapnr - the first unused page (mm/bootmem.c - node_low_pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	/* memory start is from the kernel end (aligned) to higher addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	min_low_pfn = memory_start >> PAGE_SHIFT; /* minimum for allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/* RAM is assumed contiguous */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	max_mapnr = memory_size >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	max_low_pfn = ((u64)memory_start + (u64)lowmem_size) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	max_pfn = ((u64)memory_start + (u64)memory_size) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	pr_info("%s: max_mapnr: %#lx\n", __func__, max_mapnr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	pr_info("%s: min_low_pfn: %#lx\n", __func__, min_low_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	pr_info("%s: max_low_pfn: %#lx\n", __func__, max_low_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	pr_info("%s: max_pfn: %#lx\n", __func__, max_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	paging_init();
^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) void __init mem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	high_memory = (void *)__va(memory_start + lowmem_size - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/* this will put all memory onto the freelists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	memblock_free_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	highmem_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	mem_init_print_info(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	mem_init_done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #ifndef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) int page_is_ram(unsigned long pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	return __range_ok(pfn, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) int page_is_ram(unsigned long pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	return pfn < max_low_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * Check for command-line options that affect what MMU_init will do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static void mm_cmdline_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	unsigned long maxmem = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	char *p = cmd_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	/* Look for mem= option on command line */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	p = strstr(cmd_line, "mem=");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		p += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		maxmem = memparse(p, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		if (maxmem && memory_size > maxmem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			memory_size = maxmem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			memblock.memory.regions[0].size = memory_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * MMU_init_hw does the chip-specific initialization of the MMU hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static void __init mmu_init_hw(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	 * The Zone Protection Register (ZPR) defines how protection will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	 * be applied to every page which is a member of a given zone. At
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	 * present, we utilize only two of the zones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	 * The zone index bits (of ZSEL) in the PTE are used for software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	 * indicators, except the LSB.  For user access, zone 1 is used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	 * for kernel access, zone 0 is used.  We set all but zone 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	 * to zero, allowing only kernel access as indicated in the PTE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	 * For zone 1, we set a 01 binary (a value of 10 will not work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	 * to allow user access as indicated in the PTE.  This also allows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	 * kernel access as indicated in the PTE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	__asm__ __volatile__ ("ori r11, r0, 0x10000000;" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			"mts rzpr, r11;"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			: : : "r11");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^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)  * MMU_init sets up the basic memory mappings for the kernel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  * including both RAM and possibly some I/O regions,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * and sets up the page tables and the MMU hardware ready to go.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /* called from head.S */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) asmlinkage void __init mmu_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	unsigned int kstart, ksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (!memblock.reserved.cnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		pr_emerg("Error memory count\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		machine_restart(NULL);
^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) 	if ((u32) memblock.memory.regions[0].size < 0x400000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		pr_emerg("Memory must be greater than 4MB\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		machine_restart(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if ((u32) memblock.memory.regions[0].size < kernel_tlb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		pr_emerg("Kernel size is greater than memory node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		machine_restart(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	/* Find main memory where the kernel is */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	memory_start = (u32) memblock.memory.regions[0].base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	lowmem_size = memory_size = (u32) memblock.memory.regions[0].size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	if (lowmem_size > CONFIG_LOWMEM_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		lowmem_size = CONFIG_LOWMEM_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) #ifndef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		memory_size = lowmem_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) #endif
^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) 	mm_cmdline_setup(); /* FIXME parse args from command line - not used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	 * Map out the kernel text/data/bss from the available physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	 * memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	kstart = __pa(CONFIG_KERNEL_START); /* kernel start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	/* kernel size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	ksize = PAGE_ALIGN(((u32)_end - (u32)CONFIG_KERNEL_START));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	memblock_reserve(kstart, ksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #if defined(CONFIG_BLK_DEV_INITRD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	/* Remove the init RAM disk from the available memory. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (initrd_start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		size = initrd_end - initrd_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		memblock_reserve(__virt_to_phys(initrd_start), size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) #endif /* CONFIG_BLK_DEV_INITRD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	/* Initialize the MMU hardware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	mmu_init_hw();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	/* Map in all of RAM starting at CONFIG_KERNEL_START */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	mapin_ram();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	/* Extend vmalloc and ioremap area as big as possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	ioremap_base = ioremap_bot = PKMAP_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	ioremap_base = ioremap_bot = FIXADDR_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	/* Initialize the context management stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	mmu_context_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	/* Shortly after that, the entire linear mapping will be available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	/* This will also cause that unflatten device tree will be allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	 * inside 768MB limit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	memblock_set_current_limit(memory_start + lowmem_size - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	parse_early_param();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	/* CMA initialization */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	dma_contiguous_reserve(memory_start + lowmem_size - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /* This is only called until mem_init is done. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) void __init *early_get_page(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	 * Mem start + kernel_tlb -> here is limit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	 * because of mem mapping from head.S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	return memblock_alloc_try_nid_raw(PAGE_SIZE, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 				MEMBLOCK_LOW_LIMIT, memory_start + kernel_tlb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 				NUMA_NO_NODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) #endif /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) void * __ref zalloc_maybe_bootmem(size_t size, gfp_t mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	void *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	if (mem_init_done) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		p = kzalloc(size, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		p = memblock_alloc(size, SMP_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			panic("%s: Failed to allocate %zu bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			      __func__, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }