setup.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. extern void generic_find_legacy_serial_ports(u64 *physport,
  69. unsigned int *default_speed);
  70. static void maple_restart(char *cmd)
  71. {
  72. unsigned int maple_nvram_base;
  73. unsigned int maple_nvram_offset;
  74. unsigned int maple_nvram_command;
  75. struct device_node *rtcs;
  76. /* find NVRAM device */
  77. rtcs = find_compatible_devices("nvram", "AMD8111");
  78. if (rtcs && rtcs->addrs) {
  79. maple_nvram_base = rtcs->addrs[0].address;
  80. } else {
  81. printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
  82. printk(KERN_EMERG "Maple: Manual Restart Required\n");
  83. return;
  84. }
  85. /* find service processor device */
  86. rtcs = find_devices("service-processor");
  87. if (!rtcs) {
  88. printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
  89. printk(KERN_EMERG "Maple: Manual Restart Required\n");
  90. return;
  91. }
  92. maple_nvram_offset = *(unsigned int*) get_property(rtcs,
  93. "restart-addr", NULL);
  94. maple_nvram_command = *(unsigned int*) get_property(rtcs,
  95. "restart-value", NULL);
  96. /* send command */
  97. outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
  98. for (;;) ;
  99. }
  100. static void maple_power_off(void)
  101. {
  102. unsigned int maple_nvram_base;
  103. unsigned int maple_nvram_offset;
  104. unsigned int maple_nvram_command;
  105. struct device_node *rtcs;
  106. /* find NVRAM device */
  107. rtcs = find_compatible_devices("nvram", "AMD8111");
  108. if (rtcs && rtcs->addrs) {
  109. maple_nvram_base = rtcs->addrs[0].address;
  110. } else {
  111. printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
  112. printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
  113. return;
  114. }
  115. /* find service processor device */
  116. rtcs = find_devices("service-processor");
  117. if (!rtcs) {
  118. printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
  119. printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
  120. return;
  121. }
  122. maple_nvram_offset = *(unsigned int*) get_property(rtcs,
  123. "power-off-addr", NULL);
  124. maple_nvram_command = *(unsigned int*) get_property(rtcs,
  125. "power-off-value", NULL);
  126. /* send command */
  127. outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
  128. for (;;) ;
  129. }
  130. static void maple_halt(void)
  131. {
  132. maple_power_off();
  133. }
  134. #ifdef CONFIG_SMP
  135. struct smp_ops_t maple_smp_ops = {
  136. .probe = smp_mpic_probe,
  137. .message_pass = smp_mpic_message_pass,
  138. .kick_cpu = smp_generic_kick_cpu,
  139. .setup_cpu = smp_mpic_setup_cpu,
  140. .give_timebase = smp_generic_give_timebase,
  141. .take_timebase = smp_generic_take_timebase,
  142. };
  143. #endif /* CONFIG_SMP */
  144. void __init maple_setup_arch(void)
  145. {
  146. /* init to some ~sane value until calibrate_delay() runs */
  147. loops_per_jiffy = 50000000;
  148. /* Setup SMP callback */
  149. #ifdef CONFIG_SMP
  150. smp_ops = &maple_smp_ops;
  151. #endif
  152. /* Lookup PCI hosts */
  153. maple_pci_init();
  154. #ifdef CONFIG_DUMMY_CONSOLE
  155. conswitchp = &dummy_con;
  156. #endif
  157. printk(KERN_INFO "Using native/NAP idle loop\n");
  158. }
  159. /*
  160. * Early initialization.
  161. */
  162. static void __init maple_init_early(void)
  163. {
  164. unsigned int default_speed;
  165. u64 physport;
  166. DBG(" -> maple_init_early\n");
  167. /* Initialize hash table, from now on, we can take hash faults
  168. * and call ioremap
  169. */
  170. hpte_init_native();
  171. /* Find the serial port */
  172. generic_find_legacy_serial_ports(&physport, &default_speed);
  173. DBG("phys port addr: %lx\n", (long)physport);
  174. if (physport) {
  175. void *comport;
  176. /* Map the uart for udbg. */
  177. comport = (void *)ioremap(physport, 16);
  178. udbg_init_uart(comport, default_speed);
  179. DBG("Hello World !\n");
  180. }
  181. /* Setup interrupt mapping options */
  182. ppc64_interrupt_controller = IC_OPEN_PIC;
  183. iommu_init_early_u3();
  184. DBG(" <- maple_init_early\n");
  185. }
  186. static __init void maple_init_IRQ(void)
  187. {
  188. struct device_node *root;
  189. unsigned int *opprop;
  190. unsigned long opic_addr;
  191. struct mpic *mpic;
  192. unsigned char senses[128];
  193. int n;
  194. DBG(" -> maple_init_IRQ\n");
  195. /* XXX: Non standard, replace that with a proper openpic/mpic node
  196. * in the device-tree. Find the Open PIC if present */
  197. root = of_find_node_by_path("/");
  198. opprop = (unsigned int *) get_property(root,
  199. "platform-open-pic", NULL);
  200. if (opprop == 0)
  201. panic("OpenPIC not found !\n");
  202. n = prom_n_addr_cells(root);
  203. for (opic_addr = 0; n > 0; --n)
  204. opic_addr = (opic_addr << 32) + *opprop++;
  205. of_node_put(root);
  206. /* Obtain sense values from device-tree */
  207. prom_get_irq_senses(senses, 0, 128);
  208. mpic = mpic_alloc(opic_addr,
  209. MPIC_PRIMARY | MPIC_BIG_ENDIAN |
  210. MPIC_BROKEN_U3 | MPIC_WANTS_RESET,
  211. 0, 0, 128, 128, senses, 128, "U3-MPIC");
  212. BUG_ON(mpic == NULL);
  213. mpic_init(mpic);
  214. DBG(" <- maple_init_IRQ\n");
  215. }
  216. static void __init maple_progress(char *s, unsigned short hex)
  217. {
  218. printk("*** %04x : %s\n", hex, s ? s : "");
  219. }
  220. /*
  221. * Called very early, MMU is off, device-tree isn't unflattened
  222. */
  223. static int __init maple_probe(int platform)
  224. {
  225. if (platform != PLATFORM_MAPLE)
  226. return 0;
  227. /*
  228. * On U3, the DART (iommu) must be allocated now since it
  229. * has an impact on htab_initialize (due to the large page it
  230. * occupies having to be broken up so the DART itself is not
  231. * part of the cacheable linar mapping
  232. */
  233. alloc_u3_dart_table();
  234. return 1;
  235. }
  236. struct machdep_calls __initdata maple_md = {
  237. .probe = maple_probe,
  238. .setup_arch = maple_setup_arch,
  239. .init_early = maple_init_early,
  240. .init_IRQ = maple_init_IRQ,
  241. .get_irq = mpic_get_irq,
  242. .pcibios_fixup = maple_pcibios_fixup,
  243. .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
  244. .restart = maple_restart,
  245. .power_off = maple_power_off,
  246. .halt = maple_halt,
  247. .get_boot_time = maple_get_boot_time,
  248. .set_rtc_time = maple_set_rtc_time,
  249. .get_rtc_time = maple_get_rtc_time,
  250. .calibrate_decr = generic_calibrate_decr,
  251. .progress = maple_progress,
  252. .idle_loop = native_idle,
  253. #ifdef CONFIG_KEXEC
  254. .machine_kexec = default_machine_kexec,
  255. .machine_kexec_prepare = default_machine_kexec_prepare,
  256. #endif
  257. };