PageRenderTime 26ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/powerpc/platforms/powermac/setup.c

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