rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * linux/arch/m32r/mm/discontig.c |
| 4 | * |
| 5 | * Discontig memory support |
| 6 | * |
| 7 | * Copyright (c) 2003 Hitoshi Yamamoto |
| 8 | */ |
| 9 | |
| 10 | #include <linux/mm.h> |
| 11 | #include <linux/bootmem.h> |
| 12 | #include <linux/mmzone.h> |
| 13 | #include <linux/initrd.h> |
| 14 | #include <linux/nodemask.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/pfn.h> |
| 17 | |
| 18 | #include <asm/setup.h> |
| 19 | |
| 20 | extern char _end[]; |
| 21 | |
| 22 | struct pglist_data *node_data[MAX_NUMNODES]; |
| 23 | EXPORT_SYMBOL(node_data); |
| 24 | |
| 25 | pg_data_t m32r_node_data[MAX_NUMNODES]; |
| 26 | |
| 27 | /* Memory profile */ |
| 28 | typedef struct { |
| 29 | unsigned long start_pfn; |
| 30 | unsigned long pages; |
| 31 | unsigned long holes; |
| 32 | unsigned long free_pfn; |
| 33 | } mem_prof_t; |
| 34 | static mem_prof_t mem_prof[MAX_NUMNODES]; |
| 35 | |
| 36 | extern unsigned long memory_start; |
| 37 | extern unsigned long memory_end; |
| 38 | |
| 39 | static void __init mem_prof_init(void) |
| 40 | { |
| 41 | unsigned long start_pfn, holes, free_pfn; |
| 42 | const unsigned long zone_alignment = 1UL << (MAX_ORDER - 1); |
| 43 | unsigned long ul; |
| 44 | mem_prof_t *mp; |
| 45 | |
| 46 | /* Node#0 SDRAM */ |
| 47 | mp = &mem_prof[0]; |
| 48 | mp->start_pfn = PFN_UP(CONFIG_MEMORY_START); |
| 49 | mp->pages = PFN_DOWN(memory_end - memory_start); |
| 50 | mp->holes = 0; |
| 51 | mp->free_pfn = PFN_UP(__pa(_end)); |
| 52 | |
| 53 | /* Node#1 internal SRAM */ |
| 54 | mp = &mem_prof[1]; |
| 55 | start_pfn = free_pfn = PFN_UP(CONFIG_IRAM_START); |
| 56 | holes = 0; |
| 57 | if (start_pfn & (zone_alignment - 1)) { |
| 58 | ul = zone_alignment; |
| 59 | while (start_pfn >= ul) |
| 60 | ul += zone_alignment; |
| 61 | |
| 62 | start_pfn = ul - zone_alignment; |
| 63 | holes = free_pfn - start_pfn; |
| 64 | } |
| 65 | |
| 66 | mp->start_pfn = start_pfn; |
| 67 | mp->pages = PFN_DOWN(CONFIG_IRAM_SIZE) + holes; |
| 68 | mp->holes = holes; |
| 69 | mp->free_pfn = PFN_UP(CONFIG_IRAM_START); |
| 70 | } |
| 71 | |
| 72 | unsigned long __init setup_memory(void) |
| 73 | { |
| 74 | unsigned long bootmap_size; |
| 75 | unsigned long min_pfn; |
| 76 | int nid; |
| 77 | mem_prof_t *mp; |
| 78 | |
| 79 | max_low_pfn = 0; |
| 80 | min_low_pfn = -1; |
| 81 | |
| 82 | mem_prof_init(); |
| 83 | |
| 84 | for_each_online_node(nid) { |
| 85 | mp = &mem_prof[nid]; |
| 86 | NODE_DATA(nid)=(pg_data_t *)&m32r_node_data[nid]; |
| 87 | NODE_DATA(nid)->bdata = &bootmem_node_data[nid]; |
| 88 | min_pfn = mp->start_pfn; |
| 89 | max_pfn = mp->start_pfn + mp->pages; |
| 90 | bootmap_size = init_bootmem_node(NODE_DATA(nid), mp->free_pfn, |
| 91 | mp->start_pfn, max_pfn); |
| 92 | |
| 93 | free_bootmem_node(NODE_DATA(nid), PFN_PHYS(mp->start_pfn), |
| 94 | PFN_PHYS(mp->pages)); |
| 95 | |
| 96 | reserve_bootmem_node(NODE_DATA(nid), PFN_PHYS(mp->start_pfn), |
| 97 | PFN_PHYS(mp->free_pfn - mp->start_pfn) + bootmap_size, |
| 98 | BOOTMEM_DEFAULT); |
| 99 | |
| 100 | if (max_low_pfn < max_pfn) |
| 101 | max_low_pfn = max_pfn; |
| 102 | |
| 103 | if (min_low_pfn > min_pfn) |
| 104 | min_low_pfn = min_pfn; |
| 105 | } |
| 106 | |
| 107 | #ifdef CONFIG_BLK_DEV_INITRD |
| 108 | if (LOADER_TYPE && INITRD_START) { |
| 109 | if (INITRD_START + INITRD_SIZE <= PFN_PHYS(max_low_pfn)) { |
| 110 | reserve_bootmem_node(NODE_DATA(0), INITRD_START, |
| 111 | INITRD_SIZE, BOOTMEM_DEFAULT); |
| 112 | initrd_start = INITRD_START + PAGE_OFFSET; |
| 113 | initrd_end = initrd_start + INITRD_SIZE; |
| 114 | printk("initrd:start[%08lx],size[%08lx]\n", |
| 115 | initrd_start, INITRD_SIZE); |
| 116 | } else { |
| 117 | printk("initrd extends beyond end of memory " |
| 118 | "(0x%08lx > 0x%08llx)\ndisabling initrd\n", |
| 119 | INITRD_START + INITRD_SIZE, |
| 120 | (unsigned long long)PFN_PHYS(max_low_pfn)); |
| 121 | |
| 122 | initrd_start = 0; |
| 123 | } |
| 124 | } |
| 125 | #endif /* CONFIG_BLK_DEV_INITRD */ |
| 126 | |
| 127 | return max_low_pfn; |
| 128 | } |
| 129 | |
| 130 | #define START_PFN(nid) (NODE_DATA(nid)->bdata->node_min_pfn) |
| 131 | #define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn) |
| 132 | |
| 133 | void __init zone_sizes_init(void) |
| 134 | { |
| 135 | unsigned long zones_size[MAX_NR_ZONES], zholes_size[MAX_NR_ZONES]; |
| 136 | unsigned long low, start_pfn; |
| 137 | int nid, i; |
| 138 | mem_prof_t *mp; |
| 139 | |
| 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 | |
| 151 | node_set_state(nid, N_NORMAL_MEMORY); |
| 152 | free_area_init_node(nid, zones_size, start_pfn, zholes_size); |
| 153 | } |
| 154 | |
| 155 | /* |
| 156 | * For test |
| 157 | * Use all area of internal RAM. |
| 158 | * see __alloc_pages() |
| 159 | */ |
| 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; |
| 163 | } |