setup-common.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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/platform_device.h>
  22. #include <linux/ide.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/ioport.h>
  25. #include <linux/console.h>
  26. #include <linux/utsname.h>
  27. #include <linux/tty.h>
  28. #include <linux/root_dev.h>
  29. #include <linux/notifier.h>
  30. #include <linux/cpu.h>
  31. #include <linux/unistd.h>
  32. #include <linux/serial.h>
  33. #include <linux/serial_8250.h>
  34. #include <asm/io.h>
  35. #include <asm/prom.h>
  36. #include <asm/processor.h>
  37. #include <asm/vdso_datapage.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/smp.h>
  40. #include <asm/elf.h>
  41. #include <asm/machdep.h>
  42. #include <asm/time.h>
  43. #include <asm/cputable.h>
  44. #include <asm/sections.h>
  45. #include <asm/btext.h>
  46. #include <asm/nvram.h>
  47. #include <asm/setup.h>
  48. #include <asm/system.h>
  49. #include <asm/rtas.h>
  50. #include <asm/iommu.h>
  51. #include <asm/serial.h>
  52. #include <asm/cache.h>
  53. #include <asm/page.h>
  54. #include <asm/mmu.h>
  55. #include <asm/lmb.h>
  56. #include <asm/xmon.h>
  57. #include "setup.h"
  58. #undef DEBUG
  59. #ifdef DEBUG
  60. #include <asm/udbg.h>
  61. #define DBG(fmt...) udbg_printf(fmt)
  62. #else
  63. #define DBG(fmt...)
  64. #endif
  65. #ifdef CONFIG_PPC_MULTIPLATFORM
  66. int _machine = 0;
  67. EXPORT_SYMBOL(_machine);
  68. #endif
  69. unsigned long klimit = (unsigned long) _end;
  70. /*
  71. * This still seems to be needed... -- paulus
  72. */
  73. struct screen_info screen_info = {
  74. .orig_x = 0,
  75. .orig_y = 25,
  76. .orig_video_cols = 80,
  77. .orig_video_lines = 25,
  78. .orig_video_isVGA = 1,
  79. .orig_video_points = 16
  80. };
  81. #ifdef __DO_IRQ_CANON
  82. /* XXX should go elsewhere eventually */
  83. int ppc_do_canonicalize_irqs;
  84. EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
  85. #endif
  86. /* also used by kexec */
  87. void machine_shutdown(void)
  88. {
  89. if (ppc_md.machine_shutdown)
  90. ppc_md.machine_shutdown();
  91. }
  92. void machine_restart(char *cmd)
  93. {
  94. machine_shutdown();
  95. if (ppc_md.restart)
  96. ppc_md.restart(cmd);
  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. void machine_power_off(void)
  105. {
  106. machine_shutdown();
  107. if (ppc_md.power_off)
  108. ppc_md.power_off();
  109. #ifdef CONFIG_SMP
  110. smp_send_stop();
  111. #endif
  112. printk(KERN_EMERG "System Halted, OK to turn off power\n");
  113. local_irq_disable();
  114. while (1) ;
  115. }
  116. /* Used by the G5 thermal driver */
  117. EXPORT_SYMBOL_GPL(machine_power_off);
  118. void (*pm_power_off)(void) = machine_power_off;
  119. EXPORT_SYMBOL_GPL(pm_power_off);
  120. void machine_halt(void)
  121. {
  122. machine_shutdown();
  123. if (ppc_md.halt)
  124. ppc_md.halt();
  125. #ifdef CONFIG_SMP
  126. smp_send_stop();
  127. #endif
  128. printk(KERN_EMERG "System Halted, OK to turn off power\n");
  129. local_irq_disable();
  130. while (1) ;
  131. }
  132. #ifdef CONFIG_TAU
  133. extern u32 cpu_temp(unsigned long cpu);
  134. extern u32 cpu_temp_both(unsigned long cpu);
  135. #endif /* CONFIG_TAU */
  136. #ifdef CONFIG_SMP
  137. DEFINE_PER_CPU(unsigned int, pvr);
  138. #endif
  139. static int show_cpuinfo(struct seq_file *m, void *v)
  140. {
  141. unsigned long cpu_id = (unsigned long)v - 1;
  142. unsigned int pvr;
  143. unsigned short maj;
  144. unsigned short min;
  145. if (cpu_id == NR_CPUS) {
  146. #if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
  147. unsigned long bogosum = 0;
  148. int i;
  149. for (i = 0; i < NR_CPUS; ++i)
  150. if (cpu_online(i))
  151. bogosum += loops_per_jiffy;
  152. seq_printf(m, "total bogomips\t: %lu.%02lu\n",
  153. bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
  154. #endif /* CONFIG_SMP && CONFIG_PPC32 */
  155. seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
  156. if (ppc_md.show_cpuinfo != NULL)
  157. ppc_md.show_cpuinfo(m);
  158. return 0;
  159. }
  160. /* We only show online cpus: disable preempt (overzealous, I
  161. * knew) to prevent cpu going down. */
  162. preempt_disable();
  163. if (!cpu_online(cpu_id)) {
  164. preempt_enable();
  165. return 0;
  166. }
  167. #ifdef CONFIG_SMP
  168. pvr = per_cpu(pvr, cpu_id);
  169. #else
  170. pvr = mfspr(SPRN_PVR);
  171. #endif
  172. maj = (pvr >> 8) & 0xFF;
  173. min = pvr & 0xFF;
  174. seq_printf(m, "processor\t: %lu\n", cpu_id);
  175. seq_printf(m, "cpu\t\t: ");
  176. if (cur_cpu_spec->pvr_mask)
  177. seq_printf(m, "%s", cur_cpu_spec->cpu_name);
  178. else
  179. seq_printf(m, "unknown (%08x)", pvr);
  180. #ifdef CONFIG_ALTIVEC
  181. if (cpu_has_feature(CPU_FTR_ALTIVEC))
  182. seq_printf(m, ", altivec supported");
  183. #endif /* CONFIG_ALTIVEC */
  184. seq_printf(m, "\n");
  185. #ifdef CONFIG_TAU
  186. if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
  187. #ifdef CONFIG_TAU_AVERAGE
  188. /* more straightforward, but potentially misleading */
  189. seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
  190. cpu_temp(cpu_id));
  191. #else
  192. /* show the actual temp sensor range */
  193. u32 temp;
  194. temp = cpu_temp_both(cpu_id);
  195. seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
  196. temp & 0xff, temp >> 16);
  197. #endif
  198. }
  199. #endif /* CONFIG_TAU */
  200. /*
  201. * Assume here that all clock rates are the same in a
  202. * smp system. -- Cort
  203. */
  204. if (ppc_proc_freq)
  205. seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
  206. ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
  207. if (ppc_md.show_percpuinfo != NULL)
  208. ppc_md.show_percpuinfo(m, cpu_id);
  209. /* If we are a Freescale core do a simple check so
  210. * we dont have to keep adding cases in the future */
  211. if (PVR_VER(pvr) & 0x8000) {
  212. maj = PVR_MAJ(pvr);
  213. min = PVR_MIN(pvr);
  214. } else {
  215. switch (PVR_VER(pvr)) {
  216. case 0x0020: /* 403 family */
  217. maj = PVR_MAJ(pvr) + 1;
  218. min = PVR_MIN(pvr);
  219. break;
  220. case 0x1008: /* 740P/750P ?? */
  221. maj = ((pvr >> 8) & 0xFF) - 1;
  222. min = pvr & 0xFF;
  223. break;
  224. default:
  225. maj = (pvr >> 8) & 0xFF;
  226. min = pvr & 0xFF;
  227. break;
  228. }
  229. }
  230. seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
  231. maj, min, PVR_VER(pvr), PVR_REV(pvr));
  232. #ifdef CONFIG_PPC32
  233. seq_printf(m, "bogomips\t: %lu.%02lu\n",
  234. loops_per_jiffy / (500000/HZ),
  235. (loops_per_jiffy / (5000/HZ)) % 100);
  236. #endif
  237. #ifdef CONFIG_SMP
  238. seq_printf(m, "\n");
  239. #endif
  240. preempt_enable();
  241. return 0;
  242. }
  243. static void *c_start(struct seq_file *m, loff_t *pos)
  244. {
  245. unsigned long i = *pos;
  246. return i <= NR_CPUS ? (void *)(i + 1) : NULL;
  247. }
  248. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  249. {
  250. ++*pos;
  251. return c_start(m, pos);
  252. }
  253. static void c_stop(struct seq_file *m, void *v)
  254. {
  255. }
  256. struct seq_operations cpuinfo_op = {
  257. .start =c_start,
  258. .next = c_next,
  259. .stop = c_stop,
  260. .show = show_cpuinfo,
  261. };
  262. void __init check_for_initrd(void)
  263. {
  264. #ifdef CONFIG_BLK_DEV_INITRD
  265. unsigned long *prop;
  266. DBG(" -> check_for_initrd()\n");
  267. if (of_chosen) {
  268. prop = (unsigned long *)get_property(of_chosen,
  269. "linux,initrd-start", NULL);
  270. if (prop != NULL) {
  271. initrd_start = (unsigned long)__va(*prop);
  272. prop = (unsigned long *)get_property(of_chosen,
  273. "linux,initrd-end", NULL);
  274. if (prop != NULL) {
  275. initrd_end = (unsigned long)__va(*prop);
  276. initrd_below_start_ok = 1;
  277. } else
  278. initrd_start = 0;
  279. }
  280. }
  281. /* If we were passed an initrd, set the ROOT_DEV properly if the values
  282. * look sensible. If not, clear initrd reference.
  283. */
  284. if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) &&
  285. initrd_end > initrd_start)
  286. ROOT_DEV = Root_RAM0;
  287. else
  288. initrd_start = initrd_end = 0;
  289. if (initrd_start)
  290. printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
  291. DBG(" <- check_for_initrd()\n");
  292. #endif /* CONFIG_BLK_DEV_INITRD */
  293. }
  294. #ifdef CONFIG_SMP
  295. /**
  296. * setup_cpu_maps - initialize the following cpu maps:
  297. * cpu_possible_map
  298. * cpu_present_map
  299. * cpu_sibling_map
  300. *
  301. * Having the possible map set up early allows us to restrict allocations
  302. * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
  303. *
  304. * We do not initialize the online map here; cpus set their own bits in
  305. * cpu_online_map as they come up.
  306. *
  307. * This function is valid only for Open Firmware systems. finish_device_tree
  308. * must be called before using this.
  309. *
  310. * While we're here, we may as well set the "physical" cpu ids in the paca.
  311. */
  312. void __init smp_setup_cpu_maps(void)
  313. {
  314. struct device_node *dn = NULL;
  315. int cpu = 0;
  316. int swap_cpuid = 0;
  317. while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
  318. int *intserv;
  319. int j, len = sizeof(u32), nthreads = 1;
  320. intserv = (int *)get_property(dn, "ibm,ppc-interrupt-server#s",
  321. &len);
  322. if (intserv)
  323. nthreads = len / sizeof(int);
  324. else {
  325. intserv = (int *) get_property(dn, "reg", NULL);
  326. if (!intserv)
  327. intserv = &cpu; /* assume logical == phys */
  328. }
  329. for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
  330. cpu_set(cpu, cpu_present_map);
  331. set_hard_smp_processor_id(cpu, intserv[j]);
  332. if (intserv[j] == boot_cpuid_phys)
  333. swap_cpuid = cpu;
  334. cpu_set(cpu, cpu_possible_map);
  335. cpu++;
  336. }
  337. }
  338. /* Swap CPU id 0 with boot_cpuid_phys, so we can always assume that
  339. * boot cpu is logical 0.
  340. */
  341. if (boot_cpuid_phys != get_hard_smp_processor_id(0)) {
  342. u32 tmp;
  343. tmp = get_hard_smp_processor_id(0);
  344. set_hard_smp_processor_id(0, boot_cpuid_phys);
  345. set_hard_smp_processor_id(swap_cpuid, tmp);
  346. }
  347. #ifdef CONFIG_PPC64
  348. /*
  349. * On pSeries LPAR, we need to know how many cpus
  350. * could possibly be added to this partition.
  351. */
  352. if (_machine == PLATFORM_PSERIES_LPAR &&
  353. (dn = of_find_node_by_path("/rtas"))) {
  354. int num_addr_cell, num_size_cell, maxcpus;
  355. unsigned int *ireg;
  356. num_addr_cell = prom_n_addr_cells(dn);
  357. num_size_cell = prom_n_size_cells(dn);
  358. ireg = (unsigned int *)
  359. get_property(dn, "ibm,lrdr-capacity", NULL);
  360. if (!ireg)
  361. goto out;
  362. maxcpus = ireg[num_addr_cell + num_size_cell];
  363. /* Double maxcpus for processors which have SMT capability */
  364. if (cpu_has_feature(CPU_FTR_SMT))
  365. maxcpus *= 2;
  366. if (maxcpus > NR_CPUS) {
  367. printk(KERN_WARNING
  368. "Partition configured for %d cpus, "
  369. "operating system maximum is %d.\n",
  370. maxcpus, NR_CPUS);
  371. maxcpus = NR_CPUS;
  372. } else
  373. printk(KERN_INFO "Partition configured for %d cpus.\n",
  374. maxcpus);
  375. for (cpu = 0; cpu < maxcpus; cpu++)
  376. cpu_set(cpu, cpu_possible_map);
  377. out:
  378. of_node_put(dn);
  379. }
  380. /*
  381. * Do the sibling map; assume only two threads per processor.
  382. */
  383. for_each_cpu(cpu) {
  384. cpu_set(cpu, cpu_sibling_map[cpu]);
  385. if (cpu_has_feature(CPU_FTR_SMT))
  386. cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]);
  387. }
  388. vdso_data->processorCount = num_present_cpus();
  389. #endif /* CONFIG_PPC64 */
  390. }
  391. #endif /* CONFIG_SMP */
  392. #ifdef CONFIG_XMON
  393. static int __init early_xmon(char *p)
  394. {
  395. /* ensure xmon is enabled */
  396. if (p) {
  397. if (strncmp(p, "on", 2) == 0)
  398. xmon_init(1);
  399. if (strncmp(p, "off", 3) == 0)
  400. xmon_init(0);
  401. if (strncmp(p, "early", 5) != 0)
  402. return 0;
  403. }
  404. xmon_init(1);
  405. debugger(NULL);
  406. return 0;
  407. }
  408. early_param("xmon", early_xmon);
  409. #endif
  410. static __init int add_pcspkr(void)
  411. {
  412. struct device_node *np;
  413. struct platform_device *pd;
  414. int ret;
  415. np = of_find_compatible_node(NULL, NULL, "pnpPNP,100");
  416. of_node_put(np);
  417. if (!np)
  418. return -ENODEV;
  419. pd = platform_device_alloc("pcspkr", -1);
  420. if (!pd)
  421. return -ENOMEM;
  422. ret = platform_device_add(pd);
  423. if (ret)
  424. platform_device_put(pd);
  425. return ret;
  426. }
  427. device_initcall(add_pcspkr);