pmac_setup.c 11 KB

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