3 * Discover the memory map and associated nodes.
5 * Doesn't use the ACPI SRAT table because it has a questionable license.
6 * Instead the northbridge registers are read directly.
7 * XXX in 2.5 we could use the generic SRAT code
9 * Copyright 2002,2003 Andi Kleen, SuSE Labs.
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/string.h>
14 #include <linux/module.h>
15 #include <linux/nodemask.h>
17 #include <linux/pci_ids.h>
18 #include <asm/types.h>
19 #include <asm/mmzone.h>
20 #include <asm/proto.h>
22 #include <asm/pci-direct.h>
25 static __init int find_northbridge(void)
29 for (num = 0; num < 32; num++) {
32 header = read_pci_config(0, num, 0, 0x00);
33 if (header != (PCI_VENDOR_ID_AMD | (0x1100<<16)))
36 header = read_pci_config(0, num, 1, 0x00);
37 if (header != (PCI_VENDOR_ID_AMD | (0x1101<<16)))
45 int __init k8_scan_nodes(unsigned long start, unsigned long end)
47 unsigned long prevbase;
48 struct node nodes[MAXNODE];
53 nb = find_northbridge();
57 printk(KERN_INFO "Scanning NUMA topology in Northbridge %d\n", nb);
59 reg = read_pci_config(0, nb, 0, 0x60);
60 numnodes = ((reg >> 4) & 7) + 1;
62 printk(KERN_INFO "Number of nodes %d (%x)\n", numnodes, reg);
64 memset(&nodes,0,sizeof(nodes));
66 for (i = 0; i < 8; i++) {
67 unsigned long base,limit;
69 base = read_pci_config(0, nb, 1, 0x40 + i*8);
70 limit = read_pci_config(0, nb, 1, 0x44 + i*8);
73 if ((base & 3) == 0) {
75 printk("Skipping disabled node %d\n", i);
78 if (nodeid >= numnodes) {
79 printk("Ignoring excess node %d (%lx:%lx)\n", nodeid,
85 printk(KERN_INFO "Skipping node entry %d (base %lx)\n", i,
89 if ((base >> 8) & 3 || (limit >> 8) & 3) {
90 printk(KERN_ERR "Node %d using interleaving mode %lx/%lx\n",
91 nodeid, (base>>8)&3, (limit>>8) & 3);
94 if (node_online(nodeid)) {
95 printk(KERN_INFO "Node %d already present. Skipping\n",
104 if (limit > end_pfn << PAGE_SHIFT)
105 limit = end_pfn << PAGE_SHIFT;
117 printk(KERN_ERR "Empty node %d\n", nodeid);
121 printk(KERN_ERR "Node %d bogus settings %lx-%lx.\n",
122 nodeid, base, limit);
126 /* Could sort here, but pun for now. Should not happen anyroads. */
127 if (prevbase > base) {
128 printk(KERN_ERR "Node map not sorted %lx,%lx\n",
133 printk(KERN_INFO "Node %d MemBase %016lx Limit %016lx\n",
134 nodeid, base, limit);
138 nodes[nodeid].start = base;
139 nodes[nodeid].end = limit;
147 memnode_shift = compute_hash_shift(nodes);
148 if (memnode_shift < 0) {
149 printk(KERN_ERR "No NUMA node hash function found. Contact maintainer\n");
152 printk(KERN_INFO "Using node hash shift of %d\n", memnode_shift);
154 for (i = 0; i < MAXNODE; i++) {
155 if (nodes[i].start != nodes[i].end) {
156 /* assume 1:1 NODE:CPU */
158 setup_node_bootmem(i, nodes[i].start, nodes[i].end);