Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 1 | /* |
| 2 | * arch/sh/mm/numa.c - Multiple node support for SH machines |
| 3 | * |
| 4 | * Copyright (C) 2007 Paul Mundt |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file "COPYING" in the main directory of this archive |
| 8 | * for more details. |
| 9 | */ |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/bootmem.h> |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 12 | #include <linux/memblock.h> |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 13 | #include <linux/mm.h> |
| 14 | #include <linux/numa.h> |
| 15 | #include <linux/pfn.h> |
| 16 | #include <asm/sections.h> |
| 17 | |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 18 | struct pglist_data *node_data[MAX_NUMNODES] __read_mostly; |
| 19 | EXPORT_SYMBOL_GPL(node_data); |
| 20 | |
| 21 | /* |
| 22 | * On SH machines the conventional approach is to stash system RAM |
| 23 | * in node 0, and other memory blocks in to node 1 and up, ordered by |
| 24 | * latency. Each node's pgdat is node-local at the beginning of the node, |
| 25 | * immediately followed by the node mem map. |
| 26 | */ |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 27 | void __init setup_bootmem_node(int nid, unsigned long start, unsigned long end) |
| 28 | { |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 29 | unsigned long bootmap_pages; |
| 30 | unsigned long start_pfn, end_pfn; |
| 31 | unsigned long bootmem_paddr; |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 32 | |
| 33 | /* Don't allow bogus node assignment */ |
Roel Kluin | 9016332 | 2009-11-02 16:14:42 +0000 | [diff] [blame] | 34 | BUG_ON(nid > MAX_NUMNODES || nid <= 0); |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 35 | |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 36 | start_pfn = start >> PAGE_SHIFT; |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 37 | end_pfn = end >> PAGE_SHIFT; |
| 38 | |
Paul Mundt | 09e1172 | 2010-03-03 13:16:31 +0900 | [diff] [blame] | 39 | pmb_bolt_mapping((unsigned long)__va(start), start, end - start, |
| 40 | PAGE_KERNEL); |
| 41 | |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 42 | memblock_add(start, end - start); |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 43 | |
Magnus Damm | 0146ba7 | 2008-04-23 20:56:44 +0900 | [diff] [blame] | 44 | __add_active_range(nid, start_pfn, end_pfn); |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 45 | |
| 46 | /* Node-local pgdat */ |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 47 | NODE_DATA(nid) = __va(memblock_alloc_base(sizeof(struct pglist_data), |
Magnus Damm | b25b975 | 2009-12-07 14:16:07 +0000 | [diff] [blame] | 48 | SMP_CACHE_BYTES, end)); |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 49 | memset(NODE_DATA(nid), 0, sizeof(struct pglist_data)); |
| 50 | |
Johannes Weiner | b61bfa3 | 2008-07-23 21:26:55 -0700 | [diff] [blame] | 51 | NODE_DATA(nid)->bdata = &bootmem_node_data[nid]; |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 52 | NODE_DATA(nid)->node_start_pfn = start_pfn; |
| 53 | NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn; |
| 54 | |
| 55 | /* Node-local bootmap */ |
| 56 | bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn); |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 57 | bootmem_paddr = memblock_alloc_base(bootmap_pages << PAGE_SHIFT, |
Magnus Damm | b25b975 | 2009-12-07 14:16:07 +0000 | [diff] [blame] | 58 | PAGE_SIZE, end); |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 59 | init_bootmem_node(NODE_DATA(nid), bootmem_paddr >> PAGE_SHIFT, |
| 60 | start_pfn, end_pfn); |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 61 | |
| 62 | free_bootmem_with_active_regions(nid, end_pfn); |
| 63 | |
| 64 | /* Reserve the pgdat and bootmap space with the bootmem allocator */ |
| 65 | reserve_bootmem_node(NODE_DATA(nid), start_pfn << PAGE_SHIFT, |
Bernhard Walle | 72a7fe3 | 2008-02-07 00:15:17 -0800 | [diff] [blame] | 66 | sizeof(struct pglist_data), BOOTMEM_DEFAULT); |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 67 | reserve_bootmem_node(NODE_DATA(nid), bootmem_paddr, |
Bernhard Walle | 72a7fe3 | 2008-02-07 00:15:17 -0800 | [diff] [blame] | 68 | bootmap_pages << PAGE_SHIFT, BOOTMEM_DEFAULT); |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 69 | |
| 70 | /* It's up */ |
| 71 | node_set_online(nid); |
| 72 | |
| 73 | /* Kick sparsemem */ |
| 74 | sparse_memory_present_with_active_regions(nid); |
| 75 | } |