@@ -39,6 +39,7 @@ obj-y += mem_access.o
obj-y += mm.o
obj-y += monitor.o
obj-$(CONFIG_NUMA) += numa.o
+obj-$(CONFIG_DEVICE_TREE_NUMA) += numa_device_tree.o
obj-y += p2m.o
obj-y += percpu.o
obj-y += platform.o
@@ -28,6 +28,8 @@ enum dt_numa_status {
DT_NUMA_OFF,
};
+extern enum dt_numa_status device_tree_numa;
+
/*
* In ACPI spec, 0-9 are the reserved values for node distance,
* 10 indicates local node distance, 20 indicates remote node
@@ -20,7 +20,7 @@
#include <xen/init.h>
#include <xen/numa.h>
-static enum dt_numa_status __read_mostly device_tree_numa;
+enum dt_numa_status __read_mostly device_tree_numa;
static unsigned char __read_mostly
node_distance_map[MAX_NUMNODES][MAX_NUMNODES] = {
new file mode 100644
@@ -0,0 +1,64 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Arm Architecture support layer for device tree NUMA.
+ *
+ * Copyright (C) 2022 Arm Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#include <xen/init.h>
+#include <xen/nodemask.h>
+#include <xen/numa.h>
+#include <xen/libfdt/libfdt.h>
+#include <xen/device_tree.h>
+
+/* Callback for device tree processor affinity */
+static int __init fdt_numa_processor_affinity_init(nodeid_t node)
+{
+ numa_set_processor_nodes_parsed(node);
+ device_tree_numa = DT_NUMA_ON;
+
+ printk(KERN_INFO "DT: NUMA node %"PRIu8" processor parsed\n", node);
+
+ return 0;
+}
+
+/* Parse CPU NUMA node info */
+static int __init fdt_parse_numa_cpu_node(const void *fdt, int node)
+{
+ unsigned int nid;
+
+ if ( numa_disabled() )
+ return -EINVAL;
+
+ /*
+ * device_tree_get_u32 will return NUMA_NO_NODE when this CPU
+ * DT node doesn't have numa-node-id. This can help us to
+ * distinguish a bad DTB and a normal DTB without NUMA info.
+ */
+ nid = device_tree_get_u32(fdt, node, "numa-node-id", NUMA_NO_NODE);
+ if ( nid == NUMA_NO_NODE )
+ {
+ numa_fw_bad();
+ return -ENODATA;
+ }
+ else if ( nid >= MAX_NUMNODES )
+ {
+ printk(XENLOG_ERR "DT: CPU numa node id %u is invalid\n", nid);
+ numa_fw_bad();
+ return -EINVAL;
+ }
+
+ return fdt_numa_processor_affinity_init(nid);
+}
Processor NUMA ID information is stored in device tree's processor node as "numa-node-id". We need a new helper to parse this ID from processor node. If we get this ID from processor node, this ID's validity still need to be checked. Once we got a invalid NUMA ID from any processor node, the device tree will be marked as NUMA information invalid. Signed-off-by: Wei Chen <wei.chen@arm.com> --- v1 -> v2: 1. Move numa_disabled from fdt_numa_processor_affinity_init to fdt_parse_numa_cpu_node. 2. Move invalid NUMA id check to fdt_parse_numa_cpu_node. 3. Return ENODATA for normal dtb without NUMA info. 4. Use NUMA status helpers instead of SRAT functions. --- xen/arch/arm/Makefile | 1 + xen/arch/arm/include/asm/numa.h | 2 ++ xen/arch/arm/numa.c | 2 +- xen/arch/arm/numa_device_tree.c | 64 +++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/numa_device_tree.c