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 | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 48 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | asm volatile ( |
| 50 | " sam31\n" |
| 51 | " diag %0,%0,0x10\n" |
| 52 | "0: sam64\n" |
| 53 | ".section __ex_table,\"a\"\n" |
| 54 | " .align 8\n" |
| 55 | " .quad 0b, 0b\n" |
| 56 | ".previous\n" |
| 57 | : : "a" (addr)); |
| 58 | #else |
| 59 | asm volatile ( |
| 60 | " diag %0,%0,0x10\n" |
| 61 | "0:\n" |
| 62 | ".section __ex_table,\"a\"\n" |
| 63 | " .align 4\n" |
| 64 | " .long 0b, 0b\n" |
| 65 | ".previous\n" |
| 66 | : : "a" (addr)); |
| 67 | #endif |
| 68 | } |
| 69 | |
| 70 | void show_mem(void) |
| 71 | { |
| 72 | int i, total = 0, reserved = 0; |
| 73 | int shared = 0, cached = 0; |
| 74 | |
| 75 | printk("Mem-info:\n"); |
| 76 | show_free_areas(); |
| 77 | printk("Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10)); |
| 78 | i = max_mapnr; |
| 79 | while (i-- > 0) { |
| 80 | total++; |
| 81 | if (PageReserved(mem_map+i)) |
| 82 | reserved++; |
| 83 | else if (PageSwapCache(mem_map+i)) |
| 84 | cached++; |
| 85 | else if (page_count(mem_map+i)) |
| 86 | shared += page_count(mem_map+i) - 1; |
| 87 | } |
| 88 | printk("%d pages of RAM\n",total); |
| 89 | printk("%d reserved pages\n",reserved); |
| 90 | printk("%d pages shared\n",shared); |
| 91 | printk("%d pages swap cached\n",cached); |
| 92 | } |
| 93 | |
Heiko Carstens | c9e3735 | 2005-05-01 08:58:57 -0700 | [diff] [blame] | 94 | extern unsigned long __initdata zholes_size[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | /* |
| 96 | * paging_init() sets up the page tables |
| 97 | */ |
| 98 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 99 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | void __init paging_init(void) |
| 101 | { |
| 102 | pgd_t * pg_dir; |
| 103 | pte_t * pg_table; |
| 104 | pte_t pte; |
| 105 | int i; |
| 106 | unsigned long tmp; |
| 107 | unsigned long pfn = 0; |
| 108 | unsigned long pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | _KERNSEG_TABLE; |
| 109 | static const int ssm_mask = 0x04000000L; |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame^] | 110 | unsigned long ro_start_pfn, ro_end_pfn; |
| 111 | |
| 112 | ro_start_pfn = PFN_DOWN((unsigned long)&__start_rodata); |
| 113 | ro_end_pfn = PFN_UP((unsigned long)&__end_rodata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 115 | /* unmap whole virtual address space */ |
| 116 | |
| 117 | pg_dir = swapper_pg_dir; |
| 118 | |
| 119 | for (i=0;i<KERNEL_PGD_PTRS;i++) |
| 120 | pmd_clear((pmd_t*)pg_dir++); |
| 121 | |
| 122 | /* |
| 123 | * map whole physical memory to virtual memory (identity mapping) |
| 124 | */ |
| 125 | |
| 126 | pg_dir = swapper_pg_dir; |
| 127 | |
| 128 | while (pfn < max_low_pfn) { |
| 129 | /* |
| 130 | * pg_table is physical at this point |
| 131 | */ |
| 132 | pg_table = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE); |
| 133 | |
| 134 | pg_dir->pgd0 = (_PAGE_TABLE | __pa(pg_table)); |
| 135 | pg_dir->pgd1 = (_PAGE_TABLE | (__pa(pg_table)+1024)); |
| 136 | pg_dir->pgd2 = (_PAGE_TABLE | (__pa(pg_table)+2048)); |
| 137 | pg_dir->pgd3 = (_PAGE_TABLE | (__pa(pg_table)+3072)); |
| 138 | pg_dir++; |
| 139 | |
| 140 | for (tmp = 0 ; tmp < PTRS_PER_PTE ; tmp++,pg_table++) { |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame^] | 141 | if (pfn >= ro_start_pfn && pfn < ro_end_pfn) |
| 142 | pte = pfn_pte(pfn, __pgprot(_PAGE_RO)); |
| 143 | else |
| 144 | pte = pfn_pte(pfn, PAGE_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | if (pfn >= max_low_pfn) |
| 146 | pte_clear(&init_mm, 0, &pte); |
| 147 | set_pte(pg_table, pte); |
| 148 | pfn++; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | S390_lowcore.kernel_asce = pgdir_k; |
| 153 | |
| 154 | /* enable virtual mapping in kernel mode */ |
| 155 | __asm__ __volatile__(" LCTL 1,1,%0\n" |
| 156 | " LCTL 7,7,%0\n" |
| 157 | " LCTL 13,13,%0\n" |
| 158 | " SSM %1" |
| 159 | : : "m" (pgdir_k), "m" (ssm_mask)); |
| 160 | |
| 161 | local_flush_tlb(); |
| 162 | |
| 163 | { |
Heiko Carstens | c9e3735 | 2005-05-01 08:58:57 -0700 | [diff] [blame] | 164 | unsigned long zones_size[MAX_NR_ZONES]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Heiko Carstens | c9e3735 | 2005-05-01 08:58:57 -0700 | [diff] [blame] | 166 | memset(zones_size, 0, sizeof(zones_size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | zones_size[ZONE_DMA] = max_low_pfn; |
Heiko Carstens | c9e3735 | 2005-05-01 08:58:57 -0700 | [diff] [blame] | 168 | free_area_init_node(0, &contig_page_data, zones_size, |
| 169 | __pa(PAGE_OFFSET) >> PAGE_SHIFT, |
| 170 | zholes_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | return; |
| 173 | } |
| 174 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 175 | #else /* CONFIG_64BIT */ |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame^] | 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | void __init paging_init(void) |
| 178 | { |
| 179 | pgd_t * pg_dir; |
| 180 | pmd_t * pm_dir; |
| 181 | pte_t * pt_dir; |
| 182 | pte_t pte; |
| 183 | int i,j,k; |
| 184 | unsigned long pfn = 0; |
| 185 | unsigned long pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | |
| 186 | _KERN_REGION_TABLE; |
| 187 | static const int ssm_mask = 0x04000000L; |
Heiko Carstens | c9e3735 | 2005-05-01 08:58:57 -0700 | [diff] [blame] | 188 | unsigned long zones_size[MAX_NR_ZONES]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | unsigned long dma_pfn, high_pfn; |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame^] | 190 | unsigned long ro_start_pfn, ro_end_pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Heiko Carstens | c9e3735 | 2005-05-01 08:58:57 -0700 | [diff] [blame] | 192 | memset(zones_size, 0, sizeof(zones_size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT; |
| 194 | high_pfn = max_low_pfn; |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame^] | 195 | ro_start_pfn = PFN_DOWN((unsigned long)&__start_rodata); |
| 196 | ro_end_pfn = PFN_UP((unsigned long)&__end_rodata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | if (dma_pfn > high_pfn) |
| 199 | zones_size[ZONE_DMA] = high_pfn; |
| 200 | else { |
| 201 | zones_size[ZONE_DMA] = dma_pfn; |
| 202 | zones_size[ZONE_NORMAL] = high_pfn - dma_pfn; |
| 203 | } |
| 204 | |
| 205 | /* Initialize mem_map[]. */ |
Heiko Carstens | c9e3735 | 2005-05-01 08:58:57 -0700 | [diff] [blame] | 206 | free_area_init_node(0, &contig_page_data, zones_size, |
| 207 | __pa(PAGE_OFFSET) >> PAGE_SHIFT, zholes_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * map whole physical memory to virtual memory (identity mapping) |
| 211 | */ |
| 212 | |
| 213 | pg_dir = swapper_pg_dir; |
| 214 | |
| 215 | for (i = 0 ; i < PTRS_PER_PGD ; i++,pg_dir++) { |
| 216 | |
| 217 | if (pfn >= max_low_pfn) { |
| 218 | pgd_clear(pg_dir); |
| 219 | continue; |
| 220 | } |
| 221 | |
| 222 | pm_dir = (pmd_t *) alloc_bootmem_low_pages(PAGE_SIZE*4); |
| 223 | pgd_populate(&init_mm, pg_dir, pm_dir); |
| 224 | |
| 225 | for (j = 0 ; j < PTRS_PER_PMD ; j++,pm_dir++) { |
| 226 | if (pfn >= max_low_pfn) { |
| 227 | pmd_clear(pm_dir); |
| 228 | continue; |
| 229 | } |
| 230 | |
| 231 | pt_dir = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE); |
| 232 | pmd_populate_kernel(&init_mm, pm_dir, pt_dir); |
| 233 | |
| 234 | for (k = 0 ; k < PTRS_PER_PTE ; k++,pt_dir++) { |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame^] | 235 | if (pfn >= ro_start_pfn && pfn < ro_end_pfn) |
| 236 | pte = pfn_pte(pfn, __pgprot(_PAGE_RO)); |
| 237 | else |
| 238 | pte = pfn_pte(pfn, PAGE_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | if (pfn >= max_low_pfn) { |
| 240 | pte_clear(&init_mm, 0, &pte); |
| 241 | continue; |
| 242 | } |
| 243 | set_pte(pt_dir, pte); |
| 244 | pfn++; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | S390_lowcore.kernel_asce = pgdir_k; |
| 250 | |
| 251 | /* enable virtual mapping in kernel mode */ |
| 252 | __asm__ __volatile__("lctlg 1,1,%0\n\t" |
| 253 | "lctlg 7,7,%0\n\t" |
| 254 | "lctlg 13,13,%0\n\t" |
| 255 | "ssm %1" |
| 256 | : :"m" (pgdir_k), "m" (ssm_mask)); |
| 257 | |
| 258 | local_flush_tlb(); |
| 259 | |
| 260 | return; |
| 261 | } |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 262 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
| 264 | void __init mem_init(void) |
| 265 | { |
| 266 | unsigned long codesize, reservedpages, datasize, initsize; |
| 267 | |
| 268 | max_mapnr = num_physpages = max_low_pfn; |
| 269 | high_memory = (void *) __va(max_low_pfn * PAGE_SIZE); |
| 270 | |
| 271 | /* clear the zero-page */ |
| 272 | memset(empty_zero_page, 0, PAGE_SIZE); |
| 273 | |
| 274 | /* this will put all low memory onto the freelists */ |
| 275 | totalram_pages += free_all_bootmem(); |
| 276 | |
| 277 | reservedpages = 0; |
| 278 | |
| 279 | codesize = (unsigned long) &_etext - (unsigned long) &_text; |
| 280 | datasize = (unsigned long) &_edata - (unsigned long) &_etext; |
| 281 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; |
| 282 | printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, %ldk data, %ldk init)\n", |
| 283 | (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), |
| 284 | max_mapnr << (PAGE_SHIFT-10), |
| 285 | codesize >> 10, |
| 286 | reservedpages << (PAGE_SHIFT-10), |
| 287 | datasize >>10, |
| 288 | initsize >> 10); |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame^] | 289 | printk("Write protected kernel read-only data: %#lx - %#lx\n", |
| 290 | (unsigned long)&__start_rodata, |
| 291 | PFN_ALIGN((unsigned long)&__end_rodata) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void free_initmem(void) |
| 295 | { |
| 296 | unsigned long addr; |
| 297 | |
| 298 | addr = (unsigned long)(&__init_begin); |
| 299 | for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) { |
| 300 | ClearPageReserved(virt_to_page(addr)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 301 | init_page_count(virt_to_page(addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | free_page(addr); |
| 303 | totalram_pages++; |
| 304 | } |
| 305 | printk ("Freeing unused kernel memory: %ldk freed\n", |
| 306 | ((unsigned long)&__init_end - (unsigned long)&__init_begin) >> 10); |
| 307 | } |
| 308 | |
| 309 | #ifdef CONFIG_BLK_DEV_INITRD |
| 310 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 311 | { |
| 312 | if (start < end) |
| 313 | printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10); |
| 314 | for (; start < end; start += PAGE_SIZE) { |
| 315 | ClearPageReserved(virt_to_page(start)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 316 | init_page_count(virt_to_page(start)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | free_page(start); |
| 318 | totalram_pages++; |
| 319 | } |
| 320 | } |
| 321 | #endif |