setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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/screen_info.h>
  13. #include <linux/bootmem.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/root_dev.h>
  16. #include <linux/cpu.h>
  17. #include <linux/console.h>
  18. #include <asm/residual.h>
  19. #include <asm/io.h>
  20. #include <asm/prom.h>
  21. #include <asm/processor.h>
  22. #include <asm/pgtable.h>
  23. #include <asm/bootinfo.h>
  24. #include <asm/setup.h>
  25. #include <asm/smp.h>
  26. #include <asm/elf.h>
  27. #include <asm/cputable.h>
  28. #include <asm/bootx.h>
  29. #include <asm/btext.h>
  30. #include <asm/machdep.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/system.h>
  33. #include <asm/sections.h>
  34. #include <asm/nvram.h>
  35. #include <asm/xmon.h>
  36. #include <asm/ocp.h>
  37. #include <asm/irq.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. /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
  53. size value reported by the boot loader. */
  54. unsigned long boot_mem_size;
  55. unsigned long ISA_DMA_THRESHOLD;
  56. unsigned int DMA_MODE_READ;
  57. unsigned int DMA_MODE_WRITE;
  58. #ifdef CONFIG_PPC_PREP
  59. extern void prep_init(unsigned long r3, unsigned long r4,
  60. unsigned long r5, unsigned long r6, unsigned long r7);
  61. dev_t boot_dev;
  62. #endif /* CONFIG_PPC_PREP */
  63. int have_of;
  64. EXPORT_SYMBOL(have_of);
  65. #ifdef __DO_IRQ_CANON
  66. int ppc_do_canonicalize_irqs;
  67. EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
  68. #endif
  69. #ifdef CONFIG_VGA_CONSOLE
  70. unsigned long vgacon_remap_base;
  71. #endif
  72. struct machdep_calls ppc_md;
  73. /*
  74. * These are used in binfmt_elf.c to put aux entries on the stack
  75. * for each elf executable being started.
  76. */
  77. int dcache_bsize;
  78. int icache_bsize;
  79. int ucache_bsize;
  80. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
  81. defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
  82. struct screen_info screen_info = {
  83. 0, 25, /* orig-x, orig-y */
  84. 0, /* unused */
  85. 0, /* orig-video-page */
  86. 0, /* orig-video-mode */
  87. 80, /* orig-video-cols */
  88. 0,0,0, /* ega_ax, ega_bx, ega_cx */
  89. 25, /* orig-video-lines */
  90. 1, /* orig-video-isVGA */
  91. 16 /* orig-video-points */
  92. };
  93. #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
  94. void machine_restart(char *cmd)
  95. {
  96. #ifdef CONFIG_NVRAM
  97. nvram_sync();
  98. #endif
  99. ppc_md.restart(cmd);
  100. }
  101. static void ppc_generic_power_off(void)
  102. {
  103. ppc_md.power_off();
  104. }
  105. void machine_halt(void)
  106. {
  107. #ifdef CONFIG_NVRAM
  108. nvram_sync();
  109. #endif
  110. ppc_md.halt();
  111. }
  112. void (*pm_power_off)(void) = ppc_generic_power_off;
  113. void machine_power_off(void)
  114. {
  115. #ifdef CONFIG_NVRAM
  116. nvram_sync();
  117. #endif
  118. if (pm_power_off)
  119. pm_power_off();
  120. ppc_generic_power_off();
  121. }
  122. #ifdef CONFIG_TAU
  123. extern u32 cpu_temp(unsigned long cpu);
  124. extern u32 cpu_temp_both(unsigned long cpu);
  125. #endif /* CONFIG_TAU */
  126. int show_cpuinfo(struct seq_file *m, void *v)
  127. {
  128. int i = (int) v - 1;
  129. int err = 0;
  130. unsigned int pvr;
  131. unsigned short maj, min;
  132. unsigned long lpj;
  133. if (i >= NR_CPUS) {
  134. /* Show summary information */
  135. #ifdef CONFIG_SMP
  136. unsigned long bogosum = 0;
  137. for_each_online_cpu(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. const 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. __init
  250. unsigned long
  251. early_init(int r3, int r4, int r5)
  252. {
  253. unsigned long phys;
  254. unsigned long offset = reloc_offset();
  255. struct cpu_spec *spec;
  256. /* Default */
  257. phys = offset + KERNELBASE;
  258. /* First zero the BSS -- use memset, some arches don't have
  259. * caches on yet */
  260. memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
  261. /*
  262. * Identify the CPU type and fix up code sections
  263. * that depend on which cpu we have.
  264. */
  265. #if defined(CONFIG_440EP) && defined(CONFIG_PPC_FPU)
  266. /* We pass the virtual PVR here for 440EP as 440EP and 440GR have
  267. * identical PVRs and there is no reliable way to check for the FPU
  268. */
  269. spec = identify_cpu(offset, (mfspr(SPRN_PVR) | 0x8));
  270. #else
  271. spec = identify_cpu(offset, mfspr(SPRN_PVR));
  272. #endif
  273. do_feature_fixups(spec->cpu_features,
  274. PTRRELOC(&__start___ftr_fixup),
  275. PTRRELOC(&__stop___ftr_fixup));
  276. return phys;
  277. }
  278. #ifdef CONFIG_PPC_PREP
  279. /*
  280. * The PPC_PREP version of platform_init...
  281. */
  282. void __init
  283. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  284. unsigned long r6, unsigned long r7)
  285. {
  286. #ifdef CONFIG_BOOTX_TEXT
  287. if (boot_text_mapped) {
  288. btext_clearscreen();
  289. btext_welcome();
  290. }
  291. #endif
  292. parse_bootinfo(find_bootinfo());
  293. prep_init(r3, r4, r5, r6, r7);
  294. }
  295. #endif /* CONFIG_PPC_PREP */
  296. struct bi_record *find_bootinfo(void)
  297. {
  298. struct bi_record *rec;
  299. rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
  300. if ( rec->tag != BI_FIRST ) {
  301. /*
  302. * This 0x10000 offset is a terrible hack but it will go away when
  303. * we have the bootloader handle all the relocation and
  304. * prom calls -- Cort
  305. */
  306. rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
  307. if ( rec->tag != BI_FIRST )
  308. return NULL;
  309. }
  310. return rec;
  311. }
  312. void parse_bootinfo(struct bi_record *rec)
  313. {
  314. if (rec == NULL || rec->tag != BI_FIRST)
  315. return;
  316. while (rec->tag != BI_LAST) {
  317. ulong *data = rec->data;
  318. switch (rec->tag) {
  319. case BI_CMD_LINE:
  320. strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
  321. break;
  322. #ifdef CONFIG_BLK_DEV_INITRD
  323. case BI_INITRD:
  324. initrd_start = data[0] + KERNELBASE;
  325. initrd_end = data[0] + data[1] + KERNELBASE;
  326. break;
  327. #endif /* CONFIG_BLK_DEV_INITRD */
  328. case BI_MEMSIZE:
  329. boot_mem_size = data[0];
  330. break;
  331. }
  332. rec = (struct bi_record *)((ulong)rec + rec->size);
  333. }
  334. }
  335. /*
  336. * Find out what kind of machine we're on and save any data we need
  337. * from the early boot process (devtree is copied on pmac by prom_init()).
  338. * This is called very early on the boot process, after a minimal
  339. * MMU environment has been set up but before MMU_init is called.
  340. */
  341. void __init
  342. machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
  343. unsigned long r6, unsigned long r7)
  344. {
  345. #ifdef CONFIG_CMDLINE
  346. strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
  347. #endif /* CONFIG_CMDLINE */
  348. #ifdef CONFIG_6xx
  349. ppc_md.power_save = ppc6xx_idle;
  350. #endif
  351. platform_init(r3, r4, r5, r6, r7);
  352. if (ppc_md.progress)
  353. ppc_md.progress("id mach(): done", 0x200);
  354. }
  355. #ifdef CONFIG_BOOKE_WDT
  356. /* Checks wdt=x and wdt_period=xx command-line option */
  357. int __init early_parse_wdt(char *p)
  358. {
  359. if (p && strncmp(p, "0", 1) != 0)
  360. booke_wdt_enabled = 1;
  361. return 0;
  362. }
  363. early_param("wdt", early_parse_wdt);
  364. int __init early_parse_wdt_period (char *p)
  365. {
  366. if (p)
  367. booke_wdt_period = simple_strtoul(p, NULL, 0);
  368. return 0;
  369. }
  370. early_param("wdt_period", early_parse_wdt_period);
  371. #endif /* CONFIG_BOOKE_WDT */
  372. /* Checks "l2cr=xxxx" command-line option */
  373. int __init ppc_setup_l2cr(char *str)
  374. {
  375. if (cpu_has_feature(CPU_FTR_L2CR)) {
  376. unsigned long val = simple_strtoul(str, NULL, 0);
  377. printk(KERN_INFO "l2cr set to %lx\n", val);
  378. _set_L2CR(0); /* force invalidate by disable cache */
  379. _set_L2CR(val); /* and enable it */
  380. }
  381. return 1;
  382. }
  383. __setup("l2cr=", ppc_setup_l2cr);
  384. #ifdef CONFIG_GENERIC_NVRAM
  385. /* Generic nvram hooks used by drivers/char/gen_nvram.c */
  386. unsigned char nvram_read_byte(int addr)
  387. {
  388. if (ppc_md.nvram_read_val)
  389. return ppc_md.nvram_read_val(addr);
  390. return 0xff;
  391. }
  392. EXPORT_SYMBOL(nvram_read_byte);
  393. void nvram_write_byte(unsigned char val, int addr)
  394. {
  395. if (ppc_md.nvram_write_val)
  396. ppc_md.nvram_write_val(addr, val);
  397. }
  398. EXPORT_SYMBOL(nvram_write_byte);
  399. void nvram_sync(void)
  400. {
  401. if (ppc_md.nvram_sync)
  402. ppc_md.nvram_sync();
  403. }
  404. EXPORT_SYMBOL(nvram_sync);
  405. #endif /* CONFIG_NVRAM */
  406. static struct cpu cpu_devices[NR_CPUS];
  407. int __init ppc_init(void)
  408. {
  409. int i;
  410. /* clear the progress line */
  411. if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
  412. /* register CPU devices */
  413. for_each_possible_cpu(i)
  414. register_cpu(&cpu_devices[i], i);
  415. /* call platform init */
  416. if (ppc_md.init != NULL) {
  417. ppc_md.init();
  418. }
  419. return 0;
  420. }
  421. arch_initcall(ppc_init);
  422. /* Warning, IO base is not yet inited */
  423. void __init setup_arch(char **cmdline_p)
  424. {
  425. extern char *klimit;
  426. extern void do_init_bootmem(void);
  427. /* so udelay does something sensible, assume <= 1000 bogomips */
  428. loops_per_jiffy = 500000000 / HZ;
  429. if (ppc_md.init_early)
  430. ppc_md.init_early();
  431. #ifdef CONFIG_XMON
  432. xmon_init(1);
  433. if (strstr(cmd_line, "xmon"))
  434. xmon(NULL);
  435. #endif /* CONFIG_XMON */
  436. if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
  437. #if defined(CONFIG_KGDB)
  438. if (ppc_md.kgdb_map_scc)
  439. ppc_md.kgdb_map_scc();
  440. set_debug_traps();
  441. if (strstr(cmd_line, "gdb")) {
  442. if (ppc_md.progress)
  443. ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
  444. printk("kgdb breakpoint activated\n");
  445. breakpoint();
  446. }
  447. #endif
  448. /*
  449. * Set cache line size based on type of cpu as a default.
  450. * Systems with OF can look in the properties on the cpu node(s)
  451. * for a possibly more accurate value.
  452. */
  453. if (! cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE)) {
  454. dcache_bsize = cur_cpu_spec->dcache_bsize;
  455. icache_bsize = cur_cpu_spec->icache_bsize;
  456. ucache_bsize = 0;
  457. } else
  458. ucache_bsize = dcache_bsize = icache_bsize
  459. = cur_cpu_spec->dcache_bsize;
  460. /* reboot on panic */
  461. panic_timeout = 180;
  462. init_mm.start_code = PAGE_OFFSET;
  463. init_mm.end_code = (unsigned long) _etext;
  464. init_mm.end_data = (unsigned long) _edata;
  465. init_mm.brk = (unsigned long) klimit;
  466. /* Save unparsed command line copy for /proc/cmdline */
  467. strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
  468. *cmdline_p = cmd_line;
  469. parse_early_param();
  470. /* set up the bootmem stuff with available memory */
  471. do_init_bootmem();
  472. if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
  473. #ifdef CONFIG_PPC_OCP
  474. /* Initialize OCP device list */
  475. ocp_early_init();
  476. if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
  477. #endif
  478. #ifdef CONFIG_DUMMY_CONSOLE
  479. conswitchp = &dummy_con;
  480. #endif
  481. ppc_md.setup_arch();
  482. if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
  483. paging_init();
  484. }