pSeries_setup.c 11 KB

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