diff options
author | Huacai Chen <chenhc@lemote.com> | 2014-06-25 23:41:28 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2014-07-30 15:46:19 -0400 |
commit | c46173183657bbdbe0d54a981c28807581648422 (patch) | |
tree | 554d75cfc577d82c043b3e2fca17819abd63033b /arch/mips/loongson/loongson-3/numa.c | |
parent | 140e39c1e3d29f50e161f55cca60f60b80408c2a (diff) |
MIPS: Add NUMA support for Loongson-3
Multiple Loongson-3A chips can be interconnected with HT0-bus. This is
a CC-NUMA system that every chip (node) has its own local memory and
cache coherency is maintained by hardware. The 64-bit physical memory
address format is as follows:
0x-0000-YZZZ-ZZZZ-ZZZZ
The high 16 bits should be 0, which means the real physical address
supported by Loongson-3 is 48-bit. The "Y" bits is the base address of
each node, which can be also considered as the node-id. The "Z" bits is
the address offset within a node, which means every node has a 44 bits
address space.
Macros XPHYSADDR and MAX_PHYSMEM_BITS are modified unconditionally,
because many other MIPS CPUs have also extended their address spaces.
Signed-off-by: Huacai Chen <chenhc@lemote.com>
Cc: John Crispin <john@phrozen.org>
Cc: Steven J. Hill <Steven.Hill@imgtec.com>
Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: linux-mips@linux-mips.org
Cc: Fuxin Zhang <zhangfx@lemote.com>
Cc: Zhangjin Wu <wuzhangjin@gmail.com>
Patchwork: https://patchwork.linux-mips.org/patch/7187/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/loongson/loongson-3/numa.c')
-rw-r--r-- | arch/mips/loongson/loongson-3/numa.c | 291 |
1 files changed, 291 insertions, 0 deletions
diff --git a/arch/mips/loongson/loongson-3/numa.c b/arch/mips/loongson/loongson-3/numa.c new file mode 100644 index 000000000000..ca025a6ba559 --- /dev/null +++ b/arch/mips/loongson/loongson-3/numa.c | |||
@@ -0,0 +1,291 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2010 Loongson Inc. & Lemote Inc. & | ||
3 | * Insititute of Computing Technology | ||
4 | * Author: Xiang Gao, gaoxiang@ict.ac.cn | ||
5 | * Huacai Chen, chenhc@lemote.com | ||
6 | * Xiaofu Meng, Shuangshuang Zhang | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | */ | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/mm.h> | ||
16 | #include <linux/mmzone.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/nodemask.h> | ||
19 | #include <linux/swap.h> | ||
20 | #include <linux/memblock.h> | ||
21 | #include <linux/bootmem.h> | ||
22 | #include <linux/pfn.h> | ||
23 | #include <linux/highmem.h> | ||
24 | #include <asm/page.h> | ||
25 | #include <asm/pgalloc.h> | ||
26 | #include <asm/sections.h> | ||
27 | #include <linux/bootmem.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <linux/irq.h> | ||
30 | #include <asm/bootinfo.h> | ||
31 | #include <asm/mc146818-time.h> | ||
32 | #include <asm/time.h> | ||
33 | #include <asm/wbflush.h> | ||
34 | #include <boot_param.h> | ||
35 | |||
36 | static struct node_data prealloc__node_data[MAX_NUMNODES]; | ||
37 | unsigned char __node_distances[MAX_NUMNODES][MAX_NUMNODES]; | ||
38 | struct node_data *__node_data[MAX_NUMNODES]; | ||
39 | EXPORT_SYMBOL(__node_data); | ||
40 | |||
41 | static void enable_lpa(void) | ||
42 | { | ||
43 | unsigned long value; | ||
44 | |||
45 | value = __read_32bit_c0_register($16, 3); | ||
46 | value |= 0x00000080; | ||
47 | __write_32bit_c0_register($16, 3, value); | ||
48 | value = __read_32bit_c0_register($16, 3); | ||
49 | pr_info("CP0_Config3: CP0 16.3 (0x%lx)\n", value); | ||
50 | |||
51 | value = __read_32bit_c0_register($5, 1); | ||
52 | value |= 0x20000000; | ||
53 | __write_32bit_c0_register($5, 1, value); | ||
54 | value = __read_32bit_c0_register($5, 1); | ||
55 | pr_info("CP0_PageGrain: CP0 5.1 (0x%lx)\n", value); | ||
56 | } | ||
57 | |||
58 | static void cpu_node_probe(void) | ||
59 | { | ||
60 | int i; | ||
61 | |||
62 | nodes_clear(node_possible_map); | ||
63 | nodes_clear(node_online_map); | ||
64 | for (i = 0; i < loongson_sysconf.nr_nodes; i++) { | ||
65 | node_set_state(num_online_nodes(), N_POSSIBLE); | ||
66 | node_set_online(num_online_nodes()); | ||
67 | } | ||
68 | |||
69 | pr_info("NUMA: Discovered %d cpus on %d nodes\n", | ||
70 | loongson_sysconf.nr_cpus, num_online_nodes()); | ||
71 | } | ||
72 | |||
73 | static int __init compute_node_distance(int row, int col) | ||
74 | { | ||
75 | int package_row = row * loongson_sysconf.cores_per_node / | ||
76 | loongson_sysconf.cores_per_package; | ||
77 | int package_col = col * loongson_sysconf.cores_per_node / | ||
78 | loongson_sysconf.cores_per_package; | ||
79 | |||
80 | if (col == row) | ||
81 | return 0; | ||
82 | else if (package_row == package_col) | ||
83 | return 40; | ||
84 | else | ||
85 | return 100; | ||
86 | } | ||
87 | |||
88 | static void __init init_topology_matrix(void) | ||
89 | { | ||
90 | int row, col; | ||
91 | |||
92 | for (row = 0; row < MAX_NUMNODES; row++) | ||
93 | for (col = 0; col < MAX_NUMNODES; col++) | ||
94 | __node_distances[row][col] = -1; | ||
95 | |||
96 | for_each_online_node(row) { | ||
97 | for_each_online_node(col) { | ||
98 | __node_distances[row][col] = | ||
99 | compute_node_distance(row, col); | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | |||
104 | static unsigned long nid_to_addroffset(unsigned int nid) | ||
105 | { | ||
106 | unsigned long result; | ||
107 | switch (nid) { | ||
108 | case 0: | ||
109 | default: | ||
110 | result = NODE0_ADDRSPACE_OFFSET; | ||
111 | break; | ||
112 | case 1: | ||
113 | result = NODE1_ADDRSPACE_OFFSET; | ||
114 | break; | ||
115 | case 2: | ||
116 | result = NODE2_ADDRSPACE_OFFSET; | ||
117 | break; | ||
118 | case 3: | ||
119 | result = NODE3_ADDRSPACE_OFFSET; | ||
120 | break; | ||
121 | } | ||
122 | return result; | ||
123 | } | ||
124 | |||
125 | static void __init szmem(unsigned int node) | ||
126 | { | ||
127 | u32 i, mem_type; | ||
128 | static unsigned long num_physpages = 0; | ||
129 | u64 node_id, node_psize, start_pfn, end_pfn, mem_start, mem_size; | ||
130 | |||
131 | /* Parse memory information and activate */ | ||
132 | for (i = 0; i < loongson_memmap->nr_map; i++) { | ||
133 | node_id = loongson_memmap->map[i].node_id; | ||
134 | if (node_id != node) | ||
135 | continue; | ||
136 | |||
137 | mem_type = loongson_memmap->map[i].mem_type; | ||
138 | mem_size = loongson_memmap->map[i].mem_size; | ||
139 | mem_start = loongson_memmap->map[i].mem_start; | ||
140 | |||
141 | switch (mem_type) { | ||
142 | case SYSTEM_RAM_LOW: | ||
143 | start_pfn = ((node_id << 44) + mem_start) >> PAGE_SHIFT; | ||
144 | node_psize = (mem_size << 20) >> PAGE_SHIFT; | ||
145 | end_pfn = start_pfn + node_psize; | ||
146 | num_physpages += node_psize; | ||
147 | pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx MB\n", | ||
148 | (u32)node_id, mem_type, mem_start, mem_size); | ||
149 | pr_info(" start_pfn:0x%llx, end_pfn:0x%llx, num_physpages:0x%lx\n", | ||
150 | start_pfn, end_pfn, num_physpages); | ||
151 | add_memory_region((node_id << 44) + mem_start, | ||
152 | (u64)mem_size << 20, BOOT_MEM_RAM); | ||
153 | memblock_add_node(PFN_PHYS(start_pfn), | ||
154 | PFN_PHYS(end_pfn - start_pfn), node); | ||
155 | break; | ||
156 | case SYSTEM_RAM_HIGH: | ||
157 | start_pfn = ((node_id << 44) + mem_start) >> PAGE_SHIFT; | ||
158 | node_psize = (mem_size << 20) >> PAGE_SHIFT; | ||
159 | end_pfn = start_pfn + node_psize; | ||
160 | num_physpages += node_psize; | ||
161 | pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx MB\n", | ||
162 | (u32)node_id, mem_type, mem_start, mem_size); | ||
163 | pr_info(" start_pfn:0x%llx, end_pfn:0x%llx, num_physpages:0x%lx\n", | ||
164 | start_pfn, end_pfn, num_physpages); | ||
165 | add_memory_region((node_id << 44) + mem_start, | ||
166 | (u64)mem_size << 20, BOOT_MEM_RAM); | ||
167 | memblock_add_node(PFN_PHYS(start_pfn), | ||
168 | PFN_PHYS(end_pfn - start_pfn), node); | ||
169 | break; | ||
170 | case MEM_RESERVED: | ||
171 | pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx MB\n", | ||
172 | (u32)node_id, mem_type, mem_start, mem_size); | ||
173 | add_memory_region((node_id << 44) + mem_start, | ||
174 | (u64)mem_size << 20, BOOT_MEM_RESERVED); | ||
175 | memblock_reserve(((node_id << 44) + mem_start), | ||
176 | mem_size << 20); | ||
177 | break; | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | |||
182 | static void __init node_mem_init(unsigned int node) | ||
183 | { | ||
184 | unsigned long bootmap_size; | ||
185 | unsigned long node_addrspace_offset; | ||
186 | unsigned long start_pfn, end_pfn, freepfn; | ||
187 | |||
188 | node_addrspace_offset = nid_to_addroffset(node); | ||
189 | pr_info("Node%d's addrspace_offset is 0x%lx\n", | ||
190 | node, node_addrspace_offset); | ||
191 | |||
192 | get_pfn_range_for_nid(node, &start_pfn, &end_pfn); | ||
193 | freepfn = start_pfn; | ||
194 | if (node == 0) | ||
195 | freepfn = PFN_UP(__pa_symbol(&_end)); /* kernel end address */ | ||
196 | pr_info("Node%d: start_pfn=0x%lx, end_pfn=0x%lx, freepfn=0x%lx\n", | ||
197 | node, start_pfn, end_pfn, freepfn); | ||
198 | |||
199 | __node_data[node] = prealloc__node_data + node; | ||
200 | |||
201 | NODE_DATA(node)->bdata = &bootmem_node_data[node]; | ||
202 | NODE_DATA(node)->node_start_pfn = start_pfn; | ||
203 | NODE_DATA(node)->node_spanned_pages = end_pfn - start_pfn; | ||
204 | |||
205 | bootmap_size = init_bootmem_node(NODE_DATA(node), freepfn, | ||
206 | start_pfn, end_pfn); | ||
207 | free_bootmem_with_active_regions(node, end_pfn); | ||
208 | if (node == 0) /* used by finalize_initrd() */ | ||
209 | max_low_pfn = end_pfn; | ||
210 | |||
211 | /* This is reserved for the kernel and bdata->node_bootmem_map */ | ||
212 | reserve_bootmem_node(NODE_DATA(node), start_pfn << PAGE_SHIFT, | ||
213 | ((freepfn - start_pfn) << PAGE_SHIFT) + bootmap_size, | ||
214 | BOOTMEM_DEFAULT); | ||
215 | |||
216 | if (node == 0 && node_end_pfn(0) >= (0xffffffff >> PAGE_SHIFT)) { | ||
217 | /* Reserve 0xff800000~0xffffffff for RS780E integrated GPU */ | ||
218 | reserve_bootmem_node(NODE_DATA(node), | ||
219 | (node_addrspace_offset | 0xff800000), | ||
220 | 8 << 20, BOOTMEM_DEFAULT); | ||
221 | } | ||
222 | |||
223 | sparse_memory_present_with_active_regions(node); | ||
224 | } | ||
225 | |||
226 | static __init void prom_meminit(void) | ||
227 | { | ||
228 | unsigned int node, cpu; | ||
229 | |||
230 | cpu_node_probe(); | ||
231 | init_topology_matrix(); | ||
232 | |||
233 | for (node = 0; node < loongson_sysconf.nr_nodes; node++) { | ||
234 | if (node_online(node)) { | ||
235 | szmem(node); | ||
236 | node_mem_init(node); | ||
237 | cpus_clear(__node_data[(node)]->cpumask); | ||
238 | } | ||
239 | } | ||
240 | for (cpu = 0; cpu < loongson_sysconf.nr_cpus; cpu++) { | ||
241 | node = cpu / loongson_sysconf.cores_per_node; | ||
242 | if (node >= num_online_nodes()) | ||
243 | node = 0; | ||
244 | pr_info("NUMA: set cpumask cpu %d on node %d\n", cpu, node); | ||
245 | cpu_set(cpu, __node_data[(node)]->cpumask); | ||
246 | } | ||
247 | } | ||
248 | |||
249 | void __init paging_init(void) | ||
250 | { | ||
251 | unsigned node; | ||
252 | unsigned long zones_size[MAX_NR_ZONES] = {0, }; | ||
253 | |||
254 | pagetable_init(); | ||
255 | |||
256 | for_each_online_node(node) { | ||
257 | unsigned long start_pfn, end_pfn; | ||
258 | |||
259 | get_pfn_range_for_nid(node, &start_pfn, &end_pfn); | ||
260 | |||
261 | if (end_pfn > max_low_pfn) | ||
262 | max_low_pfn = end_pfn; | ||
263 | } | ||
264 | #ifdef CONFIG_ZONE_DMA32 | ||
265 | zones_size[ZONE_DMA32] = MAX_DMA32_PFN; | ||
266 | #endif | ||
267 | zones_size[ZONE_NORMAL] = max_low_pfn; | ||
268 | free_area_init_nodes(zones_size); | ||
269 | } | ||
270 | |||
271 | void __init mem_init(void) | ||
272 | { | ||
273 | high_memory = (void *) __va(get_num_physpages() << PAGE_SHIFT); | ||
274 | free_all_bootmem(); | ||
275 | setup_zero_pages(); /* This comes from node 0 */ | ||
276 | mem_init_print_info(NULL); | ||
277 | } | ||
278 | |||
279 | /* All PCI device belongs to logical Node-0 */ | ||
280 | int pcibus_to_node(struct pci_bus *bus) | ||
281 | { | ||
282 | return 0; | ||
283 | } | ||
284 | EXPORT_SYMBOL(pcibus_to_node); | ||
285 | |||
286 | void __init prom_init_numa_memory(void) | ||
287 | { | ||
288 | enable_lpa(); | ||
289 | prom_meminit(); | ||
290 | } | ||
291 | EXPORT_SYMBOL(prom_init_numa_memory); | ||