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 <asm/types.h>
17 #include <asm/mmzone.h>
18 #include <asm/proto.h>
20 #include <asm/pci-direct.h>
23 static __init
int find_northbridge(void)
27 for (num
= 0; num
< 32; num
++) {
30 header
= read_pci_config(0, num
, 0, 0x00);
31 if (header
!= (PCI_VENDOR_ID_AMD
| (0x1100<<16)) &&
32 header
!= (PCI_VENDOR_ID_AMD
| (0x1200<<16)) &&
33 header
!= (PCI_VENDOR_ID_AMD
| (0x1300<<16)))
36 header
= read_pci_config(0, num
, 1, 0x00);
37 if (header
!= (PCI_VENDOR_ID_AMD
| (0x1101<<16)) &&
38 header
!= (PCI_VENDOR_ID_AMD
| (0x1201<<16)) &&
39 header
!= (PCI_VENDOR_ID_AMD
| (0x1301<<16)))
47 int __init
k8_scan_nodes(unsigned long start
, unsigned long end
)
49 unsigned long prevbase
;
50 struct bootnode nodes
[8];
52 unsigned char nodeids
[8];
60 if (!early_pci_allowed())
63 nb
= find_northbridge();
67 printk(KERN_INFO
"Scanning NUMA topology in Northbridge %d\n", nb
);
69 reg
= read_pci_config(0, nb
, 0, 0x60);
70 numnodes
= ((reg
>> 4) & 0xF) + 1;
74 printk(KERN_INFO
"Number of nodes %d\n", numnodes
);
76 memset(&nodes
, 0, sizeof(nodes
));
78 for (i
= 0; i
< 8; i
++) {
79 unsigned long base
, limit
;
82 base
= read_pci_config(0, nb
, 1, 0x40 + i
*8);
83 limit
= read_pci_config(0, nb
, 1, 0x44 + i
*8);
87 if ((base
& 3) == 0) {
89 printk("Skipping disabled node %d\n", i
);
92 if (nodeid
>= numnodes
) {
93 printk("Ignoring excess node %d (%lx:%lx)\n", nodeid
,
99 printk(KERN_INFO
"Skipping node entry %d (base %lx)\n",
103 if ((base
>> 8) & 3 || (limit
>> 8) & 3) {
104 printk(KERN_ERR
"Node %d using interleaving mode %lx/%lx\n",
105 nodeid
, (base
>>8)&3, (limit
>>8) & 3);
108 if (node_isset(nodeid
, node_possible_map
)) {
109 printk(KERN_INFO
"Node %d already present. Skipping\n",
119 if (limit
> end_pfn
<< PAGE_SHIFT
)
120 limit
= end_pfn
<< PAGE_SHIFT
;
132 printk(KERN_ERR
"Empty node %d\n", nodeid
);
136 printk(KERN_ERR
"Node %d bogus settings %lx-%lx.\n",
137 nodeid
, base
, limit
);
141 /* Could sort here, but pun for now. Should not happen anyroads. */
142 if (prevbase
> base
) {
143 printk(KERN_ERR
"Node map not sorted %lx,%lx\n",
148 printk(KERN_INFO
"Node %d MemBase %016lx Limit %016lx\n",
149 nodeid
, base
, limit
);
153 nodes
[nodeid
].start
= base
;
154 nodes
[nodeid
].end
= limit
;
155 e820_register_active_regions(nodeid
,
156 nodes
[nodeid
].start
>> PAGE_SHIFT
,
157 nodes
[nodeid
].end
>> PAGE_SHIFT
);
161 node_set(nodeid
, node_possible_map
);
167 memnode_shift
= compute_hash_shift(nodes
, 8, NULL
);
168 if (memnode_shift
< 0) {
169 printk(KERN_ERR
"No NUMA node hash function found. Contact maintainer\n");
172 printk(KERN_INFO
"Using node hash shift of %d\n", memnode_shift
);
174 /* use the coreid bits from early_identify_cpu */
175 bits
= boot_cpu_data
.x86_coreid_bits
;
178 for (i
= 0; i
< 8; i
++) {
179 if (nodes
[i
].start
!= nodes
[i
].end
) {
181 for (j
= 0; j
< cores
; j
++)
182 apicid_to_node
[(nodeid
<< bits
) + j
] = i
;
183 setup_node_bootmem(i
, nodes
[i
].start
, nodes
[i
].end
);