]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/blackfin/mm/init.c
Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/hskinnemoen...
[mirror_ubuntu-bionic-kernel.git] / arch / blackfin / mm / init.c
CommitLineData
1394f032
BW
1/*
2 * File: arch/blackfin/mm/init.c
3 * Based on:
4 * Author:
5 *
6 * Created:
7 * Description:
8 *
9 * Modified:
321f6e0f 10 * Copyright 2004-2007 Analog Devices Inc.
1394f032
BW
11 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30#include <linux/swap.h>
31#include <linux/bootmem.h>
1f83b8f1 32#include <linux/uaccess.h>
1394f032 33#include <asm/bfin-global.h>
1394f032
BW
34#include <asm/l1layout.h>
35#include "blackfin_sram.h"
36
37/*
38 * BAD_PAGE is the page that is used for page faults when linux
39 * is out-of-memory. Older versions of linux just did a
40 * do_exit(), but using this instead means there is less risk
41 * for a process dying in kernel mode, possibly leaving a inode
42 * unused etc..
43 *
44 * BAD_PAGETABLE is the accompanying page-table: it is initialized
45 * to point to BAD_PAGE entries.
46 *
47 * ZERO_PAGE is a special page that is used for zero-initialized
48 * data and COW.
49 */
50static unsigned long empty_bad_page_table;
51
52static unsigned long empty_bad_page;
53
54unsigned long empty_zero_page;
55
1394f032
BW
56/*
57 * paging_init() continues the virtual memory environment setup which
58 * was begun by the code in arch/head.S.
59 * The parameters are pointers to where to stick the starting and ending
60 * addresses of available kernel virtual memory.
61 */
321f6e0f 62void __init paging_init(void)
1394f032
BW
63{
64 /*
65 * make sure start_mem is page aligned, otherwise bootmem and
66 * page_alloc get different views og the world
67 */
68 unsigned long end_mem = memory_end & PAGE_MASK;
69
70 pr_debug("start_mem is %#lx virtual_end is %#lx\n", PAGE_ALIGN(memory_start), end_mem);
71
72 /*
73 * initialize the bad page table and bad page to point
74 * to a couple of allocated pages
75 */
76 empty_bad_page_table = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
77 empty_bad_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
78 empty_zero_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
79 memset((void *)empty_zero_page, 0, PAGE_SIZE);
80
81 /*
82 * Set up SFC/DFC registers (user data space)
83 */
84 set_fs(KERNEL_DS);
85
86 pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n",
87 PAGE_ALIGN(memory_start), end_mem);
88
89 {
90 unsigned long zones_size[MAX_NR_ZONES] = { 0, };
91
e3defffe
AL
92 zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT;
93 zones_size[ZONE_NORMAL] = 0;
1394f032
BW
94#ifdef CONFIG_HIGHMEM
95 zones_size[ZONE_HIGHMEM] = 0;
96#endif
97 free_area_init(zones_size);
98 }
99}
100
321f6e0f 101void __init mem_init(void)
1394f032
BW
102{
103 unsigned int codek = 0, datak = 0, initk = 0;
ee7883b7 104 unsigned int reservedpages = 0, freepages = 0;
1394f032 105 unsigned long tmp;
1394f032
BW
106 unsigned long start_mem = memory_start;
107 unsigned long end_mem = memory_end;
108
109 end_mem &= PAGE_MASK;
110 high_memory = (void *)end_mem;
111
112 start_mem = PAGE_ALIGN(start_mem);
113 max_mapnr = num_physpages = MAP_NR(high_memory);
856783b3 114 printk(KERN_DEBUG "Kernel managed physical pages: %lu\n", num_physpages);
1394f032
BW
115
116 /* This will put all memory onto the freelists. */
117 totalram_pages = free_all_bootmem();
118
ee7883b7
YL
119 reservedpages = 0;
120 for (tmp = 0; tmp < max_mapnr; tmp++)
121 if (PageReserved(pfn_to_page(tmp)))
122 reservedpages++;
123 freepages = max_mapnr - reservedpages;
124
125 /* do not count in kernel image between _rambase and _ramstart */
126 reservedpages -= (_ramstart - _rambase) >> PAGE_SHIFT;
127#if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
856783b3 128 reservedpages += (_ramend - memory_end - DMA_UNCACHED_REGION) >> PAGE_SHIFT;
ee7883b7
YL
129#endif
130
1394f032 131 codek = (_etext - _stext) >> 10;
1394f032 132 initk = (__init_end - __init_begin) >> 10;
ee7883b7 133 datak = ((_ramstart - _rambase) >> 10) - codek - initk;
1394f032 134
1394f032 135 printk(KERN_INFO
ee7883b7 136 "Memory available: %luk/%luk RAM, "
856783b3 137 "(%uk init code, %uk kernel code, %uk data, %uk dma, %uk reserved)\n",
ee7883b7 138 (unsigned long) freepages << (PAGE_SHIFT-10), _ramend >> 10,
856783b3 139 initk, codek, datak, DMA_UNCACHED_REGION >> 10, (reservedpages << (PAGE_SHIFT-10)));
5d481f49
SZ
140}
141
142static int __init sram_init(void)
143{
144 unsigned long tmp;
1394f032
BW
145
146 /* Initialize the blackfin L1 Memory. */
5d481f49 147 bfin_sram_init();
1394f032
BW
148
149 /* Allocate this once; never free it. We assume this gives us a
150 pointer to the start of L1 scratchpad memory; panic if it
151 doesn't. */
152 tmp = (unsigned long)l1sram_alloc(sizeof(struct l1_scratch_task_info));
153 if (tmp != (unsigned long)L1_SCRATCH_TASK_INFO) {
154 printk(KERN_EMERG "mem_init(): Did not get the right address from l1sram_alloc: %08lx != %08lx\n",
155 tmp, (unsigned long)L1_SCRATCH_TASK_INFO);
156 panic("No L1, time to give up\n");
157 }
5d481f49
SZ
158
159 return 0;
1394f032 160}
5d481f49 161pure_initcall(sram_init);
1394f032 162
c051489d 163static void __init free_init_pages(const char *what, unsigned long begin, unsigned long end)
1394f032 164{
1d189474
MF
165 unsigned long addr;
166 /* next to check that the page we free is not a partial page */
167 for (addr = begin; addr + PAGE_SIZE <= end; addr += PAGE_SIZE) {
168 ClearPageReserved(virt_to_page(addr));
169 init_page_count(virt_to_page(addr));
170 free_page(addr);
1394f032 171 totalram_pages++;
1394f032 172 }
1d189474
MF
173 printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
174}
175
176#ifdef CONFIG_BLK_DEV_INITRD
177void __init free_initrd_mem(unsigned long start, unsigned long end)
178{
b97b8a99 179#ifndef CONFIG_MPU
1d189474 180 free_init_pages("initrd memory", start, end);
b97b8a99 181#endif
1394f032
BW
182}
183#endif
184
c051489d 185void __init_refok free_initmem(void)
1394f032 186{
b97b8a99 187#if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU
1d189474
MF
188 free_init_pages("unused kernel memory",
189 (unsigned long)(&__init_begin),
190 (unsigned long)(&__init_end));
1394f032
BW
191#endif
192}