ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / i386 / kernel / numaq.c
1 /*
2  * Written by: Patricia Gaughen, IBM Corporation
3  *
4  * Copyright (C) 2002, IBM Corp.
5  *
6  * All rights reserved.          
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
16  * NON INFRINGEMENT.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  * Send feedback to <gone@us.ibm.com>
24  */
25
26 #include <linux/config.h>
27 #include <linux/mm.h>
28 #include <linux/bootmem.h>
29 #include <linux/mmzone.h>
30 #include <linux/module.h>
31 #include <asm/numaq.h>
32
33 /* These are needed before the pgdat's are created */
34 extern long node_start_pfn[], node_end_pfn[];
35
36 #define MB_TO_PAGES(addr) ((addr) << (20 - PAGE_SHIFT))
37
38 /*
39  * Function: smp_dump_qct()
40  *
41  * Description: gets memory layout from the quad config table.  This
42  * function also increments numnodes with the number of nodes (quads)
43  * present.
44  */
45 static void __init smp_dump_qct(void)
46 {
47         int node;
48         struct eachquadmem *eq;
49         struct sys_cfg_data *scd =
50                 (struct sys_cfg_data *)__va(SYS_CFG_DATA_PRIV_ADDR);
51
52         numnodes = 0;
53         for(node = 0; node < MAX_NUMNODES; node++) {
54                 if(scd->quads_present31_0 & (1 << node)) {
55                         node_set_online(node);
56                         numnodes++;
57                         eq = &scd->eq[node];
58                         /* Convert to pages */
59                         node_start_pfn[node] = MB_TO_PAGES(
60                                 eq->hi_shrd_mem_start - eq->priv_mem_size);
61                         node_end_pfn[node] = MB_TO_PAGES(
62                                 eq->hi_shrd_mem_start + eq->hi_shrd_mem_size);
63                 }
64         }
65 }
66
67 /*
68  * for each node mark the regions
69  *        TOPOFMEM = hi_shrd_mem_start + hi_shrd_mem_size
70  *
71  * need to be very careful to not mark 1024+ as belonging
72  * to node 0. will want 1027 to show as belonging to node 1
73  * example:
74  *  TOPOFMEM = 1024
75  * 1024 >> 8 = 4 (subtract 1 for starting at 0]
76  * tmpvar = TOPOFMEM - 256 = 768
77  * 1024 >> 8 = 4 (subtract 1 for starting at 0]
78  * 
79  */
80 static void __init initialize_physnode_map(void)
81 {
82         int nid;
83         unsigned int topofmem, cur;
84         struct eachquadmem *eq;
85         struct sys_cfg_data *scd =
86                 (struct sys_cfg_data *)__va(SYS_CFG_DATA_PRIV_ADDR);
87
88         
89         for(nid = 0; nid < numnodes; nid++) {
90                 if(scd->quads_present31_0 & (1 << nid)) {
91                         eq = &scd->eq[nid];
92                         cur = eq->hi_shrd_mem_start;
93                         topofmem = eq->hi_shrd_mem_start + eq->hi_shrd_mem_size;
94                         while (cur < topofmem) {
95                                 physnode_map[cur >> 8] = nid;
96                                 cur ++;
97                         }
98                 }
99         }
100 }
101
102 /*
103  * Unlike Summit, we don't really care to let the NUMA-Q
104  * fall back to flat mode.  Don't compile for NUMA-Q
105  * unless you really need it!
106  */
107 int __init get_memcfg_numaq(void)
108 {
109         smp_dump_qct();
110         initialize_physnode_map();
111         return 1;
112 }