setup.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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. #include <linux/config.h>
  25. #include <linux/init.h>
  26. #include <linux/errno.h>
  27. #include <linux/sched.h>
  28. #include <linux/kernel.h>
  29. #include <linux/mm.h>
  30. #include <linux/stddef.h>
  31. #include <linux/unistd.h>
  32. #include <linux/ptrace.h>
  33. #include <linux/slab.h>
  34. #include <linux/user.h>
  35. #include <linux/a.out.h>
  36. #include <linux/tty.h>
  37. #include <linux/string.h>
  38. #include <linux/delay.h>
  39. #include <linux/ioport.h>
  40. #include <linux/major.h>
  41. #include <linux/initrd.h>
  42. #include <linux/vt_kern.h>
  43. #include <linux/console.h>
  44. #include <linux/ide.h>
  45. #include <linux/pci.h>
  46. #include <linux/adb.h>
  47. #include <linux/cuda.h>
  48. #include <linux/pmu.h>
  49. #include <linux/irq.h>
  50. #include <linux/seq_file.h>
  51. #include <linux/root_dev.h>
  52. #include <linux/bitops.h>
  53. #include <linux/suspend.h>
  54. #include <asm/reg.h>
  55. #include <asm/sections.h>
  56. #include <asm/prom.h>
  57. #include <asm/system.h>
  58. #include <asm/pgtable.h>
  59. #include <asm/io.h>
  60. #include <asm/pci-bridge.h>
  61. #include <asm/ohare.h>
  62. #include <asm/mediabay.h>
  63. #include <asm/machdep.h>
  64. #include <asm/dma.h>
  65. #include <asm/bootx.h>
  66. #include <asm/cputable.h>
  67. #include <asm/btext.h>
  68. #include <asm/pmac_feature.h>
  69. #include <asm/time.h>
  70. #include <asm/of_device.h>
  71. #include <asm/mmu_context.h>
  72. #include "pmac.h"
  73. #undef SHOW_GATWICK_IRQS
  74. unsigned char drive_info;
  75. int ppc_override_l2cr = 0;
  76. int ppc_override_l2cr_value;
  77. int has_l2cache = 0;
  78. int pmac_newworld = 1;
  79. static int current_root_goodness = -1;
  80. extern int pmac_newworld;
  81. #define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */
  82. extern void zs_kgdb_hook(int tty_num);
  83. static void ohare_init(void);
  84. #ifdef CONFIG_BOOTX_TEXT
  85. static void pmac_progress(char *s, unsigned short hex);
  86. #endif
  87. sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN;
  88. #ifdef CONFIG_SMP
  89. extern struct smp_ops_t psurge_smp_ops;
  90. extern struct smp_ops_t core99_smp_ops;
  91. #endif /* CONFIG_SMP */
  92. static void pmac_show_cpuinfo(struct seq_file *m)
  93. {
  94. struct device_node *np;
  95. char *pp;
  96. int plen;
  97. int mbmodel;
  98. unsigned int mbflags;
  99. char* mbname;
  100. mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
  101. PMAC_MB_INFO_MODEL, 0);
  102. mbflags = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
  103. PMAC_MB_INFO_FLAGS, 0);
  104. if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME,
  105. (long) &mbname) != 0)
  106. mbname = "Unknown";
  107. /* find motherboard type */
  108. seq_printf(m, "machine\t\t: ");
  109. np = of_find_node_by_path("/");
  110. if (np != NULL) {
  111. pp = (char *) get_property(np, "model", NULL);
  112. if (pp != NULL)
  113. seq_printf(m, "%s\n", pp);
  114. else
  115. seq_printf(m, "PowerMac\n");
  116. pp = (char *) get_property(np, "compatible", &plen);
  117. if (pp != NULL) {
  118. seq_printf(m, "motherboard\t:");
  119. while (plen > 0) {
  120. int l = strlen(pp) + 1;
  121. seq_printf(m, " %s", pp);
  122. plen -= l;
  123. pp += l;
  124. }
  125. seq_printf(m, "\n");
  126. }
  127. of_node_put(np);
  128. } else
  129. seq_printf(m, "PowerMac\n");
  130. /* print parsed model */
  131. seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname);
  132. seq_printf(m, "pmac flags\t: %08x\n", mbflags);
  133. /* find l2 cache info */
  134. np = of_find_node_by_name(NULL, "l2-cache");
  135. if (np == NULL)
  136. np = of_find_node_by_type(NULL, "cache");
  137. if (np != NULL) {
  138. unsigned int *ic = (unsigned int *)
  139. get_property(np, "i-cache-size", NULL);
  140. unsigned int *dc = (unsigned int *)
  141. get_property(np, "d-cache-size", NULL);
  142. seq_printf(m, "L2 cache\t:");
  143. has_l2cache = 1;
  144. if (get_property(np, "cache-unified", NULL) != 0 && dc) {
  145. seq_printf(m, " %dK unified", *dc / 1024);
  146. } else {
  147. if (ic)
  148. seq_printf(m, " %dK instruction", *ic / 1024);
  149. if (dc)
  150. seq_printf(m, "%s %dK data",
  151. (ic? " +": ""), *dc / 1024);
  152. }
  153. pp = get_property(np, "ram-type", NULL);
  154. if (pp)
  155. seq_printf(m, " %s", pp);
  156. seq_printf(m, "\n");
  157. of_node_put(np);
  158. }
  159. /* Indicate newworld/oldworld */
  160. seq_printf(m, "pmac-generation\t: %s\n",
  161. pmac_newworld ? "NewWorld" : "OldWorld");
  162. }
  163. static void pmac_show_percpuinfo(struct seq_file *m, int i)
  164. {
  165. #ifdef CONFIG_CPU_FREQ_PMAC
  166. extern unsigned int pmac_get_one_cpufreq(int i);
  167. unsigned int freq = pmac_get_one_cpufreq(i);
  168. if (freq != 0) {
  169. seq_printf(m, "clock\t\t: %dMHz\n", freq/1000);
  170. return;
  171. }
  172. #endif /* CONFIG_CPU_FREQ_PMAC */
  173. of_show_percpuinfo(m, i);
  174. }
  175. static volatile u32 *sysctrl_regs;
  176. void __init
  177. pmac_setup_arch(void)
  178. {
  179. struct device_node *cpu;
  180. int *fp;
  181. unsigned long pvr;
  182. pvr = PVR_VER(mfspr(SPRN_PVR));
  183. /* Set loops_per_jiffy to a half-way reasonable value,
  184. for use until calibrate_delay gets called. */
  185. cpu = find_type_devices("cpu");
  186. if (cpu != 0) {
  187. fp = (int *) get_property(cpu, "clock-frequency", NULL);
  188. if (fp != 0) {
  189. if (pvr == 4 || pvr >= 8)
  190. /* 604, G3, G4 etc. */
  191. loops_per_jiffy = *fp / HZ;
  192. else
  193. /* 601, 603, etc. */
  194. loops_per_jiffy = *fp / (2*HZ);
  195. } else
  196. loops_per_jiffy = 50000000 / HZ;
  197. }
  198. /* this area has the CPU identification register
  199. and some registers used by smp boards */
  200. sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000);
  201. ohare_init();
  202. /* Lookup PCI hosts */
  203. pmac_find_bridges();
  204. /* Checks "l2cr-value" property in the registry */
  205. if (cpu_has_feature(CPU_FTR_L2CR)) {
  206. struct device_node *np = find_devices("cpus");
  207. if (np == 0)
  208. np = find_type_devices("cpu");
  209. if (np != 0) {
  210. unsigned int *l2cr = (unsigned int *)
  211. get_property(np, "l2cr-value", NULL);
  212. if (l2cr != 0) {
  213. ppc_override_l2cr = 1;
  214. ppc_override_l2cr_value = *l2cr;
  215. _set_L2CR(0);
  216. _set_L2CR(ppc_override_l2cr_value);
  217. }
  218. }
  219. }
  220. if (ppc_override_l2cr)
  221. printk(KERN_INFO "L2CR overriden (0x%x), backside cache is %s\n",
  222. ppc_override_l2cr_value, (ppc_override_l2cr_value & 0x80000000)
  223. ? "enabled" : "disabled");
  224. #ifdef CONFIG_KGDB
  225. zs_kgdb_hook(0);
  226. #endif
  227. #ifdef CONFIG_ADB_CUDA
  228. find_via_cuda();
  229. #else
  230. if (find_devices("via-cuda")) {
  231. printk("WARNING ! Your machine is Cuda based but your kernel\n");
  232. printk(" wasn't compiled with CONFIG_ADB_CUDA option !\n");
  233. }
  234. #endif
  235. #ifdef CONFIG_ADB_PMU
  236. find_via_pmu();
  237. #else
  238. if (find_devices("via-pmu")) {
  239. printk("WARNING ! Your machine is PMU based but your kernel\n");
  240. printk(" wasn't compiled with CONFIG_ADB_PMU option !\n");
  241. }
  242. #endif
  243. #ifdef CONFIG_NVRAM
  244. pmac_nvram_init();
  245. #endif
  246. #ifdef CONFIG_BLK_DEV_INITRD
  247. if (initrd_start)
  248. ROOT_DEV = Root_RAM0;
  249. else
  250. #endif
  251. ROOT_DEV = DEFAULT_ROOT_DEVICE;
  252. #ifdef CONFIG_SMP
  253. /* Check for Core99 */
  254. if (find_devices("uni-n") || find_devices("u3"))
  255. smp_ops = &core99_smp_ops;
  256. else
  257. smp_ops = &psurge_smp_ops;
  258. #endif /* CONFIG_SMP */
  259. pci_create_OF_bus_map();
  260. }
  261. static void __init ohare_init(void)
  262. {
  263. /*
  264. * Turn on the L2 cache.
  265. * We assume that we have a PSX memory controller iff
  266. * we have an ohare I/O controller.
  267. */
  268. if (find_devices("ohare") != NULL) {
  269. if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) {
  270. if (sysctrl_regs[4] & 0x10)
  271. sysctrl_regs[4] |= 0x04000020;
  272. else
  273. sysctrl_regs[4] |= 0x04000000;
  274. if(has_l2cache)
  275. printk(KERN_INFO "Level 2 cache enabled\n");
  276. }
  277. }
  278. }
  279. char *bootpath;
  280. char *bootdevice;
  281. void *boot_host;
  282. int boot_target;
  283. int boot_part;
  284. extern dev_t boot_dev;
  285. #ifdef CONFIG_SCSI
  286. void __init
  287. note_scsi_host(struct device_node *node, void *host)
  288. {
  289. int l;
  290. char *p;
  291. l = strlen(node->full_name);
  292. if (bootpath != NULL && bootdevice != NULL
  293. && strncmp(node->full_name, bootdevice, l) == 0
  294. && (bootdevice[l] == '/' || bootdevice[l] == 0)) {
  295. boot_host = host;
  296. /*
  297. * There's a bug in OF 1.0.5. (Why am I not surprised.)
  298. * If you pass a path like scsi/sd@1:0 to canon, it returns
  299. * something like /bandit@F2000000/gc@10/53c94@10000/sd@0,0
  300. * That is, the scsi target number doesn't get preserved.
  301. * So we pick the target number out of bootpath and use that.
  302. */
  303. p = strstr(bootpath, "/sd@");
  304. if (p != NULL) {
  305. p += 4;
  306. boot_target = simple_strtoul(p, NULL, 10);
  307. p = strchr(p, ':');
  308. if (p != NULL)
  309. boot_part = simple_strtoul(p + 1, NULL, 10);
  310. }
  311. }
  312. }
  313. EXPORT_SYMBOL(note_scsi_host);
  314. #endif
  315. #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
  316. static dev_t __init
  317. find_ide_boot(void)
  318. {
  319. char *p;
  320. int n;
  321. dev_t __init pmac_find_ide_boot(char *bootdevice, int n);
  322. if (bootdevice == NULL)
  323. return 0;
  324. p = strrchr(bootdevice, '/');
  325. if (p == NULL)
  326. return 0;
  327. n = p - bootdevice;
  328. return pmac_find_ide_boot(bootdevice, n);
  329. }
  330. #endif /* CONFIG_BLK_DEV_IDE && CONFIG_BLK_DEV_IDE_PMAC */
  331. static void __init
  332. find_boot_device(void)
  333. {
  334. #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
  335. boot_dev = find_ide_boot();
  336. #endif
  337. }
  338. static int initializing = 1;
  339. /* TODO: Merge the suspend-to-ram with the common code !!!
  340. * currently, this is a stub implementation for suspend-to-disk
  341. * only
  342. */
  343. #ifdef CONFIG_SOFTWARE_SUSPEND
  344. static int pmac_pm_prepare(suspend_state_t state)
  345. {
  346. printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
  347. return 0;
  348. }
  349. static int pmac_pm_enter(suspend_state_t state)
  350. {
  351. printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
  352. /* Giveup the lazy FPU & vec so we don't have to back them
  353. * up from the low level code
  354. */
  355. enable_kernel_fp();
  356. #ifdef CONFIG_ALTIVEC
  357. if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
  358. enable_kernel_altivec();
  359. #endif /* CONFIG_ALTIVEC */
  360. return 0;
  361. }
  362. static int pmac_pm_finish(suspend_state_t state)
  363. {
  364. printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
  365. /* Restore userland MMU context */
  366. set_context(current->active_mm->context, current->active_mm->pgd);
  367. return 0;
  368. }
  369. static struct pm_ops pmac_pm_ops = {
  370. .pm_disk_mode = PM_DISK_SHUTDOWN,
  371. .prepare = pmac_pm_prepare,
  372. .enter = pmac_pm_enter,
  373. .finish = pmac_pm_finish,
  374. };
  375. #endif /* CONFIG_SOFTWARE_SUSPEND */
  376. static int pmac_late_init(void)
  377. {
  378. initializing = 0;
  379. #ifdef CONFIG_SOFTWARE_SUSPEND
  380. pm_set_ops(&pmac_pm_ops);
  381. #endif /* CONFIG_SOFTWARE_SUSPEND */
  382. return 0;
  383. }
  384. late_initcall(pmac_late_init);
  385. /* can't be __init - can be called whenever a disk is first accessed */
  386. void
  387. note_bootable_part(dev_t dev, int part, int goodness)
  388. {
  389. static int found_boot = 0;
  390. char *p;
  391. if (!initializing)
  392. return;
  393. if ((goodness <= current_root_goodness) &&
  394. ROOT_DEV != DEFAULT_ROOT_DEVICE)
  395. return;
  396. p = strstr(saved_command_line, "root=");
  397. if (p != NULL && (p == saved_command_line || p[-1] == ' '))
  398. return;
  399. if (!found_boot) {
  400. find_boot_device();
  401. found_boot = 1;
  402. }
  403. if (!boot_dev || dev == boot_dev) {
  404. ROOT_DEV = dev + part;
  405. boot_dev = 0;
  406. current_root_goodness = goodness;
  407. }
  408. }
  409. static void
  410. pmac_restart(char *cmd)
  411. {
  412. #ifdef CONFIG_ADB_CUDA
  413. struct adb_request req;
  414. #endif /* CONFIG_ADB_CUDA */
  415. switch (sys_ctrler) {
  416. #ifdef CONFIG_ADB_CUDA
  417. case SYS_CTRLER_CUDA:
  418. cuda_request(&req, NULL, 2, CUDA_PACKET,
  419. CUDA_RESET_SYSTEM);
  420. for (;;)
  421. cuda_poll();
  422. break;
  423. #endif /* CONFIG_ADB_CUDA */
  424. #ifdef CONFIG_ADB_PMU
  425. case SYS_CTRLER_PMU:
  426. pmu_restart();
  427. break;
  428. #endif /* CONFIG_ADB_PMU */
  429. default: ;
  430. }
  431. }
  432. static void
  433. pmac_power_off(void)
  434. {
  435. #ifdef CONFIG_ADB_CUDA
  436. struct adb_request req;
  437. #endif /* CONFIG_ADB_CUDA */
  438. switch (sys_ctrler) {
  439. #ifdef CONFIG_ADB_CUDA
  440. case SYS_CTRLER_CUDA:
  441. cuda_request(&req, NULL, 2, CUDA_PACKET,
  442. CUDA_POWERDOWN);
  443. for (;;)
  444. cuda_poll();
  445. break;
  446. #endif /* CONFIG_ADB_CUDA */
  447. #ifdef CONFIG_ADB_PMU
  448. case SYS_CTRLER_PMU:
  449. pmu_shutdown();
  450. break;
  451. #endif /* CONFIG_ADB_PMU */
  452. default: ;
  453. }
  454. }
  455. static void
  456. pmac_halt(void)
  457. {
  458. pmac_power_off();
  459. }
  460. void __init pmac_init(void)
  461. {
  462. /* isa_io_base gets set in pmac_find_bridges */
  463. isa_mem_base = PMAC_ISA_MEM_BASE;
  464. pci_dram_offset = PMAC_PCI_DRAM_OFFSET;
  465. ISA_DMA_THRESHOLD = ~0L;
  466. DMA_MODE_READ = 1;
  467. DMA_MODE_WRITE = 2;
  468. ppc_md.setup_arch = pmac_setup_arch;
  469. ppc_md.show_cpuinfo = pmac_show_cpuinfo;
  470. ppc_md.show_percpuinfo = pmac_show_percpuinfo;
  471. ppc_md.init_IRQ = pmac_pic_init;
  472. ppc_md.get_irq = pmac_get_irq; /* Changed later on ... */
  473. ppc_md.pcibios_fixup = pmac_pcibios_fixup;
  474. ppc_md.pcibios_enable_device_hook = pmac_pci_enable_device_hook;
  475. ppc_md.pcibios_after_init = pmac_pcibios_after_init;
  476. ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
  477. ppc_md.restart = pmac_restart;
  478. ppc_md.power_off = pmac_power_off;
  479. ppc_md.halt = pmac_halt;
  480. ppc_md.time_init = pmac_time_init;
  481. ppc_md.set_rtc_time = pmac_set_rtc_time;
  482. ppc_md.get_rtc_time = pmac_get_rtc_time;
  483. ppc_md.get_boot_time = pmac_get_boot_time;
  484. ppc_md.calibrate_decr = pmac_calibrate_decr;
  485. ppc_md.feature_call = pmac_do_feature_call;
  486. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
  487. #ifdef CONFIG_BLK_DEV_IDE_PMAC
  488. ppc_ide_md.ide_init_hwif = pmac_ide_init_hwif_ports;
  489. ppc_ide_md.default_io_base = pmac_ide_get_base;
  490. #endif /* CONFIG_BLK_DEV_IDE_PMAC */
  491. #endif /* defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE) */
  492. #ifdef CONFIG_BOOTX_TEXT
  493. ppc_md.progress = pmac_progress;
  494. #endif /* CONFIG_BOOTX_TEXT */
  495. if (ppc_md.progress) ppc_md.progress("pmac_init(): exit", 0);
  496. }
  497. #ifdef CONFIG_BOOTX_TEXT
  498. static void __init
  499. pmac_progress(char *s, unsigned short hex)
  500. {
  501. if (boot_text_mapped) {
  502. btext_drawstring(s);
  503. btext_drawchar('\n');
  504. }
  505. }
  506. #endif /* CONFIG_BOOTX_TEXT */
  507. static int __init
  508. pmac_declare_of_platform_devices(void)
  509. {
  510. struct device_node *np;
  511. np = find_devices("uni-n");
  512. if (np) {
  513. for (np = np->child; np != NULL; np = np->sibling)
  514. if (strncmp(np->name, "i2c", 3) == 0) {
  515. of_platform_device_create(np, "uni-n-i2c",
  516. NULL);
  517. break;
  518. }
  519. }
  520. np = find_devices("u3");
  521. if (np) {
  522. for (np = np->child; np != NULL; np = np->sibling)
  523. if (strncmp(np->name, "i2c", 3) == 0) {
  524. of_platform_device_create(np, "u3-i2c",
  525. NULL);
  526. break;
  527. }
  528. }
  529. np = find_devices("valkyrie");
  530. if (np)
  531. of_platform_device_create(np, "valkyrie", NULL);
  532. np = find_devices("platinum");
  533. if (np)
  534. of_platform_device_create(np, "platinum", NULL);
  535. return 0;
  536. }
  537. device_initcall(pmac_declare_of_platform_devices);