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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [arch/] [sh/] [mm/] [init.c] - Blame information for rev 1275

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

Line No. Rev Author Line
1 1275 phoenix
/* $Id: init.c,v 1.1.1.1 2004-04-15 01:17:15 phoenix Exp $
2
 *
3
 *  linux/arch/sh/mm/init.c
4
 *
5
 *  Copyright (C) 1999  Niibe Yutaka
6
 *
7
 *  Based on linux/arch/i386/mm/init.c:
8
 *   Copyright (C) 1995  Linus Torvalds
9
 */
10
 
11
#include <linux/config.h>
12
#include <linux/signal.h>
13
#include <linux/sched.h>
14
#include <linux/kernel.h>
15
#include <linux/errno.h>
16
#include <linux/string.h>
17
#include <linux/types.h>
18
#include <linux/ptrace.h>
19
#include <linux/mman.h>
20
#include <linux/mm.h>
21
#include <linux/swap.h>
22
#include <linux/smp.h>
23
#include <linux/init.h>
24
#ifdef CONFIG_BLK_DEV_INITRD
25
#include <linux/blk.h>
26
#endif
27
#include <linux/highmem.h>
28
#include <linux/bootmem.h>
29
 
30
#include <asm/processor.h>
31
#include <asm/system.h>
32
#include <asm/uaccess.h>
33
#include <asm/pgtable.h>
34
#include <asm/pgalloc.h>
35
#include <asm/mmu_context.h>
36
#include <asm/io.h>
37
#include <asm/tlb.h>
38
 
39
mmu_gather_t mmu_gathers[NR_CPUS];
40
 
41
/*
42
 * Cache of MMU context last used.
43
 */
44
unsigned long mmu_context_cache;
45
 
46
#ifdef CONFIG_DISCONTIGMEM
47
pg_data_t discontig_page_data[NR_NODES];
48
bootmem_data_t discontig_node_bdata[NR_NODES];
49
#endif
50
 
51
static unsigned long totalram_pages;
52
static unsigned long totalhigh_pages;
53
 
54
void show_mem(void)
55
{
56
        int i, total = 0, reserved = 0;
57
        int shared = 0, cached = 0;
58
 
59
        printk("Mem-info:\n");
60
        show_free_areas();
61
        printk("Free swap:       %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
62
        i = max_mapnr;
63
        while (i-- > 0) {
64
                total++;
65
                if (PageReserved(mem_map+i))
66
                        reserved++;
67
                else if (PageSwapCache(mem_map+i))
68
                        cached++;
69
                else if (page_count(mem_map+i))
70
                        shared += page_count(mem_map+i) - 1;
71
        }
72
        printk("%d pages of RAM\n",total);
73
        printk("%d reserved pages\n",reserved);
74
        printk("%d pages shared\n",shared);
75
        printk("%d pages swap cached\n",cached);
76
        show_buffers();
77
}
78
 
79
/* References to section boundaries */
80
 
81
extern char _text, _etext, _edata, __bss_start, _end;
82
extern char __init_begin, __init_end;
83
 
84
pgd_t swapper_pg_dir[PTRS_PER_PGD];
85
 
86
/* It'd be good if these lines were in the standard header file. */
87
#define START_PFN       (NODE_DATA(0)->bdata->node_boot_start >> PAGE_SHIFT)
88
#define MAX_LOW_PFN     (NODE_DATA(0)->bdata->node_low_pfn)
89
 
90
/*
91
 * paging_init() sets up the page tables
92
 *
93
 * This routines also unmaps the page at virtual kernel address 0, so
94
 * that we can trap those pesky NULL-reference errors in the kernel.
95
 */
96
void __init paging_init(void)
97
{
98
        int i;
99
        pgd_t * pg_dir;
100
 
101
        /* We don't need kernel mapping as hardware support that. */
102
        pg_dir = swapper_pg_dir;
103
 
104
        for (i=0; i < PTRS_PER_PGD; i++)
105
                pgd_val(pg_dir[i]) = 0;
106
 
107
        /* Enable MMU */
108
        ctrl_outl(MMU_CONTROL_INIT, MMUCR);
109
 
110
        /* The manual suggests doing some nops after turning on the MMU */
111
        asm volatile("nop;nop;nop;nop;nop;nop;");
112
 
113
        mmu_context_cache = MMU_CONTEXT_FIRST_VERSION;
114
        set_asid(mmu_context_cache & MMU_CONTEXT_ASID_MASK);
115
 
116
        {
117
                unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0};
118
                unsigned long max_dma, low, start_pfn;
119
 
120
                start_pfn = START_PFN;
121
                max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
122
                low = MAX_LOW_PFN;
123
 
124
                if (low < max_dma)
125
                        zones_size[ZONE_DMA] = low - start_pfn;
126
                else {
127
                        zones_size[ZONE_DMA] = max_dma - start_pfn;
128
                        zones_size[ZONE_NORMAL] = low - max_dma;
129
                }
130
                free_area_init_node(0, NODE_DATA(0), 0, zones_size, __MEMORY_START, 0);
131
#ifdef CONFIG_DISCONTIGMEM
132
                zones_size[ZONE_DMA] = __MEMORY_SIZE_2ND >> PAGE_SHIFT;
133
                zones_size[ZONE_NORMAL] = 0;
134
                free_area_init_node(1, NODE_DATA(1), 0, zones_size, __MEMORY_START_2ND, 0);
135
#endif
136
        }
137
}
138
 
139
void __init mem_init(void)
140
{
141
        extern unsigned long empty_zero_page[1024];
142
        int codesize, reservedpages, datasize, bsssize, initsize, pagemapsize;
143
        int tmp;
144
 
145
        max_mapnr = num_physpages = MAX_LOW_PFN - START_PFN;
146
        high_memory = (void *)__va(MAX_LOW_PFN * PAGE_SIZE);
147
 
148
        /* clear the zero-page */
149
        memset(empty_zero_page, 0, PAGE_SIZE);
150
        __flush_wback_region(empty_zero_page, PAGE_SIZE);
151
 
152
        /* this will put all low memory onto the freelists */
153
        totalram_pages += free_all_bootmem_node(NODE_DATA(0));
154
#ifdef CONFIG_DISCONTIGMEM
155
        totalram_pages += free_all_bootmem_node(NODE_DATA(1));
156
#endif
157
        reservedpages = 0;
158
        for (tmp = 0; tmp < num_physpages; tmp++)
159
                /*
160
                 * Only count reserved RAM pages
161
                 */
162
                if (PageReserved(mem_map+tmp))
163
                        reservedpages++;
164
        codesize =  (unsigned long) &_etext - (unsigned long) &_text;
165
        datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
166
        bsssize  =  (unsigned long) &_end - (unsigned long) &__bss_start;
167
        initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
168
        pagemapsize = (max_mapnr + 1)*sizeof(struct page);
169
 
170
        printk("Memory: %luk/%luk available (%dk reserved including: %dk kernel code, %dk data, %dk BSS, %dk init, %dk page map)\n",
171
               (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
172
               max_mapnr << (PAGE_SHIFT-10),
173
               reservedpages << (PAGE_SHIFT-10),
174
               codesize >> 10,
175
               datasize >> 10,
176
               bsssize >> 10,
177
               initsize >> 10,
178
               pagemapsize >> 10);
179
 
180
        p3_cache_init();
181
}
182
 
183
void free_initmem(void)
184
{
185
        unsigned long addr;
186
 
187
        addr = (unsigned long)(&__init_begin);
188
        for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
189
                ClearPageReserved(virt_to_page(addr));
190
                set_page_count(virt_to_page(addr), 1);
191
                free_page(addr);
192
                totalram_pages++;
193
        }
194
        printk (KERN_INFO "Freeing unused kernel memory: %dk freed\n", (&__init_end - &__init_begin) >> 10);
195
}
196
 
197
#ifdef CONFIG_BLK_DEV_INITRD
198
void free_initrd_mem(unsigned long start, unsigned long end)
199
{
200
        unsigned long p;
201
        for (p = start; p < end; p += PAGE_SIZE) {
202
                ClearPageReserved(virt_to_page(p));
203
                set_page_count(virt_to_page(p), 1);
204
                free_page(p);
205
                totalram_pages++;
206
        }
207
        printk (KERN_INFO "Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
208
}
209
#endif
210
 
211
void si_meminfo(struct sysinfo *val)
212
{
213
        val->totalram = totalram_pages;
214
        val->sharedram = 0;
215
        val->freeram = nr_free_pages();
216
        val->bufferram = atomic_read(&buffermem_pages);
217
        val->totalhigh = totalhigh_pages;
218
        val->freehigh = nr_free_highpages();
219
        val->mem_unit = PAGE_SIZE;
220
        return;
221
}

powered by: WebSVN 2.1.0

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