xics.c 18 KB

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