x86: let MPS support be selectable, v2
[deliverable/linux.git] / arch / x86 / mm / k8topology_64.c
CommitLineData
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>
1da177e4
LT
25
26static __init int find_northbridge(void)
27{
3aa88cdf 28 int num;
1da177e4 29
3aa88cdf 30 for (num = 0; num < 32; num++) {
1da177e4 31 u32 header;
3aa88cdf
CM
32
33 header = read_pci_config(0, num, 0, 0x00);
bb4a1d64
JD
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)))
3aa88cdf 37 continue;
1da177e4 38
3aa88cdf 39 header = read_pci_config(0, num, 1, 0x00);
bb4a1d64
JD
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)))
3aa88cdf
CM
43 continue;
44 return num;
45 }
1da177e4 46
3aa88cdf 47 return -1;
1da177e4
LT
48}
49
cbf9bd60
YL
50static __init void early_get_boot_cpu_id(void)
51{
52 /*
53 * need to get boot_cpu_id so can use that to create apicid_to_node
54 * in k8_scan_nodes()
55 */
56 /*
57 * Find possible boot-time SMP configuration:
58 */
59 early_find_smp_config();
60#ifdef CONFIG_ACPI
61 /*
62 * Read APIC information from ACPI tables.
63 */
64 early_acpi_boot_init();
65#endif
66 /*
67 * get boot-time SMP configuration:
68 */
69 if (smp_found_config)
70 early_get_smp_config();
71 early_init_lapic_mapping();
72}
73
1da177e4 74int __init k8_scan_nodes(unsigned long start, unsigned long end)
3aa88cdf 75{
1da177e4 76 unsigned long prevbase;
abe059e7 77 struct bootnode nodes[8];
3f6e5a12 78 int nodeid, i, nb;
3f098c26 79 unsigned char nodeids[8];
1da177e4
LT
80 int found = 0;
81 u32 reg;
82 unsigned numnodes;
3f6e5a12
YL
83 unsigned cores;
84 unsigned bits;
85 int j;
cbf9bd60 86 unsigned apicid_base;
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;
3f098c26 108 u32 nodeid;
3aa88cdf 109
1da177e4
LT
110 base = read_pci_config(0, nb, 1, 0x40 + i*8);
111 limit = read_pci_config(0, nb, 1, 0x44 + i*8);
112
3aa88cdf 113 nodeid = limit & 7;
3f098c26 114 nodeids[i] = nodeid;
3aa88cdf 115 if ((base & 3) == 0) {
1da177e4 116 if (i < numnodes)
3aa88cdf 117 printk("Skipping disabled node %d\n", i);
1da177e4 118 continue;
3aa88cdf 119 }
1da177e4
LT
120 if (nodeid >= numnodes) {
121 printk("Ignoring excess node %d (%lx:%lx)\n", nodeid,
3aa88cdf 122 base, limit);
1da177e4 123 continue;
3aa88cdf 124 }
1da177e4 125
3aa88cdf
CM
126 if (!limit) {
127 printk(KERN_INFO "Skipping node entry %d (base %lx)\n",
128 i, base);
1da177e4
LT
129 continue;
130 }
131 if ((base >> 8) & 3 || (limit >> 8) & 3) {
3aa88cdf
CM
132 printk(KERN_ERR "Node %d using interleaving mode %lx/%lx\n",
133 nodeid, (base>>8)&3, (limit>>8) & 3);
134 return -1;
135 }
e3f1caee 136 if (node_isset(nodeid, node_possible_map)) {
3aa88cdf 137 printk(KERN_INFO "Node %d already present. Skipping\n",
1da177e4
LT
138 nodeid);
139 continue;
140 }
141
3aa88cdf
CM
142 limit >>= 16;
143 limit <<= 24;
1da177e4 144 limit |= (1<<24)-1;
ffd10a2b 145 limit++;
1da177e4
LT
146
147 if (limit > end_pfn << PAGE_SHIFT)
148 limit = end_pfn << PAGE_SHIFT;
149 if (limit <= base)
3aa88cdf
CM
150 continue;
151
1da177e4 152 base >>= 16;
3aa88cdf
CM
153 base <<= 24;
154
155 if (base < start)
156 base = start;
157 if (limit > end)
158 limit = end;
159 if (limit == base) {
160 printk(KERN_ERR "Empty node %d\n", nodeid);
161 continue;
1da177e4 162 }
3aa88cdf 163 if (limit < base) {
1da177e4 164 printk(KERN_ERR "Node %d bogus settings %lx-%lx.\n",
3aa88cdf 165 nodeid, base, limit);
1da177e4 166 continue;
3aa88cdf
CM
167 }
168
1da177e4 169 /* Could sort here, but pun for now. Should not happen anyroads. */
3aa88cdf 170 if (prevbase > base) {
1da177e4 171 printk(KERN_ERR "Node map not sorted %lx,%lx\n",
3aa88cdf 172 prevbase, base);
1da177e4
LT
173 return -1;
174 }
3aa88cdf
CM
175
176 printk(KERN_INFO "Node %d MemBase %016lx Limit %016lx\n",
177 nodeid, base, limit);
178
1da177e4 179 found++;
3aa88cdf
CM
180
181 nodes[nodeid].start = base;
1da177e4 182 nodes[nodeid].end = limit;
5cb248ab
MG
183 e820_register_active_regions(nodeid,
184 nodes[nodeid].start >> PAGE_SHIFT,
185 nodes[nodeid].end >> PAGE_SHIFT);
1da177e4
LT
186
187 prevbase = base;
188
e3f1caee 189 node_set(nodeid, node_possible_map);
3aa88cdf 190 }
1da177e4
LT
191
192 if (!found)
3aa88cdf 193 return -1;
1da177e4 194
6ec6e0d9 195 memnode_shift = compute_hash_shift(nodes, 8, NULL);
3aa88cdf
CM
196 if (memnode_shift < 0) {
197 printk(KERN_ERR "No NUMA node hash function found. Contact maintainer\n");
198 return -1;
199 }
200 printk(KERN_INFO "Using node hash shift of %d\n", memnode_shift);
1da177e4 201
3f6e5a12
YL
202 /* use the coreid bits from early_identify_cpu */
203 bits = boot_cpu_data.x86_coreid_bits;
204 cores = (1<<bits);
cbf9bd60
YL
205 apicid_base = 0;
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;
212 }
3f6e5a12 213
1da177e4 214 for (i = 0; i < 8; i++) {
3aa88cdf 215 if (nodes[i].start != nodes[i].end) {
3f098c26 216 nodeid = nodeids[i];
cbf9bd60 217 for (j = apicid_base; j < cores + apicid_base; j++)
3f6e5a12 218 apicid_to_node[(nodeid << bits) + j] = i;
3aa88cdf
CM
219 setup_node_bootmem(i, nodes[i].start, nodes[i].end);
220 }
1da177e4
LT
221 }
222
223 numa_init_array();
224 return 0;
3aa88cdf 225}
This page took 0.35382 seconds and 5 git commands to generate.