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)  *  acpi_numa.c - ACPI NUMA support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2002 Takayoshi Kochi <t-kochi@bq.jp.nec.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #define pr_fmt(fmt) "ACPI: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/numa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/nodemask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/topology.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static nodemask_t nodes_found_map = NODE_MASK_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /* maps to convert between proximity domain and logical node ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static int pxm_to_node_map[MAX_PXM_DOMAINS]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 			= { [0 ... MAX_PXM_DOMAINS - 1] = NUMA_NO_NODE };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static int node_to_pxm_map[MAX_NUMNODES]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 			= { [0 ... MAX_NUMNODES - 1] = PXM_INVAL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) unsigned char acpi_srat_revision __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static int acpi_numa __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) void __init disable_srat(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	acpi_numa = -1;
^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) int pxm_to_node(int pxm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (pxm < 0 || pxm >= MAX_PXM_DOMAINS || numa_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		return NUMA_NO_NODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return pxm_to_node_map[pxm];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) EXPORT_SYMBOL(pxm_to_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) int node_to_pxm(int node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (node < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		return PXM_INVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	return node_to_pxm_map[node];
^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) static void __acpi_map_pxm_to_node(int pxm, int node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (pxm_to_node_map[pxm] == NUMA_NO_NODE || node < pxm_to_node_map[pxm])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		pxm_to_node_map[pxm] = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (node_to_pxm_map[node] == PXM_INVAL || pxm < node_to_pxm_map[node])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		node_to_pxm_map[node] = pxm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) int acpi_map_pxm_to_node(int pxm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	int node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (pxm < 0 || pxm >= MAX_PXM_DOMAINS || numa_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return NUMA_NO_NODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	node = pxm_to_node_map[pxm];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (node == NUMA_NO_NODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		if (nodes_weight(nodes_found_map) >= MAX_NUMNODES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			return NUMA_NO_NODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		node = first_unset_node(nodes_found_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		__acpi_map_pxm_to_node(pxm, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		node_set(node, nodes_found_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) EXPORT_SYMBOL(acpi_map_pxm_to_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) acpi_table_print_srat_entry(struct acpi_subtable_header *header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	switch (header->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	case ACPI_SRAT_TYPE_CPU_AFFINITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			struct acpi_srat_cpu_affinity *p =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			    (struct acpi_srat_cpu_affinity *)header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			pr_debug("SRAT Processor (id[0x%02x] eid[0x%02x]) in proximity domain %d %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 				 p->apic_id, p->local_sapic_eid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 				 p->proximity_domain_lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 				 (p->flags & ACPI_SRAT_CPU_ENABLED) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 				 "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	case ACPI_SRAT_TYPE_MEMORY_AFFINITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			struct acpi_srat_mem_affinity *p =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			    (struct acpi_srat_mem_affinity *)header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			pr_debug("SRAT Memory (0x%llx length 0x%llx) in proximity domain %d %s%s%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 				 (unsigned long long)p->base_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 				 (unsigned long long)p->length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				 p->proximity_domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 				 (p->flags & ACPI_SRAT_MEM_ENABLED) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				 "enabled" : "disabled",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 				 (p->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 				 " hot-pluggable" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 				 (p->flags & ACPI_SRAT_MEM_NON_VOLATILE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 				 " non-volatile" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			struct acpi_srat_x2apic_cpu_affinity *p =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			    (struct acpi_srat_x2apic_cpu_affinity *)header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			pr_debug("SRAT Processor (x2apicid[0x%08x]) in proximity domain %d %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 				 p->apic_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 				 p->proximity_domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 				 (p->flags & ACPI_SRAT_CPU_ENABLED) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				 "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	case ACPI_SRAT_TYPE_GICC_AFFINITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			struct acpi_srat_gicc_affinity *p =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			    (struct acpi_srat_gicc_affinity *)header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			pr_debug("SRAT Processor (acpi id[0x%04x]) in proximity domain %d %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				 p->acpi_processor_uid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 				 p->proximity_domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 				 (p->flags & ACPI_SRAT_GICC_ENABLED) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 				 "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	case ACPI_SRAT_TYPE_GENERIC_AFFINITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		struct acpi_srat_generic_affinity *p =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			(struct acpi_srat_generic_affinity *)header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		if (p->device_handle_type == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			 * For pci devices this may be the only place they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			 * are assigned a proximity domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			pr_debug("SRAT Generic Initiator(Seg:%u BDF:%u) in proximity domain %d %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 				 *(u16 *)(&p->device_handle[0]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				 *(u16 *)(&p->device_handle[2]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				 p->proximity_domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				 (p->flags & ACPI_SRAT_GENERIC_AFFINITY_ENABLED) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				"enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			 * In this case we can rely on the device having a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			 * proximity domain reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			pr_debug("SRAT Generic Initiator(HID=%.8s UID=%.4s) in proximity domain %d %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				(char *)(&p->device_handle[0]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				(char *)(&p->device_handle[8]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 				p->proximity_domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 				(p->flags & ACPI_SRAT_GENERIC_AFFINITY_ENABLED) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 				"enabled" : "disabled");
^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) 	break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		pr_warn("Found unsupported SRAT entry (type = 0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			header->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  * A lot of BIOS fill in 10 (= no distance) everywhere. This messes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * up the NUMA heuristics which wants the local node to have a smaller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  * distance than the others.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * Do some quick checks here and only use the SLIT if it passes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int __init slit_valid(struct acpi_table_slit *slit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	int d = slit->locality_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	for (i = 0; i < d; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		for (j = 0; j < d; j++)  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			u8 val = slit->entry[d*i + j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			if (i == j) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 				if (val != LOCAL_DISTANCE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 					return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			} else if (val <= LOCAL_DISTANCE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) void __init bad_srat(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	pr_err("SRAT: SRAT not used.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	disable_srat();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) int __init srat_disabled(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return acpi_numa < 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) #if defined(CONFIG_X86) || defined(CONFIG_ARM64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * Callback for SLIT parsing.  pxm_to_node() returns NUMA_NO_NODE for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * I/O localities since SRAT does not list them.  I/O localities are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * not supported at this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	for (i = 0; i < slit->locality_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		const int from_node = pxm_to_node(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		if (from_node == NUMA_NO_NODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		for (j = 0; j < slit->locality_count; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			const int to_node = pxm_to_node(j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			if (to_node == NUMA_NO_NODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			numa_set_distance(from_node, to_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 				slit->entry[slit->locality_count * i + j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * Default callback for parsing of the Proximity Domain <-> Memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  * Area mappings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	u64 start, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	u32 hotpluggable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	int node, pxm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (srat_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (ma->header.length < sizeof(struct acpi_srat_mem_affinity)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		pr_err("SRAT: Unexpected header length: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		       ma->header.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		goto out_err_bad_srat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if ((ma->flags & ACPI_SRAT_MEM_ENABLED) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	hotpluggable = ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (hotpluggable && !IS_ENABLED(CONFIG_MEMORY_HOTPLUG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	start = ma->base_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	end = start + ma->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	pxm = ma->proximity_domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (acpi_srat_revision <= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		pxm &= 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	node = acpi_map_pxm_to_node(pxm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (node == NUMA_NO_NODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		pr_err("SRAT: Too many proximity domains.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		goto out_err_bad_srat;
^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) 	if (numa_add_memblk(node, start, end) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		pr_err("SRAT: Failed to add memblk to node %u [mem %#010Lx-%#010Lx]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		       node, (unsigned long long) start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		       (unsigned long long) end - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		goto out_err_bad_srat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	node_set(node, numa_nodes_parsed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	pr_info("SRAT: Node %u PXM %u [mem %#010Lx-%#010Lx]%s%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		node, pxm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		(unsigned long long) start, (unsigned long long) end - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		hotpluggable ? " hotplug" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		ma->flags & ACPI_SRAT_MEM_NON_VOLATILE ? " non-volatile" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	/* Mark hotplug range in memblock. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (hotpluggable && memblock_mark_hotplug(start, ma->length))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		pr_warn("SRAT: Failed to mark hotplug range [mem %#010Lx-%#010Lx] in memblock\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			(unsigned long long)start, (unsigned long long)end - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	max_possible_pfn = max(max_possible_pfn, PFN_UP(end - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) out_err_bad_srat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	bad_srat();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) #endif /* defined(CONFIG_X86) || defined (CONFIG_ARM64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static int __init acpi_parse_slit(struct acpi_table_header *table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	struct acpi_table_slit *slit = (struct acpi_table_slit *)table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	if (!slit_valid(slit)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		pr_info("SLIT table looks invalid. Not used.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	acpi_numa_slit_init(slit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) void __init __weak
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	pr_warn("Found unsupported x2apic [0x%08x] SRAT entry\n", pa->apic_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) acpi_parse_x2apic_affinity(union acpi_subtable_headers *header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			   const unsigned long end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	struct acpi_srat_x2apic_cpu_affinity *processor_affinity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	processor_affinity = (struct acpi_srat_x2apic_cpu_affinity *)header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	acpi_table_print_srat_entry(&header->common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	/* let architecture-dependent part to do it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	acpi_numa_x2apic_affinity_init(processor_affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) acpi_parse_processor_affinity(union acpi_subtable_headers *header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			      const unsigned long end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	struct acpi_srat_cpu_affinity *processor_affinity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	processor_affinity = (struct acpi_srat_cpu_affinity *)header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	acpi_table_print_srat_entry(&header->common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	/* let architecture-dependent part to do it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	acpi_numa_processor_affinity_init(processor_affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) acpi_parse_gicc_affinity(union acpi_subtable_headers *header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			 const unsigned long end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	struct acpi_srat_gicc_affinity *processor_affinity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	processor_affinity = (struct acpi_srat_gicc_affinity *)header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	acpi_table_print_srat_entry(&header->common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	/* let architecture-dependent part to do it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	acpi_numa_gicc_affinity_init(processor_affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) #if defined(CONFIG_X86) || defined(CONFIG_ARM64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) acpi_parse_gi_affinity(union acpi_subtable_headers *header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		       const unsigned long end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	struct acpi_srat_generic_affinity *gi_affinity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	int node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	gi_affinity = (struct acpi_srat_generic_affinity *)header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	if (!gi_affinity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	acpi_table_print_srat_entry(&header->common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	if (!(gi_affinity->flags & ACPI_SRAT_GENERIC_AFFINITY_ENABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	node = acpi_map_pxm_to_node(gi_affinity->proximity_domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		pr_err("SRAT: Too many proximity domains.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	node_set(node, numa_nodes_parsed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	node_set_state(node, N_GENERIC_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) acpi_parse_gi_affinity(union acpi_subtable_headers *header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		       const unsigned long end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) #endif /* defined(CONFIG_X86) || defined (CONFIG_ARM64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static int __initdata parsed_numa_memblks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) acpi_parse_memory_affinity(union acpi_subtable_headers * header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 			   const unsigned long end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	struct acpi_srat_mem_affinity *memory_affinity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	memory_affinity = (struct acpi_srat_mem_affinity *)header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	acpi_table_print_srat_entry(&header->common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	/* let architecture-dependent part to do it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	if (!acpi_numa_memory_affinity_init(memory_affinity))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		parsed_numa_memblks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) static int __init acpi_parse_srat(struct acpi_table_header *table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	struct acpi_table_srat *srat = (struct acpi_table_srat *)table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	acpi_srat_revision = srat->header.revision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	/* Real work done in acpi_table_parse_srat below. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) acpi_table_parse_srat(enum acpi_srat_type id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		      acpi_tbl_entry_handler handler, unsigned int max_entries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	return acpi_table_parse_entries(ACPI_SIG_SRAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 					    sizeof(struct acpi_table_srat), id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 					    handler, max_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) int __init acpi_numa_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	int cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	if (acpi_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	 * Should not limit number with cpu num that is from NR_CPUS or nr_cpus=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	 * SRAT cpu entries could have different order with that in MADT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	 * So go over all cpu entries in SRAT to get apicid to node mapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	/* SRAT: System Resource Affinity Table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		struct acpi_subtable_proc srat_proc[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		memset(srat_proc, 0, sizeof(srat_proc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		srat_proc[0].id = ACPI_SRAT_TYPE_CPU_AFFINITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		srat_proc[0].handler = acpi_parse_processor_affinity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		srat_proc[1].id = ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		srat_proc[1].handler = acpi_parse_x2apic_affinity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		srat_proc[2].id = ACPI_SRAT_TYPE_GICC_AFFINITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		srat_proc[2].handler = acpi_parse_gicc_affinity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		srat_proc[3].id = ACPI_SRAT_TYPE_GENERIC_AFFINITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		srat_proc[3].handler = acpi_parse_gi_affinity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		acpi_table_parse_entries_array(ACPI_SIG_SRAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 					sizeof(struct acpi_table_srat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 					srat_proc, ARRAY_SIZE(srat_proc), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		cnt = acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 					    acpi_parse_memory_affinity, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	/* SLIT: System Locality Information Table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	acpi_table_parse(ACPI_SIG_SLIT, acpi_parse_slit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	if (cnt < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		return cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	else if (!parsed_numa_memblks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static int acpi_get_pxm(acpi_handle h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	unsigned long long pxm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	acpi_handle handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	acpi_handle phandle = h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		handle = phandle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		status = acpi_evaluate_integer(handle, "_PXM", NULL, &pxm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			return pxm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		status = acpi_get_parent(handle, &phandle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	} while (ACPI_SUCCESS(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) int acpi_get_node(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	int pxm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	pxm = acpi_get_pxm(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	return pxm_to_node(pxm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) EXPORT_SYMBOL(acpi_get_node);