setup-common.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. /*
  2. * Common boot and setup code for both 32-bit and 64-bit.
  3. * Extracted from arch/powerpc/kernel/setup_64.c.
  4. *
  5. * Copyright (C) 2001 PPC64 Team, IBM Corp
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <linux/config.h>
  13. #include <linux/module.h>
  14. #include <linux/string.h>
  15. #include <linux/sched.h>
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/reboot.h>
  19. #include <linux/delay.h>
  20. #include <linux/initrd.h>
  21. #include <linux/ide.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/ioport.h>
  24. #include <linux/console.h>
  25. #include <linux/utsname.h>
  26. #include <linux/tty.h>
  27. #include <linux/root_dev.h>
  28. #include <linux/notifier.h>
  29. #include <linux/cpu.h>
  30. #include <linux/unistd.h>
  31. #include <linux/serial.h>
  32. #include <linux/serial_8250.h>
  33. #include <asm/io.h>
  34. #include <asm/prom.h>
  35. #include <asm/processor.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/smp.h>
  38. #include <asm/elf.h>
  39. #include <asm/machdep.h>
  40. #include <asm/time.h>
  41. #include <asm/cputable.h>
  42. #include <asm/sections.h>
  43. #include <asm/btext.h>
  44. #include <asm/nvram.h>
  45. #include <asm/setup.h>
  46. #include <asm/system.h>
  47. #include <asm/rtas.h>
  48. #include <asm/iommu.h>
  49. #include <asm/serial.h>
  50. #include <asm/cache.h>
  51. #include <asm/page.h>
  52. #include <asm/mmu.h>
  53. #include <asm/lmb.h>
  54. #include <asm/xmon.h>
  55. #undef DEBUG
  56. #ifdef DEBUG
  57. #define DBG(fmt...) udbg_printf(fmt)
  58. #else
  59. #define DBG(fmt...)
  60. #endif
  61. /*
  62. * This still seems to be needed... -- paulus
  63. */
  64. struct screen_info screen_info = {
  65. .orig_x = 0,
  66. .orig_y = 25,
  67. .orig_video_cols = 80,
  68. .orig_video_lines = 25,
  69. .orig_video_isVGA = 1,
  70. .orig_video_points = 16
  71. };
  72. #ifdef __DO_IRQ_CANON
  73. /* XXX should go elsewhere eventually */
  74. int ppc_do_canonicalize_irqs;
  75. EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
  76. #endif
  77. /* also used by kexec */
  78. void machine_shutdown(void)
  79. {
  80. if (ppc_md.nvram_sync)
  81. ppc_md.nvram_sync();
  82. }
  83. void machine_restart(char *cmd)
  84. {
  85. machine_shutdown();
  86. ppc_md.restart(cmd);
  87. #ifdef CONFIG_SMP
  88. smp_send_stop();
  89. #endif
  90. printk(KERN_EMERG "System Halted, OK to turn off power\n");
  91. local_irq_disable();
  92. while (1) ;
  93. }
  94. void machine_power_off(void)
  95. {
  96. machine_shutdown();
  97. ppc_md.power_off();
  98. #ifdef CONFIG_SMP
  99. smp_send_stop();
  100. #endif
  101. printk(KERN_EMERG "System Halted, OK to turn off power\n");
  102. local_irq_disable();
  103. while (1) ;
  104. }
  105. /* Used by the G5 thermal driver */
  106. EXPORT_SYMBOL_GPL(machine_power_off);
  107. void (*pm_power_off)(void) = machine_power_off;
  108. EXPORT_SYMBOL_GPL(pm_power_off);
  109. void machine_halt(void)
  110. {
  111. machine_shutdown();
  112. ppc_md.halt();
  113. #ifdef CONFIG_SMP
  114. smp_send_stop();
  115. #endif
  116. printk(KERN_EMERG "System Halted, OK to turn off power\n");
  117. local_irq_disable();
  118. while (1) ;
  119. }
  120. #ifdef CONFIG_TAU
  121. extern u32 cpu_temp(unsigned long cpu);
  122. extern u32 cpu_temp_both(unsigned long cpu);
  123. #endif /* CONFIG_TAU */
  124. #ifdef CONFIG_SMP
  125. DEFINE_PER_CPU(unsigned int, pvr);
  126. #endif
  127. static int show_cpuinfo(struct seq_file *m, void *v)
  128. {
  129. unsigned long cpu_id = (unsigned long)v - 1;
  130. unsigned int pvr;
  131. unsigned short maj;
  132. unsigned short min;
  133. if (cpu_id == NR_CPUS) {
  134. #if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
  135. unsigned long bogosum = 0;
  136. int i;
  137. for (i = 0; i < NR_CPUS; ++i)
  138. if (cpu_online(i))
  139. bogosum += 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 && CONFIG_PPC32 */
  143. seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
  144. if (ppc_md.show_cpuinfo != NULL)
  145. ppc_md.show_cpuinfo(m);
  146. return 0;
  147. }
  148. /* We only show online cpus: disable preempt (overzealous, I
  149. * knew) to prevent cpu going down. */
  150. preempt_disable();
  151. if (!cpu_online(cpu_id)) {
  152. preempt_enable();
  153. return 0;
  154. }
  155. #ifdef CONFIG_SMP
  156. pvr = per_cpu(pvr, cpu_id);
  157. #else
  158. pvr = mfspr(SPRN_PVR);
  159. #endif
  160. maj = (pvr >> 8) & 0xFF;
  161. min = pvr & 0xFF;
  162. seq_printf(m, "processor\t: %lu\n", cpu_id);
  163. seq_printf(m, "cpu\t\t: ");
  164. if (cur_cpu_spec->pvr_mask)
  165. seq_printf(m, "%s", cur_cpu_spec->cpu_name);
  166. else
  167. seq_printf(m, "unknown (%08x)", pvr);
  168. #ifdef CONFIG_ALTIVEC
  169. if (cpu_has_feature(CPU_FTR_ALTIVEC))
  170. seq_printf(m, ", altivec supported");
  171. #endif /* CONFIG_ALTIVEC */
  172. seq_printf(m, "\n");
  173. #ifdef CONFIG_TAU
  174. if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
  175. #ifdef CONFIG_TAU_AVERAGE
  176. /* more straightforward, but potentially misleading */
  177. seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
  178. cpu_temp(cpu_id));
  179. #else
  180. /* show the actual temp sensor range */
  181. u32 temp;
  182. temp = cpu_temp_both(cpu_id);
  183. seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
  184. temp & 0xff, temp >> 16);
  185. #endif
  186. }
  187. #endif /* CONFIG_TAU */
  188. /*
  189. * Assume here that all clock rates are the same in a
  190. * smp system. -- Cort
  191. */
  192. if (ppc_proc_freq)
  193. seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
  194. ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
  195. if (ppc_md.show_percpuinfo != NULL)
  196. ppc_md.show_percpuinfo(m, cpu_id);
  197. /* If we are a Freescale core do a simple check so
  198. * we dont have to keep adding cases in the future */
  199. if (PVR_VER(pvr) & 0x8000) {
  200. maj = PVR_MAJ(pvr);
  201. min = PVR_MIN(pvr);
  202. } else {
  203. switch (PVR_VER(pvr)) {
  204. case 0x0020: /* 403 family */
  205. maj = PVR_MAJ(pvr) + 1;
  206. min = PVR_MIN(pvr);
  207. break;
  208. case 0x1008: /* 740P/750P ?? */
  209. maj = ((pvr >> 8) & 0xFF) - 1;
  210. min = pvr & 0xFF;
  211. break;
  212. default:
  213. maj = (pvr >> 8) & 0xFF;
  214. min = pvr & 0xFF;
  215. break;
  216. }
  217. }
  218. seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
  219. maj, min, PVR_VER(pvr), PVR_REV(pvr));
  220. #ifdef CONFIG_PPC32
  221. seq_printf(m, "bogomips\t: %lu.%02lu\n",
  222. loops_per_jiffy / (500000/HZ),
  223. (loops_per_jiffy / (5000/HZ)) % 100);
  224. #endif
  225. #ifdef CONFIG_SMP
  226. seq_printf(m, "\n");
  227. #endif
  228. preempt_enable();
  229. return 0;
  230. }
  231. static void *c_start(struct seq_file *m, loff_t *pos)
  232. {
  233. unsigned long i = *pos;
  234. return i <= NR_CPUS ? (void *)(i + 1) : NULL;
  235. }
  236. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  237. {
  238. ++*pos;
  239. return c_start(m, pos);
  240. }
  241. static void c_stop(struct seq_file *m, void *v)
  242. {
  243. }
  244. struct seq_operations cpuinfo_op = {
  245. .start =c_start,
  246. .next = c_next,
  247. .stop = c_stop,
  248. .show = show_cpuinfo,
  249. };
  250. #ifdef CONFIG_PPC_MULTIPLATFORM
  251. static int __init set_preferred_console(void)
  252. {
  253. struct device_node *prom_stdout = NULL;
  254. char *name;
  255. u32 *spd;
  256. int offset = 0;
  257. DBG(" -> set_preferred_console()\n");
  258. /* The user has requested a console so this is already set up. */
  259. if (strstr(saved_command_line, "console=")) {
  260. DBG(" console was specified !\n");
  261. return -EBUSY;
  262. }
  263. if (!of_chosen) {
  264. DBG(" of_chosen is NULL !\n");
  265. return -ENODEV;
  266. }
  267. /* We are getting a weird phandle from OF ... */
  268. /* ... So use the full path instead */
  269. name = (char *)get_property(of_chosen, "linux,stdout-path", NULL);
  270. if (name == NULL) {
  271. DBG(" no linux,stdout-path !\n");
  272. return -ENODEV;
  273. }
  274. prom_stdout = of_find_node_by_path(name);
  275. if (!prom_stdout) {
  276. DBG(" can't find stdout package %s !\n", name);
  277. return -ENODEV;
  278. }
  279. DBG("stdout is %s\n", prom_stdout->full_name);
  280. name = (char *)get_property(prom_stdout, "name", NULL);
  281. if (!name) {
  282. DBG(" stdout package has no name !\n");
  283. goto not_found;
  284. }
  285. spd = (u32 *)get_property(prom_stdout, "current-speed", NULL);
  286. if (0)
  287. ;
  288. #ifdef CONFIG_SERIAL_8250_CONSOLE
  289. else if (strcmp(name, "serial") == 0) {
  290. int i;
  291. u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i);
  292. if (i > 8) {
  293. switch (reg[1]) {
  294. case 0x3f8:
  295. offset = 0;
  296. break;
  297. case 0x2f8:
  298. offset = 1;
  299. break;
  300. case 0x898:
  301. offset = 2;
  302. break;
  303. case 0x890:
  304. offset = 3;
  305. break;
  306. default:
  307. /* We dont recognise the serial port */
  308. goto not_found;
  309. }
  310. }
  311. }
  312. #endif /* CONFIG_SERIAL_8250_CONSOLE */
  313. #ifdef CONFIG_PPC_PSERIES
  314. else if (strcmp(name, "vty") == 0) {
  315. u32 *reg = (u32 *)get_property(prom_stdout, "reg", NULL);
  316. char *compat = (char *)get_property(prom_stdout, "compatible", NULL);
  317. if (reg && compat && (strcmp(compat, "hvterm-protocol") == 0)) {
  318. /* Host Virtual Serial Interface */
  319. switch (reg[0]) {
  320. case 0x30000000:
  321. offset = 0;
  322. break;
  323. case 0x30000001:
  324. offset = 1;
  325. break;
  326. default:
  327. goto not_found;
  328. }
  329. of_node_put(prom_stdout);
  330. DBG("Found hvsi console at offset %d\n", offset);
  331. return add_preferred_console("hvsi", offset, NULL);
  332. } else {
  333. /* pSeries LPAR virtual console */
  334. of_node_put(prom_stdout);
  335. DBG("Found hvc console\n");
  336. return add_preferred_console("hvc", 0, NULL);
  337. }
  338. }
  339. #endif /* CONFIG_PPC_PSERIES */
  340. #ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
  341. else if (strcmp(name, "ch-a") == 0)
  342. offset = 0;
  343. else if (strcmp(name, "ch-b") == 0)
  344. offset = 1;
  345. #endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */
  346. else
  347. goto not_found;
  348. of_node_put(prom_stdout);
  349. DBG("Found serial console at ttyS%d\n", offset);
  350. if (spd) {
  351. static char __initdata opt[16];
  352. sprintf(opt, "%d", *spd);
  353. return add_preferred_console("ttyS", offset, opt);
  354. } else
  355. return add_preferred_console("ttyS", offset, NULL);
  356. not_found:
  357. DBG("No preferred console found !\n");
  358. of_node_put(prom_stdout);
  359. return -ENODEV;
  360. }
  361. console_initcall(set_preferred_console);
  362. #endif /* CONFIG_PPC_MULTIPLATFORM */
  363. void __init check_for_initrd(void)
  364. {
  365. #ifdef CONFIG_BLK_DEV_INITRD
  366. unsigned long *prop;
  367. DBG(" -> check_for_initrd()\n");
  368. if (of_chosen) {
  369. prop = (unsigned long *)get_property(of_chosen,
  370. "linux,initrd-start", NULL);
  371. if (prop != NULL) {
  372. initrd_start = (unsigned long)__va(*prop);
  373. prop = (unsigned long *)get_property(of_chosen,
  374. "linux,initrd-end", NULL);
  375. if (prop != NULL) {
  376. initrd_end = (unsigned long)__va(*prop);
  377. initrd_below_start_ok = 1;
  378. } else
  379. initrd_start = 0;
  380. }
  381. }
  382. /* If we were passed an initrd, set the ROOT_DEV properly if the values
  383. * look sensible. If not, clear initrd reference.
  384. */
  385. if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
  386. initrd_end > initrd_start)
  387. ROOT_DEV = Root_RAM0;
  388. else {
  389. printk("Bogus initrd %08lx %08lx\n", initrd_start, initrd_end);
  390. initrd_start = initrd_end = 0;
  391. }
  392. if (initrd_start)
  393. printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
  394. DBG(" <- check_for_initrd()\n");
  395. #endif /* CONFIG_BLK_DEV_INITRD */
  396. }
  397. #ifdef CONFIG_SMP
  398. /**
  399. * setup_cpu_maps - initialize the following cpu maps:
  400. * cpu_possible_map
  401. * cpu_present_map
  402. * cpu_sibling_map
  403. *
  404. * Having the possible map set up early allows us to restrict allocations
  405. * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
  406. *
  407. * We do not initialize the online map here; cpus set their own bits in
  408. * cpu_online_map as they come up.
  409. *
  410. * This function is valid only for Open Firmware systems. finish_device_tree
  411. * must be called before using this.
  412. *
  413. * While we're here, we may as well set the "physical" cpu ids in the paca.
  414. */
  415. void __init smp_setup_cpu_maps(void)
  416. {
  417. struct device_node *dn = NULL;
  418. int cpu = 0;
  419. int swap_cpuid = 0;
  420. while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
  421. int *intserv;
  422. int j, len = sizeof(u32), nthreads = 1;
  423. intserv = (int *)get_property(dn, "ibm,ppc-interrupt-server#s",
  424. &len);
  425. if (intserv)
  426. nthreads = len / sizeof(int);
  427. else {
  428. intserv = (int *) get_property(dn, "reg", NULL);
  429. if (!intserv)
  430. intserv = &cpu; /* assume logical == phys */
  431. }
  432. for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
  433. cpu_set(cpu, cpu_present_map);
  434. set_hard_smp_processor_id(cpu, intserv[j]);
  435. if (intserv[j] == boot_cpuid_phys)
  436. swap_cpuid = cpu;
  437. cpu_set(cpu, cpu_possible_map);
  438. cpu++;
  439. }
  440. }
  441. /* Swap CPU id 0 with boot_cpuid_phys, so we can always assume that
  442. * boot cpu is logical 0.
  443. */
  444. if (boot_cpuid_phys != get_hard_smp_processor_id(0)) {
  445. u32 tmp;
  446. tmp = get_hard_smp_processor_id(0);
  447. set_hard_smp_processor_id(0, boot_cpuid_phys);
  448. set_hard_smp_processor_id(swap_cpuid, tmp);
  449. }
  450. #ifdef CONFIG_PPC64
  451. /*
  452. * On pSeries LPAR, we need to know how many cpus
  453. * could possibly be added to this partition.
  454. */
  455. if (systemcfg->platform == PLATFORM_PSERIES_LPAR &&
  456. (dn = of_find_node_by_path("/rtas"))) {
  457. int num_addr_cell, num_size_cell, maxcpus;
  458. unsigned int *ireg;
  459. num_addr_cell = prom_n_addr_cells(dn);
  460. num_size_cell = prom_n_size_cells(dn);
  461. ireg = (unsigned int *)
  462. get_property(dn, "ibm,lrdr-capacity", NULL);
  463. if (!ireg)
  464. goto out;
  465. maxcpus = ireg[num_addr_cell + num_size_cell];
  466. /* Double maxcpus for processors which have SMT capability */
  467. if (cpu_has_feature(CPU_FTR_SMT))
  468. maxcpus *= 2;
  469. if (maxcpus > NR_CPUS) {
  470. printk(KERN_WARNING
  471. "Partition configured for %d cpus, "
  472. "operating system maximum is %d.\n",
  473. maxcpus, NR_CPUS);
  474. maxcpus = NR_CPUS;
  475. } else
  476. printk(KERN_INFO "Partition configured for %d cpus.\n",
  477. maxcpus);
  478. for (cpu = 0; cpu < maxcpus; cpu++)
  479. cpu_set(cpu, cpu_possible_map);
  480. out:
  481. of_node_put(dn);
  482. }
  483. /*
  484. * Do the sibling map; assume only two threads per processor.
  485. */
  486. for_each_cpu(cpu) {
  487. cpu_set(cpu, cpu_sibling_map[cpu]);
  488. if (cpu_has_feature(CPU_FTR_SMT))
  489. cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]);
  490. }
  491. systemcfg->processorCount = num_present_cpus();
  492. #endif /* CONFIG_PPC64 */
  493. }
  494. #endif /* CONFIG_SMP */
  495. #ifdef CONFIG_XMON
  496. static int __init early_xmon(char *p)
  497. {
  498. /* ensure xmon is enabled */
  499. if (p) {
  500. if (strncmp(p, "on", 2) == 0)
  501. xmon_init(1);
  502. if (strncmp(p, "off", 3) == 0)
  503. xmon_init(0);
  504. if (strncmp(p, "early", 5) != 0)
  505. return 0;
  506. }
  507. xmon_init(1);
  508. debugger(NULL);
  509. return 0;
  510. }
  511. early_param("xmon", early_xmon);
  512. #endif