setup.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * Maple (970 eval board) setup code
  3. *
  4. * (c) Copyright 2004 Benjamin Herrenschmidt (benh@kernel.crashing.org),
  5. * IBM Corp.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. *
  12. */
  13. #define DEBUG
  14. #include <linux/config.h>
  15. #include <linux/init.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/string.h>
  28. #include <linux/delay.h>
  29. #include <linux/ioport.h>
  30. #include <linux/major.h>
  31. #include <linux/initrd.h>
  32. #include <linux/vt_kern.h>
  33. #include <linux/console.h>
  34. #include <linux/ide.h>
  35. #include <linux/pci.h>
  36. #include <linux/adb.h>
  37. #include <linux/cuda.h>
  38. #include <linux/pmu.h>
  39. #include <linux/irq.h>
  40. #include <linux/seq_file.h>
  41. #include <linux/root_dev.h>
  42. #include <linux/serial.h>
  43. #include <linux/smp.h>
  44. #include <asm/processor.h>
  45. #include <asm/sections.h>
  46. #include <asm/prom.h>
  47. #include <asm/system.h>
  48. #include <asm/pgtable.h>
  49. #include <asm/bitops.h>
  50. #include <asm/io.h>
  51. #include <asm/kexec.h>
  52. #include <asm/pci-bridge.h>
  53. #include <asm/iommu.h>
  54. #include <asm/machdep.h>
  55. #include <asm/dma.h>
  56. #include <asm/cputable.h>
  57. #include <asm/time.h>
  58. #include <asm/of_device.h>
  59. #include <asm/lmb.h>
  60. #include <asm/mpic.h>
  61. #include <asm/udbg.h>
  62. #include "maple.h"
  63. #ifdef DEBUG
  64. #define DBG(fmt...) udbg_printf(fmt)
  65. #else
  66. #define DBG(fmt...)
  67. #endif
  68. static void maple_restart(char *cmd)
  69. {
  70. unsigned int maple_nvram_base;
  71. unsigned int maple_nvram_offset;
  72. unsigned int maple_nvram_command;
  73. struct device_node *rtcs;
  74. /* find NVRAM device */
  75. rtcs = find_compatible_devices("nvram", "AMD8111");
  76. if (rtcs && rtcs->addrs) {
  77. maple_nvram_base = rtcs->addrs[0].address;
  78. } else {
  79. printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
  80. printk(KERN_EMERG "Maple: Manual Restart Required\n");
  81. return;
  82. }
  83. /* find service processor device */
  84. rtcs = find_devices("service-processor");
  85. if (!rtcs) {
  86. printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
  87. printk(KERN_EMERG "Maple: Manual Restart Required\n");
  88. return;
  89. }
  90. maple_nvram_offset = *(unsigned int*) get_property(rtcs,
  91. "restart-addr", NULL);
  92. maple_nvram_command = *(unsigned int*) get_property(rtcs,
  93. "restart-value", NULL);
  94. /* send command */
  95. outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
  96. for (;;) ;
  97. }
  98. static void maple_power_off(void)
  99. {
  100. unsigned int maple_nvram_base;
  101. unsigned int maple_nvram_offset;
  102. unsigned int maple_nvram_command;
  103. struct device_node *rtcs;
  104. /* find NVRAM device */
  105. rtcs = find_compatible_devices("nvram", "AMD8111");
  106. if (rtcs && rtcs->addrs) {
  107. maple_nvram_base = rtcs->addrs[0].address;
  108. } else {
  109. printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
  110. printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
  111. return;
  112. }
  113. /* find service processor device */
  114. rtcs = find_devices("service-processor");
  115. if (!rtcs) {
  116. printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
  117. printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
  118. return;
  119. }
  120. maple_nvram_offset = *(unsigned int*) get_property(rtcs,
  121. "power-off-addr", NULL);
  122. maple_nvram_command = *(unsigned int*) get_property(rtcs,
  123. "power-off-value", NULL);
  124. /* send command */
  125. outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
  126. for (;;) ;
  127. }
  128. static void maple_halt(void)
  129. {
  130. maple_power_off();
  131. }
  132. #ifdef CONFIG_SMP
  133. struct smp_ops_t maple_smp_ops = {
  134. .probe = smp_mpic_probe,
  135. .message_pass = smp_mpic_message_pass,
  136. .kick_cpu = smp_generic_kick_cpu,
  137. .setup_cpu = smp_mpic_setup_cpu,
  138. .give_timebase = smp_generic_give_timebase,
  139. .take_timebase = smp_generic_take_timebase,
  140. };
  141. #endif /* CONFIG_SMP */
  142. void __init maple_setup_arch(void)
  143. {
  144. /* init to some ~sane value until calibrate_delay() runs */
  145. loops_per_jiffy = 50000000;
  146. /* Setup SMP callback */
  147. #ifdef CONFIG_SMP
  148. smp_ops = &maple_smp_ops;
  149. #endif
  150. /* Lookup PCI hosts */
  151. maple_pci_init();
  152. #ifdef CONFIG_DUMMY_CONSOLE
  153. conswitchp = &dummy_con;
  154. #endif
  155. printk(KERN_INFO "Using native/NAP idle loop\n");
  156. }
  157. /*
  158. * Early initialization.
  159. */
  160. static void __init maple_init_early(void)
  161. {
  162. unsigned int default_speed;
  163. u64 physport;
  164. DBG(" -> maple_init_early\n");
  165. /* Initialize hash table, from now on, we can take hash faults
  166. * and call ioremap
  167. */
  168. hpte_init_native();
  169. /* Setup interrupt mapping options */
  170. ppc64_interrupt_controller = IC_OPEN_PIC;
  171. iommu_init_early_dart();
  172. DBG(" <- maple_init_early\n");
  173. }
  174. static __init void maple_init_IRQ(void)
  175. {
  176. struct device_node *root;
  177. unsigned int *opprop;
  178. unsigned long opic_addr;
  179. struct mpic *mpic;
  180. unsigned char senses[128];
  181. int n;
  182. DBG(" -> maple_init_IRQ\n");
  183. /* XXX: Non standard, replace that with a proper openpic/mpic node
  184. * in the device-tree. Find the Open PIC if present */
  185. root = of_find_node_by_path("/");
  186. opprop = (unsigned int *) get_property(root,
  187. "platform-open-pic", NULL);
  188. if (opprop == 0)
  189. panic("OpenPIC not found !\n");
  190. n = prom_n_addr_cells(root);
  191. for (opic_addr = 0; n > 0; --n)
  192. opic_addr = (opic_addr << 32) + *opprop++;
  193. of_node_put(root);
  194. /* Obtain sense values from device-tree */
  195. prom_get_irq_senses(senses, 0, 128);
  196. mpic = mpic_alloc(opic_addr,
  197. MPIC_PRIMARY | MPIC_BIG_ENDIAN |
  198. MPIC_BROKEN_U3 | MPIC_WANTS_RESET,
  199. 0, 0, 128, 128, senses, 128, "U3-MPIC");
  200. BUG_ON(mpic == NULL);
  201. mpic_init(mpic);
  202. DBG(" <- maple_init_IRQ\n");
  203. }
  204. static void __init maple_progress(char *s, unsigned short hex)
  205. {
  206. printk("*** %04x : %s\n", hex, s ? s : "");
  207. }
  208. /*
  209. * Called very early, MMU is off, device-tree isn't unflattened
  210. */
  211. static int __init maple_probe(int platform)
  212. {
  213. if (platform != PLATFORM_MAPLE)
  214. return 0;
  215. /*
  216. * On U3, the DART (iommu) must be allocated now since it
  217. * has an impact on htab_initialize (due to the large page it
  218. * occupies having to be broken up so the DART itself is not
  219. * part of the cacheable linar mapping
  220. */
  221. alloc_dart_table();
  222. return 1;
  223. }
  224. struct machdep_calls __initdata maple_md = {
  225. .probe = maple_probe,
  226. .setup_arch = maple_setup_arch,
  227. .init_early = maple_init_early,
  228. .init_IRQ = maple_init_IRQ,
  229. .get_irq = mpic_get_irq,
  230. .pcibios_fixup = maple_pcibios_fixup,
  231. .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
  232. .restart = maple_restart,
  233. .power_off = maple_power_off,
  234. .halt = maple_halt,
  235. .get_boot_time = maple_get_boot_time,
  236. .set_rtc_time = maple_set_rtc_time,
  237. .get_rtc_time = maple_get_rtc_time,
  238. .calibrate_decr = generic_calibrate_decr,
  239. .progress = maple_progress,
  240. .idle_loop = native_idle,
  241. #ifdef CONFIG_KEXEC
  242. .machine_kexec = default_machine_kexec,
  243. .machine_kexec_prepare = default_machine_kexec_prepare,
  244. .machine_crash_shutdown = default_machine_crash_shutdown,
  245. #endif
  246. };