OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [arch/] [armnommu/] [mm/] [init.c] - Blame information for rev 1781

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 *  linux/arch/arm/mm/init.c
3
 *
4
 *  Copyright (C) 1995, 1996  Russell King
5
 */
6
 
7
#include <linux/config.h>
8
#include <linux/signal.h>
9
#include <linux/sched.h>
10
#include <linux/head.h>
11
#include <linux/kernel.h>
12
#include <linux/errno.h>
13
#include <linux/string.h>
14
#include <linux/types.h>
15
#include <linux/ptrace.h>
16
#include <linux/mman.h>
17
#include <linux/mm.h>
18
#include <linux/swap.h>
19
#include <linux/smp.h>
20
#ifdef CONFIG_BLK_DEV_INITRD
21
#include <linux/blk.h>
22
#endif
23
 
24
#include <asm/system.h>
25
#include <asm/segment.h>
26
#include <asm/pgtable.h>
27
#include <asm/dma.h>
28
#include <asm/hardware.h>
29
#include <asm/proc/mm-init.h>
30
 
31
#define DEBUG
32
 
33
unsigned long *empty_zero_page;
34
unsigned long *empty_bad_page;
35
unsigned long max_mapnr;
36
 
37
#ifndef NO_MM
38
pgd_t swapper_pg_dir[PTRS_PER_PGD];
39
 
40
const char bad_pmd_string[] = "Bad pmd in pte_alloc: %08lx\n";
41
 
42
/*
43
 * BAD_PAGE is the page that is used for page faults when linux
44
 * is out-of-memory. Older versions of linux just did a
45
 * do_exit(), but using this instead means there is less risk
46
 * for a process dying in kernel mode, possibly leaving a inode
47
 * unused etc..
48
 *
49
 * BAD_PAGETABLE is the accompanying page-table: it is initialized
50
 * to point to BAD_PAGE entries.
51
 *
52
 * ZERO_PAGE is a special page that is used for zero-initialized
53
 * data and COW.
54
 */
55
#if PTRS_PER_PTE != 1
56
unsigned long *empty_bad_page_table;
57
 
58
pte_t *__bad_pagetable(void)
59
{
60
        int i;
61
        pte_t bad_page;
62
 
63
        bad_page = BAD_PAGE;
64
        for (i = 0; i < PTRS_PER_PTE; i++)
65
                empty_bad_page_table[i] = (unsigned long)pte_val(bad_page);
66
        return (pte_t *) empty_bad_page_table;
67
}
68
#endif
69
 
70
 
71
pte_t __bad_page(void)
72
{
73
        memzero (empty_bad_page, PAGE_SIZE);
74
        return pte_nocache(pte_mkdirty(mk_pte((unsigned long) empty_bad_page, PAGE_SHARED)));
75
}
76
 
77
#endif
78
 
79
void show_mem(void)
80
{
81
        extern void show_net_buffers(void);
82
        int i,free = 0,total = 0,reserved = 0;
83
        int shared = 0;
84
 
85
        printk("Mem-info:\n");
86
        show_free_areas();
87
#if defined(CONFIG_CPU_ARM2) || defined(CONFIG_CPU_ARM3)
88
        kmalloc_stats();
89
#endif
90
        printk("Free swap:       %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
91
        i = max_mapnr;
92
        while (i-- > 0) {
93
                total++;
94
                if (PageReserved(mem_map+i))
95
                        reserved++;
96
                else if (!mem_map[i].count)
97
                        free++;
98
                else
99
                        shared += mem_map[i].count-1;
100
        }
101
        printk("%d pages of RAM\n",total);
102
        printk("%d free pages\n",free);
103
        printk("%d reserved pages\n",reserved);
104
        printk("%d pages shared\n",shared);
105
        show_buffers();
106
#ifdef CONFIG_NET
107
        show_net_buffers();
108
#endif
109
}
110
 
111
void si_meminfo(struct sysinfo *val)
112
{
113
        int i;
114
 
115
        i = max_mapnr;
116
        val->totalram = 0;
117
        val->sharedram = 0;
118
        val->freeram = nr_free_pages << PAGE_SHIFT;
119
        val->bufferram = buffermem;
120
        while (i-- > 0)  {
121
                if (PageReserved(mem_map+i))
122
                        continue;
123
                val->totalram++;
124
                if (!mem_map[i].count)
125
                        continue;
126
                val->sharedram += mem_map[i].count-1;
127
        }
128
        val->totalram <<= PAGE_SHIFT;
129
        val->sharedram <<= PAGE_SHIFT;
130
}
131
 
132
#ifndef NO_MM
133
/*
134
 * paging_init() sets up the page tables...
135
 */
136
unsigned long paging_init(unsigned long start_mem, unsigned long end_mem)
137
{
138
        extern unsigned long free_area_init(unsigned long, unsigned long);
139
 
140
        /* We appear to need this */
141
        current_set[0] = &init_task;
142
        SET_PAGE_DIR(current, swapper_pg_dir);
143
 
144
        start_mem = PAGE_ALIGN(start_mem);
145
        empty_zero_page = (unsigned long *)start_mem;
146
        start_mem += PAGE_SIZE;
147
        empty_bad_page = (unsigned long *)start_mem;
148
        start_mem += PAGE_SIZE;
149
#if PTRS_PER_PTE != 1
150
        empty_bad_page_table = (unsigned long *)start_mem;
151
        start_mem += PTRS_PER_PTE * sizeof (void *);
152
#endif
153
        memzero (empty_zero_page, PAGE_SIZE);
154
 
155
        start_mem = setup_pagetables (start_mem, end_mem);
156
 
157
        flush_tlb_all ();
158
        update_mm_cache_all ();
159
 
160
        return free_area_init (start_mem, end_mem);
161
}
162
 
163
#else
164
 
165
extern unsigned long free_area_init(unsigned long, unsigned long);
166
 
167
unsigned long paging_init(unsigned long start_mem, unsigned long end_mem)
168
{
169
 
170
#ifdef DEBUG
171
        unsigned long mem_avail = end_mem - start_mem;
172
 
173
        printk ("memory available is %ldKB\n", mem_avail >> 10);
174
#endif
175
 
176
        /*
177
         * virtual address after end of kernel
178
         * "availmem" is setup by the code in head.S.
179
         */
180
        /*start_mem = availmem;*/
181
 
182
#ifdef DEBUG
183
        printk ("start_mem is %#lx\nvirtual_end is %#lx\n",
184
                        start_mem, end_mem);
185
#endif
186
 
187
        /*
188
         * initialize the bad page table and bad page to point
189
         * to a couple of allocated pages
190
         */
191
//      empty_bad_page_table = start_mem;
192
//      start_mem += PAGE_SIZE;
193
        empty_bad_page = (unsigned long*)start_mem;
194
        start_mem += PAGE_SIZE;
195
        empty_zero_page = (unsigned long*)start_mem;
196
        start_mem += PAGE_SIZE;
197
        memset((void *)empty_zero_page, 0, PAGE_SIZE);
198
 
199
        /*
200
         * Set up SFC/DFC registers (user data space)
201
         */
202
//      set_fs (USER_DS);
203
 
204
#ifdef DEBUG
205
        printk ("before free_area_init\n");
206
 
207
        printk ("free_area_init -> start_mem is %#lx\nvirtual_end is %#lx\n",
208
                        start_mem, end_mem);
209
#endif
210
 
211
        return PAGE_ALIGN(free_area_init (start_mem, end_mem));
212
}
213
#endif
214
 
215
/*
216
 * mem_init() marks the free areas in the mem_map and tells us how much
217
 * memory is free.  This is done after various parts of the system have
218
 * claimed their memory after the kernel image.
219
 */
220
void mem_init(unsigned long start_mem, unsigned long end_mem)
221
{
222
        extern void sound_init(void);
223
        int codepages = 0;
224
        int reservedpages = 0;
225
        int datapages = 0;
226
        unsigned long tmp;
227
 
228
        /* mark usable pages in the mem_map[] */
229
        mark_usable_memory_areas(&start_mem, end_mem);
230
 
231
        end_mem &= PAGE_MASK;
232
        high_memory = end_mem;
233
        max_mapnr = MAP_NR(end_mem);
234
 
235
        for (tmp = PAGE_OFFSET; tmp < high_memory ; tmp += PAGE_SIZE) {
236
                extern int etext;
237
                extern int _stext;
238
                if (PageReserved(mem_map+MAP_NR(tmp))) {
239
                        if (tmp < KERNTOPHYS(_stext))
240
                                reservedpages++;
241
                        else if (tmp < KERNTOPHYS(etext))
242
                                codepages++;
243
                        else
244
                                datapages++;
245
                        continue;
246
                }
247
                mem_map[MAP_NR(tmp)].count = 1;
248
#ifdef CONFIG_BLK_DEV_INITRD
249
                if (!initrd_start || (tmp < initrd_start || tmp >= initrd_end))
250
#endif
251
                        free_page(tmp);
252
        }
253
        tmp = nr_free_pages << PAGE_SHIFT;
254
        printk ("Memory: %luk/%luM available (%dk kernel code, %dk reserved, %dk data)\n",
255
                 tmp >> 10,
256
                 max_mapnr >> (20 - PAGE_SHIFT),
257
                 codepages << (PAGE_SHIFT-10),
258
                 reservedpages << (PAGE_SHIFT-10),
259
                 datapages << (PAGE_SHIFT-10));
260
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.