setup.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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/pci-bridge.h>
  52. #include <asm/iommu.h>
  53. #include <asm/machdep.h>
  54. #include <asm/dma.h>
  55. #include <asm/cputable.h>
  56. #include <asm/time.h>
  57. #include <asm/of_device.h>
  58. #include <asm/lmb.h>
  59. #include <asm/mpic.h>
  60. #include <asm/udbg.h>
  61. #include "maple.h"
  62. #ifdef DEBUG
  63. #define DBG(fmt...) udbg_printf(fmt)
  64. #else
  65. #define DBG(fmt...)
  66. #endif
  67. extern void generic_find_legacy_serial_ports(u64 *physport,
  68. unsigned int *default_speed);
  69. static void maple_restart(char *cmd)
  70. {
  71. unsigned int maple_nvram_base;
  72. unsigned int maple_nvram_offset;
  73. unsigned int maple_nvram_command;
  74. struct device_node *rtcs;
  75. /* find NVRAM device */
  76. rtcs = find_compatible_devices("nvram", "AMD8111");
  77. if (rtcs && rtcs->addrs) {
  78. maple_nvram_base = rtcs->addrs[0].address;
  79. } else {
  80. printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
  81. printk(KERN_EMERG "Maple: Manual Restart Required\n");
  82. return;
  83. }
  84. /* find service processor device */
  85. rtcs = find_devices("service-processor");
  86. if (!rtcs) {
  87. printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
  88. printk(KERN_EMERG "Maple: Manual Restart Required\n");
  89. return;
  90. }
  91. maple_nvram_offset = *(unsigned int*) get_property(rtcs,
  92. "restart-addr", NULL);
  93. maple_nvram_command = *(unsigned int*) get_property(rtcs,
  94. "restart-value", NULL);
  95. /* send command */
  96. outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
  97. for (;;) ;
  98. }
  99. static void maple_power_off(void)
  100. {
  101. unsigned int maple_nvram_base;
  102. unsigned int maple_nvram_offset;
  103. unsigned int maple_nvram_command;
  104. struct device_node *rtcs;
  105. /* find NVRAM device */
  106. rtcs = find_compatible_devices("nvram", "AMD8111");
  107. if (rtcs && rtcs->addrs) {
  108. maple_nvram_base = rtcs->addrs[0].address;
  109. } else {
  110. printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
  111. printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
  112. return;
  113. }
  114. /* find service processor device */
  115. rtcs = find_devices("service-processor");
  116. if (!rtcs) {
  117. printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
  118. printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
  119. return;
  120. }
  121. maple_nvram_offset = *(unsigned int*) get_property(rtcs,
  122. "power-off-addr", NULL);
  123. maple_nvram_command = *(unsigned int*) get_property(rtcs,
  124. "power-off-value", NULL);
  125. /* send command */
  126. outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
  127. for (;;) ;
  128. }
  129. static void maple_halt(void)
  130. {
  131. maple_power_off();
  132. }
  133. #ifdef CONFIG_SMP
  134. struct smp_ops_t maple_smp_ops = {
  135. .probe = smp_mpic_probe,
  136. .message_pass = smp_mpic_message_pass,
  137. .kick_cpu = smp_generic_kick_cpu,
  138. .setup_cpu = smp_mpic_setup_cpu,
  139. .give_timebase = smp_generic_give_timebase,
  140. .take_timebase = smp_generic_take_timebase,
  141. };
  142. #endif /* CONFIG_SMP */
  143. void __init maple_setup_arch(void)
  144. {
  145. /* init to some ~sane value until calibrate_delay() runs */
  146. loops_per_jiffy = 50000000;
  147. /* Setup SMP callback */
  148. #ifdef CONFIG_SMP
  149. smp_ops = &maple_smp_ops;
  150. #endif
  151. /* Lookup PCI hosts */
  152. maple_pci_init();
  153. #ifdef CONFIG_DUMMY_CONSOLE
  154. conswitchp = &dummy_con;
  155. #endif
  156. printk(KERN_INFO "Using native/NAP idle loop\n");
  157. }
  158. /*
  159. * Early initialization.
  160. */
  161. static void __init maple_init_early(void)
  162. {
  163. unsigned int default_speed;
  164. u64 physport;
  165. DBG(" -> maple_init_early\n");
  166. /* Initialize hash table, from now on, we can take hash faults
  167. * and call ioremap
  168. */
  169. hpte_init_native();
  170. /* Find the serial port */
  171. generic_find_legacy_serial_ports(&physport, &default_speed);
  172. DBG("phys port addr: %lx\n", (long)physport);
  173. if (physport) {
  174. void *comport;
  175. /* Map the uart for udbg. */
  176. comport = (void *)ioremap(physport, 16);
  177. udbg_init_uart(comport, default_speed);
  178. DBG("Hello World !\n");
  179. }
  180. /* Setup interrupt mapping options */
  181. ppc64_interrupt_controller = IC_OPEN_PIC;
  182. iommu_init_early_u3();
  183. DBG(" <- maple_init_early\n");
  184. }
  185. static __init void maple_init_IRQ(void)
  186. {
  187. struct device_node *root;
  188. unsigned int *opprop;
  189. unsigned long opic_addr;
  190. struct mpic *mpic;
  191. unsigned char senses[128];
  192. int n;
  193. DBG(" -> maple_init_IRQ\n");
  194. /* XXX: Non standard, replace that with a proper openpic/mpic node
  195. * in the device-tree. Find the Open PIC if present */
  196. root = of_find_node_by_path("/");
  197. opprop = (unsigned int *) get_property(root,
  198. "platform-open-pic", NULL);
  199. if (opprop == 0)
  200. panic("OpenPIC not found !\n");
  201. n = prom_n_addr_cells(root);
  202. for (opic_addr = 0; n > 0; --n)
  203. opic_addr = (opic_addr << 32) + *opprop++;
  204. of_node_put(root);
  205. /* Obtain sense values from device-tree */
  206. prom_get_irq_senses(senses, 0, 128);
  207. mpic = mpic_alloc(opic_addr,
  208. MPIC_PRIMARY | MPIC_BIG_ENDIAN |
  209. MPIC_BROKEN_U3 | MPIC_WANTS_RESET,
  210. 0, 0, 128, 128, senses, 128, "U3-MPIC");
  211. BUG_ON(mpic == NULL);
  212. mpic_init(mpic);
  213. DBG(" <- maple_init_IRQ\n");
  214. }
  215. static void __init maple_progress(char *s, unsigned short hex)
  216. {
  217. printk("*** %04x : %s\n", hex, s ? s : "");
  218. }
  219. /*
  220. * Called very early, MMU is off, device-tree isn't unflattened
  221. */
  222. static int __init maple_probe(int platform)
  223. {
  224. if (platform != PLATFORM_MAPLE)
  225. return 0;
  226. /*
  227. * On U3, the DART (iommu) must be allocated now since it
  228. * has an impact on htab_initialize (due to the large page it
  229. * occupies having to be broken up so the DART itself is not
  230. * part of the cacheable linar mapping
  231. */
  232. alloc_u3_dart_table();
  233. return 1;
  234. }
  235. struct machdep_calls __initdata maple_md = {
  236. .probe = maple_probe,
  237. .setup_arch = maple_setup_arch,
  238. .init_early = maple_init_early,
  239. .init_IRQ = maple_init_IRQ,
  240. .get_irq = mpic_get_irq,
  241. .pcibios_fixup = maple_pcibios_fixup,
  242. .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
  243. .restart = maple_restart,
  244. .power_off = maple_power_off,
  245. .halt = maple_halt,
  246. .get_boot_time = maple_get_boot_time,
  247. .set_rtc_time = maple_set_rtc_time,
  248. .get_rtc_time = maple_get_rtc_time,
  249. .calibrate_decr = generic_calibrate_decr,
  250. .progress = maple_progress,
  251. .idle_loop = native_idle,
  252. };