xics.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  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 0
  304. if (test_and_clear_bit(PPC_MSG_MIGRATE_TASK,
  305. &xics_ipi_message[cpu].value)) {
  306. mb();
  307. smp_message_recv(PPC_MSG_MIGRATE_TASK);
  308. }
  309. #endif
  310. #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
  311. if (test_and_clear_bit(PPC_MSG_DEBUGGER_BREAK,
  312. &xics_ipi_message[cpu].value)) {
  313. mb();
  314. smp_message_recv(PPC_MSG_DEBUGGER_BREAK);
  315. }
  316. #endif
  317. }
  318. return IRQ_HANDLED;
  319. }
  320. static irqreturn_t xics_ipi_action_direct(int irq, void *dev_id)
  321. {
  322. int cpu = smp_processor_id();
  323. direct_qirr_info(cpu, 0xff);
  324. return xics_ipi_dispatch(cpu);
  325. }
  326. static irqreturn_t xics_ipi_action_lpar(int irq, void *dev_id)
  327. {
  328. int cpu = smp_processor_id();
  329. lpar_qirr_info(cpu, 0xff);
  330. return xics_ipi_dispatch(cpu);
  331. }
  332. void xics_cause_IPI(int cpu)
  333. {
  334. if (firmware_has_feature(FW_FEATURE_LPAR))
  335. lpar_qirr_info(cpu, IPI_PRIORITY);
  336. else
  337. direct_qirr_info(cpu, IPI_PRIORITY);
  338. }
  339. #endif /* CONFIG_SMP */
  340. static void xics_set_cpu_priority(unsigned char cppr)
  341. {
  342. if (firmware_has_feature(FW_FEATURE_LPAR))
  343. lpar_cppr_info(cppr);
  344. else
  345. direct_cppr_info(cppr);
  346. iosync();
  347. }
  348. static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
  349. {
  350. unsigned int irq;
  351. int status;
  352. int xics_status[2];
  353. int irq_server;
  354. irq = (unsigned int)irq_map[virq].hwirq;
  355. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  356. return;
  357. status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
  358. if (status) {
  359. printk(KERN_ERR "xics_set_affinity: irq=%u ibm,get-xive "
  360. "returns %d\n", irq, status);
  361. return;
  362. }
  363. /*
  364. * For the moment only implement delivery to all cpus or one cpu.
  365. * Get current irq_server for the given irq
  366. */
  367. irq_server = get_irq_server(virq, 1);
  368. if (irq_server == -1) {
  369. char cpulist[128];
  370. cpumask_scnprintf(cpulist, sizeof(cpulist), cpumask);
  371. printk(KERN_WARNING "xics_set_affinity: No online cpus in "
  372. "the mask %s for irq %d\n", cpulist, virq);
  373. return;
  374. }
  375. status = rtas_call(ibm_set_xive, 3, 1, NULL,
  376. irq, irq_server, xics_status[1]);
  377. if (status) {
  378. printk(KERN_ERR "xics_set_affinity: irq=%u ibm,set-xive "
  379. "returns %d\n", irq, status);
  380. return;
  381. }
  382. }
  383. void xics_setup_cpu(void)
  384. {
  385. xics_set_cpu_priority(0xff);
  386. /*
  387. * Put the calling processor into the GIQ. This is really only
  388. * necessary from a secondary thread as the OF start-cpu interface
  389. * performs this function for us on primary threads.
  390. *
  391. * XXX: undo of teardown on kexec needs this too, as may hotplug
  392. */
  393. rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  394. (1UL << interrupt_server_size) - 1 - default_distrib_server, 1);
  395. }
  396. static struct irq_chip xics_pic_direct = {
  397. .typename = " XICS ",
  398. .startup = xics_startup,
  399. .mask = xics_mask_irq,
  400. .unmask = xics_unmask_irq,
  401. .eoi = xics_eoi_direct,
  402. .set_affinity = xics_set_affinity
  403. };
  404. static struct irq_chip xics_pic_lpar = {
  405. .typename = " XICS ",
  406. .startup = xics_startup,
  407. .mask = xics_mask_irq,
  408. .unmask = xics_unmask_irq,
  409. .eoi = xics_eoi_lpar,
  410. .set_affinity = xics_set_affinity
  411. };
  412. /* Points to the irq_chip we're actually using */
  413. static struct irq_chip *xics_irq_chip;
  414. static int xics_host_match(struct irq_host *h, struct device_node *node)
  415. {
  416. /* IBM machines have interrupt parents of various funky types for things
  417. * like vdevices, events, etc... The trick we use here is to match
  418. * everything here except the legacy 8259 which is compatible "chrp,iic"
  419. */
  420. return !of_device_is_compatible(node, "chrp,iic");
  421. }
  422. static int xics_host_map(struct irq_host *h, unsigned int virq,
  423. irq_hw_number_t hw)
  424. {
  425. pr_debug("xics: map virq %d, hwirq 0x%lx\n", virq, hw);
  426. get_irq_desc(virq)->status |= IRQ_LEVEL;
  427. set_irq_chip_and_handler(virq, xics_irq_chip, handle_fasteoi_irq);
  428. return 0;
  429. }
  430. static int xics_host_xlate(struct irq_host *h, struct device_node *ct,
  431. u32 *intspec, unsigned int intsize,
  432. irq_hw_number_t *out_hwirq, unsigned int *out_flags)
  433. {
  434. /* Current xics implementation translates everything
  435. * to level. It is not technically right for MSIs but this
  436. * is irrelevant at this point. We might get smarter in the future
  437. */
  438. *out_hwirq = intspec[0];
  439. *out_flags = IRQ_TYPE_LEVEL_LOW;
  440. return 0;
  441. }
  442. static struct irq_host_ops xics_host_ops = {
  443. .match = xics_host_match,
  444. .map = xics_host_map,
  445. .xlate = xics_host_xlate,
  446. };
  447. static void __init xics_init_host(void)
  448. {
  449. if (firmware_has_feature(FW_FEATURE_LPAR))
  450. xics_irq_chip = &xics_pic_lpar;
  451. else
  452. xics_irq_chip = &xics_pic_direct;
  453. xics_host = irq_alloc_host(NULL, IRQ_HOST_MAP_TREE, 0, &xics_host_ops,
  454. XICS_IRQ_SPURIOUS);
  455. BUG_ON(xics_host == NULL);
  456. irq_set_default_host(xics_host);
  457. }
  458. static void __init xics_map_one_cpu(int hw_id, unsigned long addr,
  459. unsigned long size)
  460. {
  461. #ifdef CONFIG_SMP
  462. int i;
  463. /* This may look gross but it's good enough for now, we don't quite
  464. * have a hard -> linux processor id matching.
  465. */
  466. for_each_possible_cpu(i) {
  467. if (!cpu_present(i))
  468. continue;
  469. if (hw_id == get_hard_smp_processor_id(i)) {
  470. xics_per_cpu[i] = ioremap(addr, size);
  471. return;
  472. }
  473. }
  474. #else
  475. if (hw_id != 0)
  476. return;
  477. xics_per_cpu[0] = ioremap(addr, size);
  478. #endif /* CONFIG_SMP */
  479. }
  480. static void __init xics_init_one_node(struct device_node *np,
  481. unsigned int *indx)
  482. {
  483. unsigned int ilen;
  484. const u32 *ireg;
  485. /* This code does the theorically broken assumption that the interrupt
  486. * server numbers are the same as the hard CPU numbers.
  487. * This happens to be the case so far but we are playing with fire...
  488. * should be fixed one of these days. -BenH.
  489. */
  490. ireg = of_get_property(np, "ibm,interrupt-server-ranges", NULL);
  491. /* Do that ever happen ? we'll know soon enough... but even good'old
  492. * f80 does have that property ..
  493. */
  494. WARN_ON(ireg == NULL);
  495. if (ireg) {
  496. /*
  497. * set node starting index for this node
  498. */
  499. *indx = *ireg;
  500. }
  501. ireg = of_get_property(np, "reg", &ilen);
  502. if (!ireg)
  503. panic("xics_init_IRQ: can't find interrupt reg property");
  504. while (ilen >= (4 * sizeof(u32))) {
  505. unsigned long addr, size;
  506. /* XXX Use proper OF parsing code here !!! */
  507. addr = (unsigned long)*ireg++ << 32;
  508. ilen -= sizeof(u32);
  509. addr |= *ireg++;
  510. ilen -= sizeof(u32);
  511. size = (unsigned long)*ireg++ << 32;
  512. ilen -= sizeof(u32);
  513. size |= *ireg++;
  514. ilen -= sizeof(u32);
  515. xics_map_one_cpu(*indx, addr, size);
  516. (*indx)++;
  517. }
  518. }
  519. void __init xics_init_IRQ(void)
  520. {
  521. struct device_node *np;
  522. u32 indx = 0;
  523. int found = 0;
  524. ppc64_boot_msg(0x20, "XICS Init");
  525. ibm_get_xive = rtas_token("ibm,get-xive");
  526. ibm_set_xive = rtas_token("ibm,set-xive");
  527. ibm_int_on = rtas_token("ibm,int-on");
  528. ibm_int_off = rtas_token("ibm,int-off");
  529. for_each_node_by_type(np, "PowerPC-External-Interrupt-Presentation") {
  530. found = 1;
  531. if (firmware_has_feature(FW_FEATURE_LPAR))
  532. break;
  533. xics_init_one_node(np, &indx);
  534. }
  535. if (found == 0)
  536. return;
  537. xics_init_host();
  538. xics_update_irq_servers();
  539. if (firmware_has_feature(FW_FEATURE_LPAR))
  540. ppc_md.get_irq = xics_get_irq_lpar;
  541. else
  542. ppc_md.get_irq = xics_get_irq_direct;
  543. xics_setup_cpu();
  544. ppc64_boot_msg(0x21, "XICS Done");
  545. }
  546. #ifdef CONFIG_SMP
  547. void xics_request_IPIs(void)
  548. {
  549. unsigned int ipi;
  550. int rc;
  551. ipi = irq_create_mapping(xics_host, XICS_IPI);
  552. BUG_ON(ipi == NO_IRQ);
  553. /*
  554. * IPIs are marked IRQF_DISABLED as they must run with irqs
  555. * disabled
  556. */
  557. set_irq_handler(ipi, handle_percpu_irq);
  558. if (firmware_has_feature(FW_FEATURE_LPAR))
  559. rc = request_irq(ipi, xics_ipi_action_lpar, IRQF_DISABLED,
  560. "IPI", NULL);
  561. else
  562. rc = request_irq(ipi, xics_ipi_action_direct, IRQF_DISABLED,
  563. "IPI", NULL);
  564. BUG_ON(rc);
  565. }
  566. #endif /* CONFIG_SMP */
  567. void xics_teardown_cpu(void)
  568. {
  569. int cpu = smp_processor_id();
  570. xics_set_cpu_priority(0);
  571. /*
  572. * Clear IPI
  573. */
  574. if (firmware_has_feature(FW_FEATURE_LPAR))
  575. lpar_qirr_info(cpu, 0xff);
  576. else
  577. direct_qirr_info(cpu, 0xff);
  578. }
  579. void xics_kexec_teardown_cpu(int secondary)
  580. {
  581. unsigned int ipi;
  582. struct irq_desc *desc;
  583. xics_teardown_cpu();
  584. /*
  585. * we need to EOI the IPI
  586. *
  587. * probably need to check all the other interrupts too
  588. * should we be flagging idle loop instead?
  589. * or creating some task to be scheduled?
  590. */
  591. ipi = irq_find_mapping(xics_host, XICS_IPI);
  592. if (ipi == XICS_IRQ_SPURIOUS)
  593. return;
  594. desc = get_irq_desc(ipi);
  595. if (desc->chip && desc->chip->eoi)
  596. desc->chip->eoi(ipi);
  597. /*
  598. * Some machines need to have at least one cpu in the GIQ,
  599. * so leave the master cpu in the group.
  600. */
  601. if (secondary)
  602. rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  603. (1UL << interrupt_server_size) - 1 -
  604. default_distrib_server, 0);
  605. }
  606. #ifdef CONFIG_HOTPLUG_CPU
  607. /* Interrupts are disabled. */
  608. void xics_migrate_irqs_away(void)
  609. {
  610. int status;
  611. int cpu = smp_processor_id(), hw_cpu = hard_smp_processor_id();
  612. unsigned int irq, virq;
  613. /* Reject any interrupt that was queued to us... */
  614. xics_set_cpu_priority(0);
  615. /* remove ourselves from the global interrupt queue */
  616. status = rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  617. (1UL << interrupt_server_size) - 1 - default_distrib_server, 0);
  618. WARN_ON(status < 0);
  619. /* Allow IPIs again... */
  620. xics_set_cpu_priority(DEFAULT_PRIORITY);
  621. for_each_irq(virq) {
  622. struct irq_desc *desc;
  623. int xics_status[2];
  624. unsigned long flags;
  625. /* We cant set affinity on ISA interrupts */
  626. if (virq < NUM_ISA_INTERRUPTS)
  627. continue;
  628. if (irq_map[virq].host != xics_host)
  629. continue;
  630. irq = (unsigned int)irq_map[virq].hwirq;
  631. /* We need to get IPIs still. */
  632. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  633. continue;
  634. desc = get_irq_desc(virq);
  635. /* We only need to migrate enabled IRQS */
  636. if (desc == NULL || desc->chip == NULL
  637. || desc->action == NULL
  638. || desc->chip->set_affinity == NULL)
  639. continue;
  640. spin_lock_irqsave(&desc->lock, flags);
  641. status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
  642. if (status) {
  643. printk(KERN_ERR "migrate_irqs_away: irq=%u "
  644. "ibm,get-xive returns %d\n",
  645. virq, status);
  646. goto unlock;
  647. }
  648. /*
  649. * We only support delivery to all cpus or to one cpu.
  650. * The irq has to be migrated only in the single cpu
  651. * case.
  652. */
  653. if (xics_status[0] != hw_cpu)
  654. goto unlock;
  655. printk(KERN_WARNING "IRQ %u affinity broken off cpu %u\n",
  656. virq, cpu);
  657. /* Reset affinity to all cpus */
  658. irq_desc[virq].affinity = CPU_MASK_ALL;
  659. desc->chip->set_affinity(virq, CPU_MASK_ALL);
  660. unlock:
  661. spin_unlock_irqrestore(&desc->lock, flags);
  662. }
  663. }
  664. #endif