setup.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /*
  2. * Common prep/pmac/chrp boot and setup code.
  3. */
  4. #include <linux/config.h>
  5. #include <linux/module.h>
  6. #include <linux/string.h>
  7. #include <linux/sched.h>
  8. #include <linux/init.h>
  9. #include <linux/kernel.h>
  10. #include <linux/reboot.h>
  11. #include <linux/delay.h>
  12. #include <linux/initrd.h>
  13. #include <linux/ide.h>
  14. #include <linux/tty.h>
  15. #include <linux/bootmem.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/root_dev.h>
  18. #include <linux/cpu.h>
  19. #include <linux/console.h>
  20. #include <asm/residual.h>
  21. #include <asm/io.h>
  22. #include <asm/prom.h>
  23. #include <asm/processor.h>
  24. #include <asm/pgtable.h>
  25. #include <asm/bootinfo.h>
  26. #include <asm/setup.h>
  27. #include <asm/amigappc.h>
  28. #include <asm/smp.h>
  29. #include <asm/elf.h>
  30. #include <asm/cputable.h>
  31. #include <asm/bootx.h>
  32. #include <asm/btext.h>
  33. #include <asm/machdep.h>
  34. #include <asm/uaccess.h>
  35. #include <asm/system.h>
  36. #include <asm/pmac_feature.h>
  37. #include <asm/sections.h>
  38. #include <asm/nvram.h>
  39. #include <asm/xmon.h>
  40. #include <asm/ocp.h>
  41. #if defined(CONFIG_85xx) || defined(CONFIG_83xx)
  42. #include <asm/ppc_sys.h>
  43. #endif
  44. #if defined CONFIG_KGDB
  45. #include <asm/kgdb.h>
  46. #endif
  47. extern void platform_init(unsigned long r3, unsigned long r4,
  48. unsigned long r5, unsigned long r6, unsigned long r7);
  49. extern void bootx_init(unsigned long r4, unsigned long phys);
  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. char *sysmap;
  58. unsigned long sysmap_size;
  59. /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
  60. size value reported by the boot loader. */
  61. unsigned long boot_mem_size;
  62. unsigned long ISA_DMA_THRESHOLD;
  63. unsigned long DMA_MODE_READ, DMA_MODE_WRITE;
  64. #ifdef CONFIG_PPC_MULTIPLATFORM
  65. int _machine = 0;
  66. extern void prep_init(unsigned long r3, unsigned long r4,
  67. unsigned long r5, unsigned long r6, unsigned long r7);
  68. extern void pmac_init(unsigned long r3, unsigned long r4,
  69. unsigned long r5, unsigned long r6, unsigned long r7);
  70. extern void chrp_init(unsigned long r3, unsigned long r4,
  71. unsigned long r5, unsigned long r6, unsigned long r7);
  72. #endif /* CONFIG_PPC_MULTIPLATFORM */
  73. #ifdef CONFIG_MAGIC_SYSRQ
  74. unsigned long SYSRQ_KEY = 0x54;
  75. #endif /* CONFIG_MAGIC_SYSRQ */
  76. #ifdef CONFIG_VGA_CONSOLE
  77. unsigned long vgacon_remap_base;
  78. #endif
  79. struct machdep_calls ppc_md;
  80. /*
  81. * These are used in binfmt_elf.c to put aux entries on the stack
  82. * for each elf executable being started.
  83. */
  84. int dcache_bsize;
  85. int icache_bsize;
  86. int ucache_bsize;
  87. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
  88. defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
  89. struct screen_info screen_info = {
  90. 0, 25, /* orig-x, orig-y */
  91. 0, /* unused */
  92. 0, /* orig-video-page */
  93. 0, /* orig-video-mode */
  94. 80, /* orig-video-cols */
  95. 0,0,0, /* ega_ax, ega_bx, ega_cx */
  96. 25, /* orig-video-lines */
  97. 1, /* orig-video-isVGA */
  98. 16 /* orig-video-points */
  99. };
  100. #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
  101. void machine_restart(char *cmd)
  102. {
  103. #ifdef CONFIG_NVRAM
  104. nvram_sync();
  105. #endif
  106. ppc_md.restart(cmd);
  107. }
  108. EXPORT_SYMBOL(machine_restart);
  109. void machine_power_off(void)
  110. {
  111. #ifdef CONFIG_NVRAM
  112. nvram_sync();
  113. #endif
  114. ppc_md.power_off();
  115. }
  116. EXPORT_SYMBOL(machine_power_off);
  117. void machine_halt(void)
  118. {
  119. #ifdef CONFIG_NVRAM
  120. nvram_sync();
  121. #endif
  122. ppc_md.halt();
  123. }
  124. EXPORT_SYMBOL(machine_halt);
  125. void (*pm_power_off)(void) = machine_power_off;
  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 (i = 0; i < NR_CPUS; ++i)
  142. if (cpu_online(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[i]->pvr_mask)
  163. seq_printf(m, "%s", cur_cpu_spec[i]->cpu_name);
  164. else
  165. seq_printf(m, "unknown (%08x)", pvr);
  166. #ifdef CONFIG_ALTIVEC
  167. if (cur_cpu_spec[i]->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[i]->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. switch (PVR_VER(pvr)) {
  192. case 0x0020: /* 403 family */
  193. maj = PVR_MAJ(pvr) + 1;
  194. min = PVR_MIN(pvr);
  195. break;
  196. case 0x1008: /* 740P/750P ?? */
  197. maj = ((pvr >> 8) & 0xFF) - 1;
  198. min = pvr & 0xFF;
  199. break;
  200. case 0x8083: /* e300 */
  201. maj = PVR_MAJ(pvr);
  202. min = PVR_MIN(pvr);
  203. break;
  204. case 0x8020: /* e500 */
  205. maj = PVR_MAJ(pvr);
  206. min = PVR_MIN(pvr);
  207. break;
  208. default:
  209. maj = (pvr >> 8) & 0xFF;
  210. min = pvr & 0xFF;
  211. break;
  212. }
  213. seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
  214. maj, min, PVR_VER(pvr), PVR_REV(pvr));
  215. seq_printf(m, "bogomips\t: %lu.%02lu\n",
  216. lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
  217. #if defined(CONFIG_85xx) || defined(CONFIG_83xx)
  218. if (cur_ppc_sys_spec->ppc_sys_name)
  219. seq_printf(m, "chipset\t\t: %s\n",
  220. cur_ppc_sys_spec->ppc_sys_name);
  221. #endif
  222. #ifdef CONFIG_SMP
  223. seq_printf(m, "\n");
  224. #endif
  225. return 0;
  226. }
  227. static void *c_start(struct seq_file *m, loff_t *pos)
  228. {
  229. int i = *pos;
  230. return i <= NR_CPUS? (void *) (i + 1): NULL;
  231. }
  232. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  233. {
  234. ++*pos;
  235. return c_start(m, pos);
  236. }
  237. static void c_stop(struct seq_file *m, void *v)
  238. {
  239. }
  240. struct seq_operations cpuinfo_op = {
  241. .start =c_start,
  242. .next = c_next,
  243. .stop = c_stop,
  244. .show = show_cpuinfo,
  245. };
  246. /*
  247. * We're called here very early in the boot. We determine the machine
  248. * type and call the appropriate low-level setup functions.
  249. * -- Cort <cort@fsmlabs.com>
  250. *
  251. * Note that the kernel may be running at an address which is different
  252. * from the address that it was linked at, so we must use RELOC/PTRRELOC
  253. * to access static data (including strings). -- paulus
  254. */
  255. __init
  256. unsigned long
  257. early_init(int r3, int r4, int r5)
  258. {
  259. unsigned long phys;
  260. unsigned long offset = reloc_offset();
  261. /* Default */
  262. phys = offset + KERNELBASE;
  263. /* First zero the BSS -- use memset, some arches don't have
  264. * caches on yet */
  265. memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
  266. /*
  267. * Identify the CPU type and fix up code sections
  268. * that depend on which cpu we have.
  269. */
  270. identify_cpu(offset, 0);
  271. do_cpu_ftr_fixups(offset);
  272. #if defined(CONFIG_PPC_MULTIPLATFORM)
  273. reloc_got2(offset);
  274. /* If we came here from BootX, clear the screen,
  275. * set up some pointers and return. */
  276. if ((r3 == 0x426f6f58) && (r5 == 0))
  277. bootx_init(r4, phys);
  278. /*
  279. * don't do anything on prep
  280. * for now, don't use bootinfo because it breaks yaboot 0.5
  281. * and assume that if we didn't find a magic number, we have OF
  282. */
  283. else if (*(unsigned long *)(0) != 0xdeadc0de)
  284. phys = prom_init(r3, r4, (prom_entry)r5);
  285. reloc_got2(-offset);
  286. #endif
  287. return phys;
  288. }
  289. #ifdef CONFIG_PPC_OF
  290. /*
  291. * Assume here that all clock rates are the same in a
  292. * smp system. -- Cort
  293. */
  294. int __openfirmware
  295. of_show_percpuinfo(struct seq_file *m, int i)
  296. {
  297. struct device_node *cpu_node;
  298. u32 *fp;
  299. int s;
  300. cpu_node = find_type_devices("cpu");
  301. if (!cpu_node)
  302. return 0;
  303. for (s = 0; s < i && cpu_node->next; s++)
  304. cpu_node = cpu_node->next;
  305. fp = (u32 *)get_property(cpu_node, "clock-frequency", NULL);
  306. if (fp)
  307. seq_printf(m, "clock\t\t: %dMHz\n", *fp / 1000000);
  308. return 0;
  309. }
  310. void __init
  311. intuit_machine_type(void)
  312. {
  313. char *model;
  314. struct device_node *root;
  315. /* ask the OF info if we're a chrp or pmac */
  316. root = find_path_device("/");
  317. if (root != 0) {
  318. /* assume pmac unless proven to be chrp -- Cort */
  319. _machine = _MACH_Pmac;
  320. model = get_property(root, "device_type", NULL);
  321. if (model && !strncmp("chrp", model, 4))
  322. _machine = _MACH_chrp;
  323. else {
  324. model = get_property(root, "model", NULL);
  325. if (model && !strncmp(model, "IBM", 3))
  326. _machine = _MACH_chrp;
  327. }
  328. }
  329. }
  330. #endif
  331. #ifdef CONFIG_PPC_MULTIPLATFORM
  332. /*
  333. * The PPC_MULTIPLATFORM version of platform_init...
  334. */
  335. void __init
  336. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  337. unsigned long r6, unsigned long r7)
  338. {
  339. #ifdef CONFIG_BOOTX_TEXT
  340. if (boot_text_mapped) {
  341. btext_clearscreen();
  342. btext_welcome();
  343. }
  344. #endif
  345. parse_bootinfo(find_bootinfo());
  346. /* if we didn't get any bootinfo telling us what we are... */
  347. if (_machine == 0) {
  348. /* prep boot loader tells us if we're prep or not */
  349. if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
  350. _machine = _MACH_prep;
  351. }
  352. /* not much more to do here, if prep */
  353. if (_machine == _MACH_prep) {
  354. prep_init(r3, r4, r5, r6, r7);
  355. return;
  356. }
  357. /* prom_init has already been called from __start */
  358. if (boot_infos)
  359. relocate_nodes();
  360. /* If we aren't PReP, we can find out if we're Pmac
  361. * or CHRP with this. */
  362. if (_machine == 0)
  363. intuit_machine_type();
  364. /* finish_device_tree may need _machine defined. */
  365. finish_device_tree();
  366. /*
  367. * If we were booted via quik, r3 points to the physical
  368. * address of the command-line parameters.
  369. * If we were booted from an xcoff image (i.e. netbooted or
  370. * booted from floppy), we get the command line from the
  371. * bootargs property of the /chosen node.
  372. * If an initial ramdisk is present, r3 and r4
  373. * are used for initrd_start and initrd_size,
  374. * otherwise they contain 0xdeadbeef.
  375. */
  376. if (r3 >= 0x4000 && r3 < 0x800000 && r4 == 0) {
  377. strlcpy(cmd_line, (char *)r3 + KERNELBASE,
  378. sizeof(cmd_line));
  379. } else if (boot_infos != 0) {
  380. /* booted by BootX - check for ramdisk */
  381. if (boot_infos->kernelParamsOffset != 0)
  382. strlcpy(cmd_line, (char *) boot_infos
  383. + boot_infos->kernelParamsOffset,
  384. sizeof(cmd_line));
  385. #ifdef CONFIG_BLK_DEV_INITRD
  386. if (boot_infos->ramDisk) {
  387. initrd_start = (unsigned long) boot_infos
  388. + boot_infos->ramDisk;
  389. initrd_end = initrd_start + boot_infos->ramDiskSize;
  390. initrd_below_start_ok = 1;
  391. }
  392. #endif
  393. } else {
  394. struct device_node *chosen;
  395. char *p;
  396. #ifdef CONFIG_BLK_DEV_INITRD
  397. if (r3 && r4 && r4 != 0xdeadbeef) {
  398. if (r3 < KERNELBASE)
  399. r3 += KERNELBASE;
  400. initrd_start = r3;
  401. initrd_end = r3 + r4;
  402. ROOT_DEV = Root_RAM0;
  403. initrd_below_start_ok = 1;
  404. }
  405. #endif
  406. chosen = find_devices("chosen");
  407. if (chosen != NULL) {
  408. p = get_property(chosen, "bootargs", NULL);
  409. if (p && *p) {
  410. strlcpy(cmd_line, p, sizeof(cmd_line));
  411. }
  412. }
  413. }
  414. #ifdef CONFIG_ADB
  415. if (strstr(cmd_line, "adb_sync")) {
  416. extern int __adb_probe_sync;
  417. __adb_probe_sync = 1;
  418. }
  419. #endif /* CONFIG_ADB */
  420. switch (_machine) {
  421. case _MACH_Pmac:
  422. pmac_init(r3, r4, r5, r6, r7);
  423. break;
  424. case _MACH_chrp:
  425. chrp_init(r3, r4, r5, r6, r7);
  426. break;
  427. }
  428. }
  429. #ifdef CONFIG_SERIAL_CORE_CONSOLE
  430. extern char *of_stdout_device;
  431. static int __init set_preferred_console(void)
  432. {
  433. struct device_node *prom_stdout;
  434. char *name;
  435. int offset;
  436. if (of_stdout_device == NULL)
  437. return -ENODEV;
  438. /* The user has requested a console so this is already set up. */
  439. if (strstr(saved_command_line, "console="))
  440. return -EBUSY;
  441. prom_stdout = find_path_device(of_stdout_device);
  442. if (!prom_stdout)
  443. return -ENODEV;
  444. name = (char *)get_property(prom_stdout, "name", NULL);
  445. if (!name)
  446. return -ENODEV;
  447. if (strcmp(name, "serial") == 0) {
  448. int i;
  449. u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i);
  450. if (i > 8) {
  451. switch (reg[1]) {
  452. case 0x3f8:
  453. offset = 0;
  454. break;
  455. case 0x2f8:
  456. offset = 1;
  457. break;
  458. case 0x898:
  459. offset = 2;
  460. break;
  461. case 0x890:
  462. offset = 3;
  463. break;
  464. default:
  465. /* We dont recognise the serial port */
  466. return -ENODEV;
  467. }
  468. }
  469. } else if (strcmp(name, "ch-a") == 0)
  470. offset = 0;
  471. else if (strcmp(name, "ch-b") == 0)
  472. offset = 1;
  473. else
  474. return -ENODEV;
  475. return add_preferred_console("ttyS", offset, NULL);
  476. }
  477. console_initcall(set_preferred_console);
  478. #endif /* CONFIG_SERIAL_CORE_CONSOLE */
  479. #endif /* CONFIG_PPC_MULTIPLATFORM */
  480. struct bi_record *find_bootinfo(void)
  481. {
  482. struct bi_record *rec;
  483. rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
  484. if ( rec->tag != BI_FIRST ) {
  485. /*
  486. * This 0x10000 offset is a terrible hack but it will go away when
  487. * we have the bootloader handle all the relocation and
  488. * prom calls -- Cort
  489. */
  490. rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
  491. if ( rec->tag != BI_FIRST )
  492. return NULL;
  493. }
  494. return rec;
  495. }
  496. void parse_bootinfo(struct bi_record *rec)
  497. {
  498. if (rec == NULL || rec->tag != BI_FIRST)
  499. return;
  500. while (rec->tag != BI_LAST) {
  501. ulong *data = rec->data;
  502. switch (rec->tag) {
  503. case BI_CMD_LINE:
  504. strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
  505. break;
  506. case BI_SYSMAP:
  507. sysmap = (char *)((data[0] >= (KERNELBASE)) ? data[0] :
  508. (data[0]+KERNELBASE));
  509. sysmap_size = data[1];
  510. break;
  511. #ifdef CONFIG_BLK_DEV_INITRD
  512. case BI_INITRD:
  513. initrd_start = data[0] + KERNELBASE;
  514. initrd_end = data[0] + data[1] + KERNELBASE;
  515. break;
  516. #endif /* CONFIG_BLK_DEV_INITRD */
  517. #ifdef CONFIG_PPC_MULTIPLATFORM
  518. case BI_MACHTYPE:
  519. _machine = data[0];
  520. break;
  521. #endif
  522. case BI_MEMSIZE:
  523. boot_mem_size = data[0];
  524. break;
  525. }
  526. rec = (struct bi_record *)((ulong)rec + rec->size);
  527. }
  528. }
  529. /*
  530. * Find out what kind of machine we're on and save any data we need
  531. * from the early boot process (devtree is copied on pmac by prom_init()).
  532. * This is called very early on the boot process, after a minimal
  533. * MMU environment has been set up but before MMU_init is called.
  534. */
  535. void __init
  536. machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
  537. unsigned long r6, unsigned long r7)
  538. {
  539. #ifdef CONFIG_CMDLINE
  540. strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
  541. #endif /* CONFIG_CMDLINE */
  542. #ifdef CONFIG_6xx
  543. ppc_md.power_save = ppc6xx_idle;
  544. #endif
  545. #ifdef CONFIG_POWER4
  546. ppc_md.power_save = power4_idle;
  547. #endif
  548. platform_init(r3, r4, r5, r6, r7);
  549. if (ppc_md.progress)
  550. ppc_md.progress("id mach(): done", 0x200);
  551. }
  552. /* Checks "l2cr=xxxx" command-line option */
  553. int __init ppc_setup_l2cr(char *str)
  554. {
  555. if (cpu_has_feature(CPU_FTR_L2CR)) {
  556. unsigned long val = simple_strtoul(str, NULL, 0);
  557. printk(KERN_INFO "l2cr set to %lx\n", val);
  558. _set_L2CR(0); /* force invalidate by disable cache */
  559. _set_L2CR(val); /* and enable it */
  560. }
  561. return 1;
  562. }
  563. __setup("l2cr=", ppc_setup_l2cr);
  564. #ifdef CONFIG_GENERIC_NVRAM
  565. /* Generic nvram hooks used by drivers/char/gen_nvram.c */
  566. unsigned char nvram_read_byte(int addr)
  567. {
  568. if (ppc_md.nvram_read_val)
  569. return ppc_md.nvram_read_val(addr);
  570. return 0xff;
  571. }
  572. EXPORT_SYMBOL(nvram_read_byte);
  573. void nvram_write_byte(unsigned char val, int addr)
  574. {
  575. if (ppc_md.nvram_write_val)
  576. ppc_md.nvram_write_val(addr, val);
  577. }
  578. EXPORT_SYMBOL(nvram_write_byte);
  579. void nvram_sync(void)
  580. {
  581. if (ppc_md.nvram_sync)
  582. ppc_md.nvram_sync();
  583. }
  584. EXPORT_SYMBOL(nvram_sync);
  585. #endif /* CONFIG_NVRAM */
  586. static struct cpu cpu_devices[NR_CPUS];
  587. int __init ppc_init(void)
  588. {
  589. int i;
  590. /* clear the progress line */
  591. if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
  592. /* register CPU devices */
  593. for (i = 0; i < NR_CPUS; i++)
  594. if (cpu_possible(i))
  595. register_cpu(&cpu_devices[i], i, NULL);
  596. /* call platform init */
  597. if (ppc_md.init != NULL) {
  598. ppc_md.init();
  599. }
  600. return 0;
  601. }
  602. arch_initcall(ppc_init);
  603. /* Warning, IO base is not yet inited */
  604. void __init setup_arch(char **cmdline_p)
  605. {
  606. extern char *klimit;
  607. extern void do_init_bootmem(void);
  608. /* so udelay does something sensible, assume <= 1000 bogomips */
  609. loops_per_jiffy = 500000000 / HZ;
  610. #ifdef CONFIG_PPC_MULTIPLATFORM
  611. /* This could be called "early setup arch", it must be done
  612. * now because xmon need it
  613. */
  614. if (_machine == _MACH_Pmac)
  615. pmac_feature_init(); /* New cool way */
  616. #endif
  617. #ifdef CONFIG_XMON
  618. xmon_map_scc();
  619. if (strstr(cmd_line, "xmon"))
  620. xmon(NULL);
  621. #endif /* CONFIG_XMON */
  622. if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
  623. #if defined(CONFIG_KGDB)
  624. if (ppc_md.kgdb_map_scc)
  625. ppc_md.kgdb_map_scc();
  626. set_debug_traps();
  627. if (strstr(cmd_line, "gdb")) {
  628. if (ppc_md.progress)
  629. ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
  630. printk("kgdb breakpoint activated\n");
  631. breakpoint();
  632. }
  633. #endif
  634. /*
  635. * Set cache line size based on type of cpu as a default.
  636. * Systems with OF can look in the properties on the cpu node(s)
  637. * for a possibly more accurate value.
  638. */
  639. if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
  640. dcache_bsize = cur_cpu_spec[0]->dcache_bsize;
  641. icache_bsize = cur_cpu_spec[0]->icache_bsize;
  642. ucache_bsize = 0;
  643. } else
  644. ucache_bsize = dcache_bsize = icache_bsize
  645. = cur_cpu_spec[0]->dcache_bsize;
  646. /* reboot on panic */
  647. panic_timeout = 180;
  648. init_mm.start_code = PAGE_OFFSET;
  649. init_mm.end_code = (unsigned long) _etext;
  650. init_mm.end_data = (unsigned long) _edata;
  651. init_mm.brk = (unsigned long) klimit;
  652. /* Save unparsed command line copy for /proc/cmdline */
  653. strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
  654. *cmdline_p = cmd_line;
  655. /* set up the bootmem stuff with available memory */
  656. do_init_bootmem();
  657. if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
  658. #ifdef CONFIG_PPC_OCP
  659. /* Initialize OCP device list */
  660. ocp_early_init();
  661. if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
  662. #endif
  663. #ifdef CONFIG_DUMMY_CONSOLE
  664. conswitchp = &dummy_con;
  665. #endif
  666. ppc_md.setup_arch();
  667. if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
  668. paging_init();
  669. /* this is for modules since _machine can be a define -- Cort */
  670. ppc_md.ppc_machine = _machine;
  671. }