2 * linux/arch/sh/mm/init.c
4 * Copyright (C) 1999 Niibe Yutaka
5 * Copyright (C) 2002 - 2007 Paul Mundt
7 * Based on linux/arch/i386/mm/init.c:
8 * Copyright (C) 1995 Linus Torvalds
11 #include <linux/swap.h>
12 #include <linux/init.h>
13 #include <linux/bootmem.h>
14 #include <linux/proc_fs.h>
15 #include <linux/pagemap.h>
16 #include <linux/percpu.h>
18 #include <asm/mmu_context.h>
20 #include <asm/cacheflush.h>
21 #include <asm/cache.h>
23 DEFINE_PER_CPU(struct mmu_gather
, mmu_gathers
);
24 pgd_t swapper_pg_dir
[PTRS_PER_PGD
];
26 void (*copy_page
)(void *from
, void *to
);
27 void (*clear_page
)(void *to
);
31 int total
= 0, reserved
= 0, free
= 0;
32 int shared
= 0, cached
= 0, slab
= 0;
35 printk("Mem-info:\n");
38 for_each_online_pgdat(pgdat
) {
39 struct page
*page
, *end
;
42 pgdat_resize_lock(pgdat
, &flags
);
43 page
= pgdat
->node_mem_map
;
44 end
= page
+ pgdat
->node_spanned_pages
;
48 if (PageReserved(page
))
50 else if (PageSwapCache(page
))
52 else if (PageSlab(page
))
54 else if (!page_count(page
))
57 shared
+= page_count(page
) - 1;
61 pgdat_resize_unlock(pgdat
, &flags
);
64 printk("Free swap: %6ldkB\n", nr_swap_pages
<<(PAGE_SHIFT
-10));
65 printk("%d pages of RAM\n", total
);
66 printk("%d free pages\n", free
);
67 printk("%d reserved pages\n", reserved
);
68 printk("%d slab pages\n", slab
);
69 printk("%d pages shared\n", shared
);
70 printk("%d pages swap cached\n", cached
);
71 printk(KERN_INFO
"Total of %ld pages in page table cache\n",
72 quicklist_total_size());
76 static void set_pte_phys(unsigned long addr
, unsigned long phys
, pgprot_t prot
)
83 pgd
= pgd_offset_k(addr
);
89 pud
= pud_alloc(NULL
, pgd
, addr
);
95 pmd
= pmd_alloc(NULL
, pud
, addr
);
101 pte
= pte_offset_kernel(pmd
, addr
);
102 if (!pte_none(*pte
)) {
107 set_pte(pte
, pfn_pte(phys
>> PAGE_SHIFT
, prot
));
109 flush_tlb_one(get_asid(), addr
);
113 * As a performance optimization, other platforms preserve the fixmap mapping
114 * across a context switch, we don't presently do this, but this could be done
115 * in a similar fashion as to the wired TLB interface that sh64 uses (by way
116 * of the memory mapped UTLB configuration) -- this unfortunately forces us to
117 * give up a TLB entry for each mapping we want to preserve. While this may be
118 * viable for a small number of fixmaps, it's not particularly useful for
119 * everything and needs to be carefully evaluated. (ie, we may want this for
120 * the vsyscall page).
122 * XXX: Perhaps add a _PAGE_WIRED flag or something similar that we can pass
123 * in at __set_fixmap() time to determine the appropriate behavior to follow.
127 void __set_fixmap(enum fixed_addresses idx
, unsigned long phys
, pgprot_t prot
)
129 unsigned long address
= __fix_to_virt(idx
);
131 if (idx
>= __end_of_fixed_addresses
) {
136 set_pte_phys(address
, phys
, prot
);
138 #endif /* CONFIG_MMU */
140 /* References to section boundaries */
142 extern char _text
, _etext
, _edata
, __bss_start
, _end
;
143 extern char __init_begin
, __init_end
;
146 * paging_init() sets up the page tables
148 void __init
paging_init(void)
152 /* We don't need to map the kernel through the TLB, as
153 * it is permanatly mapped using P1. So clear the
155 memset(swapper_pg_dir
, 0, sizeof(swapper_pg_dir
));
157 /* Set an initial value for the MMU.TTB so we don't have to
158 * check for a null value. */
159 set_TTB(swapper_pg_dir
);
161 for_each_online_node(nid
) {
162 pg_data_t
*pgdat
= NODE_DATA(nid
);
163 unsigned long max_zone_pfns
[MAX_NR_ZONES
];
164 unsigned long low
, start_pfn
;
166 memset(max_zone_pfns
, 0, sizeof(max_zone_pfns
));
168 start_pfn
= pgdat
->bdata
->node_boot_start
>> PAGE_SHIFT
;
169 low
= pgdat
->bdata
->node_low_pfn
;
171 max_zone_pfns
[ZONE_NORMAL
] = low
;
172 add_active_range(nid
, start_pfn
, low
);
174 printk("Node %u: start_pfn = 0x%lx, low = 0x%lx\n",
175 nid
, start_pfn
, low
);
177 free_area_init_nodes(max_zone_pfns
);
179 printk("Node %u: mem_map starts at %p\n",
180 pgdat
->node_id
, pgdat
->node_mem_map
);
184 static struct kcore_list kcore_mem
, kcore_vmalloc
;
186 void __init
mem_init(void)
188 int codesize
, reservedpages
, datasize
, initsize
;
193 for_each_online_node(nid
) {
194 pg_data_t
*pgdat
= NODE_DATA(nid
);
195 unsigned long node_pages
= 0;
196 void *node_high_memory
;
199 num_physpages
+= pgdat
->node_present_pages
;
201 if (pgdat
->node_spanned_pages
)
202 node_pages
= free_all_bootmem_node(pgdat
);
204 totalram_pages
+= node_pages
;
206 for (i
= 0; i
< node_pages
; i
++)
207 if (PageReserved(pgdat
->node_mem_map
+ i
))
210 node_high_memory
= (void *)((pgdat
->node_start_pfn
+
211 pgdat
->node_spanned_pages
) <<
213 if (node_high_memory
> high_memory
)
214 high_memory
= node_high_memory
;
217 /* clear the zero-page */
218 memset(empty_zero_page
, 0, PAGE_SIZE
);
219 __flush_wback_region(empty_zero_page
, PAGE_SIZE
);
222 * Setup wrappers for copy/clear_page(), these will get overridden
223 * later in the boot process if a better method is available.
226 copy_page
= copy_page_slow
;
227 clear_page
= clear_page_slow
;
229 copy_page
= copy_page_nommu
;
230 clear_page
= clear_page_nommu
;
233 codesize
= (unsigned long) &_etext
- (unsigned long) &_text
;
234 datasize
= (unsigned long) &_edata
- (unsigned long) &_etext
;
235 initsize
= (unsigned long) &__init_end
- (unsigned long) &__init_begin
;
237 kclist_add(&kcore_mem
, __va(0), max_low_pfn
<< PAGE_SHIFT
);
238 kclist_add(&kcore_vmalloc
, (void *)VMALLOC_START
,
239 VMALLOC_END
- VMALLOC_START
);
241 printk(KERN_INFO
"Memory: %luk/%luk available (%dk kernel code, "
242 "%dk reserved, %dk data, %dk init)\n",
243 (unsigned long) nr_free_pages() << (PAGE_SHIFT
-10),
244 totalram_pages
<< (PAGE_SHIFT
-10),
246 reservedpages
<< (PAGE_SHIFT
-10),
252 /* Initialize the vDSO */
256 void free_initmem(void)
260 addr
= (unsigned long)(&__init_begin
);
261 for (; addr
< (unsigned long)(&__init_end
); addr
+= PAGE_SIZE
) {
262 ClearPageReserved(virt_to_page(addr
));
263 init_page_count(virt_to_page(addr
));
267 printk ("Freeing unused kernel memory: %dk freed\n", (&__init_end
- &__init_begin
) >> 10);
270 #ifdef CONFIG_BLK_DEV_INITRD
271 void free_initrd_mem(unsigned long start
, unsigned long end
)
274 for (p
= start
; p
< end
; p
+= PAGE_SIZE
) {
275 ClearPageReserved(virt_to_page(p
));
276 init_page_count(virt_to_page(p
));
280 printk ("Freeing initrd memory: %ldk freed\n", (end
- start
) >> 10);