1 // SPDX-License-Identifier: GPL-2.0
3 * linux/arch/alpha/mm/numa.c
5 * DISCONTIGMEM NUMA alpha support.
7 * Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE
10 #include <linux/types.h>
11 #include <linux/kernel.h>
13 #include <linux/memblock.h>
14 #include <linux/swap.h>
15 #include <linux/initrd.h>
16 #include <linux/pfn.h>
17 #include <linux/module.h>
19 #include <asm/hwrpb.h>
20 #include <asm/pgalloc.h>
21 #include <asm/sections.h>
23 pg_data_t node_data
[MAX_NUMNODES
];
24 EXPORT_SYMBOL(node_data
);
26 #undef DEBUG_DISCONTIG
27 #ifdef DEBUG_DISCONTIG
28 #define DBGDCONT(args...) printk(args)
30 #define DBGDCONT(args...)
33 #define for_each_mem_cluster(memdesc, _cluster, i) \
34 for ((_cluster) = (memdesc)->cluster, (i) = 0; \
35 (i) < (memdesc)->numclusters; (i)++, (_cluster)++)
37 static void __init
show_mem_layout(void)
39 struct memclust_struct
* cluster
;
40 struct memdesc_struct
* memdesc
;
43 /* Find free clusters, and init and free the bootmem accordingly. */
44 memdesc
= (struct memdesc_struct
*)
45 (hwrpb
->mddt_offset
+ (unsigned long) hwrpb
);
47 printk("Raw memory layout:\n");
48 for_each_mem_cluster(memdesc
, cluster
, i
) {
49 printk(" memcluster %2d, usage %1lx, start %8lu, end %8lu\n",
50 i
, cluster
->usage
, cluster
->start_pfn
,
51 cluster
->start_pfn
+ cluster
->numpages
);
56 setup_memory_node(int nid
, void *kernel_end
)
58 extern unsigned long mem_size_limit
;
59 struct memclust_struct
* cluster
;
60 struct memdesc_struct
* memdesc
;
61 unsigned long start_kernel_pfn
, end_kernel_pfn
;
62 unsigned long start
, end
;
63 unsigned long node_pfn_start
, node_pfn_end
;
64 unsigned long node_min_pfn
, node_max_pfn
;
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) */
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
83 if (cluster
->usage
& 3)
86 start
= cluster
->start_pfn
;
87 end
= start
+ cluster
->numpages
;
89 if (start
>= node_pfn_end
|| end
<= node_pfn_start
)
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
)
105 if (start
< node_min_pfn
)
106 node_min_pfn
= start
;
107 if (end
> node_max_pfn
)
111 if (mem_size_limit
&& node_max_pfn
> mem_size_limit
) {
112 static int msg_shown
= 0;
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
)
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 #if 0 /* we'll try this one again in a little while */
132 /* Cute trick to make sure our local node data is on local memory */
133 node_data
[nid
] = (pg_data_t
*)(__va(node_min_pfn
<< PAGE_SHIFT
));
135 printk(" Detected node memory: start %8lu, end %8lu\n",
136 node_min_pfn
, node_max_pfn
);
138 DBGDCONT(" DISCONTIG: node_data[%d] is at 0x%p\n", nid
, NODE_DATA(nid
));
140 /* Find the bounds of kernel memory. */
141 start_kernel_pfn
= PFN_DOWN(KERNEL_START_PHYS
);
142 end_kernel_pfn
= PFN_UP(virt_to_phys(kernel_end
));
144 if (!nid
&& (node_max_pfn
< end_kernel_pfn
|| node_min_pfn
> start_kernel_pfn
))
145 panic("kernel loaded out of ram");
147 memblock_add(PFN_PHYS(node_min_pfn
),
148 (node_max_pfn
- node_min_pfn
) << PAGE_SHIFT
);
150 /* Zone start phys-addr must be 2^(MAX_ORDER-1) aligned.
151 Note that we round this down, not up - node memory
152 has much larger alignment than 8Mb, so it's safe. */
153 node_min_pfn
&= ~((1UL << (MAX_ORDER
-1))-1);
155 NODE_DATA(nid
)->node_start_pfn
= node_min_pfn
;
156 NODE_DATA(nid
)->node_present_pages
= node_max_pfn
- node_min_pfn
;
158 node_set_online(nid
);
162 setup_memory(void *kernel_end
)
164 unsigned long kernel_size
;
169 nodes_clear(node_online_map
);
173 for (nid
= 0; nid
< MAX_NUMNODES
; nid
++)
174 setup_memory_node(nid
, kernel_end
);
176 kernel_size
= virt_to_phys(kernel_end
) - KERNEL_START_PHYS
;
177 memblock_reserve(KERNEL_START_PHYS
, kernel_size
);
179 #ifdef CONFIG_BLK_DEV_INITRD
180 initrd_start
= INITRD_START
;
182 extern void *move_initrd(unsigned long);
184 initrd_end
= initrd_start
+INITRD_SIZE
;
185 printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
186 (void *) initrd_start
, INITRD_SIZE
);
188 if ((void *)initrd_end
> phys_to_virt(PFN_PHYS(max_low_pfn
))) {
189 if (!move_initrd(PFN_PHYS(max_low_pfn
)))
190 printk("initrd extends beyond end of memory "
191 "(0x%08lx > 0x%p)\ndisabling initrd\n",
193 phys_to_virt(PFN_PHYS(max_low_pfn
)));
195 nid
= kvaddr_to_nid(initrd_start
);
196 memblock_reserve(virt_to_phys((void *)initrd_start
),
200 #endif /* CONFIG_BLK_DEV_INITRD */
203 void __init
paging_init(void)
206 unsigned long zones_size
[MAX_NR_ZONES
] = {0, };
207 unsigned long dma_local_pfn
;
210 * The old global MAX_DMA_ADDRESS per-arch API doesn't fit
211 * in the NUMA model, for now we convert it to a pfn and
212 * we interpret this pfn as a local per-node information.
213 * This issue isn't very important since none of these machines
214 * have legacy ISA slots anyways.
216 dma_local_pfn
= virt_to_phys((char *)MAX_DMA_ADDRESS
) >> PAGE_SHIFT
;
218 for_each_online_node(nid
) {
219 unsigned long start_pfn
= NODE_DATA(nid
)->node_start_pfn
;
220 unsigned long end_pfn
= start_pfn
+ NODE_DATA(nid
)->node_present_pages
;
222 if (dma_local_pfn
>= end_pfn
- start_pfn
)
223 zones_size
[ZONE_DMA
] = end_pfn
- start_pfn
;
225 zones_size
[ZONE_DMA
] = dma_local_pfn
;
226 zones_size
[ZONE_NORMAL
] = (end_pfn
- start_pfn
) - dma_local_pfn
;
228 node_set_state(nid
, N_NORMAL_MEMORY
);
229 free_area_init_node(nid
, zones_size
, start_pfn
, NULL
);
232 /* Initialize the kernel's ZERO_PGE. */
233 memset((void *)ZERO_PGE
, 0, PAGE_SIZE
);