c486835415200ef2d4c9c0f2a50f584ff853a016
2 * arch/ubicom32/mm/init.c
3 * Ubicom32 architecture virtual memory initialization.
5 * (C) Copyright 2009, Ubicom, Inc.
6 * Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>,
7 * Kenneth Albanowski <kjahds@kjahds.com>,
8 * Copyright (C) 2000 Lineo, Inc. (www.lineo.com)
12 * linux/arch/m68k/mm/init.c
14 * Copyright (C) 1995 Hamish Macdonald
16 * JAN/1999 -- hacked to support ColdFire (gerg@snapgear.com)
17 * DEC/2000 -- linux 2.4 support <davidm@snapgear.com>
19 * This file is part of the Ubicom32 Linux Kernel Port.
21 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
22 * it and/or modify it under the terms of the GNU General Public License
23 * as published by the Free Software Foundation, either version 2 of the
24 * License, or (at your option) any later version.
26 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
27 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
28 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
29 * the GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with the Ubicom32 Linux Kernel Port. If not,
33 * see <http://www.gnu.org/licenses/>.
35 * Ubicom32 implementation derived from (with many thanks):
41 #include <linux/signal.h>
42 #include <linux/sched.h>
43 #include <linux/kernel.h>
44 #include <linux/errno.h>
45 #include <linux/string.h>
46 #include <linux/types.h>
47 #include <linux/ptrace.h>
48 #include <linux/mman.h>
50 #include <linux/swap.h>
51 #include <linux/init.h>
52 #include <linux/highmem.h>
53 #include <linux/pagemap.h>
54 #include <linux/bootmem.h>
55 #include <linux/slab.h>
57 #include <asm/setup.h>
58 #include <asm/segment.h>
60 #include <asm/pgtable.h>
61 #include <asm/system.h>
62 #include <asm/machdep.h>
63 #include <asm/ocm-alloc.h>
64 #include <asm/processor.h>
68 extern void die_if_kernel(char *,struct pt_regs
*,long);
69 extern void free_initmem(void);
72 * BAD_PAGE is the page that is used for page faults when linux
73 * is out-of-memory. Older versions of linux just did a
74 * do_exit(), but using this instead means there is less risk
75 * for a process dying in kernel mode, possibly leaving a inode
78 * BAD_PAGETABLE is the accompanying page-table: it is initialized
79 * to point to BAD_PAGE entries.
81 * ZERO_PAGE is a special page that is used for zero-initialized
84 static unsigned long empty_bad_page_table
;
86 static unsigned long empty_bad_page
;
88 unsigned long empty_zero_page
;
93 int free
= 0, total
= 0, reserved
= 0, shared
= 0;
96 printk(KERN_INFO
"\nMem-info:\n");
101 if (PageReserved(mem_map
+i
))
103 else if (PageSwapCache(mem_map
+i
))
105 else if (!page_count(mem_map
+i
))
108 shared
+= page_count(mem_map
+i
) - 1;
110 printk(KERN_INFO
"%d pages of RAM\n",total
);
111 printk(KERN_INFO
"%d free pages\n",free
);
112 printk(KERN_INFO
"%d reserved pages\n",reserved
);
113 printk(KERN_INFO
"%d pages shared\n",shared
);
114 printk(KERN_INFO
"%d pages swap cached\n",cached
);
117 extern unsigned long memory_start
;
118 extern unsigned long memory_end
;
119 extern char __ocm_free_begin
;
120 extern char __ocm_free_end
;
123 * paging_init() continues the virtual memory environment setup which
124 * was begun by the code in arch/head.S.
125 * The parameters are pointers to where to stick the starting and ending
126 * addresses of available kernel virtual memory.
128 void __init
paging_init(void)
131 * Make sure start_mem is page aligned, otherwise bootmem and
132 * page_alloc get different views of the world.
135 unsigned long start_mem
= PAGE_ALIGN(memory_start
);
137 unsigned long end_mem
= memory_end
& PAGE_MASK
;
140 printk (KERN_DEBUG
"start_mem is %#lx\nvirtual_end is %#lx\n",
145 * Initialize the bad page table and bad page to point
146 * to a couple of allocated pages.
148 empty_bad_page_table
= (unsigned long)alloc_bootmem_pages(PAGE_SIZE
);
149 empty_bad_page
= (unsigned long)alloc_bootmem_pages(PAGE_SIZE
);
150 empty_zero_page
= (unsigned long)alloc_bootmem_pages(PAGE_SIZE
);
151 memset((void *)empty_zero_page
, 0, PAGE_SIZE
);
154 * TODO: enable setting up for user memory management interface.
158 printk (KERN_DEBUG
"before free_area_init\n");
160 printk (KERN_DEBUG
"free_area_init -> start_mem is %#lx\nvirtual_end is %#lx\n",
165 unsigned long zones_size
[MAX_NR_ZONES
] = {0, };
166 #ifdef CONFIG_ZONE_DMA
167 zones_size
[ZONE_DMA
] = OCMSIZE
>> PAGE_SHIFT
;
169 zones_size
[ZONE_NORMAL
] = (end_mem
- PAGE_OFFSET
) >> PAGE_SHIFT
;
170 #ifdef CONFIG_HIGHMEM
171 zones_size
[ZONE_HIGHMEM
] = 0;
173 free_area_init(zones_size
);
177 void __init
mem_init(void)
179 int codek
= 0, datak
= 0, initk
= 0;
180 unsigned long tmp
, ram_start
, ram_end
, len
;
181 extern char _etext
, _stext
, _sdata
, _ebss
, __init_begin
, __init_end
;
183 unsigned long start_mem
= memory_start
; /* DAVIDM - these must start at end of kernel */
184 unsigned long end_mem
= memory_end
; /* DAVIDM - this must not include kernel stack at top */
185 processor_dram(&ram_start
, &ram_end
);
186 len
= (ram_end
- ram_start
) + OCMSIZE
;
188 printk(KERN_DEBUG
"Mem_init: start=%lx, end=%lx\n", start_mem
, end_mem
);
191 end_mem
&= PAGE_MASK
;
192 high_memory
= (void *) end_mem
;
194 start_mem
= PAGE_ALIGN(start_mem
);
195 max_mapnr
= num_physpages
= (((unsigned long) high_memory
) - PAGE_OFFSET
) >> PAGE_SHIFT
;
197 /* this will put all memory onto the freelists */
198 #ifdef CONFIG_ZONE_DMA
200 unsigned long ocm_free_begin
= (unsigned long)&__ocm_free_begin
;
201 unsigned long ocm_free_end
= (unsigned long)&__ocm_free_end
;
202 unsigned long zone_dma_begin
= (ocm_free_begin
+ PAGE_SIZE
- 1) & PAGE_MASK
;
203 unsigned long zone_dma_end
= ocm_free_end
& PAGE_MASK
;
204 if (zone_dma_end
> zone_dma_begin
)
205 free_bootmem(zone_dma_begin
, zone_dma_end
-zone_dma_begin
);
208 totalram_pages
= free_all_bootmem();
210 codek
= (&_etext
- &_stext
) >> 10;
211 datak
= (&_ebss
- &_sdata
) >> 10;
212 initk
= (&__init_begin
- &__init_end
) >> 10;
214 tmp
= nr_free_pages() << PAGE_SHIFT
;
215 printk(KERN_INFO
"Memory available: %luk/%luk RAM, (%dk kernel code, %dk data)\n",
224 #ifdef CONFIG_BLK_DEV_INITRD
225 void free_initrd_mem(unsigned long start
, unsigned long end
)
228 for (; start
< end
; start
+= PAGE_SIZE
) {
229 ClearPageReserved(virt_to_page(start
));
230 init_page_count(virt_to_page(start
));
235 printk (KERN_NOTICE
"Freeing initrd memory: %dk freed\n", pages
);
242 #ifdef CONFIG_RAMKERNEL
244 extern char __init_begin
, __init_end
;
246 * The following code should be cool even if these sections
247 * are not page aligned.
249 addr
= PAGE_ALIGN((unsigned long)(&__init_begin
));
250 /* next to check that the page we free is not a partial page */
251 for (; addr
+ PAGE_SIZE
< (unsigned long)(&__init_end
); addr
+=PAGE_SIZE
) {
252 ClearPageReserved(virt_to_page(addr
));
253 init_page_count(virt_to_page(addr
));
257 printk(KERN_NOTICE
"Freeing unused kernel memory: %ldk freed (0x%x - 0x%x)\n",
258 (addr
- PAGE_ALIGN((long) &__init_begin
)) >> 10,
259 (int)(PAGE_ALIGN((unsigned long)(&__init_begin
))),
260 (int)(addr
- PAGE_SIZE
));