]>
Commit | Line | Data |
---|---|---|
3aa88cdf | 1 | /* |
1da177e4 LT |
2 | * AMD K8 NUMA support. |
3 | * Discover the memory map and associated nodes. | |
3aa88cdf | 4 | * |
1da177e4 | 5 | * This version reads it directly from the K8 northbridge. |
3aa88cdf | 6 | * |
1da177e4 LT |
7 | * Copyright 2002,2003 Andi Kleen, SuSE Labs. |
8 | */ | |
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> | |
14 | #include <asm/io.h> | |
15 | #include <linux/pci_ids.h> | |
cbf9bd60 | 16 | #include <linux/acpi.h> |
1da177e4 LT |
17 | #include <asm/types.h> |
18 | #include <asm/mmzone.h> | |
19 | #include <asm/proto.h> | |
20 | #include <asm/e820.h> | |
21 | #include <asm/pci-direct.h> | |
22 | #include <asm/numa.h> | |
cbf9bd60 YL |
23 | #include <asm/mpspec.h> |
24 | #include <asm/apic.h> | |
0eafe234 | 25 | #include <asm/k8.h> |
1da177e4 LT |
26 | |
27 | static __init int find_northbridge(void) | |
28 | { | |
3aa88cdf | 29 | int num; |
1da177e4 | 30 | |
3aa88cdf | 31 | for (num = 0; num < 32; num++) { |
1da177e4 | 32 | u32 header; |
3aa88cdf CM |
33 | |
34 | header = read_pci_config(0, num, 0, 0x00); | |
bb4a1d64 JD |
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))) | |
3aa88cdf | 38 | continue; |
1da177e4 | 39 | |
3aa88cdf | 40 | header = read_pci_config(0, num, 1, 0x00); |
bb4a1d64 JD |
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))) | |
3aa88cdf CM |
44 | continue; |
45 | return num; | |
46 | } | |
1da177e4 | 47 | |
3aa88cdf | 48 | return -1; |
1da177e4 LT |
49 | } |
50 | ||
cbf9bd60 YL |
51 | static __init void early_get_boot_cpu_id(void) |
52 | { | |
53 | /* | |
54 | * need to get boot_cpu_id so can use that to create apicid_to_node | |
55 | * in k8_scan_nodes() | |
56 | */ | |
57 | /* | |
58 | * Find possible boot-time SMP configuration: | |
59 | */ | |
a4caa18e | 60 | #ifdef CONFIG_X86_MPPARSE |
cbf9bd60 | 61 | early_find_smp_config(); |
a4caa18e | 62 | #endif |
cbf9bd60 YL |
63 | #ifdef CONFIG_ACPI |
64 | /* | |
65 | * Read APIC information from ACPI tables. | |
66 | */ | |
67 | early_acpi_boot_init(); | |
68 | #endif | |
a4caa18e | 69 | #ifdef CONFIG_X86_MPPARSE |
cbf9bd60 YL |
70 | /* |
71 | * get boot-time SMP configuration: | |
72 | */ | |
73 | if (smp_found_config) | |
74 | early_get_smp_config(); | |
a4caa18e | 75 | #endif |
cbf9bd60 YL |
76 | early_init_lapic_mapping(); |
77 | } | |
78 | ||
1da177e4 | 79 | int __init k8_scan_nodes(unsigned long start, unsigned long end) |
3aa88cdf | 80 | { |
55d4f22a | 81 | unsigned numnodes, cores, bits, apicid_base; |
1da177e4 | 82 | unsigned long prevbase; |
abe059e7 | 83 | struct bootnode nodes[8]; |
3f098c26 | 84 | unsigned char nodeids[8]; |
55d4f22a | 85 | int i, j, nb, found = 0; |
d34c0895 | 86 | u32 nodeid, reg; |
1da177e4 | 87 | |
0637a70a AK |
88 | if (!early_pci_allowed()) |
89 | return -1; | |
90 | ||
3aa88cdf CM |
91 | nb = find_northbridge(); |
92 | if (nb < 0) | |
1da177e4 LT |
93 | return nb; |
94 | ||
3aa88cdf | 95 | printk(KERN_INFO "Scanning NUMA topology in Northbridge %d\n", nb); |
1da177e4 | 96 | |
3aa88cdf | 97 | reg = read_pci_config(0, nb, 0, 0x60); |
1da177e4 | 98 | numnodes = ((reg >> 4) & 0xF) + 1; |
3bea9c97 AK |
99 | if (numnodes <= 1) |
100 | return -1; | |
1da177e4 LT |
101 | |
102 | printk(KERN_INFO "Number of nodes %d\n", numnodes); | |
103 | ||
3aa88cdf | 104 | memset(&nodes, 0, sizeof(nodes)); |
1da177e4 | 105 | prevbase = 0; |
3aa88cdf CM |
106 | for (i = 0; i < 8; i++) { |
107 | unsigned long base, limit; | |
3aa88cdf | 108 | |
1da177e4 LT |
109 | base = read_pci_config(0, nb, 1, 0x40 + i*8); |
110 | limit = read_pci_config(0, nb, 1, 0x44 + i*8); | |
111 | ||
3aa88cdf | 112 | nodeid = limit & 7; |
3f098c26 | 113 | nodeids[i] = nodeid; |
3aa88cdf | 114 | if ((base & 3) == 0) { |
1da177e4 | 115 | if (i < numnodes) |
3aa88cdf | 116 | printk("Skipping disabled node %d\n", i); |
1da177e4 | 117 | continue; |
3aa88cdf | 118 | } |
1da177e4 LT |
119 | if (nodeid >= numnodes) { |
120 | printk("Ignoring excess node %d (%lx:%lx)\n", nodeid, | |
3aa88cdf | 121 | base, limit); |
1da177e4 | 122 | continue; |
3aa88cdf | 123 | } |
1da177e4 | 124 | |
3aa88cdf CM |
125 | if (!limit) { |
126 | printk(KERN_INFO "Skipping node entry %d (base %lx)\n", | |
127 | i, base); | |
1da177e4 LT |
128 | continue; |
129 | } | |
130 | if ((base >> 8) & 3 || (limit >> 8) & 3) { | |
3aa88cdf CM |
131 | printk(KERN_ERR "Node %d using interleaving mode %lx/%lx\n", |
132 | nodeid, (base>>8)&3, (limit>>8) & 3); | |
133 | return -1; | |
134 | } | |
e3f1caee | 135 | if (node_isset(nodeid, node_possible_map)) { |
3aa88cdf | 136 | printk(KERN_INFO "Node %d already present. Skipping\n", |
1da177e4 LT |
137 | nodeid); |
138 | continue; | |
139 | } | |
140 | ||
3aa88cdf CM |
141 | limit >>= 16; |
142 | limit <<= 24; | |
1da177e4 | 143 | limit |= (1<<24)-1; |
ffd10a2b | 144 | limit++; |
1da177e4 | 145 | |
c987d12f YL |
146 | if (limit > max_pfn << PAGE_SHIFT) |
147 | limit = max_pfn << PAGE_SHIFT; | |
1da177e4 | 148 | if (limit <= base) |
3aa88cdf CM |
149 | continue; |
150 | ||
1da177e4 | 151 | base >>= 16; |
3aa88cdf CM |
152 | base <<= 24; |
153 | ||
154 | if (base < start) | |
155 | base = start; | |
156 | if (limit > end) | |
157 | limit = end; | |
158 | if (limit == base) { | |
159 | printk(KERN_ERR "Empty node %d\n", nodeid); | |
160 | continue; | |
1da177e4 | 161 | } |
3aa88cdf | 162 | if (limit < base) { |
1da177e4 | 163 | printk(KERN_ERR "Node %d bogus settings %lx-%lx.\n", |
3aa88cdf | 164 | nodeid, base, limit); |
1da177e4 | 165 | continue; |
3aa88cdf CM |
166 | } |
167 | ||
1da177e4 | 168 | /* Could sort here, but pun for now. Should not happen anyroads. */ |
3aa88cdf | 169 | if (prevbase > base) { |
1da177e4 | 170 | printk(KERN_ERR "Node map not sorted %lx,%lx\n", |
3aa88cdf | 171 | prevbase, base); |
1da177e4 LT |
172 | return -1; |
173 | } | |
3aa88cdf CM |
174 | |
175 | printk(KERN_INFO "Node %d MemBase %016lx Limit %016lx\n", | |
176 | nodeid, base, limit); | |
177 | ||
1da177e4 | 178 | found++; |
3aa88cdf CM |
179 | |
180 | nodes[nodeid].start = base; | |
1da177e4 | 181 | nodes[nodeid].end = limit; |
5cb248ab MG |
182 | e820_register_active_regions(nodeid, |
183 | nodes[nodeid].start >> PAGE_SHIFT, | |
184 | nodes[nodeid].end >> PAGE_SHIFT); | |
1da177e4 LT |
185 | |
186 | prevbase = base; | |
187 | ||
e3f1caee | 188 | node_set(nodeid, node_possible_map); |
3aa88cdf | 189 | } |
1da177e4 LT |
190 | |
191 | if (!found) | |
3aa88cdf | 192 | return -1; |
1da177e4 | 193 | |
6ec6e0d9 | 194 | memnode_shift = compute_hash_shift(nodes, 8, NULL); |
3aa88cdf CM |
195 | if (memnode_shift < 0) { |
196 | printk(KERN_ERR "No NUMA node hash function found. Contact maintainer\n"); | |
197 | return -1; | |
198 | } | |
199 | printk(KERN_INFO "Using node hash shift of %d\n", memnode_shift); | |
1da177e4 | 200 | |
3f6e5a12 YL |
201 | /* use the coreid bits from early_identify_cpu */ |
202 | bits = boot_cpu_data.x86_coreid_bits; | |
203 | cores = (1<<bits); | |
cbf9bd60 YL |
204 | apicid_base = 0; |
205 | /* need to get boot_cpu_id early for system with apicid lifting */ | |
206 | early_get_boot_cpu_id(); | |
207 | if (boot_cpu_physical_apicid > 0) { | |
208 | printk(KERN_INFO "BSP APIC ID: %02x\n", | |
209 | boot_cpu_physical_apicid); | |
210 | apicid_base = boot_cpu_physical_apicid; | |
211 | } | |
3f6e5a12 | 212 | |
1da177e4 | 213 | for (i = 0; i < 8; i++) { |
3aa88cdf | 214 | if (nodes[i].start != nodes[i].end) { |
3f098c26 | 215 | nodeid = nodeids[i]; |
cbf9bd60 | 216 | for (j = apicid_base; j < cores + apicid_base; j++) |
3f6e5a12 | 217 | apicid_to_node[(nodeid << bits) + j] = i; |
3aa88cdf CM |
218 | setup_node_bootmem(i, nodes[i].start, nodes[i].end); |
219 | } | |
1da177e4 LT |
220 | } |
221 | ||
222 | numa_init_array(); | |
223 | return 0; | |
3aa88cdf | 224 | } |