2 * ACPI 5.1 based NUMA setup for ARM64
3 * Lots of code was borrowed from arch/x86/mm/srat.c
5 * Copyright 2004 Andi Kleen, SuSE Labs.
6 * Copyright (C) 2013-2016, Linaro Ltd.
7 * Author: Hanjun Guo <hanjun.guo@linaro.org>
9 * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
11 * Called from acpi_numa_init while reading the SRAT and SLIT tables.
12 * Assumes all memory regions belonging to a single proximity domain
13 * are in one chunk. Holes between them will be included in the node.
16 #define pr_fmt(fmt) "ACPI: NUMA: " fmt
18 #include <linux/acpi.h>
19 #include <linux/bitmap.h>
20 #include <linux/bootmem.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>
28 #include <acpi/processor.h>
31 static int cpus_in_srat;
33 struct __node_cpu_hwid {
34 u32 node_id; /* logical node containing this CPU */
35 u64 cpu_hwid; /* MPIDR for this CPU */
38 static struct __node_cpu_hwid early_node_cpu_hwid[NR_CPUS] = {
39 [0 ... NR_CPUS - 1] = {NUMA_NO_NODE, PHYS_CPUID_INVALID} };
41 int acpi_numa_get_nid(unsigned int cpu, u64 hwid)
45 for (i = 0; i < cpus_in_srat; i++) {
46 if (hwid == early_node_cpu_hwid[i].cpu_hwid)
47 return early_node_cpu_hwid[i].node_id;
53 /* Callback for Proximity Domain -> ACPI processor UID mapping */
54 void __init acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa)
62 if (pa->header.length < sizeof(struct acpi_srat_gicc_affinity)) {
63 pr_err("SRAT: Invalid SRAT header length: %d\n",
69 if (!(pa->flags & ACPI_SRAT_GICC_ENABLED))
72 if (cpus_in_srat >= NR_CPUS) {
73 pr_warn_once("SRAT: cpu_to_node_map[%d] is too small, may not be able to use all cpus\n",
78 pxm = pa->proximity_domain;
79 node = acpi_map_pxm_to_node(pxm);
81 if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) {
82 pr_err("SRAT: Too many proximity domains %d\n", pxm);
87 mpidr = acpi_map_madt_entry(pa->acpi_processor_uid);
88 if (mpidr == PHYS_CPUID_INVALID) {
89 pr_err("SRAT: PXM %d with ACPI ID %d has no valid MPIDR in MADT\n",
90 pxm, pa->acpi_processor_uid);
95 early_node_cpu_hwid[cpus_in_srat].node_id = node;
96 early_node_cpu_hwid[cpus_in_srat].cpu_hwid = mpidr;
97 node_set(node, numa_nodes_parsed);
99 pr_info("SRAT: PXM %d -> MPIDR 0x%Lx -> Node %d\n",
103 int __init arm64_acpi_numa_init(void)
107 ret = acpi_numa_init();
109 pr_info("Failed to initialise from firmware\n");
113 return srat_disabled() ? -EINVAL : 0;