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 <linux/acpi.h>
17 #include <asm/types.h>
18 #include <asm/mmzone.h>
19 #include <asm/proto.h>
21 #include <asm/pci-direct.h>
23 #include <asm/mpspec.h>
27 static __init int find_northbridge(void)
31 for (num = 0; num < 32; num++) {
34 header = read_pci_config(0, num, 0, 0x00);
35 if (header != (PCI_VENDOR_ID_AMD | (0x1100<<16)) &&
36 header != (PCI_VENDOR_ID_AMD | (0x1200<<16)) &&
37 header != (PCI_VENDOR_ID_AMD | (0x1300<<16)))
40 header = read_pci_config(0, num, 1, 0x00);
41 if (header != (PCI_VENDOR_ID_AMD | (0x1101<<16)) &&
42 header != (PCI_VENDOR_ID_AMD | (0x1201<<16)) &&
43 header != (PCI_VENDOR_ID_AMD | (0x1301<<16)))
51 static __init void early_get_boot_cpu_id(void)
54 * need to get boot_cpu_id so can use that to create apicid_to_node
58 * Find possible boot-time SMP configuration:
60 #ifdef CONFIG_X86_MPPARSE
61 early_find_smp_config();
65 * Read APIC information from ACPI tables.
67 early_acpi_boot_init();
69 #ifdef CONFIG_X86_MPPARSE
71 * get boot-time SMP configuration:
74 early_get_smp_config();
76 early_init_lapic_mapping();
79 int __init k8_scan_nodes(unsigned long start, unsigned long end)
81 unsigned numnodes, cores, bits, apicid_base;
82 unsigned long prevbase;
83 struct bootnode nodes[8];
84 int i, j, nb, found = 0;
87 if (!early_pci_allowed())
90 nb = find_northbridge();
94 printk(KERN_INFO "Scanning NUMA topology in Northbridge %d\n", nb);
96 reg = read_pci_config(0, nb, 0, 0x60);
97 numnodes = ((reg >> 4) & 0xF) + 1;
101 printk(KERN_INFO "Number of nodes %d\n", numnodes);
103 memset(&nodes, 0, sizeof(nodes));
105 for (i = 0; i < 8; i++) {
106 unsigned long base, limit;
108 base = read_pci_config(0, nb, 1, 0x40 + i*8);
109 limit = read_pci_config(0, nb, 1, 0x44 + i*8);
112 if ((base & 3) == 0) {
114 printk("Skipping disabled node %d\n", i);
117 if (nodeid >= numnodes) {
118 printk("Ignoring excess node %d (%lx:%lx)\n", nodeid,
124 printk(KERN_INFO "Skipping node entry %d (base %lx)\n",
128 if ((base >> 8) & 3 || (limit >> 8) & 3) {
129 printk(KERN_ERR "Node %d using interleaving mode %lx/%lx\n",
130 nodeid, (base>>8)&3, (limit>>8) & 3);
133 if (node_isset(nodeid, node_possible_map)) {
134 printk(KERN_INFO "Node %d already present. Skipping\n",
144 if (limit > max_pfn << PAGE_SHIFT)
145 limit = max_pfn << PAGE_SHIFT;
157 printk(KERN_ERR "Empty node %d\n", nodeid);
161 printk(KERN_ERR "Node %d bogus settings %lx-%lx.\n",
162 nodeid, base, limit);
166 /* Could sort here, but pun for now. Should not happen anyroads. */
167 if (prevbase > base) {
168 printk(KERN_ERR "Node map not sorted %lx,%lx\n",
173 printk(KERN_INFO "Node %d MemBase %016lx Limit %016lx\n",
174 nodeid, base, limit);
178 nodes[nodeid].start = base;
179 nodes[nodeid].end = limit;
183 node_set(nodeid, node_possible_map);
189 memnode_shift = compute_hash_shift(nodes, 8, NULL);
190 if (memnode_shift < 0) {
191 printk(KERN_ERR "No NUMA node hash function found. Contact maintainer\n");
194 printk(KERN_INFO "Using node hash shift of %d\n", memnode_shift);
196 /* use the coreid bits from early_identify_cpu */
197 bits = boot_cpu_data.x86_coreid_bits;
200 /* need to get boot_cpu_id early for system with apicid lifting */
201 early_get_boot_cpu_id();
202 if (boot_cpu_physical_apicid > 0) {
203 printk(KERN_INFO "BSP APIC ID: %02x\n",
204 boot_cpu_physical_apicid);
205 apicid_base = boot_cpu_physical_apicid;
208 for (i = 0; i < 8; i++) {
209 if (nodes[i].start == nodes[i].end)
212 e820_register_active_regions(i,
213 nodes[i].start >> PAGE_SHIFT,
214 nodes[i].end >> PAGE_SHIFT);
215 for (j = apicid_base; j < cores + apicid_base; j++)
216 apicid_to_node[(i << bits) + j] = i;
217 setup_node_bootmem(i, nodes[i].start, nodes[i].end);