setup-common.c 13 KB

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