setup-common.c 13 KB

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