Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/m32r/mm/discontig.c |
| 3 | * |
| 4 | * Discontig memory support |
| 5 | * |
| 6 | * Copyright (c) 2003 Hitoshi Yamamoto |
| 7 | */ |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/mm.h> |
| 10 | #include <linux/bootmem.h> |
| 11 | #include <linux/mmzone.h> |
| 12 | #include <linux/initrd.h> |
| 13 | #include <linux/nodemask.h> |
Al Viro | eaaece2 | 2005-08-23 22:47:57 +0100 | [diff] [blame] | 14 | #include <linux/module.h> |
Dave Hansen | 22a9835 | 2006-03-27 01:16:04 -0800 | [diff] [blame] | 15 | #include <linux/pfn.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #include <asm/setup.h> |
| 18 | |
| 19 | extern char _end[]; |
| 20 | |
| 21 | struct pglist_data *node_data[MAX_NUMNODES]; |
Al Viro | eaaece2 | 2005-08-23 22:47:57 +0100 | [diff] [blame] | 22 | EXPORT_SYMBOL(node_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | pg_data_t m32r_node_data[MAX_NUMNODES]; |
| 25 | |
| 26 | /* Memory profile */ |
| 27 | typedef struct { |
| 28 | unsigned long start_pfn; |
| 29 | unsigned long pages; |
| 30 | unsigned long holes; |
| 31 | unsigned long free_pfn; |
| 32 | } mem_prof_t; |
| 33 | static mem_prof_t mem_prof[MAX_NUMNODES]; |
| 34 | |
Hirokazu Takata | 6b6fabc | 2009-09-23 21:37:06 +0900 | [diff] [blame] | 35 | extern unsigned long memory_start; |
| 36 | extern unsigned long memory_end; |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | static void __init mem_prof_init(void) |
| 39 | { |
| 40 | unsigned long start_pfn, holes, free_pfn; |
| 41 | const unsigned long zone_alignment = 1UL << (MAX_ORDER - 1); |
| 42 | unsigned long ul; |
| 43 | mem_prof_t *mp; |
| 44 | |
| 45 | /* Node#0 SDRAM */ |
| 46 | mp = &mem_prof[0]; |
| 47 | mp->start_pfn = PFN_UP(CONFIG_MEMORY_START); |
Hirokazu Takata | 6b6fabc | 2009-09-23 21:37:06 +0900 | [diff] [blame] | 48 | mp->pages = PFN_DOWN(memory_end - memory_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | mp->holes = 0; |
| 50 | mp->free_pfn = PFN_UP(__pa(_end)); |
| 51 | |
| 52 | /* Node#1 internal SRAM */ |
| 53 | mp = &mem_prof[1]; |
| 54 | start_pfn = free_pfn = PFN_UP(CONFIG_IRAM_START); |
| 55 | holes = 0; |
| 56 | if (start_pfn & (zone_alignment - 1)) { |
| 57 | ul = zone_alignment; |
| 58 | while (start_pfn >= ul) |
| 59 | ul += zone_alignment; |
| 60 | |
| 61 | start_pfn = ul - zone_alignment; |
| 62 | holes = free_pfn - start_pfn; |
| 63 | } |
| 64 | |
| 65 | mp->start_pfn = start_pfn; |
| 66 | mp->pages = PFN_DOWN(CONFIG_IRAM_SIZE) + holes; |
| 67 | mp->holes = holes; |
| 68 | mp->free_pfn = PFN_UP(CONFIG_IRAM_START); |
| 69 | } |
| 70 | |
| 71 | unsigned long __init setup_memory(void) |
| 72 | { |
| 73 | unsigned long bootmap_size; |
| 74 | unsigned long min_pfn; |
| 75 | int nid; |
| 76 | mem_prof_t *mp; |
| 77 | |
| 78 | max_low_pfn = 0; |
| 79 | min_low_pfn = -1; |
| 80 | |
| 81 | mem_prof_init(); |
| 82 | |
| 83 | for_each_online_node(nid) { |
| 84 | mp = &mem_prof[nid]; |
| 85 | NODE_DATA(nid)=(pg_data_t *)&m32r_node_data[nid]; |
Johannes Weiner | b61bfa3 | 2008-07-23 21:26:55 -0700 | [diff] [blame] | 86 | NODE_DATA(nid)->bdata = &bootmem_node_data[nid]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | min_pfn = mp->start_pfn; |
| 88 | max_pfn = mp->start_pfn + mp->pages; |
| 89 | bootmap_size = init_bootmem_node(NODE_DATA(nid), mp->free_pfn, |
| 90 | mp->start_pfn, max_pfn); |
| 91 | |
| 92 | free_bootmem_node(NODE_DATA(nid), PFN_PHYS(mp->start_pfn), |
| 93 | PFN_PHYS(mp->pages)); |
| 94 | |
| 95 | reserve_bootmem_node(NODE_DATA(nid), PFN_PHYS(mp->start_pfn), |
Bernhard Walle | 72a7fe3 | 2008-02-07 00:15:17 -0800 | [diff] [blame] | 96 | PFN_PHYS(mp->free_pfn - mp->start_pfn) + bootmap_size, |
| 97 | BOOTMEM_DEFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | if (max_low_pfn < max_pfn) |
| 100 | max_low_pfn = max_pfn; |
| 101 | |
| 102 | if (min_low_pfn > min_pfn) |
| 103 | min_low_pfn = min_pfn; |
| 104 | } |
| 105 | |
| 106 | #ifdef CONFIG_BLK_DEV_INITRD |
| 107 | if (LOADER_TYPE && INITRD_START) { |
| 108 | if (INITRD_START + INITRD_SIZE <= PFN_PHYS(max_low_pfn)) { |
| 109 | reserve_bootmem_node(NODE_DATA(0), INITRD_START, |
Bernhard Walle | 72a7fe3 | 2008-02-07 00:15:17 -0800 | [diff] [blame] | 110 | INITRD_SIZE, BOOTMEM_DEFAULT); |
Henry Nestler | 19e5d9c | 2006-12-06 20:37:45 -0800 | [diff] [blame] | 111 | initrd_start = INITRD_START + PAGE_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | initrd_end = initrd_start + INITRD_SIZE; |
| 113 | printk("initrd:start[%08lx],size[%08lx]\n", |
| 114 | initrd_start, INITRD_SIZE); |
| 115 | } else { |
| 116 | printk("initrd extends beyond end of memory " |
Jeremy Fitzhardinge | 947d049 | 2008-09-11 01:31:48 -0700 | [diff] [blame] | 117 | "(0x%08lx > 0x%08llx)\ndisabling initrd\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | INITRD_START + INITRD_SIZE, |
Jeremy Fitzhardinge | 947d049 | 2008-09-11 01:31:48 -0700 | [diff] [blame] | 119 | (unsigned long long)PFN_PHYS(max_low_pfn)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | initrd_start = 0; |
| 122 | } |
| 123 | } |
| 124 | #endif /* CONFIG_BLK_DEV_INITRD */ |
| 125 | |
| 126 | return max_low_pfn; |
| 127 | } |
| 128 | |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 129 | #define START_PFN(nid) (NODE_DATA(nid)->bdata->node_min_pfn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | #define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn) |
| 131 | |
| 132 | unsigned long __init zone_sizes_init(void) |
| 133 | { |
| 134 | unsigned long zones_size[MAX_NR_ZONES], zholes_size[MAX_NR_ZONES]; |
| 135 | unsigned long low, start_pfn; |
| 136 | unsigned long holes = 0; |
| 137 | int nid, i; |
| 138 | mem_prof_t *mp; |
| 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | for_each_online_node(nid) { |
| 141 | mp = &mem_prof[nid]; |
| 142 | for (i = 0 ; i < MAX_NR_ZONES ; i++) { |
| 143 | zones_size[i] = 0; |
| 144 | zholes_size[i] = 0; |
| 145 | } |
| 146 | start_pfn = START_PFN(nid); |
| 147 | low = MAX_LOW_PFN(nid); |
| 148 | zones_size[ZONE_DMA] = low - start_pfn; |
| 149 | zholes_size[ZONE_DMA] = mp->holes; |
| 150 | holes += zholes_size[ZONE_DMA]; |
| 151 | |
Johannes Weiner | 9109fb7 | 2008-07-23 21:27:20 -0700 | [diff] [blame] | 152 | free_area_init_node(nid, zones_size, start_pfn, zholes_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /* |
| 156 | * For test |
| 157 | * Use all area of internal RAM. |
| 158 | * see __alloc_pages() |
| 159 | */ |
Mel Gorman | 4185896 | 2009-06-16 15:32:12 -0700 | [diff] [blame] | 160 | NODE_DATA(1)->node_zones->watermark[WMARK_MIN] = 0; |
| 161 | NODE_DATA(1)->node_zones->watermark[WMARK_LOW] = 0; |
| 162 | NODE_DATA(1)->node_zones->watermark[WMARK_HIGH] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
| 164 | return holes; |
| 165 | } |