setup_32.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /*
  2. * Common prep/pmac/chrp boot and setup code.
  3. */
  4. #include <linux/config.h>
  5. #include <linux/module.h>
  6. #include <linux/string.h>
  7. #include <linux/sched.h>
  8. #include <linux/init.h>
  9. #include <linux/kernel.h>
  10. #include <linux/reboot.h>
  11. #include <linux/delay.h>
  12. #include <linux/initrd.h>
  13. #include <linux/ide.h>
  14. #include <linux/tty.h>
  15. #include <linux/bootmem.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/root_dev.h>
  18. #include <linux/cpu.h>
  19. #include <linux/console.h>
  20. #include <asm/residual.h>
  21. #include <asm/io.h>
  22. #include <asm/prom.h>
  23. #include <asm/processor.h>
  24. #include <asm/pgtable.h>
  25. #include <asm/bootinfo.h>
  26. #include <asm/setup.h>
  27. #include <asm/amigappc.h>
  28. #include <asm/smp.h>
  29. #include <asm/elf.h>
  30. #include <asm/cputable.h>
  31. #include <asm/bootx.h>
  32. #include <asm/btext.h>
  33. #include <asm/machdep.h>
  34. #include <asm/uaccess.h>
  35. #include <asm/system.h>
  36. #include <asm/pmac_feature.h>
  37. #include <asm/sections.h>
  38. #include <asm/nvram.h>
  39. #include <asm/xmon.h>
  40. #include <asm/ocp.h>
  41. #define USES_PPC_SYS (defined(CONFIG_85xx) || defined(CONFIG_83xx) || \
  42. defined(CONFIG_MPC10X_BRIDGE) || defined(CONFIG_8260) || \
  43. defined(CONFIG_PPC_MPC52xx))
  44. #if USES_PPC_SYS
  45. #include <asm/ppc_sys.h>
  46. #endif
  47. #if defined CONFIG_KGDB
  48. #include <asm/kgdb.h>
  49. #endif
  50. extern void platform_init(void);
  51. extern void bootx_init(unsigned long r4, unsigned long phys);
  52. extern void ppc6xx_idle(void);
  53. extern void power4_idle(void);
  54. boot_infos_t *boot_infos;
  55. struct ide_machdep_calls ppc_ide_md;
  56. /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
  57. size value reported by the boot loader. */
  58. unsigned long boot_mem_size;
  59. unsigned long ISA_DMA_THRESHOLD;
  60. unsigned int DMA_MODE_READ;
  61. unsigned int DMA_MODE_WRITE;
  62. int have_of = 1;
  63. #ifdef CONFIG_PPC_MULTIPLATFORM
  64. int _machine = 0;
  65. extern void prep_init(void);
  66. extern void pmac_init(void);
  67. extern void chrp_init(void);
  68. dev_t boot_dev;
  69. #endif /* CONFIG_PPC_MULTIPLATFORM */
  70. #ifdef CONFIG_MAGIC_SYSRQ
  71. unsigned long SYSRQ_KEY = 0x54;
  72. #endif /* CONFIG_MAGIC_SYSRQ */
  73. #ifdef CONFIG_VGA_CONSOLE
  74. unsigned long vgacon_remap_base;
  75. #endif
  76. struct machdep_calls ppc_md;
  77. EXPORT_SYMBOL(ppc_md);
  78. /*
  79. * These are used in binfmt_elf.c to put aux entries on the stack
  80. * for each elf executable being started.
  81. */
  82. int dcache_bsize;
  83. int icache_bsize;
  84. int ucache_bsize;
  85. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
  86. defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
  87. struct screen_info screen_info = {
  88. 0, 25, /* orig-x, orig-y */
  89. 0, /* unused */
  90. 0, /* orig-video-page */
  91. 0, /* orig-video-mode */
  92. 80, /* orig-video-cols */
  93. 0,0,0, /* ega_ax, ega_bx, ega_cx */
  94. 25, /* orig-video-lines */
  95. 1, /* orig-video-isVGA */
  96. 16 /* orig-video-points */
  97. };
  98. #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
  99. void machine_restart(char *cmd)
  100. {
  101. #ifdef CONFIG_NVRAM
  102. nvram_sync();
  103. #endif
  104. ppc_md.restart(cmd);
  105. }
  106. void machine_power_off(void)
  107. {
  108. #ifdef CONFIG_NVRAM
  109. nvram_sync();
  110. #endif
  111. ppc_md.power_off();
  112. }
  113. void machine_halt(void)
  114. {
  115. #ifdef CONFIG_NVRAM
  116. nvram_sync();
  117. #endif
  118. ppc_md.halt();
  119. }
  120. void (*pm_power_off)(void) = machine_power_off;
  121. #ifdef CONFIG_TAU
  122. extern u32 cpu_temp(unsigned long cpu);
  123. extern u32 cpu_temp_both(unsigned long cpu);
  124. #endif /* CONFIG_TAU */
  125. int show_cpuinfo(struct seq_file *m, void *v)
  126. {
  127. int i = (int) v - 1;
  128. int err = 0;
  129. unsigned int pvr;
  130. unsigned short maj, min;
  131. unsigned long lpj;
  132. if (i >= NR_CPUS) {
  133. /* Show summary information */
  134. #ifdef CONFIG_SMP
  135. unsigned long bogosum = 0;
  136. for (i = 0; i < NR_CPUS; ++i)
  137. if (cpu_online(i))
  138. bogosum += cpu_data[i].loops_per_jiffy;
  139. seq_printf(m, "total bogomips\t: %lu.%02lu\n",
  140. bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
  141. #endif /* CONFIG_SMP */
  142. if (ppc_md.show_cpuinfo != NULL)
  143. err = ppc_md.show_cpuinfo(m);
  144. return err;
  145. }
  146. #ifdef CONFIG_SMP
  147. if (!cpu_online(i))
  148. return 0;
  149. pvr = cpu_data[i].pvr;
  150. lpj = cpu_data[i].loops_per_jiffy;
  151. #else
  152. pvr = mfspr(SPRN_PVR);
  153. lpj = loops_per_jiffy;
  154. #endif
  155. seq_printf(m, "processor\t: %d\n", i);
  156. seq_printf(m, "cpu\t\t: ");
  157. if (cur_cpu_spec->pvr_mask)
  158. seq_printf(m, "%s", cur_cpu_spec->cpu_name);
  159. else
  160. seq_printf(m, "unknown (%08x)", pvr);
  161. #ifdef CONFIG_ALTIVEC
  162. if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
  163. seq_printf(m, ", altivec supported");
  164. #endif
  165. seq_printf(m, "\n");
  166. #ifdef CONFIG_TAU
  167. if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
  168. #ifdef CONFIG_TAU_AVERAGE
  169. /* more straightforward, but potentially misleading */
  170. seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
  171. cpu_temp(i));
  172. #else
  173. /* show the actual temp sensor range */
  174. u32 temp;
  175. temp = cpu_temp_both(i);
  176. seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
  177. temp & 0xff, temp >> 16);
  178. #endif
  179. }
  180. #endif /* CONFIG_TAU */
  181. if (ppc_md.show_percpuinfo != NULL) {
  182. err = ppc_md.show_percpuinfo(m, i);
  183. if (err)
  184. return err;
  185. }
  186. /* If we are a Freescale core do a simple check so
  187. * we dont have to keep adding cases in the future */
  188. if ((PVR_VER(pvr) & 0x8000) == 0x8000) {
  189. maj = PVR_MAJ(pvr);
  190. min = PVR_MIN(pvr);
  191. } else {
  192. switch (PVR_VER(pvr)) {
  193. case 0x0020: /* 403 family */
  194. maj = PVR_MAJ(pvr) + 1;
  195. min = PVR_MIN(pvr);
  196. break;
  197. case 0x1008: /* 740P/750P ?? */
  198. maj = ((pvr >> 8) & 0xFF) - 1;
  199. min = pvr & 0xFF;
  200. break;
  201. default:
  202. maj = (pvr >> 8) & 0xFF;
  203. min = pvr & 0xFF;
  204. break;
  205. }
  206. }
  207. seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
  208. maj, min, PVR_VER(pvr), PVR_REV(pvr));
  209. seq_printf(m, "bogomips\t: %lu.%02lu\n",
  210. lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
  211. #if USES_PPC_SYS
  212. if (cur_ppc_sys_spec->ppc_sys_name)
  213. seq_printf(m, "chipset\t\t: %s\n",
  214. cur_ppc_sys_spec->ppc_sys_name);
  215. #endif
  216. #ifdef CONFIG_SMP
  217. seq_printf(m, "\n");
  218. #endif
  219. return 0;
  220. }
  221. static void *c_start(struct seq_file *m, loff_t *pos)
  222. {
  223. int i = *pos;
  224. return i <= NR_CPUS? (void *) (i + 1): NULL;
  225. }
  226. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  227. {
  228. ++*pos;
  229. return c_start(m, pos);
  230. }
  231. static void c_stop(struct seq_file *m, void *v)
  232. {
  233. }
  234. struct seq_operations cpuinfo_op = {
  235. .start =c_start,
  236. .next = c_next,
  237. .stop = c_stop,
  238. .show = show_cpuinfo,
  239. };
  240. /*
  241. * We're called here very early in the boot. We determine the machine
  242. * type and call the appropriate low-level setup functions.
  243. * -- Cort <cort@fsmlabs.com>
  244. *
  245. * Note that the kernel may be running at an address which is different
  246. * from the address that it was linked at, so we must use RELOC/PTRRELOC
  247. * to access static data (including strings). -- paulus
  248. */
  249. unsigned long __init early_init(unsigned long dt_ptr)
  250. {
  251. unsigned long offset = reloc_offset();
  252. /* First zero the BSS -- use memset_io, some platforms don't have
  253. * caches on yet */
  254. memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
  255. /*
  256. * Identify the CPU type and fix up code sections
  257. * that depend on which cpu we have.
  258. */
  259. identify_cpu(offset, 0);
  260. do_cpu_ftr_fixups(offset);
  261. return KERNELBASE + offset;
  262. }
  263. #ifdef CONFIG_PPC_OF
  264. /*
  265. * Assume here that all clock rates are the same in a
  266. * smp system. -- Cort
  267. */
  268. int
  269. of_show_percpuinfo(struct seq_file *m, int i)
  270. {
  271. struct device_node *cpu_node;
  272. u32 *fp;
  273. int s;
  274. cpu_node = find_type_devices("cpu");
  275. if (!cpu_node)
  276. return 0;
  277. for (s = 0; s < i && cpu_node->next; s++)
  278. cpu_node = cpu_node->next;
  279. fp = (u32 *)get_property(cpu_node, "clock-frequency", NULL);
  280. if (fp)
  281. seq_printf(m, "clock\t\t: %dMHz\n", *fp / 1000000);
  282. return 0;
  283. }
  284. void __init
  285. intuit_machine_type(void)
  286. {
  287. char *model;
  288. struct device_node *root;
  289. /* ask the OF info if we're a chrp or pmac */
  290. root = find_path_device("/");
  291. if (root != 0) {
  292. /* assume pmac unless proven to be chrp -- Cort */
  293. _machine = _MACH_Pmac;
  294. model = get_property(root, "device_type", NULL);
  295. if (model && !strncmp("chrp", model, 4))
  296. _machine = _MACH_chrp;
  297. else {
  298. model = get_property(root, "model", NULL);
  299. if (model && !strncmp(model, "IBM", 3))
  300. _machine = _MACH_chrp;
  301. }
  302. }
  303. }
  304. #endif
  305. #ifdef CONFIG_PPC_MULTIPLATFORM
  306. /*
  307. * The PPC_MULTIPLATFORM version of platform_init...
  308. */
  309. void __init platform_init(void)
  310. {
  311. /* if we didn't get any bootinfo telling us what we are... */
  312. if (_machine == 0) {
  313. /* prep boot loader tells us if we're prep or not */
  314. if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
  315. _machine = _MACH_prep;
  316. }
  317. #ifdef CONFIG_PPC_PREP
  318. /* not much more to do here, if prep */
  319. if (_machine == _MACH_prep) {
  320. prep_init();
  321. return;
  322. }
  323. #endif
  324. #ifdef CONFIG_ADB
  325. if (strstr(cmd_line, "adb_sync")) {
  326. extern int __adb_probe_sync;
  327. __adb_probe_sync = 1;
  328. }
  329. #endif /* CONFIG_ADB */
  330. switch (_machine) {
  331. #ifdef CONFIG_PPC_PMAC
  332. case _MACH_Pmac:
  333. pmac_init();
  334. break;
  335. #endif
  336. #ifdef CONFIG_PPC_CHRP
  337. case _MACH_chrp:
  338. chrp_init();
  339. break;
  340. #endif
  341. }
  342. }
  343. #ifdef CONFIG_SERIAL_CORE_CONSOLE
  344. extern char *of_stdout_device;
  345. static int __init set_preferred_console(void)
  346. {
  347. struct device_node *prom_stdout;
  348. char *name;
  349. int offset = 0;
  350. if (of_stdout_device == NULL)
  351. return -ENODEV;
  352. /* The user has requested a console so this is already set up. */
  353. if (strstr(saved_command_line, "console="))
  354. return -EBUSY;
  355. prom_stdout = find_path_device(of_stdout_device);
  356. if (!prom_stdout)
  357. return -ENODEV;
  358. name = (char *)get_property(prom_stdout, "name", NULL);
  359. if (!name)
  360. return -ENODEV;
  361. if (strcmp(name, "serial") == 0) {
  362. int i;
  363. u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i);
  364. if (i > 8) {
  365. switch (reg[1]) {
  366. case 0x3f8:
  367. offset = 0;
  368. break;
  369. case 0x2f8:
  370. offset = 1;
  371. break;
  372. case 0x898:
  373. offset = 2;
  374. break;
  375. case 0x890:
  376. offset = 3;
  377. break;
  378. default:
  379. /* We dont recognise the serial port */
  380. return -ENODEV;
  381. }
  382. }
  383. } else if (strcmp(name, "ch-a") == 0)
  384. offset = 0;
  385. else if (strcmp(name, "ch-b") == 0)
  386. offset = 1;
  387. else
  388. return -ENODEV;
  389. return add_preferred_console("ttyS", offset, NULL);
  390. }
  391. console_initcall(set_preferred_console);
  392. #endif /* CONFIG_SERIAL_CORE_CONSOLE */
  393. #endif /* CONFIG_PPC_MULTIPLATFORM */
  394. /*
  395. * Find out what kind of machine we're on and save any data we need
  396. * from the early boot process (devtree is copied on pmac by prom_init()).
  397. * This is called very early on the boot process, after a minimal
  398. * MMU environment has been set up but before MMU_init is called.
  399. */
  400. void __init machine_init(unsigned long dt_ptr, unsigned long phys)
  401. {
  402. early_init_devtree(__va(dt_ptr));
  403. #ifdef CONFIG_CMDLINE
  404. strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
  405. #endif /* CONFIG_CMDLINE */
  406. #ifdef CONFIG_6xx
  407. ppc_md.power_save = ppc6xx_idle;
  408. #endif
  409. #ifdef CONFIG_POWER4
  410. ppc_md.power_save = power4_idle;
  411. #endif
  412. platform_init();
  413. if (ppc_md.progress)
  414. ppc_md.progress("id mach(): done", 0x200);
  415. }
  416. #ifdef CONFIG_BOOKE_WDT
  417. /* Checks wdt=x and wdt_period=xx command-line option */
  418. int __init early_parse_wdt(char *p)
  419. {
  420. if (p && strncmp(p, "0", 1) != 0)
  421. booke_wdt_enabled = 1;
  422. return 0;
  423. }
  424. early_param("wdt", early_parse_wdt);
  425. int __init early_parse_wdt_period (char *p)
  426. {
  427. if (p)
  428. booke_wdt_period = simple_strtoul(p, NULL, 0);
  429. return 0;
  430. }
  431. early_param("wdt_period", early_parse_wdt_period);
  432. #endif /* CONFIG_BOOKE_WDT */
  433. /* Checks "l2cr=xxxx" command-line option */
  434. int __init ppc_setup_l2cr(char *str)
  435. {
  436. if (cpu_has_feature(CPU_FTR_L2CR)) {
  437. unsigned long val = simple_strtoul(str, NULL, 0);
  438. printk(KERN_INFO "l2cr set to %lx\n", val);
  439. _set_L2CR(0); /* force invalidate by disable cache */
  440. _set_L2CR(val); /* and enable it */
  441. }
  442. return 1;
  443. }
  444. __setup("l2cr=", ppc_setup_l2cr);
  445. #ifdef CONFIG_GENERIC_NVRAM
  446. /* Generic nvram hooks used by drivers/char/gen_nvram.c */
  447. unsigned char nvram_read_byte(int addr)
  448. {
  449. if (ppc_md.nvram_read_val)
  450. return ppc_md.nvram_read_val(addr);
  451. return 0xff;
  452. }
  453. EXPORT_SYMBOL(nvram_read_byte);
  454. void nvram_write_byte(unsigned char val, int addr)
  455. {
  456. if (ppc_md.nvram_write_val)
  457. ppc_md.nvram_write_val(addr, val);
  458. }
  459. EXPORT_SYMBOL(nvram_write_byte);
  460. void nvram_sync(void)
  461. {
  462. if (ppc_md.nvram_sync)
  463. ppc_md.nvram_sync();
  464. }
  465. EXPORT_SYMBOL(nvram_sync);
  466. #endif /* CONFIG_NVRAM */
  467. static struct cpu cpu_devices[NR_CPUS];
  468. int __init ppc_init(void)
  469. {
  470. int i;
  471. /* clear the progress line */
  472. if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
  473. /* register CPU devices */
  474. for (i = 0; i < NR_CPUS; i++)
  475. if (cpu_possible(i))
  476. register_cpu(&cpu_devices[i], i, NULL);
  477. /* call platform init */
  478. if (ppc_md.init != NULL) {
  479. ppc_md.init();
  480. }
  481. return 0;
  482. }
  483. arch_initcall(ppc_init);
  484. /* Warning, IO base is not yet inited */
  485. void __init setup_arch(char **cmdline_p)
  486. {
  487. extern char *klimit;
  488. extern void do_init_bootmem(void);
  489. /* so udelay does something sensible, assume <= 1000 bogomips */
  490. loops_per_jiffy = 500000000 / HZ;
  491. unflatten_device_tree();
  492. finish_device_tree();
  493. #ifdef CONFIG_BOOTX_TEXT
  494. init_boot_display();
  495. #endif
  496. #ifdef CONFIG_PPC_MULTIPLATFORM
  497. /* This could be called "early setup arch", it must be done
  498. * now because xmon need it
  499. */
  500. if (_machine == _MACH_Pmac)
  501. pmac_feature_init(); /* New cool way */
  502. #endif
  503. #ifdef CONFIG_XMON
  504. xmon_map_scc();
  505. if (strstr(cmd_line, "xmon"))
  506. xmon(NULL);
  507. #endif /* CONFIG_XMON */
  508. if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
  509. #if defined(CONFIG_KGDB)
  510. if (ppc_md.kgdb_map_scc)
  511. ppc_md.kgdb_map_scc();
  512. set_debug_traps();
  513. if (strstr(cmd_line, "gdb")) {
  514. if (ppc_md.progress)
  515. ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
  516. printk("kgdb breakpoint activated\n");
  517. breakpoint();
  518. }
  519. #endif
  520. /*
  521. * Set cache line size based on type of cpu as a default.
  522. * Systems with OF can look in the properties on the cpu node(s)
  523. * for a possibly more accurate value.
  524. */
  525. if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
  526. dcache_bsize = cur_cpu_spec->dcache_bsize;
  527. icache_bsize = cur_cpu_spec->icache_bsize;
  528. ucache_bsize = 0;
  529. } else
  530. ucache_bsize = dcache_bsize = icache_bsize
  531. = cur_cpu_spec->dcache_bsize;
  532. /* reboot on panic */
  533. panic_timeout = 180;
  534. init_mm.start_code = PAGE_OFFSET;
  535. init_mm.end_code = (unsigned long) _etext;
  536. init_mm.end_data = (unsigned long) _edata;
  537. init_mm.brk = (unsigned long) klimit;
  538. /* Save unparsed command line copy for /proc/cmdline */
  539. strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
  540. *cmdline_p = cmd_line;
  541. parse_early_param();
  542. /* set up the bootmem stuff with available memory */
  543. do_init_bootmem();
  544. if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
  545. #ifdef CONFIG_PPC_OCP
  546. /* Initialize OCP device list */
  547. ocp_early_init();
  548. if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
  549. #endif
  550. #ifdef CONFIG_DUMMY_CONSOLE
  551. conswitchp = &dummy_con;
  552. #endif
  553. ppc_md.setup_arch();
  554. if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
  555. paging_init();
  556. /* this is for modules since _machine can be a define -- Cort */
  557. ppc_md.ppc_machine = _machine;
  558. }