Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/s390/mm/init.c |
| 3 | * |
| 4 | * S390 version |
| 5 | * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 6 | * Author(s): Hartmut Penner (hp@de.ibm.com) |
| 7 | * |
| 8 | * Derived from "arch/i386/mm/init.c" |
| 9 | * Copyright (C) 1995 Linus Torvalds |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/signal.h> |
| 13 | #include <linux/sched.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/string.h> |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/ptrace.h> |
| 19 | #include <linux/mman.h> |
| 20 | #include <linux/mm.h> |
| 21 | #include <linux/swap.h> |
| 22 | #include <linux/smp.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/pagemap.h> |
| 25 | #include <linux/bootmem.h> |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame] | 26 | #include <linux/pfn.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | #include <asm/processor.h> |
| 29 | #include <asm/system.h> |
| 30 | #include <asm/uaccess.h> |
| 31 | #include <asm/pgtable.h> |
| 32 | #include <asm/pgalloc.h> |
| 33 | #include <asm/dma.h> |
| 34 | #include <asm/lowcore.h> |
| 35 | #include <asm/tlb.h> |
| 36 | #include <asm/tlbflush.h> |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame] | 37 | #include <asm/sections.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); |
| 40 | |
| 41 | pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__((__aligned__(PAGE_SIZE))); |
| 42 | char empty_zero_page[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE))); |
| 43 | |
| 44 | void diag10(unsigned long addr) |
| 45 | { |
| 46 | if (addr >= 0x7ff00000) |
| 47 | return; |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame^] | 48 | asm volatile( |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 49 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame^] | 50 | " sam31\n" |
| 51 | " diag %0,%0,0x10\n" |
| 52 | "0: sam64\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #else |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame^] | 54 | " diag %0,%0,0x10\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | "0:\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #endif |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame^] | 57 | EX_TABLE(0b,0b) |
| 58 | : : "a" (addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void show_mem(void) |
| 62 | { |
| 63 | int i, total = 0, reserved = 0; |
| 64 | int shared = 0, cached = 0; |
| 65 | |
| 66 | printk("Mem-info:\n"); |
| 67 | show_free_areas(); |
| 68 | printk("Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10)); |
| 69 | i = max_mapnr; |
| 70 | while (i-- > 0) { |
| 71 | total++; |
| 72 | if (PageReserved(mem_map+i)) |
| 73 | reserved++; |
| 74 | else if (PageSwapCache(mem_map+i)) |
| 75 | cached++; |
| 76 | else if (page_count(mem_map+i)) |
| 77 | shared += page_count(mem_map+i) - 1; |
| 78 | } |
| 79 | printk("%d pages of RAM\n",total); |
| 80 | printk("%d reserved pages\n",reserved); |
| 81 | printk("%d pages shared\n",shared); |
| 82 | printk("%d pages swap cached\n",cached); |
| 83 | } |
| 84 | |
Heiko Carstens | c9e3735 | 2005-05-01 08:58:57 -0700 | [diff] [blame] | 85 | extern unsigned long __initdata zholes_size[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* |
| 87 | * paging_init() sets up the page tables |
| 88 | */ |
| 89 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 90 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | void __init paging_init(void) |
| 92 | { |
| 93 | pgd_t * pg_dir; |
| 94 | pte_t * pg_table; |
| 95 | pte_t pte; |
| 96 | int i; |
| 97 | unsigned long tmp; |
| 98 | unsigned long pfn = 0; |
| 99 | unsigned long pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | _KERNSEG_TABLE; |
| 100 | static const int ssm_mask = 0x04000000L; |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame] | 101 | unsigned long ro_start_pfn, ro_end_pfn; |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 102 | unsigned long zones_size[MAX_NR_ZONES]; |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame] | 103 | |
| 104 | ro_start_pfn = PFN_DOWN((unsigned long)&__start_rodata); |
| 105 | ro_end_pfn = PFN_UP((unsigned long)&__end_rodata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 107 | memset(zones_size, 0, sizeof(zones_size)); |
| 108 | zones_size[ZONE_DMA] = max_low_pfn; |
| 109 | free_area_init_node(0, &contig_page_data, zones_size, |
| 110 | __pa(PAGE_OFFSET) >> PAGE_SHIFT, |
| 111 | zholes_size); |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /* unmap whole virtual address space */ |
| 114 | |
| 115 | pg_dir = swapper_pg_dir; |
| 116 | |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 117 | for (i = 0; i < PTRS_PER_PGD; i++) |
| 118 | pmd_clear((pmd_t *) pg_dir++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * map whole physical memory to virtual memory (identity mapping) |
| 122 | */ |
| 123 | |
| 124 | pg_dir = swapper_pg_dir; |
| 125 | |
| 126 | while (pfn < max_low_pfn) { |
| 127 | /* |
| 128 | * pg_table is physical at this point |
| 129 | */ |
Heiko Carstens | 3e03a2f | 2006-08-16 13:49:37 +0200 | [diff] [blame] | 130 | pg_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 132 | pmd_populate_kernel(&init_mm, (pmd_t *) pg_dir, pg_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | pg_dir++; |
| 134 | |
| 135 | for (tmp = 0 ; tmp < PTRS_PER_PTE ; tmp++,pg_table++) { |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame] | 136 | if (pfn >= ro_start_pfn && pfn < ro_end_pfn) |
| 137 | pte = pfn_pte(pfn, __pgprot(_PAGE_RO)); |
| 138 | else |
| 139 | pte = pfn_pte(pfn, PAGE_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | if (pfn >= max_low_pfn) |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 141 | pte_val(pte) = _PAGE_TYPE_EMPTY; |
| 142 | set_pte(pg_table, pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | pfn++; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | S390_lowcore.kernel_asce = pgdir_k; |
| 148 | |
| 149 | /* enable virtual mapping in kernel mode */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame^] | 150 | __ctl_load(pgdir_k, 1, 1); |
| 151 | __ctl_load(pgdir_k, 7, 7); |
| 152 | __ctl_load(pgdir_k, 13, 13); |
| 153 | __raw_local_irq_ssm(ssm_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | local_flush_tlb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | return; |
| 157 | } |
| 158 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 159 | #else /* CONFIG_64BIT */ |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame] | 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | void __init paging_init(void) |
| 162 | { |
| 163 | pgd_t * pg_dir; |
| 164 | pmd_t * pm_dir; |
| 165 | pte_t * pt_dir; |
| 166 | pte_t pte; |
| 167 | int i,j,k; |
| 168 | unsigned long pfn = 0; |
| 169 | unsigned long pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | |
| 170 | _KERN_REGION_TABLE; |
| 171 | static const int ssm_mask = 0x04000000L; |
Heiko Carstens | c9e3735 | 2005-05-01 08:58:57 -0700 | [diff] [blame] | 172 | unsigned long zones_size[MAX_NR_ZONES]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | unsigned long dma_pfn, high_pfn; |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame] | 174 | unsigned long ro_start_pfn, ro_end_pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Heiko Carstens | c9e3735 | 2005-05-01 08:58:57 -0700 | [diff] [blame] | 176 | memset(zones_size, 0, sizeof(zones_size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT; |
| 178 | high_pfn = max_low_pfn; |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame] | 179 | ro_start_pfn = PFN_DOWN((unsigned long)&__start_rodata); |
| 180 | ro_end_pfn = PFN_UP((unsigned long)&__end_rodata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | if (dma_pfn > high_pfn) |
| 183 | zones_size[ZONE_DMA] = high_pfn; |
| 184 | else { |
| 185 | zones_size[ZONE_DMA] = dma_pfn; |
| 186 | zones_size[ZONE_NORMAL] = high_pfn - dma_pfn; |
| 187 | } |
| 188 | |
| 189 | /* Initialize mem_map[]. */ |
Heiko Carstens | c9e3735 | 2005-05-01 08:58:57 -0700 | [diff] [blame] | 190 | free_area_init_node(0, &contig_page_data, zones_size, |
| 191 | __pa(PAGE_OFFSET) >> PAGE_SHIFT, zholes_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | /* |
| 194 | * map whole physical memory to virtual memory (identity mapping) |
| 195 | */ |
| 196 | |
| 197 | pg_dir = swapper_pg_dir; |
| 198 | |
| 199 | for (i = 0 ; i < PTRS_PER_PGD ; i++,pg_dir++) { |
| 200 | |
| 201 | if (pfn >= max_low_pfn) { |
| 202 | pgd_clear(pg_dir); |
| 203 | continue; |
| 204 | } |
| 205 | |
Heiko Carstens | 3e03a2f | 2006-08-16 13:49:37 +0200 | [diff] [blame] | 206 | pm_dir = (pmd_t *) alloc_bootmem_pages(PAGE_SIZE * 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | pgd_populate(&init_mm, pg_dir, pm_dir); |
| 208 | |
| 209 | for (j = 0 ; j < PTRS_PER_PMD ; j++,pm_dir++) { |
| 210 | if (pfn >= max_low_pfn) { |
| 211 | pmd_clear(pm_dir); |
| 212 | continue; |
| 213 | } |
| 214 | |
Heiko Carstens | 3e03a2f | 2006-08-16 13:49:37 +0200 | [diff] [blame] | 215 | pt_dir = (pte_t *) alloc_bootmem_pages(PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | pmd_populate_kernel(&init_mm, pm_dir, pt_dir); |
| 217 | |
| 218 | for (k = 0 ; k < PTRS_PER_PTE ; k++,pt_dir++) { |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame] | 219 | if (pfn >= ro_start_pfn && pfn < ro_end_pfn) |
| 220 | pte = pfn_pte(pfn, __pgprot(_PAGE_RO)); |
| 221 | else |
| 222 | pte = pfn_pte(pfn, PAGE_KERNEL); |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 223 | if (pfn >= max_low_pfn) |
| 224 | pte_val(pte) = _PAGE_TYPE_EMPTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | set_pte(pt_dir, pte); |
| 226 | pfn++; |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | S390_lowcore.kernel_asce = pgdir_k; |
| 232 | |
| 233 | /* enable virtual mapping in kernel mode */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame^] | 234 | __ctl_load(pgdir_k, 1, 1); |
| 235 | __ctl_load(pgdir_k, 7, 7); |
| 236 | __ctl_load(pgdir_k, 13, 13); |
| 237 | __raw_local_irq_ssm(ssm_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
| 239 | local_flush_tlb(); |
| 240 | |
| 241 | return; |
| 242 | } |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 243 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
| 245 | void __init mem_init(void) |
| 246 | { |
| 247 | unsigned long codesize, reservedpages, datasize, initsize; |
| 248 | |
| 249 | max_mapnr = num_physpages = max_low_pfn; |
| 250 | high_memory = (void *) __va(max_low_pfn * PAGE_SIZE); |
| 251 | |
| 252 | /* clear the zero-page */ |
| 253 | memset(empty_zero_page, 0, PAGE_SIZE); |
| 254 | |
| 255 | /* this will put all low memory onto the freelists */ |
| 256 | totalram_pages += free_all_bootmem(); |
| 257 | |
| 258 | reservedpages = 0; |
| 259 | |
| 260 | codesize = (unsigned long) &_etext - (unsigned long) &_text; |
| 261 | datasize = (unsigned long) &_edata - (unsigned long) &_etext; |
| 262 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; |
| 263 | printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, %ldk data, %ldk init)\n", |
| 264 | (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), |
| 265 | max_mapnr << (PAGE_SHIFT-10), |
| 266 | codesize >> 10, |
| 267 | reservedpages << (PAGE_SHIFT-10), |
| 268 | datasize >>10, |
| 269 | initsize >> 10); |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame] | 270 | printk("Write protected kernel read-only data: %#lx - %#lx\n", |
| 271 | (unsigned long)&__start_rodata, |
| 272 | PFN_ALIGN((unsigned long)&__end_rodata) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | void free_initmem(void) |
| 276 | { |
| 277 | unsigned long addr; |
| 278 | |
| 279 | addr = (unsigned long)(&__init_begin); |
| 280 | for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) { |
| 281 | ClearPageReserved(virt_to_page(addr)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 282 | init_page_count(virt_to_page(addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | free_page(addr); |
| 284 | totalram_pages++; |
| 285 | } |
| 286 | printk ("Freeing unused kernel memory: %ldk freed\n", |
| 287 | ((unsigned long)&__init_end - (unsigned long)&__init_begin) >> 10); |
| 288 | } |
| 289 | |
| 290 | #ifdef CONFIG_BLK_DEV_INITRD |
| 291 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 292 | { |
| 293 | if (start < end) |
| 294 | printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10); |
| 295 | for (; start < end; start += PAGE_SIZE) { |
| 296 | ClearPageReserved(virt_to_page(start)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 297 | init_page_count(virt_to_page(start)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | free_page(start); |
| 299 | totalram_pages++; |
| 300 | } |
| 301 | } |
| 302 | #endif |