setup-common.c 12 KB

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