setup.c 8.8 KB

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