setup.c 13 KB

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