init_no.c 3.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 *  linux/arch/m68knommu/mm/init.c
 *
 *  Copyright (C) 1998  D. Jeff Dionne <jeff@lineo.ca>,
 *                      Kenneth Albanowski <kjahds@kjahds.com>,
 *  Copyright (C) 2000  Lineo, Inc.  (www.lineo.com) 
 *
 *  Based on:
 *
 *  linux/arch/m68k/mm/init.c
 *
 *  Copyright (C) 1995  Hamish Macdonald
 *
 *  JAN/1999 -- hacked to support ColdFire (gerg@snapgear.com)
 *  DEC/2000 -- linux 2.4 support <davidm@snapgear.com>
 */

#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/types.h>
#include <linux/ptrace.h>
#include <linux/mman.h>
#include <linux/mm.h>
#include <linux/swap.h>
#include <linux/init.h>
#include <linux/highmem.h>
#include <linux/pagemap.h>
#include <linux/bootmem.h>
32
#include <linux/gfp.h>
L
Linus Torvalds 已提交
33 34

#include <asm/setup.h>
35
#include <asm/sections.h>
L
Linus Torvalds 已提交
36 37 38 39 40 41 42 43 44
#include <asm/segment.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <asm/machdep.h>

/*
 * ZERO_PAGE is a special page that is used for zero-initialized
 * data and COW.
 */
45
void *empty_zero_page;
L
Linus Torvalds 已提交
46 47 48 49 50 51 52

/*
 * paging_init() continues the virtual memory environment setup which
 * was begun by the code in arch/head.S.
 * The parameters are pointers to where to stick the starting and ending
 * addresses of available kernel virtual memory.
 */
53
void __init paging_init(void)
L
Linus Torvalds 已提交
54 55 56 57 58 59
{
	/*
	 * Make sure start_mem is page aligned, otherwise bootmem and
	 * page_alloc get different views of the world.
	 */
	unsigned long end_mem   = memory_end & PAGE_MASK;
G
Greg Ungerer 已提交
60
	unsigned long zones_size[MAX_NR_ZONES] = {0, };
L
Linus Torvalds 已提交
61

62 63
	empty_zero_page = alloc_bootmem_pages(PAGE_SIZE);
	memset(empty_zero_page, 0, PAGE_SIZE);
L
Linus Torvalds 已提交
64 65 66 67 68 69

	/*
	 * Set up SFC/DFC registers (user data space).
	 */
	set_fs (USER_DS);

G
Greg Ungerer 已提交
70 71
	zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT;
	free_area_init(zones_size);
L
Linus Torvalds 已提交
72 73
}

74
void __init mem_init(void)
L
Linus Torvalds 已提交
75 76 77 78 79 80 81
{
	int codek = 0, datak = 0, initk = 0;
	unsigned long tmp;
	unsigned long len = _ramend - _rambase;
	unsigned long start_mem = memory_start; /* DAVIDM - these must start at end of kernel */
	unsigned long end_mem   = memory_end; /* DAVIDM - this must not include kernel stack at top */

82
	pr_debug("Mem_init: start=%lx, end=%lx\n", start_mem, end_mem);
L
Linus Torvalds 已提交
83 84 85 86 87 88 89 90 91 92

	end_mem &= PAGE_MASK;
	high_memory = (void *) end_mem;

	start_mem = PAGE_ALIGN(start_mem);
	max_mapnr = num_physpages = (((unsigned long) high_memory) - PAGE_OFFSET) >> PAGE_SHIFT;

	/* this will put all memory onto the freelists */
	totalram_pages = free_all_bootmem();

93
	codek = (_etext - _stext) >> 10;
94
	datak = (__bss_stop - _sdata) >> 10;
95
	initk = (__init_begin - __init_end) >> 10;
L
Linus Torvalds 已提交
96 97

	tmp = nr_free_pages() << PAGE_SHIFT;
98
	printk(KERN_INFO "Memory available: %luk/%luk RAM, (%dk kernel code, %dk data)\n",
L
Linus Torvalds 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112
	       tmp >> 10,
	       len >> 10,
	       codek,
	       datak
	       );
}


#ifdef CONFIG_BLK_DEV_INITRD
void free_initrd_mem(unsigned long start, unsigned long end)
{
	int pages = 0;
	for (; start < end; start += PAGE_SIZE) {
		ClearPageReserved(virt_to_page(start));
113
		init_page_count(virt_to_page(start));
L
Linus Torvalds 已提交
114 115 116 117
		free_page(start);
		totalram_pages++;
		pages++;
	}
118 119
	pr_notice("Freeing initrd memory: %luk freed\n",
		  pages * (PAGE_SIZE / 1024));
L
Linus Torvalds 已提交
120 121 122
}
#endif

G
Greg Ungerer 已提交
123
void free_initmem(void)
L
Linus Torvalds 已提交
124 125 126 127 128 129 130
{
#ifdef CONFIG_RAMKERNEL
	unsigned long addr;
	/*
	 * The following code should be cool even if these sections
	 * are not page aligned.
	 */
131
	addr = PAGE_ALIGN((unsigned long) __init_begin);
L
Linus Torvalds 已提交
132
	/* next to check that the page we free is not a partial page */
133
	for (; addr + PAGE_SIZE < ((unsigned long) __init_end); addr += PAGE_SIZE) {
L
Linus Torvalds 已提交
134
		ClearPageReserved(virt_to_page(addr));
135
		init_page_count(virt_to_page(addr));
L
Linus Torvalds 已提交
136 137 138
		free_page(addr);
		totalram_pages++;
	}
139
	pr_notice("Freeing unused kernel memory: %luk freed (0x%x - 0x%x)\n",
140 141
			(addr - PAGE_ALIGN((unsigned long) __init_begin)) >> 10,
			(int)(PAGE_ALIGN((unsigned long) __init_begin)),
L
Linus Torvalds 已提交
142 143 144 145
			(int)(addr - PAGE_SIZE));
#endif
}