setup.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. #define DEBUG
  14. #include <linux/config.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <linux/sched.h>
  18. #include <linux/kernel.h>
  19. #include <linux/mm.h>
  20. #include <linux/stddef.h>
  21. #include <linux/unistd.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/slab.h>
  24. #include <linux/user.h>
  25. #include <linux/a.out.h>
  26. #include <linux/tty.h>
  27. #include <linux/string.h>
  28. #include <linux/delay.h>
  29. #include <linux/ioport.h>
  30. #include <linux/major.h>
  31. #include <linux/initrd.h>
  32. #include <linux/vt_kern.h>
  33. #include <linux/console.h>
  34. #include <linux/ide.h>
  35. #include <linux/pci.h>
  36. #include <linux/adb.h>
  37. #include <linux/cuda.h>
  38. #include <linux/pmu.h>
  39. #include <linux/irq.h>
  40. #include <linux/seq_file.h>
  41. #include <linux/root_dev.h>
  42. #include <linux/serial.h>
  43. #include <linux/smp.h>
  44. #include <asm/processor.h>
  45. #include <asm/sections.h>
  46. #include <asm/prom.h>
  47. #include <asm/system.h>
  48. #include <asm/pgtable.h>
  49. #include <asm/bitops.h>
  50. #include <asm/io.h>
  51. #include <asm/kexec.h>
  52. #include <asm/pci-bridge.h>
  53. #include <asm/iommu.h>
  54. #include <asm/machdep.h>
  55. #include <asm/dma.h>
  56. #include <asm/cputable.h>
  57. #include <asm/time.h>
  58. #include <asm/of_device.h>
  59. #include <asm/lmb.h>
  60. #include <asm/mpic.h>
  61. #include <asm/udbg.h>
  62. #include "maple.h"
  63. #ifdef DEBUG
  64. #define DBG(fmt...) udbg_printf(fmt)
  65. #else
  66. #define DBG(fmt...)
  67. #endif
  68. static unsigned long maple_find_nvram_base(void)
  69. {
  70. struct device_node *rtcs;
  71. unsigned long result = 0;
  72. /* find NVRAM device */
  73. rtcs = of_find_compatible_node(NULL, "nvram", "AMD8111");
  74. if (rtcs) {
  75. struct resource r;
  76. if (of_address_to_resource(rtcs, 0, &r)) {
  77. printk(KERN_EMERG "Maple: Unable to translate NVRAM"
  78. " address\n");
  79. goto bail;
  80. }
  81. if (!(r.flags & IORESOURCE_IO)) {
  82. printk(KERN_EMERG "Maple: NVRAM address isn't PIO!\n");
  83. goto bail;
  84. }
  85. result = r.start;
  86. } else
  87. printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
  88. bail:
  89. of_node_put(rtcs);
  90. return result;
  91. }
  92. static void maple_restart(char *cmd)
  93. {
  94. unsigned int maple_nvram_base;
  95. unsigned int maple_nvram_offset;
  96. unsigned int maple_nvram_command;
  97. struct device_node *sp;
  98. maple_nvram_base = maple_find_nvram_base();
  99. if (maple_nvram_base == 0)
  100. goto fail;
  101. /* find service processor device */
  102. sp = of_find_node_by_name(NULL, "service-processor");
  103. if (!sp) {
  104. printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
  105. goto fail;
  106. }
  107. maple_nvram_offset = *(unsigned int*) get_property(sp,
  108. "restart-addr", NULL);
  109. maple_nvram_command = *(unsigned int*) get_property(sp,
  110. "restart-value", NULL);
  111. of_node_put(sp);
  112. /* send command */
  113. outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
  114. for (;;) ;
  115. fail:
  116. printk(KERN_EMERG "Maple: Manual Restart Required\n");
  117. }
  118. static void maple_power_off(void)
  119. {
  120. unsigned int maple_nvram_base;
  121. unsigned int maple_nvram_offset;
  122. unsigned int maple_nvram_command;
  123. struct device_node *sp;
  124. maple_nvram_base = maple_find_nvram_base();
  125. if (maple_nvram_base == 0)
  126. goto fail;
  127. /* find service processor device */
  128. sp = of_find_node_by_name(NULL, "service-processor");
  129. if (!sp) {
  130. printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
  131. goto fail;
  132. }
  133. maple_nvram_offset = *(unsigned int*) get_property(sp,
  134. "power-off-addr", NULL);
  135. maple_nvram_command = *(unsigned int*) get_property(sp,
  136. "power-off-value", NULL);
  137. of_node_put(sp);
  138. /* send command */
  139. outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
  140. for (;;) ;
  141. fail:
  142. printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
  143. }
  144. static void maple_halt(void)
  145. {
  146. maple_power_off();
  147. }
  148. #ifdef CONFIG_SMP
  149. struct smp_ops_t maple_smp_ops = {
  150. .probe = smp_mpic_probe,
  151. .message_pass = smp_mpic_message_pass,
  152. .kick_cpu = smp_generic_kick_cpu,
  153. .setup_cpu = smp_mpic_setup_cpu,
  154. .give_timebase = smp_generic_give_timebase,
  155. .take_timebase = smp_generic_take_timebase,
  156. };
  157. #endif /* CONFIG_SMP */
  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. printk(KERN_DEBUG "Using native/NAP idle loop\n");
  172. }
  173. /*
  174. * Early initialization.
  175. */
  176. static void __init maple_init_early(void)
  177. {
  178. DBG(" -> maple_init_early\n");
  179. /* Setup interrupt mapping options */
  180. ppc64_interrupt_controller = IC_OPEN_PIC;
  181. iommu_init_early_dart();
  182. DBG(" <- maple_init_early\n");
  183. }
  184. static __init void maple_init_IRQ(void)
  185. {
  186. struct device_node *root;
  187. unsigned int *opprop;
  188. unsigned long opic_addr;
  189. struct mpic *mpic;
  190. unsigned char senses[128];
  191. int n;
  192. DBG(" -> maple_init_IRQ\n");
  193. /* XXX: Non standard, replace that with a proper openpic/mpic node
  194. * in the device-tree. Find the Open PIC if present */
  195. root = of_find_node_by_path("/");
  196. opprop = (unsigned int *) get_property(root,
  197. "platform-open-pic", NULL);
  198. if (opprop == 0)
  199. panic("OpenPIC not found !\n");
  200. n = prom_n_addr_cells(root);
  201. for (opic_addr = 0; n > 0; --n)
  202. opic_addr = (opic_addr << 32) + *opprop++;
  203. of_node_put(root);
  204. /* Obtain sense values from device-tree */
  205. prom_get_irq_senses(senses, 0, 128);
  206. mpic = mpic_alloc(opic_addr,
  207. MPIC_PRIMARY | MPIC_BIG_ENDIAN |
  208. MPIC_BROKEN_U3 | MPIC_WANTS_RESET,
  209. 0, 0, 128, 128, senses, 128, "U3-MPIC");
  210. BUG_ON(mpic == NULL);
  211. mpic_init(mpic);
  212. DBG(" <- maple_init_IRQ\n");
  213. }
  214. static void __init maple_progress(char *s, unsigned short hex)
  215. {
  216. printk("*** %04x : %s\n", hex, s ? s : "");
  217. }
  218. /*
  219. * Called very early, MMU is off, device-tree isn't unflattened
  220. */
  221. static int __init maple_probe(void)
  222. {
  223. unsigned long root = of_get_flat_dt_root();
  224. if (!of_flat_dt_is_compatible(root, "Momentum,Maple"))
  225. return 0;
  226. /*
  227. * On U3, the DART (iommu) must be allocated now since it
  228. * has an impact on htab_initialize (due to the large page it
  229. * occupies having to be broken up so the DART itself is not
  230. * part of the cacheable linar mapping
  231. */
  232. alloc_dart_table();
  233. hpte_init_native();
  234. return 1;
  235. }
  236. define_machine(maple_md) {
  237. .name = "Maple",
  238. .probe = maple_probe,
  239. .setup_arch = maple_setup_arch,
  240. .init_early = maple_init_early,
  241. .init_IRQ = maple_init_IRQ,
  242. .get_irq = mpic_get_irq,
  243. .pcibios_fixup = maple_pcibios_fixup,
  244. .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
  245. .restart = maple_restart,
  246. .power_off = maple_power_off,
  247. .halt = maple_halt,
  248. .get_boot_time = maple_get_boot_time,
  249. .set_rtc_time = maple_set_rtc_time,
  250. .get_rtc_time = maple_get_rtc_time,
  251. .calibrate_decr = generic_calibrate_decr,
  252. .progress = maple_progress,
  253. .power_save = power4_idle,
  254. #ifdef CONFIG_KEXEC
  255. .machine_kexec = default_machine_kexec,
  256. .machine_kexec_prepare = default_machine_kexec_prepare,
  257. .machine_crash_shutdown = default_machine_crash_shutdown,
  258. #endif
  259. };