1 /* init.c: memory initialisation for FRV
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 * - linux/arch/m68knommu/mm/init.c
13 * - Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>, Kenneth Albanowski <kjahds@kjahds.com>,
14 * - Copyright (C) 2000 Lineo, Inc. (www.lineo.com)
15 * - linux/arch/m68k/mm/init.c
16 * - Copyright (C) 1995 Hamish Macdonald
19 #include <linux/signal.h>
20 #include <linux/sched.h>
21 #include <linux/sched/task.h>
22 #include <linux/pagemap.h>
23 #include <linux/gfp.h>
24 #include <linux/swap.h>
26 #include <linux/kernel.h>
27 #include <linux/string.h>
28 #include <linux/types.h>
29 #include <linux/bootmem.h>
30 #include <linux/highmem.h>
31 #include <linux/module.h>
33 #include <asm/setup.h>
34 #include <asm/segment.h>
36 #include <asm/pgtable.h>
37 #include <asm/mmu_context.h>
38 #include <asm/virtconvert.h>
39 #include <asm/sections.h>
45 * BAD_PAGE is the page that is used for page faults when linux
46 * is out-of-memory. Older versions of linux just did a
47 * do_exit(), but using this instead means there is less risk
48 * for a process dying in kernel mode, possibly leaving a inode
51 * BAD_PAGETABLE is the accompanying page-table: it is initialized
52 * to point to BAD_PAGE entries.
54 * ZERO_PAGE is a special page that is used for zero-initialized
57 static unsigned long empty_bad_page_table
;
58 static unsigned long empty_bad_page
;
60 unsigned long empty_zero_page
;
61 EXPORT_SYMBOL(empty_zero_page
);
63 /*****************************************************************************/
65 * paging_init() continues the virtual memory environment setup which
66 * was begun by the code in arch/head.S.
67 * The parameters are pointers to where to stick the starting and ending
68 * addresses of available kernel virtual memory.
70 void __init
paging_init(void)
72 unsigned long zones_size
[MAX_NR_ZONES
] = {0, };
74 /* allocate some pages for kernel housekeeping tasks */
75 empty_bad_page_table
= (unsigned long) alloc_bootmem_pages(PAGE_SIZE
);
76 empty_bad_page
= (unsigned long) alloc_bootmem_pages(PAGE_SIZE
);
77 empty_zero_page
= (unsigned long) alloc_bootmem_pages(PAGE_SIZE
);
79 memset((void *) empty_zero_page
, 0, PAGE_SIZE
);
82 if (get_num_physpages() - num_mappedpages
) {
87 pkmap_page_table
= alloc_bootmem_pages(PAGE_SIZE
);
89 pge
= swapper_pg_dir
+ pgd_index_k(PKMAP_BASE
);
90 pue
= pud_offset(pge
, PKMAP_BASE
);
91 pme
= pmd_offset(pue
, PKMAP_BASE
);
92 __set_pmd(pme
, virt_to_phys(pkmap_page_table
) | _PAGE_TABLE
);
96 /* distribute the allocatable pages across the various zones and pass them to the allocator
98 zones_size
[ZONE_NORMAL
] = max_low_pfn
- min_low_pfn
;
100 zones_size
[ZONE_HIGHMEM
] = get_num_physpages() - num_mappedpages
;
103 free_area_init(zones_size
);
106 /* initialise init's MMU context */
107 init_new_context(&init_task
, &init_mm
);
110 } /* end paging_init() */
112 /*****************************************************************************/
116 void __init
mem_init(void)
118 unsigned long code_size
= _etext
- _stext
;
120 /* this will put all low memory onto the freelists */
122 #if defined(CONFIG_MMU) && defined(CONFIG_HIGHMEM)
126 for (pfn
= get_num_physpages() - 1;
127 pfn
>= num_mappedpages
; pfn
--)
128 free_highmem_page(&mem_map
[pfn
]);
132 mem_init_print_info(NULL
);
133 if (rom_length
> 0 && rom_length
>= code_size
)
134 printk("Memory available: %luKiB/%luKiB ROM\n",
135 (rom_length
- code_size
) >> 10, rom_length
>> 10);
136 } /* end mem_init() */
138 /*****************************************************************************/
140 * free the memory that was only required for initialisation
142 void free_initmem(void)
144 #if defined(CONFIG_RAMKERNEL) && !defined(CONFIG_PROTECT_KERNEL)
145 free_initmem_default(-1);
147 } /* end free_initmem() */
149 /*****************************************************************************/
151 * free the initial ramdisk memory
153 #ifdef CONFIG_BLK_DEV_INITRD
154 void __init
free_initrd_mem(unsigned long start
, unsigned long end
)
156 free_reserved_area((void *)start
, (void *)end
, -1, "initrd");
157 } /* end free_initrd_mem() */