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>
16 #include <linux/pci_ids.h>
17 #include <asm/types.h>
18 #include <asm/mmzone.h>
19 #include <asm/proto.h>
21 #include <asm/pci-direct.h>
24 static __init int find_northbridge(void)
28 for (num = 0; num < 32; num++) {
31 header = read_pci_config(0, num, 0, 0x00);
32 if (header != (PCI_VENDOR_ID_AMD | (0x1100<<16)))
35 header = read_pci_config(0, num, 1, 0x00);
36 if (header != (PCI_VENDOR_ID_AMD | (0x1101<<16)))
44 int __init k8_scan_nodes(unsigned long start, unsigned long end)
46 unsigned long prevbase;
47 struct node nodes[MAXNODE];
52 nb = find_northbridge();
56 printk(KERN_INFO "Scanning NUMA topology in Northbridge %d\n", nb);
58 reg = read_pci_config(0, nb, 0, 0x60);
59 numnodes = ((reg >> 4) & 7) + 1;
61 printk(KERN_INFO "Number of nodes %d (%x)\n", numnodes, reg);
63 memset(&nodes,0,sizeof(nodes));
65 for (i = 0; i < 8; i++) {
66 unsigned long base,limit;
68 base = read_pci_config(0, nb, 1, 0x40 + i*8);
69 limit = read_pci_config(0, nb, 1, 0x44 + i*8);
72 if ((base & 3) == 0) {
74 printk("Skipping disabled node %d\n", i);
77 if (nodeid >= numnodes) {
78 printk("Ignoring excess node %d (%lx:%lx)\n", nodeid,
84 printk(KERN_INFO "Skipping node entry %d (base %lx)\n", i,
88 if ((base >> 8) & 3 || (limit >> 8) & 3) {
89 printk(KERN_ERR "Node %d using interleaving mode %lx/%lx\n",
90 nodeid, (base>>8)&3, (limit>>8) & 3);
93 if (node_online(nodeid)) {
94 printk(KERN_INFO "Node %d already present. Skipping\n",
103 if (limit > end_pfn << PAGE_SHIFT)
104 limit = end_pfn << PAGE_SHIFT;
116 printk(KERN_ERR "Empty node %d\n", nodeid);
120 printk(KERN_ERR "Node %d bogus settings %lx-%lx.\n",
121 nodeid, base, limit);
125 /* Could sort here, but pun for now. Should not happen anyroads. */
126 if (prevbase > base) {
127 printk(KERN_ERR "Node map not sorted %lx,%lx\n",
132 printk(KERN_INFO "Node %d MemBase %016lx Limit %016lx\n",
133 nodeid, base, limit);
137 nodes[nodeid].start = base;
138 nodes[nodeid].end = limit;
146 memnode_shift = compute_hash_shift(nodes);
147 if (memnode_shift < 0) {
148 printk(KERN_ERR "No NUMA node hash function found. Contact maintainer\n");
151 printk(KERN_INFO "Using node hash shift of %d\n", memnode_shift);
153 for (i = 0; i < MAXNODE; i++) {
154 if (nodes[i].start != nodes[i].end) {
155 /* assume 1:1 NODE:CPU */
157 setup_node_bootmem(i, nodes[i].start, nodes[i].end);