setup.c 13 KB

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