pmac_setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. /*
  2. * arch/ppc/platforms/setup.c
  3. *
  4. * PowerPC version
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. *
  7. * Adapted for Power Macintosh by Paul Mackerras
  8. * Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
  9. *
  10. * Derived from "arch/alpha/kernel/setup.c"
  11. * Copyright (C) 1995 Linus Torvalds
  12. *
  13. * Maintained by Benjamin Herrenschmidt (benh@kernel.crashing.org)
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. *
  20. */
  21. /*
  22. * bootup setup stuff..
  23. */
  24. #undef DEBUG
  25. #include <linux/config.h>
  26. #include <linux/init.h>
  27. #include <linux/errno.h>
  28. #include <linux/sched.h>
  29. #include <linux/kernel.h>
  30. #include <linux/mm.h>
  31. #include <linux/stddef.h>
  32. #include <linux/unistd.h>
  33. #include <linux/ptrace.h>
  34. #include <linux/slab.h>
  35. #include <linux/user.h>
  36. #include <linux/a.out.h>
  37. #include <linux/tty.h>
  38. #include <linux/string.h>
  39. #include <linux/delay.h>
  40. #include <linux/ioport.h>
  41. #include <linux/major.h>
  42. #include <linux/initrd.h>
  43. #include <linux/vt_kern.h>
  44. #include <linux/console.h>
  45. #include <linux/ide.h>
  46. #include <linux/pci.h>
  47. #include <linux/adb.h>
  48. #include <linux/cuda.h>
  49. #include <linux/pmu.h>
  50. #include <linux/irq.h>
  51. #include <linux/seq_file.h>
  52. #include <linux/root_dev.h>
  53. #include <linux/bitops.h>
  54. #include <asm/processor.h>
  55. #include <asm/sections.h>
  56. #include <asm/prom.h>
  57. #include <asm/system.h>
  58. #include <asm/io.h>
  59. #include <asm/pci-bridge.h>
  60. #include <asm/iommu.h>
  61. #include <asm/machdep.h>
  62. #include <asm/dma.h>
  63. #include <asm/btext.h>
  64. #include <asm/cputable.h>
  65. #include <asm/pmac_feature.h>
  66. #include <asm/time.h>
  67. #include <asm/of_device.h>
  68. #include <asm/lmb.h>
  69. #include <asm/smu.h>
  70. #include <asm/pmc.h>
  71. #include "pmac.h"
  72. #include "mpic.h"
  73. #ifdef DEBUG
  74. #define DBG(fmt...) udbg_printf(fmt)
  75. #else
  76. #define DBG(fmt...)
  77. #endif
  78. static int current_root_goodness = -1;
  79. #define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */
  80. extern int powersave_nap;
  81. int sccdbg;
  82. sys_ctrler_t sys_ctrler;
  83. EXPORT_SYMBOL(sys_ctrler);
  84. #ifdef CONFIG_PMAC_SMU
  85. unsigned long smu_cmdbuf_abs;
  86. EXPORT_SYMBOL(smu_cmdbuf_abs);
  87. #endif
  88. extern void udbg_init_scc(struct device_node *np);
  89. static void __pmac pmac_show_cpuinfo(struct seq_file *m)
  90. {
  91. struct device_node *np;
  92. char *pp;
  93. int plen;
  94. char* mbname;
  95. int mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
  96. PMAC_MB_INFO_MODEL, 0);
  97. unsigned int mbflags = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
  98. PMAC_MB_INFO_FLAGS, 0);
  99. if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME,
  100. (long)&mbname) != 0)
  101. mbname = "Unknown";
  102. /* find motherboard type */
  103. seq_printf(m, "machine\t\t: ");
  104. np = find_devices("device-tree");
  105. if (np != NULL) {
  106. pp = (char *) get_property(np, "model", NULL);
  107. if (pp != NULL)
  108. seq_printf(m, "%s\n", pp);
  109. else
  110. seq_printf(m, "PowerMac\n");
  111. pp = (char *) get_property(np, "compatible", &plen);
  112. if (pp != NULL) {
  113. seq_printf(m, "motherboard\t:");
  114. while (plen > 0) {
  115. int l = strlen(pp) + 1;
  116. seq_printf(m, " %s", pp);
  117. plen -= l;
  118. pp += l;
  119. }
  120. seq_printf(m, "\n");
  121. }
  122. } else
  123. seq_printf(m, "PowerMac\n");
  124. /* print parsed model */
  125. seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname);
  126. seq_printf(m, "pmac flags\t: %08x\n", mbflags);
  127. /* Indicate newworld */
  128. seq_printf(m, "pmac-generation\t: NewWorld\n");
  129. }
  130. static void __init pmac_setup_arch(void)
  131. {
  132. /* init to some ~sane value until calibrate_delay() runs */
  133. loops_per_jiffy = 50000000;
  134. /* Probe motherboard chipset */
  135. pmac_feature_init();
  136. #if 0
  137. /* Lock-enable the SCC channel used for debug */
  138. if (sccdbg) {
  139. np = of_find_node_by_name(NULL, "escc");
  140. if (np)
  141. pmac_call_feature(PMAC_FTR_SCC_ENABLE, np,
  142. PMAC_SCC_ASYNC | PMAC_SCC_FLAG_XMON, 1);
  143. }
  144. #endif
  145. /* We can NAP */
  146. powersave_nap = 1;
  147. #ifdef CONFIG_ADB_PMU
  148. /* Initialize the PMU if any */
  149. find_via_pmu();
  150. #endif
  151. #ifdef CONFIG_PMAC_SMU
  152. /* Initialize the SMU if any */
  153. smu_init();
  154. #endif
  155. /* Init NVRAM access */
  156. pmac_nvram_init();
  157. /* Setup SMP callback */
  158. #ifdef CONFIG_SMP
  159. pmac_setup_smp();
  160. #endif
  161. /* Lookup PCI hosts */
  162. pmac_pci_init();
  163. #ifdef CONFIG_DUMMY_CONSOLE
  164. conswitchp = &dummy_con;
  165. #endif
  166. printk(KERN_INFO "Using native/NAP idle loop\n");
  167. }
  168. #ifdef CONFIG_SCSI
  169. void note_scsi_host(struct device_node *node, void *host)
  170. {
  171. /* Obsolete */
  172. }
  173. #endif
  174. static int initializing = 1;
  175. static int pmac_late_init(void)
  176. {
  177. initializing = 0;
  178. return 0;
  179. }
  180. late_initcall(pmac_late_init);
  181. /* can't be __init - can be called whenever a disk is first accessed */
  182. void __pmac note_bootable_part(dev_t dev, int part, int goodness)
  183. {
  184. extern dev_t boot_dev;
  185. char *p;
  186. if (!initializing)
  187. return;
  188. if ((goodness <= current_root_goodness) &&
  189. ROOT_DEV != DEFAULT_ROOT_DEVICE)
  190. return;
  191. p = strstr(saved_command_line, "root=");
  192. if (p != NULL && (p == saved_command_line || p[-1] == ' '))
  193. return;
  194. if (!boot_dev || dev == boot_dev) {
  195. ROOT_DEV = dev + part;
  196. boot_dev = 0;
  197. current_root_goodness = goodness;
  198. }
  199. }
  200. static void __pmac pmac_restart(char *cmd)
  201. {
  202. switch(sys_ctrler) {
  203. #ifdef CONFIG_ADB_PMU
  204. case SYS_CTRLER_PMU:
  205. pmu_restart();
  206. break;
  207. #endif
  208. #ifdef CONFIG_PMAC_SMU
  209. case SYS_CTRLER_SMU:
  210. smu_restart();
  211. break;
  212. #endif
  213. default:
  214. ;
  215. }
  216. }
  217. static void __pmac pmac_power_off(void)
  218. {
  219. switch(sys_ctrler) {
  220. #ifdef CONFIG_ADB_PMU
  221. case SYS_CTRLER_PMU:
  222. pmu_shutdown();
  223. break;
  224. #endif
  225. #ifdef CONFIG_PMAC_SMU
  226. case SYS_CTRLER_SMU:
  227. smu_shutdown();
  228. break;
  229. #endif
  230. default:
  231. ;
  232. }
  233. }
  234. static void __pmac pmac_halt(void)
  235. {
  236. pmac_power_off();
  237. }
  238. #ifdef CONFIG_BOOTX_TEXT
  239. static void btext_putc(unsigned char c)
  240. {
  241. btext_drawchar(c);
  242. }
  243. static void __init init_boot_display(void)
  244. {
  245. char *name;
  246. struct device_node *np = NULL;
  247. int rc = -ENODEV;
  248. printk("trying to initialize btext ...\n");
  249. name = (char *)get_property(of_chosen, "linux,stdout-path", NULL);
  250. if (name != NULL) {
  251. np = of_find_node_by_path(name);
  252. if (np != NULL) {
  253. if (strcmp(np->type, "display") != 0) {
  254. printk("boot stdout isn't a display !\n");
  255. of_node_put(np);
  256. np = NULL;
  257. }
  258. }
  259. }
  260. if (np)
  261. rc = btext_initialize(np);
  262. if (rc == 0)
  263. return;
  264. for (np = NULL; (np = of_find_node_by_type(np, "display"));) {
  265. if (get_property(np, "linux,opened", NULL)) {
  266. printk("trying %s ...\n", np->full_name);
  267. rc = btext_initialize(np);
  268. printk("result: %d\n", rc);
  269. }
  270. if (rc == 0)
  271. return;
  272. }
  273. }
  274. #endif /* CONFIG_BOOTX_TEXT */
  275. /*
  276. * Early initialization.
  277. */
  278. static void __init pmac_init_early(void)
  279. {
  280. DBG(" -> pmac_init_early\n");
  281. /* Initialize hash table, from now on, we can take hash faults
  282. * and call ioremap
  283. */
  284. hpte_init_native();
  285. /* Init SCC */
  286. if (strstr(cmd_line, "sccdbg")) {
  287. sccdbg = 1;
  288. udbg_init_scc(NULL);
  289. }
  290. #ifdef CONFIG_BOOTX_TEXT
  291. else {
  292. init_boot_display();
  293. udbg_putc = btext_putc;
  294. }
  295. #endif /* CONFIG_BOOTX_TEXT */
  296. /* Setup interrupt mapping options */
  297. ppc64_interrupt_controller = IC_OPEN_PIC;
  298. iommu_init_early_u3();
  299. DBG(" <- pmac_init_early\n");
  300. }
  301. static int pmac_u3_cascade(struct pt_regs *regs, void *data)
  302. {
  303. return mpic_get_one_irq((struct mpic *)data, regs);
  304. }
  305. static __init void pmac_init_IRQ(void)
  306. {
  307. struct device_node *irqctrler = NULL;
  308. struct device_node *irqctrler2 = NULL;
  309. struct device_node *np = NULL;
  310. struct mpic *mpic1, *mpic2;
  311. /* We first try to detect Apple's new Core99 chipset, since mac-io
  312. * is quite different on those machines and contains an IBM MPIC2.
  313. */
  314. while ((np = of_find_node_by_type(np, "open-pic")) != NULL) {
  315. struct device_node *parent = of_get_parent(np);
  316. if (parent && !strcmp(parent->name, "u3"))
  317. irqctrler2 = of_node_get(np);
  318. else
  319. irqctrler = of_node_get(np);
  320. of_node_put(parent);
  321. }
  322. if (irqctrler != NULL && irqctrler->n_addrs > 0) {
  323. unsigned char senses[128];
  324. printk(KERN_INFO "PowerMac using OpenPIC irq controller at 0x%08x\n",
  325. (unsigned int)irqctrler->addrs[0].address);
  326. prom_get_irq_senses(senses, 0, 128);
  327. mpic1 = mpic_alloc(irqctrler->addrs[0].address,
  328. MPIC_PRIMARY | MPIC_WANTS_RESET,
  329. 0, 0, 128, 256, senses, 128, " K2-MPIC ");
  330. BUG_ON(mpic1 == NULL);
  331. mpic_init(mpic1);
  332. if (irqctrler2 != NULL && irqctrler2->n_intrs > 0 &&
  333. irqctrler2->n_addrs > 0) {
  334. printk(KERN_INFO "Slave OpenPIC at 0x%08x hooked on IRQ %d\n",
  335. (u32)irqctrler2->addrs[0].address,
  336. irqctrler2->intrs[0].line);
  337. pmac_call_feature(PMAC_FTR_ENABLE_MPIC, irqctrler2, 0, 0);
  338. prom_get_irq_senses(senses, 128, 128 + 128);
  339. /* We don't need to set MPIC_BROKEN_U3 here since we don't have
  340. * hypertransport interrupts routed to it
  341. */
  342. mpic2 = mpic_alloc(irqctrler2->addrs[0].address,
  343. MPIC_BIG_ENDIAN | MPIC_WANTS_RESET,
  344. 0, 128, 128, 0, senses, 128, " U3-MPIC ");
  345. BUG_ON(mpic2 == NULL);
  346. mpic_init(mpic2);
  347. mpic_setup_cascade(irqctrler2->intrs[0].line,
  348. pmac_u3_cascade, mpic2);
  349. }
  350. }
  351. of_node_put(irqctrler);
  352. of_node_put(irqctrler2);
  353. }
  354. static void __init pmac_progress(char *s, unsigned short hex)
  355. {
  356. if (sccdbg) {
  357. udbg_puts(s);
  358. udbg_puts("\n");
  359. }
  360. #ifdef CONFIG_BOOTX_TEXT
  361. else if (boot_text_mapped) {
  362. btext_drawstring(s);
  363. btext_drawstring("\n");
  364. }
  365. #endif /* CONFIG_BOOTX_TEXT */
  366. }
  367. /*
  368. * pmac has no legacy IO, anything calling this function has to
  369. * fail or bad things will happen
  370. */
  371. static int pmac_check_legacy_ioport(unsigned int baseport)
  372. {
  373. return -ENODEV;
  374. }
  375. static int __init pmac_declare_of_platform_devices(void)
  376. {
  377. struct device_node *np;
  378. np = find_devices("u3");
  379. if (np) {
  380. for (np = np->child; np != NULL; np = np->sibling)
  381. if (strncmp(np->name, "i2c", 3) == 0) {
  382. of_platform_device_create(np, "u3-i2c");
  383. break;
  384. }
  385. }
  386. return 0;
  387. }
  388. device_initcall(pmac_declare_of_platform_devices);
  389. /*
  390. * Called very early, MMU is off, device-tree isn't unflattened
  391. */
  392. static int __init pmac_probe(int platform)
  393. {
  394. if (platform != PLATFORM_POWERMAC)
  395. return 0;
  396. /*
  397. * On U3, the DART (iommu) must be allocated now since it
  398. * has an impact on htab_initialize (due to the large page it
  399. * occupies having to be broken up so the DART itself is not
  400. * part of the cacheable linar mapping
  401. */
  402. alloc_u3_dart_table();
  403. #ifdef CONFIG_PMAC_SMU
  404. /*
  405. * SMU based G5s need some memory below 2Gb, at least the current
  406. * driver needs that. We have to allocate it now. We allocate 4k
  407. * (1 small page) for now.
  408. */
  409. smu_cmdbuf_abs = lmb_alloc_base(4096, 4096, 0x80000000UL);
  410. #endif /* CONFIG_PMAC_SMU */
  411. return 1;
  412. }
  413. struct machdep_calls __initdata pmac_md = {
  414. #ifdef CONFIG_HOTPLUG_CPU
  415. .cpu_die = generic_mach_cpu_die,
  416. #endif
  417. .probe = pmac_probe,
  418. .setup_arch = pmac_setup_arch,
  419. .init_early = pmac_init_early,
  420. .get_cpuinfo = pmac_show_cpuinfo,
  421. .init_IRQ = pmac_init_IRQ,
  422. .get_irq = mpic_get_irq,
  423. .pcibios_fixup = pmac_pcibios_fixup,
  424. .restart = pmac_restart,
  425. .power_off = pmac_power_off,
  426. .halt = pmac_halt,
  427. .get_boot_time = pmac_get_boot_time,
  428. .set_rtc_time = pmac_set_rtc_time,
  429. .get_rtc_time = pmac_get_rtc_time,
  430. .calibrate_decr = pmac_calibrate_decr,
  431. .feature_call = pmac_do_feature_call,
  432. .progress = pmac_progress,
  433. .check_legacy_ioport = pmac_check_legacy_ioport,
  434. .idle_loop = native_idle,
  435. .enable_pmcs = power4_enable_pmcs,
  436. };