blob: 4f4f1815e0471e0eb2e242b8462a7e4eb8e8b137 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Hanjun Guod8b47fc2016-05-24 15:35:44 -07002/*
3 * ACPI 5.1 based NUMA setup for ARM64
4 * Lots of code was borrowed from arch/x86/mm/srat.c
5 *
6 * Copyright 2004 Andi Kleen, SuSE Labs.
7 * Copyright (C) 2013-2016, Linaro Ltd.
8 * Author: Hanjun Guo <hanjun.guo@linaro.org>
9 *
10 * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
11 *
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.
15 */
16
17#define pr_fmt(fmt) "ACPI: NUMA: " fmt
18
19#include <linux/acpi.h>
20#include <linux/bitmap.h>
21#include <linux/bootmem.h>
22#include <linux/kernel.h>
23#include <linux/mm.h>
24#include <linux/memblock.h>
25#include <linux/mmzone.h>
26#include <linux/module.h>
27#include <linux/topology.h>
28
Hanjun Guod8b47fc2016-05-24 15:35:44 -070029#include <asm/numa.h>
30
Lorenzo Pieralisie1896242018-06-25 14:05:52 +010031static int acpi_early_node_map[NR_CPUS] __initdata = { NUMA_NO_NODE };
Hanjun Guod8b47fc2016-05-24 15:35:44 -070032
Lorenzo Pieralisie1896242018-06-25 14:05:52 +010033int __init acpi_numa_get_nid(unsigned int cpu)
Hanjun Guod8b47fc2016-05-24 15:35:44 -070034{
Lorenzo Pieralisie1896242018-06-25 14:05:52 +010035 return acpi_early_node_map[cpu];
36}
Hanjun Guod8b47fc2016-05-24 15:35:44 -070037
Lorenzo Pieralisie1896242018-06-25 14:05:52 +010038static inline int get_cpu_for_acpi_id(u32 uid)
39{
40 int cpu;
Hanjun Guod8b47fc2016-05-24 15:35:44 -070041
Lorenzo Pieralisie1896242018-06-25 14:05:52 +010042 for (cpu = 0; cpu < nr_cpu_ids; cpu++)
43 if (uid == get_acpi_id_for_cpu(cpu))
44 return cpu;
45
46 return -EINVAL;
47}
48
49static int __init acpi_parse_gicc_pxm(struct acpi_subtable_header *header,
50 const unsigned long end)
51{
52 struct acpi_srat_gicc_affinity *pa;
53 int cpu, pxm, node;
54
55 if (srat_disabled())
56 return -EINVAL;
57
58 pa = (struct acpi_srat_gicc_affinity *)header;
59 if (!pa)
60 return -EINVAL;
61
62 if (!(pa->flags & ACPI_SRAT_GICC_ENABLED))
63 return 0;
64
65 pxm = pa->proximity_domain;
66 node = pxm_to_node(pxm);
67
68 /*
69 * If we can't map the UID to a logical cpu this
70 * means that the UID is not part of possible cpus
71 * so we do not need a NUMA mapping for it, skip
72 * the SRAT entry and keep parsing.
73 */
74 cpu = get_cpu_for_acpi_id(pa->acpi_processor_uid);
75 if (cpu < 0)
76 return 0;
77
78 acpi_early_node_map[cpu] = node;
79 pr_info("SRAT: PXM %d -> MPIDR 0x%llx -> Node %d\n", pxm,
80 cpu_logical_map(cpu), node);
81
82 return 0;
83}
84
85void __init acpi_map_cpus_to_nodes(void)
86{
87 acpi_table_parse_entries(ACPI_SIG_SRAT, sizeof(struct acpi_table_srat),
88 ACPI_SRAT_TYPE_GICC_AFFINITY,
89 acpi_parse_gicc_pxm, 0);
Hanjun Guod8b47fc2016-05-24 15:35:44 -070090}
91
92/* Callback for Proximity Domain -> ACPI processor UID mapping */
93void __init acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa)
94{
95 int pxm, node;
Hanjun Guod8b47fc2016-05-24 15:35:44 -070096
97 if (srat_disabled())
98 return;
99
100 if (pa->header.length < sizeof(struct acpi_srat_gicc_affinity)) {
101 pr_err("SRAT: Invalid SRAT header length: %d\n",
102 pa->header.length);
103 bad_srat();
104 return;
105 }
106
107 if (!(pa->flags & ACPI_SRAT_GICC_ENABLED))
108 return;
109
Hanjun Guod8b47fc2016-05-24 15:35:44 -0700110 pxm = pa->proximity_domain;
111 node = acpi_map_pxm_to_node(pxm);
112
113 if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) {
114 pr_err("SRAT: Too many proximity domains %d\n", pxm);
115 bad_srat();
116 return;
117 }
118
Hanjun Guod8b47fc2016-05-24 15:35:44 -0700119 node_set(node, numa_nodes_parsed);
Hanjun Guod8b47fc2016-05-24 15:35:44 -0700120}
121
122int __init arm64_acpi_numa_init(void)
123{
124 int ret;
125
126 ret = acpi_numa_init();
Zhen Lei794224ea2016-09-01 14:54:56 +0800127 if (ret) {
128 pr_info("Failed to initialise from firmware\n");
Hanjun Guod8b47fc2016-05-24 15:35:44 -0700129 return ret;
Zhen Lei794224ea2016-09-01 14:54:56 +0800130 }
Hanjun Guod8b47fc2016-05-24 15:35:44 -0700131
132 return srat_disabled() ? -EINVAL : 0;
133}