ppc4xx_setup.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. *
  3. * Copyright (c) 1999-2000 Grant Erickson <grant@lcse.umn.edu>
  4. *
  5. * Copyright 2000-2001 MontaVista Software Inc.
  6. * Completed implementation.
  7. * Author: MontaVista Software, Inc. <source@mvista.com>
  8. * Frank Rowand <frank_rowand@mvista.com>
  9. * Debbie Chu <debbie_chu@mvista.com>
  10. * Further modifications by Armin Kuster
  11. *
  12. * Module name: ppc4xx_setup.c
  13. *
  14. */
  15. #include <linux/init.h>
  16. #include <linux/smp.h>
  17. #include <linux/threads.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/reboot.h>
  20. #include <linux/param.h>
  21. #include <linux/string.h>
  22. #include <linux/initrd.h>
  23. #include <linux/pci.h>
  24. #include <linux/rtc.h>
  25. #include <linux/console.h>
  26. #include <linux/serial_reg.h>
  27. #include <linux/seq_file.h>
  28. #include <asm/system.h>
  29. #include <asm/processor.h>
  30. #include <asm/machdep.h>
  31. #include <asm/page.h>
  32. #include <asm/kgdb.h>
  33. #include <asm/ibm4xx.h>
  34. #include <asm/time.h>
  35. #include <asm/todc.h>
  36. #include <asm/ppc4xx_pic.h>
  37. #include <asm/pci-bridge.h>
  38. #include <asm/bootinfo.h>
  39. #include <syslib/gen550.h>
  40. /* Function Prototypes */
  41. extern void abort(void);
  42. extern void ppc4xx_find_bridges(void);
  43. /* Global Variables */
  44. bd_t __res;
  45. void __init
  46. ppc4xx_setup_arch(void)
  47. {
  48. #if !defined(CONFIG_BDI_SWITCH)
  49. /*
  50. * The Abatron BDI JTAG debugger does not tolerate others
  51. * mucking with the debug registers.
  52. */
  53. mtspr(SPRN_DBCR0, (DBCR0_IDM));
  54. mtspr(SPRN_DBSR, 0xffffffff);
  55. #endif
  56. /* Setup PCI host bridges */
  57. #ifdef CONFIG_PCI
  58. ppc4xx_find_bridges();
  59. #endif
  60. }
  61. /*
  62. * This routine pretty-prints the platform's internal CPU clock
  63. * frequencies into the buffer for usage in /proc/cpuinfo.
  64. */
  65. static int
  66. ppc4xx_show_percpuinfo(struct seq_file *m, int i)
  67. {
  68. seq_printf(m, "clock\t\t: %ldMHz\n", (long)__res.bi_intfreq / 1000000);
  69. return 0;
  70. }
  71. /*
  72. * This routine pretty-prints the platform's internal bus clock
  73. * frequencies into the buffer for usage in /proc/cpuinfo.
  74. */
  75. static int
  76. ppc4xx_show_cpuinfo(struct seq_file *m)
  77. {
  78. bd_t *bip = &__res;
  79. seq_printf(m, "machine\t\t: %s\n", PPC4xx_MACHINE_NAME);
  80. seq_printf(m, "plb bus clock\t: %ldMHz\n",
  81. (long) bip->bi_busfreq / 1000000);
  82. #ifdef CONFIG_PCI
  83. seq_printf(m, "pci bus clock\t: %dMHz\n",
  84. bip->bi_pci_busfreq / 1000000);
  85. #endif
  86. return 0;
  87. }
  88. /*
  89. * Return the virtual address representing the top of physical RAM.
  90. */
  91. static unsigned long __init
  92. ppc4xx_find_end_of_memory(void)
  93. {
  94. return ((unsigned long) __res.bi_memsize);
  95. }
  96. void __init
  97. ppc4xx_map_io(void)
  98. {
  99. io_block_mapping(PPC4xx_ONB_IO_VADDR,
  100. PPC4xx_ONB_IO_PADDR, PPC4xx_ONB_IO_SIZE, _PAGE_IO);
  101. #ifdef CONFIG_PCI
  102. io_block_mapping(PPC4xx_PCI_IO_VADDR,
  103. PPC4xx_PCI_IO_PADDR, PPC4xx_PCI_IO_SIZE, _PAGE_IO);
  104. io_block_mapping(PPC4xx_PCI_CFG_VADDR,
  105. PPC4xx_PCI_CFG_PADDR, PPC4xx_PCI_CFG_SIZE, _PAGE_IO);
  106. io_block_mapping(PPC4xx_PCI_LCFG_VADDR,
  107. PPC4xx_PCI_LCFG_PADDR, PPC4xx_PCI_LCFG_SIZE, _PAGE_IO);
  108. #endif
  109. }
  110. void __init
  111. ppc4xx_init_IRQ(void)
  112. {
  113. ppc4xx_pic_init();
  114. }
  115. static void
  116. ppc4xx_restart(char *cmd)
  117. {
  118. printk("%s\n", cmd);
  119. abort();
  120. }
  121. static void
  122. ppc4xx_power_off(void)
  123. {
  124. printk("System Halted\n");
  125. local_irq_disable();
  126. while (1) ;
  127. }
  128. static void
  129. ppc4xx_halt(void)
  130. {
  131. printk("System Halted\n");
  132. local_irq_disable();
  133. while (1) ;
  134. }
  135. /*
  136. * This routine retrieves the internal processor frequency from the board
  137. * information structure, sets up the kernel timer decrementer based on
  138. * that value, enables the 4xx programmable interval timer (PIT) and sets
  139. * it up for auto-reload.
  140. */
  141. static void __init
  142. ppc4xx_calibrate_decr(void)
  143. {
  144. unsigned int freq;
  145. bd_t *bip = &__res;
  146. #if defined(CONFIG_WALNUT) || defined(CONFIG_SYCAMORE)
  147. /* Walnut boot rom sets DCR CHCR1 (aka CPC0_CR1) bit CETE to 1 */
  148. mtdcr(DCRN_CHCR1, mfdcr(DCRN_CHCR1) & ~CHR1_CETE);
  149. #endif
  150. freq = bip->bi_tbfreq;
  151. tb_ticks_per_jiffy = freq / HZ;
  152. tb_to_us = mulhwu_scale_factor(freq, 1000000);
  153. /* Set the time base to zero.
  154. ** At 200 Mhz, time base will rollover in ~2925 years.
  155. */
  156. mtspr(SPRN_TBWL, 0);
  157. mtspr(SPRN_TBWU, 0);
  158. /* Clear any pending timer interrupts */
  159. mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_PIS | TSR_FIS);
  160. mtspr(SPRN_TCR, TCR_PIE | TCR_ARE);
  161. /* Set the PIT reload value and just let it run. */
  162. mtspr(SPRN_PIT, tb_ticks_per_jiffy);
  163. }
  164. TODC_ALLOC();
  165. /*
  166. * Input(s):
  167. * r3 - Optional pointer to a board information structure.
  168. * r4 - Optional pointer to the physical starting address of the init RAM
  169. * disk.
  170. * r5 - Optional pointer to the physical ending address of the init RAM
  171. * disk.
  172. * r6 - Optional pointer to the physical starting address of any kernel
  173. * command-line parameters.
  174. * r7 - Optional pointer to the physical ending address of any kernel
  175. * command-line parameters.
  176. */
  177. void __init
  178. ppc4xx_init(unsigned long r3, unsigned long r4, unsigned long r5,
  179. unsigned long r6, unsigned long r7)
  180. {
  181. parse_bootinfo(find_bootinfo());
  182. /*
  183. * If we were passed in a board information, copy it into the
  184. * residual data area.
  185. */
  186. if (r3)
  187. __res = *(bd_t *)(r3 + KERNELBASE);
  188. #if defined(CONFIG_BLK_DEV_INITRD)
  189. /*
  190. * If the init RAM disk has been configured in, and there's a valid
  191. * starting address for it, set it up.
  192. */
  193. if (r4) {
  194. initrd_start = r4 + KERNELBASE;
  195. initrd_end = r5 + KERNELBASE;
  196. }
  197. #endif /* CONFIG_BLK_DEV_INITRD */
  198. /* Copy the kernel command line arguments to a safe place. */
  199. if (r6) {
  200. *(char *) (r7 + KERNELBASE) = 0;
  201. strcpy(cmd_line, (char *) (r6 + KERNELBASE));
  202. }
  203. /* Initialize machine-dependent vectors */
  204. ppc_md.setup_arch = ppc4xx_setup_arch;
  205. ppc_md.show_percpuinfo = ppc4xx_show_percpuinfo;
  206. ppc_md.show_cpuinfo = ppc4xx_show_cpuinfo;
  207. ppc_md.init_IRQ = ppc4xx_init_IRQ;
  208. ppc_md.restart = ppc4xx_restart;
  209. ppc_md.power_off = ppc4xx_power_off;
  210. ppc_md.halt = ppc4xx_halt;
  211. ppc_md.calibrate_decr = ppc4xx_calibrate_decr;
  212. ppc_md.find_end_of_memory = ppc4xx_find_end_of_memory;
  213. ppc_md.setup_io_mappings = ppc4xx_map_io;
  214. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  215. ppc_md.progress = gen550_progress;
  216. #endif
  217. }
  218. /* Called from machine_check_exception */
  219. void platform_machine_check(struct pt_regs *regs)
  220. {
  221. #if defined(DCRN_PLB0_BEAR)
  222. printk("PLB0: BEAR= 0x%08x ACR= 0x%08x BESR= 0x%08x\n",
  223. mfdcr(DCRN_PLB0_BEAR), mfdcr(DCRN_PLB0_ACR),
  224. mfdcr(DCRN_PLB0_BESR));
  225. #endif
  226. #if defined(DCRN_POB0_BEAR)
  227. printk("PLB0 to OPB: BEAR= 0x%08x BESR0= 0x%08x BESR1= 0x%08x\n",
  228. mfdcr(DCRN_POB0_BEAR), mfdcr(DCRN_POB0_BESR0),
  229. mfdcr(DCRN_POB0_BESR1));
  230. #endif
  231. }