setup-common.c 14 KB

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