setup.c 8.3 KB

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