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; |
Heiko Carstens | 0b2b6e1d | 2006-10-04 20:02:23 +0200 | [diff] [blame] | 65 | struct page *page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | printk("Mem-info:\n"); |
| 68 | show_free_areas(); |
| 69 | printk("Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10)); |
| 70 | i = max_mapnr; |
| 71 | while (i-- > 0) { |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 72 | if (!pfn_valid(i)) |
| 73 | continue; |
Heiko Carstens | 0b2b6e1d | 2006-10-04 20:02:23 +0200 | [diff] [blame] | 74 | page = pfn_to_page(i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | total++; |
Heiko Carstens | 0b2b6e1d | 2006-10-04 20:02:23 +0200 | [diff] [blame] | 76 | if (PageReserved(page)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | reserved++; |
Heiko Carstens | 0b2b6e1d | 2006-10-04 20:02:23 +0200 | [diff] [blame] | 78 | else if (PageSwapCache(page)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | cached++; |
Heiko Carstens | 0b2b6e1d | 2006-10-04 20:02:23 +0200 | [diff] [blame] | 80 | else if (page_count(page)) |
| 81 | shared += page_count(page) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
| 83 | printk("%d pages of RAM\n",total); |
| 84 | printk("%d reserved pages\n",reserved); |
| 85 | printk("%d pages shared\n",shared); |
| 86 | printk("%d pages swap cached\n",cached); |
| 87 | } |
| 88 | |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 89 | static void __init setup_ro_region(void) |
| 90 | { |
| 91 | pgd_t *pgd; |
| 92 | pmd_t *pmd; |
| 93 | pte_t *pte; |
| 94 | pte_t new_pte; |
| 95 | unsigned long address, end; |
| 96 | |
| 97 | address = ((unsigned long)&__start_rodata) & PAGE_MASK; |
| 98 | end = PFN_ALIGN((unsigned long)&__end_rodata); |
| 99 | |
| 100 | for (; address < end; address += PAGE_SIZE) { |
| 101 | pgd = pgd_offset_k(address); |
| 102 | pmd = pmd_offset(pgd, address); |
| 103 | pte = pte_offset_kernel(pmd, address); |
| 104 | new_pte = mk_pte_phys(address, __pgprot(_PAGE_RO)); |
| 105 | set_pte(pte, new_pte); |
| 106 | } |
| 107 | } |
| 108 | |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 109 | extern void vmem_map_init(void); |
Heiko Carstens | 39b742f | 2006-12-08 15:56:10 +0100 | [diff] [blame^] | 110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | /* |
| 112 | * paging_init() sets up the page tables |
| 113 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | void __init paging_init(void) |
| 115 | { |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 116 | pgd_t *pg_dir; |
| 117 | int i; |
| 118 | unsigned long pgdir_k; |
| 119 | static const int ssm_mask = 0x04000000L; |
Heiko Carstens | 39b742f | 2006-12-08 15:56:10 +0100 | [diff] [blame^] | 120 | unsigned long max_zone_pfns[MAX_NR_ZONES]; |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame] | 121 | |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 122 | pg_dir = swapper_pg_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 124 | #ifdef CONFIG_64BIT |
| 125 | pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | _KERN_REGION_TABLE; |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 126 | for (i = 0; i < PTRS_PER_PGD; i++) |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 127 | pgd_clear(pg_dir + i); |
| 128 | #else |
| 129 | pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | _KERNSEG_TABLE; |
| 130 | for (i = 0; i < PTRS_PER_PGD; i++) |
| 131 | pmd_clear((pmd_t *)(pg_dir + i)); |
| 132 | #endif |
| 133 | vmem_map_init(); |
| 134 | setup_ro_region(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | S390_lowcore.kernel_asce = pgdir_k; |
| 137 | |
| 138 | /* enable virtual mapping in kernel mode */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 139 | __ctl_load(pgdir_k, 1, 1); |
| 140 | __ctl_load(pgdir_k, 7, 7); |
| 141 | __ctl_load(pgdir_k, 13, 13); |
| 142 | __raw_local_irq_ssm(ssm_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Heiko Carstens | 39b742f | 2006-12-08 15:56:10 +0100 | [diff] [blame^] | 144 | memset(max_zone_pfns, 0, sizeof(max_zone_pfns)); |
| 145 | max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS); |
| 146 | max_zone_pfns[ZONE_NORMAL] = max_low_pfn; |
| 147 | free_area_init_nodes(max_zone_pfns); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | void __init mem_init(void) |
| 151 | { |
| 152 | unsigned long codesize, reservedpages, datasize, initsize; |
| 153 | |
| 154 | max_mapnr = num_physpages = max_low_pfn; |
| 155 | high_memory = (void *) __va(max_low_pfn * PAGE_SIZE); |
| 156 | |
| 157 | /* clear the zero-page */ |
| 158 | memset(empty_zero_page, 0, PAGE_SIZE); |
| 159 | |
| 160 | /* this will put all low memory onto the freelists */ |
| 161 | totalram_pages += free_all_bootmem(); |
| 162 | |
| 163 | reservedpages = 0; |
| 164 | |
| 165 | codesize = (unsigned long) &_etext - (unsigned long) &_text; |
| 166 | datasize = (unsigned long) &_edata - (unsigned long) &_etext; |
| 167 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; |
| 168 | printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, %ldk data, %ldk init)\n", |
| 169 | (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), |
| 170 | max_mapnr << (PAGE_SHIFT-10), |
| 171 | codesize >> 10, |
| 172 | reservedpages << (PAGE_SHIFT-10), |
| 173 | datasize >>10, |
| 174 | initsize >> 10); |
Heiko Carstens | d882b17 | 2006-07-01 04:36:31 -0700 | [diff] [blame] | 175 | printk("Write protected kernel read-only data: %#lx - %#lx\n", |
| 176 | (unsigned long)&__start_rodata, |
| 177 | PFN_ALIGN((unsigned long)&__end_rodata) - 1); |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 178 | printk("Virtual memmap size: %ldk\n", |
| 179 | (max_pfn * sizeof(struct page)) >> 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | void free_initmem(void) |
| 183 | { |
| 184 | unsigned long addr; |
| 185 | |
| 186 | addr = (unsigned long)(&__init_begin); |
| 187 | for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) { |
| 188 | ClearPageReserved(virt_to_page(addr)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 189 | init_page_count(virt_to_page(addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | free_page(addr); |
| 191 | totalram_pages++; |
| 192 | } |
| 193 | printk ("Freeing unused kernel memory: %ldk freed\n", |
| 194 | ((unsigned long)&__init_end - (unsigned long)&__init_begin) >> 10); |
| 195 | } |
| 196 | |
| 197 | #ifdef CONFIG_BLK_DEV_INITRD |
| 198 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 199 | { |
| 200 | if (start < end) |
| 201 | printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10); |
| 202 | for (; start < end; start += PAGE_SIZE) { |
| 203 | ClearPageReserved(virt_to_page(start)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 204 | init_page_count(virt_to_page(start)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | free_page(start); |
| 206 | totalram_pages++; |
| 207 | } |
| 208 | } |
| 209 | #endif |