2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
8 * Copyright (C) 2000, 2001 Paolo Alberelli
9 * Copyright (C) 2003, 2004 Paul Mundt
13 #include <linux/init.h>
14 #include <linux/rwsem.h>
16 #include <linux/swap.h>
17 #include <linux/bootmem.h>
19 #include <asm/mmu_context.h>
21 #include <asm/pgalloc.h>
22 #include <asm/pgtable.h>
25 #ifdef CONFIG_BLK_DEV_INITRD
26 #include <linux/blk.h>
29 DEFINE_PER_CPU(struct mmu_gather
, mmu_gathers
);
32 * Cache of MMU context last used.
34 unsigned long mmu_context_cache
;
35 pgd_t
* mmu_pdtp_cache
;
36 int after_bootmem
= 0;
39 * BAD_PAGE is the page that is used for page faults when linux
40 * is out-of-memory. Older versions of linux just did a
41 * do_exit(), but using this instead means there is less risk
42 * for a process dying in kernel mode, possibly leaving an inode
45 * BAD_PAGETABLE is the accompanying page-table: it is initialized
46 * to point to BAD_PAGE entries.
48 * ZERO_PAGE is a special page that is used for zero-initialized
52 extern unsigned char empty_zero_page
[PAGE_SIZE
];
53 extern unsigned char empty_bad_page
[PAGE_SIZE
];
54 extern pte_t empty_bad_pte_table
[PTRS_PER_PTE
];
55 extern pgd_t swapper_pg_dir
[PTRS_PER_PGD
];
57 extern char _text
, _etext
, _edata
, __bss_start
, _end
;
58 extern char __init_begin
, __init_end
;
60 /* It'd be good if these lines were in the standard header file. */
61 #define START_PFN (NODE_DATA(0)->bdata->node_boot_start >> PAGE_SHIFT)
62 #define MAX_LOW_PFN (NODE_DATA(0)->bdata->node_low_pfn)
67 int i
, total
= 0, reserved
= 0;
68 int shared
= 0, cached
= 0;
70 printk("Mem-info:\n");
72 printk("Free swap: %6ldkB\n",nr_swap_pages
<<(PAGE_SHIFT
-10));
76 if (PageReserved(mem_map
+i
))
78 else if (PageSwapCache(mem_map
+i
))
80 else if (page_count(mem_map
+i
))
81 shared
+= page_count(mem_map
+i
) - 1;
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 printk("%ld pages in page table cache\n",pgtable_cache_size
);
91 * paging_init() sets up the page tables.
93 * head.S already did a lot to set up address translation for the kernel.
97 * . some 512MB regions being mapped of which the most relevant here is:
98 * . CACHED segment (ASID 0 [irrelevant], shared AND NOT user)
99 * . possible variable length regions being mapped as:
100 * . UNCACHED segment (ASID 0 [irrelevant], shared AND NOT user)
101 * . All of the memory regions are placed, independently from the platform
102 * on high addresses, above 0x80000000.
103 * . swapper_pg_dir is already cleared out by the .space directive
104 * in any case swapper does not require a real page directory since
105 * it's all kernel contained.
107 * Those pesky NULL-reference errors in the kernel are then
108 * dealt with by not mapping address 0x00000000 at all.
111 void __init
paging_init(void)
113 unsigned long zones_size
[MAX_NR_ZONES
] = {0, 0, 0};
115 pgd_init((unsigned long)swapper_pg_dir
);
116 pgd_init((unsigned long)swapper_pg_dir
+
117 sizeof(pgd_t
) * USER_PTRS_PER_PGD
);
119 mmu_context_cache
= MMU_CONTEXT_FIRST_VERSION
;
122 * All memory is good as ZONE_NORMAL (fall-through) and ZONE_DMA.
124 zones_size
[ZONE_DMA
] = MAX_LOW_PFN
- START_PFN
;
125 NODE_DATA(0)->node_mem_map
= NULL
;
126 free_area_init_node(0, NODE_DATA(0), zones_size
, __MEMORY_START
>> PAGE_SHIFT
, 0);
129 void __init
mem_init(void)
131 int codesize
, reservedpages
, datasize
, initsize
;
134 max_mapnr
= num_physpages
= MAX_LOW_PFN
- START_PFN
;
135 high_memory
= (void *)__va(MAX_LOW_PFN
* PAGE_SIZE
);
138 * Clear the zero-page.
139 * This is not required but we might want to re-use
140 * this very page to pass boot parameters, one day.
142 memset(empty_zero_page
, 0, PAGE_SIZE
);
144 /* this will put all low memory onto the freelists */
145 totalram_pages
+= free_all_bootmem_node(NODE_DATA(0));
147 for (tmp
= 0; tmp
< num_physpages
; tmp
++)
149 * Only count reserved RAM pages
151 if (PageReserved(mem_map
+tmp
))
156 codesize
= (unsigned long) &_etext
- (unsigned long) &_text
;
157 datasize
= (unsigned long) &_edata
- (unsigned long) &_etext
;
158 initsize
= (unsigned long) &__init_end
- (unsigned long) &__init_begin
;
160 printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init)\n",
161 (unsigned long) nr_free_pages() << (PAGE_SHIFT
-10),
162 max_mapnr
<< (PAGE_SHIFT
-10),
164 reservedpages
<< (PAGE_SHIFT
-10),
169 void free_initmem(void)
173 addr
= (unsigned long)(&__init_begin
);
174 for (; addr
< (unsigned long)(&__init_end
); addr
+= PAGE_SIZE
) {
175 ClearPageReserved(virt_to_page(addr
));
176 set_page_count(virt_to_page(addr
), 1);
180 printk ("Freeing unused kernel memory: %ldk freed\n", (&__init_end
- &__init_begin
) >> 10);
183 #ifdef CONFIG_BLK_DEV_INITRD
184 void free_initrd_mem(unsigned long start
, unsigned long end
)
187 for (p
= start
; p
< end
; p
+= PAGE_SIZE
) {
188 ClearPageReserved(virt_to_page(p
));
189 set_page_count(virt_to_page(p
), 1);
193 printk ("Freeing initrd memory: %ldk freed\n", (end
- start
) >> 10);