setup.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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/user.h>
  23. #include <linux/tty.h>
  24. #include <linux/string.h>
  25. #include <linux/delay.h>
  26. #include <linux/ioport.h>
  27. #include <linux/major.h>
  28. #include <linux/initrd.h>
  29. #include <linux/vt_kern.h>
  30. #include <linux/console.h>
  31. #include <linux/pci.h>
  32. #include <linux/adb.h>
  33. #include <linux/cuda.h>
  34. #include <linux/pmu.h>
  35. #include <linux/irq.h>
  36. #include <linux/seq_file.h>
  37. #include <linux/root_dev.h>
  38. #include <linux/serial.h>
  39. #include <linux/smp.h>
  40. #include <linux/bitops.h>
  41. #include <linux/of_device.h>
  42. #include <linux/memblock.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/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 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. }
  112. static void maple_power_off(void)
  113. {
  114. unsigned int maple_nvram_base;
  115. const unsigned int *maple_nvram_offset, *maple_nvram_command;
  116. struct device_node *sp;
  117. maple_nvram_base = maple_find_nvram_base();
  118. if (maple_nvram_base == 0)
  119. goto fail;
  120. /* find service processor device */
  121. sp = of_find_node_by_name(NULL, "service-processor");
  122. if (!sp) {
  123. printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
  124. goto fail;
  125. }
  126. maple_nvram_offset = of_get_property(sp, "power-off-addr", NULL);
  127. maple_nvram_command = of_get_property(sp, "power-off-value", NULL);
  128. of_node_put(sp);
  129. /* send command */
  130. outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
  131. for (;;) ;
  132. fail:
  133. printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
  134. }
  135. static void maple_halt(void)
  136. {
  137. maple_power_off();
  138. }
  139. #ifdef CONFIG_SMP
  140. struct smp_ops_t maple_smp_ops = {
  141. .probe = smp_mpic_probe,
  142. .message_pass = smp_mpic_message_pass,
  143. .kick_cpu = smp_generic_kick_cpu,
  144. .setup_cpu = smp_mpic_setup_cpu,
  145. .give_timebase = smp_generic_give_timebase,
  146. .take_timebase = smp_generic_take_timebase,
  147. };
  148. #endif /* CONFIG_SMP */
  149. static void __init maple_use_rtas_reboot_and_halt_if_present(void)
  150. {
  151. if (rtas_service_present("system-reboot") &&
  152. rtas_service_present("power-off")) {
  153. ppc_md.restart = rtas_restart;
  154. ppc_md.power_off = rtas_power_off;
  155. ppc_md.halt = rtas_halt;
  156. }
  157. }
  158. void __init maple_setup_arch(void)
  159. {
  160. /* init to some ~sane value until calibrate_delay() runs */
  161. loops_per_jiffy = 50000000;
  162. /* Setup SMP callback */
  163. #ifdef CONFIG_SMP
  164. smp_ops = &maple_smp_ops;
  165. #endif
  166. /* Lookup PCI hosts */
  167. maple_pci_init();
  168. #ifdef CONFIG_DUMMY_CONSOLE
  169. conswitchp = &dummy_con;
  170. #endif
  171. maple_use_rtas_reboot_and_halt_if_present();
  172. printk(KERN_DEBUG "Using native/NAP idle loop\n");
  173. mmio_nvram_init();
  174. }
  175. /*
  176. * Early initialization.
  177. */
  178. static void __init maple_init_early(void)
  179. {
  180. DBG(" -> maple_init_early\n");
  181. iommu_init_early_dart();
  182. DBG(" <- maple_init_early\n");
  183. }
  184. /*
  185. * This is almost identical to pSeries and CHRP. We need to make that
  186. * code generic at one point, with appropriate bits in the device-tree to
  187. * identify the presence of an HT APIC
  188. */
  189. static void __init maple_init_IRQ(void)
  190. {
  191. struct device_node *root, *np, *mpic_node = NULL;
  192. const unsigned int *opprop;
  193. unsigned long openpic_addr = 0;
  194. int naddr, n, i, opplen, has_isus = 0;
  195. struct mpic *mpic;
  196. unsigned int flags = MPIC_PRIMARY;
  197. /* Locate MPIC in the device-tree. Note that there is a bug
  198. * in Maple device-tree where the type of the controller is
  199. * open-pic and not interrupt-controller
  200. */
  201. for_each_node_by_type(np, "interrupt-controller")
  202. if (of_device_is_compatible(np, "open-pic")) {
  203. mpic_node = np;
  204. break;
  205. }
  206. if (mpic_node == NULL)
  207. for_each_node_by_type(np, "open-pic") {
  208. mpic_node = np;
  209. break;
  210. }
  211. if (mpic_node == NULL) {
  212. printk(KERN_ERR
  213. "Failed to locate the MPIC interrupt controller\n");
  214. return;
  215. }
  216. /* Find address list in /platform-open-pic */
  217. root = of_find_node_by_path("/");
  218. naddr = of_n_addr_cells(root);
  219. opprop = of_get_property(root, "platform-open-pic", &opplen);
  220. if (opprop != 0) {
  221. openpic_addr = of_read_number(opprop, naddr);
  222. has_isus = (opplen > naddr);
  223. printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
  224. openpic_addr, has_isus);
  225. }
  226. BUG_ON(openpic_addr == 0);
  227. /* Check for a big endian MPIC */
  228. if (of_get_property(np, "big-endian", NULL) != NULL)
  229. flags |= MPIC_BIG_ENDIAN;
  230. /* XXX Maple specific bits */
  231. flags |= MPIC_U3_HT_IRQS | MPIC_WANTS_RESET;
  232. /* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
  233. flags |= MPIC_BIG_ENDIAN;
  234. /* Setup the openpic driver. More device-tree junks, we hard code no
  235. * ISUs for now. I'll have to revisit some stuffs with the folks doing
  236. * the firmware for those
  237. */
  238. mpic = mpic_alloc(mpic_node, openpic_addr, flags,
  239. /*has_isus ? 16 :*/ 0, 0, " MPIC ");
  240. BUG_ON(mpic == NULL);
  241. /* Add ISUs */
  242. opplen /= sizeof(u32);
  243. for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
  244. unsigned long isuaddr = of_read_number(opprop + i, naddr);
  245. mpic_assign_isu(mpic, n, isuaddr);
  246. }
  247. /* All ISUs are setup, complete initialization */
  248. mpic_init(mpic);
  249. ppc_md.get_irq = mpic_get_irq;
  250. of_node_put(mpic_node);
  251. of_node_put(root);
  252. }
  253. static void __init maple_progress(char *s, unsigned short hex)
  254. {
  255. printk("*** %04x : %s\n", hex, s ? s : "");
  256. }
  257. /*
  258. * Called very early, MMU is off, device-tree isn't unflattened
  259. */
  260. static int __init maple_probe(void)
  261. {
  262. unsigned long root = of_get_flat_dt_root();
  263. if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
  264. !of_flat_dt_is_compatible(root, "Momentum,Apache"))
  265. return 0;
  266. /*
  267. * On U3, the DART (iommu) must be allocated now since it
  268. * has an impact on htab_initialize (due to the large page it
  269. * occupies having to be broken up so the DART itself is not
  270. * part of the cacheable linar mapping
  271. */
  272. alloc_dart_table();
  273. hpte_init_native();
  274. return 1;
  275. }
  276. define_machine(maple) {
  277. .name = "Maple",
  278. .probe = maple_probe,
  279. .setup_arch = maple_setup_arch,
  280. .init_early = maple_init_early,
  281. .init_IRQ = maple_init_IRQ,
  282. .pci_irq_fixup = maple_pci_irq_fixup,
  283. .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
  284. .restart = maple_restart,
  285. .power_off = maple_power_off,
  286. .halt = maple_halt,
  287. .get_boot_time = maple_get_boot_time,
  288. .set_rtc_time = maple_set_rtc_time,
  289. .get_rtc_time = maple_get_rtc_time,
  290. .calibrate_decr = generic_calibrate_decr,
  291. .progress = maple_progress,
  292. .power_save = power4_idle,
  293. };
  294. #ifdef CONFIG_EDAC
  295. /*
  296. * Register a platform device for CPC925 memory controller on
  297. * Motorola ATCA-6101 blade.
  298. */
  299. #define MAPLE_CPC925_MODEL "Motorola,ATCA-6101"
  300. static int __init maple_cpc925_edac_setup(void)
  301. {
  302. struct platform_device *pdev;
  303. struct device_node *np = NULL;
  304. struct resource r;
  305. const unsigned char *model;
  306. int ret;
  307. np = of_find_node_by_path("/");
  308. if (!np) {
  309. printk(KERN_ERR "%s: Unable to get root node\n", __func__);
  310. return -ENODEV;
  311. }
  312. model = (const unsigned char *)of_get_property(np, "model", NULL);
  313. if (!model) {
  314. printk(KERN_ERR "%s: Unabel to get model info\n", __func__);
  315. return -ENODEV;
  316. }
  317. ret = strcmp(model, MAPLE_CPC925_MODEL);
  318. of_node_put(np);
  319. if (ret != 0)
  320. return 0;
  321. np = of_find_node_by_type(NULL, "memory-controller");
  322. if (!np) {
  323. printk(KERN_ERR "%s: Unable to find memory-controller node\n",
  324. __func__);
  325. return -ENODEV;
  326. }
  327. ret = of_address_to_resource(np, 0, &r);
  328. of_node_put(np);
  329. if (ret < 0) {
  330. printk(KERN_ERR "%s: Unable to get memory-controller reg\n",
  331. __func__);
  332. return -ENODEV;
  333. }
  334. pdev = platform_device_register_simple("cpc925_edac", 0, &r, 1);
  335. if (IS_ERR(pdev))
  336. return PTR_ERR(pdev);
  337. printk(KERN_INFO "%s: CPC925 platform device created\n", __func__);
  338. return 0;
  339. }
  340. machine_device_initcall(maple, maple_cpc925_edac_setup);
  341. #endif