blob: aa39591ca130e8a04c906ab898490df6443b7880 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070012#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 Carstensd882b172006-07-01 04:36:31 -070026#include <linux/pfn.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
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 Carstensd882b172006-07-01 04:36:31 -070037#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
40
41pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__((__aligned__(PAGE_SIZE)));
42char empty_zero_page[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
43
44void diag10(unsigned long addr)
45{
46 if (addr >= 0x7ff00000)
47 return;
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020048 asm volatile(
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080049#ifdef CONFIG_64BIT
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020050 " sam31\n"
51 " diag %0,%0,0x10\n"
52 "0: sam64\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#else
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020054 " diag %0,%0,0x10\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 "0:\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#endif
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020057 EX_TABLE(0b,0b)
58 : : "a" (addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
61void show_mem(void)
62{
63 int i, total = 0, reserved = 0;
64 int shared = 0, cached = 0;
Heiko Carstens0b2b6e1d2006-10-04 20:02:23 +020065 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
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 Carstensf4eb07c2006-12-08 15:56:07 +010072 if (!pfn_valid(i))
73 continue;
Heiko Carstens0b2b6e1d2006-10-04 20:02:23 +020074 page = pfn_to_page(i);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 total++;
Heiko Carstens0b2b6e1d2006-10-04 20:02:23 +020076 if (PageReserved(page))
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 reserved++;
Heiko Carstens0b2b6e1d2006-10-04 20:02:23 +020078 else if (PageSwapCache(page))
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 cached++;
Heiko Carstens0b2b6e1d2006-10-04 20:02:23 +020080 else if (page_count(page))
81 shared += page_count(page) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 }
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 Carstensf4eb07c2006-12-08 15:56:07 +010089static 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 Carstensf4eb07c2006-12-08 15:56:07 +0100109extern void vmem_map_init(void);
Heiko Carstens39b742f2006-12-08 15:56:10 +0100110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111/*
112 * paging_init() sets up the page tables
113 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114void __init paging_init(void)
115{
Heiko Carstensf4eb07c2006-12-08 15:56:07 +0100116 pgd_t *pg_dir;
117 int i;
118 unsigned long pgdir_k;
119 static const int ssm_mask = 0x04000000L;
Heiko Carstens39b742f2006-12-08 15:56:10 +0100120 unsigned long max_zone_pfns[MAX_NR_ZONES];
Heiko Carstensd882b172006-07-01 04:36:31 -0700121
Heiko Carstensf4eb07c2006-12-08 15:56:07 +0100122 pg_dir = swapper_pg_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Heiko Carstensf4eb07c2006-12-08 15:56:07 +0100124#ifdef CONFIG_64BIT
125 pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | _KERN_REGION_TABLE;
Gerald Schaefer9282ed92006-09-20 15:59:37 +0200126 for (i = 0; i < PTRS_PER_PGD; i++)
Heiko Carstensf4eb07c2006-12-08 15:56:07 +0100127 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 Torvalds1da177e2005-04-16 15:20:36 -0700135
136 S390_lowcore.kernel_asce = pgdir_k;
137
138 /* enable virtual mapping in kernel mode */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200139 __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 Torvalds1da177e2005-04-16 15:20:36 -0700143
Heiko Carstens39b742f2006-12-08 15:56:10 +0100144 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 Torvalds1da177e2005-04-16 15:20:36 -0700148}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150void __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 Carstensd882b172006-07-01 04:36:31 -0700175 printk("Write protected kernel read-only data: %#lx - %#lx\n",
176 (unsigned long)&__start_rodata,
177 PFN_ALIGN((unsigned long)&__end_rodata) - 1);
Heiko Carstensf4eb07c2006-12-08 15:56:07 +0100178 printk("Virtual memmap size: %ldk\n",
179 (max_pfn * sizeof(struct page)) >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180}
181
182void 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 Piggin7835e982006-03-22 00:08:40 -0800189 init_page_count(virt_to_page(addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 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
198void 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 Piggin7835e982006-03-22 00:08:40 -0800204 init_page_count(virt_to_page(start));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 free_page(start);
206 totalram_pages++;
207 }
208}
209#endif