Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/m32r/mm/init.c |
| 3 | * |
| 4 | * Copyright (c) 2001, 2002 Hitoshi Yamamoto |
| 5 | * |
| 6 | * Some code taken from sh version. |
| 7 | * Copyright (C) 1999 Niibe Yutaka |
| 8 | * Based on linux/arch/i386/mm/init.c: |
| 9 | * Copyright (C) 1995 Linus Torvalds |
| 10 | */ |
| 11 | |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/mm.h> |
| 15 | #include <linux/pagemap.h> |
| 16 | #include <linux/bootmem.h> |
| 17 | #include <linux/swap.h> |
| 18 | #include <linux/highmem.h> |
| 19 | #include <linux/bitops.h> |
| 20 | #include <linux/nodemask.h> |
Dave Hansen | 22a9835 | 2006-03-27 01:16:04 -0800 | [diff] [blame] | 21 | #include <linux/pfn.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/types.h> |
| 24 | #include <asm/processor.h> |
| 25 | #include <asm/page.h> |
| 26 | #include <asm/pgtable.h> |
| 27 | #include <asm/pgalloc.h> |
| 28 | #include <asm/mmu_context.h> |
| 29 | #include <asm/setup.h> |
| 30 | #include <asm/tlb.h> |
Jiang Liu | 8be6585 | 2013-04-29 15:06:40 -0700 | [diff] [blame] | 31 | #include <asm/sections.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | pgd_t swapper_pg_dir[1024]; |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | /* |
| 36 | * Cache of MMU context last used. |
| 37 | */ |
| 38 | #ifndef CONFIG_SMP |
| 39 | unsigned long mmu_context_cache_dat; |
| 40 | #else |
| 41 | unsigned long mmu_context_cache_dat[NR_CPUS]; |
| 42 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * function prototype |
| 46 | */ |
| 47 | void __init paging_init(void); |
| 48 | void __init mem_init(void); |
| 49 | void free_initmem(void); |
| 50 | #ifdef CONFIG_BLK_DEV_INITRD |
| 51 | void free_initrd_mem(unsigned long, unsigned long); |
| 52 | #endif |
| 53 | |
| 54 | /* It'd be good if these lines were in the standard header file. */ |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 55 | #define START_PFN(nid) (NODE_DATA(nid)->bdata->node_min_pfn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn) |
| 57 | |
| 58 | #ifndef CONFIG_DISCONTIGMEM |
Jiang Liu | a0e7b80 | 2013-07-03 15:03:59 -0700 | [diff] [blame] | 59 | void __init zone_sizes_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
Christoph Lameter | f06a968 | 2006-09-25 23:31:10 -0700 | [diff] [blame] | 61 | unsigned long zones_size[MAX_NR_ZONES] = {0, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | unsigned long max_dma; |
| 63 | unsigned long low; |
| 64 | unsigned long start_pfn; |
| 65 | |
| 66 | #ifdef CONFIG_MMU |
| 67 | start_pfn = START_PFN(0); |
| 68 | max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT; |
| 69 | low = MAX_LOW_PFN(0); |
| 70 | |
| 71 | if (low < max_dma){ |
| 72 | zones_size[ZONE_DMA] = low - start_pfn; |
| 73 | zones_size[ZONE_NORMAL] = 0; |
| 74 | } else { |
| 75 | zones_size[ZONE_DMA] = low - start_pfn; |
| 76 | zones_size[ZONE_NORMAL] = low - max_dma; |
| 77 | } |
| 78 | #else |
| 79 | zones_size[ZONE_DMA] = 0 >> PAGE_SHIFT; |
| 80 | zones_size[ZONE_NORMAL] = __MEMORY_SIZE >> PAGE_SHIFT; |
| 81 | start_pfn = __MEMORY_START >> PAGE_SHIFT; |
| 82 | #endif /* CONFIG_MMU */ |
| 83 | |
Johannes Weiner | 9109fb7 | 2008-07-23 21:27:20 -0700 | [diff] [blame] | 84 | free_area_init_node(0, zones_size, start_pfn, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | #else /* CONFIG_DISCONTIGMEM */ |
Jiang Liu | a0e7b80 | 2013-07-03 15:03:59 -0700 | [diff] [blame] | 87 | extern void zone_sizes_init(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #endif /* CONFIG_DISCONTIGMEM */ |
| 89 | |
| 90 | /*======================================================================* |
| 91 | * paging_init() : sets up the page tables |
| 92 | *======================================================================*/ |
| 93 | void __init paging_init(void) |
| 94 | { |
| 95 | #ifdef CONFIG_MMU |
| 96 | int i; |
| 97 | pgd_t *pg_dir; |
| 98 | |
| 99 | /* We don't need kernel mapping as hardware support that. */ |
| 100 | pg_dir = swapper_pg_dir; |
| 101 | |
| 102 | for (i = 0 ; i < USER_PTRS_PER_PGD * 2 ; i++) |
| 103 | pgd_val(pg_dir[i]) = 0; |
| 104 | #endif /* CONFIG_MMU */ |
Jiang Liu | a0e7b80 | 2013-07-03 15:03:59 -0700 | [diff] [blame] | 105 | zone_sizes_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /*======================================================================* |
| 109 | * mem_init() : |
| 110 | * orig : arch/sh/mm/init.c |
| 111 | *======================================================================*/ |
| 112 | void __init mem_init(void) |
| 113 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | #ifndef CONFIG_MMU |
| 115 | extern unsigned long memory_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | high_memory = (void *)(memory_end & PAGE_MASK); |
Jiang Liu | c5c009f | 2013-07-03 15:04:26 -0700 | [diff] [blame] | 118 | #else |
| 119 | high_memory = (void *)__va(PFN_PHYS(MAX_LOW_PFN(0))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | #endif /* CONFIG_MMU */ |
| 121 | |
| 122 | /* clear the zero-page */ |
| 123 | memset(empty_zero_page, 0, PAGE_SIZE); |
| 124 | |
Jiang Liu | c5c009f | 2013-07-03 15:04:26 -0700 | [diff] [blame] | 125 | set_max_mapnr(get_num_physpages()); |
| 126 | free_all_bootmem(); |
Jiang Liu | a0e7b80 | 2013-07-03 15:03:59 -0700 | [diff] [blame] | 127 | mem_init_print_info(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /*======================================================================* |
| 131 | * free_initmem() : |
| 132 | * orig : arch/sh/mm/init.c |
| 133 | *======================================================================*/ |
| 134 | void free_initmem(void) |
| 135 | { |
Jiang Liu | dbe67df | 2013-07-03 15:02:51 -0700 | [diff] [blame] | 136 | free_initmem_default(-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | #ifdef CONFIG_BLK_DEV_INITRD |
| 140 | /*======================================================================* |
| 141 | * free_initrd_mem() : |
| 142 | * orig : arch/sh/mm/init.c |
| 143 | *======================================================================*/ |
| 144 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 145 | { |
Jiang Liu | dbe67df | 2013-07-03 15:02:51 -0700 | [diff] [blame] | 146 | free_reserved_area((void *)start, (void *)end, -1, "initrd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | #endif |