maple_setup.c 7.4 KB

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