more changes on original files
[linux-2.4.git] / arch / cris / kernel / setup.c
1 /*
2  *  linux/arch/cris/kernel/setup.c
3  *
4  *  Copyright (C) 1995  Linus Torvalds
5  *  Copyright (c) 2001, 2002, 2003  Axis Communications AB
6  */
7
8 /*
9  * This file handles the architecture-dependent parts of initialization
10  */
11
12 #include <linux/errno.h>
13 #include <linux/sched.h>
14 #include <linux/kernel.h>
15 #include <linux/mm.h>
16 #include <linux/stddef.h>
17 #include <linux/unistd.h>
18 #include <linux/ptrace.h>
19 #include <linux/slab.h>
20 #include <linux/user.h>
21 #include <linux/a.out.h>
22 #include <linux/tty.h>
23 #include <linux/ioport.h>
24 #include <linux/delay.h>
25 #include <linux/config.h>
26 #include <linux/init.h>
27 #include <linux/bootmem.h>
28 #include <linux/seq_file.h>
29
30 #include <asm/segment.h>
31 #include <asm/system.h>
32 #include <asm/smp.h>
33 #include <asm/pgtable.h>
34 #include <asm/types.h>
35 #include <asm/svinto.h>
36
37 /*
38  * Setup options
39  */
40 struct drive_info_struct { char dummy[32]; } drive_info;
41 struct screen_info screen_info;
42
43 unsigned char aux_device_present;
44
45 extern int root_mountflags;
46 extern char _etext, _edata, _end;
47
48 #define COMMAND_LINE_SIZE 256
49
50 static char command_line[COMMAND_LINE_SIZE] = { 0, };
51        char saved_command_line[COMMAND_LINE_SIZE];
52
53 extern const unsigned long text_start, edata; /* set by the linker script */
54
55 extern unsigned long romfs_start, romfs_length, romfs_in_flash; /* from head.S */
56
57 /* This mainly sets up the memory area, and can be really confusing.
58  *
59  * The physical DRAM is virtually mapped into dram_start to dram_end
60  * (usually c0000000 to c0000000 + DRAM size). The physical address is
61  * given by the macro __pa().
62  *
63  * In this DRAM, the kernel code and data is loaded, in the beginning.
64  * It really starts at c0004000 to make room for some special pages - 
65  * the start address is text_start. The kernel data ends at _end. After
66  * this the ROM filesystem is appended (if there is any).
67  * 
68  * Between this address and dram_end, we have RAM pages usable to the
69  * boot code and the system.
70  *
71  */
72
73 void __init 
74 setup_arch(char **cmdline_p)
75 {
76         extern void init_etrax_debug(void);
77         unsigned long bootmap_size;
78         unsigned long start_pfn, max_pfn;
79         unsigned long memory_start;
80
81         /* register an initial console printing routine for printk's */
82
83         init_etrax_debug();
84
85         /* we should really poll for DRAM size! */
86
87         high_memory = &dram_end;
88
89         if(romfs_in_flash || !romfs_length) {
90                 /* if we have the romfs in flash, or if there is no rom filesystem,
91                  * our free area starts directly after the BSS
92                  */
93                 memory_start = (unsigned long) &_end;
94         } else {
95                 /* otherwise the free area starts after the ROM filesystem */
96                 printk(KERN_INFO "ROM fs in RAM, size %lu bytes\n",
97                        romfs_length);
98                 memory_start = romfs_start + romfs_length;
99         }
100
101         /* process 1's initial memory region is the kernel code/data */
102
103         init_mm.start_code = (unsigned long) &text_start;
104         init_mm.end_code =   (unsigned long) &_etext;
105         init_mm.end_data =   (unsigned long) &_edata;
106         init_mm.brk =        (unsigned long) &_end;
107
108 #define PFN_UP(x)       (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
109 #define PFN_DOWN(x)     ((x) >> PAGE_SHIFT)
110 #define PFN_PHYS(x)     ((x) << PAGE_SHIFT)
111
112         /* min_low_pfn points to the start of DRAM, start_pfn points
113          * to the first DRAM pages after the kernel, and max_low_pfn
114          * to the end of DRAM.
115          */
116
117         /*
118          * partially used pages are not usable - thus
119          * we are rounding upwards:
120          */
121
122         start_pfn = PFN_UP(memory_start);  /* usually c0000000 + kernel + romfs */
123         max_pfn =   PFN_DOWN((unsigned long)high_memory); /* usually c0000000 + dram size */
124
125         /*
126          * Initialize the boot-time allocator (start, end)
127          *
128          * We give it access to all our DRAM, but we could as well just have
129          * given it a small slice. No point in doing that though, unless we
130          * have non-contiguous memory and want the boot-stuff to be in, say,
131          * the smallest area.
132          *
133          * It will put a bitmap of the allocated pages in the beginning
134          * of the range we give it, but it won't mark the bitmaps pages
135          * as reserved. We have to do that ourselves below.
136          *
137          * We need to use init_bootmem_node instead of init_bootmem
138          * because our map starts at a quite high address (min_low_pfn).
139          */
140
141         max_low_pfn = max_pfn;
142         min_low_pfn = PAGE_OFFSET >> PAGE_SHIFT;
143
144         bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
145                                          min_low_pfn, 
146                                          max_low_pfn);
147
148         /* And free all memory not belonging to the kernel (addr, size) */
149
150         free_bootmem(PFN_PHYS(start_pfn), PFN_PHYS(max_pfn - start_pfn));
151
152         /*
153          * Reserve the bootmem bitmap itself as well. We do this in two
154          * steps (first step was init_bootmem()) because this catches
155          * the (very unlikely) case of us accidentally initializing the
156          * bootmem allocator with an invalid RAM area.
157          *
158          * Arguments are start, size
159          */
160
161         reserve_bootmem(PFN_PHYS(start_pfn), bootmap_size);
162
163         /* paging_init() sets up the MMU and marks all pages as reserved */
164
165         paging_init();
166
167         /* We dont use a command line yet, so just re-initialize it without
168            saving anything that might be there.  */
169
170         *cmdline_p = command_line;
171
172 #ifdef CONFIG_ETRAX_CMDLINE
173         strncpy(command_line, CONFIG_ETRAX_CMDLINE, COMMAND_LINE_SIZE);
174 #elif defined(CONFIG_ETRAX_ROOT_DEVICE)
175         strncpy(command_line, "root=", COMMAND_LINE_SIZE);
176         strncpy(command_line+5, CONFIG_ETRAX_ROOT_DEVICE,
177                         COMMAND_LINE_SIZE-5);
178 #endif
179         command_line[COMMAND_LINE_SIZE - 1] = '\0';
180
181         /* Save command line copy for /proc/cmdline */
182         
183         memcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
184         saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
185
186         /* give credit for the CRIS port */
187
188         printk(KERN_INFO "Linux/CRIS port on ETRAX 100LX (c) 2001, 2002 Axis Communications AB\n");
189
190 }
191
192 #ifdef CONFIG_PROC_FS
193 #define HAS_FPU         0x0001
194 #define HAS_MMU         0x0002
195 #define HAS_ETHERNET100 0x0004
196 #define HAS_TOKENRING   0x0008
197 #define HAS_SCSI        0x0010
198 #define HAS_ATA         0x0020
199 #define HAS_USB         0x0040
200 #define HAS_IRQ_BUG     0x0080
201 #define HAS_MMU_BUG     0x0100
202
203 static struct cpu_info {
204         char *model;
205         unsigned short cache;
206         unsigned short flags;
207 } cpu_info[] = {
208         /* The first four models will never ever run this code and are
209            only here for display.  */
210         { "ETRAX 1",         0, 0 },
211         { "ETRAX 2",         0, 0 },
212         { "ETRAX 3",         0, HAS_TOKENRING },
213         { "ETRAX 4",         0, HAS_TOKENRING | HAS_SCSI },
214         { "Unknown",         0, 0 },
215         { "Unknown",         0, 0 },
216         { "Unknown",         0, 0 },
217         { "Simulator",       8, HAS_ETHERNET100 | HAS_SCSI | HAS_ATA },
218         { "ETRAX 100",       8, HAS_ETHERNET100 | HAS_SCSI | HAS_ATA | HAS_IRQ_BUG },
219         { "ETRAX 100",       8, HAS_ETHERNET100 | HAS_SCSI | HAS_ATA },
220         { "ETRAX 100LX",     8, HAS_ETHERNET100 | HAS_SCSI | HAS_ATA | HAS_USB | HAS_MMU | HAS_MMU_BUG },
221         { "ETRAX 100LX v2",  8, HAS_ETHERNET100 | HAS_SCSI | HAS_ATA | HAS_USB | HAS_MMU  },
222         { "Unknown",         0, 0 }  /* This entry MUST be the last */
223 };
224
225 static int show_cpuinfo(struct seq_file *m, void *v)
226 {
227         unsigned long revision;
228         struct cpu_info *info;
229
230         /* read the version register in the CPU and print some stuff */
231
232         revision = rdvr();
233
234         if (revision >= sizeof cpu_info/sizeof *cpu_info)
235                 info = &cpu_info[sizeof cpu_info/sizeof *cpu_info - 1];
236         else
237                 info = &cpu_info[revision];
238
239         return seq_printf(m,
240                           "processor\t: 0\n"
241                           "cpu\t\t: CRIS\n"
242                           "cpu revision\t: %lu\n"
243                           "cpu model\t: %s\n"
244                           "cache size\t: %d kB\n"
245                           "fpu\t\t: %s\n"
246                           "mmu\t\t: %s\n"
247                           "mmu DMA bug\t: %s\n"
248                           "ethernet\t: %s Mbps\n"
249                           "token ring\t: %s\n"
250                           "scsi\t\t: %s\n"
251                           "ata\t\t: %s\n"
252                           "usb\t\t: %s\n"
253                           "bogomips\t: %lu.%02lu\n",
254
255                           revision,
256                           info->model,
257                           info->cache,
258                           info->flags & HAS_FPU ? "yes" : "no",
259                           info->flags & HAS_MMU ? "yes" : "no",
260                           info->flags & HAS_MMU_BUG ? "yes" : "no",
261                           info->flags & HAS_ETHERNET100 ? "10/100" : "10",
262                           info->flags & HAS_TOKENRING ? "4/16 Mbps" : "no",
263                           info->flags & HAS_SCSI ? "yes" : "no",
264                           info->flags & HAS_ATA ? "yes" : "no",
265                           info->flags & HAS_USB ? "yes" : "no",
266                           (loops_per_jiffy * HZ + 500) / 500000,
267                           ((loops_per_jiffy * HZ + 500) / 5000) % 100);
268 }
269
270 static void *c_start(struct seq_file *m, loff_t *pos)
271 {
272         /* We only got one CPU... */
273         return *pos < 1 ? (void *)1 : NULL;
274 }
275
276 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
277 {
278         ++*pos;
279         return NULL;
280 }
281
282 static void c_stop(struct seq_file *m, void *v)
283 {
284 }
285
286 struct seq_operations cpuinfo_op = {
287         start:  c_start,
288         next:   c_next,
289         stop:   c_stop,
290         show:   show_cpuinfo,
291 };
292
293 #endif /* CONFIG_PROC_FS */