xics.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. /*
  2. * arch/powerpc/platforms/pseries/xics.c
  3. *
  4. * Copyright 2000 IBM Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #undef DEBUG
  12. #include <linux/types.h>
  13. #include <linux/threads.h>
  14. #include <linux/kernel.h>
  15. #include <linux/irq.h>
  16. #include <linux/smp.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/signal.h>
  19. #include <linux/init.h>
  20. #include <linux/gfp.h>
  21. #include <linux/radix-tree.h>
  22. #include <linux/cpu.h>
  23. #include <asm/firmware.h>
  24. #include <asm/prom.h>
  25. #include <asm/io.h>
  26. #include <asm/pgtable.h>
  27. #include <asm/smp.h>
  28. #include <asm/rtas.h>
  29. #include <asm/hvcall.h>
  30. #include <asm/machdep.h>
  31. #include <asm/i8259.h>
  32. #include "xics.h"
  33. #include "plpar_wrappers.h"
  34. #define XICS_IPI 2
  35. #define XICS_IRQ_SPURIOUS 0
  36. /* Want a priority other than 0. Various HW issues require this. */
  37. #define DEFAULT_PRIORITY 5
  38. /*
  39. * Mark IPIs as higher priority so we can take them inside interrupts that
  40. * arent marked IRQF_DISABLED
  41. */
  42. #define IPI_PRIORITY 4
  43. struct xics_ipl {
  44. union {
  45. u32 word;
  46. u8 bytes[4];
  47. } xirr_poll;
  48. union {
  49. u32 word;
  50. u8 bytes[4];
  51. } xirr;
  52. u32 dummy;
  53. union {
  54. u32 word;
  55. u8 bytes[4];
  56. } qirr;
  57. };
  58. static struct xics_ipl __iomem *xics_per_cpu[NR_CPUS];
  59. static unsigned int default_server = 0xFF;
  60. static unsigned int default_distrib_server = 0;
  61. static unsigned int interrupt_server_size = 8;
  62. static struct irq_host *xics_host;
  63. /*
  64. * XICS only has a single IPI, so encode the messages per CPU
  65. */
  66. struct xics_ipi_struct xics_ipi_message[NR_CPUS] __cacheline_aligned;
  67. /* RTAS service tokens */
  68. static int ibm_get_xive;
  69. static int ibm_set_xive;
  70. static int ibm_int_on;
  71. static int ibm_int_off;
  72. /* Direct HW low level accessors */
  73. static inline unsigned int direct_xirr_info_get(void)
  74. {
  75. int cpu = smp_processor_id();
  76. return in_be32(&xics_per_cpu[cpu]->xirr.word);
  77. }
  78. static inline void direct_xirr_info_set(int value)
  79. {
  80. int cpu = smp_processor_id();
  81. out_be32(&xics_per_cpu[cpu]->xirr.word, value);
  82. }
  83. static inline void direct_cppr_info(u8 value)
  84. {
  85. int cpu = smp_processor_id();
  86. out_8(&xics_per_cpu[cpu]->xirr.bytes[0], value);
  87. }
  88. static inline void direct_qirr_info(int n_cpu, u8 value)
  89. {
  90. out_8(&xics_per_cpu[n_cpu]->qirr.bytes[0], value);
  91. }
  92. /* LPAR low level accessors */
  93. static inline unsigned int lpar_xirr_info_get(void)
  94. {
  95. unsigned long lpar_rc;
  96. unsigned long return_value;
  97. lpar_rc = plpar_xirr(&return_value);
  98. if (lpar_rc != H_SUCCESS)
  99. panic(" bad return code xirr - rc = %lx \n", lpar_rc);
  100. return (unsigned int)return_value;
  101. }
  102. static inline void lpar_xirr_info_set(int value)
  103. {
  104. unsigned long lpar_rc;
  105. unsigned long val64 = value & 0xffffffff;
  106. lpar_rc = plpar_eoi(val64);
  107. if (lpar_rc != H_SUCCESS)
  108. panic("bad return code EOI - rc = %ld, value=%lx\n", lpar_rc,
  109. val64);
  110. }
  111. static inline void lpar_cppr_info(u8 value)
  112. {
  113. unsigned long lpar_rc;
  114. lpar_rc = plpar_cppr(value);
  115. if (lpar_rc != H_SUCCESS)
  116. panic("bad return code cppr - rc = %lx\n", lpar_rc);
  117. }
  118. static inline void lpar_qirr_info(int n_cpu , u8 value)
  119. {
  120. unsigned long lpar_rc;
  121. lpar_rc = plpar_ipi(get_hard_smp_processor_id(n_cpu), value);
  122. if (lpar_rc != H_SUCCESS)
  123. panic("bad return code qirr - rc = %lx\n", lpar_rc);
  124. }
  125. /* High level handlers and init code */
  126. static void xics_update_irq_servers(void)
  127. {
  128. int i, j;
  129. struct device_node *np;
  130. u32 ilen;
  131. const u32 *ireg, *isize;
  132. u32 hcpuid;
  133. /* Find the server numbers for the boot cpu. */
  134. np = of_get_cpu_node(boot_cpuid, NULL);
  135. BUG_ON(!np);
  136. ireg = of_get_property(np, "ibm,ppc-interrupt-gserver#s", &ilen);
  137. if (!ireg) {
  138. of_node_put(np);
  139. return;
  140. }
  141. i = ilen / sizeof(int);
  142. hcpuid = get_hard_smp_processor_id(boot_cpuid);
  143. /* Global interrupt distribution server is specified in the last
  144. * entry of "ibm,ppc-interrupt-gserver#s" property. Get the last
  145. * entry fom this property for current boot cpu id and use it as
  146. * default distribution server
  147. */
  148. for (j = 0; j < i; j += 2) {
  149. if (ireg[j] == hcpuid) {
  150. default_server = hcpuid;
  151. default_distrib_server = ireg[j+1];
  152. isize = of_get_property(np,
  153. "ibm,interrupt-server#-size", NULL);
  154. if (isize)
  155. interrupt_server_size = *isize;
  156. }
  157. }
  158. of_node_put(np);
  159. }
  160. #ifdef CONFIG_SMP
  161. static int get_irq_server(unsigned int virq, unsigned int strict_check)
  162. {
  163. int server;
  164. /* For the moment only implement delivery to all cpus or one cpu */
  165. cpumask_t cpumask = irq_desc[virq].affinity;
  166. cpumask_t tmp = CPU_MASK_NONE;
  167. if (! cpu_isset(default_server, cpu_online_map))
  168. xics_update_irq_servers();
  169. if (!distribute_irqs)
  170. return default_server;
  171. if (!cpus_equal(cpumask, CPU_MASK_ALL)) {
  172. cpus_and(tmp, cpu_online_map, cpumask);
  173. server = first_cpu(tmp);
  174. if (server < NR_CPUS)
  175. return get_hard_smp_processor_id(server);
  176. if (strict_check)
  177. return -1;
  178. }
  179. if (cpus_equal(cpu_online_map, cpu_present_map))
  180. return default_distrib_server;
  181. return default_server;
  182. }
  183. #else
  184. static int get_irq_server(unsigned int virq, unsigned int strict_check)
  185. {
  186. return default_server;
  187. }
  188. #endif
  189. static void xics_unmask_irq(unsigned int virq)
  190. {
  191. unsigned int irq;
  192. int call_status;
  193. int server;
  194. pr_debug("xics: unmask virq %d\n", virq);
  195. irq = (unsigned int)irq_map[virq].hwirq;
  196. pr_debug(" -> map to hwirq 0x%x\n", irq);
  197. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  198. return;
  199. server = get_irq_server(virq, 0);
  200. call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, server,
  201. DEFAULT_PRIORITY);
  202. if (call_status != 0) {
  203. printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_set_xive "
  204. "returned %d\n", irq, call_status);
  205. printk("set_xive %x, server %x\n", ibm_set_xive, server);
  206. return;
  207. }
  208. /* Now unmask the interrupt (often a no-op) */
  209. call_status = rtas_call(ibm_int_on, 1, 1, NULL, irq);
  210. if (call_status != 0) {
  211. printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_int_on "
  212. "returned %d\n", irq, call_status);
  213. return;
  214. }
  215. }
  216. static void xics_mask_real_irq(unsigned int irq)
  217. {
  218. int call_status;
  219. if (irq == XICS_IPI)
  220. return;
  221. call_status = rtas_call(ibm_int_off, 1, 1, NULL, irq);
  222. if (call_status != 0) {
  223. printk(KERN_ERR "xics_disable_real_irq: irq=%u: "
  224. "ibm_int_off returned %d\n", irq, call_status);
  225. return;
  226. }
  227. /* Have to set XIVE to 0xff to be able to remove a slot */
  228. call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq,
  229. default_server, 0xff);
  230. if (call_status != 0) {
  231. printk(KERN_ERR "xics_disable_irq: irq=%u: ibm_set_xive(0xff)"
  232. " returned %d\n", irq, call_status);
  233. return;
  234. }
  235. }
  236. static void xics_mask_irq(unsigned int virq)
  237. {
  238. unsigned int irq;
  239. pr_debug("xics: mask virq %d\n", virq);
  240. irq = (unsigned int)irq_map[virq].hwirq;
  241. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  242. return;
  243. xics_mask_real_irq(irq);
  244. }
  245. static unsigned int xics_startup(unsigned int virq)
  246. {
  247. unsigned int irq;
  248. /* force a reverse mapping of the interrupt so it gets in the cache */
  249. irq = (unsigned int)irq_map[virq].hwirq;
  250. irq_radix_revmap(xics_host, irq);
  251. /* unmask it */
  252. xics_unmask_irq(virq);
  253. return 0;
  254. }
  255. static void xics_eoi_direct(unsigned int virq)
  256. {
  257. unsigned int irq = (unsigned int)irq_map[virq].hwirq;
  258. iosync();
  259. direct_xirr_info_set((0xff << 24) | irq);
  260. }
  261. static void xics_eoi_lpar(unsigned int virq)
  262. {
  263. unsigned int irq = (unsigned int)irq_map[virq].hwirq;
  264. iosync();
  265. lpar_xirr_info_set((0xff << 24) | irq);
  266. }
  267. static inline unsigned int xics_remap_irq(unsigned int vec)
  268. {
  269. unsigned int irq;
  270. vec &= 0x00ffffff;
  271. if (vec == XICS_IRQ_SPURIOUS)
  272. return NO_IRQ;
  273. irq = irq_radix_revmap(xics_host, vec);
  274. if (likely(irq != NO_IRQ))
  275. return irq;
  276. printk(KERN_ERR "Interrupt %u (real) is invalid,"
  277. " disabling it.\n", vec);
  278. xics_mask_real_irq(vec);
  279. return NO_IRQ;
  280. }
  281. static unsigned int xics_get_irq_direct(void)
  282. {
  283. return xics_remap_irq(direct_xirr_info_get());
  284. }
  285. static unsigned int xics_get_irq_lpar(void)
  286. {
  287. return xics_remap_irq(lpar_xirr_info_get());
  288. }
  289. #ifdef CONFIG_SMP
  290. static irqreturn_t xics_ipi_dispatch(int cpu)
  291. {
  292. WARN_ON(cpu_is_offline(cpu));
  293. while (xics_ipi_message[cpu].value) {
  294. if (test_and_clear_bit(PPC_MSG_CALL_FUNCTION,
  295. &xics_ipi_message[cpu].value)) {
  296. mb();
  297. smp_message_recv(PPC_MSG_CALL_FUNCTION);
  298. }
  299. if (test_and_clear_bit(PPC_MSG_RESCHEDULE,
  300. &xics_ipi_message[cpu].value)) {
  301. mb();
  302. smp_message_recv(PPC_MSG_RESCHEDULE);
  303. }
  304. #if 0
  305. if (test_and_clear_bit(PPC_MSG_MIGRATE_TASK,
  306. &xics_ipi_message[cpu].value)) {
  307. mb();
  308. smp_message_recv(PPC_MSG_MIGRATE_TASK);
  309. }
  310. #endif
  311. #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
  312. if (test_and_clear_bit(PPC_MSG_DEBUGGER_BREAK,
  313. &xics_ipi_message[cpu].value)) {
  314. mb();
  315. smp_message_recv(PPC_MSG_DEBUGGER_BREAK);
  316. }
  317. #endif
  318. }
  319. return IRQ_HANDLED;
  320. }
  321. static irqreturn_t xics_ipi_action_direct(int irq, void *dev_id)
  322. {
  323. int cpu = smp_processor_id();
  324. direct_qirr_info(cpu, 0xff);
  325. return xics_ipi_dispatch(cpu);
  326. }
  327. static irqreturn_t xics_ipi_action_lpar(int irq, void *dev_id)
  328. {
  329. int cpu = smp_processor_id();
  330. lpar_qirr_info(cpu, 0xff);
  331. return xics_ipi_dispatch(cpu);
  332. }
  333. void xics_cause_IPI(int cpu)
  334. {
  335. if (firmware_has_feature(FW_FEATURE_LPAR))
  336. lpar_qirr_info(cpu, IPI_PRIORITY);
  337. else
  338. direct_qirr_info(cpu, IPI_PRIORITY);
  339. }
  340. #endif /* CONFIG_SMP */
  341. static void xics_set_cpu_priority(unsigned char cppr)
  342. {
  343. if (firmware_has_feature(FW_FEATURE_LPAR))
  344. lpar_cppr_info(cppr);
  345. else
  346. direct_cppr_info(cppr);
  347. iosync();
  348. }
  349. static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
  350. {
  351. unsigned int irq;
  352. int status;
  353. int xics_status[2];
  354. int irq_server;
  355. irq = (unsigned int)irq_map[virq].hwirq;
  356. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  357. return;
  358. status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
  359. if (status) {
  360. printk(KERN_ERR "xics_set_affinity: irq=%u ibm,get-xive "
  361. "returns %d\n", irq, status);
  362. return;
  363. }
  364. /*
  365. * For the moment only implement delivery to all cpus or one cpu.
  366. * Get current irq_server for the given irq
  367. */
  368. irq_server = get_irq_server(virq, 1);
  369. if (irq_server == -1) {
  370. char cpulist[128];
  371. cpumask_scnprintf(cpulist, sizeof(cpulist), cpumask);
  372. printk(KERN_WARNING "xics_set_affinity: No online cpus in "
  373. "the mask %s for irq %d\n", cpulist, virq);
  374. return;
  375. }
  376. status = rtas_call(ibm_set_xive, 3, 1, NULL,
  377. irq, irq_server, xics_status[1]);
  378. if (status) {
  379. printk(KERN_ERR "xics_set_affinity: irq=%u ibm,set-xive "
  380. "returns %d\n", irq, status);
  381. return;
  382. }
  383. }
  384. void xics_setup_cpu(void)
  385. {
  386. xics_set_cpu_priority(0xff);
  387. /*
  388. * Put the calling processor into the GIQ. This is really only
  389. * necessary from a secondary thread as the OF start-cpu interface
  390. * performs this function for us on primary threads.
  391. *
  392. * XXX: undo of teardown on kexec needs this too, as may hotplug
  393. */
  394. rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  395. (1UL << interrupt_server_size) - 1 - default_distrib_server, 1);
  396. }
  397. static struct irq_chip xics_pic_direct = {
  398. .typename = " XICS ",
  399. .startup = xics_startup,
  400. .mask = xics_mask_irq,
  401. .unmask = xics_unmask_irq,
  402. .eoi = xics_eoi_direct,
  403. .set_affinity = xics_set_affinity
  404. };
  405. static struct irq_chip xics_pic_lpar = {
  406. .typename = " XICS ",
  407. .startup = xics_startup,
  408. .mask = xics_mask_irq,
  409. .unmask = xics_unmask_irq,
  410. .eoi = xics_eoi_lpar,
  411. .set_affinity = xics_set_affinity
  412. };
  413. static int xics_host_match(struct irq_host *h, struct device_node *node)
  414. {
  415. /* IBM machines have interrupt parents of various funky types for things
  416. * like vdevices, events, etc... The trick we use here is to match
  417. * everything here except the legacy 8259 which is compatible "chrp,iic"
  418. */
  419. return !of_device_is_compatible(node, "chrp,iic");
  420. }
  421. static int xics_host_map_direct(struct irq_host *h, unsigned int virq,
  422. irq_hw_number_t hw)
  423. {
  424. pr_debug("xics: map_direct virq %d, hwirq 0x%lx\n", virq, hw);
  425. get_irq_desc(virq)->status |= IRQ_LEVEL;
  426. set_irq_chip_and_handler(virq, &xics_pic_direct, handle_fasteoi_irq);
  427. return 0;
  428. }
  429. static int xics_host_map_lpar(struct irq_host *h, unsigned int virq,
  430. irq_hw_number_t hw)
  431. {
  432. pr_debug("xics: map_direct virq %d, hwirq 0x%lx\n", virq, hw);
  433. get_irq_desc(virq)->status |= IRQ_LEVEL;
  434. set_irq_chip_and_handler(virq, &xics_pic_lpar, handle_fasteoi_irq);
  435. return 0;
  436. }
  437. static int xics_host_xlate(struct irq_host *h, struct device_node *ct,
  438. u32 *intspec, unsigned int intsize,
  439. irq_hw_number_t *out_hwirq, unsigned int *out_flags)
  440. {
  441. /* Current xics implementation translates everything
  442. * to level. It is not technically right for MSIs but this
  443. * is irrelevant at this point. We might get smarter in the future
  444. */
  445. *out_hwirq = intspec[0];
  446. *out_flags = IRQ_TYPE_LEVEL_LOW;
  447. return 0;
  448. }
  449. static struct irq_host_ops xics_host_direct_ops = {
  450. .match = xics_host_match,
  451. .map = xics_host_map_direct,
  452. .xlate = xics_host_xlate,
  453. };
  454. static struct irq_host_ops xics_host_lpar_ops = {
  455. .match = xics_host_match,
  456. .map = xics_host_map_lpar,
  457. .xlate = xics_host_xlate,
  458. };
  459. static void __init xics_init_host(void)
  460. {
  461. struct irq_host_ops *ops;
  462. if (firmware_has_feature(FW_FEATURE_LPAR))
  463. ops = &xics_host_lpar_ops;
  464. else
  465. ops = &xics_host_direct_ops;
  466. xics_host = irq_alloc_host(NULL, IRQ_HOST_MAP_TREE, 0, ops,
  467. XICS_IRQ_SPURIOUS);
  468. BUG_ON(xics_host == NULL);
  469. irq_set_default_host(xics_host);
  470. }
  471. static void __init xics_map_one_cpu(int hw_id, unsigned long addr,
  472. unsigned long size)
  473. {
  474. #ifdef CONFIG_SMP
  475. int i;
  476. /* This may look gross but it's good enough for now, we don't quite
  477. * have a hard -> linux processor id matching.
  478. */
  479. for_each_possible_cpu(i) {
  480. if (!cpu_present(i))
  481. continue;
  482. if (hw_id == get_hard_smp_processor_id(i)) {
  483. xics_per_cpu[i] = ioremap(addr, size);
  484. return;
  485. }
  486. }
  487. #else
  488. if (hw_id != 0)
  489. return;
  490. xics_per_cpu[0] = ioremap(addr, size);
  491. #endif /* CONFIG_SMP */
  492. }
  493. static void __init xics_init_one_node(struct device_node *np,
  494. unsigned int *indx)
  495. {
  496. unsigned int ilen;
  497. const u32 *ireg;
  498. /* This code does the theorically broken assumption that the interrupt
  499. * server numbers are the same as the hard CPU numbers.
  500. * This happens to be the case so far but we are playing with fire...
  501. * should be fixed one of these days. -BenH.
  502. */
  503. ireg = of_get_property(np, "ibm,interrupt-server-ranges", NULL);
  504. /* Do that ever happen ? we'll know soon enough... but even good'old
  505. * f80 does have that property ..
  506. */
  507. WARN_ON(ireg == NULL);
  508. if (ireg) {
  509. /*
  510. * set node starting index for this node
  511. */
  512. *indx = *ireg;
  513. }
  514. ireg = of_get_property(np, "reg", &ilen);
  515. if (!ireg)
  516. panic("xics_init_IRQ: can't find interrupt reg property");
  517. while (ilen >= (4 * sizeof(u32))) {
  518. unsigned long addr, size;
  519. /* XXX Use proper OF parsing code here !!! */
  520. addr = (unsigned long)*ireg++ << 32;
  521. ilen -= sizeof(u32);
  522. addr |= *ireg++;
  523. ilen -= sizeof(u32);
  524. size = (unsigned long)*ireg++ << 32;
  525. ilen -= sizeof(u32);
  526. size |= *ireg++;
  527. ilen -= sizeof(u32);
  528. xics_map_one_cpu(*indx, addr, size);
  529. (*indx)++;
  530. }
  531. }
  532. static void __init xics_setup_8259_cascade(void)
  533. {
  534. struct device_node *np, *old, *found = NULL;
  535. int cascade, naddr;
  536. const u32 *addrp;
  537. unsigned long intack = 0;
  538. for_each_node_by_type(np, "interrupt-controller")
  539. if (of_device_is_compatible(np, "chrp,iic")) {
  540. found = np;
  541. break;
  542. }
  543. if (found == NULL) {
  544. printk(KERN_DEBUG "xics: no ISA interrupt controller\n");
  545. return;
  546. }
  547. cascade = irq_of_parse_and_map(found, 0);
  548. if (cascade == NO_IRQ) {
  549. printk(KERN_ERR "xics: failed to map cascade interrupt");
  550. return;
  551. }
  552. pr_debug("xics: cascade mapped to irq %d\n", cascade);
  553. for (old = of_node_get(found); old != NULL ; old = np) {
  554. np = of_get_parent(old);
  555. of_node_put(old);
  556. if (np == NULL)
  557. break;
  558. if (strcmp(np->name, "pci") != 0)
  559. continue;
  560. addrp = of_get_property(np, "8259-interrupt-acknowledge", NULL);
  561. if (addrp == NULL)
  562. continue;
  563. naddr = of_n_addr_cells(np);
  564. intack = addrp[naddr-1];
  565. if (naddr > 1)
  566. intack |= ((unsigned long)addrp[naddr-2]) << 32;
  567. }
  568. if (intack)
  569. printk(KERN_DEBUG "xics: PCI 8259 intack at 0x%016lx\n", intack);
  570. i8259_init(found, intack);
  571. of_node_put(found);
  572. set_irq_chained_handler(cascade, pseries_8259_cascade);
  573. }
  574. void __init xics_init_IRQ(void)
  575. {
  576. struct device_node *np;
  577. u32 indx = 0;
  578. int found = 0;
  579. ppc64_boot_msg(0x20, "XICS Init");
  580. ibm_get_xive = rtas_token("ibm,get-xive");
  581. ibm_set_xive = rtas_token("ibm,set-xive");
  582. ibm_int_on = rtas_token("ibm,int-on");
  583. ibm_int_off = rtas_token("ibm,int-off");
  584. for_each_node_by_type(np, "PowerPC-External-Interrupt-Presentation") {
  585. found = 1;
  586. if (firmware_has_feature(FW_FEATURE_LPAR))
  587. break;
  588. xics_init_one_node(np, &indx);
  589. }
  590. if (found == 0)
  591. return;
  592. xics_init_host();
  593. xics_update_irq_servers();
  594. if (firmware_has_feature(FW_FEATURE_LPAR))
  595. ppc_md.get_irq = xics_get_irq_lpar;
  596. else
  597. ppc_md.get_irq = xics_get_irq_direct;
  598. xics_setup_cpu();
  599. xics_setup_8259_cascade();
  600. ppc64_boot_msg(0x21, "XICS Done");
  601. }
  602. #ifdef CONFIG_SMP
  603. void xics_request_IPIs(void)
  604. {
  605. unsigned int ipi;
  606. int rc;
  607. ipi = irq_create_mapping(xics_host, XICS_IPI);
  608. BUG_ON(ipi == NO_IRQ);
  609. /*
  610. * IPIs are marked IRQF_DISABLED as they must run with irqs
  611. * disabled
  612. */
  613. set_irq_handler(ipi, handle_percpu_irq);
  614. if (firmware_has_feature(FW_FEATURE_LPAR))
  615. rc = request_irq(ipi, xics_ipi_action_lpar, IRQF_DISABLED,
  616. "IPI", NULL);
  617. else
  618. rc = request_irq(ipi, xics_ipi_action_direct, IRQF_DISABLED,
  619. "IPI", NULL);
  620. BUG_ON(rc);
  621. }
  622. #endif /* CONFIG_SMP */
  623. void xics_teardown_cpu()
  624. {
  625. int cpu = smp_processor_id();
  626. xics_set_cpu_priority(0);
  627. /*
  628. * Clear IPI
  629. */
  630. if (firmware_has_feature(FW_FEATURE_LPAR))
  631. lpar_qirr_info(cpu, 0xff);
  632. else
  633. direct_qirr_info(cpu, 0xff);
  634. }
  635. void xics_kexec_teardown_cpu(int secondary)
  636. {
  637. unsigned int ipi;
  638. struct irq_desc *desc;
  639. xics_teardown_cpu();
  640. /*
  641. * we need to EOI the IPI
  642. *
  643. * probably need to check all the other interrupts too
  644. * should we be flagging idle loop instead?
  645. * or creating some task to be scheduled?
  646. */
  647. ipi = irq_find_mapping(xics_host, XICS_IPI);
  648. if (ipi == XICS_IRQ_SPURIOUS)
  649. return;
  650. desc = get_irq_desc(ipi);
  651. if (desc->chip && desc->chip->eoi)
  652. desc->chip->eoi(ipi);
  653. /*
  654. * Some machines need to have at least one cpu in the GIQ,
  655. * so leave the master cpu in the group.
  656. */
  657. if (secondary)
  658. rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  659. (1UL << interrupt_server_size) - 1 -
  660. default_distrib_server, 0);
  661. }
  662. #ifdef CONFIG_HOTPLUG_CPU
  663. /* Interrupts are disabled. */
  664. void xics_migrate_irqs_away(void)
  665. {
  666. int status;
  667. int cpu = smp_processor_id(), hw_cpu = hard_smp_processor_id();
  668. unsigned int irq, virq;
  669. /* Reject any interrupt that was queued to us... */
  670. xics_set_cpu_priority(0);
  671. /* remove ourselves from the global interrupt queue */
  672. status = rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  673. (1UL << interrupt_server_size) - 1 - default_distrib_server, 0);
  674. WARN_ON(status < 0);
  675. /* Allow IPIs again... */
  676. xics_set_cpu_priority(DEFAULT_PRIORITY);
  677. for_each_irq(virq) {
  678. struct irq_desc *desc;
  679. int xics_status[2];
  680. unsigned long flags;
  681. /* We cant set affinity on ISA interrupts */
  682. if (virq < NUM_ISA_INTERRUPTS)
  683. continue;
  684. if (irq_map[virq].host != xics_host)
  685. continue;
  686. irq = (unsigned int)irq_map[virq].hwirq;
  687. /* We need to get IPIs still. */
  688. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  689. continue;
  690. desc = get_irq_desc(virq);
  691. /* We only need to migrate enabled IRQS */
  692. if (desc == NULL || desc->chip == NULL
  693. || desc->action == NULL
  694. || desc->chip->set_affinity == NULL)
  695. continue;
  696. spin_lock_irqsave(&desc->lock, flags);
  697. status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
  698. if (status) {
  699. printk(KERN_ERR "migrate_irqs_away: irq=%u "
  700. "ibm,get-xive returns %d\n",
  701. virq, status);
  702. goto unlock;
  703. }
  704. /*
  705. * We only support delivery to all cpus or to one cpu.
  706. * The irq has to be migrated only in the single cpu
  707. * case.
  708. */
  709. if (xics_status[0] != hw_cpu)
  710. goto unlock;
  711. printk(KERN_WARNING "IRQ %u affinity broken off cpu %u\n",
  712. virq, cpu);
  713. /* Reset affinity to all cpus */
  714. irq_desc[virq].affinity = CPU_MASK_ALL;
  715. desc->chip->set_affinity(virq, CPU_MASK_ALL);
  716. unlock:
  717. spin_unlock_irqrestore(&desc->lock, flags);
  718. }
  719. }
  720. #endif