| 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> | 
|  | 12 | #include <linux/mm.h> | 
|  | 13 | #include <linux/numa.h> | 
|  | 14 | #include <linux/pfn.h> | 
|  | 15 | #include <asm/sections.h> | 
|  | 16 |  | 
| Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 17 | struct pglist_data *node_data[MAX_NUMNODES] __read_mostly; | 
|  | 18 | EXPORT_SYMBOL_GPL(node_data); | 
|  | 19 |  | 
|  | 20 | /* | 
|  | 21 | * On SH machines the conventional approach is to stash system RAM | 
|  | 22 | * in node 0, and other memory blocks in to node 1 and up, ordered by | 
|  | 23 | * latency. Each node's pgdat is node-local at the beginning of the node, | 
|  | 24 | * immediately followed by the node mem map. | 
|  | 25 | */ | 
|  | 26 | void __init setup_memory(void) | 
|  | 27 | { | 
|  | 28 | unsigned long free_pfn = PFN_UP(__pa(_end)); | 
|  | 29 |  | 
|  | 30 | /* | 
|  | 31 | * Node 0 sets up its pgdat at the first available pfn, | 
|  | 32 | * and bumps it up before setting up the bootmem allocator. | 
|  | 33 | */ | 
|  | 34 | NODE_DATA(0) = pfn_to_kaddr(free_pfn); | 
|  | 35 | memset(NODE_DATA(0), 0, sizeof(struct pglist_data)); | 
|  | 36 | free_pfn += PFN_UP(sizeof(struct pglist_data)); | 
| Johannes Weiner | b61bfa3 | 2008-07-23 21:26:55 -0700 | [diff] [blame] | 37 | NODE_DATA(0)->bdata = &bootmem_node_data[0]; | 
| Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 38 |  | 
|  | 39 | /* Set up node 0 */ | 
|  | 40 | setup_bootmem_allocator(free_pfn); | 
|  | 41 |  | 
|  | 42 | /* Give the platforms a chance to hook up their nodes */ | 
|  | 43 | plat_mem_setup(); | 
|  | 44 | } | 
|  | 45 |  | 
|  | 46 | void __init setup_bootmem_node(int nid, unsigned long start, unsigned long end) | 
|  | 47 | { | 
|  | 48 | unsigned long bootmap_pages, bootmap_start, bootmap_size; | 
|  | 49 | unsigned long start_pfn, free_pfn, end_pfn; | 
|  | 50 |  | 
|  | 51 | /* Don't allow bogus node assignment */ | 
|  | 52 | BUG_ON(nid > MAX_NUMNODES || nid == 0); | 
|  | 53 |  | 
|  | 54 | /* | 
|  | 55 | * The free pfn starts at the beginning of the range, and is | 
|  | 56 | * advanced as necessary for pgdat and node map allocations. | 
|  | 57 | */ | 
|  | 58 | free_pfn = start_pfn = start >> PAGE_SHIFT; | 
|  | 59 | end_pfn = end >> PAGE_SHIFT; | 
|  | 60 |  | 
| Magnus Damm | 0146ba7 | 2008-04-23 20:56:44 +0900 | [diff] [blame] | 61 | __add_active_range(nid, start_pfn, end_pfn); | 
| Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 62 |  | 
|  | 63 | /* Node-local pgdat */ | 
|  | 64 | NODE_DATA(nid) = pfn_to_kaddr(free_pfn); | 
|  | 65 | free_pfn += PFN_UP(sizeof(struct pglist_data)); | 
|  | 66 | memset(NODE_DATA(nid), 0, sizeof(struct pglist_data)); | 
|  | 67 |  | 
| Johannes Weiner | b61bfa3 | 2008-07-23 21:26:55 -0700 | [diff] [blame] | 68 | NODE_DATA(nid)->bdata = &bootmem_node_data[nid]; | 
| Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 69 | NODE_DATA(nid)->node_start_pfn = start_pfn; | 
|  | 70 | NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn; | 
|  | 71 |  | 
|  | 72 | /* Node-local bootmap */ | 
|  | 73 | bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn); | 
|  | 74 | bootmap_start = (unsigned long)pfn_to_kaddr(free_pfn); | 
|  | 75 | bootmap_size = init_bootmem_node(NODE_DATA(nid), free_pfn, start_pfn, | 
|  | 76 | end_pfn); | 
|  | 77 |  | 
|  | 78 | free_bootmem_with_active_regions(nid, end_pfn); | 
|  | 79 |  | 
|  | 80 | /* Reserve the pgdat and bootmap space with the bootmem allocator */ | 
|  | 81 | reserve_bootmem_node(NODE_DATA(nid), start_pfn << PAGE_SHIFT, | 
| Bernhard Walle | 72a7fe3 | 2008-02-07 00:15:17 -0800 | [diff] [blame] | 82 | sizeof(struct pglist_data), BOOTMEM_DEFAULT); | 
| Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 83 | reserve_bootmem_node(NODE_DATA(nid), free_pfn << PAGE_SHIFT, | 
| Bernhard Walle | 72a7fe3 | 2008-02-07 00:15:17 -0800 | [diff] [blame] | 84 | bootmap_pages << PAGE_SHIFT, BOOTMEM_DEFAULT); | 
| Paul Mundt | b241cb0 | 2007-06-06 17:52:19 +0900 | [diff] [blame] | 85 |  | 
|  | 86 | /* It's up */ | 
|  | 87 | node_set_online(nid); | 
|  | 88 |  | 
|  | 89 | /* Kick sparsemem */ | 
|  | 90 | sparse_memory_present_with_active_regions(nid); | 
|  | 91 | } |