setup.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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/export.h>
  19. #include <linux/mm.h>
  20. #include <linux/stddef.h>
  21. #include <linux/unistd.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/user.h>
  24. #include <linux/tty.h>
  25. #include <linux/string.h>
  26. #include <linux/delay.h>
  27. #include <linux/ioport.h>
  28. #include <linux/major.h>
  29. #include <linux/initrd.h>
  30. #include <linux/vt_kern.h>
  31. #include <linux/console.h>
  32. #include <linux/pci.h>
  33. #include <linux/adb.h>
  34. #include <linux/cuda.h>
  35. #include <linux/pmu.h>
  36. #include <linux/irq.h>
  37. #include <linux/seq_file.h>
  38. #include <linux/root_dev.h>
  39. #include <linux/serial.h>
  40. #include <linux/smp.h>
  41. #include <linux/bitops.h>
  42. #include <linux/of_device.h>
  43. #include <linux/memblock.h>
  44. #include <asm/processor.h>
  45. #include <asm/sections.h>
  46. #include <asm/prom.h>
  47. #include <asm/pgtable.h>
  48. #include <asm/io.h>
  49. #include <asm/pci-bridge.h>
  50. #include <asm/iommu.h>
  51. #include <asm/machdep.h>
  52. #include <asm/dma.h>
  53. #include <asm/cputable.h>
  54. #include <asm/time.h>
  55. #include <asm/mpic.h>
  56. #include <asm/rtas.h>
  57. #include <asm/udbg.h>
  58. #include <asm/nvram.h>
  59. #include "maple.h"
  60. #ifdef DEBUG
  61. #define DBG(fmt...) udbg_printf(fmt)
  62. #else
  63. #define DBG(fmt...)
  64. #endif
  65. static unsigned long maple_find_nvram_base(void)
  66. {
  67. struct device_node *rtcs;
  68. unsigned long result = 0;
  69. /* find NVRAM device */
  70. rtcs = of_find_compatible_node(NULL, "nvram", "AMD8111");
  71. if (rtcs) {
  72. struct resource r;
  73. if (of_address_to_resource(rtcs, 0, &r)) {
  74. printk(KERN_EMERG "Maple: Unable to translate NVRAM"
  75. " address\n");
  76. goto bail;
  77. }
  78. if (!(r.flags & IORESOURCE_IO)) {
  79. printk(KERN_EMERG "Maple: NVRAM address isn't PIO!\n");
  80. goto bail;
  81. }
  82. result = r.start;
  83. } else
  84. printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
  85. bail:
  86. of_node_put(rtcs);
  87. return result;
  88. }
  89. static void __noreturn maple_restart(char *cmd)
  90. {
  91. unsigned int maple_nvram_base;
  92. const unsigned int *maple_nvram_offset, *maple_nvram_command;
  93. struct device_node *sp;
  94. maple_nvram_base = maple_find_nvram_base();
  95. if (maple_nvram_base == 0)
  96. goto fail;
  97. /* find service processor device */
  98. sp = of_find_node_by_name(NULL, "service-processor");
  99. if (!sp) {
  100. printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
  101. goto fail;
  102. }
  103. maple_nvram_offset = of_get_property(sp, "restart-addr", NULL);
  104. maple_nvram_command = of_get_property(sp, "restart-value", NULL);
  105. of_node_put(sp);
  106. /* send command */
  107. outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
  108. for (;;) ;
  109. fail:
  110. printk(KERN_EMERG "Maple: Manual Restart Required\n");
  111. for (;;) ;
  112. }
  113. static void __noreturn maple_power_off(void)
  114. {
  115. unsigned int maple_nvram_base;
  116. const unsigned int *maple_nvram_offset, *maple_nvram_command;
  117. struct device_node *sp;
  118. maple_nvram_base = maple_find_nvram_base();
  119. if (maple_nvram_base == 0)
  120. goto fail;
  121. /* find service processor device */
  122. sp = of_find_node_by_name(NULL, "service-processor");
  123. if (!sp) {
  124. printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
  125. goto fail;
  126. }
  127. maple_nvram_offset = of_get_property(sp, "power-off-addr", NULL);
  128. maple_nvram_command = of_get_property(sp, "power-off-value", NULL);
  129. of_node_put(sp);
  130. /* send command */
  131. outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
  132. for (;;) ;
  133. fail:
  134. printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
  135. for (;;) ;
  136. }
  137. static void __noreturn maple_halt(void)
  138. {
  139. maple_power_off();
  140. }
  141. #ifdef CONFIG_SMP
  142. static 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. static void __init maple_use_rtas_reboot_and_halt_if_present(void)
  152. {
  153. if (rtas_service_present("system-reboot") &&
  154. rtas_service_present("power-off")) {
  155. ppc_md.restart = rtas_restart;
  156. pm_power_off = rtas_power_off;
  157. ppc_md.halt = rtas_halt;
  158. }
  159. }
  160. static void __init maple_setup_arch(void)
  161. {
  162. /* init to some ~sane value until calibrate_delay() runs */
  163. loops_per_jiffy = 50000000;
  164. /* Setup SMP callback */
  165. #ifdef CONFIG_SMP
  166. smp_ops = &maple_smp_ops;
  167. #endif
  168. /* Lookup PCI hosts */
  169. maple_pci_init();
  170. #ifdef CONFIG_DUMMY_CONSOLE
  171. conswitchp = &dummy_con;
  172. #endif
  173. maple_use_rtas_reboot_and_halt_if_present();
  174. printk(KERN_DEBUG "Using native/NAP idle loop\n");
  175. mmio_nvram_init();
  176. }
  177. /*
  178. * This is almost identical to pSeries and CHRP. We need to make that
  179. * code generic at one point, with appropriate bits in the device-tree to
  180. * identify the presence of an HT APIC
  181. */
  182. static void __init maple_init_IRQ(void)
  183. {
  184. struct device_node *root, *np, *mpic_node = NULL;
  185. const unsigned int *opprop;
  186. unsigned long openpic_addr = 0;
  187. int naddr, n, i, opplen, has_isus = 0;
  188. struct mpic *mpic;
  189. unsigned int flags = 0;
  190. /* Locate MPIC in the device-tree. Note that there is a bug
  191. * in Maple device-tree where the type of the controller is
  192. * open-pic and not interrupt-controller
  193. */
  194. for_each_node_by_type(np, "interrupt-controller")
  195. if (of_device_is_compatible(np, "open-pic")) {
  196. mpic_node = np;
  197. break;
  198. }
  199. if (mpic_node == NULL)
  200. for_each_node_by_type(np, "open-pic") {
  201. mpic_node = np;
  202. break;
  203. }
  204. if (mpic_node == NULL) {
  205. printk(KERN_ERR
  206. "Failed to locate the MPIC interrupt controller\n");
  207. return;
  208. }
  209. /* Find address list in /platform-open-pic */
  210. root = of_find_node_by_path("/");
  211. naddr = of_n_addr_cells(root);
  212. opprop = of_get_property(root, "platform-open-pic", &opplen);
  213. if (opprop != 0) {
  214. openpic_addr = of_read_number(opprop, naddr);
  215. has_isus = (opplen > naddr);
  216. printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
  217. openpic_addr, has_isus);
  218. }
  219. BUG_ON(openpic_addr == 0);
  220. /* Check for a big endian MPIC */
  221. if (of_get_property(np, "big-endian", NULL) != NULL)
  222. flags |= MPIC_BIG_ENDIAN;
  223. /* XXX Maple specific bits */
  224. flags |= MPIC_U3_HT_IRQS;
  225. /* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
  226. flags |= MPIC_BIG_ENDIAN;
  227. /* Setup the openpic driver. More device-tree junks, we hard code no
  228. * ISUs for now. I'll have to revisit some stuffs with the folks doing
  229. * the firmware for those
  230. */
  231. mpic = mpic_alloc(mpic_node, openpic_addr, flags,
  232. /*has_isus ? 16 :*/ 0, 0, " MPIC ");
  233. BUG_ON(mpic == NULL);
  234. /* Add ISUs */
  235. opplen /= sizeof(u32);
  236. for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
  237. unsigned long isuaddr = of_read_number(opprop + i, naddr);
  238. mpic_assign_isu(mpic, n, isuaddr);
  239. }
  240. /* All ISUs are setup, complete initialization */
  241. mpic_init(mpic);
  242. ppc_md.get_irq = mpic_get_irq;
  243. of_node_put(mpic_node);
  244. of_node_put(root);
  245. }
  246. static void __init maple_progress(char *s, unsigned short hex)
  247. {
  248. printk("*** %04x : %s\n", hex, s ? s : "");
  249. }
  250. /*
  251. * Called very early, MMU is off, device-tree isn't unflattened
  252. */
  253. static int __init maple_probe(void)
  254. {
  255. if (!of_machine_is_compatible("Momentum,Maple") &&
  256. !of_machine_is_compatible("Momentum,Apache"))
  257. return 0;
  258. pm_power_off = maple_power_off;
  259. iommu_init_early_dart(&maple_pci_controller_ops);
  260. return 1;
  261. }
  262. define_machine(maple) {
  263. .name = "Maple",
  264. .probe = maple_probe,
  265. .setup_arch = maple_setup_arch,
  266. .init_IRQ = maple_init_IRQ,
  267. .pci_irq_fixup = maple_pci_irq_fixup,
  268. .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
  269. .restart = maple_restart,
  270. .halt = maple_halt,
  271. .get_boot_time = maple_get_boot_time,
  272. .set_rtc_time = maple_set_rtc_time,
  273. .get_rtc_time = maple_get_rtc_time,
  274. .calibrate_decr = generic_calibrate_decr,
  275. .progress = maple_progress,
  276. .power_save = power4_idle,
  277. };
  278. #ifdef CONFIG_EDAC
  279. /*
  280. * Register a platform device for CPC925 memory controller on
  281. * all boards with U3H (CPC925) bridge.
  282. */
  283. static int __init maple_cpc925_edac_setup(void)
  284. {
  285. struct platform_device *pdev;
  286. struct device_node *np = NULL;
  287. struct resource r;
  288. int ret;
  289. volatile void __iomem *mem;
  290. u32 rev;
  291. np = of_find_node_by_type(NULL, "memory-controller");
  292. if (!np) {
  293. printk(KERN_ERR "%s: Unable to find memory-controller node\n",
  294. __func__);
  295. return -ENODEV;
  296. }
  297. ret = of_address_to_resource(np, 0, &r);
  298. of_node_put(np);
  299. if (ret < 0) {
  300. printk(KERN_ERR "%s: Unable to get memory-controller reg\n",
  301. __func__);
  302. return -ENODEV;
  303. }
  304. mem = ioremap(r.start, resource_size(&r));
  305. if (!mem) {
  306. printk(KERN_ERR "%s: Unable to map memory-controller memory\n",
  307. __func__);
  308. return -ENOMEM;
  309. }
  310. rev = __raw_readl(mem);
  311. iounmap(mem);
  312. if (rev < 0x34 || rev > 0x3f) { /* U3H */
  313. printk(KERN_ERR "%s: Non-CPC925(U3H) bridge revision: %02x\n",
  314. __func__, rev);
  315. return 0;
  316. }
  317. pdev = platform_device_register_simple("cpc925_edac", 0, &r, 1);
  318. if (IS_ERR(pdev))
  319. return PTR_ERR(pdev);
  320. printk(KERN_INFO "%s: CPC925 platform device created\n", __func__);
  321. return 0;
  322. }
  323. machine_device_initcall(maple, maple_cpc925_edac_setup);
  324. #endif