pSeries_setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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 find_udbg_vterm(void);
  69. extern void system_reset_fwnmi(void); /* from head.S */
  70. extern void machine_check_fwnmi(void); /* from head.S */
  71. extern void generic_find_legacy_serial_ports(u64 *physport,
  72. unsigned int *default_speed);
  73. int fwnmi_active; /* TRUE if an FWNMI handler is present */
  74. extern void pSeries_system_reset_exception(struct pt_regs *regs);
  75. extern int pSeries_machine_check_exception(struct pt_regs *regs);
  76. static volatile void __iomem * chrp_int_ack_special;
  77. struct mpic *pSeries_mpic;
  78. void pSeries_get_cpuinfo(struct seq_file *m)
  79. {
  80. struct device_node *root;
  81. const char *model = "";
  82. root = of_find_node_by_path("/");
  83. if (root)
  84. model = get_property(root, "model", NULL);
  85. seq_printf(m, "machine\t\t: CHRP %s\n", model);
  86. of_node_put(root);
  87. }
  88. /* Initialize firmware assisted non-maskable interrupts if
  89. * the firmware supports this feature.
  90. *
  91. */
  92. static void __init fwnmi_init(void)
  93. {
  94. int ret;
  95. int ibm_nmi_register = rtas_token("ibm,nmi-register");
  96. if (ibm_nmi_register == RTAS_UNKNOWN_SERVICE)
  97. return;
  98. ret = rtas_call(ibm_nmi_register, 2, 1, NULL,
  99. __pa((unsigned long)system_reset_fwnmi),
  100. __pa((unsigned long)machine_check_fwnmi));
  101. if (ret == 0)
  102. fwnmi_active = 1;
  103. }
  104. static int pSeries_irq_cascade(struct pt_regs *regs, void *data)
  105. {
  106. if (chrp_int_ack_special)
  107. return readb(chrp_int_ack_special);
  108. else
  109. return i8259_irq(smp_processor_id());
  110. }
  111. static void __init pSeries_init_mpic(void)
  112. {
  113. unsigned int *addrp;
  114. struct device_node *np;
  115. int i;
  116. /* All ISUs are setup, complete initialization */
  117. mpic_init(pSeries_mpic);
  118. /* Check what kind of cascade ACK we have */
  119. if (!(np = of_find_node_by_name(NULL, "pci"))
  120. || !(addrp = (unsigned int *)
  121. get_property(np, "8259-interrupt-acknowledge", NULL)))
  122. printk(KERN_ERR "Cannot find pci to get ack address\n");
  123. else
  124. chrp_int_ack_special = ioremap(addrp[prom_n_addr_cells(np)-1], 1);
  125. of_node_put(np);
  126. /* Setup the legacy interrupts & controller */
  127. for (i = 0; i < NUM_ISA_INTERRUPTS; i++)
  128. irq_desc[i].handler = &i8259_pic;
  129. i8259_init(0);
  130. /* Hook cascade to mpic */
  131. mpic_setup_cascade(NUM_ISA_INTERRUPTS, pSeries_irq_cascade, NULL);
  132. }
  133. static void __init pSeries_setup_mpic(void)
  134. {
  135. unsigned int *opprop;
  136. unsigned long openpic_addr = 0;
  137. unsigned char senses[NR_IRQS - NUM_ISA_INTERRUPTS];
  138. struct device_node *root;
  139. int irq_count;
  140. /* Find the Open PIC if present */
  141. root = of_find_node_by_path("/");
  142. opprop = (unsigned int *) get_property(root, "platform-open-pic", NULL);
  143. if (opprop != 0) {
  144. int n = prom_n_addr_cells(root);
  145. for (openpic_addr = 0; n > 0; --n)
  146. openpic_addr = (openpic_addr << 32) + *opprop++;
  147. printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
  148. }
  149. of_node_put(root);
  150. BUG_ON(openpic_addr == 0);
  151. /* Get the sense values from OF */
  152. prom_get_irq_senses(senses, NUM_ISA_INTERRUPTS, NR_IRQS);
  153. /* Setup the openpic driver */
  154. irq_count = NR_IRQS - NUM_ISA_INTERRUPTS - 4; /* leave room for IPIs */
  155. pSeries_mpic = mpic_alloc(openpic_addr, MPIC_PRIMARY,
  156. 16, 16, irq_count, /* isu size, irq offset, irq count */
  157. NR_IRQS - 4, /* ipi offset */
  158. senses, irq_count, /* sense & sense size */
  159. " MPIC ");
  160. }
  161. static void __init pSeries_setup_arch(void)
  162. {
  163. /* Fixup ppc_md depending on the type of interrupt controller */
  164. if (ppc64_interrupt_controller == IC_OPEN_PIC) {
  165. ppc_md.init_IRQ = pSeries_init_mpic;
  166. ppc_md.get_irq = mpic_get_irq;
  167. /* Allocate the mpic now, so that find_and_init_phbs() can
  168. * fill the ISUs */
  169. pSeries_setup_mpic();
  170. } else {
  171. ppc_md.init_IRQ = xics_init_IRQ;
  172. ppc_md.get_irq = xics_get_irq;
  173. }
  174. #ifdef CONFIG_SMP
  175. smp_init_pSeries();
  176. #endif
  177. /* openpic global configuration register (64-bit format). */
  178. /* openpic Interrupt Source Unit pointer (64-bit format). */
  179. /* python0 facility area (mmio) (64-bit format) REAL address. */
  180. /* init to some ~sane value until calibrate_delay() runs */
  181. loops_per_jiffy = 50000000;
  182. if (ROOT_DEV == 0) {
  183. printk("No ramdisk, default root is /dev/sda2\n");
  184. ROOT_DEV = Root_SDA2;
  185. }
  186. fwnmi_init();
  187. /* Find and initialize PCI host bridges */
  188. init_pci_config_tokens();
  189. eeh_init();
  190. find_and_init_phbs();
  191. #ifdef CONFIG_DUMMY_CONSOLE
  192. conswitchp = &dummy_con;
  193. #endif
  194. pSeries_nvram_init();
  195. if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR)
  196. vpa_init(boot_cpuid);
  197. }
  198. static int __init pSeries_init_panel(void)
  199. {
  200. /* Manually leave the kernel version on the panel. */
  201. ppc_md.progress("Linux ppc64\n", 0);
  202. ppc_md.progress(UTS_RELEASE, 0);
  203. return 0;
  204. }
  205. arch_initcall(pSeries_init_panel);
  206. /* Build up the firmware_features bitmask field
  207. * using contents of device-tree/ibm,hypertas-functions.
  208. * Ultimately this functionality may be moved into prom.c prom_init().
  209. */
  210. void __init fw_feature_init(void)
  211. {
  212. struct device_node * dn;
  213. char * hypertas;
  214. unsigned int len;
  215. DBG(" -> fw_feature_init()\n");
  216. cur_cpu_spec->firmware_features = 0;
  217. dn = of_find_node_by_path("/rtas");
  218. if (dn == NULL) {
  219. printk(KERN_ERR "WARNING ! Cannot find RTAS in device-tree !\n");
  220. goto no_rtas;
  221. }
  222. hypertas = get_property(dn, "ibm,hypertas-functions", &len);
  223. if (hypertas) {
  224. while (len > 0){
  225. int i, hypertas_len;
  226. /* check value against table of strings */
  227. for(i=0; i < FIRMWARE_MAX_FEATURES ;i++) {
  228. if ((firmware_features_table[i].name) &&
  229. (strcmp(firmware_features_table[i].name,hypertas))==0) {
  230. /* we have a match */
  231. cur_cpu_spec->firmware_features |=
  232. (firmware_features_table[i].val);
  233. break;
  234. }
  235. }
  236. hypertas_len = strlen(hypertas);
  237. len -= hypertas_len +1;
  238. hypertas+= hypertas_len +1;
  239. }
  240. }
  241. of_node_put(dn);
  242. no_rtas:
  243. printk(KERN_INFO "firmware_features = 0x%lx\n",
  244. cur_cpu_spec->firmware_features);
  245. DBG(" <- fw_feature_init()\n");
  246. }
  247. static void __init pSeries_discover_pic(void)
  248. {
  249. struct device_node *np;
  250. char *typep;
  251. /*
  252. * Setup interrupt mapping options that are needed for finish_device_tree
  253. * to properly parse the OF interrupt tree & do the virtual irq mapping
  254. */
  255. __irq_offset_value = NUM_ISA_INTERRUPTS;
  256. ppc64_interrupt_controller = IC_INVALID;
  257. for (np = NULL; (np = of_find_node_by_name(np, "interrupt-controller"));) {
  258. typep = (char *)get_property(np, "compatible", NULL);
  259. if (strstr(typep, "open-pic"))
  260. ppc64_interrupt_controller = IC_OPEN_PIC;
  261. else if (strstr(typep, "ppc-xicp"))
  262. ppc64_interrupt_controller = IC_PPC_XIC;
  263. else
  264. printk("pSeries_discover_pic: failed to recognize"
  265. " interrupt-controller\n");
  266. break;
  267. }
  268. }
  269. static void pSeries_mach_cpu_die(void)
  270. {
  271. local_irq_disable();
  272. idle_task_exit();
  273. /* Some hardware requires clearing the CPPR, while other hardware does not
  274. * it is safe either way
  275. */
  276. pSeriesLP_cppr_info(0, 0);
  277. rtas_stop_self();
  278. /* Should never get here... */
  279. BUG();
  280. for(;;);
  281. }
  282. /*
  283. * Early initialization. Relocation is on but do not reference unbolted pages
  284. */
  285. static void __init pSeries_init_early(void)
  286. {
  287. void *comport;
  288. int iommu_off = 0;
  289. unsigned int default_speed;
  290. u64 physport;
  291. DBG(" -> pSeries_init_early()\n");
  292. fw_feature_init();
  293. if (systemcfg->platform & PLATFORM_LPAR)
  294. hpte_init_lpar();
  295. else {
  296. hpte_init_native();
  297. iommu_off = (of_chosen &&
  298. get_property(of_chosen, "linux,iommu-off", NULL));
  299. }
  300. generic_find_legacy_serial_ports(&physport, &default_speed);
  301. if (systemcfg->platform & PLATFORM_LPAR)
  302. find_udbg_vterm();
  303. else if (physport) {
  304. /* Map the uart for udbg. */
  305. comport = (void *)ioremap(physport, 16);
  306. udbg_init_uart(comport, default_speed);
  307. ppc_md.udbg_putc = udbg_putc;
  308. ppc_md.udbg_getc = udbg_getc;
  309. ppc_md.udbg_getc_poll = udbg_getc_poll;
  310. DBG("Hello World !\n");
  311. }
  312. iommu_init_early_pSeries();
  313. pSeries_discover_pic();
  314. DBG(" <- pSeries_init_early()\n");
  315. }
  316. static int pSeries_check_legacy_ioport(unsigned int baseport)
  317. {
  318. struct device_node *np;
  319. #define I8042_DATA_REG 0x60
  320. #define FDC_BASE 0x3f0
  321. switch(baseport) {
  322. case I8042_DATA_REG:
  323. np = of_find_node_by_type(NULL, "8042");
  324. if (np == NULL)
  325. return -ENODEV;
  326. of_node_put(np);
  327. break;
  328. case FDC_BASE:
  329. np = of_find_node_by_type(NULL, "fdc");
  330. if (np == NULL)
  331. return -ENODEV;
  332. of_node_put(np);
  333. break;
  334. }
  335. return 0;
  336. }
  337. /*
  338. * Called very early, MMU is off, device-tree isn't unflattened
  339. */
  340. extern struct machdep_calls pSeries_md;
  341. static int __init pSeries_probe(int platform)
  342. {
  343. if (platform != PLATFORM_PSERIES &&
  344. platform != PLATFORM_PSERIES_LPAR)
  345. return 0;
  346. /* if we have some ppc_md fixups for LPAR to do, do
  347. * it here ...
  348. */
  349. return 1;
  350. }
  351. struct machdep_calls __initdata pSeries_md = {
  352. .probe = pSeries_probe,
  353. .setup_arch = pSeries_setup_arch,
  354. .init_early = pSeries_init_early,
  355. .get_cpuinfo = pSeries_get_cpuinfo,
  356. .log_error = pSeries_log_error,
  357. .pcibios_fixup = pSeries_final_fixup,
  358. .restart = rtas_restart,
  359. .power_off = rtas_power_off,
  360. .halt = rtas_halt,
  361. .panic = rtas_os_term,
  362. .cpu_die = pSeries_mach_cpu_die,
  363. .get_boot_time = rtas_get_boot_time,
  364. .get_rtc_time = rtas_get_rtc_time,
  365. .set_rtc_time = rtas_set_rtc_time,
  366. .calibrate_decr = generic_calibrate_decr,
  367. .progress = rtas_progress,
  368. .check_legacy_ioport = pSeries_check_legacy_ioport,
  369. .system_reset_exception = pSeries_system_reset_exception,
  370. .machine_check_exception = pSeries_machine_check_exception,
  371. };