VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / arch / ppc / syslib / m8260_setup.c
1 /*
2  *  arch/ppc/kernel/setup.c
3  *
4  *  Copyright (C) 1995  Linus Torvalds
5  *  Adapted from 'alpha' version by Gary Thomas
6  *  Modified by Cort Dougan (cort@cs.nmt.edu)
7  *  Modified for MBX using prep/chrp/pmac functions by Dan (dmalek@jlc.net)
8  *  Further modified for generic 8xx and 8260 by Dan.
9  */
10
11 /*
12  * bootup setup stuff..
13  */
14
15 #include <linux/config.h>
16 #include <linux/errno.h>
17 #include <linux/sched.h>
18 #include <linux/kernel.h>
19 #include <linux/mm.h>
20 #include <linux/stddef.h>
21 #include <linux/unistd.h>
22 #include <linux/ptrace.h>
23 #include <linux/slab.h>
24 #include <linux/user.h>
25 #include <linux/a.out.h>
26 #include <linux/tty.h>
27 #include <linux/major.h>
28 #include <linux/interrupt.h>
29 #include <linux/reboot.h>
30 #include <linux/init.h>
31 #include <linux/initrd.h>
32 #include <linux/ioport.h>
33 #include <linux/ide.h>
34 #include <linux/seq_file.h>
35
36 #include <asm/mmu.h>
37 #include <asm/residual.h>
38 #include <asm/io.h>
39 #include <asm/pgtable.h>
40 #include <asm/ide.h>
41 #include <asm/mpc8260.h>
42 #include <asm/immap_cpm2.h>
43 #include <asm/machdep.h>
44 #include <asm/bootinfo.h>
45 #include <asm/time.h>
46
47 #include "cpm2_pic.h"
48
49 static int m8260_set_rtc_time(unsigned long time);
50 static unsigned long m8260_get_rtc_time(void);
51 static void m8260_calibrate_decr(void);
52
53 unsigned char __res[sizeof(bd_t)];
54
55 extern void cpm2_reset(void);
56 extern void m8260_find_bridges(void);
57 extern void idma_pci9_init(void);
58
59 static void __init
60 m8260_setup_arch(void)
61 {
62         /* Reset the Communication Processor Module.
63         */
64         cpm2_reset();
65 #ifdef CONFIG_8260_PCI9
66         /* Initialise IDMA for PCI erratum workaround */
67         idma_pci9_init();
68 #endif
69 #ifdef CONFIG_PCI_8260
70         m8260_find_bridges();
71 #endif
72 }
73
74 /* The decrementer counts at the system (internal) clock frequency
75  * divided by four.
76  */
77 static void __init
78 m8260_calibrate_decr(void)
79 {
80         bd_t    *binfo = (bd_t *)__res;
81         int freq, divisor;
82
83         freq = binfo->bi_busfreq;
84         divisor = 4;
85         tb_ticks_per_jiffy = freq / HZ / divisor;
86         tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);
87 }
88
89 /* The 8260 has an internal 1-second timer update register that
90  * we should use for this purpose.
91  */
92 static uint rtc_time;
93
94 static int
95 m8260_set_rtc_time(unsigned long time)
96 {
97         rtc_time = time;
98
99         return(0);
100 }
101
102 static unsigned long
103 m8260_get_rtc_time(void)
104 {
105         /* Get time from the RTC.
106         */
107         return((unsigned long)rtc_time);
108 }
109
110 #ifndef BOOTROM_RESTART_ADDR
111 #warning "Using default BOOTROM_RESTART_ADDR!"
112 #define BOOTROM_RESTART_ADDR    0xff000104
113 #endif
114
115 static void
116 m8260_restart(char *cmd)
117 {
118         extern void m8260_gorom(bd_t *bi, uint addr);
119         uint    startaddr;
120
121         /* Most boot roms have a warmstart as the second instruction
122          * of the reset vector.  If that doesn't work for you, change this
123          * or the reboot program to send a proper address.
124          */
125         startaddr = BOOTROM_RESTART_ADDR;
126         if (cmd != NULL) {
127                 if (!strncmp(cmd, "startaddr=", 10))
128                         startaddr = simple_strtoul(&cmd[10], NULL, 0);
129         }
130
131         m8260_gorom((void*)__pa(__res), startaddr);
132 }
133
134 static void
135 m8260_halt(void)
136 {
137         local_irq_disable();
138         while (1);
139 }
140
141 static void
142 m8260_power_off(void)
143 {
144         m8260_halt();
145 }
146
147 static int
148 m8260_show_percpuinfo(struct seq_file *m, int i)
149 {
150         bd_t    *bp;
151
152         bp = (bd_t *)__res;
153
154         seq_printf(m, "core clock\t: %ld MHz\n"
155                    "CPM  clock\t: %ld MHz\n"
156                    "bus  clock\t: %ld MHz\n",
157                    bp->bi_intfreq / 1000000,
158                    bp->bi_cpmfreq / 1000000,
159                    bp->bi_busfreq / 1000000);
160         return 0;
161 }
162
163 /* Initialize the internal interrupt controller.  The number of
164  * interrupts supported can vary with the processor type, and the
165  * 8260 family can have up to 64.
166  * External interrupts can be either edge or level triggered, and
167  * need to be initialized by the appropriate driver.
168  */
169 static void __init
170 m8260_init_IRQ(void)
171 {
172         int i;
173         void cpm_interrupt_init(void);
174
175         for ( i = 0 ; i < NR_SIU_INTS ; i++ )
176                 irq_desc[i].handler = &cpm2_pic;
177
178         /* Initialize the default interrupt mapping priorities,
179          * in case the boot rom changed something on us.
180          */
181         cpm2_immr->im_intctl.ic_sicr = 0;
182         cpm2_immr->im_intctl.ic_siprr = 0x05309770;
183         cpm2_immr->im_intctl.ic_scprrh = 0x05309770;
184         cpm2_immr->im_intctl.ic_scprrl = 0x05309770;
185 }
186
187 /*
188  * Same hack as 8xx
189  */
190 static unsigned long __init
191 m8260_find_end_of_memory(void)
192 {
193         bd_t    *binfo;
194         extern unsigned char __res[];
195
196         binfo = (bd_t *)__res;
197
198         return binfo->bi_memsize;
199 }
200
201 /* Map the IMMR, plus anything else we can cover
202  * in that upper space according to the memory controller
203  * chip select mapping.  Grab another bunch of space
204  * below that for stuff we can't cover in the upper.
205  */
206 static void __init
207 m8260_map_io(void)
208 {
209         uint addr;
210
211         /* Map IMMR region to a 256MB BAT */
212         addr = (cpm2_immr != NULL) ? (uint)cpm2_immr : CPM_MAP_ADDR;
213         io_block_mapping(addr, addr, 0x10000000, _PAGE_IO);
214
215         /* Map I/O region to a 256MB BAT */
216         io_block_mapping(IO_VIRT_ADDR, IO_PHYS_ADDR, 0x10000000, _PAGE_IO);
217 }
218
219 /* Inputs:
220  *   r3 - Optional pointer to a board information structure.
221  *   r4 - Optional pointer to the physical starting address of the init RAM
222  *        disk.
223  *   r5 - Optional pointer to the physical ending address of the init RAM
224  *        disk.
225  *   r6 - Optional pointer to the physical starting address of any kernel
226  *        command-line parameters.
227  *   r7 - Optional pointer to the physical ending address of any kernel
228  *        command-line parameters.
229  */
230 void __init
231 m8260_init(unsigned long r3, unsigned long r4, unsigned long r5,
232               unsigned long r6, unsigned long r7)
233 {
234         parse_bootinfo(find_bootinfo());
235
236         if ( r3 )
237                 memcpy( (void *)__res,(void *)(r3+KERNELBASE), sizeof(bd_t) );
238
239 #ifdef CONFIG_BLK_DEV_INITRD
240         /* take care of initrd if we have one */
241         if ( r4 ) {
242                 initrd_start = r4 + KERNELBASE;
243                 initrd_end = r5 + KERNELBASE;
244         }
245 #endif /* CONFIG_BLK_DEV_INITRD */
246         /* take care of cmd line */
247         if ( r6 ) {
248                 *(char *)(r7+KERNELBASE) = 0;
249                 strcpy(cmd_line, (char *)(r6+KERNELBASE));
250         }
251
252         ppc_md.setup_arch               = m8260_setup_arch;
253         ppc_md.show_percpuinfo          = m8260_show_percpuinfo;
254         ppc_md.irq_canonicalize = NULL;
255         ppc_md.init_IRQ                 = m8260_init_IRQ;
256         ppc_md.get_irq                  = cpm2_get_irq;
257         ppc_md.init                     = NULL;
258
259         ppc_md.restart                  = m8260_restart;
260         ppc_md.power_off                = m8260_power_off;
261         ppc_md.halt                     = m8260_halt;
262
263         ppc_md.time_init                = NULL;
264         ppc_md.set_rtc_time             = m8260_set_rtc_time;
265         ppc_md.get_rtc_time             = m8260_get_rtc_time;
266         ppc_md.calibrate_decr           = m8260_calibrate_decr;
267
268         ppc_md.find_end_of_memory       = m8260_find_end_of_memory;
269         ppc_md.setup_io_mappings        = m8260_map_io;
270 }