3 * Discover the memory map and associated nodes.
5 * This version reads it directly from the K8 northbridge.
7 * Copyright 2002,2003 Andi Kleen, SuSE Labs.
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/string.h>
12 #include <linux/module.h>
13 #include <linux/nodemask.h>
15 #include <linux/pci_ids.h>
16 #include <asm/types.h>
17 #include <asm/mmzone.h>
18 #include <asm/proto.h>
20 #include <asm/pci-direct.h>
23 static __init int find_northbridge(void)
27 for (num = 0; num < 32; num++) {
30 header = read_pci_config(0, num, 0, 0x00);
31 if (header != (PCI_VENDOR_ID_AMD | (0x1100<<16)))
34 header = read_pci_config(0, num, 1, 0x00);
35 if (header != (PCI_VENDOR_ID_AMD | (0x1101<<16)))
43 int __init k8_scan_nodes(unsigned long start, unsigned long end)
45 unsigned long prevbase;
48 unsigned char nodeids[8];
52 nodemask_t nodes_parsed;
53 unsigned dualcore = 0;
55 nodes_clear(nodes_parsed);
57 nb = find_northbridge();
61 printk(KERN_INFO "Scanning NUMA topology in Northbridge %d\n", nb);
63 reg = read_pci_config(0, nb, 0, 0x60);
64 numnodes = ((reg >> 4) & 0xF) + 1;
66 printk(KERN_INFO "Number of nodes %d\n", numnodes);
68 memset(&nodes,0,sizeof(nodes));
70 for (i = 0; i < 8; i++) {
71 unsigned long base,limit;
74 /* Undefined before E stepping, but hopefully 0 */
75 dualcore |= ((read_pci_config(0, nb, 3, 0xe8) >> 12) & 3) == 1;
76 base = read_pci_config(0, nb, 1, 0x40 + i*8);
77 limit = read_pci_config(0, nb, 1, 0x44 + i*8);
81 if ((base & 3) == 0) {
83 printk("Skipping disabled node %d\n", i);
86 if (nodeid >= numnodes) {
87 printk("Ignoring excess node %d (%lx:%lx)\n", nodeid,
93 printk(KERN_INFO "Skipping node entry %d (base %lx)\n", i,
97 if ((base >> 8) & 3 || (limit >> 8) & 3) {
98 printk(KERN_ERR "Node %d using interleaving mode %lx/%lx\n",
99 nodeid, (base>>8)&3, (limit>>8) & 3);
102 if (node_isset(nodeid, nodes_parsed)) {
103 printk(KERN_INFO "Node %d already present. Skipping\n",
113 if (limit > end_pfn << PAGE_SHIFT)
114 limit = end_pfn << PAGE_SHIFT;
126 printk(KERN_ERR "Empty node %d\n", nodeid);
130 printk(KERN_ERR "Node %d bogus settings %lx-%lx.\n",
131 nodeid, base, limit);
135 /* Could sort here, but pun for now. Should not happen anyroads. */
136 if (prevbase > base) {
137 printk(KERN_ERR "Node map not sorted %lx,%lx\n",
142 printk(KERN_INFO "Node %d MemBase %016lx Limit %016lx\n",
143 nodeid, base, limit);
147 nodes[nodeid].start = base;
148 nodes[nodeid].end = limit;
152 node_set(nodeid, nodes_parsed);
158 memnode_shift = compute_hash_shift(nodes, 8);
159 if (memnode_shift < 0) {
160 printk(KERN_ERR "No NUMA node hash function found. Contact maintainer\n");
163 printk(KERN_INFO "Using node hash shift of %d\n", memnode_shift);
165 for (i = 0; i < 8; i++) {
166 if (nodes[i].start != nodes[i].end) {
168 apicid_to_node[nodeid << dualcore] = i;
169 apicid_to_node[(nodeid << dualcore) + dualcore] = i;
170 setup_node_bootmem(i, nodes[i].start, nodes[i].end);