setup-common.c 14 KB

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