pSeries_setup.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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/cpu.h>
  20. #include <linux/errno.h>
  21. #include <linux/sched.h>
  22. #include <linux/kernel.h>
  23. #include <linux/mm.h>
  24. #include <linux/stddef.h>
  25. #include <linux/unistd.h>
  26. #include <linux/slab.h>
  27. #include <linux/user.h>
  28. #include <linux/a.out.h>
  29. #include <linux/tty.h>
  30. #include <linux/major.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/reboot.h>
  33. #include <linux/init.h>
  34. #include <linux/ioport.h>
  35. #include <linux/console.h>
  36. #include <linux/pci.h>
  37. #include <linux/version.h>
  38. #include <linux/adb.h>
  39. #include <linux/module.h>
  40. #include <linux/delay.h>
  41. #include <linux/irq.h>
  42. #include <linux/seq_file.h>
  43. #include <linux/root_dev.h>
  44. #include <asm/mmu.h>
  45. #include <asm/processor.h>
  46. #include <asm/io.h>
  47. #include <asm/pgtable.h>
  48. #include <asm/prom.h>
  49. #include <asm/rtas.h>
  50. #include <asm/pci-bridge.h>
  51. #include <asm/iommu.h>
  52. #include <asm/dma.h>
  53. #include <asm/machdep.h>
  54. #include <asm/irq.h>
  55. #include <asm/time.h>
  56. #include <asm/nvram.h>
  57. #include <asm/plpar_wrappers.h>
  58. #include <asm/xics.h>
  59. #include <asm/firmware.h>
  60. #include "i8259.h"
  61. #include "mpic.h"
  62. #include "pci.h"
  63. #ifdef DEBUG
  64. #define DBG(fmt...) udbg_printf(fmt)
  65. #else
  66. #define DBG(fmt...)
  67. #endif
  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 int pseries_shared_idle(void);
  77. static int pseries_dedicated_idle(void);
  78. static volatile void __iomem * chrp_int_ack_special;
  79. struct mpic *pSeries_mpic;
  80. void pSeries_get_cpuinfo(struct seq_file *m)
  81. {
  82. struct device_node *root;
  83. const char *model = "";
  84. root = of_find_node_by_path("/");
  85. if (root)
  86. model = get_property(root, "model", NULL);
  87. seq_printf(m, "machine\t\t: CHRP %s\n", model);
  88. of_node_put(root);
  89. }
  90. /* Initialize firmware assisted non-maskable interrupts if
  91. * the firmware supports this feature.
  92. *
  93. */
  94. static void __init fwnmi_init(void)
  95. {
  96. int ret;
  97. int ibm_nmi_register = rtas_token("ibm,nmi-register");
  98. if (ibm_nmi_register == RTAS_UNKNOWN_SERVICE)
  99. return;
  100. ret = rtas_call(ibm_nmi_register, 2, 1, NULL,
  101. __pa((unsigned long)system_reset_fwnmi),
  102. __pa((unsigned long)machine_check_fwnmi));
  103. if (ret == 0)
  104. fwnmi_active = 1;
  105. }
  106. static int pSeries_irq_cascade(struct pt_regs *regs, void *data)
  107. {
  108. if (chrp_int_ack_special)
  109. return readb(chrp_int_ack_special);
  110. else
  111. return i8259_irq(smp_processor_id());
  112. }
  113. static void __init pSeries_init_mpic(void)
  114. {
  115. unsigned int *addrp;
  116. struct device_node *np;
  117. int i;
  118. /* All ISUs are setup, complete initialization */
  119. mpic_init(pSeries_mpic);
  120. /* Check what kind of cascade ACK we have */
  121. if (!(np = of_find_node_by_name(NULL, "pci"))
  122. || !(addrp = (unsigned int *)
  123. get_property(np, "8259-interrupt-acknowledge", NULL)))
  124. printk(KERN_ERR "Cannot find pci to get ack address\n");
  125. else
  126. chrp_int_ack_special = ioremap(addrp[prom_n_addr_cells(np)-1], 1);
  127. of_node_put(np);
  128. /* Setup the legacy interrupts & controller */
  129. for (i = 0; i < NUM_ISA_INTERRUPTS; i++)
  130. irq_desc[i].handler = &i8259_pic;
  131. i8259_init(0);
  132. /* Hook cascade to mpic */
  133. mpic_setup_cascade(NUM_ISA_INTERRUPTS, pSeries_irq_cascade, NULL);
  134. }
  135. static void __init pSeries_setup_mpic(void)
  136. {
  137. unsigned int *opprop;
  138. unsigned long openpic_addr = 0;
  139. unsigned char senses[NR_IRQS - NUM_ISA_INTERRUPTS];
  140. struct device_node *root;
  141. int irq_count;
  142. /* Find the Open PIC if present */
  143. root = of_find_node_by_path("/");
  144. opprop = (unsigned int *) get_property(root, "platform-open-pic", NULL);
  145. if (opprop != 0) {
  146. int n = prom_n_addr_cells(root);
  147. for (openpic_addr = 0; n > 0; --n)
  148. openpic_addr = (openpic_addr << 32) + *opprop++;
  149. printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
  150. }
  151. of_node_put(root);
  152. BUG_ON(openpic_addr == 0);
  153. /* Get the sense values from OF */
  154. prom_get_irq_senses(senses, NUM_ISA_INTERRUPTS, NR_IRQS);
  155. /* Setup the openpic driver */
  156. irq_count = NR_IRQS - NUM_ISA_INTERRUPTS - 4; /* leave room for IPIs */
  157. pSeries_mpic = mpic_alloc(openpic_addr, MPIC_PRIMARY,
  158. 16, 16, irq_count, /* isu size, irq offset, irq count */
  159. NR_IRQS - 4, /* ipi offset */
  160. senses, irq_count, /* sense & sense size */
  161. " MPIC ");
  162. }
  163. static void __init pSeries_setup_arch(void)
  164. {
  165. /* Fixup ppc_md depending on the type of interrupt controller */
  166. if (ppc64_interrupt_controller == IC_OPEN_PIC) {
  167. ppc_md.init_IRQ = pSeries_init_mpic;
  168. ppc_md.get_irq = mpic_get_irq;
  169. ppc_md.cpu_irq_down = mpic_teardown_this_cpu;
  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. ppc_md.cpu_irq_down = xics_teardown_cpu;
  177. }
  178. #ifdef CONFIG_SMP
  179. smp_init_pSeries();
  180. #endif
  181. /* openpic global configuration register (64-bit format). */
  182. /* openpic Interrupt Source Unit pointer (64-bit format). */
  183. /* python0 facility area (mmio) (64-bit format) REAL address. */
  184. /* init to some ~sane value until calibrate_delay() runs */
  185. loops_per_jiffy = 50000000;
  186. if (ROOT_DEV == 0) {
  187. printk("No ramdisk, default root is /dev/sda2\n");
  188. ROOT_DEV = Root_SDA2;
  189. }
  190. fwnmi_init();
  191. /* Find and initialize PCI host bridges */
  192. init_pci_config_tokens();
  193. eeh_init();
  194. find_and_init_phbs();
  195. #ifdef CONFIG_DUMMY_CONSOLE
  196. conswitchp = &dummy_con;
  197. #endif
  198. pSeries_nvram_init();
  199. /* Choose an idle loop */
  200. if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
  201. vpa_init(boot_cpuid);
  202. if (get_paca()->lppaca.shared_proc) {
  203. printk(KERN_INFO "Using shared processor idle loop\n");
  204. ppc_md.idle_loop = pseries_shared_idle;
  205. } else {
  206. printk(KERN_INFO "Using dedicated idle loop\n");
  207. ppc_md.idle_loop = pseries_dedicated_idle;
  208. }
  209. } else {
  210. printk(KERN_INFO "Using default idle loop\n");
  211. ppc_md.idle_loop = default_idle;
  212. }
  213. }
  214. static int __init pSeries_init_panel(void)
  215. {
  216. /* Manually leave the kernel version on the panel. */
  217. ppc_md.progress("Linux ppc64\n", 0);
  218. ppc_md.progress(UTS_RELEASE, 0);
  219. return 0;
  220. }
  221. arch_initcall(pSeries_init_panel);
  222. /* Build up the ppc64_firmware_features bitmask field
  223. * using contents of device-tree/ibm,hypertas-functions.
  224. * Ultimately this functionality may be moved into prom.c prom_init().
  225. */
  226. void __init fw_feature_init(void)
  227. {
  228. struct device_node * dn;
  229. char * hypertas;
  230. unsigned int len;
  231. DBG(" -> fw_feature_init()\n");
  232. ppc64_firmware_features = 0;
  233. dn = of_find_node_by_path("/rtas");
  234. if (dn == NULL) {
  235. printk(KERN_ERR "WARNING ! Cannot find RTAS in device-tree !\n");
  236. goto no_rtas;
  237. }
  238. hypertas = get_property(dn, "ibm,hypertas-functions", &len);
  239. if (hypertas) {
  240. while (len > 0){
  241. int i, hypertas_len;
  242. /* check value against table of strings */
  243. for(i=0; i < FIRMWARE_MAX_FEATURES ;i++) {
  244. if ((firmware_features_table[i].name) &&
  245. (strcmp(firmware_features_table[i].name,hypertas))==0) {
  246. /* we have a match */
  247. ppc64_firmware_features |=
  248. (firmware_features_table[i].val);
  249. break;
  250. }
  251. }
  252. hypertas_len = strlen(hypertas);
  253. len -= hypertas_len +1;
  254. hypertas+= hypertas_len +1;
  255. }
  256. }
  257. of_node_put(dn);
  258. no_rtas:
  259. printk(KERN_INFO "firmware_features = 0x%lx\n",
  260. ppc64_firmware_features);
  261. DBG(" <- fw_feature_init()\n");
  262. }
  263. static void __init pSeries_discover_pic(void)
  264. {
  265. struct device_node *np;
  266. char *typep;
  267. /*
  268. * Setup interrupt mapping options that are needed for finish_device_tree
  269. * to properly parse the OF interrupt tree & do the virtual irq mapping
  270. */
  271. __irq_offset_value = NUM_ISA_INTERRUPTS;
  272. ppc64_interrupt_controller = IC_INVALID;
  273. for (np = NULL; (np = of_find_node_by_name(np, "interrupt-controller"));) {
  274. typep = (char *)get_property(np, "compatible", NULL);
  275. if (strstr(typep, "open-pic"))
  276. ppc64_interrupt_controller = IC_OPEN_PIC;
  277. else if (strstr(typep, "ppc-xicp"))
  278. ppc64_interrupt_controller = IC_PPC_XIC;
  279. else
  280. printk("pSeries_discover_pic: failed to recognize"
  281. " interrupt-controller\n");
  282. break;
  283. }
  284. }
  285. static void pSeries_mach_cpu_die(void)
  286. {
  287. local_irq_disable();
  288. idle_task_exit();
  289. /* Some hardware requires clearing the CPPR, while other hardware does not
  290. * it is safe either way
  291. */
  292. pSeriesLP_cppr_info(0, 0);
  293. rtas_stop_self();
  294. /* Should never get here... */
  295. BUG();
  296. for(;;);
  297. }
  298. /*
  299. * Early initialization. Relocation is on but do not reference unbolted pages
  300. */
  301. static void __init pSeries_init_early(void)
  302. {
  303. void *comport;
  304. int iommu_off = 0;
  305. unsigned int default_speed;
  306. u64 physport;
  307. DBG(" -> pSeries_init_early()\n");
  308. fw_feature_init();
  309. if (systemcfg->platform & PLATFORM_LPAR)
  310. hpte_init_lpar();
  311. else {
  312. hpte_init_native();
  313. iommu_off = (of_chosen &&
  314. get_property(of_chosen, "linux,iommu-off", NULL));
  315. }
  316. generic_find_legacy_serial_ports(&physport, &default_speed);
  317. if (systemcfg->platform & PLATFORM_LPAR)
  318. find_udbg_vterm();
  319. else if (physport) {
  320. /* Map the uart for udbg. */
  321. comport = (void *)ioremap(physport, 16);
  322. udbg_init_uart(comport, default_speed);
  323. ppc_md.udbg_putc = udbg_putc;
  324. ppc_md.udbg_getc = udbg_getc;
  325. ppc_md.udbg_getc_poll = udbg_getc_poll;
  326. DBG("Hello World !\n");
  327. }
  328. iommu_init_early_pSeries();
  329. pSeries_discover_pic();
  330. DBG(" <- pSeries_init_early()\n");
  331. }
  332. static int pSeries_check_legacy_ioport(unsigned int baseport)
  333. {
  334. struct device_node *np;
  335. #define I8042_DATA_REG 0x60
  336. #define FDC_BASE 0x3f0
  337. switch(baseport) {
  338. case I8042_DATA_REG:
  339. np = of_find_node_by_type(NULL, "8042");
  340. if (np == NULL)
  341. return -ENODEV;
  342. of_node_put(np);
  343. break;
  344. case FDC_BASE:
  345. np = of_find_node_by_type(NULL, "fdc");
  346. if (np == NULL)
  347. return -ENODEV;
  348. of_node_put(np);
  349. break;
  350. }
  351. return 0;
  352. }
  353. /*
  354. * Called very early, MMU is off, device-tree isn't unflattened
  355. */
  356. extern struct machdep_calls pSeries_md;
  357. static int __init pSeries_probe(int platform)
  358. {
  359. if (platform != PLATFORM_PSERIES &&
  360. platform != PLATFORM_PSERIES_LPAR)
  361. return 0;
  362. /* if we have some ppc_md fixups for LPAR to do, do
  363. * it here ...
  364. */
  365. return 1;
  366. }
  367. DECLARE_PER_CPU(unsigned long, smt_snooze_delay);
  368. static inline void dedicated_idle_sleep(unsigned int cpu)
  369. {
  370. struct paca_struct *ppaca = &paca[cpu ^ 1];
  371. /* Only sleep if the other thread is not idle */
  372. if (!(ppaca->lppaca.idle)) {
  373. local_irq_disable();
  374. /*
  375. * We are about to sleep the thread and so wont be polling any
  376. * more.
  377. */
  378. clear_thread_flag(TIF_POLLING_NRFLAG);
  379. /*
  380. * SMT dynamic mode. Cede will result in this thread going
  381. * dormant, if the partner thread is still doing work. Thread
  382. * wakes up if partner goes idle, an interrupt is presented, or
  383. * a prod occurs. Returning from the cede enables external
  384. * interrupts.
  385. */
  386. if (!need_resched())
  387. cede_processor();
  388. else
  389. local_irq_enable();
  390. } else {
  391. /*
  392. * Give the HV an opportunity at the processor, since we are
  393. * not doing any work.
  394. */
  395. poll_pending();
  396. }
  397. }
  398. static int pseries_dedicated_idle(void)
  399. {
  400. long oldval;
  401. struct paca_struct *lpaca = get_paca();
  402. unsigned int cpu = smp_processor_id();
  403. unsigned long start_snooze;
  404. unsigned long *smt_snooze_delay = &__get_cpu_var(smt_snooze_delay);
  405. while (1) {
  406. /*
  407. * Indicate to the HV that we are idle. Now would be
  408. * a good time to find other work to dispatch.
  409. */
  410. lpaca->lppaca.idle = 1;
  411. oldval = test_and_clear_thread_flag(TIF_NEED_RESCHED);
  412. if (!oldval) {
  413. set_thread_flag(TIF_POLLING_NRFLAG);
  414. start_snooze = __get_tb() +
  415. *smt_snooze_delay * tb_ticks_per_usec;
  416. while (!need_resched() && !cpu_is_offline(cpu)) {
  417. ppc64_runlatch_off();
  418. /*
  419. * Go into low thread priority and possibly
  420. * low power mode.
  421. */
  422. HMT_low();
  423. HMT_very_low();
  424. if (*smt_snooze_delay != 0 &&
  425. __get_tb() > start_snooze) {
  426. HMT_medium();
  427. dedicated_idle_sleep(cpu);
  428. }
  429. }
  430. HMT_medium();
  431. clear_thread_flag(TIF_POLLING_NRFLAG);
  432. } else {
  433. set_need_resched();
  434. }
  435. lpaca->lppaca.idle = 0;
  436. ppc64_runlatch_on();
  437. schedule();
  438. if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
  439. cpu_die();
  440. }
  441. }
  442. static int pseries_shared_idle(void)
  443. {
  444. struct paca_struct *lpaca = get_paca();
  445. unsigned int cpu = smp_processor_id();
  446. while (1) {
  447. /*
  448. * Indicate to the HV that we are idle. Now would be
  449. * a good time to find other work to dispatch.
  450. */
  451. lpaca->lppaca.idle = 1;
  452. while (!need_resched() && !cpu_is_offline(cpu)) {
  453. local_irq_disable();
  454. ppc64_runlatch_off();
  455. /*
  456. * Yield the processor to the hypervisor. We return if
  457. * an external interrupt occurs (which are driven prior
  458. * to returning here) or if a prod occurs from another
  459. * processor. When returning here, external interrupts
  460. * are enabled.
  461. *
  462. * Check need_resched() again with interrupts disabled
  463. * to avoid a race.
  464. */
  465. if (!need_resched())
  466. cede_processor();
  467. else
  468. local_irq_enable();
  469. HMT_medium();
  470. }
  471. lpaca->lppaca.idle = 0;
  472. ppc64_runlatch_on();
  473. schedule();
  474. if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
  475. cpu_die();
  476. }
  477. return 0;
  478. }
  479. struct machdep_calls __initdata pSeries_md = {
  480. .probe = pSeries_probe,
  481. .setup_arch = pSeries_setup_arch,
  482. .init_early = pSeries_init_early,
  483. .get_cpuinfo = pSeries_get_cpuinfo,
  484. .log_error = pSeries_log_error,
  485. .pcibios_fixup = pSeries_final_fixup,
  486. .irq_bus_setup = pSeries_irq_bus_setup,
  487. .restart = rtas_restart,
  488. .power_off = rtas_power_off,
  489. .halt = rtas_halt,
  490. .panic = rtas_os_term,
  491. .cpu_die = pSeries_mach_cpu_die,
  492. .get_boot_time = rtas_get_boot_time,
  493. .get_rtc_time = rtas_get_rtc_time,
  494. .set_rtc_time = rtas_set_rtc_time,
  495. .calibrate_decr = generic_calibrate_decr,
  496. .progress = rtas_progress,
  497. .check_legacy_ioport = pSeries_check_legacy_ioport,
  498. .system_reset_exception = pSeries_system_reset_exception,
  499. .machine_check_exception = pSeries_machine_check_exception,
  500. };