]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/s390/mm/init.c
[S390] noexec protection
[linux-2.6-omap-h63xx.git] / arch / s390 / mm / init.c
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
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>
26 #include <linux/pfn.h>
27 #include <linux/poison.h>
28 #include <linux/initrd.h>
29
30 #include <asm/processor.h>
31 #include <asm/system.h>
32 #include <asm/uaccess.h>
33 #include <asm/pgtable.h>
34 #include <asm/pgalloc.h>
35 #include <asm/dma.h>
36 #include <asm/lowcore.h>
37 #include <asm/tlb.h>
38 #include <asm/tlbflush.h>
39 #include <asm/sections.h>
40
41 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
42
43 pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__((__aligned__(PAGE_SIZE)));
44 char  empty_zero_page[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
45
46 void diag10(unsigned long addr)
47 {
48         if (addr >= 0x7ff00000)
49                 return;
50         asm volatile(
51 #ifdef CONFIG_64BIT
52                 "       sam31\n"
53                 "       diag    %0,%0,0x10\n"
54                 "0:     sam64\n"
55 #else
56                 "       diag    %0,%0,0x10\n"
57                 "0:\n"
58 #endif
59                 EX_TABLE(0b,0b)
60                 : : "a" (addr));
61 }
62
63 void show_mem(void)
64 {
65         int i, total = 0, reserved = 0;
66         int shared = 0, cached = 0;
67         struct page *page;
68
69         printk("Mem-info:\n");
70         show_free_areas();
71         printk("Free swap:       %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
72         i = max_mapnr;
73         while (i-- > 0) {
74                 if (!pfn_valid(i))
75                         continue;
76                 page = pfn_to_page(i);
77                 total++;
78                 if (PageReserved(page))
79                         reserved++;
80                 else if (PageSwapCache(page))
81                         cached++;
82                 else if (page_count(page))
83                         shared += page_count(page) - 1;
84         }
85         printk("%d pages of RAM\n",total);
86         printk("%d reserved pages\n",reserved);
87         printk("%d pages shared\n",shared);
88         printk("%d pages swap cached\n",cached);
89 }
90
91 static void __init setup_ro_region(void)
92 {
93         pgd_t *pgd;
94         pmd_t *pmd;
95         pte_t *pte;
96         pte_t new_pte;
97         unsigned long address, end;
98
99         address = ((unsigned long)&__start_rodata) & PAGE_MASK;
100         end = PFN_ALIGN((unsigned long)&__end_rodata);
101
102         for (; address < end; address += PAGE_SIZE) {
103                 pgd = pgd_offset_k(address);
104                 pmd = pmd_offset(pgd, address);
105                 pte = pte_offset_kernel(pmd, address);
106                 new_pte = mk_pte_phys(address, __pgprot(_PAGE_RO));
107                 *pte = new_pte;
108         }
109 }
110
111 /*
112  * paging_init() sets up the page tables
113  */
114 void __init paging_init(void)
115 {
116         pgd_t *pg_dir;
117         int i;
118         unsigned long pgdir_k;
119         static const int ssm_mask = 0x04000000L;
120         unsigned long max_zone_pfns[MAX_NR_ZONES];
121
122         pg_dir = swapper_pg_dir;
123         
124 #ifdef CONFIG_64BIT
125         pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | _KERN_REGION_TABLE;
126         for (i = 0; i < PTRS_PER_PGD; i++)
127                 pgd_clear_kernel(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_kernel((pmd_t *)(pg_dir + i));
132 #endif
133         vmem_map_init();
134         setup_ro_region();
135
136         S390_lowcore.kernel_asce = pgdir_k;
137
138         /* enable virtual mapping in kernel mode */
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);
143
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);
148 }
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);
175         printk("Write protected kernel read-only data: %#lx - %#lx\n",
176                (unsigned long)&__start_rodata,
177                PFN_ALIGN((unsigned long)&__end_rodata) - 1);
178 }
179
180 void free_initmem(void)
181 {
182         unsigned long addr;
183
184         addr = (unsigned long)(&__init_begin);
185         for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
186                 ClearPageReserved(virt_to_page(addr));
187                 init_page_count(virt_to_page(addr));
188                 memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
189                 free_page(addr);
190                 totalram_pages++;
191         }
192         printk ("Freeing unused kernel memory: %ldk freed\n",
193                 ((unsigned long)&__init_end - (unsigned long)&__init_begin) >> 10);
194 }
195
196 #ifdef CONFIG_BLK_DEV_INITRD
197 void free_initrd_mem(unsigned long start, unsigned long end)
198 {
199         if (start < end)
200                 printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
201         for (; start < end; start += PAGE_SIZE) {
202                 ClearPageReserved(virt_to_page(start));
203                 init_page_count(virt_to_page(start));
204                 free_page(start);
205                 totalram_pages++;
206         }
207 }
208 #endif