setup.c 13 KB

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