aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/pci/k8-bus_64.c
diff options
context:
space:
mode:
authorYinghai Lu <Yinghai.Lu@Sun.COM>2008-02-19 06:20:09 -0500
committerIngo Molnar <mingo@elte.hu>2008-04-26 17:41:04 -0400
commit871d5f8dd0f7647f03facd4cb79485938d1b61ab (patch)
treeb08eee02ddd7b4bdb9dfde2637f5154e409cdacc /arch/x86/pci/k8-bus_64.c
parentbb63b4219976d48ed6d22ac33c18be334fb5a78c (diff)
x86: get mp_bus_to_node early
Currently, on an amd k8 system with multi ht chains, the numa_node of pci devices under /sys/devices/pci0000:80/* is always 0, even if that chain is on node 1 or 2 or 3. Workaround: pcibus_to_node(bus) is used when we want to get the node that pci_device is on. In struct device, we already have numa_node member, and we could use dev_to_node()/set_dev_node() to get and set numa_node in the device. set_dev_node is called in pci_device_add() with pcibus_to_node(bus), and pcibus_to_node uses bus->sysdata for nodeid. The problem is when pci_add_device is called, bus->sysdata is not assigned correct nodeid yet. The result is that numa_node will always be 0. pcibios_scan_root and pci_scan_root could take sysdata. So we need to get mp_bus_to_node mapping before these two are called, and thus get_mp_bus_to_node could get correct node for sysdata in root bus. In scanning of the root bus, all child busses will take parent bus sysdata. So all pci_device->dev.numa_node will be assigned correctly and automatically. Later we could use dev_to_node(&pci_dev->dev) to get numa_node, and we could also could make other bus specific device get the correct numa_node too. This is an updated version of pci_sysdata and Jeff's pci_domain patch. [ mingo@elte.hu: build fix ] Signed-off-by: Yinghai Lu <yinghai.lu@sun.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/x86/pci/k8-bus_64.c')
-rw-r--r--arch/x86/pci/k8-bus_64.c92
1 files changed, 66 insertions, 26 deletions
diff --git a/arch/x86/pci/k8-bus_64.c b/arch/x86/pci/k8-bus_64.c
index 9cc813e29706..3903efbca535 100644
--- a/arch/x86/pci/k8-bus_64.c
+++ b/arch/x86/pci/k8-bus_64.c
@@ -1,7 +1,9 @@
1#include <linux/init.h> 1#include <linux/init.h>
2#include <linux/pci.h> 2#include <linux/pci.h>
3#include <asm/pci-direct.h>
3#include <asm/mpspec.h> 4#include <asm/mpspec.h>
4#include <linux/cpumask.h> 5#include <linux/cpumask.h>
6#include <linux/topology.h>
5 7
6/* 8/*
7 * This discovers the pcibus <-> node mapping on AMD K8. 9 * This discovers the pcibus <-> node mapping on AMD K8.
@@ -20,64 +22,102 @@
20#define SUBORDINATE_LDT_BUS_NUMBER(dword) ((dword >> 16) & 0xFF) 22#define SUBORDINATE_LDT_BUS_NUMBER(dword) ((dword >> 16) & 0xFF)
21#define PCI_DEVICE_ID_K8HTCONFIG 0x1100 23#define PCI_DEVICE_ID_K8HTCONFIG 0x1100
22 24
25#ifdef CONFIG_NUMA
26
27#define BUS_NR 256
28
29static int mp_bus_to_node[BUS_NR];
30
31void set_mp_bus_to_node(int busnum, int node)
32{
33 if (busnum >= 0 && busnum < BUS_NR)
34 mp_bus_to_node[busnum] = node;
35}
36
37int get_mp_bus_to_node(int busnum)
38{
39 int node = -1;
40
41 if (busnum < 0 || busnum > (BUS_NR - 1))
42 return node;
43
44 node = mp_bus_to_node[busnum];
45
46 /*
47 * let numa_node_id to decide it later in dma_alloc_pages
48 * if there is no ram on that node
49 */
50 if (node != -1 && !node_online(node))
51 node = -1;
52
53 return node;
54}
55
56#endif
57
23/** 58/**
24 * fill_mp_bus_to_cpumask() 59 * early_fill_mp_bus_to_node()
60 * called before pcibios_scan_root and pci_scan_bus
25 * fills the mp_bus_to_cpumask array based according to the LDT Bus Number 61 * fills the mp_bus_to_cpumask array based according to the LDT Bus Number
26 * Registers found in the K8 northbridge 62 * Registers found in the K8 northbridge
27 */ 63 */
28__init static int 64__init static int
29fill_mp_bus_to_cpumask(void) 65early_fill_mp_bus_to_node(void)
30{ 66{
31 struct pci_dev *nb_dev = NULL; 67#ifdef CONFIG_NUMA
32 int i, j; 68 int i, j;
69 unsigned slot;
33 u32 ldtbus, nid; 70 u32 ldtbus, nid;
71 u32 id;
34 static int lbnr[3] = { 72 static int lbnr[3] = {
35 LDT_BUS_NUMBER_REGISTER_0, 73 LDT_BUS_NUMBER_REGISTER_0,
36 LDT_BUS_NUMBER_REGISTER_1, 74 LDT_BUS_NUMBER_REGISTER_1,
37 LDT_BUS_NUMBER_REGISTER_2 75 LDT_BUS_NUMBER_REGISTER_2
38 }; 76 };
39 77
40 while ((nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 78 for (i = 0; i < BUS_NR; i++)
41 PCI_DEVICE_ID_K8HTCONFIG, nb_dev))) { 79 mp_bus_to_node[i] = -1;
42 pci_read_config_dword(nb_dev, NODE_ID_REGISTER, &nid); 80
81 if (!early_pci_allowed())
82 return -1;
83
84 for (slot = 0x18; slot < 0x20; slot++) {
85 id = read_pci_config(0, slot, 0, PCI_VENDOR_ID);
86 if (id != (PCI_VENDOR_ID_AMD | (PCI_DEVICE_ID_K8HTCONFIG<<16)))
87 break;
88 nid = read_pci_config(0, slot, 0, NODE_ID_REGISTER);
43 89
44 for (i = 0; i < NR_LDT_BUS_NUMBER_REGISTERS; i++) { 90 for (i = 0; i < NR_LDT_BUS_NUMBER_REGISTERS; i++) {
45 pci_read_config_dword(nb_dev, lbnr[i], &ldtbus); 91 ldtbus = read_pci_config(0, slot, 0, lbnr[i]);
46 /* 92 /*
47 * if there are no busses hanging off of the current 93 * if there are no busses hanging off of the current
48 * ldt link then both the secondary and subordinate 94 * ldt link then both the secondary and subordinate
49 * bus number fields are set to 0. 95 * bus number fields are set to 0.
50 * 96 *
51 * RED-PEN 97 * RED-PEN
52 * This is slightly broken because it assumes 98 * This is slightly broken because it assumes
53 * HT node IDs == Linux node ids, which is not always 99 * HT node IDs == Linux node ids, which is not always
54 * true. However it is probably mostly true. 100 * true. However it is probably mostly true.
55 */ 101 */
56 if (!(SECONDARY_LDT_BUS_NUMBER(ldtbus) == 0 102 if (!(SECONDARY_LDT_BUS_NUMBER(ldtbus) == 0
57 && SUBORDINATE_LDT_BUS_NUMBER(ldtbus) == 0)) { 103 && SUBORDINATE_LDT_BUS_NUMBER(ldtbus) == 0)) {
58 for (j = SECONDARY_LDT_BUS_NUMBER(ldtbus); 104 for (j = SECONDARY_LDT_BUS_NUMBER(ldtbus);
59 j <= SUBORDINATE_LDT_BUS_NUMBER(ldtbus); 105 j <= SUBORDINATE_LDT_BUS_NUMBER(ldtbus);
60 j++) { 106 j++) {
61 struct pci_bus *bus; 107 int node = NODE_ID(nid);
62 struct pci_sysdata *sd; 108 mp_bus_to_node[j] = (unsigned char)node;
63 109 }
64 long node = NODE_ID(nid);
65 /* Algorithm a bit dumb, but
66 it shouldn't matter here */
67 bus = pci_find_bus(0, j);
68 if (!bus)
69 continue;
70 if (!node_online(node))
71 node = 0;
72
73 sd = bus->sysdata;
74 sd->node = node;
75 }
76 } 110 }
77 } 111 }
78 } 112 }
79 113
114 for (i = 0; i < BUS_NR; i++) {
115 int node = mp_bus_to_node[i];
116 if (node >= 0)
117 printk(KERN_DEBUG "bus: %02x to node: %02x\n", i, node);
118 }
119#endif
80 return 0; 120 return 0;
81} 121}
82 122
83fs_initcall(fill_mp_bus_to_cpumask); 123postcore_initcall(early_fill_mp_bus_to_node);