setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. /*
  2. * Common prep boot and setup code.
  3. */
  4. #include <linux/module.h>
  5. #include <linux/string.h>
  6. #include <linux/sched.h>
  7. #include <linux/init.h>
  8. #include <linux/kernel.h>
  9. #include <linux/reboot.h>
  10. #include <linux/delay.h>
  11. #include <linux/initrd.h>
  12. #include <linux/ide.h>
  13. #include <linux/screen_info.h>
  14. #include <linux/bootmem.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/root_dev.h>
  17. #include <linux/cpu.h>
  18. #include <linux/console.h>
  19. #include <asm/residual.h>
  20. #include <asm/io.h>
  21. #include <asm/prom.h>
  22. #include <asm/processor.h>
  23. #include <asm/pgtable.h>
  24. #include <asm/bootinfo.h>
  25. #include <asm/setup.h>
  26. #include <asm/smp.h>
  27. #include <asm/elf.h>
  28. #include <asm/cputable.h>
  29. #include <asm/bootx.h>
  30. #include <asm/btext.h>
  31. #include <asm/machdep.h>
  32. #include <asm/uaccess.h>
  33. #include <asm/system.h>
  34. #include <asm/sections.h>
  35. #include <asm/nvram.h>
  36. #include <asm/xmon.h>
  37. #include <asm/ocp.h>
  38. #define USES_PPC_SYS (defined(CONFIG_85xx) || defined(CONFIG_83xx) || \
  39. defined(CONFIG_MPC10X_BRIDGE) || defined(CONFIG_8260) || \
  40. defined(CONFIG_PPC_MPC52xx))
  41. #if USES_PPC_SYS
  42. #include <asm/ppc_sys.h>
  43. #endif
  44. #if defined CONFIG_KGDB
  45. #include <asm/kgdb.h>
  46. #endif
  47. extern void platform_init(unsigned long r3, unsigned long r4,
  48. unsigned long r5, unsigned long r6, unsigned long r7);
  49. extern void reloc_got2(unsigned long offset);
  50. extern void ppc6xx_idle(void);
  51. extern void power4_idle(void);
  52. extern boot_infos_t *boot_infos;
  53. struct ide_machdep_calls ppc_ide_md;
  54. /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
  55. size value reported by the boot loader. */
  56. unsigned long boot_mem_size;
  57. unsigned long ISA_DMA_THRESHOLD;
  58. unsigned int DMA_MODE_READ;
  59. unsigned int DMA_MODE_WRITE;
  60. #ifdef CONFIG_PPC_PREP
  61. extern void prep_init(unsigned long r3, unsigned long r4,
  62. unsigned long r5, unsigned long r6, unsigned long r7);
  63. dev_t boot_dev;
  64. #endif /* CONFIG_PPC_PREP */
  65. int have_of;
  66. EXPORT_SYMBOL(have_of);
  67. #ifdef __DO_IRQ_CANON
  68. int ppc_do_canonicalize_irqs;
  69. EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
  70. #endif
  71. #ifdef CONFIG_VGA_CONSOLE
  72. unsigned long vgacon_remap_base;
  73. #endif
  74. struct machdep_calls ppc_md;
  75. /*
  76. * These are used in binfmt_elf.c to put aux entries on the stack
  77. * for each elf executable being started.
  78. */
  79. int dcache_bsize;
  80. int icache_bsize;
  81. int ucache_bsize;
  82. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
  83. defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
  84. struct screen_info screen_info = {
  85. 0, 25, /* orig-x, orig-y */
  86. 0, /* unused */
  87. 0, /* orig-video-page */
  88. 0, /* orig-video-mode */
  89. 80, /* orig-video-cols */
  90. 0,0,0, /* ega_ax, ega_bx, ega_cx */
  91. 25, /* orig-video-lines */
  92. 1, /* orig-video-isVGA */
  93. 16 /* orig-video-points */
  94. };
  95. #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
  96. void machine_restart(char *cmd)
  97. {
  98. #ifdef CONFIG_NVRAM
  99. nvram_sync();
  100. #endif
  101. ppc_md.restart(cmd);
  102. }
  103. static void ppc_generic_power_off(void)
  104. {
  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) = ppc_generic_power_off;
  115. void machine_power_off(void)
  116. {
  117. #ifdef CONFIG_NVRAM
  118. nvram_sync();
  119. #endif
  120. if (pm_power_off)
  121. pm_power_off();
  122. ppc_generic_power_off();
  123. }
  124. #ifdef CONFIG_TAU
  125. extern u32 cpu_temp(unsigned long cpu);
  126. extern u32 cpu_temp_both(unsigned long cpu);
  127. #endif /* CONFIG_TAU */
  128. int show_cpuinfo(struct seq_file *m, void *v)
  129. {
  130. int i = (int) v - 1;
  131. int err = 0;
  132. unsigned int pvr;
  133. unsigned short maj, min;
  134. unsigned long lpj;
  135. if (i >= NR_CPUS) {
  136. /* Show summary information */
  137. #ifdef CONFIG_SMP
  138. unsigned long bogosum = 0;
  139. for_each_online_cpu(i)
  140. bogosum += cpu_data[i].loops_per_jiffy;
  141. seq_printf(m, "total bogomips\t: %lu.%02lu\n",
  142. bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
  143. #endif /* CONFIG_SMP */
  144. if (ppc_md.show_cpuinfo != NULL)
  145. err = ppc_md.show_cpuinfo(m);
  146. return err;
  147. }
  148. #ifdef CONFIG_SMP
  149. if (!cpu_online(i))
  150. return 0;
  151. pvr = cpu_data[i].pvr;
  152. lpj = cpu_data[i].loops_per_jiffy;
  153. #else
  154. pvr = mfspr(SPRN_PVR);
  155. lpj = loops_per_jiffy;
  156. #endif
  157. seq_printf(m, "processor\t: %d\n", i);
  158. seq_printf(m, "cpu\t\t: ");
  159. if (cur_cpu_spec->pvr_mask)
  160. seq_printf(m, "%s", cur_cpu_spec->cpu_name);
  161. else
  162. seq_printf(m, "unknown (%08x)", pvr);
  163. #ifdef CONFIG_ALTIVEC
  164. if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
  165. seq_printf(m, ", altivec supported");
  166. #endif
  167. seq_printf(m, "\n");
  168. #ifdef CONFIG_TAU
  169. if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
  170. #ifdef CONFIG_TAU_AVERAGE
  171. /* more straightforward, but potentially misleading */
  172. seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
  173. cpu_temp(i));
  174. #else
  175. /* show the actual temp sensor range */
  176. u32 temp;
  177. temp = cpu_temp_both(i);
  178. seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
  179. temp & 0xff, temp >> 16);
  180. #endif
  181. }
  182. #endif /* CONFIG_TAU */
  183. if (ppc_md.show_percpuinfo != NULL) {
  184. err = ppc_md.show_percpuinfo(m, i);
  185. if (err)
  186. return err;
  187. }
  188. /* If we are a Freescale core do a simple check so
  189. * we dont have to keep adding cases in the future */
  190. if ((PVR_VER(pvr) & 0x8000) == 0x8000) {
  191. maj = PVR_MAJ(pvr);
  192. min = PVR_MIN(pvr);
  193. } else {
  194. switch (PVR_VER(pvr)) {
  195. case 0x0020: /* 403 family */
  196. maj = PVR_MAJ(pvr) + 1;
  197. min = PVR_MIN(pvr);
  198. break;
  199. case 0x1008: /* 740P/750P ?? */
  200. maj = ((pvr >> 8) & 0xFF) - 1;
  201. min = pvr & 0xFF;
  202. break;
  203. default:
  204. maj = (pvr >> 8) & 0xFF;
  205. min = pvr & 0xFF;
  206. break;
  207. }
  208. }
  209. seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
  210. maj, min, PVR_VER(pvr), PVR_REV(pvr));
  211. seq_printf(m, "bogomips\t: %lu.%02lu\n",
  212. lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
  213. #if USES_PPC_SYS
  214. if (cur_ppc_sys_spec->ppc_sys_name)
  215. seq_printf(m, "chipset\t\t: %s\n",
  216. cur_ppc_sys_spec->ppc_sys_name);
  217. #endif
  218. #ifdef CONFIG_SMP
  219. seq_printf(m, "\n");
  220. #endif
  221. return 0;
  222. }
  223. static void *c_start(struct seq_file *m, loff_t *pos)
  224. {
  225. int i = *pos;
  226. return i <= NR_CPUS? (void *) (i + 1): NULL;
  227. }
  228. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  229. {
  230. ++*pos;
  231. return c_start(m, pos);
  232. }
  233. static void c_stop(struct seq_file *m, void *v)
  234. {
  235. }
  236. struct seq_operations cpuinfo_op = {
  237. .start =c_start,
  238. .next = c_next,
  239. .stop = c_stop,
  240. .show = show_cpuinfo,
  241. };
  242. /*
  243. * We're called here very early in the boot. We determine the machine
  244. * type and call the appropriate low-level setup functions.
  245. * -- Cort <cort@fsmlabs.com>
  246. *
  247. * Note that the kernel may be running at an address which is different
  248. * from the address that it was linked at, so we must use RELOC/PTRRELOC
  249. * to access static data (including strings). -- paulus
  250. */
  251. __init
  252. unsigned long
  253. early_init(int r3, int r4, int r5)
  254. {
  255. unsigned long phys;
  256. unsigned long offset = reloc_offset();
  257. struct cpu_spec *spec;
  258. /* Default */
  259. phys = offset + KERNELBASE;
  260. /* First zero the BSS -- use memset, some arches don't have
  261. * caches on yet */
  262. memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
  263. /*
  264. * Identify the CPU type and fix up code sections
  265. * that depend on which cpu we have.
  266. */
  267. #if defined(CONFIG_440EP) && defined(CONFIG_PPC_FPU)
  268. /* We pass the virtual PVR here for 440EP as 440EP and 440GR have
  269. * identical PVRs and there is no reliable way to check for the FPU
  270. */
  271. spec = identify_cpu(offset, (mfspr(SPRN_PVR) | 0x8));
  272. #else
  273. spec = identify_cpu(offset, mfspr(SPRN_PVR));
  274. #endif
  275. do_feature_fixups(spec->cpu_features,
  276. PTRRELOC(&__start___ftr_fixup),
  277. PTRRELOC(&__stop___ftr_fixup));
  278. return phys;
  279. }
  280. #ifdef CONFIG_PPC_PREP
  281. /*
  282. * The PPC_PREP version of platform_init...
  283. */
  284. void __init
  285. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  286. unsigned long r6, unsigned long r7)
  287. {
  288. #ifdef CONFIG_BOOTX_TEXT
  289. if (boot_text_mapped) {
  290. btext_clearscreen();
  291. btext_welcome();
  292. }
  293. #endif
  294. parse_bootinfo(find_bootinfo());
  295. prep_init(r3, r4, r5, r6, r7);
  296. }
  297. #endif /* CONFIG_PPC_PREP */
  298. struct bi_record *find_bootinfo(void)
  299. {
  300. struct bi_record *rec;
  301. rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
  302. if ( rec->tag != BI_FIRST ) {
  303. /*
  304. * This 0x10000 offset is a terrible hack but it will go away when
  305. * we have the bootloader handle all the relocation and
  306. * prom calls -- Cort
  307. */
  308. rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
  309. if ( rec->tag != BI_FIRST )
  310. return NULL;
  311. }
  312. return rec;
  313. }
  314. void parse_bootinfo(struct bi_record *rec)
  315. {
  316. if (rec == NULL || rec->tag != BI_FIRST)
  317. return;
  318. while (rec->tag != BI_LAST) {
  319. ulong *data = rec->data;
  320. switch (rec->tag) {
  321. case BI_CMD_LINE:
  322. strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
  323. break;
  324. #ifdef CONFIG_BLK_DEV_INITRD
  325. case BI_INITRD:
  326. initrd_start = data[0] + KERNELBASE;
  327. initrd_end = data[0] + data[1] + KERNELBASE;
  328. break;
  329. #endif /* CONFIG_BLK_DEV_INITRD */
  330. case BI_MEMSIZE:
  331. boot_mem_size = data[0];
  332. break;
  333. }
  334. rec = (struct bi_record *)((ulong)rec + rec->size);
  335. }
  336. }
  337. /*
  338. * Find out what kind of machine we're on and save any data we need
  339. * from the early boot process (devtree is copied on pmac by prom_init()).
  340. * This is called very early on the boot process, after a minimal
  341. * MMU environment has been set up but before MMU_init is called.
  342. */
  343. void __init
  344. machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
  345. unsigned long r6, unsigned long r7)
  346. {
  347. #ifdef CONFIG_CMDLINE
  348. strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
  349. #endif /* CONFIG_CMDLINE */
  350. #ifdef CONFIG_6xx
  351. ppc_md.power_save = ppc6xx_idle;
  352. #endif
  353. platform_init(r3, r4, r5, r6, r7);
  354. if (ppc_md.progress)
  355. ppc_md.progress("id mach(): done", 0x200);
  356. }
  357. #ifdef CONFIG_BOOKE_WDT
  358. /* Checks wdt=x and wdt_period=xx command-line option */
  359. int __init early_parse_wdt(char *p)
  360. {
  361. if (p && strncmp(p, "0", 1) != 0)
  362. booke_wdt_enabled = 1;
  363. return 0;
  364. }
  365. early_param("wdt", early_parse_wdt);
  366. int __init early_parse_wdt_period (char *p)
  367. {
  368. if (p)
  369. booke_wdt_period = simple_strtoul(p, NULL, 0);
  370. return 0;
  371. }
  372. early_param("wdt_period", early_parse_wdt_period);
  373. #endif /* CONFIG_BOOKE_WDT */
  374. /* Checks "l2cr=xxxx" command-line option */
  375. int __init ppc_setup_l2cr(char *str)
  376. {
  377. if (cpu_has_feature(CPU_FTR_L2CR)) {
  378. unsigned long val = simple_strtoul(str, NULL, 0);
  379. printk(KERN_INFO "l2cr set to %lx\n", val);
  380. _set_L2CR(0); /* force invalidate by disable cache */
  381. _set_L2CR(val); /* and enable it */
  382. }
  383. return 1;
  384. }
  385. __setup("l2cr=", ppc_setup_l2cr);
  386. #ifdef CONFIG_GENERIC_NVRAM
  387. /* Generic nvram hooks used by drivers/char/gen_nvram.c */
  388. unsigned char nvram_read_byte(int addr)
  389. {
  390. if (ppc_md.nvram_read_val)
  391. return ppc_md.nvram_read_val(addr);
  392. return 0xff;
  393. }
  394. EXPORT_SYMBOL(nvram_read_byte);
  395. void nvram_write_byte(unsigned char val, int addr)
  396. {
  397. if (ppc_md.nvram_write_val)
  398. ppc_md.nvram_write_val(addr, val);
  399. }
  400. EXPORT_SYMBOL(nvram_write_byte);
  401. void nvram_sync(void)
  402. {
  403. if (ppc_md.nvram_sync)
  404. ppc_md.nvram_sync();
  405. }
  406. EXPORT_SYMBOL(nvram_sync);
  407. #endif /* CONFIG_NVRAM */
  408. static struct cpu cpu_devices[NR_CPUS];
  409. int __init ppc_init(void)
  410. {
  411. int i;
  412. /* clear the progress line */
  413. if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
  414. /* register CPU devices */
  415. for_each_possible_cpu(i)
  416. register_cpu(&cpu_devices[i], i);
  417. /* call platform init */
  418. if (ppc_md.init != NULL) {
  419. ppc_md.init();
  420. }
  421. return 0;
  422. }
  423. arch_initcall(ppc_init);
  424. /* Warning, IO base is not yet inited */
  425. void __init setup_arch(char **cmdline_p)
  426. {
  427. extern char *klimit;
  428. extern void do_init_bootmem(void);
  429. /* so udelay does something sensible, assume <= 1000 bogomips */
  430. loops_per_jiffy = 500000000 / HZ;
  431. if (ppc_md.init_early)
  432. ppc_md.init_early();
  433. #ifdef CONFIG_XMON
  434. xmon_init(1);
  435. if (strstr(cmd_line, "xmon"))
  436. xmon(NULL);
  437. #endif /* CONFIG_XMON */
  438. if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
  439. #if defined(CONFIG_KGDB)
  440. if (ppc_md.kgdb_map_scc)
  441. ppc_md.kgdb_map_scc();
  442. set_debug_traps();
  443. if (strstr(cmd_line, "gdb")) {
  444. if (ppc_md.progress)
  445. ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
  446. printk("kgdb breakpoint activated\n");
  447. breakpoint();
  448. }
  449. #endif
  450. /*
  451. * Set cache line size based on type of cpu as a default.
  452. * Systems with OF can look in the properties on the cpu node(s)
  453. * for a possibly more accurate value.
  454. */
  455. if (! cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE)) {
  456. dcache_bsize = cur_cpu_spec->dcache_bsize;
  457. icache_bsize = cur_cpu_spec->icache_bsize;
  458. ucache_bsize = 0;
  459. } else
  460. ucache_bsize = dcache_bsize = icache_bsize
  461. = cur_cpu_spec->dcache_bsize;
  462. /* reboot on panic */
  463. panic_timeout = 180;
  464. init_mm.start_code = PAGE_OFFSET;
  465. init_mm.end_code = (unsigned long) _etext;
  466. init_mm.end_data = (unsigned long) _edata;
  467. init_mm.brk = (unsigned long) klimit;
  468. /* Save unparsed command line copy for /proc/cmdline */
  469. strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
  470. *cmdline_p = cmd_line;
  471. parse_early_param();
  472. /* set up the bootmem stuff with available memory */
  473. do_init_bootmem();
  474. if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
  475. #ifdef CONFIG_PPC_OCP
  476. /* Initialize OCP device list */
  477. ocp_early_init();
  478. if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
  479. #endif
  480. #ifdef CONFIG_DUMMY_CONSOLE
  481. conswitchp = &dummy_con;
  482. #endif
  483. ppc_md.setup_arch();
  484. if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
  485. paging_init();
  486. }