1 // SPDX-License-Identifier: GPL-2.0
3 * ACPI 5.1 based NUMA setup for ARM64
4 * Lots of code was borrowed from arch/x86/mm/srat.c
6 * Copyright 2004 Andi Kleen, SuSE Labs.
7 * Copyright (C) 2013-2016, Linaro Ltd.
8 * Author: Hanjun Guo <hanjun.guo@linaro.org>
10 * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
12 * Called from acpi_numa_init while reading the SRAT and SLIT tables.
13 * Assumes all memory regions belonging to a single proximity domain
14 * are in one chunk. Holes between them will be included in the node.
17 #define pr_fmt(fmt) "ACPI: NUMA: " fmt
19 #include <linux/acpi.h>
20 #include <linux/bitmap.h>
21 #include <linux/kernel.h>
23 #include <linux/memblock.h>
24 #include <linux/mmzone.h>
25 #include <linux/module.h>
26 #include <linux/topology.h>
30 static int acpi_early_node_map
[NR_CPUS
] __initdata
= { NUMA_NO_NODE
};
32 int __init
acpi_numa_get_nid(unsigned int cpu
)
34 return acpi_early_node_map
[cpu
];
37 static inline int get_cpu_for_acpi_id(u32 uid
)
41 for (cpu
= 0; cpu
< nr_cpu_ids
; cpu
++)
42 if (uid
== get_acpi_id_for_cpu(cpu
))
48 static int __init
acpi_parse_gicc_pxm(union acpi_subtable_headers
*header
,
49 const unsigned long end
)
51 struct acpi_srat_gicc_affinity
*pa
;
57 pa
= (struct acpi_srat_gicc_affinity
*)header
;
61 if (!(pa
->flags
& ACPI_SRAT_GICC_ENABLED
))
64 pxm
= pa
->proximity_domain
;
65 node
= pxm_to_node(pxm
);
68 * If we can't map the UID to a logical cpu this
69 * means that the UID is not part of possible cpus
70 * so we do not need a NUMA mapping for it, skip
71 * the SRAT entry and keep parsing.
73 cpu
= get_cpu_for_acpi_id(pa
->acpi_processor_uid
);
77 acpi_early_node_map
[cpu
] = node
;
78 pr_info("SRAT: PXM %d -> MPIDR 0x%llx -> Node %d\n", pxm
,
79 cpu_logical_map(cpu
), node
);
84 void __init
acpi_map_cpus_to_nodes(void)
86 acpi_table_parse_entries(ACPI_SIG_SRAT
, sizeof(struct acpi_table_srat
),
87 ACPI_SRAT_TYPE_GICC_AFFINITY
,
88 acpi_parse_gicc_pxm
, 0);
91 /* Callback for Proximity Domain -> ACPI processor UID mapping */
92 void __init
acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity
*pa
)
99 if (pa
->header
.length
< sizeof(struct acpi_srat_gicc_affinity
)) {
100 pr_err("SRAT: Invalid SRAT header length: %d\n",
106 if (!(pa
->flags
& ACPI_SRAT_GICC_ENABLED
))
109 pxm
= pa
->proximity_domain
;
110 node
= acpi_map_pxm_to_node(pxm
);
112 if (node
== NUMA_NO_NODE
|| node
>= MAX_NUMNODES
) {
113 pr_err("SRAT: Too many proximity domains %d\n", pxm
);
118 node_set(node
, numa_nodes_parsed
);
121 int __init
arm64_acpi_numa_init(void)
125 ret
= acpi_numa_init();
127 pr_info("Failed to initialise from firmware\n");
131 return srat_disabled() ? -EINVAL
: 0;