2 * arch/sh/mm/numa.c - Multiple node support for SH machines
4 * Copyright (C) 2007 Paul Mundt
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
10 #include <linux/module.h>
11 #include <linux/bootmem.h>
12 #include <linux/lmb.h>
14 #include <linux/numa.h>
15 #include <linux/pfn.h>
16 #include <asm/sections.h>
18 struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
19 EXPORT_SYMBOL_GPL(node_data);
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.
27 void __init setup_memory(void)
29 unsigned long free_pfn = PFN_UP(__pa(_end));
30 u64 base = min_low_pfn << PAGE_SHIFT;
31 u64 size = (max_low_pfn << PAGE_SHIFT) - base;
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));
41 * Reserve physical pages below CONFIG_ZERO_PAGE_OFFSET.
43 if (CONFIG_ZERO_PAGE_OFFSET != 0)
44 lmb_reserve(__MEMORY_START, CONFIG_ZERO_PAGE_OFFSET);
50 * Node 0 sets up its pgdat at the first available pfn,
51 * and bumps it up before setting up the bootmem allocator.
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));
56 NODE_DATA(0)->bdata = &bootmem_node_data[0];
59 setup_bootmem_allocator(free_pfn);
61 /* Give the platforms a chance to hook up their nodes */
65 void __init setup_bootmem_node(int nid, unsigned long start, unsigned long end)
67 unsigned long bootmap_pages;
68 unsigned long start_pfn, end_pfn;
69 unsigned long bootmem_paddr;
71 /* Don't allow bogus node assignment */
72 BUG_ON(nid > MAX_NUMNODES || nid <= 0);
74 start_pfn = start >> PAGE_SHIFT;
75 end_pfn = end >> PAGE_SHIFT;
77 pmb_bolt_mapping((unsigned long)__va(start), start, end - start,
80 lmb_add(start, end - start);
82 __add_active_range(nid, start_pfn, end_pfn);
84 /* Node-local pgdat */
85 NODE_DATA(nid) = __va(lmb_alloc_base(sizeof(struct pglist_data),
86 SMP_CACHE_BYTES, end));
87 memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
89 NODE_DATA(nid)->bdata = &bootmem_node_data[nid];
90 NODE_DATA(nid)->node_start_pfn = start_pfn;
91 NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
93 /* Node-local bootmap */
94 bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
95 bootmem_paddr = lmb_alloc_base(bootmap_pages << PAGE_SHIFT,
97 init_bootmem_node(NODE_DATA(nid), bootmem_paddr >> PAGE_SHIFT,
100 free_bootmem_with_active_regions(nid, end_pfn);
102 /* Reserve the pgdat and bootmap space with the bootmem allocator */
103 reserve_bootmem_node(NODE_DATA(nid), start_pfn << PAGE_SHIFT,
104 sizeof(struct pglist_data), BOOTMEM_DEFAULT);
105 reserve_bootmem_node(NODE_DATA(nid), bootmem_paddr,
106 bootmap_pages << PAGE_SHIFT, BOOTMEM_DEFAULT);
109 node_set_online(nid);
112 sparse_memory_present_with_active_regions(nid);