@@ -46,6 +46,7 @@ extern void numa_set_distance(nodeid_t from, nodeid_t to,
unsigned int distance);
extern void numa_detect_cpu_node(unsigned int cpu);
extern int numa_device_tree_init(const void *fdt);
+extern void numa_init(void);
#else
@@ -91,6 +92,10 @@ static inline void numa_detect_cpu_node(unsigned int cpu)
{
}
+static inline void numa_init(void)
+{
+}
+
#endif
#define arch_want_default_dmazone() (false)
@@ -18,7 +18,11 @@
*
*/
#include <xen/init.h>
+#include <xen/device_tree.h>
+#include <xen/nodemask.h>
#include <xen/numa.h>
+#include <xen/pfn.h>
+#include <xen/acpi.h>
enum dt_numa_status __ro_after_init device_tree_numa = DT_NUMA_DEFAULT;
@@ -105,6 +109,59 @@ unsigned char __node_distance(nodeid_t from, nodeid_t to)
EXPORT_SYMBOL(__node_distance);
+void __init numa_init(void)
+{
+ unsigned int idx;
+ paddr_t ram_start = INVALID_PADDR;
+ paddr_t ram_size = 0;
+ paddr_t ram_end = 0;
+
+ /* NUMA has been turned off through Xen parameters */
+ if ( numa_off )
+ goto mem_init;
+
+ /* Initialize NUMA from device tree when system is not ACPI booted */
+ if ( acpi_disabled )
+ {
+ int ret = numa_device_tree_init(device_tree_flattened);
+ if ( ret )
+ {
+ numa_off = true;
+ if ( ret == -EINVAL )
+ printk(XENLOG_WARNING
+ "Init NUMA from device tree failed, ret=%d\n", ret);
+ }
+ }
+ else
+ {
+ /* We don't support NUMA for ACPI boot currently */
+ printk(XENLOG_WARNING
+ "ACPI NUMA has not been supported yet, NUMA off!\n");
+ numa_off = true;
+ }
+
+mem_init:
+ /*
+ * Find the minimal and maximum address of RAM, NUMA will
+ * build a memory to node mapping table for the whole range.
+ */
+ ram_start = bootinfo.mem.bank[0].start;
+ ram_size = bootinfo.mem.bank[0].size;
+ ram_end = ram_start + ram_size;
+ for ( idx = 1 ; idx < bootinfo.mem.nr_banks; idx++ )
+ {
+ paddr_t bank_start = bootinfo.mem.bank[idx].start;
+ paddr_t bank_size = bootinfo.mem.bank[idx].size;
+ paddr_t bank_end = bank_start + bank_size;
+
+ ram_size = ram_size + bank_size;
+ ram_start = min(ram_start, bank_start);
+ ram_end = max(ram_end, bank_end);
+ }
+
+ numa_initmem_init(PFN_UP(ram_start), PFN_DOWN(ram_end));
+}
+
int __init arch_get_ram_range(unsigned int idx, paddr_t *start, paddr_t *end)
{
if ( idx >= bootinfo.mem.nr_banks )
@@ -1121,6 +1121,13 @@ void __init start_xen(unsigned long boot_phys_offset,
/* Parse the ACPI tables for possible boot-time configuration */
acpi_boot_table_init();
+ /*
+ * Try to initialize NUMA system, if failed, the system will
+ * fallback to uniform system which means system has only 1
+ * NUMA node.
+ */
+ numa_init();
+
end_boot_allocator();
/*