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> |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 12 | #include <linux/lmb.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 | */ |
| 27 | void __init setup_memory(void) |
| 28 | { |
| 29 | unsigned long free_pfn = PFN_UP(__pa(_end)); |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 30 | u64 base = min_low_pfn << PAGE_SHIFT; |
Magnus Damm | f3a4c00 | 2009-12-07 14:11:59 +0000 | [diff] [blame] | 31 | u64 size = (max_low_pfn << PAGE_SHIFT) - base; |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 32 | |
| 33 | lmb_add(base, size); |
| 34 | |
| 35 | /* Reserve the LMB regions used by the kernel, initrd, etc.. */ |
| 36 | lmb_reserve(__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET, |
| 37 | (PFN_PHYS(free_pfn) + PAGE_SIZE - 1) - |
| 38 | (__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET)); |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 39 | |
| 40 | /* |
Magnus Damm | b25b975 | 2009-12-07 14:16:07 +0000 | [diff] [blame^] | 41 | * Reserve physical pages below CONFIG_ZERO_PAGE_OFFSET. |
| 42 | */ |
| 43 | if (CONFIG_ZERO_PAGE_OFFSET != 0) |
| 44 | lmb_reserve(__MEMORY_START, CONFIG_ZERO_PAGE_OFFSET); |
| 45 | |
| 46 | lmb_analyze(); |
| 47 | lmb_dump_all(); |
| 48 | |
| 49 | /* |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 50 | * Node 0 sets up its pgdat at the first available pfn, |
| 51 | * and bumps it up before setting up the bootmem allocator. |
| 52 | */ |
| 53 | NODE_DATA(0) = pfn_to_kaddr(free_pfn); |
| 54 | memset(NODE_DATA(0), 0, sizeof(struct pglist_data)); |
| 55 | free_pfn += PFN_UP(sizeof(struct pglist_data)); |
Johannes Weiner | b61bfa3 | 2008-07-23 21:26:55 -0700 | [diff] [blame] | 56 | NODE_DATA(0)->bdata = &bootmem_node_data[0]; |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 57 | |
| 58 | /* Set up node 0 */ |
| 59 | setup_bootmem_allocator(free_pfn); |
| 60 | |
| 61 | /* Give the platforms a chance to hook up their nodes */ |
| 62 | plat_mem_setup(); |
| 63 | } |
| 64 | |
| 65 | void __init setup_bootmem_node(int nid, unsigned long start, unsigned long end) |
| 66 | { |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 67 | unsigned long bootmap_pages; |
| 68 | unsigned long start_pfn, end_pfn; |
| 69 | unsigned long bootmem_paddr; |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 70 | |
| 71 | /* Don't allow bogus node assignment */ |
Roel Kluin | 9016332 | 2009-11-02 16:14:42 +0000 | [diff] [blame] | 72 | BUG_ON(nid > MAX_NUMNODES || nid <= 0); |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 73 | |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 74 | start_pfn = start >> PAGE_SHIFT; |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 75 | end_pfn = end >> PAGE_SHIFT; |
| 76 | |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 77 | lmb_add(start, end - start); |
| 78 | |
Magnus Damm | 0146ba7 | 2008-04-23 20:56:44 +0900 | [diff] [blame] | 79 | __add_active_range(nid, start_pfn, end_pfn); |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 80 | |
| 81 | /* Node-local pgdat */ |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 82 | NODE_DATA(nid) = __va(lmb_alloc_base(sizeof(struct pglist_data), |
Magnus Damm | b25b975 | 2009-12-07 14:16:07 +0000 | [diff] [blame^] | 83 | SMP_CACHE_BYTES, end)); |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 84 | memset(NODE_DATA(nid), 0, sizeof(struct pglist_data)); |
| 85 | |
Johannes Weiner | b61bfa3 | 2008-07-23 21:26:55 -0700 | [diff] [blame] | 86 | NODE_DATA(nid)->bdata = &bootmem_node_data[nid]; |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 87 | NODE_DATA(nid)->node_start_pfn = start_pfn; |
| 88 | NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn; |
| 89 | |
| 90 | /* Node-local bootmap */ |
| 91 | bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn); |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 92 | bootmem_paddr = lmb_alloc_base(bootmap_pages << PAGE_SHIFT, |
Magnus Damm | b25b975 | 2009-12-07 14:16:07 +0000 | [diff] [blame^] | 93 | PAGE_SIZE, end); |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 94 | init_bootmem_node(NODE_DATA(nid), bootmem_paddr >> PAGE_SHIFT, |
| 95 | start_pfn, end_pfn); |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 96 | |
| 97 | free_bootmem_with_active_regions(nid, end_pfn); |
| 98 | |
| 99 | /* Reserve the pgdat and bootmap space with the bootmem allocator */ |
| 100 | reserve_bootmem_node(NODE_DATA(nid), start_pfn << PAGE_SHIFT, |
Bernhard Walle | 72a7fe3 | 2008-02-07 00:15:17 -0800 | [diff] [blame] | 101 | sizeof(struct pglist_data), BOOTMEM_DEFAULT); |
Matt Fleming | 5084f61 | 2009-07-03 23:34:51 +0100 | [diff] [blame] | 102 | reserve_bootmem_node(NODE_DATA(nid), bootmem_paddr, |
Bernhard Walle | 72a7fe3 | 2008-02-07 00:15:17 -0800 | [diff] [blame] | 103 | bootmap_pages << PAGE_SHIFT, BOOTMEM_DEFAULT); |
Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 104 | |
| 105 | /* It's up */ |
| 106 | node_set_online(nid); |
| 107 | |
| 108 | /* Kick sparsemem */ |
| 109 | sparse_memory_present_with_active_regions(nid); |
| 110 | } |