
From: "Andi Kleen" <ak@suse.de>

Add x86_64 support for Jack Steiner's SLIT sysfs patch

Make Jack's code compile on x86-64 and add x86-64 low level support to save
the SLIT pointer and a node_distance() implementation.

Requires the previous SRAT patch. 

Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/arch/x86_64/mm/srat.c         |   29 ++++++++++++++++++++++++++++-
 25-akpm/drivers/base/node.c           |    4 ++--
 25-akpm/include/asm-x86_64/topology.h |    6 ++++++
 3 files changed, 36 insertions(+), 3 deletions(-)

diff -puN arch/x86_64/mm/srat.c~x86_64-add-x86_64-support-for-jack-steiners-slit-sysfs arch/x86_64/mm/srat.c
--- 25/arch/x86_64/mm/srat.c~x86_64-add-x86_64-support-for-jack-steiners-slit-sysfs	2004-11-28 01:54:52.116674168 -0800
+++ 25-akpm/arch/x86_64/mm/srat.c	2004-11-28 01:54:52.123673104 -0800
@@ -13,9 +13,13 @@
 #include <linux/acpi.h>
 #include <linux/mmzone.h>
 #include <linux/bitmap.h>
+#include <linux/module.h>
+#include <linux/topology.h>
 #include <asm/proto.h>
 #include <asm/numa.h>
 
+static struct acpi_table_slit *acpi_slit;
+
 static DECLARE_BITMAP(nodes_parsed, MAX_NUMNODES) __initdata;
 static struct node nodes[MAX_NUMNODES] __initdata;
 static __u8  pxm2node[256] __initdata = { [0 ... 255] = 0xff };
@@ -77,7 +81,7 @@ static __init inline int srat_disabled(v
 /* Callback for SLIT parsing */
 void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
 {
-	/* ignored for now */
+	acpi_slit = slit;
 }
 
 /* Callback for Proximity Domain -> LAPIC mapping */
@@ -180,3 +184,26 @@ int __init acpi_scan_nodes(unsigned long
 	numa_init_array();
 	return 0;
 }
+
+int node_to_pxm(int n)
+{
+       int i;
+       if (pxm2node[n] == n)
+               return n;
+       for (i = 0; i < 256; i++)
+               if (pxm2node[i] == n)
+                       return i;
+       return 0;
+}
+
+int __node_distance(int a, int b)
+{
+	int index;
+
+	if (!acpi_slit)
+		return a == b ? 10 : 20;
+	index = acpi_slit->localities * node_to_pxm(a);
+	return acpi_slit->entry[index + node_to_pxm(b)];
+}
+
+EXPORT_SYMBOL(__node_distance);
diff -puN drivers/base/node.c~x86_64-add-x86_64-support-for-jack-steiners-slit-sysfs drivers/base/node.c
--- 25/drivers/base/node.c~x86_64-add-x86_64-support-for-jack-steiners-slit-sysfs	2004-11-28 01:54:52.117674016 -0800
+++ 25-akpm/drivers/base/node.c	2004-11-28 01:54:52.124672952 -0800
@@ -23,7 +23,7 @@ static ssize_t node_read_cpumap(struct s
 	int len;
 
 	/* 2004/06/03: buf currently PAGE_SIZE, need > 1 char per 4 bits. */
-	BUILD_BUG_ON(NR_CPUS/4 > PAGE_SIZE/2);
+	BUILD_BUG_ON(MAX_NUMNODES/4 > PAGE_SIZE/2);
 
 	len = cpumask_scnprintf(buf, PAGE_SIZE-1, mask);
 	len += sprintf(buf + len, "\n");
@@ -118,7 +118,7 @@ static ssize_t node_read_distance(struct
 	int i;
 
 	/* buf currently PAGE_SIZE, need ~4 chars per node */
-	BUILD_BUG_ON(NR_NODES*4 > PAGE_SIZE/2);
+	BUILD_BUG_ON(MAX_NUMNODES*4 > PAGE_SIZE/2);
 
 	for (i = 0; i < numnodes; i++)
 		len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i));
diff -puN include/asm-x86_64/topology.h~x86_64-add-x86_64-support-for-jack-steiners-slit-sysfs include/asm-x86_64/topology.h
--- 25/include/asm-x86_64/topology.h~x86_64-add-x86_64-support-for-jack-steiners-slit-sysfs	2004-11-28 01:54:52.119673712 -0800
+++ 25-akpm/include/asm-x86_64/topology.h	2004-11-28 01:54:52.123673104 -0800
@@ -16,6 +16,12 @@ extern unsigned char cpu_to_node[];
 extern cpumask_t     node_to_cpumask[];
 extern cpumask_t pci_bus_to_cpumask[];
 
+#ifdef CONFIG_ACPI_NUMA
+extern int __node_distance(int, int);
+#define node_distance(a,b) __node_distance(a,b)
+/* #else fallback version */
+#endif
+
 #define cpu_to_node(cpu)		(cpu_to_node[cpu])
 #define parent_node(node)		(node)
 #define node_to_first_cpu(node) 	(__ffs(node_to_cpumask[node]))
_
