pSeries_setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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 void pSeries_system_reset_exception(struct pt_regs *regs);
  78. extern int pSeries_machine_check_exception(struct pt_regs *regs);
  79. static volatile void __iomem * chrp_int_ack_special;
  80. struct mpic *pSeries_mpic;
  81. void pSeries_get_cpuinfo(struct seq_file *m)
  82. {
  83. struct device_node *root;
  84. const char *model = "";
  85. root = of_find_node_by_path("/");
  86. if (root)
  87. model = get_property(root, "model", NULL);
  88. seq_printf(m, "machine\t\t: CHRP %s\n", model);
  89. of_node_put(root);
  90. }
  91. /* Initialize firmware assisted non-maskable interrupts if
  92. * the firmware supports this feature.
  93. *
  94. */
  95. static void __init fwnmi_init(void)
  96. {
  97. int ret;
  98. int ibm_nmi_register = rtas_token("ibm,nmi-register");
  99. if (ibm_nmi_register == RTAS_UNKNOWN_SERVICE)
  100. return;
  101. ret = rtas_call(ibm_nmi_register, 2, 1, NULL,
  102. __pa((unsigned long)system_reset_fwnmi),
  103. __pa((unsigned long)machine_check_fwnmi));
  104. if (ret == 0)
  105. fwnmi_active = 1;
  106. }
  107. static int pSeries_irq_cascade(struct pt_regs *regs, void *data)
  108. {
  109. if (chrp_int_ack_special)
  110. return readb(chrp_int_ack_special);
  111. else
  112. return i8259_irq(smp_processor_id());
  113. }
  114. static void __init pSeries_init_mpic(void)
  115. {
  116. unsigned int *addrp;
  117. struct device_node *np;
  118. int i;
  119. /* All ISUs are setup, complete initialization */
  120. mpic_init(pSeries_mpic);
  121. /* Check what kind of cascade ACK we have */
  122. if (!(np = of_find_node_by_name(NULL, "pci"))
  123. || !(addrp = (unsigned int *)
  124. get_property(np, "8259-interrupt-acknowledge", NULL)))
  125. printk(KERN_ERR "Cannot find pci to get ack address\n");
  126. else
  127. chrp_int_ack_special = ioremap(addrp[prom_n_addr_cells(np)-1], 1);
  128. of_node_put(np);
  129. /* Setup the legacy interrupts & controller */
  130. for (i = 0; i < NUM_ISA_INTERRUPTS; i++)
  131. irq_desc[i].handler = &i8259_pic;
  132. i8259_init(0);
  133. /* Hook cascade to mpic */
  134. mpic_setup_cascade(NUM_ISA_INTERRUPTS, pSeries_irq_cascade, NULL);
  135. }
  136. static void __init pSeries_setup_mpic(void)
  137. {
  138. unsigned int *opprop;
  139. unsigned long openpic_addr = 0;
  140. unsigned char senses[NR_IRQS - NUM_ISA_INTERRUPTS];
  141. struct device_node *root;
  142. int irq_count;
  143. /* Find the Open PIC if present */
  144. root = of_find_node_by_path("/");
  145. opprop = (unsigned int *) get_property(root, "platform-open-pic", NULL);
  146. if (opprop != 0) {
  147. int n = prom_n_addr_cells(root);
  148. for (openpic_addr = 0; n > 0; --n)
  149. openpic_addr = (openpic_addr << 32) + *opprop++;
  150. printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
  151. }
  152. of_node_put(root);
  153. BUG_ON(openpic_addr == 0);
  154. /* Get the sense values from OF */
  155. prom_get_irq_senses(senses, NUM_ISA_INTERRUPTS, NR_IRQS);
  156. /* Setup the openpic driver */
  157. irq_count = NR_IRQS - NUM_ISA_INTERRUPTS - 4; /* leave room for IPIs */
  158. pSeries_mpic = mpic_alloc(openpic_addr, MPIC_PRIMARY,
  159. 16, 16, irq_count, /* isu size, irq offset, irq count */
  160. NR_IRQS - 4, /* ipi offset */
  161. senses, irq_count, /* sense & sense size */
  162. " MPIC ");
  163. }
  164. static void __init pSeries_setup_arch(void)
  165. {
  166. /* Fixup ppc_md depending on the type of interrupt controller */
  167. if (ppc64_interrupt_controller == IC_OPEN_PIC) {
  168. ppc_md.init_IRQ = pSeries_init_mpic;
  169. ppc_md.get_irq = mpic_get_irq;
  170. /* Allocate the mpic now, so that find_and_init_phbs() can
  171. * fill the ISUs */
  172. pSeries_setup_mpic();
  173. } else {
  174. ppc_md.init_IRQ = xics_init_IRQ;
  175. ppc_md.get_irq = xics_get_irq;
  176. }
  177. #ifdef CONFIG_SMP
  178. smp_init_pSeries();
  179. #endif
  180. /* openpic global configuration register (64-bit format). */
  181. /* openpic Interrupt Source Unit pointer (64-bit format). */
  182. /* python0 facility area (mmio) (64-bit format) REAL address. */
  183. /* init to some ~sane value until calibrate_delay() runs */
  184. loops_per_jiffy = 50000000;
  185. if (ROOT_DEV == 0) {
  186. printk("No ramdisk, default root is /dev/sda2\n");
  187. ROOT_DEV = Root_SDA2;
  188. }
  189. fwnmi_init();
  190. /* Find and initialize PCI host bridges */
  191. init_pci_config_tokens();
  192. eeh_init();
  193. find_and_init_phbs();
  194. #ifdef CONFIG_DUMMY_CONSOLE
  195. conswitchp = &dummy_con;
  196. #endif
  197. pSeries_nvram_init();
  198. if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR)
  199. vpa_init(boot_cpuid);
  200. }
  201. static int __init pSeries_init_panel(void)
  202. {
  203. /* Manually leave the kernel version on the panel. */
  204. ppc_md.progress("Linux ppc64\n", 0);
  205. ppc_md.progress(UTS_RELEASE, 0);
  206. return 0;
  207. }
  208. arch_initcall(pSeries_init_panel);
  209. /* Build up the firmware_features bitmask field
  210. * using contents of device-tree/ibm,hypertas-functions.
  211. * Ultimately this functionality may be moved into prom.c prom_init().
  212. */
  213. void __init fw_feature_init(void)
  214. {
  215. struct device_node * dn;
  216. char * hypertas;
  217. unsigned int len;
  218. DBG(" -> fw_feature_init()\n");
  219. cur_cpu_spec->firmware_features = 0;
  220. dn = of_find_node_by_path("/rtas");
  221. if (dn == NULL) {
  222. printk(KERN_ERR "WARNING ! Cannot find RTAS in device-tree !\n");
  223. goto no_rtas;
  224. }
  225. hypertas = get_property(dn, "ibm,hypertas-functions", &len);
  226. if (hypertas) {
  227. while (len > 0){
  228. int i, hypertas_len;
  229. /* check value against table of strings */
  230. for(i=0; i < FIRMWARE_MAX_FEATURES ;i++) {
  231. if ((firmware_features_table[i].name) &&
  232. (strcmp(firmware_features_table[i].name,hypertas))==0) {
  233. /* we have a match */
  234. cur_cpu_spec->firmware_features |=
  235. (firmware_features_table[i].val);
  236. break;
  237. }
  238. }
  239. hypertas_len = strlen(hypertas);
  240. len -= hypertas_len +1;
  241. hypertas+= hypertas_len +1;
  242. }
  243. }
  244. of_node_put(dn);
  245. no_rtas:
  246. printk(KERN_INFO "firmware_features = 0x%lx\n",
  247. cur_cpu_spec->firmware_features);
  248. DBG(" <- fw_feature_init()\n");
  249. }
  250. static void __init pSeries_discover_pic(void)
  251. {
  252. struct device_node *np;
  253. char *typep;
  254. /*
  255. * Setup interrupt mapping options that are needed for finish_device_tree
  256. * to properly parse the OF interrupt tree & do the virtual irq mapping
  257. */
  258. __irq_offset_value = NUM_ISA_INTERRUPTS;
  259. ppc64_interrupt_controller = IC_INVALID;
  260. for (np = NULL; (np = of_find_node_by_name(np, "interrupt-controller"));) {
  261. typep = (char *)get_property(np, "compatible", NULL);
  262. if (strstr(typep, "open-pic"))
  263. ppc64_interrupt_controller = IC_OPEN_PIC;
  264. else if (strstr(typep, "ppc-xicp"))
  265. ppc64_interrupt_controller = IC_PPC_XIC;
  266. else
  267. printk("pSeries_discover_pic: failed to recognize"
  268. " interrupt-controller\n");
  269. break;
  270. }
  271. }
  272. static void pSeries_mach_cpu_die(void)
  273. {
  274. local_irq_disable();
  275. idle_task_exit();
  276. /* Some hardware requires clearing the CPPR, while other hardware does not
  277. * it is safe either way
  278. */
  279. pSeriesLP_cppr_info(0, 0);
  280. rtas_stop_self();
  281. /* Should never get here... */
  282. BUG();
  283. for(;;);
  284. }
  285. /*
  286. * Early initialization. Relocation is on but do not reference unbolted pages
  287. */
  288. static void __init pSeries_init_early(void)
  289. {
  290. void *comport;
  291. int iommu_off = 0;
  292. unsigned int default_speed;
  293. u64 physport;
  294. DBG(" -> pSeries_init_early()\n");
  295. fw_feature_init();
  296. if (systemcfg->platform & PLATFORM_LPAR)
  297. hpte_init_lpar();
  298. else {
  299. hpte_init_native();
  300. iommu_off = (of_chosen &&
  301. get_property(of_chosen, "linux,iommu-off", NULL));
  302. }
  303. generic_find_legacy_serial_ports(&physport, &default_speed);
  304. if (systemcfg->platform & PLATFORM_LPAR)
  305. find_udbg_vterm();
  306. else if (physport) {
  307. /* Map the uart for udbg. */
  308. comport = (void *)ioremap(physport, 16);
  309. udbg_init_uart(comport, default_speed);
  310. ppc_md.udbg_putc = udbg_putc;
  311. ppc_md.udbg_getc = udbg_getc;
  312. ppc_md.udbg_getc_poll = udbg_getc_poll;
  313. DBG("Hello World !\n");
  314. }
  315. iommu_init_early_pSeries();
  316. pSeries_discover_pic();
  317. DBG(" <- pSeries_init_early()\n");
  318. }
  319. static void pSeries_progress(char *s, unsigned short hex)
  320. {
  321. struct device_node *root;
  322. int width, *p;
  323. char *os;
  324. static int display_character, set_indicator;
  325. static int max_width;
  326. static DEFINE_SPINLOCK(progress_lock);
  327. static int pending_newline = 0; /* did last write end with unprinted newline? */
  328. if (!rtas.base)
  329. return;
  330. if (max_width == 0) {
  331. if ((root = find_path_device("/rtas")) &&
  332. (p = (unsigned int *)get_property(root,
  333. "ibm,display-line-length",
  334. NULL)))
  335. max_width = *p;
  336. else
  337. max_width = 0x10;
  338. display_character = rtas_token("display-character");
  339. set_indicator = rtas_token("set-indicator");
  340. }
  341. if (display_character == RTAS_UNKNOWN_SERVICE) {
  342. /* use hex display if available */
  343. if (set_indicator != RTAS_UNKNOWN_SERVICE)
  344. rtas_call(set_indicator, 3, 1, NULL, 6, 0, hex);
  345. return;
  346. }
  347. spin_lock(&progress_lock);
  348. /*
  349. * Last write ended with newline, but we didn't print it since
  350. * it would just clear the bottom line of output. Print it now
  351. * instead.
  352. *
  353. * If no newline is pending, print a CR to start output at the
  354. * beginning of the line.
  355. */
  356. if (pending_newline) {
  357. rtas_call(display_character, 1, 1, NULL, '\r');
  358. rtas_call(display_character, 1, 1, NULL, '\n');
  359. pending_newline = 0;
  360. } else {
  361. rtas_call(display_character, 1, 1, NULL, '\r');
  362. }
  363. width = max_width;
  364. os = s;
  365. while (*os) {
  366. if (*os == '\n' || *os == '\r') {
  367. /* Blank to end of line. */
  368. while (width-- > 0)
  369. rtas_call(display_character, 1, 1, NULL, ' ');
  370. /* If newline is the last character, save it
  371. * until next call to avoid bumping up the
  372. * display output.
  373. */
  374. if (*os == '\n' && !os[1]) {
  375. pending_newline = 1;
  376. spin_unlock(&progress_lock);
  377. return;
  378. }
  379. /* RTAS wants CR-LF, not just LF */
  380. if (*os == '\n') {
  381. rtas_call(display_character, 1, 1, NULL, '\r');
  382. rtas_call(display_character, 1, 1, NULL, '\n');
  383. } else {
  384. /* CR might be used to re-draw a line, so we'll
  385. * leave it alone and not add LF.
  386. */
  387. rtas_call(display_character, 1, 1, NULL, *os);
  388. }
  389. width = max_width;
  390. } else {
  391. width--;
  392. rtas_call(display_character, 1, 1, NULL, *os);
  393. }
  394. os++;
  395. /* if we overwrite the screen length */
  396. if (width <= 0)
  397. while ((*os != 0) && (*os != '\n') && (*os != '\r'))
  398. os++;
  399. }
  400. /* Blank to end of line. */
  401. while (width-- > 0)
  402. rtas_call(display_character, 1, 1, NULL, ' ');
  403. spin_unlock(&progress_lock);
  404. }
  405. static int pSeries_check_legacy_ioport(unsigned int baseport)
  406. {
  407. struct device_node *np;
  408. #define I8042_DATA_REG 0x60
  409. #define FDC_BASE 0x3f0
  410. switch(baseport) {
  411. case I8042_DATA_REG:
  412. np = of_find_node_by_type(NULL, "8042");
  413. if (np == NULL)
  414. return -ENODEV;
  415. of_node_put(np);
  416. break;
  417. case FDC_BASE:
  418. np = of_find_node_by_type(NULL, "fdc");
  419. if (np == NULL)
  420. return -ENODEV;
  421. of_node_put(np);
  422. break;
  423. }
  424. return 0;
  425. }
  426. /*
  427. * Called very early, MMU is off, device-tree isn't unflattened
  428. */
  429. extern struct machdep_calls pSeries_md;
  430. static int __init pSeries_probe(int platform)
  431. {
  432. if (platform != PLATFORM_PSERIES &&
  433. platform != PLATFORM_PSERIES_LPAR)
  434. return 0;
  435. /* if we have some ppc_md fixups for LPAR to do, do
  436. * it here ...
  437. */
  438. return 1;
  439. }
  440. struct machdep_calls __initdata pSeries_md = {
  441. .probe = pSeries_probe,
  442. .setup_arch = pSeries_setup_arch,
  443. .init_early = pSeries_init_early,
  444. .get_cpuinfo = pSeries_get_cpuinfo,
  445. .log_error = pSeries_log_error,
  446. .pcibios_fixup = pSeries_final_fixup,
  447. .restart = rtas_restart,
  448. .power_off = rtas_power_off,
  449. .halt = rtas_halt,
  450. .panic = rtas_os_term,
  451. .cpu_die = pSeries_mach_cpu_die,
  452. .get_boot_time = pSeries_get_boot_time,
  453. .get_rtc_time = pSeries_get_rtc_time,
  454. .set_rtc_time = pSeries_set_rtc_time,
  455. .calibrate_decr = generic_calibrate_decr,
  456. .progress = pSeries_progress,
  457. .check_legacy_ioport = pSeries_check_legacy_ioport,
  458. .system_reset_exception = pSeries_system_reset_exception,
  459. .machine_check_exception = pSeries_machine_check_exception,
  460. };