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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  * ia64 kernel NUMA specific stuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * Copyright (C) 2002 Erich Focht <efocht@ess.nec.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * Copyright (C) 2004 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  *   Jesse Barnes <jbarnes@sgi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/topology.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) u16 cpu_to_node_map[NR_CPUS] __cacheline_aligned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) EXPORT_SYMBOL(cpu_to_node_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) cpumask_t node_to_cpu_mask[MAX_NUMNODES] __cacheline_aligned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) EXPORT_SYMBOL(node_to_cpu_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) void map_cpu_to_node(int cpu, int nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	int oldnid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	if (nid < 0) { /* just initialize by zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 		cpu_to_node_map[cpu] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	/* sanity check first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	oldnid = cpu_to_node_map[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	if (cpumask_test_cpu(cpu, &node_to_cpu_mask[oldnid])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 		return; /* nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	/* we don't have cpu-driven node hot add yet...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	   In usual case, node is created from SRAT at boot time. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	if (!node_online(nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 		nid = first_online_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	cpu_to_node_map[cpu] = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	cpumask_set_cpu(cpu, &node_to_cpu_mask[nid]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) void unmap_cpu_from_node(int cpu, int nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	WARN_ON(!cpumask_test_cpu(cpu, &node_to_cpu_mask[nid]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	WARN_ON(cpu_to_node_map[cpu] != nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	cpu_to_node_map[cpu] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	cpumask_clear_cpu(cpu, &node_to_cpu_mask[nid]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)  * build_cpu_to_node_map - setup cpu to node and node to cpumask arrays
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)  * Build cpu to node mapping and initialize the per node cpu masks using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)  * info from the node_cpuid array handed to us by ACPI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) void __init build_cpu_to_node_map(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	int cpu, i, node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	for(node=0; node < MAX_NUMNODES; node++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 		cpumask_clear(&node_to_cpu_mask[node]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	for_each_possible_early_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 		node = NUMA_NO_NODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 		for (i = 0; i < NR_CPUS; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 			if (cpu_physical_id(cpu) == node_cpuid[i].phys_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 				node = node_cpuid[i].nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 		map_cpu_to_node(cpu, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }