pSeries_setup.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /*
  2. * linux/arch/ppc/kernel/setup.c
  3. *
  4. * Copyright (C) 1995 Linus Torvalds
  5. * Adapted from 'alpha' version by Gary Thomas
  6. * Modified by Cort Dougan (cort@cs.nmt.edu)
  7. * Modified by PPC64 Team, IBM Corp
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. /*
  15. * bootup setup stuff..
  16. */
  17. #undef DEBUG
  18. #include <linux/config.h>
  19. #include <linux/errno.h>
  20. #include <linux/sched.h>
  21. #include <linux/kernel.h>
  22. #include <linux/mm.h>
  23. #include <linux/stddef.h>
  24. #include <linux/unistd.h>
  25. #include <linux/slab.h>
  26. #include <linux/user.h>
  27. #include <linux/a.out.h>
  28. #include <linux/tty.h>
  29. #include <linux/major.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/reboot.h>
  32. #include <linux/init.h>
  33. #include <linux/ioport.h>
  34. #include <linux/console.h>
  35. #include <linux/pci.h>
  36. #include <linux/version.h>
  37. #include <linux/adb.h>
  38. #include <linux/module.h>
  39. #include <linux/delay.h>
  40. #include <linux/irq.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/root_dev.h>
  43. #include <asm/mmu.h>
  44. #include <asm/processor.h>
  45. #include <asm/io.h>
  46. #include <asm/pgtable.h>
  47. #include <asm/prom.h>
  48. #include <asm/rtas.h>
  49. #include <asm/pci-bridge.h>
  50. #include <asm/iommu.h>
  51. #include <asm/dma.h>
  52. #include <asm/machdep.h>
  53. #include <asm/irq.h>
  54. #include <asm/time.h>
  55. #include <asm/nvram.h>
  56. #include <asm/plpar_wrappers.h>
  57. #include <asm/xics.h>
  58. #include <asm/cputable.h>
  59. #include "i8259.h"
  60. #include "mpic.h"
  61. #include "pci.h"
  62. #ifdef DEBUG
  63. #define DBG(fmt...) udbg_printf(fmt)
  64. #else
  65. #define DBG(fmt...)
  66. #endif
  67. extern void pSeries_final_fixup(void);
  68. extern void pSeries_get_boot_time(struct rtc_time *rtc_time);
  69. extern void pSeries_get_rtc_time(struct rtc_time *rtc_time);
  70. extern int pSeries_set_rtc_time(struct rtc_time *rtc_time);
  71. extern void find_udbg_vterm(void);
  72. extern void system_reset_fwnmi(void); /* from head.S */
  73. extern void machine_check_fwnmi(void); /* from head.S */
  74. extern void generic_find_legacy_serial_ports(u64 *physport,
  75. unsigned int *default_speed);
  76. int fwnmi_active; /* TRUE if an FWNMI handler is present */
  77. extern unsigned long ppc_proc_freq;
  78. extern unsigned long ppc_tb_freq;
  79. extern void pSeries_system_reset_exception(struct pt_regs *regs);
  80. extern int pSeries_machine_check_exception(struct pt_regs *regs);
  81. static volatile void __iomem * chrp_int_ack_special;
  82. struct mpic *pSeries_mpic;
  83. void pSeries_get_cpuinfo(struct seq_file *m)
  84. {
  85. struct device_node *root;
  86. const char *model = "";
  87. root = of_find_node_by_path("/");
  88. if (root)
  89. model = get_property(root, "model", NULL);
  90. seq_printf(m, "machine\t\t: CHRP %s\n", model);
  91. of_node_put(root);
  92. }
  93. /* Initialize firmware assisted non-maskable interrupts if
  94. * the firmware supports this feature.
  95. *
  96. */
  97. static void __init fwnmi_init(void)
  98. {
  99. int ret;
  100. int ibm_nmi_register = rtas_token("ibm,nmi-register");
  101. if (ibm_nmi_register == RTAS_UNKNOWN_SERVICE)
  102. return;
  103. ret = rtas_call(ibm_nmi_register, 2, 1, NULL,
  104. __pa((unsigned long)system_reset_fwnmi),
  105. __pa((unsigned long)machine_check_fwnmi));
  106. if (ret == 0)
  107. fwnmi_active = 1;
  108. }
  109. static int pSeries_irq_cascade(struct pt_regs *regs, void *data)
  110. {
  111. if (chrp_int_ack_special)
  112. return readb(chrp_int_ack_special);
  113. else
  114. return i8259_irq(smp_processor_id());
  115. }
  116. static void __init pSeries_init_mpic(void)
  117. {
  118. unsigned int *addrp;
  119. struct device_node *np;
  120. int i;
  121. /* All ISUs are setup, complete initialization */
  122. mpic_init(pSeries_mpic);
  123. /* Check what kind of cascade ACK we have */
  124. if (!(np = of_find_node_by_name(NULL, "pci"))
  125. || !(addrp = (unsigned int *)
  126. get_property(np, "8259-interrupt-acknowledge", NULL)))
  127. printk(KERN_ERR "Cannot find pci to get ack address\n");
  128. else
  129. chrp_int_ack_special = ioremap(addrp[prom_n_addr_cells(np)-1], 1);
  130. of_node_put(np);
  131. /* Setup the legacy interrupts & controller */
  132. for (i = 0; i < NUM_ISA_INTERRUPTS; i++)
  133. irq_desc[i].handler = &i8259_pic;
  134. i8259_init(0);
  135. /* Hook cascade to mpic */
  136. mpic_setup_cascade(NUM_ISA_INTERRUPTS, pSeries_irq_cascade, NULL);
  137. }
  138. static void __init pSeries_setup_mpic(void)
  139. {
  140. unsigned int *opprop;
  141. unsigned long openpic_addr = 0;
  142. unsigned char senses[NR_IRQS - NUM_ISA_INTERRUPTS];
  143. struct device_node *root;
  144. int irq_count;
  145. /* Find the Open PIC if present */
  146. root = of_find_node_by_path("/");
  147. opprop = (unsigned int *) get_property(root, "platform-open-pic", NULL);
  148. if (opprop != 0) {
  149. int n = prom_n_addr_cells(root);
  150. for (openpic_addr = 0; n > 0; --n)
  151. openpic_addr = (openpic_addr << 32) + *opprop++;
  152. printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
  153. }
  154. of_node_put(root);
  155. BUG_ON(openpic_addr == 0);
  156. /* Get the sense values from OF */
  157. prom_get_irq_senses(senses, NUM_ISA_INTERRUPTS, NR_IRQS);
  158. /* Setup the openpic driver */
  159. irq_count = NR_IRQS - NUM_ISA_INTERRUPTS - 4; /* leave room for IPIs */
  160. pSeries_mpic = mpic_alloc(openpic_addr, MPIC_PRIMARY,
  161. 16, 16, irq_count, /* isu size, irq offset, irq count */
  162. NR_IRQS - 4, /* ipi offset */
  163. senses, irq_count, /* sense & sense size */
  164. " MPIC ");
  165. }
  166. static void __init pSeries_setup_arch(void)
  167. {
  168. /* Fixup ppc_md depending on the type of interrupt controller */
  169. if (ppc64_interrupt_controller == IC_OPEN_PIC) {
  170. ppc_md.init_IRQ = pSeries_init_mpic;
  171. ppc_md.get_irq = mpic_get_irq;
  172. /* Allocate the mpic now, so that find_and_init_phbs() can
  173. * fill the ISUs */
  174. pSeries_setup_mpic();
  175. } else {
  176. ppc_md.init_IRQ = xics_init_IRQ;
  177. ppc_md.get_irq = xics_get_irq;
  178. }
  179. #ifdef CONFIG_SMP
  180. smp_init_pSeries();
  181. #endif
  182. /* openpic global configuration register (64-bit format). */
  183. /* openpic Interrupt Source Unit pointer (64-bit format). */
  184. /* python0 facility area (mmio) (64-bit format) REAL address. */
  185. /* init to some ~sane value until calibrate_delay() runs */
  186. loops_per_jiffy = 50000000;
  187. if (ROOT_DEV == 0) {
  188. printk("No ramdisk, default root is /dev/sda2\n");
  189. ROOT_DEV = Root_SDA2;
  190. }
  191. fwnmi_init();
  192. /* Find and initialize PCI host bridges */
  193. init_pci_config_tokens();
  194. eeh_init();
  195. find_and_init_phbs();
  196. #ifdef CONFIG_DUMMY_CONSOLE
  197. conswitchp = &dummy_con;
  198. #endif
  199. pSeries_nvram_init();
  200. if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR)
  201. vpa_init(boot_cpuid);
  202. }
  203. static int __init pSeries_init_panel(void)
  204. {
  205. /* Manually leave the kernel version on the panel. */
  206. ppc_md.progress("Linux ppc64\n", 0);
  207. ppc_md.progress(UTS_RELEASE, 0);
  208. return 0;
  209. }
  210. arch_initcall(pSeries_init_panel);
  211. /* Build up the firmware_features bitmask field
  212. * using contents of device-tree/ibm,hypertas-functions.
  213. * Ultimately this functionality may be moved into prom.c prom_init().
  214. */
  215. void __init fw_feature_init(void)
  216. {
  217. struct device_node * dn;
  218. char * hypertas;
  219. unsigned int len;
  220. DBG(" -> fw_feature_init()\n");
  221. cur_cpu_spec->firmware_features = 0;
  222. dn = of_find_node_by_path("/rtas");
  223. if (dn == NULL) {
  224. printk(KERN_ERR "WARNING ! Cannot find RTAS in device-tree !\n");
  225. goto no_rtas;
  226. }
  227. hypertas = get_property(dn, "ibm,hypertas-functions", &len);
  228. if (hypertas) {
  229. while (len > 0){
  230. int i, hypertas_len;
  231. /* check value against table of strings */
  232. for(i=0; i < FIRMWARE_MAX_FEATURES ;i++) {
  233. if ((firmware_features_table[i].name) &&
  234. (strcmp(firmware_features_table[i].name,hypertas))==0) {
  235. /* we have a match */
  236. cur_cpu_spec->firmware_features |=
  237. (firmware_features_table[i].val);
  238. break;
  239. }
  240. }
  241. hypertas_len = strlen(hypertas);
  242. len -= hypertas_len +1;
  243. hypertas+= hypertas_len +1;
  244. }
  245. }
  246. of_node_put(dn);
  247. no_rtas:
  248. printk(KERN_INFO "firmware_features = 0x%lx\n",
  249. cur_cpu_spec->firmware_features);
  250. DBG(" <- fw_feature_init()\n");
  251. }
  252. static void __init pSeries_discover_pic(void)
  253. {
  254. struct device_node *np;
  255. char *typep;
  256. /*
  257. * Setup interrupt mapping options that are needed for finish_device_tree
  258. * to properly parse the OF interrupt tree & do the virtual irq mapping
  259. */
  260. __irq_offset_value = NUM_ISA_INTERRUPTS;
  261. ppc64_interrupt_controller = IC_INVALID;
  262. for (np = NULL; (np = of_find_node_by_name(np, "interrupt-controller"));) {
  263. typep = (char *)get_property(np, "compatible", NULL);
  264. if (strstr(typep, "open-pic"))
  265. ppc64_interrupt_controller = IC_OPEN_PIC;
  266. else if (strstr(typep, "ppc-xicp"))
  267. ppc64_interrupt_controller = IC_PPC_XIC;
  268. else
  269. printk("pSeries_discover_pic: failed to recognize"
  270. " interrupt-controller\n");
  271. break;
  272. }
  273. }
  274. static void pSeries_mach_cpu_die(void)
  275. {
  276. local_irq_disable();
  277. idle_task_exit();
  278. /* Some hardware requires clearing the CPPR, while other hardware does not
  279. * it is safe either way
  280. */
  281. pSeriesLP_cppr_info(0, 0);
  282. rtas_stop_self();
  283. /* Should never get here... */
  284. BUG();
  285. for(;;);
  286. }
  287. /*
  288. * Early initialization. Relocation is on but do not reference unbolted pages
  289. */
  290. static void __init pSeries_init_early(void)
  291. {
  292. void *comport;
  293. int iommu_off = 0;
  294. unsigned int default_speed;
  295. u64 physport;
  296. DBG(" -> pSeries_init_early()\n");
  297. fw_feature_init();
  298. if (systemcfg->platform & PLATFORM_LPAR)
  299. hpte_init_lpar();
  300. else {
  301. hpte_init_native();
  302. iommu_off = (of_chosen &&
  303. get_property(of_chosen, "linux,iommu-off", NULL));
  304. }
  305. generic_find_legacy_serial_ports(&physport, &default_speed);
  306. if (systemcfg->platform & PLATFORM_LPAR)
  307. find_udbg_vterm();
  308. else if (physport) {
  309. /* Map the uart for udbg. */
  310. comport = (void *)ioremap(physport, 16);
  311. udbg_init_uart(comport, default_speed);
  312. ppc_md.udbg_putc = udbg_putc;
  313. ppc_md.udbg_getc = udbg_getc;
  314. ppc_md.udbg_getc_poll = udbg_getc_poll;
  315. DBG("Hello World !\n");
  316. }
  317. iommu_init_early_pSeries();
  318. pSeries_discover_pic();
  319. DBG(" <- pSeries_init_early()\n");
  320. }
  321. static void pSeries_progress(char *s, unsigned short hex)
  322. {
  323. struct device_node *root;
  324. int width, *p;
  325. char *os;
  326. static int display_character, set_indicator;
  327. static int max_width;
  328. static DEFINE_SPINLOCK(progress_lock);
  329. static int pending_newline = 0; /* did last write end with unprinted newline? */
  330. if (!rtas.base)
  331. return;
  332. if (max_width == 0) {
  333. if ((root = find_path_device("/rtas")) &&
  334. (p = (unsigned int *)get_property(root,
  335. "ibm,display-line-length",
  336. NULL)))
  337. max_width = *p;
  338. else
  339. max_width = 0x10;
  340. display_character = rtas_token("display-character");
  341. set_indicator = rtas_token("set-indicator");
  342. }
  343. if (display_character == RTAS_UNKNOWN_SERVICE) {
  344. /* use hex display if available */
  345. if (set_indicator != RTAS_UNKNOWN_SERVICE)
  346. rtas_call(set_indicator, 3, 1, NULL, 6, 0, hex);
  347. return;
  348. }
  349. spin_lock(&progress_lock);
  350. /*
  351. * Last write ended with newline, but we didn't print it since
  352. * it would just clear the bottom line of output. Print it now
  353. * instead.
  354. *
  355. * If no newline is pending, print a CR to start output at the
  356. * beginning of the line.
  357. */
  358. if (pending_newline) {
  359. rtas_call(display_character, 1, 1, NULL, '\r');
  360. rtas_call(display_character, 1, 1, NULL, '\n');
  361. pending_newline = 0;
  362. } else {
  363. rtas_call(display_character, 1, 1, NULL, '\r');
  364. }
  365. width = max_width;
  366. os = s;
  367. while (*os) {
  368. if (*os == '\n' || *os == '\r') {
  369. /* Blank to end of line. */
  370. while (width-- > 0)
  371. rtas_call(display_character, 1, 1, NULL, ' ');
  372. /* If newline is the last character, save it
  373. * until next call to avoid bumping up the
  374. * display output.
  375. */
  376. if (*os == '\n' && !os[1]) {
  377. pending_newline = 1;
  378. spin_unlock(&progress_lock);
  379. return;
  380. }
  381. /* RTAS wants CR-LF, not just LF */
  382. if (*os == '\n') {
  383. rtas_call(display_character, 1, 1, NULL, '\r');
  384. rtas_call(display_character, 1, 1, NULL, '\n');
  385. } else {
  386. /* CR might be used to re-draw a line, so we'll
  387. * leave it alone and not add LF.
  388. */
  389. rtas_call(display_character, 1, 1, NULL, *os);
  390. }
  391. width = max_width;
  392. } else {
  393. width--;
  394. rtas_call(display_character, 1, 1, NULL, *os);
  395. }
  396. os++;
  397. /* if we overwrite the screen length */
  398. if (width <= 0)
  399. while ((*os != 0) && (*os != '\n') && (*os != '\r'))
  400. os++;
  401. }
  402. /* Blank to end of line. */
  403. while (width-- > 0)
  404. rtas_call(display_character, 1, 1, NULL, ' ');
  405. spin_unlock(&progress_lock);
  406. }
  407. extern void setup_default_decr(void);
  408. /* Some sane defaults: 125 MHz timebase, 1GHz processor */
  409. #define DEFAULT_TB_FREQ 125000000UL
  410. #define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8)
  411. static void __init pSeries_calibrate_decr(void)
  412. {
  413. struct device_node *cpu;
  414. struct div_result divres;
  415. unsigned int *fp;
  416. int node_found;
  417. /*
  418. * The cpu node should have a timebase-frequency property
  419. * to tell us the rate at which the decrementer counts.
  420. */
  421. cpu = of_find_node_by_type(NULL, "cpu");
  422. ppc_tb_freq = DEFAULT_TB_FREQ; /* hardcoded default */
  423. node_found = 0;
  424. if (cpu != 0) {
  425. fp = (unsigned int *)get_property(cpu, "timebase-frequency",
  426. NULL);
  427. if (fp != 0) {
  428. node_found = 1;
  429. ppc_tb_freq = *fp;
  430. }
  431. }
  432. if (!node_found)
  433. printk(KERN_ERR "WARNING: Estimating decrementer frequency "
  434. "(not found)\n");
  435. ppc_proc_freq = DEFAULT_PROC_FREQ;
  436. node_found = 0;
  437. if (cpu != 0) {
  438. fp = (unsigned int *)get_property(cpu, "clock-frequency",
  439. NULL);
  440. if (fp != 0) {
  441. node_found = 1;
  442. ppc_proc_freq = *fp;
  443. }
  444. }
  445. if (!node_found)
  446. printk(KERN_ERR "WARNING: Estimating processor frequency "
  447. "(not found)\n");
  448. of_node_put(cpu);
  449. printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
  450. ppc_tb_freq/1000000, ppc_tb_freq%1000000);
  451. printk(KERN_INFO "time_init: processor frequency = %lu.%.6lu MHz\n",
  452. ppc_proc_freq/1000000, ppc_proc_freq%1000000);
  453. tb_ticks_per_jiffy = ppc_tb_freq / HZ;
  454. tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
  455. tb_ticks_per_usec = ppc_tb_freq / 1000000;
  456. tb_to_us = mulhwu_scale_factor(ppc_tb_freq, 1000000);
  457. div128_by_32(1024*1024, 0, tb_ticks_per_sec, &divres);
  458. tb_to_xs = divres.result_low;
  459. setup_default_decr();
  460. }
  461. static int pSeries_check_legacy_ioport(unsigned int baseport)
  462. {
  463. struct device_node *np;
  464. #define I8042_DATA_REG 0x60
  465. #define FDC_BASE 0x3f0
  466. switch(baseport) {
  467. case I8042_DATA_REG:
  468. np = of_find_node_by_type(NULL, "8042");
  469. if (np == NULL)
  470. return -ENODEV;
  471. of_node_put(np);
  472. break;
  473. case FDC_BASE:
  474. np = of_find_node_by_type(NULL, "fdc");
  475. if (np == NULL)
  476. return -ENODEV;
  477. of_node_put(np);
  478. break;
  479. }
  480. return 0;
  481. }
  482. /*
  483. * Called very early, MMU is off, device-tree isn't unflattened
  484. */
  485. extern struct machdep_calls pSeries_md;
  486. static int __init pSeries_probe(int platform)
  487. {
  488. if (platform != PLATFORM_PSERIES &&
  489. platform != PLATFORM_PSERIES_LPAR)
  490. return 0;
  491. /* if we have some ppc_md fixups for LPAR to do, do
  492. * it here ...
  493. */
  494. return 1;
  495. }
  496. struct machdep_calls __initdata pSeries_md = {
  497. .probe = pSeries_probe,
  498. .setup_arch = pSeries_setup_arch,
  499. .init_early = pSeries_init_early,
  500. .get_cpuinfo = pSeries_get_cpuinfo,
  501. .log_error = pSeries_log_error,
  502. .pcibios_fixup = pSeries_final_fixup,
  503. .restart = rtas_restart,
  504. .power_off = rtas_power_off,
  505. .halt = rtas_halt,
  506. .panic = rtas_os_term,
  507. .cpu_die = pSeries_mach_cpu_die,
  508. .get_boot_time = pSeries_get_boot_time,
  509. .get_rtc_time = pSeries_get_rtc_time,
  510. .set_rtc_time = pSeries_set_rtc_time,
  511. .calibrate_decr = pSeries_calibrate_decr,
  512. .progress = pSeries_progress,
  513. .check_legacy_ioport = pSeries_check_legacy_ioport,
  514. .system_reset_exception = pSeries_system_reset_exception,
  515. .machine_check_exception = pSeries_machine_check_exception,
  516. };