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 (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.h>
  38. #include <linux/of_address.h>
  39. #include <linux/platform_device.h>
  40. #include <linux/memblock.h>
  41. #include <asm/processor.h>
  42. #include <asm/sections.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_function_implemented(RTAS_FN_SYSTEM_REBOOT) &&
  149. rtas_function_implemented(RTAS_FN_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. maple_use_rtas_reboot_and_halt_if_present();
  164. printk(KERN_DEBUG "Using native/NAP idle loop\n");
  165. mmio_nvram_init();
  166. }
  167. /*
  168. * This is almost identical to pSeries and CHRP. We need to make that
  169. * code generic at one point, with appropriate bits in the device-tree to
  170. * identify the presence of an HT APIC
  171. */
  172. static void __init maple_init_IRQ(void)
  173. {
  174. struct device_node *root, *np, *mpic_node = NULL;
  175. const unsigned int *opprop;
  176. unsigned long openpic_addr = 0;
  177. int naddr, n, i, opplen, has_isus = 0;
  178. struct mpic *mpic;
  179. unsigned int flags = 0;
  180. /* Locate MPIC in the device-tree. Note that there is a bug
  181. * in Maple device-tree where the type of the controller is
  182. * open-pic and not interrupt-controller
  183. */
  184. for_each_node_by_type(np, "interrupt-controller")
  185. if (of_device_is_compatible(np, "open-pic")) {
  186. mpic_node = np;
  187. break;
  188. }
  189. if (mpic_node == NULL)
  190. for_each_node_by_type(np, "open-pic") {
  191. mpic_node = np;
  192. break;
  193. }
  194. if (mpic_node == NULL) {
  195. printk(KERN_ERR
  196. "Failed to locate the MPIC interrupt controller\n");
  197. return;
  198. }
  199. /* Find address list in /platform-open-pic */
  200. root = of_find_node_by_path("/");
  201. naddr = of_n_addr_cells(root);
  202. opprop = of_get_property(root, "platform-open-pic", &opplen);
  203. if (opprop) {
  204. openpic_addr = of_read_number(opprop, naddr);
  205. has_isus = (opplen > naddr);
  206. printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
  207. openpic_addr, has_isus);
  208. }
  209. BUG_ON(openpic_addr == 0);
  210. /* Check for a big endian MPIC */
  211. if (of_property_read_bool(np, "big-endian"))
  212. flags |= MPIC_BIG_ENDIAN;
  213. /* XXX Maple specific bits */
  214. flags |= MPIC_U3_HT_IRQS;
  215. /* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
  216. flags |= MPIC_BIG_ENDIAN;
  217. /* Setup the openpic driver. More device-tree junks, we hard code no
  218. * ISUs for now. I'll have to revisit some stuffs with the folks doing
  219. * the firmware for those
  220. */
  221. mpic = mpic_alloc(mpic_node, openpic_addr, flags,
  222. /*has_isus ? 16 :*/ 0, 0, " MPIC ");
  223. BUG_ON(mpic == NULL);
  224. /* Add ISUs */
  225. opplen /= sizeof(u32);
  226. for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
  227. unsigned long isuaddr = of_read_number(opprop + i, naddr);
  228. mpic_assign_isu(mpic, n, isuaddr);
  229. }
  230. /* All ISUs are setup, complete initialization */
  231. mpic_init(mpic);
  232. ppc_md.get_irq = mpic_get_irq;
  233. of_node_put(mpic_node);
  234. of_node_put(root);
  235. }
  236. static void __init maple_progress(char *s, unsigned short hex)
  237. {
  238. printk("*** %04x : %s\n", hex, s ? s : "");
  239. }
  240. /*
  241. * Called very early, MMU is off, device-tree isn't unflattened
  242. */
  243. static int __init maple_probe(void)
  244. {
  245. if (!of_machine_is_compatible("Momentum,Maple") &&
  246. !of_machine_is_compatible("Momentum,Apache"))
  247. return 0;
  248. pm_power_off = maple_power_off;
  249. iommu_init_early_dart(&maple_pci_controller_ops);
  250. return 1;
  251. }
  252. #ifdef CONFIG_EDAC
  253. /*
  254. * Register a platform device for CPC925 memory controller on
  255. * all boards with U3H (CPC925) bridge.
  256. */
  257. static int __init maple_cpc925_edac_setup(void)
  258. {
  259. struct platform_device *pdev;
  260. struct device_node *np = NULL;
  261. struct resource r;
  262. int ret;
  263. volatile void __iomem *mem;
  264. u32 rev;
  265. np = of_find_node_by_type(NULL, "memory-controller");
  266. if (!np) {
  267. printk(KERN_ERR "%s: Unable to find memory-controller node\n",
  268. __func__);
  269. return -ENODEV;
  270. }
  271. ret = of_address_to_resource(np, 0, &r);
  272. of_node_put(np);
  273. if (ret < 0) {
  274. printk(KERN_ERR "%s: Unable to get memory-controller reg\n",
  275. __func__);
  276. return -ENODEV;
  277. }
  278. mem = ioremap(r.start, resource_size(&r));
  279. if (!mem) {
  280. printk(KERN_ERR "%s: Unable to map memory-controller memory\n",
  281. __func__);
  282. return -ENOMEM;
  283. }
  284. rev = __raw_readl(mem);
  285. iounmap(mem);
  286. if (rev < 0x34 || rev > 0x3f) { /* U3H */
  287. printk(KERN_ERR "%s: Non-CPC925(U3H) bridge revision: %02x\n",
  288. __func__, rev);
  289. return 0;
  290. }
  291. pdev = platform_device_register_simple("cpc925_edac", 0, &r, 1);
  292. if (IS_ERR(pdev))
  293. return PTR_ERR(pdev);
  294. printk(KERN_INFO "%s: CPC925 platform device created\n", __func__);
  295. return 0;
  296. }
  297. machine_device_initcall(maple, maple_cpc925_edac_setup);
  298. #endif
  299. define_machine(maple) {
  300. .name = "Maple",
  301. .probe = maple_probe,
  302. .setup_arch = maple_setup_arch,
  303. .discover_phbs = maple_pci_init,
  304. .init_IRQ = maple_init_IRQ,
  305. .pci_irq_fixup = maple_pci_irq_fixup,
  306. .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
  307. .restart = maple_restart,
  308. .halt = maple_halt,
  309. .get_boot_time = maple_get_boot_time,
  310. .set_rtc_time = maple_set_rtc_time,
  311. .get_rtc_time = maple_get_rtc_time,
  312. .progress = maple_progress,
  313. .power_save = power4_idle,
  314. };