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