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)  * NUMA support, based on the x86 implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2015 Cavium Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author: Ganapatrao Kulkarni <gkulkarni@cavium.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define pr_fmt(fmt) "NUMA: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/acpi.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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) EXPORT_SYMBOL(node_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) nodemask_t numa_nodes_parsed __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static int cpu_to_node_map[NR_CPUS] = { [0 ... NR_CPUS-1] = NUMA_NO_NODE };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static int numa_distance_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static u8 *numa_distance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) bool numa_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static __init int numa_parse_early_param(char *opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	if (!opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	if (str_has_prefix(opt, "off"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		numa_off = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) early_param("numa", numa_parse_early_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) EXPORT_SYMBOL(node_to_cpumask_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #ifdef CONFIG_DEBUG_PER_CPU_MAPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * Returns a pointer to the bitmask of CPUs on Node 'node'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) const struct cpumask *cpumask_of_node(int node)
^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) 	if (node == NUMA_NO_NODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		return cpu_all_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (WARN_ON(node < 0 || node >= nr_node_ids))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		return cpu_none_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (WARN_ON(node_to_cpumask_map[node] == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		return cpu_online_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	return node_to_cpumask_map[node];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) EXPORT_SYMBOL(cpumask_of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static void numa_update_cpu(unsigned int cpu, bool remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int nid = cpu_to_node(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (nid == NUMA_NO_NODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		cpumask_clear_cpu(cpu, node_to_cpumask_map[nid]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		cpumask_set_cpu(cpu, node_to_cpumask_map[nid]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) void numa_add_cpu(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	numa_update_cpu(cpu, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) void numa_remove_cpu(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	numa_update_cpu(cpu, true);
^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) void numa_clear_node(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	numa_remove_cpu(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	set_cpu_numa_node(cpu, NUMA_NO_NODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * Allocate node_to_cpumask_map based on number of available nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * Requires node_possible_map to be valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * Note: cpumask_of_node() is not valid until after this is done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static void __init setup_node_to_cpumask_map(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	int node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	/* setup nr_node_ids if not done yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (nr_node_ids == MAX_NUMNODES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		setup_nr_node_ids();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	/* allocate and clear the mapping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	for (node = 0; node < nr_node_ids; node++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		cpumask_clear(node_to_cpumask_map[node]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	/* cpumask_of_node() will now work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	pr_debug("Node to cpumask map for %u nodes\n", nr_node_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * Set the cpu to node and mem mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) void numa_store_cpu_info(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	set_cpu_numa_node(cpu, cpu_to_node_map[cpu]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) void __init early_map_cpu_to_node(unsigned int cpu, int nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	/* fallback to node 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (nid < 0 || nid >= MAX_NUMNODES || numa_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		nid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	cpu_to_node_map[cpu] = nid;
^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) 	 * We should set the numa node of cpu0 as soon as possible, because it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 * has already been set up online before. cpu_to_node(0) will soon be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	 * called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (!cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		set_cpu_numa_node(cpu, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) EXPORT_SYMBOL(__per_cpu_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static int __init early_cpu_to_node(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	return cpu_to_node_map[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return node_distance(early_cpu_to_node(from), early_cpu_to_node(to));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 				       size_t align)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	int nid = early_cpu_to_node(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return  memblock_alloc_try_nid(size, align,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			__pa(MAX_DMA_ADDRESS), MEMBLOCK_ALLOC_ACCESSIBLE, nid);
^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) static void __init pcpu_fc_free(void *ptr, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	memblock_free_early(__pa(ptr), size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) void __init setup_per_cpu_areas(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	unsigned long delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	unsigned int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	int rc;
^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) 	 * Always reserve area for module percpu variables.  That's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	 * what the legacy allocator did.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	rc = pcpu_embed_first_chunk(PERCPU_MODULE_RESERVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 				    PERCPU_DYNAMIC_RESERVE, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 				    pcpu_cpu_distance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 				    pcpu_fc_alloc, pcpu_fc_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		panic("Failed to initialize percpu areas.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	for_each_possible_cpu(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		__per_cpu_offset[cpu] = delta + pcpu_unit_offsets[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #endif
^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)  * numa_add_memblk() - Set node id to memblk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * @nid: NUMA node ID of the new memblk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  * @start: Start address of the new memblk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * @end:  End address of the new memblk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  * RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  * 0 on success, -errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) int __init numa_add_memblk(int nid, u64 start, u64 end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	ret = memblock_set_node(start, (end - start), &memblock.memory, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		pr_err("memblock [0x%llx - 0x%llx] failed to add on node %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			start, (end - 1), nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return ret;
^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) 	node_set(nid, numa_nodes_parsed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * Initialize NODE_DATA for a node on the local memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static void __init setup_node_data(int nid, u64 start_pfn, u64 end_pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	const size_t nd_size = roundup(sizeof(pg_data_t), SMP_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	u64 nd_pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	void *nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	int tnid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (start_pfn >= end_pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		pr_info("Initmem setup node %d [<memory-less node>]\n", nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	nd_pa = memblock_phys_alloc_try_nid(nd_size, SMP_CACHE_BYTES, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (!nd_pa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		panic("Cannot allocate %zu bytes for node %d data\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		      nd_size, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	nd = __va(nd_pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	/* report and initialize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	pr_info("NODE_DATA [mem %#010Lx-%#010Lx]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		nd_pa, nd_pa + nd_size - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	tnid = early_pfn_to_nid(nd_pa >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (tnid != nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		pr_info("NODE_DATA(%d) on node %d\n", nid, tnid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	node_data[nid] = nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	memset(NODE_DATA(nid), 0, sizeof(pg_data_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	NODE_DATA(nid)->node_id = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	NODE_DATA(nid)->node_start_pfn = start_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  * numa_free_distance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * The current table is freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) void __init numa_free_distance(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (!numa_distance)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	size = numa_distance_cnt * numa_distance_cnt *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		sizeof(numa_distance[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	memblock_free(__pa(numa_distance), size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	numa_distance_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	numa_distance = NULL;
^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)  * Create a new NUMA distance table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static int __init numa_alloc_distance(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	u64 phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	size = nr_node_ids * nr_node_ids * sizeof(numa_distance[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	phys = memblock_find_in_range(0, PFN_PHYS(max_pfn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 				      size, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (WARN_ON(!phys))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	memblock_reserve(phys, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	numa_distance = __va(phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	numa_distance_cnt = nr_node_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	/* fill with the default distances */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	for (i = 0; i < numa_distance_cnt; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		for (j = 0; j < numa_distance_cnt; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			numa_distance[i * numa_distance_cnt + j] = i == j ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 				LOCAL_DISTANCE : REMOTE_DISTANCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	pr_debug("Initialized distance table, cnt=%d\n", numa_distance_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * numa_set_distance() - Set inter node NUMA distance from node to node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * @from: the 'from' node to set distance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  * @to: the 'to'  node to set distance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  * @distance: NUMA distance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * Set the distance from node @from to @to to @distance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  * If distance table doesn't exist, a warning is printed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  * If @from or @to is higher than the highest known node or lower than zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  * or @distance doesn't make sense, the call is ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) void __init numa_set_distance(int from, int to, int distance)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if (!numa_distance) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		pr_warn_once("Warning: distance table not allocated yet\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		return;
^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) 	if (from >= numa_distance_cnt || to >= numa_distance_cnt ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			from < 0 || to < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		pr_warn_once("Warning: node ids are out of bound, from=%d to=%d distance=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			    from, to, distance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if ((u8)distance != distance ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	    (from == to && distance != LOCAL_DISTANCE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		pr_warn_once("Warning: invalid distance parameter, from=%d to=%d distance=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			     from, to, distance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	numa_distance[from * numa_distance_cnt + to] = distance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)  * Return NUMA distance @from to @to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) int __node_distance(int from, int to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	if (from >= numa_distance_cnt || to >= numa_distance_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		return from == to ? LOCAL_DISTANCE : REMOTE_DISTANCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	return numa_distance[from * numa_distance_cnt + to];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) EXPORT_SYMBOL(__node_distance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static int __init numa_register_nodes(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	int nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	struct memblock_region *mblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	/* Check that valid nid is set to memblks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	for_each_mem_region(mblk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		int mblk_nid = memblock_get_region_node(mblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		if (mblk_nid == NUMA_NO_NODE || mblk_nid >= MAX_NUMNODES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 				mblk_nid, mblk->base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 				mblk->base + mblk->size - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	/* Finally register nodes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	for_each_node_mask(nid, numa_nodes_parsed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		unsigned long start_pfn, end_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		setup_node_data(nid, start_pfn, end_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		node_set_online(nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	/* Setup online nodes to actual nodes*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	node_possible_map = numa_nodes_parsed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static int __init numa_init(int (*init_func)(void))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	nodes_clear(numa_nodes_parsed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	nodes_clear(node_possible_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	nodes_clear(node_online_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	ret = numa_alloc_distance();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	ret = init_func();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		goto out_free_distance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	if (nodes_empty(numa_nodes_parsed)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		pr_info("No NUMA configuration found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		goto out_free_distance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	ret = numa_register_nodes();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		goto out_free_distance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	setup_node_to_cpumask_map();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) out_free_distance:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	numa_free_distance();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  * dummy_numa_init() - Fallback dummy NUMA init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)  * Used if there's no underlying NUMA architecture, NUMA initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)  * fails, or NUMA is disabled on the command line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)  * Must online at least one node (node 0) and add memory blocks that cover all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)  * allowed memory. It is unlikely that this function fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)  * Return: 0 on success, -errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static int __init dummy_numa_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	phys_addr_t start = memblock_start_of_DRAM();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	phys_addr_t end = memblock_end_of_DRAM();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	if (numa_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		pr_info("NUMA disabled\n"); /* Forced off on command line. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start, end - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	ret = numa_add_memblk(0, start, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		pr_err("NUMA init failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	numa_off = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	return 0;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  * arm64_numa_init() - Initialize NUMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)  * Try each configured NUMA initialization method until one succeeds. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)  * last fallback is dummy single node config encompassing whole memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) void __init arm64_numa_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (!numa_off) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		if (!acpi_disabled && !numa_init(arm64_acpi_numa_init))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		if (acpi_disabled && !numa_init(of_numa_init))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	numa_init(dummy_numa_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }