ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / h8300 / kernel / setup.c
1 /*
2  *  linux/arch/h8300/kernel/setup.c
3  *
4  *  Copyleft  ()) 2000       James D. Schettine {james@telos-systems.com}
5  *  Copyright (C) 1999,2000  Greg Ungerer (gerg@snapgear.com)
6  *  Copyright (C) 1998,1999  D. Jeff Dionne <jeff@lineo.ca>
7  *  Copyright (C) 1998       Kenneth Albanowski <kjahds@kjahds.com>
8  *  Copyright (C) 1995       Hamish Macdonald
9  *  Copyright (C) 2000       Lineo Inc. (www.lineo.com) 
10  *  Copyright (C) 2001       Lineo, Inc. <www.lineo.com>
11  *
12  *  H8/300 porting Yoshinori Sato <ysato@users.sourceforge.jp>
13  */
14
15 /*
16  * This file handles the architecture-dependent parts of system setup
17  */
18
19 #include <linux/config.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/delay.h>
23 #include <linux/interrupt.h>
24 #include <linux/fs.h>
25 #include <linux/fb.h>
26 #include <linux/console.h>
27 #include <linux/genhd.h>
28 #include <linux/errno.h>
29 #include <linux/string.h>
30 #include <linux/major.h>
31 #include <linux/bootmem.h>
32 #include <linux/seq_file.h>
33
34 #include <asm/setup.h>
35 #include <asm/irq.h>
36
37 #ifdef CONFIG_BLK_DEV_INITRD
38 #include <asm/pgtable.h>
39 #endif
40
41 #if defined(__H8300H__)
42 #define CPU "H8/300H"
43 #endif
44
45 #if defined(__H8300S__)
46 #define CPU "H8S"
47 #endif
48
49 #if defined(CONFIG_INTELFLASH)
50 #define BLKOFFSET 512
51 #else
52 #define BLKOFFSET 0
53 #endif
54
55 #define STUBSIZE 0xc000;
56
57 unsigned long rom_length;
58 unsigned long memory_start;
59 unsigned long memory_end;
60
61 struct task_struct *_current_task;
62
63 char command_line[512];
64 char saved_command_line[512];
65
66 extern int _stext, _etext, _sdata, _edata, _sbss, _ebss, _end;
67 extern int _ramstart, _ramend;
68 extern char _target_name[];
69 extern void h8300_gpio_init(void);
70
71 #if (defined(CONFIG_H8300H_SIM) || defined(CONFIG_H8S_SIM)) \
72     && defined(CONFIG_GDB_MAGICPRINT)
73 /* printk with gdb service */
74 static void gdb_console_output(struct console *c, const char *msg, unsigned len)
75 {
76         for (; len > 0; len--) {
77                 asm("mov.w %0,r2\n\t"
78                     "jsr @0xc4"::"r"(*msg++):"er2");
79         }
80 }
81
82 /*
83  *      Setup initial baud/bits/parity. We do two things here:
84  *      - construct a cflag setting for the first rs_open()
85  *      - initialize the serial port
86  *      Return non-zero if we didn't find a serial port.
87  */
88 static int __init gdb_console_setup(struct console *co, char *options)
89 {
90         return 0;
91 }
92
93 static const struct console gdb_console = {
94         .name           = "gdb_con",
95         .write          = gdb_console_output,
96         .device         = NULL,
97         .setup          = gdb_console_setup,
98         .flags          = CON_PRINTBUFFER,
99         .index          = -1,
100 };
101 #endif
102
103 void __init setup_arch(char **cmdline_p)
104 {
105         int bootmap_size;
106
107         memory_start = (unsigned long) &_ramstart;
108
109         /* allow for ROMFS on the end of the kernel */
110         if (memcmp((void *)(memory_start + BLKOFFSET), "-rom1fs-", 8) == 0) {
111 #if defined(CONFIG_BLK_DEV_INITRD)
112                 initrd_start = memory_start += BLKOFFSET;
113                 initrd_end = memory_start += be32_to_cpu(((unsigned long *) (memory_start))[2]);
114 #else
115                 memory_start += BLKOFFSET;
116                 memory_start += be32_to_cpu(((unsigned long *) memory_start)[2]);
117 #endif
118         }
119         memory_start = PAGE_ALIGN(memory_start);
120 #if !defined(CONFIG_BLKDEV_RESERVE)
121         memory_end = (unsigned long) &_ramend; /* by now the stack is part of the init task */
122 #if defined(CONFIG_GDB_DEBUG)
123         memory_end -= STUBSIZE;
124 #endif
125 #else
126         if ((memory_end < CONFIG_BLKDEV_RESERVE_ADDRESS) && 
127             (memory_end > CONFIG_BLKDEV_RESERVE_ADDRESS)
128             /* overlap userarea */
129             memory_end = CONFIG_BLKDEV_RESERVE_ADDRESS; 
130 #endif
131
132         init_mm.start_code = (unsigned long) &_stext;
133         init_mm.end_code = (unsigned long) &_etext;
134         init_mm.end_data = (unsigned long) &_edata;
135         init_mm.brk = (unsigned long) 0; 
136
137 #if (defined(CONFIG_H8300H_SIM) || defined(CONFIG_H8S_SIM)) && defined(CONFIG_GDB_MAGICPRINT)
138         register_console((struct console *)&gdb_console);
139 #endif
140
141         printk(KERN_INFO "\r\n\nuClinux " CPU "\n");
142         printk(KERN_INFO "Target Hardware: %s\n",_target_name);
143         printk(KERN_INFO "Flat model support (C) 1998,1999 Kenneth Albanowski, D. Jeff Dionne\n");
144         printk(KERN_INFO "H8/300 series support by Yoshinori Sato <ysato@users.sourceforge.jp>\n");
145
146 #ifdef DEBUG
147         printk(KERN_DEBUG "KERNEL -> TEXT=0x%06x-0x%06x DATA=0x%06x-0x%06x "
148                 "BSS=0x%06x-0x%06x\n", (int) &_stext, (int) &_etext,
149                 (int) &_sdata, (int) &_edata,
150                 (int) &_sbss, (int) &_ebss);
151         printk(KERN_DEBUG "KERNEL -> ROMFS=0x%06x-0x%06x MEM=0x%06x-0x%06x "
152                 "STACK=0x%06x-0x%06x\n",
153                (int) &_ebss, (int) memory_start,
154                 (int) memory_start, (int) memory_end,
155                 (int) memory_end, (int) &_ramend);
156 #endif
157
158 #ifdef CONFIG_DEFAULT_CMDLINE
159         /* set from default command line */
160         if (*command_line == '\0')
161                 strcpy(command_line,CONFIG_KERNEL_COMMAND);
162 #endif
163         /* Keep a copy of command line */
164         *cmdline_p = &command_line[0];
165         memcpy(saved_command_line, command_line, sizeof(saved_command_line));
166         saved_command_line[sizeof(saved_command_line)-1] = 0;
167
168 #ifdef DEBUG
169         if (strlen(*cmdline_p)) 
170                 printk(KERN_DEBUG "Command line: '%s'\n", *cmdline_p);
171 #endif
172
173         /*
174          * give all the memory to the bootmap allocator,  tell it to put the
175          * boot mem_map at the start of memory
176          */
177         bootmap_size = init_bootmem_node(
178                         NODE_DATA(0),
179                         memory_start >> PAGE_SHIFT, /* map goes here */
180                         PAGE_OFFSET >> PAGE_SHIFT,      /* 0 on coldfire */
181                         memory_end >> PAGE_SHIFT);
182         /*
183          * free the usable memory,  we have to make sure we do not free
184          * the bootmem bitmap so we then reserve it after freeing it :-)
185          */
186         free_bootmem(memory_start, memory_end - memory_start);
187         reserve_bootmem(memory_start, bootmap_size);
188         /*
189          * get kmalloc into gear
190          */
191         paging_init();
192         h8300_gpio_init();
193 #ifdef DEBUG
194         printk(KERN_DEBUG "Done setup_arch\n");
195 #endif
196 }
197
198 /*
199  *      Get CPU information for use by the procfs.
200  */
201
202 static int show_cpuinfo(struct seq_file *m, void *v)
203 {
204     char *cpu;
205     int mode;
206     u_long clockfreq;
207
208     cpu = CPU;
209     mode = *(volatile unsigned char *)MDCR & 0x07;
210
211     clockfreq = CONFIG_CPU_CLOCK;
212
213     seq_printf(m,  "CPU:\t\t%s (mode:%d)\n"
214                    "Clock:\t\t%lu.%1luMHz\n"
215                    "BogoMips:\t%lu.%02lu\n"
216                    "Calibration:\t%lu loops\n",
217                    cpu,mode,
218                    clockfreq/100,clockfreq%100,
219                    (loops_per_jiffy*HZ)/500000,((loops_per_jiffy*HZ)/5000)%100,
220                    (loops_per_jiffy*HZ));
221
222     return 0;
223 }
224
225 static void *c_start(struct seq_file *m, loff_t *pos)
226 {
227         return *pos < NR_CPUS ? ((void *) 0x12345678) : NULL;
228 }
229
230 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
231 {
232         ++*pos;
233         return c_start(m, pos);
234 }
235
236 static void c_stop(struct seq_file *m, void *v)
237 {
238 }
239
240 struct seq_operations cpuinfo_op = {
241         .start  = c_start,
242         .next   = c_next,
243         .stop   = c_stop,
244         .show   = show_cpuinfo,
245 };