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>
26 static __init int find_northbridge(void)
30 for (num = 0; num < 32; num++) {
33 header = read_pci_config(0, num, 0, 0x00);
34 if (header != (PCI_VENDOR_ID_AMD | (0x1100<<16)) &&
35 header != (PCI_VENDOR_ID_AMD | (0x1200<<16)) &&
36 header != (PCI_VENDOR_ID_AMD | (0x1300<<16)))
39 header = read_pci_config(0, num, 1, 0x00);
40 if (header != (PCI_VENDOR_ID_AMD | (0x1101<<16)) &&
41 header != (PCI_VENDOR_ID_AMD | (0x1201<<16)) &&
42 header != (PCI_VENDOR_ID_AMD | (0x1301<<16)))
50 static __init void early_get_boot_cpu_id(void)
53 * need to get boot_cpu_id so can use that to create apicid_to_node
57 * Find possible boot-time SMP configuration:
59 early_find_smp_config();
62 * Read APIC information from ACPI tables.
64 early_acpi_boot_init();
67 * get boot-time SMP configuration:
70 early_get_smp_config();
71 early_init_lapic_mapping();
74 int __init k8_scan_nodes(unsigned long start, unsigned long end)
76 unsigned long prevbase;
77 struct bootnode nodes[8];
79 unsigned char nodeids[8];
88 if (!early_pci_allowed())
91 nb = find_northbridge();
95 printk(KERN_INFO "Scanning NUMA topology in Northbridge %d\n", nb);
97 reg = read_pci_config(0, nb, 0, 0x60);
98 numnodes = ((reg >> 4) & 0xF) + 1;
102 printk(KERN_INFO "Number of nodes %d\n", numnodes);
104 memset(&nodes, 0, sizeof(nodes));
106 for (i = 0; i < 8; i++) {
107 unsigned long base, limit;
110 base = read_pci_config(0, nb, 1, 0x40 + i*8);
111 limit = read_pci_config(0, nb, 1, 0x44 + i*8);
115 if ((base & 3) == 0) {
117 printk("Skipping disabled node %d\n", i);
120 if (nodeid >= numnodes) {
121 printk("Ignoring excess node %d (%lx:%lx)\n", nodeid,
127 printk(KERN_INFO "Skipping node entry %d (base %lx)\n",
131 if ((base >> 8) & 3 || (limit >> 8) & 3) {
132 printk(KERN_ERR "Node %d using interleaving mode %lx/%lx\n",
133 nodeid, (base>>8)&3, (limit>>8) & 3);
136 if (node_isset(nodeid, node_possible_map)) {
137 printk(KERN_INFO "Node %d already present. Skipping\n",
147 if (limit > end_pfn << PAGE_SHIFT)
148 limit = end_pfn << PAGE_SHIFT;
160 printk(KERN_ERR "Empty node %d\n", nodeid);
164 printk(KERN_ERR "Node %d bogus settings %lx-%lx.\n",
165 nodeid, base, limit);
169 /* Could sort here, but pun for now. Should not happen anyroads. */
170 if (prevbase > base) {
171 printk(KERN_ERR "Node map not sorted %lx,%lx\n",
176 printk(KERN_INFO "Node %d MemBase %016lx Limit %016lx\n",
177 nodeid, base, limit);
181 nodes[nodeid].start = base;
182 nodes[nodeid].end = limit;
183 e820_register_active_regions(nodeid,
184 nodes[nodeid].start >> PAGE_SHIFT,
185 nodes[nodeid].end >> PAGE_SHIFT);
189 node_set(nodeid, node_possible_map);
195 memnode_shift = compute_hash_shift(nodes, 8, NULL);
196 if (memnode_shift < 0) {
197 printk(KERN_ERR "No NUMA node hash function found. Contact maintainer\n");
200 printk(KERN_INFO "Using node hash shift of %d\n", memnode_shift);
202 /* use the coreid bits from early_identify_cpu */
203 bits = boot_cpu_data.x86_coreid_bits;
206 /* need to get boot_cpu_id early for system with apicid lifting */
207 early_get_boot_cpu_id();
208 if (boot_cpu_physical_apicid > 0) {
209 printk(KERN_INFO "BSP APIC ID: %02x\n",
210 boot_cpu_physical_apicid);
211 apicid_base = boot_cpu_physical_apicid;
214 for (i = 0; i < 8; i++) {
215 if (nodes[i].start != nodes[i].end) {
217 for (j = apicid_base; j < cores + apicid_base; j++)
218 apicid_to_node[(nodeid << bits) + j] = i;
219 setup_node_bootmem(i, nodes[i].start, nodes[i].end);