xics.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  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. /* Points to the irq_chip we're actually using */
  414. static struct irq_chip *xics_irq_chip;
  415. static int xics_host_match(struct irq_host *h, struct device_node *node)
  416. {
  417. /* IBM machines have interrupt parents of various funky types for things
  418. * like vdevices, events, etc... The trick we use here is to match
  419. * everything here except the legacy 8259 which is compatible "chrp,iic"
  420. */
  421. return !of_device_is_compatible(node, "chrp,iic");
  422. }
  423. static int xics_host_map(struct irq_host *h, unsigned int virq,
  424. irq_hw_number_t hw)
  425. {
  426. pr_debug("xics: map virq %d, hwirq 0x%lx\n", virq, hw);
  427. get_irq_desc(virq)->status |= IRQ_LEVEL;
  428. set_irq_chip_and_handler(virq, xics_irq_chip, handle_fasteoi_irq);
  429. return 0;
  430. }
  431. static int xics_host_xlate(struct irq_host *h, struct device_node *ct,
  432. u32 *intspec, unsigned int intsize,
  433. irq_hw_number_t *out_hwirq, unsigned int *out_flags)
  434. {
  435. /* Current xics implementation translates everything
  436. * to level. It is not technically right for MSIs but this
  437. * is irrelevant at this point. We might get smarter in the future
  438. */
  439. *out_hwirq = intspec[0];
  440. *out_flags = IRQ_TYPE_LEVEL_LOW;
  441. return 0;
  442. }
  443. static struct irq_host_ops xics_host_ops = {
  444. .match = xics_host_match,
  445. .map = xics_host_map,
  446. .xlate = xics_host_xlate,
  447. };
  448. static void __init xics_init_host(void)
  449. {
  450. if (firmware_has_feature(FW_FEATURE_LPAR))
  451. xics_irq_chip = &xics_pic_lpar;
  452. else
  453. xics_irq_chip = &xics_pic_direct;
  454. xics_host = irq_alloc_host(NULL, IRQ_HOST_MAP_TREE, 0, &xics_host_ops,
  455. XICS_IRQ_SPURIOUS);
  456. BUG_ON(xics_host == NULL);
  457. irq_set_default_host(xics_host);
  458. }
  459. static void __init xics_map_one_cpu(int hw_id, unsigned long addr,
  460. unsigned long size)
  461. {
  462. #ifdef CONFIG_SMP
  463. int i;
  464. /* This may look gross but it's good enough for now, we don't quite
  465. * have a hard -> linux processor id matching.
  466. */
  467. for_each_possible_cpu(i) {
  468. if (!cpu_present(i))
  469. continue;
  470. if (hw_id == get_hard_smp_processor_id(i)) {
  471. xics_per_cpu[i] = ioremap(addr, size);
  472. return;
  473. }
  474. }
  475. #else
  476. if (hw_id != 0)
  477. return;
  478. xics_per_cpu[0] = ioremap(addr, size);
  479. #endif /* CONFIG_SMP */
  480. }
  481. static void __init xics_init_one_node(struct device_node *np,
  482. unsigned int *indx)
  483. {
  484. unsigned int ilen;
  485. const u32 *ireg;
  486. /* This code does the theorically broken assumption that the interrupt
  487. * server numbers are the same as the hard CPU numbers.
  488. * This happens to be the case so far but we are playing with fire...
  489. * should be fixed one of these days. -BenH.
  490. */
  491. ireg = of_get_property(np, "ibm,interrupt-server-ranges", NULL);
  492. /* Do that ever happen ? we'll know soon enough... but even good'old
  493. * f80 does have that property ..
  494. */
  495. WARN_ON(ireg == NULL);
  496. if (ireg) {
  497. /*
  498. * set node starting index for this node
  499. */
  500. *indx = *ireg;
  501. }
  502. ireg = of_get_property(np, "reg", &ilen);
  503. if (!ireg)
  504. panic("xics_init_IRQ: can't find interrupt reg property");
  505. while (ilen >= (4 * sizeof(u32))) {
  506. unsigned long addr, size;
  507. /* XXX Use proper OF parsing code here !!! */
  508. addr = (unsigned long)*ireg++ << 32;
  509. ilen -= sizeof(u32);
  510. addr |= *ireg++;
  511. ilen -= sizeof(u32);
  512. size = (unsigned long)*ireg++ << 32;
  513. ilen -= sizeof(u32);
  514. size |= *ireg++;
  515. ilen -= sizeof(u32);
  516. xics_map_one_cpu(*indx, addr, size);
  517. (*indx)++;
  518. }
  519. }
  520. void __init xics_init_IRQ(void)
  521. {
  522. struct device_node *np;
  523. u32 indx = 0;
  524. int found = 0;
  525. ppc64_boot_msg(0x20, "XICS Init");
  526. ibm_get_xive = rtas_token("ibm,get-xive");
  527. ibm_set_xive = rtas_token("ibm,set-xive");
  528. ibm_int_on = rtas_token("ibm,int-on");
  529. ibm_int_off = rtas_token("ibm,int-off");
  530. for_each_node_by_type(np, "PowerPC-External-Interrupt-Presentation") {
  531. found = 1;
  532. if (firmware_has_feature(FW_FEATURE_LPAR))
  533. break;
  534. xics_init_one_node(np, &indx);
  535. }
  536. if (found == 0)
  537. return;
  538. xics_init_host();
  539. xics_update_irq_servers();
  540. if (firmware_has_feature(FW_FEATURE_LPAR))
  541. ppc_md.get_irq = xics_get_irq_lpar;
  542. else
  543. ppc_md.get_irq = xics_get_irq_direct;
  544. xics_setup_cpu();
  545. ppc64_boot_msg(0x21, "XICS Done");
  546. }
  547. #ifdef CONFIG_SMP
  548. void xics_request_IPIs(void)
  549. {
  550. unsigned int ipi;
  551. int rc;
  552. ipi = irq_create_mapping(xics_host, XICS_IPI);
  553. BUG_ON(ipi == NO_IRQ);
  554. /*
  555. * IPIs are marked IRQF_DISABLED as they must run with irqs
  556. * disabled
  557. */
  558. set_irq_handler(ipi, handle_percpu_irq);
  559. if (firmware_has_feature(FW_FEATURE_LPAR))
  560. rc = request_irq(ipi, xics_ipi_action_lpar, IRQF_DISABLED,
  561. "IPI", NULL);
  562. else
  563. rc = request_irq(ipi, xics_ipi_action_direct, IRQF_DISABLED,
  564. "IPI", NULL);
  565. BUG_ON(rc);
  566. }
  567. #endif /* CONFIG_SMP */
  568. void xics_teardown_cpu(void)
  569. {
  570. int cpu = smp_processor_id();
  571. xics_set_cpu_priority(0);
  572. /*
  573. * Clear IPI
  574. */
  575. if (firmware_has_feature(FW_FEATURE_LPAR))
  576. lpar_qirr_info(cpu, 0xff);
  577. else
  578. direct_qirr_info(cpu, 0xff);
  579. }
  580. void xics_kexec_teardown_cpu(int secondary)
  581. {
  582. unsigned int ipi;
  583. struct irq_desc *desc;
  584. xics_teardown_cpu();
  585. /*
  586. * we need to EOI the IPI
  587. *
  588. * probably need to check all the other interrupts too
  589. * should we be flagging idle loop instead?
  590. * or creating some task to be scheduled?
  591. */
  592. ipi = irq_find_mapping(xics_host, XICS_IPI);
  593. if (ipi == XICS_IRQ_SPURIOUS)
  594. return;
  595. desc = get_irq_desc(ipi);
  596. if (desc->chip && desc->chip->eoi)
  597. desc->chip->eoi(ipi);
  598. /*
  599. * Some machines need to have at least one cpu in the GIQ,
  600. * so leave the master cpu in the group.
  601. */
  602. if (secondary)
  603. rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  604. (1UL << interrupt_server_size) - 1 -
  605. default_distrib_server, 0);
  606. }
  607. #ifdef CONFIG_HOTPLUG_CPU
  608. /* Interrupts are disabled. */
  609. void xics_migrate_irqs_away(void)
  610. {
  611. int status;
  612. int cpu = smp_processor_id(), hw_cpu = hard_smp_processor_id();
  613. unsigned int irq, virq;
  614. /* Reject any interrupt that was queued to us... */
  615. xics_set_cpu_priority(0);
  616. /* remove ourselves from the global interrupt queue */
  617. status = rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  618. (1UL << interrupt_server_size) - 1 - default_distrib_server, 0);
  619. WARN_ON(status < 0);
  620. /* Allow IPIs again... */
  621. xics_set_cpu_priority(DEFAULT_PRIORITY);
  622. for_each_irq(virq) {
  623. struct irq_desc *desc;
  624. int xics_status[2];
  625. unsigned long flags;
  626. /* We cant set affinity on ISA interrupts */
  627. if (virq < NUM_ISA_INTERRUPTS)
  628. continue;
  629. if (irq_map[virq].host != xics_host)
  630. continue;
  631. irq = (unsigned int)irq_map[virq].hwirq;
  632. /* We need to get IPIs still. */
  633. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  634. continue;
  635. desc = get_irq_desc(virq);
  636. /* We only need to migrate enabled IRQS */
  637. if (desc == NULL || desc->chip == NULL
  638. || desc->action == NULL
  639. || desc->chip->set_affinity == NULL)
  640. continue;
  641. spin_lock_irqsave(&desc->lock, flags);
  642. status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
  643. if (status) {
  644. printk(KERN_ERR "migrate_irqs_away: irq=%u "
  645. "ibm,get-xive returns %d\n",
  646. virq, status);
  647. goto unlock;
  648. }
  649. /*
  650. * We only support delivery to all cpus or to one cpu.
  651. * The irq has to be migrated only in the single cpu
  652. * case.
  653. */
  654. if (xics_status[0] != hw_cpu)
  655. goto unlock;
  656. printk(KERN_WARNING "IRQ %u affinity broken off cpu %u\n",
  657. virq, cpu);
  658. /* Reset affinity to all cpus */
  659. irq_desc[virq].affinity = CPU_MASK_ALL;
  660. desc->chip->set_affinity(virq, CPU_MASK_ALL);
  661. unlock:
  662. spin_unlock_irqrestore(&desc->lock, flags);
  663. }
  664. }
  665. #endif