setup.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*
  2. * Powermac setup and early boot code plus other random bits.
  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@samba.org)
  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. #include <linux/init.h>
  25. #include <linux/errno.h>
  26. #include <linux/sched.h>
  27. #include <linux/kernel.h>
  28. #include <linux/mm.h>
  29. #include <linux/stddef.h>
  30. #include <linux/unistd.h>
  31. #include <linux/ptrace.h>
  32. #include <linux/export.h>
  33. #include <linux/user.h>
  34. #include <linux/tty.h>
  35. #include <linux/string.h>
  36. #include <linux/delay.h>
  37. #include <linux/ioport.h>
  38. #include <linux/major.h>
  39. #include <linux/initrd.h>
  40. #include <linux/vt_kern.h>
  41. #include <linux/console.h>
  42. #include <linux/pci.h>
  43. #include <linux/adb.h>
  44. #include <linux/cuda.h>
  45. #include <linux/pmu.h>
  46. #include <linux/irq.h>
  47. #include <linux/seq_file.h>
  48. #include <linux/root_dev.h>
  49. #include <linux/bitops.h>
  50. #include <linux/suspend.h>
  51. #include <linux/of_device.h>
  52. #include <linux/of_platform.h>
  53. #include <asm/reg.h>
  54. #include <asm/sections.h>
  55. #include <asm/prom.h>
  56. #include <asm/pgtable.h>
  57. #include <asm/io.h>
  58. #include <asm/pci-bridge.h>
  59. #include <asm/ohare.h>
  60. #include <asm/mediabay.h>
  61. #include <asm/machdep.h>
  62. #include <asm/dma.h>
  63. #include <asm/cputable.h>
  64. #include <asm/btext.h>
  65. #include <asm/pmac_feature.h>
  66. #include <asm/time.h>
  67. #include <asm/mmu_context.h>
  68. #include <asm/iommu.h>
  69. #include <asm/smu.h>
  70. #include <asm/pmc.h>
  71. #include <asm/udbg.h>
  72. #include "pmac.h"
  73. #undef SHOW_GATWICK_IRQS
  74. int ppc_override_l2cr = 0;
  75. int ppc_override_l2cr_value;
  76. int has_l2cache = 0;
  77. int pmac_newworld;
  78. static int current_root_goodness = -1;
  79. extern struct machdep_calls pmac_md;
  80. #define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */
  81. #ifdef CONFIG_PPC64
  82. int sccdbg;
  83. #endif
  84. sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN;
  85. EXPORT_SYMBOL(sys_ctrler);
  86. static void pmac_show_cpuinfo(struct seq_file *m)
  87. {
  88. struct device_node *np;
  89. const char *pp;
  90. int plen;
  91. int mbmodel;
  92. unsigned int mbflags;
  93. char* mbname;
  94. mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
  95. PMAC_MB_INFO_MODEL, 0);
  96. 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 = of_find_node_by_path("/");
  104. if (np != NULL) {
  105. pp = of_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 = of_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. of_node_put(np);
  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. /* find l2 cache info */
  128. np = of_find_node_by_name(NULL, "l2-cache");
  129. if (np == NULL)
  130. np = of_find_node_by_type(NULL, "cache");
  131. if (np != NULL) {
  132. const unsigned int *ic =
  133. of_get_property(np, "i-cache-size", NULL);
  134. const unsigned int *dc =
  135. of_get_property(np, "d-cache-size", NULL);
  136. seq_printf(m, "L2 cache\t:");
  137. has_l2cache = 1;
  138. if (of_get_property(np, "cache-unified", NULL) != 0 && dc) {
  139. seq_printf(m, " %dK unified", *dc / 1024);
  140. } else {
  141. if (ic)
  142. seq_printf(m, " %dK instruction", *ic / 1024);
  143. if (dc)
  144. seq_printf(m, "%s %dK data",
  145. (ic? " +": ""), *dc / 1024);
  146. }
  147. pp = of_get_property(np, "ram-type", NULL);
  148. if (pp)
  149. seq_printf(m, " %s", pp);
  150. seq_printf(m, "\n");
  151. of_node_put(np);
  152. }
  153. /* Indicate newworld/oldworld */
  154. seq_printf(m, "pmac-generation\t: %s\n",
  155. pmac_newworld ? "NewWorld" : "OldWorld");
  156. }
  157. #ifndef CONFIG_ADB_CUDA
  158. int find_via_cuda(void)
  159. {
  160. struct device_node *dn = of_find_node_by_name(NULL, "via-cuda");
  161. if (!dn)
  162. return 0;
  163. of_node_put(dn);
  164. printk("WARNING ! Your machine is CUDA-based but your kernel\n");
  165. printk(" wasn't compiled with CONFIG_ADB_CUDA option !\n");
  166. return 0;
  167. }
  168. #endif
  169. #ifndef CONFIG_ADB_PMU
  170. int find_via_pmu(void)
  171. {
  172. struct device_node *dn = of_find_node_by_name(NULL, "via-pmu");
  173. if (!dn)
  174. return 0;
  175. of_node_put(dn);
  176. printk("WARNING ! Your machine is PMU-based but your kernel\n");
  177. printk(" wasn't compiled with CONFIG_ADB_PMU option !\n");
  178. return 0;
  179. }
  180. #endif
  181. #ifndef CONFIG_PMAC_SMU
  182. int smu_init(void)
  183. {
  184. /* should check and warn if SMU is present */
  185. return 0;
  186. }
  187. #endif
  188. #ifdef CONFIG_PPC32
  189. static volatile u32 *sysctrl_regs;
  190. static void __init ohare_init(void)
  191. {
  192. struct device_node *dn;
  193. /* this area has the CPU identification register
  194. and some registers used by smp boards */
  195. sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000);
  196. /*
  197. * Turn on the L2 cache.
  198. * We assume that we have a PSX memory controller iff
  199. * we have an ohare I/O controller.
  200. */
  201. dn = of_find_node_by_name(NULL, "ohare");
  202. if (dn) {
  203. of_node_put(dn);
  204. if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) {
  205. if (sysctrl_regs[4] & 0x10)
  206. sysctrl_regs[4] |= 0x04000020;
  207. else
  208. sysctrl_regs[4] |= 0x04000000;
  209. if(has_l2cache)
  210. printk(KERN_INFO "Level 2 cache enabled\n");
  211. }
  212. }
  213. }
  214. static void __init l2cr_init(void)
  215. {
  216. /* Checks "l2cr-value" property in the registry */
  217. if (cpu_has_feature(CPU_FTR_L2CR)) {
  218. struct device_node *np = of_find_node_by_name(NULL, "cpus");
  219. if (np == 0)
  220. np = of_find_node_by_type(NULL, "cpu");
  221. if (np != 0) {
  222. const unsigned int *l2cr =
  223. of_get_property(np, "l2cr-value", NULL);
  224. if (l2cr != 0) {
  225. ppc_override_l2cr = 1;
  226. ppc_override_l2cr_value = *l2cr;
  227. _set_L2CR(0);
  228. _set_L2CR(ppc_override_l2cr_value);
  229. }
  230. of_node_put(np);
  231. }
  232. }
  233. if (ppc_override_l2cr)
  234. printk(KERN_INFO "L2CR overridden (0x%x), "
  235. "backside cache is %s\n",
  236. ppc_override_l2cr_value,
  237. (ppc_override_l2cr_value & 0x80000000)
  238. ? "enabled" : "disabled");
  239. }
  240. #endif
  241. static void __init pmac_setup_arch(void)
  242. {
  243. struct device_node *cpu, *ic;
  244. const int *fp;
  245. unsigned long pvr;
  246. pvr = PVR_VER(mfspr(SPRN_PVR));
  247. /* Set loops_per_jiffy to a half-way reasonable value,
  248. for use until calibrate_delay gets called. */
  249. loops_per_jiffy = 50000000 / HZ;
  250. cpu = of_find_node_by_type(NULL, "cpu");
  251. if (cpu != NULL) {
  252. fp = of_get_property(cpu, "clock-frequency", NULL);
  253. if (fp != NULL) {
  254. if (pvr >= 0x30 && pvr < 0x80)
  255. /* PPC970 etc. */
  256. loops_per_jiffy = *fp / (3 * HZ);
  257. else if (pvr == 4 || pvr >= 8)
  258. /* 604, G3, G4 etc. */
  259. loops_per_jiffy = *fp / HZ;
  260. else
  261. /* 601, 603, etc. */
  262. loops_per_jiffy = *fp / (2 * HZ);
  263. }
  264. of_node_put(cpu);
  265. }
  266. /* See if newworld or oldworld */
  267. ic = of_find_node_with_property(NULL, "interrupt-controller");
  268. if (ic) {
  269. pmac_newworld = 1;
  270. of_node_put(ic);
  271. }
  272. /* Lookup PCI hosts */
  273. pmac_pci_init();
  274. #ifdef CONFIG_PPC32
  275. ohare_init();
  276. l2cr_init();
  277. #endif /* CONFIG_PPC32 */
  278. find_via_cuda();
  279. find_via_pmu();
  280. smu_init();
  281. #if defined(CONFIG_NVRAM) || defined(CONFIG_NVRAM_MODULE) || \
  282. defined(CONFIG_PPC64)
  283. pmac_nvram_init();
  284. #endif
  285. #ifdef CONFIG_PPC32
  286. #ifdef CONFIG_BLK_DEV_INITRD
  287. if (initrd_start)
  288. ROOT_DEV = Root_RAM0;
  289. else
  290. #endif
  291. ROOT_DEV = DEFAULT_ROOT_DEVICE;
  292. #endif
  293. #ifdef CONFIG_ADB
  294. if (strstr(boot_command_line, "adb_sync")) {
  295. extern int __adb_probe_sync;
  296. __adb_probe_sync = 1;
  297. }
  298. #endif /* CONFIG_ADB */
  299. }
  300. #ifdef CONFIG_SCSI
  301. void note_scsi_host(struct device_node *node, void *host)
  302. {
  303. }
  304. EXPORT_SYMBOL(note_scsi_host);
  305. #endif
  306. static int initializing = 1;
  307. static int pmac_late_init(void)
  308. {
  309. initializing = 0;
  310. return 0;
  311. }
  312. machine_late_initcall(powermac, pmac_late_init);
  313. /*
  314. * This is __ref because we check for "initializing" before
  315. * touching any of the __init sensitive things and "initializing"
  316. * will be false after __init time. This can't be __init because it
  317. * can be called whenever a disk is first accessed.
  318. */
  319. void __ref note_bootable_part(dev_t dev, int part, int goodness)
  320. {
  321. char *p;
  322. if (!initializing)
  323. return;
  324. if ((goodness <= current_root_goodness) &&
  325. ROOT_DEV != DEFAULT_ROOT_DEVICE)
  326. return;
  327. p = strstr(boot_command_line, "root=");
  328. if (p != NULL && (p == boot_command_line || p[-1] == ' '))
  329. return;
  330. ROOT_DEV = dev + part;
  331. current_root_goodness = goodness;
  332. }
  333. #ifdef CONFIG_ADB_CUDA
  334. static void __noreturn cuda_restart(void)
  335. {
  336. struct adb_request req;
  337. cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM);
  338. for (;;)
  339. cuda_poll();
  340. }
  341. static void __noreturn cuda_shutdown(void)
  342. {
  343. struct adb_request req;
  344. cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN);
  345. for (;;)
  346. cuda_poll();
  347. }
  348. #else
  349. #define cuda_restart()
  350. #define cuda_shutdown()
  351. #endif
  352. #ifndef CONFIG_ADB_PMU
  353. #define pmu_restart()
  354. #define pmu_shutdown()
  355. #endif
  356. #ifndef CONFIG_PMAC_SMU
  357. #define smu_restart()
  358. #define smu_shutdown()
  359. #endif
  360. static void __noreturn pmac_restart(char *cmd)
  361. {
  362. switch (sys_ctrler) {
  363. case SYS_CTRLER_CUDA:
  364. cuda_restart();
  365. break;
  366. case SYS_CTRLER_PMU:
  367. pmu_restart();
  368. break;
  369. case SYS_CTRLER_SMU:
  370. smu_restart();
  371. break;
  372. default: ;
  373. }
  374. while (1) ;
  375. }
  376. static void __noreturn pmac_power_off(void)
  377. {
  378. switch (sys_ctrler) {
  379. case SYS_CTRLER_CUDA:
  380. cuda_shutdown();
  381. break;
  382. case SYS_CTRLER_PMU:
  383. pmu_shutdown();
  384. break;
  385. case SYS_CTRLER_SMU:
  386. smu_shutdown();
  387. break;
  388. default: ;
  389. }
  390. while (1) ;
  391. }
  392. static void __noreturn
  393. pmac_halt(void)
  394. {
  395. pmac_power_off();
  396. }
  397. /*
  398. * Early initialization.
  399. */
  400. static void __init pmac_init(void)
  401. {
  402. /* Enable early btext debug if requested */
  403. if (strstr(boot_command_line, "btextdbg")) {
  404. udbg_adb_init_early();
  405. register_early_udbg_console();
  406. }
  407. /* Probe motherboard chipset */
  408. pmac_feature_init();
  409. /* Initialize debug stuff */
  410. udbg_scc_init(!!strstr(boot_command_line, "sccdbg"));
  411. udbg_adb_init(!!strstr(boot_command_line, "btextdbg"));
  412. #ifdef CONFIG_PPC64
  413. iommu_init_early_dart(&pmac_pci_controller_ops);
  414. #endif
  415. /* SMP Init has to be done early as we need to patch up
  416. * cpu_possible_mask before interrupt stacks are allocated
  417. * or kaboom...
  418. */
  419. #ifdef CONFIG_SMP
  420. pmac_setup_smp();
  421. #endif
  422. }
  423. static int __init pmac_declare_of_platform_devices(void)
  424. {
  425. struct device_node *np;
  426. np = of_find_node_by_name(NULL, "valkyrie");
  427. if (np) {
  428. of_platform_device_create(np, "valkyrie", NULL);
  429. of_node_put(np);
  430. }
  431. np = of_find_node_by_name(NULL, "platinum");
  432. if (np) {
  433. of_platform_device_create(np, "platinum", NULL);
  434. of_node_put(np);
  435. }
  436. np = of_find_node_by_type(NULL, "smu");
  437. if (np) {
  438. of_platform_device_create(np, "smu", NULL);
  439. of_node_put(np);
  440. }
  441. np = of_find_node_by_type(NULL, "fcu");
  442. if (np == NULL) {
  443. /* Some machines have strangely broken device-tree */
  444. np = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/fan@15e");
  445. }
  446. if (np) {
  447. of_platform_device_create(np, "temperature", NULL);
  448. of_node_put(np);
  449. }
  450. return 0;
  451. }
  452. machine_device_initcall(powermac, pmac_declare_of_platform_devices);
  453. #ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
  454. /*
  455. * This is called very early, as part of console_init() (typically just after
  456. * time_init()). This function is respondible for trying to find a good
  457. * default console on serial ports. It tries to match the open firmware
  458. * default output with one of the available serial console drivers.
  459. */
  460. static int __init check_pmac_serial_console(void)
  461. {
  462. struct device_node *prom_stdout = NULL;
  463. int offset = 0;
  464. const char *name;
  465. #ifdef CONFIG_SERIAL_PMACZILOG_TTYS
  466. char *devname = "ttyS";
  467. #else
  468. char *devname = "ttyPZ";
  469. #endif
  470. pr_debug(" -> check_pmac_serial_console()\n");
  471. /* The user has requested a console so this is already set up. */
  472. if (strstr(boot_command_line, "console=")) {
  473. pr_debug(" console was specified !\n");
  474. return -EBUSY;
  475. }
  476. if (!of_chosen) {
  477. pr_debug(" of_chosen is NULL !\n");
  478. return -ENODEV;
  479. }
  480. /* We are getting a weird phandle from OF ... */
  481. /* ... So use the full path instead */
  482. name = of_get_property(of_chosen, "linux,stdout-path", NULL);
  483. if (name == NULL) {
  484. pr_debug(" no linux,stdout-path !\n");
  485. return -ENODEV;
  486. }
  487. prom_stdout = of_find_node_by_path(name);
  488. if (!prom_stdout) {
  489. pr_debug(" can't find stdout package %s !\n", name);
  490. return -ENODEV;
  491. }
  492. pr_debug("stdout is %s\n", prom_stdout->full_name);
  493. name = of_get_property(prom_stdout, "name", NULL);
  494. if (!name) {
  495. pr_debug(" stdout package has no name !\n");
  496. goto not_found;
  497. }
  498. if (strcmp(name, "ch-a") == 0)
  499. offset = 0;
  500. else if (strcmp(name, "ch-b") == 0)
  501. offset = 1;
  502. else
  503. goto not_found;
  504. of_node_put(prom_stdout);
  505. pr_debug("Found serial console at %s%d\n", devname, offset);
  506. return add_preferred_console(devname, offset, NULL);
  507. not_found:
  508. pr_debug("No preferred console found !\n");
  509. of_node_put(prom_stdout);
  510. return -ENODEV;
  511. }
  512. console_initcall(check_pmac_serial_console);
  513. #endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */
  514. /*
  515. * Called very early, MMU is off, device-tree isn't unflattened
  516. */
  517. static int __init pmac_probe(void)
  518. {
  519. if (!of_machine_is_compatible("Power Macintosh") &&
  520. !of_machine_is_compatible("MacRISC"))
  521. return 0;
  522. #ifdef CONFIG_PPC32
  523. /* isa_io_base gets set in pmac_pci_init */
  524. ISA_DMA_THRESHOLD = ~0L;
  525. DMA_MODE_READ = 1;
  526. DMA_MODE_WRITE = 2;
  527. #endif /* CONFIG_PPC32 */
  528. pm_power_off = pmac_power_off;
  529. pmac_init();
  530. return 1;
  531. }
  532. define_machine(powermac) {
  533. .name = "PowerMac",
  534. .probe = pmac_probe,
  535. .setup_arch = pmac_setup_arch,
  536. .show_cpuinfo = pmac_show_cpuinfo,
  537. .init_IRQ = pmac_pic_init,
  538. .get_irq = NULL, /* changed later */
  539. .pci_irq_fixup = pmac_pci_irq_fixup,
  540. .restart = pmac_restart,
  541. .halt = pmac_halt,
  542. .time_init = pmac_time_init,
  543. .get_boot_time = pmac_get_boot_time,
  544. .set_rtc_time = pmac_set_rtc_time,
  545. .get_rtc_time = pmac_get_rtc_time,
  546. .calibrate_decr = pmac_calibrate_decr,
  547. .feature_call = pmac_do_feature_call,
  548. .progress = udbg_progress,
  549. #ifdef CONFIG_PPC64
  550. .power_save = power4_idle,
  551. .enable_pmcs = power4_enable_pmcs,
  552. #endif /* CONFIG_PPC64 */
  553. #ifdef CONFIG_PPC32
  554. .pcibios_after_init = pmac_pcibios_after_init,
  555. .phys_mem_access_prot = pci_phys_mem_access_prot,
  556. #endif
  557. };