setup.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. #undef DEBUG
  14. #include <linux/init.h>
  15. #include <linux/errno.h>
  16. #include <linux/sched.h>
  17. #include <linux/kernel.h>
  18. #include <linux/mm.h>
  19. #include <linux/stddef.h>
  20. #include <linux/unistd.h>
  21. #include <linux/ptrace.h>
  22. #include <linux/slab.h>
  23. #include <linux/user.h>
  24. #include <linux/a.out.h>
  25. #include <linux/tty.h>
  26. #include <linux/string.h>
  27. #include <linux/delay.h>
  28. #include <linux/ioport.h>
  29. #include <linux/major.h>
  30. #include <linux/initrd.h>
  31. #include <linux/vt_kern.h>
  32. #include <linux/console.h>
  33. #include <linux/pci.h>
  34. #include <linux/adb.h>
  35. #include <linux/cuda.h>
  36. #include <linux/pmu.h>
  37. #include <linux/irq.h>
  38. #include <linux/seq_file.h>
  39. #include <linux/root_dev.h>
  40. #include <linux/serial.h>
  41. #include <linux/smp.h>
  42. #include <asm/processor.h>
  43. #include <asm/sections.h>
  44. #include <asm/prom.h>
  45. #include <asm/system.h>
  46. #include <asm/pgtable.h>
  47. #include <asm/bitops.h>
  48. #include <asm/io.h>
  49. #include <asm/kexec.h>
  50. #include <asm/pci-bridge.h>
  51. #include <asm/iommu.h>
  52. #include <asm/machdep.h>
  53. #include <asm/dma.h>
  54. #include <asm/cputable.h>
  55. #include <asm/time.h>
  56. #include <asm/of_device.h>
  57. #include <asm/lmb.h>
  58. #include <asm/mpic.h>
  59. #include <asm/rtas.h>
  60. #include <asm/udbg.h>
  61. #include <asm/nvram.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 unsigned long maple_find_nvram_base(void)
  69. {
  70. struct device_node *rtcs;
  71. unsigned long result = 0;
  72. /* find NVRAM device */
  73. rtcs = of_find_compatible_node(NULL, "nvram", "AMD8111");
  74. if (rtcs) {
  75. struct resource r;
  76. if (of_address_to_resource(rtcs, 0, &r)) {
  77. printk(KERN_EMERG "Maple: Unable to translate NVRAM"
  78. " address\n");
  79. goto bail;
  80. }
  81. if (!(r.flags & IORESOURCE_IO)) {
  82. printk(KERN_EMERG "Maple: NVRAM address isn't PIO!\n");
  83. goto bail;
  84. }
  85. result = r.start;
  86. } else
  87. printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
  88. bail:
  89. of_node_put(rtcs);
  90. return result;
  91. }
  92. static void maple_restart(char *cmd)
  93. {
  94. unsigned int maple_nvram_base;
  95. const unsigned int *maple_nvram_offset, *maple_nvram_command;
  96. struct device_node *sp;
  97. maple_nvram_base = maple_find_nvram_base();
  98. if (maple_nvram_base == 0)
  99. goto fail;
  100. /* find service processor device */
  101. sp = of_find_node_by_name(NULL, "service-processor");
  102. if (!sp) {
  103. printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
  104. goto fail;
  105. }
  106. maple_nvram_offset = of_get_property(sp, "restart-addr", NULL);
  107. maple_nvram_command = of_get_property(sp, "restart-value", NULL);
  108. of_node_put(sp);
  109. /* send command */
  110. outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
  111. for (;;) ;
  112. fail:
  113. printk(KERN_EMERG "Maple: Manual Restart Required\n");
  114. }
  115. static void maple_power_off(void)
  116. {
  117. unsigned int maple_nvram_base;
  118. const unsigned int *maple_nvram_offset, *maple_nvram_command;
  119. struct device_node *sp;
  120. maple_nvram_base = maple_find_nvram_base();
  121. if (maple_nvram_base == 0)
  122. goto fail;
  123. /* find service processor device */
  124. sp = of_find_node_by_name(NULL, "service-processor");
  125. if (!sp) {
  126. printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
  127. goto fail;
  128. }
  129. maple_nvram_offset = of_get_property(sp, "power-off-addr", NULL);
  130. maple_nvram_command = of_get_property(sp, "power-off-value", NULL);
  131. of_node_put(sp);
  132. /* send command */
  133. outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
  134. for (;;) ;
  135. fail:
  136. printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
  137. }
  138. static void maple_halt(void)
  139. {
  140. maple_power_off();
  141. }
  142. #ifdef CONFIG_SMP
  143. struct smp_ops_t maple_smp_ops = {
  144. .probe = smp_mpic_probe,
  145. .message_pass = smp_mpic_message_pass,
  146. .kick_cpu = smp_generic_kick_cpu,
  147. .setup_cpu = smp_mpic_setup_cpu,
  148. .give_timebase = smp_generic_give_timebase,
  149. .take_timebase = smp_generic_take_timebase,
  150. };
  151. #endif /* CONFIG_SMP */
  152. static void __init maple_use_rtas_reboot_and_halt_if_present(void)
  153. {
  154. if (rtas_service_present("system-reboot") &&
  155. rtas_service_present("power-off")) {
  156. ppc_md.restart = rtas_restart;
  157. ppc_md.power_off = rtas_power_off;
  158. ppc_md.halt = rtas_halt;
  159. }
  160. }
  161. void __init maple_setup_arch(void)
  162. {
  163. /* init to some ~sane value until calibrate_delay() runs */
  164. loops_per_jiffy = 50000000;
  165. /* Setup SMP callback */
  166. #ifdef CONFIG_SMP
  167. smp_ops = &maple_smp_ops;
  168. #endif
  169. /* Lookup PCI hosts */
  170. maple_pci_init();
  171. #ifdef CONFIG_DUMMY_CONSOLE
  172. conswitchp = &dummy_con;
  173. #endif
  174. maple_use_rtas_reboot_and_halt_if_present();
  175. printk(KERN_DEBUG "Using native/NAP idle loop\n");
  176. mmio_nvram_init();
  177. }
  178. /*
  179. * Early initialization.
  180. */
  181. static void __init maple_init_early(void)
  182. {
  183. DBG(" -> maple_init_early\n");
  184. iommu_init_early_dart();
  185. DBG(" <- maple_init_early\n");
  186. }
  187. /*
  188. * This is almost identical to pSeries and CHRP. We need to make that
  189. * code generic at one point, with appropriate bits in the device-tree to
  190. * identify the presence of an HT APIC
  191. */
  192. static void __init maple_init_IRQ(void)
  193. {
  194. struct device_node *root, *np, *mpic_node = NULL;
  195. const unsigned int *opprop;
  196. unsigned long openpic_addr = 0;
  197. int naddr, n, i, opplen, has_isus = 0;
  198. struct mpic *mpic;
  199. unsigned int flags = MPIC_PRIMARY;
  200. /* Locate MPIC in the device-tree. Note that there is a bug
  201. * in Maple device-tree where the type of the controller is
  202. * open-pic and not interrupt-controller
  203. */
  204. for_each_node_by_type(np, "interrupt-controller")
  205. if (of_device_is_compatible(np, "open-pic")) {
  206. mpic_node = np;
  207. break;
  208. }
  209. if (mpic_node == NULL)
  210. for_each_node_by_type(np, "open-pic") {
  211. mpic_node = np;
  212. break;
  213. }
  214. if (mpic_node == NULL) {
  215. printk(KERN_ERR
  216. "Failed to locate the MPIC interrupt controller\n");
  217. return;
  218. }
  219. /* Find address list in /platform-open-pic */
  220. root = of_find_node_by_path("/");
  221. naddr = of_n_addr_cells(root);
  222. opprop = of_get_property(root, "platform-open-pic", &opplen);
  223. if (opprop != 0) {
  224. openpic_addr = of_read_number(opprop, naddr);
  225. has_isus = (opplen > naddr);
  226. printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
  227. openpic_addr, has_isus);
  228. }
  229. BUG_ON(openpic_addr == 0);
  230. /* Check for a big endian MPIC */
  231. if (of_get_property(np, "big-endian", NULL) != NULL)
  232. flags |= MPIC_BIG_ENDIAN;
  233. /* XXX Maple specific bits */
  234. flags |= MPIC_U3_HT_IRQS | MPIC_WANTS_RESET;
  235. /* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
  236. flags |= MPIC_BIG_ENDIAN;
  237. /* Setup the openpic driver. More device-tree junks, we hard code no
  238. * ISUs for now. I'll have to revisit some stuffs with the folks doing
  239. * the firmware for those
  240. */
  241. mpic = mpic_alloc(mpic_node, openpic_addr, flags,
  242. /*has_isus ? 16 :*/ 0, 0, " MPIC ");
  243. BUG_ON(mpic == NULL);
  244. /* Add ISUs */
  245. opplen /= sizeof(u32);
  246. for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
  247. unsigned long isuaddr = of_read_number(opprop + i, naddr);
  248. mpic_assign_isu(mpic, n, isuaddr);
  249. }
  250. /* All ISUs are setup, complete initialization */
  251. mpic_init(mpic);
  252. ppc_md.get_irq = mpic_get_irq;
  253. of_node_put(mpic_node);
  254. of_node_put(root);
  255. }
  256. static void __init maple_progress(char *s, unsigned short hex)
  257. {
  258. printk("*** %04x : %s\n", hex, s ? s : "");
  259. }
  260. /*
  261. * Called very early, MMU is off, device-tree isn't unflattened
  262. */
  263. static int __init maple_probe(void)
  264. {
  265. unsigned long root = of_get_flat_dt_root();
  266. if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
  267. !of_flat_dt_is_compatible(root, "Momentum,Apache"))
  268. return 0;
  269. /*
  270. * On U3, the DART (iommu) must be allocated now since it
  271. * has an impact on htab_initialize (due to the large page it
  272. * occupies having to be broken up so the DART itself is not
  273. * part of the cacheable linar mapping
  274. */
  275. alloc_dart_table();
  276. hpte_init_native();
  277. return 1;
  278. }
  279. define_machine(maple_md) {
  280. .name = "Maple",
  281. .probe = maple_probe,
  282. .setup_arch = maple_setup_arch,
  283. .init_early = maple_init_early,
  284. .init_IRQ = maple_init_IRQ,
  285. .pci_irq_fixup = maple_pci_irq_fixup,
  286. .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
  287. .restart = maple_restart,
  288. .power_off = maple_power_off,
  289. .halt = maple_halt,
  290. .get_boot_time = maple_get_boot_time,
  291. .set_rtc_time = maple_set_rtc_time,
  292. .get_rtc_time = maple_get_rtc_time,
  293. .calibrate_decr = generic_calibrate_decr,
  294. .progress = maple_progress,
  295. .power_save = power4_idle,
  296. #ifdef CONFIG_KEXEC
  297. .machine_kexec = default_machine_kexec,
  298. .machine_kexec_prepare = default_machine_kexec_prepare,
  299. .machine_crash_shutdown = default_machine_crash_shutdown,
  300. #endif
  301. };