GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / alpha / mm / numa.c
blobeef5acb6888c4dff2a82f34542d8d442dda6ebba
1 /*
2 * linux/arch/alpha/mm/numa.c
4 * DISCONTIGMEM NUMA alpha support.
6 * Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE
7 */
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <linux/mm.h>
12 #include <linux/bootmem.h>
13 #include <linux/swap.h>
14 #include <linux/initrd.h>
15 #include <linux/pfn.h>
16 #include <linux/module.h>
18 #include <asm/hwrpb.h>
19 #include <asm/pgalloc.h>
21 pg_data_t node_data[MAX_NUMNODES];
22 EXPORT_SYMBOL(node_data);
24 #undef DEBUG_DISCONTIG
25 #ifdef DEBUG_DISCONTIG
26 #define DBGDCONT(args...) printk(args)
27 #else
28 #define DBGDCONT(args...)
29 #endif
31 #define for_each_mem_cluster(memdesc, _cluster, i) \
32 for ((_cluster) = (memdesc)->cluster, (i) = 0; \
33 (i) < (memdesc)->numclusters; (i)++, (_cluster)++)
35 static void __init show_mem_layout(void)
37 struct memclust_struct * cluster;
38 struct memdesc_struct * memdesc;
39 int i;
41 /* Find free clusters, and init and free the bootmem accordingly. */
42 memdesc = (struct memdesc_struct *)
43 (hwrpb->mddt_offset + (unsigned long) hwrpb);
45 printk("Raw memory layout:\n");
46 for_each_mem_cluster(memdesc, cluster, i) {
47 printk(" memcluster %2d, usage %1lx, start %8lu, end %8lu\n",
48 i, cluster->usage, cluster->start_pfn,
49 cluster->start_pfn + cluster->numpages);
53 static void __init
54 setup_memory_node(int nid, void *kernel_end)
56 extern unsigned long mem_size_limit;
57 struct memclust_struct * cluster;
58 struct memdesc_struct * memdesc;
59 unsigned long start_kernel_pfn, end_kernel_pfn;
60 unsigned long bootmap_size, bootmap_pages, bootmap_start;
61 unsigned long start, end;
62 unsigned long node_pfn_start, node_pfn_end;
63 unsigned long node_min_pfn, node_max_pfn;
64 int i;
65 unsigned long node_datasz = PFN_UP(sizeof(pg_data_t));
66 int show_init = 0;
68 /* Find the bounds of current node */
69 node_pfn_start = (node_mem_start(nid)) >> PAGE_SHIFT;
70 node_pfn_end = node_pfn_start + (node_mem_size(nid) >> PAGE_SHIFT);
72 /* Find free clusters, and init and free the bootmem accordingly. */
73 memdesc = (struct memdesc_struct *)
74 (hwrpb->mddt_offset + (unsigned long) hwrpb);
76 /* find the bounds of this node (node_min_pfn/node_max_pfn) */
77 node_min_pfn = ~0UL;
78 node_max_pfn = 0UL;
79 for_each_mem_cluster(memdesc, cluster, i) {
80 /* Bit 0 is console/PALcode reserved. Bit 1 is
81 non-volatile memory -- we might want to mark
82 this for later. */
83 if (cluster->usage & 3)
84 continue;
86 start = cluster->start_pfn;
87 end = start + cluster->numpages;
89 if (start >= node_pfn_end || end <= node_pfn_start)
90 continue;
92 if (!show_init) {
93 show_init = 1;
94 printk("Initializing bootmem allocator on Node ID %d\n", nid);
96 printk(" memcluster %2d, usage %1lx, start %8lu, end %8lu\n",
97 i, cluster->usage, cluster->start_pfn,
98 cluster->start_pfn + cluster->numpages);
100 if (start < node_pfn_start)
101 start = node_pfn_start;
102 if (end > node_pfn_end)
103 end = node_pfn_end;
105 if (start < node_min_pfn)
106 node_min_pfn = start;
107 if (end > node_max_pfn)
108 node_max_pfn = end;
111 if (mem_size_limit && node_max_pfn > mem_size_limit) {
112 static int msg_shown = 0;
113 if (!msg_shown) {
114 msg_shown = 1;
115 printk("setup: forcing memory size to %ldK (from %ldK).\n",
116 mem_size_limit << (PAGE_SHIFT - 10),
117 node_max_pfn << (PAGE_SHIFT - 10));
119 node_max_pfn = mem_size_limit;
122 if (node_min_pfn >= node_max_pfn)
123 return;
125 /* Update global {min,max}_low_pfn from node information. */
126 if (node_min_pfn < min_low_pfn)
127 min_low_pfn = node_min_pfn;
128 if (node_max_pfn > max_low_pfn)
129 max_pfn = max_low_pfn = node_max_pfn;
131 num_physpages += node_max_pfn - node_min_pfn;
133 /* Quasi-mark the pg_data_t as in-use */
134 node_min_pfn += node_datasz;
135 if (node_min_pfn >= node_max_pfn) {
136 printk(" not enough mem to reserve NODE_DATA");
137 return;
139 NODE_DATA(nid)->bdata = &bootmem_node_data[nid];
141 printk(" Detected node memory: start %8lu, end %8lu\n",
142 node_min_pfn, node_max_pfn);
144 DBGDCONT(" DISCONTIG: node_data[%d] is at 0x%p\n", nid, NODE_DATA(nid));
145 DBGDCONT(" DISCONTIG: NODE_DATA(%d)->bdata is at 0x%p\n", nid, NODE_DATA(nid)->bdata);
147 /* Find the bounds of kernel memory. */
148 start_kernel_pfn = PFN_DOWN(KERNEL_START_PHYS);
149 end_kernel_pfn = PFN_UP(virt_to_phys(kernel_end));
150 bootmap_start = -1;
152 if (!nid && (node_max_pfn < end_kernel_pfn || node_min_pfn > start_kernel_pfn))
153 panic("kernel loaded out of ram");
155 /* Zone start phys-addr must be 2^(MAX_ORDER-1) aligned.
156 Note that we round this down, not up - node memory
157 has much larger alignment than 8Mb, so it's safe. */
158 node_min_pfn &= ~((1UL << (MAX_ORDER-1))-1);
160 /* We need to know how many physically contiguous pages
161 we'll need for the bootmap. */
162 bootmap_pages = bootmem_bootmap_pages(node_max_pfn-node_min_pfn);
164 /* Now find a good region where to allocate the bootmap. */
165 for_each_mem_cluster(memdesc, cluster, i) {
166 if (cluster->usage & 3)
167 continue;
169 start = cluster->start_pfn;
170 end = start + cluster->numpages;
172 if (start >= node_max_pfn || end <= node_min_pfn)
173 continue;
175 if (end > node_max_pfn)
176 end = node_max_pfn;
177 if (start < node_min_pfn)
178 start = node_min_pfn;
180 if (start < start_kernel_pfn) {
181 if (end > end_kernel_pfn
182 && end - end_kernel_pfn >= bootmap_pages) {
183 bootmap_start = end_kernel_pfn;
184 break;
185 } else if (end > start_kernel_pfn)
186 end = start_kernel_pfn;
187 } else if (start < end_kernel_pfn)
188 start = end_kernel_pfn;
189 if (end - start >= bootmap_pages) {
190 bootmap_start = start;
191 break;
195 if (bootmap_start == -1)
196 panic("couldn't find a contiguous place for the bootmap");
198 /* Allocate the bootmap and mark the whole MM as reserved. */
199 bootmap_size = init_bootmem_node(NODE_DATA(nid), bootmap_start,
200 node_min_pfn, node_max_pfn);
201 DBGDCONT(" bootmap_start %lu, bootmap_size %lu, bootmap_pages %lu\n",
202 bootmap_start, bootmap_size, bootmap_pages);
204 /* Mark the free regions. */
205 for_each_mem_cluster(memdesc, cluster, i) {
206 if (cluster->usage & 3)
207 continue;
209 start = cluster->start_pfn;
210 end = cluster->start_pfn + cluster->numpages;
212 if (start >= node_max_pfn || end <= node_min_pfn)
213 continue;
215 if (end > node_max_pfn)
216 end = node_max_pfn;
217 if (start < node_min_pfn)
218 start = node_min_pfn;
220 if (start < start_kernel_pfn) {
221 if (end > end_kernel_pfn) {
222 free_bootmem_node(NODE_DATA(nid), PFN_PHYS(start),
223 (PFN_PHYS(start_kernel_pfn)
224 - PFN_PHYS(start)));
225 printk(" freeing pages %ld:%ld\n",
226 start, start_kernel_pfn);
227 start = end_kernel_pfn;
228 } else if (end > start_kernel_pfn)
229 end = start_kernel_pfn;
230 } else if (start < end_kernel_pfn)
231 start = end_kernel_pfn;
232 if (start >= end)
233 continue;
235 free_bootmem_node(NODE_DATA(nid), PFN_PHYS(start), PFN_PHYS(end) - PFN_PHYS(start));
236 printk(" freeing pages %ld:%ld\n", start, end);
239 /* Reserve the bootmap memory. */
240 reserve_bootmem_node(NODE_DATA(nid), PFN_PHYS(bootmap_start),
241 bootmap_size, BOOTMEM_DEFAULT);
242 printk(" reserving pages %ld:%ld\n", bootmap_start, bootmap_start+PFN_UP(bootmap_size));
244 node_set_online(nid);
247 void __init
248 setup_memory(void *kernel_end)
250 int nid;
252 show_mem_layout();
254 nodes_clear(node_online_map);
256 min_low_pfn = ~0UL;
257 max_low_pfn = 0UL;
258 for (nid = 0; nid < MAX_NUMNODES; nid++)
259 setup_memory_node(nid, kernel_end);
261 #ifdef CONFIG_BLK_DEV_INITRD
262 initrd_start = INITRD_START;
263 if (initrd_start) {
264 extern void *move_initrd(unsigned long);
266 initrd_end = initrd_start+INITRD_SIZE;
267 printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
268 (void *) initrd_start, INITRD_SIZE);
270 if ((void *)initrd_end > phys_to_virt(PFN_PHYS(max_low_pfn))) {
271 if (!move_initrd(PFN_PHYS(max_low_pfn)))
272 printk("initrd extends beyond end of memory "
273 "(0x%08lx > 0x%p)\ndisabling initrd\n",
274 initrd_end,
275 phys_to_virt(PFN_PHYS(max_low_pfn)));
276 } else {
277 nid = kvaddr_to_nid(initrd_start);
278 reserve_bootmem_node(NODE_DATA(nid),
279 virt_to_phys((void *)initrd_start),
280 INITRD_SIZE, BOOTMEM_DEFAULT);
283 #endif /* CONFIG_BLK_DEV_INITRD */
286 void __init paging_init(void)
288 unsigned int nid;
289 unsigned long zones_size[MAX_NR_ZONES] = {0, };
290 unsigned long dma_local_pfn;
293 * The old global MAX_DMA_ADDRESS per-arch API doesn't fit
294 * in the NUMA model, for now we convert it to a pfn and
295 * we interpret this pfn as a local per-node information.
296 * This issue isn't very important since none of these machines
297 * have legacy ISA slots anyways.
299 dma_local_pfn = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
301 for_each_online_node(nid) {
302 bootmem_data_t *bdata = &bootmem_node_data[nid];
303 unsigned long start_pfn = bdata->node_min_pfn;
304 unsigned long end_pfn = bdata->node_low_pfn;
306 if (dma_local_pfn >= end_pfn - start_pfn)
307 zones_size[ZONE_DMA] = end_pfn - start_pfn;
308 else {
309 zones_size[ZONE_DMA] = dma_local_pfn;
310 zones_size[ZONE_NORMAL] = (end_pfn - start_pfn) - dma_local_pfn;
312 free_area_init_node(nid, zones_size, start_pfn, NULL);
315 /* Initialize the kernel's ZERO_PGE. */
316 memset((void *)ZERO_PGE, 0, PAGE_SIZE);
319 void __init mem_init(void)
321 unsigned long codesize, reservedpages, datasize, initsize, pfn;
322 extern int page_is_ram(unsigned long) __init;
323 extern char _text, _etext, _data, _edata;
324 extern char __init_begin, __init_end;
325 unsigned long nid, i;
326 high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
328 reservedpages = 0;
329 for_each_online_node(nid) {
331 * This will free up the bootmem, ie, slot 0 memory
333 totalram_pages += free_all_bootmem_node(NODE_DATA(nid));
335 pfn = NODE_DATA(nid)->node_start_pfn;
336 for (i = 0; i < node_spanned_pages(nid); i++, pfn++)
337 if (page_is_ram(pfn) &&
338 PageReserved(nid_page_nr(nid, i)))
339 reservedpages++;
342 codesize = (unsigned long) &_etext - (unsigned long) &_text;
343 datasize = (unsigned long) &_edata - (unsigned long) &_data;
344 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
346 printk("Memory: %luk/%luk available (%luk kernel code, %luk reserved, "
347 "%luk data, %luk init)\n",
348 nr_free_pages() << (PAGE_SHIFT-10),
349 num_physpages << (PAGE_SHIFT-10),
350 codesize >> 10,
351 reservedpages << (PAGE_SHIFT-10),
352 datasize >> 10,
353 initsize >> 10);