setup.c 13 KB

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