]>
git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - arch/csky/mm/init.c
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
5 #include <linux/module.h>
6 #include <linux/init.h>
7 #include <linux/signal.h>
8 #include <linux/sched.h>
9 #include <linux/kernel.h>
10 #include <linux/errno.h>
11 #include <linux/string.h>
12 #include <linux/types.h>
13 #include <linux/pagemap.h>
14 #include <linux/ptrace.h>
15 #include <linux/mman.h>
17 #include <linux/highmem.h>
18 #include <linux/memblock.h>
19 #include <linux/swap.h>
20 #include <linux/proc_fs.h>
21 #include <linux/pfn.h>
23 #include <asm/setup.h>
24 #include <asm/cachectl.h>
26 #include <asm/pgtable.h>
27 #include <asm/pgalloc.h>
28 #include <asm/mmu_context.h>
29 #include <asm/sections.h>
32 pgd_t swapper_pg_dir
[PTRS_PER_PGD
] __page_aligned_bss
;
33 pte_t invalid_pte_table
[PTRS_PER_PTE
] __page_aligned_bss
;
34 unsigned long empty_zero_page
[PAGE_SIZE
/ sizeof(unsigned long)]
36 EXPORT_SYMBOL(empty_zero_page
);
38 void __init
mem_init(void)
43 max_mapnr
= highend_pfn
;
45 max_mapnr
= max_low_pfn
;
47 high_memory
= (void *) __va(max_low_pfn
<< PAGE_SHIFT
);
52 for (tmp
= highstart_pfn
; tmp
< highend_pfn
; tmp
++) {
53 struct page
*page
= pfn_to_page(tmp
);
55 /* FIXME not sure about */
56 if (!memblock_is_reserved(tmp
<< PAGE_SHIFT
))
57 free_highmem_page(page
);
60 mem_init_print_info(NULL
);
63 #ifdef CONFIG_BLK_DEV_INITRD
64 void free_initrd_mem(unsigned long start
, unsigned long end
)
67 pr_info("Freeing initrd memory: %ldk freed\n",
70 for (; start
< end
; start
+= PAGE_SIZE
) {
71 ClearPageReserved(virt_to_page(start
));
72 init_page_count(virt_to_page(start
));
79 extern char __init_begin
[], __init_end
[];
81 void free_initmem(void)
85 addr
= (unsigned long) &__init_begin
;
87 while (addr
< (unsigned long) &__init_end
) {
88 ClearPageReserved(virt_to_page(addr
));
89 init_page_count(virt_to_page(addr
));
95 pr_info("Freeing unused kernel memory: %dk freed\n",
96 ((unsigned int)&__init_end
- (unsigned int)&__init_begin
) >> 10);
99 void pgd_init(unsigned long *p
)
103 for (i
= 0; i
< PTRS_PER_PGD
; i
++)
104 p
[i
] = __pa(invalid_pte_table
);
107 void __init
pre_mmu_init(void)
110 * Setup page-table and enable TLB-hardrefill
113 pgd_init((unsigned long *)swapper_pg_dir
);
114 TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir
);
115 TLBMISS_HANDLER_SETUP_PGD_KERNEL(swapper_pg_dir
);
117 asid_cache(smp_processor_id()) = ASID_FIRST_VERSION
;
119 /* Setup page mask to 4k */
120 write_mmu_pagemask(0);