setup-common.c 11 KB

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