/arch/powerpc/platforms/maple/setup.c

http://github.com/mirrors/linux · C · 366 lines · 275 code · 50 blank · 41 comment · 32 complexity · ed02aea160cfd90fe32504fc516faec5 MD5 · raw file

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