setup.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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. void note_bootable_part(dev_t dev, int part, int goodness);
  314. /*
  315. * This is __ref because we check for "initializing" before
  316. * touching any of the __init sensitive things and "initializing"
  317. * will be false after __init time. This can't be __init because it
  318. * can be called whenever a disk is first accessed.
  319. */
  320. void __ref note_bootable_part(dev_t dev, int part, int goodness)
  321. {
  322. char *p;
  323. if (!initializing)
  324. return;
  325. if ((goodness <= current_root_goodness) &&
  326. ROOT_DEV != DEFAULT_ROOT_DEVICE)
  327. return;
  328. p = strstr(boot_command_line, "root=");
  329. if (p != NULL && (p == boot_command_line || p[-1] == ' '))
  330. return;
  331. ROOT_DEV = dev + part;
  332. current_root_goodness = goodness;
  333. }
  334. #ifdef CONFIG_ADB_CUDA
  335. static void __noreturn cuda_restart(void)
  336. {
  337. struct adb_request req;
  338. cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM);
  339. for (;;)
  340. cuda_poll();
  341. }
  342. static void __noreturn cuda_shutdown(void)
  343. {
  344. struct adb_request req;
  345. cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN);
  346. for (;;)
  347. cuda_poll();
  348. }
  349. #else
  350. #define cuda_restart()
  351. #define cuda_shutdown()
  352. #endif
  353. #ifndef CONFIG_ADB_PMU
  354. #define pmu_restart()
  355. #define pmu_shutdown()
  356. #endif
  357. #ifndef CONFIG_PMAC_SMU
  358. #define smu_restart()
  359. #define smu_shutdown()
  360. #endif
  361. static void __noreturn pmac_restart(char *cmd)
  362. {
  363. switch (sys_ctrler) {
  364. case SYS_CTRLER_CUDA:
  365. cuda_restart();
  366. break;
  367. case SYS_CTRLER_PMU:
  368. pmu_restart();
  369. break;
  370. case SYS_CTRLER_SMU:
  371. smu_restart();
  372. break;
  373. default: ;
  374. }
  375. while (1) ;
  376. }
  377. static void __noreturn pmac_power_off(void)
  378. {
  379. switch (sys_ctrler) {
  380. case SYS_CTRLER_CUDA:
  381. cuda_shutdown();
  382. break;
  383. case SYS_CTRLER_PMU:
  384. pmu_shutdown();
  385. break;
  386. case SYS_CTRLER_SMU:
  387. smu_shutdown();
  388. break;
  389. default: ;
  390. }
  391. while (1) ;
  392. }
  393. static void __noreturn
  394. pmac_halt(void)
  395. {
  396. pmac_power_off();
  397. }
  398. /*
  399. * Early initialization.
  400. */
  401. static void __init pmac_init(void)
  402. {
  403. /* Enable early btext debug if requested */
  404. if (strstr(boot_command_line, "btextdbg")) {
  405. udbg_adb_init_early();
  406. register_early_udbg_console();
  407. }
  408. /* Probe motherboard chipset */
  409. pmac_feature_init();
  410. /* Initialize debug stuff */
  411. udbg_scc_init(!!strstr(boot_command_line, "sccdbg"));
  412. udbg_adb_init(!!strstr(boot_command_line, "btextdbg"));
  413. #ifdef CONFIG_PPC64
  414. iommu_init_early_dart(&pmac_pci_controller_ops);
  415. #endif
  416. /* SMP Init has to be done early as we need to patch up
  417. * cpu_possible_mask before interrupt stacks are allocated
  418. * or kaboom...
  419. */
  420. #ifdef CONFIG_SMP
  421. pmac_setup_smp();
  422. #endif
  423. }
  424. static int __init pmac_declare_of_platform_devices(void)
  425. {
  426. struct device_node *np;
  427. np = of_find_node_by_name(NULL, "valkyrie");
  428. if (np) {
  429. of_platform_device_create(np, "valkyrie", NULL);
  430. of_node_put(np);
  431. }
  432. np = of_find_node_by_name(NULL, "platinum");
  433. if (np) {
  434. of_platform_device_create(np, "platinum", NULL);
  435. of_node_put(np);
  436. }
  437. np = of_find_node_by_type(NULL, "smu");
  438. if (np) {
  439. of_platform_device_create(np, "smu", NULL);
  440. of_node_put(np);
  441. }
  442. np = of_find_node_by_type(NULL, "fcu");
  443. if (np == NULL) {
  444. /* Some machines have strangely broken device-tree */
  445. np = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/fan@15e");
  446. }
  447. if (np) {
  448. of_platform_device_create(np, "temperature", NULL);
  449. of_node_put(np);
  450. }
  451. return 0;
  452. }
  453. machine_device_initcall(powermac, pmac_declare_of_platform_devices);
  454. #ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
  455. /*
  456. * This is called very early, as part of console_init() (typically just after
  457. * time_init()). This function is respondible for trying to find a good
  458. * default console on serial ports. It tries to match the open firmware
  459. * default output with one of the available serial console drivers.
  460. */
  461. static int __init check_pmac_serial_console(void)
  462. {
  463. struct device_node *prom_stdout = NULL;
  464. int offset = 0;
  465. const char *name;
  466. #ifdef CONFIG_SERIAL_PMACZILOG_TTYS
  467. char *devname = "ttyS";
  468. #else
  469. char *devname = "ttyPZ";
  470. #endif
  471. pr_debug(" -> check_pmac_serial_console()\n");
  472. /* The user has requested a console so this is already set up. */
  473. if (strstr(boot_command_line, "console=")) {
  474. pr_debug(" console was specified !\n");
  475. return -EBUSY;
  476. }
  477. if (!of_chosen) {
  478. pr_debug(" of_chosen is NULL !\n");
  479. return -ENODEV;
  480. }
  481. /* We are getting a weird phandle from OF ... */
  482. /* ... So use the full path instead */
  483. name = of_get_property(of_chosen, "linux,stdout-path", NULL);
  484. if (name == NULL) {
  485. pr_debug(" no linux,stdout-path !\n");
  486. return -ENODEV;
  487. }
  488. prom_stdout = of_find_node_by_path(name);
  489. if (!prom_stdout) {
  490. pr_debug(" can't find stdout package %s !\n", name);
  491. return -ENODEV;
  492. }
  493. pr_debug("stdout is %s\n", prom_stdout->full_name);
  494. name = of_get_property(prom_stdout, "name", NULL);
  495. if (!name) {
  496. pr_debug(" stdout package has no name !\n");
  497. goto not_found;
  498. }
  499. if (strcmp(name, "ch-a") == 0)
  500. offset = 0;
  501. else if (strcmp(name, "ch-b") == 0)
  502. offset = 1;
  503. else
  504. goto not_found;
  505. of_node_put(prom_stdout);
  506. pr_debug("Found serial console at %s%d\n", devname, offset);
  507. return add_preferred_console(devname, offset, NULL);
  508. not_found:
  509. pr_debug("No preferred console found !\n");
  510. of_node_put(prom_stdout);
  511. return -ENODEV;
  512. }
  513. console_initcall(check_pmac_serial_console);
  514. #endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */
  515. /*
  516. * Called very early, MMU is off, device-tree isn't unflattened
  517. */
  518. static int __init pmac_probe(void)
  519. {
  520. if (!of_machine_is_compatible("Power Macintosh") &&
  521. !of_machine_is_compatible("MacRISC"))
  522. return 0;
  523. #ifdef CONFIG_PPC32
  524. /* isa_io_base gets set in pmac_pci_init */
  525. ISA_DMA_THRESHOLD = ~0L;
  526. DMA_MODE_READ = 1;
  527. DMA_MODE_WRITE = 2;
  528. #endif /* CONFIG_PPC32 */
  529. pm_power_off = pmac_power_off;
  530. pmac_init();
  531. return 1;
  532. }
  533. define_machine(powermac) {
  534. .name = "PowerMac",
  535. .probe = pmac_probe,
  536. .setup_arch = pmac_setup_arch,
  537. .show_cpuinfo = pmac_show_cpuinfo,
  538. .init_IRQ = pmac_pic_init,
  539. .get_irq = NULL, /* changed later */
  540. .pci_irq_fixup = pmac_pci_irq_fixup,
  541. .restart = pmac_restart,
  542. .halt = pmac_halt,
  543. .time_init = pmac_time_init,
  544. .get_boot_time = pmac_get_boot_time,
  545. .set_rtc_time = pmac_set_rtc_time,
  546. .get_rtc_time = pmac_get_rtc_time,
  547. .calibrate_decr = pmac_calibrate_decr,
  548. .feature_call = pmac_do_feature_call,
  549. .progress = udbg_progress,
  550. #ifdef CONFIG_PPC64
  551. .power_save = power4_idle,
  552. .enable_pmcs = power4_enable_pmcs,
  553. #endif /* CONFIG_PPC64 */
  554. #ifdef CONFIG_PPC32
  555. .pcibios_after_init = pmac_pcibios_after_init,
  556. .phys_mem_access_prot = pci_phys_mem_access_prot,
  557. #endif
  558. };