m8xx_setup.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:11k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * BK Id: %F% %I% %G% %U% %#%
  3.  *
  4.  *  linux/arch/ppc/kernel/setup.c
  5.  *
  6.  *  Copyright (C) 1995  Linus Torvalds
  7.  *  Adapted from 'alpha' version by Gary Thomas
  8.  *  Modified by Cort Dougan (cort@cs.nmt.edu)
  9.  *  Modified for MBX using prep/chrp/pmac functions by Dan (dmalek@jlc.net)
  10.  *  Further modified for generic 8xx by Dan.
  11.  */
  12. /*
  13.  * bootup setup stuff..
  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/blk.h>
  32. #include <linux/ioport.h>
  33. #include <linux/bootmem.h>
  34. #include <linux/seq_file.h>
  35. #include <asm/mmu.h>
  36. #include <asm/processor.h>
  37. #include <asm/residual.h>
  38. #include <asm/io.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/mpc8xx.h>
  41. #include <asm/8xx_immap.h>
  42. #include <asm/machdep.h>
  43. #include <asm/bootinfo.h>
  44. #include <asm/time.h>
  45. #include "ppc8xx_pic.h"
  46. static int m8xx_set_rtc_time(unsigned long time);
  47. static unsigned long m8xx_get_rtc_time(void);
  48. void m8xx_calibrate_decr(void);
  49. unsigned char __res[sizeof(bd_t)];
  50. extern void m8xx_ide_init(void);
  51. extern unsigned long find_available_memory(void);
  52. extern void m8xx_cpm_reset(uint);
  53. void __init
  54. m8xx_setup_arch(void)
  55. {
  56. int cpm_page;
  57. cpm_page = (int) alloc_bootmem_pages(PAGE_SIZE);
  58. /* Reset the Communication Processor Module.
  59. */
  60. m8xx_cpm_reset(cpm_page);
  61. #ifdef notdef
  62. ROOT_DEV = to_kdev_t(0x0301); /* hda1 */
  63. #endif
  64. #ifdef CONFIG_BLK_DEV_INITRD
  65. #if 0
  66. ROOT_DEV = to_kdev_t(0x0200); /* floppy */  
  67. rd_prompt = 1;
  68. rd_doload = 1;
  69. rd_image_start = 0;
  70. #endif
  71. #if 0 /* XXX this may need to be updated for the new bootmem stuff,
  72.    or possibly just deleted (see set_phys_avail() in init.c).
  73.    - paulus. */
  74. /* initrd_start and size are setup by boot/head.S and kernel/head.S */
  75. if ( initrd_start )
  76. {
  77. if (initrd_end > *memory_end_p)
  78. {
  79. printk("initrd extends beyond end of memory "
  80.        "(0x%08lx > 0x%08lx)ndisabling initrdn",
  81.        initrd_end,*memory_end_p);
  82. initrd_start = 0;
  83. }
  84. }
  85. #endif
  86. #endif
  87. }
  88. void
  89. abort(void)
  90. {
  91. #ifdef CONFIG_XMON
  92. xmon(0);
  93. #endif
  94. machine_restart(NULL);
  95. }
  96. /* A place holder for time base interrupts, if they are ever enabled. */
  97. void timebase_interrupt(int irq, void * dev, struct pt_regs * regs)
  98. {
  99. printk ("timebase_interrupt()n");
  100. }
  101. /* The decrementer counts at the system (internal) clock frequency divided by
  102.  * sixteen, or external oscillator divided by four.  We force the processor
  103.  * to use system clock divided by sixteen.
  104.  */
  105. void __init m8xx_calibrate_decr(void)
  106. {
  107. bd_t *binfo = (bd_t *)__res;
  108. int freq, fp, divisor;
  109. /* Unlock the SCCR. */
  110. ((volatile immap_t *)IMAP_ADDR)->im_clkrstk.cark_sccrk = ~KAPWR_KEY;
  111. ((volatile immap_t *)IMAP_ADDR)->im_clkrstk.cark_sccrk = KAPWR_KEY;
  112. /* Force all 8xx processors to use divide by 16 processor clock. */
  113. ((volatile immap_t *)IMAP_ADDR)->im_clkrst.car_sccr |= 0x02000000;
  114. /* Processor frequency is MHz.
  115.  * The value 'fp' is the number of decrementer ticks per second.
  116.  */
  117. fp = binfo->bi_intfreq / 16;
  118. freq = fp*60; /* try to make freq/1e6 an integer */
  119.         divisor = 60;
  120.         printk("Decrementer Frequency = %d/%dn", freq, divisor);
  121.         tb_ticks_per_jiffy = freq / HZ / divisor;
  122. tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);
  123. /* Perform some more timer/timebase initialization.  This used
  124.  * to be done elsewhere, but other changes caused it to get
  125.  * called more than once....that is a bad thing.
  126.  *
  127.  * First, unlock all of the registers we are going to modify.
  128.  * To protect them from corruption during power down, registers
  129.  * that are maintained by keep alive power are "locked".  To
  130.  * modify these registers we have to write the key value to
  131.  * the key location associated with the register.
  132.  * Some boards power up with these unlocked, while others
  133.  * are locked.  Writing anything (including the unlock code?)
  134.  * to the unlocked registers will lock them again.  So, here
  135.  * we guarantee the registers are locked, then we unlock them
  136.  * for our use.
  137.  */
  138. ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_tbscrk = ~KAPWR_KEY;
  139. ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_rtcsck = ~KAPWR_KEY;
  140. ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_tbk    = ~KAPWR_KEY;
  141. ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_tbscrk =  KAPWR_KEY;
  142. ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_rtcsck =  KAPWR_KEY;
  143. ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_tbk    =  KAPWR_KEY;
  144. /* Disable the RTC one second and alarm interrupts. */
  145. ((volatile immap_t *)IMAP_ADDR)->im_sit.sit_rtcsc &=
  146. ~(RTCSC_SIE | RTCSC_ALE);
  147. /* Enable the RTC */
  148. ((volatile immap_t *)IMAP_ADDR)->im_sit.sit_rtcsc |=
  149. (RTCSC_RTF | RTCSC_RTE);
  150. /* Enabling the decrementer also enables the timebase interrupts
  151.  * (or from the other point of view, to get decrementer interrupts
  152.  * we have to enable the timebase).  The decrementer interrupt
  153.  * is wired into the vector table, nothing to do here for that.
  154.  */
  155. ((volatile immap_t *)IMAP_ADDR)->im_sit.sit_tbscr =
  156. ((mk_int_int_mask(DEC_INTERRUPT) << 8) |
  157.  (TBSCR_TBF | TBSCR_TBE));
  158. if (request_8xxirq(DEC_INTERRUPT, timebase_interrupt, 0, "tbint", NULL) != 0)
  159. panic("Could not allocate timer IRQ!");
  160. }
  161. /* The RTC on the MPC8xx is an internal register.
  162.  * We want to protect this during power down, so we need to unlock,
  163.  * modify, and re-lock.
  164.  */
  165. static int
  166. m8xx_set_rtc_time(unsigned long time)
  167. {
  168. ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_rtck = KAPWR_KEY;
  169. ((volatile immap_t *)IMAP_ADDR)->im_sit.sit_rtc = time;
  170. ((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_rtck = ~KAPWR_KEY;
  171. return(0);
  172. }
  173. static unsigned long
  174. m8xx_get_rtc_time(void)
  175. {
  176. /* Get time from the RTC. */
  177. return((unsigned long)(((immap_t *)IMAP_ADDR)->im_sit.sit_rtc));
  178. }
  179. static void
  180. m8xx_restart(char *cmd)
  181. {
  182. __volatile__ unsigned char dummy;
  183. uint msr;
  184. cli();
  185. ((immap_t *)IMAP_ADDR)->im_clkrst.car_plprcr |= 0x00000080;
  186. /* Clear the ME bit in MSR to cause checkstop on machine check
  187. */
  188. __asm__("mfmsr %0" : "=r" (msr) );
  189. msr &= ~0x1000;
  190. __asm__("mtmsr %0" : : "r" (msr) );
  191. dummy = ((immap_t *)IMAP_ADDR)->im_clkrst.res[0];
  192. printk("Restart failedn"); 
  193. while(1);
  194. }
  195. static void
  196. m8xx_power_off(void)
  197. {
  198.    m8xx_restart(NULL);
  199. }
  200. static void
  201. m8xx_halt(void)
  202. {
  203.    m8xx_restart(NULL);
  204. }
  205. static int
  206. m8xx_show_percpuinfo(struct seq_file *m, int i)
  207. {
  208. bd_t *bp;
  209. bp = (bd_t *)__res;
  210. seq_printf(m, "clocktt: %ldMHzn"
  211.    "bus clockt: %ldMHzn",
  212.    bp->bi_intfreq / 1000000,
  213.    bp->bi_busfreq / 1000000);
  214. return 0;
  215. }
  216. /* Initialize the internal interrupt controller.  The number of
  217.  * interrupts supported can vary with the processor type, and the
  218.  * 82xx family can have up to 64.
  219.  * External interrupts can be either edge or level triggered, and
  220.  * need to be initialized by the appropriate driver.
  221.  */
  222. static void __init
  223. m8xx_init_IRQ(void)
  224. {
  225. int i;
  226. void cpm_interrupt_init(void);
  227.         for ( i = 0 ; i < NR_SIU_INTS ; i++ )
  228.                 irq_desc[i].handler = &ppc8xx_pic;
  229. /* We could probably incorporate the CPM into the multilevel
  230.  * interrupt structure.
  231.  */
  232. cpm_interrupt_init();
  233.         unmask_irq(CPM_INTERRUPT);
  234. #if defined(CONFIG_PCI)
  235.         for ( i = NR_SIU_INTS ; i < (NR_SIU_INTS + NR_8259_INTS) ; i++ )
  236.                 irq_desc[i].handler = &i8259_pic;
  237.         i8259_pic.irq_offset = NR_SIU_INTS;
  238.         i8259_init();
  239.         request_8xxirq(ISA_BRIDGE_INT, mbx_i8259_action, 0, "8259 cascade", NULL);
  240.         enable_irq(ISA_BRIDGE_INT);
  241. #endif
  242. }
  243. /* -------------------------------------------------------------------- */
  244. /*
  245.  * This is a big hack right now, but it may turn into something real
  246.  * someday.
  247.  *
  248.  * For the 8xx boards (at this time anyway), there is nothing to initialize
  249.  * associated the PROM.  Rather than include all of the prom.c
  250.  * functions in the image just to get prom_init, all we really need right
  251.  * now is the initialization of the physical memory region.
  252.  */
  253. static unsigned long __init
  254. m8xx_find_end_of_memory(void)
  255. {
  256. bd_t *binfo;
  257. extern unsigned char __res[];
  258. binfo = (bd_t *)__res;
  259. return binfo->bi_memsize;
  260. }
  261. /*
  262.  * Now map in some of the I/O space that is generically needed
  263.  * or shared with multiple devices.
  264.  * All of this fits into the same 4Mbyte region, so it only
  265.  * requires one page table page.  (or at least it used to  -- paulus)
  266.  */
  267. static void __init
  268. m8xx_map_io(void)
  269. {
  270.         io_block_mapping(IMAP_ADDR, IMAP_ADDR, IMAP_SIZE, _PAGE_IO);
  271. #ifdef CONFIG_MBX
  272.         io_block_mapping(NVRAM_ADDR, NVRAM_ADDR, NVRAM_SIZE, _PAGE_IO);
  273.         io_block_mapping(MBX_CSR_ADDR, MBX_CSR_ADDR, MBX_CSR_SIZE, _PAGE_IO);
  274.         io_block_mapping(PCI_CSR_ADDR, PCI_CSR_ADDR, PCI_CSR_SIZE, _PAGE_IO);
  275. /* Map some of the PCI/ISA I/O space to get the IDE interface.
  276. */
  277.         io_block_mapping(PCI_ISA_IO_ADDR, PCI_ISA_IO_ADDR, 0x4000, _PAGE_IO);
  278.         io_block_mapping(PCI_IDE_ADDR, PCI_IDE_ADDR, 0x4000, _PAGE_IO);
  279. #endif
  280. #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
  281. io_block_mapping(RPX_CSR_ADDR, RPX_CSR_ADDR, RPX_CSR_SIZE, _PAGE_IO);
  282. #if !defined(CONFIG_PCI)
  283. io_block_mapping(_IO_BASE,_IO_BASE,_IO_BASE_SIZE, _PAGE_IO);
  284. #endif
  285. #endif
  286. #ifdef CONFIG_HTDMSOUND
  287. io_block_mapping(HIOX_CSR_ADDR, HIOX_CSR_ADDR, HIOX_CSR_SIZE, _PAGE_IO);
  288. #endif
  289. #ifdef CONFIG_FADS
  290. io_block_mapping(BCSR_ADDR, BCSR_ADDR, BCSR_SIZE, _PAGE_IO);
  291. #endif
  292. #ifdef CONFIG_PCI
  293.         io_block_mapping(PCI_CSR_ADDR, PCI_CSR_ADDR, PCI_CSR_SIZE, _PAGE_IO);
  294. #endif
  295. }
  296. void __init
  297. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  298. unsigned long r6, unsigned long r7)
  299. {
  300. parse_bootinfo(find_bootinfo());
  301. if ( r3 )
  302. memcpy( (void *)__res,(void *)(r3+KERNELBASE), sizeof(bd_t) );
  303. #ifdef CONFIG_PCI
  304. m8xx_setup_pci_ptrs();
  305. #endif
  306. #ifdef CONFIG_BLK_DEV_INITRD
  307. /* take care of initrd if we have one */
  308. if ( r4 )
  309. {
  310. initrd_start = r4 + KERNELBASE;
  311. initrd_end = r5 + KERNELBASE;
  312. }
  313. #endif /* CONFIG_BLK_DEV_INITRD */
  314. /* take care of cmd line */
  315. if ( r6 )
  316. {
  317. *(char *)(r7+KERNELBASE) = 0;
  318. strcpy(cmd_line, (char *)(r6+KERNELBASE));
  319. }
  320. ppc_md.setup_arch = m8xx_setup_arch;
  321. ppc_md.show_percpuinfo = m8xx_show_percpuinfo;
  322. ppc_md.irq_cannonicalize = NULL;
  323. ppc_md.init_IRQ = m8xx_init_IRQ;
  324. ppc_md.get_irq = m8xx_get_irq;
  325. ppc_md.init = NULL;
  326. ppc_md.restart = m8xx_restart;
  327. ppc_md.power_off = m8xx_power_off;
  328. ppc_md.halt = m8xx_halt;
  329. ppc_md.time_init = NULL;
  330. ppc_md.set_rtc_time = m8xx_set_rtc_time;
  331. ppc_md.get_rtc_time = m8xx_get_rtc_time;
  332. ppc_md.calibrate_decr = m8xx_calibrate_decr;
  333. ppc_md.find_end_of_memory = m8xx_find_end_of_memory;
  334. ppc_md.setup_io_mappings = m8xx_map_io;
  335. ppc_md.kbd_setkeycode = NULL;
  336. ppc_md.kbd_getkeycode = NULL;
  337. ppc_md.kbd_translate = NULL;
  338. ppc_md.kbd_unexpected_up = NULL;
  339. ppc_md.kbd_leds = NULL;
  340. ppc_md.kbd_init_hw = NULL;
  341. ppc_md.ppc_kbd_sysrq_xlate = NULL;
  342. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
  343. m8xx_ide_init();
  344. #endif
  345. }