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)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * License.  See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * This file contains NUMA specific variables and functions which can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * be split away from DISCONTIGMEM and are used on NUMA machines with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * contiguous memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *                         2002/08/07 Erich Focht <efocht@ess.nec.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) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/node.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/mmzone.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/numa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * The following structures are usually initialized by ACPI or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * similar mechanisms and describe the NUMA characteristics of the machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) int num_node_memblks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) struct node_memblk_s node_memblk[NR_NODE_MEMBLKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) struct node_cpuid_s node_cpuid[NR_CPUS] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	{ [0 ... NR_CPUS-1] = { .phys_id = 0, .nid = NUMA_NO_NODE } };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * This is a matrix with "distances" between nodes, they should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * proportional to the memory access latency ratios.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) u8 numa_slit[MAX_NUMNODES * MAX_NUMNODES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) int __node_distance(int from, int to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return slit_distance(from, to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) EXPORT_SYMBOL(__node_distance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /* Identify which cnode a physical address resides on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) paddr_to_nid(unsigned long paddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	int	i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	for (i = 0; i < num_node_memblks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		if (paddr >= node_memblk[i].start_paddr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		    paddr < node_memblk[i].start_paddr + node_memblk[i].size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return (i < num_node_memblks) ? node_memblk[i].nid : (num_node_memblks ? -1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) EXPORT_SYMBOL(paddr_to_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #if defined(CONFIG_SPARSEMEM) && defined(CONFIG_NUMA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * Because of holes evaluate on section limits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * If the section of memory exists, then return the node where the section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * resides.  Otherwise return node 0 as the default.  This is used by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * SPARSEMEM to allocate the SPARSEMEM sectionmap on the NUMA node where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * the section resides.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) int __meminit __early_pfn_to_nid(unsigned long pfn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 					struct mminit_pfnnid_cache *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	int i, section = pfn >> PFN_SECTION_SHIFT, ssec, esec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (section >= state->last_start && section < state->last_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		return state->last_nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	for (i = 0; i < num_node_memblks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		ssec = node_memblk[i].start_paddr >> PA_SECTION_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		esec = (node_memblk[i].start_paddr + node_memblk[i].size +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			((1L << PA_SECTION_SHIFT) - 1)) >> PA_SECTION_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		if (section >= ssec && section < esec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			state->last_start = ssec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			state->last_end = esec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			state->last_nid = node_memblk[i].nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			return node_memblk[i].nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) void numa_clear_node(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	unmap_cpu_from_node(cpu, NUMA_NO_NODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #ifdef CONFIG_MEMORY_HOTPLUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  *  SRAT information is stored in node_memblk[], then we can use SRAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  *  information at memory-hot-add if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) int memory_add_physaddr_to_nid(u64 addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	int nid = paddr_to_nid(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (nid < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	return nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #endif