setup.c 14 KB

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