2 * arch/ppc/kernel/setup.c
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 by Dan.
12 * bootup setup stuff..
15 #include <linux/config.h>
16 #include <linux/errno.h>
17 #include <linux/sched.h>
18 #include <linux/kernel.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/bootmem.h>
34 #include <linux/seq_file.h>
35 #include <linux/root_dev.h>
39 #include <asm/residual.h>
41 #include <asm/pgtable.h>
42 #include <asm/mpc8xx.h>
43 #include <asm/8xx_immap.h>
44 #include <asm/machdep.h>
45 #include <asm/bootinfo.h>
49 #include "ppc8xx_pic.h"
51 static int m8xx_set_rtc_time(unsigned long time);
52 static unsigned long m8xx_get_rtc_time(void);
53 void m8xx_calibrate_decr(void);
55 unsigned char __res[sizeof(bd_t)];
57 extern void m8xx_ide_init(void);
59 extern unsigned long find_available_memory(void);
60 extern void m8xx_cpm_reset(uint);
61 extern void rpxfb_alloc_pages(void);
63 void __attribute__ ((weak))
73 cpm_page = (int) alloc_bootmem_pages(PAGE_SIZE);
75 /* Reset the Communication Processor Module.
77 m8xx_cpm_reset(cpm_page);
84 ROOT_DEV = Root_HDA1; /* hda1 */
87 #ifdef CONFIG_BLK_DEV_INITRD
89 ROOT_DEV = Root_FD0; /* floppy */
94 #if 0 /* XXX this may need to be updated for the new bootmem stuff,
95 or possibly just deleted (see set_phys_avail() in init.c).
97 /* initrd_start and size are setup by boot/head.S and kernel/head.S */
100 if (initrd_end > *memory_end_p)
102 printk("initrd extends beyond end of memory "
103 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
104 initrd_end,*memory_end_p);
119 machine_restart(NULL);
125 /* A place holder for time base interrupts, if they are ever enabled. */
126 void timebase_interrupt(int irq, void * dev, struct pt_regs * regs)
128 printk ("timebase_interrupt()\n");
131 /* The decrementer counts at the system (internal) clock frequency divided by
132 * sixteen, or external oscillator divided by four. We force the processor
133 * to use system clock divided by sixteen.
135 void __init m8xx_calibrate_decr(void)
137 bd_t *binfo = (bd_t *)__res;
138 int freq, fp, divisor;
140 /* Unlock the SCCR. */
141 ((volatile immap_t *)IMAP_ADDR)->im_clkrstk.cark_sccrk = ~KAPWR_KEY;
142 ((volatile immap_t *)IMAP_ADDR)->im_clkrstk.cark_sccrk = KAPWR_KEY;
144 /* Force all 8xx processors to use divide by 16 processor clock. */
145 ((volatile immap_t *)IMAP_ADDR)->im_clkrst.car_sccr |= 0x02000000;
147 /* Processor frequency is MHz.
148 * The value 'fp' is the number of decrementer ticks per second.
150 fp = binfo->bi_intfreq / 16;
151 freq = fp*60; /* try to make freq/1e6 an integer */
153 printk("Decrementer Frequency = %d/%d\n", freq, divisor);
154 tb_ticks_per_jiffy = freq / HZ / divisor;
155 tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);
157 /* Perform some more timer/timebase initialization. This used
158 * to be done elsewhere, but other changes caused it to get
159 * called more than once....that is a bad thing.
161 * First, unlock all of the registers we are going to modify.
162 * To protect them from corruption during power down, registers
163 * that are maintained by keep alive power are "locked". To
164 * modify these registers we have to write the key value to
165 * the key location associated with the register.
166 * Some boards power up with these unlocked, while others
167 * are locked. Writing anything (including the unlock code?)
168 * to the unlocked registers will lock them again. So, here
169 * we guarantee the registers are locked, then we unlock them
172 ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_tbscrk = ~KAPWR_KEY;
173 ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_rtcsck = ~KAPWR_KEY;
174 ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_tbk = ~KAPWR_KEY;
175 ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_tbscrk = KAPWR_KEY;
176 ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_rtcsck = KAPWR_KEY;
177 ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_tbk = KAPWR_KEY;
179 /* Disable the RTC one second and alarm interrupts. */
180 ((volatile immap_t *)IMAP_ADDR)->im_sit.sit_rtcsc &=
181 ~(RTCSC_SIE | RTCSC_ALE);
183 ((volatile immap_t *)IMAP_ADDR)->im_sit.sit_rtcsc |=
184 (RTCSC_RTF | RTCSC_RTE);
186 /* Enabling the decrementer also enables the timebase interrupts
187 * (or from the other point of view, to get decrementer interrupts
188 * we have to enable the timebase). The decrementer interrupt
189 * is wired into the vector table, nothing to do here for that.
191 ((volatile immap_t *)IMAP_ADDR)->im_sit.sit_tbscr =
192 ((mk_int_int_mask(DEC_INTERRUPT) << 8) |
193 (TBSCR_TBF | TBSCR_TBE));
195 if (request_8xxirq(DEC_INTERRUPT, timebase_interrupt, 0, "tbint", NULL) != 0)
196 panic("Could not allocate timer IRQ!");
199 /* The RTC on the MPC8xx is an internal register.
200 * We want to protect this during power down, so we need to unlock,
201 * modify, and re-lock.
204 m8xx_set_rtc_time(unsigned long time)
206 ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_rtck = KAPWR_KEY;
207 ((volatile immap_t *)IMAP_ADDR)->im_sit.sit_rtc = time;
208 ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_rtck = ~KAPWR_KEY;
213 m8xx_get_rtc_time(void)
215 /* Get time from the RTC. */
216 return((unsigned long)(((immap_t *)IMAP_ADDR)->im_sit.sit_rtc));
220 m8xx_restart(char *cmd)
222 __volatile__ unsigned char dummy;
225 ((immap_t *)IMAP_ADDR)->im_clkrst.car_plprcr |= 0x00000080;
227 /* Clear the ME bit in MSR to cause checkstop on machine check
229 mtmsr(mfmsr() & ~0x1000);
231 dummy = ((immap_t *)IMAP_ADDR)->im_clkrst.res[0];
232 printk("Restart failed\n");
250 m8xx_show_percpuinfo(struct seq_file *m, int i)
256 seq_printf(m, "clock\t\t: %ldMHz\n"
257 "bus clock\t: %ldMHz\n",
258 bp->bi_intfreq / 1000000,
259 bp->bi_busfreq / 1000000);
264 /* Initialize the internal interrupt controller. The number of
265 * interrupts supported can vary with the processor type, and the
266 * 82xx family can have up to 64.
267 * External interrupts can be either edge or level triggered, and
268 * need to be initialized by the appropriate driver.
274 void cpm_interrupt_init(void);
276 for ( i = 0 ; i < NR_SIU_INTS ; i++ )
277 irq_desc[i].handler = &ppc8xx_pic;
279 /* We could probably incorporate the CPM into the multilevel
280 * interrupt structure.
282 cpm_interrupt_init();
283 unmask_irq(CPM_INTERRUPT);
285 #if defined(CONFIG_PCI)
286 for ( i = NR_SIU_INTS ; i < (NR_SIU_INTS + NR_8259_INTS) ; i++ )
287 irq_desc[i].handler = &i8259_pic;
288 i8259_pic.irq_offset = NR_SIU_INTS;
290 request_8xxirq(ISA_BRIDGE_INT, mbx_i8259_action, 0, "8259 cascade", NULL);
291 enable_irq(ISA_BRIDGE_INT);
295 /* -------------------------------------------------------------------- */
298 * This is a big hack right now, but it may turn into something real
301 * For the 8xx boards (at this time anyway), there is nothing to initialize
302 * associated the PROM. Rather than include all of the prom.c
303 * functions in the image just to get prom_init, all we really need right
304 * now is the initialization of the physical memory region.
306 static unsigned long __init
307 m8xx_find_end_of_memory(void)
310 extern unsigned char __res[];
312 binfo = (bd_t *)__res;
314 return binfo->bi_memsize;
318 * Now map in some of the I/O space that is generically needed
319 * or shared with multiple devices.
320 * All of this fits into the same 4Mbyte region, so it only
321 * requires one page table page. (or at least it used to -- paulus)
326 io_block_mapping(IMAP_ADDR, IMAP_ADDR, IMAP_SIZE, _PAGE_IO);
328 io_block_mapping(NVRAM_ADDR, NVRAM_ADDR, NVRAM_SIZE, _PAGE_IO);
329 io_block_mapping(MBX_CSR_ADDR, MBX_CSR_ADDR, MBX_CSR_SIZE, _PAGE_IO);
330 io_block_mapping(PCI_CSR_ADDR, PCI_CSR_ADDR, PCI_CSR_SIZE, _PAGE_IO);
332 /* Map some of the PCI/ISA I/O space to get the IDE interface.
334 io_block_mapping(PCI_ISA_IO_ADDR, PCI_ISA_IO_ADDR, 0x4000, _PAGE_IO);
335 io_block_mapping(PCI_IDE_ADDR, PCI_IDE_ADDR, 0x4000, _PAGE_IO);
337 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
338 io_block_mapping(RPX_CSR_ADDR, RPX_CSR_ADDR, RPX_CSR_SIZE, _PAGE_IO);
339 #if !defined(CONFIG_PCI)
340 io_block_mapping(_IO_BASE,_IO_BASE,_IO_BASE_SIZE, _PAGE_IO);
343 #ifdef CONFIG_HTDMSOUND
344 io_block_mapping(HIOX_CSR_ADDR, HIOX_CSR_ADDR, HIOX_CSR_SIZE, _PAGE_IO);
347 io_block_mapping(BCSR_ADDR, BCSR_ADDR, BCSR_SIZE, _PAGE_IO);
350 io_block_mapping(PCI_CSR_ADDR, PCI_CSR_ADDR, PCI_CSR_SIZE, _PAGE_IO);
355 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
356 unsigned long r6, unsigned long r7)
358 parse_bootinfo(find_bootinfo());
361 memcpy( (void *)__res,(void *)(r3+KERNELBASE), sizeof(bd_t) );
364 m8xx_setup_pci_ptrs();
367 #ifdef CONFIG_BLK_DEV_INITRD
368 /* take care of initrd if we have one */
371 initrd_start = r4 + KERNELBASE;
372 initrd_end = r5 + KERNELBASE;
374 #endif /* CONFIG_BLK_DEV_INITRD */
375 /* take care of cmd line */
378 *(char *)(r7+KERNELBASE) = 0;
379 strcpy(cmd_line, (char *)(r6+KERNELBASE));
382 ppc_md.setup_arch = m8xx_setup_arch;
383 ppc_md.show_percpuinfo = m8xx_show_percpuinfo;
384 ppc_md.irq_canonicalize = NULL;
385 ppc_md.init_IRQ = m8xx_init_IRQ;
386 ppc_md.get_irq = m8xx_get_irq;
389 ppc_md.restart = m8xx_restart;
390 ppc_md.power_off = m8xx_power_off;
391 ppc_md.halt = m8xx_halt;
393 ppc_md.time_init = NULL;
394 ppc_md.set_rtc_time = m8xx_set_rtc_time;
395 ppc_md.get_rtc_time = m8xx_get_rtc_time;
396 ppc_md.calibrate_decr = m8xx_calibrate_decr;
398 ppc_md.find_end_of_memory = m8xx_find_end_of_memory;
399 ppc_md.setup_io_mappings = m8xx_map_io;
401 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)