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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * ACPI 5.1 based NUMA setup for ARM64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Lots of code was borrowed from arch/x86/mm/srat.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright 2004 Andi Kleen, SuSE Labs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2013-2016, Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *		Author: Hanjun Guo <hanjun.guo@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Called from acpi_numa_init while reading the SRAT and SLIT tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * Assumes all memory regions belonging to a single proximity domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * are in one chunk. Holes between them will be included in the node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define pr_fmt(fmt) "ACPI: NUMA: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/bitmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/mmzone.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/topology.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <asm/numa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static int acpi_early_node_map[NR_CPUS] __initdata = { NUMA_NO_NODE };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) int __init acpi_numa_get_nid(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	return acpi_early_node_map[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static inline int get_cpu_for_acpi_id(u32 uid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	for (cpu = 0; cpu < nr_cpu_ids; cpu++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		if (uid == get_acpi_id_for_cpu(cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			return cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static int __init acpi_parse_gicc_pxm(union acpi_subtable_headers *header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 				      const unsigned long end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct acpi_srat_gicc_affinity *pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	int cpu, pxm, node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (srat_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	pa = (struct acpi_srat_gicc_affinity *)header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (!pa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	if (!(pa->flags & ACPI_SRAT_GICC_ENABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	pxm = pa->proximity_domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	node = pxm_to_node(pxm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	 * If we can't map the UID to a logical cpu this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	 * means that the UID is not part of possible cpus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	 * so we do not need a NUMA mapping for it, skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	 * the SRAT entry and keep parsing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	cpu = get_cpu_for_acpi_id(pa->acpi_processor_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (cpu < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	acpi_early_node_map[cpu] = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	pr_info("SRAT: PXM %d -> MPIDR 0x%llx -> Node %d\n", pxm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		cpu_logical_map(cpu), node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) void __init acpi_map_cpus_to_nodes(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	acpi_table_parse_entries(ACPI_SIG_SRAT, sizeof(struct acpi_table_srat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 					    ACPI_SRAT_TYPE_GICC_AFFINITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 					    acpi_parse_gicc_pxm, 0);
^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) /* Callback for Proximity Domain -> ACPI processor UID mapping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) void __init acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	int pxm, node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (srat_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (pa->header.length < sizeof(struct acpi_srat_gicc_affinity)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		pr_err("SRAT: Invalid SRAT header length: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			pa->header.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		bad_srat();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (!(pa->flags & ACPI_SRAT_GICC_ENABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	pxm = pa->proximity_domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	node = acpi_map_pxm_to_node(pxm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		pr_err("SRAT: Too many proximity domains %d\n", pxm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		bad_srat();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	node_set(node, numa_nodes_parsed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int __init arm64_acpi_numa_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	ret = acpi_numa_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		pr_info("Failed to initialise from firmware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		return ret;
^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) 	return srat_disabled() ? -EINVAL : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }