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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #ifdef CONFIG_BLK_DEV_INITRD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/initrd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/of_fdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/arcregs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) pgd_t swapper_pg_dir[PTRS_PER_PGD] __aligned(PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) char empty_zero_page[PAGE_SIZE] __aligned(PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) EXPORT_SYMBOL(empty_zero_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static const unsigned long low_mem_start = CONFIG_LINUX_RAM_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static unsigned long low_mem_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static unsigned long min_high_pfn, max_high_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static phys_addr_t high_mem_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static phys_addr_t high_mem_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #ifdef CONFIG_DISCONTIGMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) struct pglist_data node_data[MAX_NUMNODES] __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) EXPORT_SYMBOL(node_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) long __init arc_get_mem_sz(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	return low_mem_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) /* User can over-ride above with "mem=nnn[KkMm]" in cmdline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static int __init setup_mem_sz(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	low_mem_sz = memparse(str, NULL) & PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	/* early console might not be setup yet - it will show up later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	pr_info("\"mem=%s\": mem sz set to %ldM\n", str, TO_MB(low_mem_sz));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) early_param("mem", setup_mem_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) void __init early_init_dt_add_memory_arch(u64 base, u64 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	int in_use = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (!low_mem_sz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		if (base != low_mem_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			panic("CONFIG_LINUX_RAM_BASE != DT memory { }");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		low_mem_sz = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		in_use = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		memblock_add_node(base, size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		high_mem_start = base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		high_mem_sz = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		in_use = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		memblock_add_node(base, size, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		memblock_reserve(base, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	pr_info("Memory @ %llx [%lldM] %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		base, TO_MB(size), !in_use ? "Not used":"");
^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) bool arch_has_descending_max_zone_pfns(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return !IS_ENABLED(CONFIG_ARC_HAS_PAE40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * First memory setup routine called from setup_arch()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * 1. setup swapper's mm @init_mm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * 2. Count the pages we have and setup bootmem allocator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * 3. zone setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) void __init setup_arch_memory(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	init_mm.start_code = (unsigned long)_text;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	init_mm.end_code = (unsigned long)_etext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	init_mm.end_data = (unsigned long)_edata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	init_mm.brk = (unsigned long)_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	/* first page of system - kernel .vector starts here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	min_low_pfn = ARCH_PFN_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	/* Last usable page of low mem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	max_low_pfn = max_pfn = PFN_DOWN(low_mem_start + low_mem_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #ifdef CONFIG_FLATMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	/* pfn_valid() uses this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	max_mapnr = max_low_pfn - min_low_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	/*------------- bootmem allocator setup -----------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 * seed the bootmem allocator after any DT memory node parsing or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * "mem=xxx" cmdline overrides have potentially updated @arc_mem_sz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 * Only low mem is added, otherwise we have crashes when allocating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 * mem_map[] itself. NO_BOOTMEM allocates mem_map[] at the end of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	 * avail memory, ending in highmem with a > 32-bit address. However
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	 * it then tries to memset it with a truncaed 32-bit handle, causing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 * the crash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	memblock_reserve(CONFIG_LINUX_LINK_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			 __pa(_end) - CONFIG_LINUX_LINK_BASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #ifdef CONFIG_BLK_DEV_INITRD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (phys_initrd_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		memblock_reserve(phys_initrd_start, phys_initrd_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		initrd_start = (unsigned long)__va(phys_initrd_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		initrd_end = initrd_start + phys_initrd_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	early_init_fdt_reserve_self();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	early_init_fdt_scan_reserved_mem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	memblock_dump_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	/*----------------- node/zones setup --------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	max_zone_pfn[ZONE_NORMAL] = max_low_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	 * Populate a new node with highmem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	 * On ARC (w/o PAE) HIGHMEM addresses are actually smaller (0 based)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	 * than addresses in normal ala low memory (0x8000_0000 based).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	 * Even with PAE, the huge peripheral space hole would waste a lot of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	 * mem with single mem_map[]. This warrants a mem_map per region design.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	 * Thus HIGHMEM on ARC is imlemented with DISCONTIGMEM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	 * DISCONTIGMEM in turns requires multiple nodes. node 0 above is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	 * populated with normal memory zone while node 1 only has highmem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	node_set_online(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	min_high_pfn = PFN_DOWN(high_mem_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	max_high_pfn = PFN_DOWN(high_mem_start + high_mem_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	 * max_high_pfn should be ok here for both HIGHMEM and HIGHMEM+PAE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 * For HIGHMEM without PAE max_high_pfn should be less than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	 * min_low_pfn to guarantee that these two regions don't overlap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	 * For PAE case highmem is greater than lowmem, so it is natural
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	 * to use max_high_pfn.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	 * In both cases, holes should be handled by pfn_valid().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	max_zone_pfn[ZONE_HIGHMEM] = max_high_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	high_memory = (void *)(min_high_pfn << PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	kmap_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	free_area_init(max_zone_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static void __init highmem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	unsigned long tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	memblock_free(high_mem_start, high_mem_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	for (tmp = min_high_pfn; tmp < max_high_pfn; tmp++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		free_highmem_page(pfn_to_page(tmp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #endif
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * mem_init - initializes memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * Frees up bootmem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  * Calculates and displays memory available/used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) void __init mem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	memblock_free_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	highmem_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	mem_init_print_info(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }