ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / cris / mm / init.c
1 /*
2  *  linux/arch/cris/mm/init.c
3  *
4  *  Copyright (C) 1995  Linus Torvalds
5  *  Copyright (C) 2000,2001  Axis Communications AB
6  *
7  *  Authors:  Bjorn Wesen (bjornw@axis.com)
8  *
9  *  $Log: init.c,v $
10  *  Revision 1.9  2003/07/04 08:27:54  starvik
11  *  Merge of Linux 2.5.74
12  *
13  *  Revision 1.8  2003/04/09 05:20:48  starvik
14  *  Merge of Linux 2.5.67
15  *
16  *  Revision 1.7  2003/01/22 06:48:38  starvik
17  *  Fixed warnings issued by GCC 3.2.1
18  *
19  *  Revision 1.6  2002/12/11 14:44:48  starvik
20  *  Extracted v10 (ETRAX 100LX) specific stuff to arch/cris/arch-v10/mm
21  *
22  *  Revision 1.5  2002/11/18 07:37:37  starvik
23  *  Added cache bug workaround (from Linux 2.4)
24  *
25  *  Revision 1.4  2002/11/13 15:40:24  starvik
26  *  Removed the page table cache stuff (as done in other archs)
27  *
28  *  Revision 1.3  2002/11/05 06:45:13  starvik
29  *  Merge of Linux 2.5.45
30  *
31  *  Revision 1.2  2001/12/18 13:35:22  bjornw
32  *  Applied the 2.4.13->2.4.16 CRIS patch to 2.5.1 (is a copy of 2.4.15).
33  *
34  *  Revision 1.31  2001/11/13 16:22:00  bjornw
35  *  Skip calculating totalram and sharedram in si_meminfo
36  *
37  *  Revision 1.30  2001/11/12 19:02:10  pkj
38  *  Fixed compiler warnings.
39  *
40  *  Revision 1.29  2001/07/25 16:09:50  bjornw
41  *  val->sharedram will stay 0
42  *
43  *  Revision 1.28  2001/06/28 16:30:17  bjornw
44  *  Oops. This needs to wait until 2.4.6 is merged
45  *
46  *  Revision 1.27  2001/06/28 14:04:07  bjornw
47  *  Fill in sharedram
48  *
49  *  Revision 1.26  2001/06/18 06:36:02  hp
50  *  Enable free_initmem of __init-type pages
51  *
52  *  Revision 1.25  2001/06/13 00:02:23  bjornw
53  *  Use a separate variable to store the current pgd to avoid races in schedule
54  *
55  *  Revision 1.24  2001/05/15 00:52:20  hp
56  *  Only map segment 0xa as seg if CONFIG_JULIETTE
57  *
58  *  Revision 1.23  2001/04/04 14:35:40  bjornw
59  *  * Removed get_pte_slow and friends (2.4.3 change)
60  *  * Removed bad_pmd handling (2.4.3 change)
61  *
62  *  Revision 1.22  2001/04/04 13:38:04  matsfg
63  *  Moved ioremap to a separate function instead
64  *
65  *  Revision 1.21  2001/03/27 09:28:33  bjornw
66  *  ioremap used too early - lets try it in mem_init instead
67  *
68  *  Revision 1.20  2001/03/23 07:39:21  starvik
69  *  Corrected according to review remarks
70  *
71  *  Revision 1.19  2001/03/15 14:25:17  bjornw
72  *  More general shadow registers and ioremaped addresses for external I/O
73  *
74  *  Revision 1.18  2001/02/23 12:46:44  bjornw
75  *  * 0xc was not CSE1; 0x8 is, same as uncached flash, so we move the uncached
76  *    flash during CRIS_LOW_MAP from 0xe to 0x8 so both the flash and the I/O
77  *    is mapped straight over (for !CRIS_LOW_MAP the uncached flash is still 0xe)
78  *
79  *  Revision 1.17  2001/02/22 15:05:21  bjornw
80  *  Map 0x9 straight over during LOW_MAP to allow for memory mapped LEDs
81  *
82  *  Revision 1.16  2001/02/22 15:02:35  bjornw
83  *  Map 0xc straight over during LOW_MAP to allow for memory mapped I/O
84  *
85  *  Revision 1.15  2001/01/10 21:12:10  bjornw
86  *  loops_per_sec -> loops_per_jiffy
87  *
88  *  Revision 1.14  2000/11/22 16:23:20  bjornw
89  *  Initialize totalhigh counters to 0 to make /proc/meminfo look nice.
90  *
91  *  Revision 1.13  2000/11/21 16:37:51  bjornw
92  *  Temporarily disable initmem freeing
93  *
94  *  Revision 1.12  2000/11/21 13:55:07  bjornw
95  *  Use CONFIG_CRIS_LOW_MAP for the low VM map instead of explicit CPU type
96  *
97  *  Revision 1.11  2000/10/06 12:38:22  bjornw
98  *  Cast empty_bad_page correctly (should really be of * type from the start..
99  *
100  *  Revision 1.10  2000/10/04 16:53:57  bjornw
101  *  Fix memory-map due to LX features
102  *
103  *  Revision 1.9  2000/09/13 15:47:49  bjornw
104  *  Wrong count in reserved-pages loop
105  *
106  *  Revision 1.8  2000/09/13 14:35:10  bjornw
107  *  2.4.0-test8 added a new arg to free_area_init_node
108  *
109  *  Revision 1.7  2000/08/17 15:35:55  bjornw
110  *  2.4.0-test6 removed MAP_NR and inserted virt_to_page
111  *
112  *
113  */
114
115 #include <linux/init.h>
116 #include <linux/bootmem.h>
117 #include <asm/tlb.h>
118
119 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
120
121 unsigned long empty_zero_page;
122
123 extern unsigned long loops_per_jiffy; /* init/main.c */
124 unsigned long loops_per_usec;
125
126 extern char _stext, _edata, _etext; /* From linkerscript */
127 extern char __init_begin, __init_end;
128
129 void 
130 show_mem(void)
131 {
132         int i,free = 0,total = 0,cached = 0, reserved = 0, nonshared = 0;
133         int shared = 0;
134
135         printk("\nMem-info:\n");
136         show_free_areas();
137         printk("Free swap:       %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
138         i = max_mapnr;
139         while (i-- > 0) {
140                 total++;
141                 if (PageReserved(mem_map+i))
142                         reserved++;
143                 else if (PageSwapCache(mem_map+i))
144                         cached++;
145                 else if (!page_count(mem_map+i))
146                         free++;
147                 else if (page_count(mem_map+i) == 1)
148                         nonshared++;
149                 else
150                         shared += page_count(mem_map+i) - 1;
151         }
152         printk("%d pages of RAM\n",total);
153         printk("%d free pages\n",free);
154         printk("%d reserved pages\n",reserved);
155         printk("%d pages nonshared\n",nonshared);
156         printk("%d pages shared\n",shared);
157         printk("%d pages swap cached\n",cached);
158 }
159
160 void __init
161 mem_init(void)
162 {
163         int codesize, reservedpages, datasize, initsize;
164         unsigned long tmp;
165
166         if(!mem_map)
167                 BUG();
168
169         /* max/min_low_pfn was set by setup.c
170          * now we just copy it to some other necessary places...
171          *
172          * high_memory was also set in setup.c
173          */
174
175         max_mapnr = num_physpages = max_low_pfn - min_low_pfn;
176  
177         /* this will put all memory onto the freelists */
178         totalram_pages = free_all_bootmem();
179
180         reservedpages = 0;
181         for (tmp = 0; tmp < max_mapnr; tmp++) {
182                 /*
183                  * Only count reserved RAM pages
184                  */
185                 if (PageReserved(mem_map + tmp))
186                         reservedpages++;
187         }
188
189         codesize =  (unsigned long) &_etext - (unsigned long) &_stext;
190         datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
191         initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
192         
193         printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, "
194                "%dk init)\n" ,
195                (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
196                max_mapnr << (PAGE_SHIFT-10),
197                codesize >> 10,
198                reservedpages << (PAGE_SHIFT-10),
199                datasize >> 10,
200                initsize >> 10
201                );
202
203         /* HACK alert - calculate a loops_per_usec for asm/delay.h here
204          * since this is called just after calibrate_delay in init/main.c
205          * but before places which use udelay. cannot be in time.c since
206          * that is called _before_ calibrate_delay
207          */
208
209         loops_per_usec = (loops_per_jiffy * HZ) / 1000000;
210
211         return;
212 }
213
214 /* free the pages occupied by initialization code */
215
216 void 
217 free_initmem(void)
218 {
219         unsigned long addr;
220
221         addr = (unsigned long)(&__init_begin);
222         for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
223                 ClearPageReserved(virt_to_page(addr));
224                 set_page_count(virt_to_page(addr), 1);
225                 free_page(addr);
226                 totalram_pages++;
227         }
228         printk ("Freeing unused kernel memory: %luk freed\n", 
229                 (unsigned long)((&__init_end - &__init_begin) >> 10));
230 }