setup_32.c 14 KB

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