pmac_setup.c 12 KB

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