xics.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  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 (!distribute_irqs)
  167. return default_server;
  168. if (!cpus_equal(cpumask, CPU_MASK_ALL)) {
  169. cpus_and(tmp, cpu_online_map, cpumask);
  170. server = first_cpu(tmp);
  171. if (server < NR_CPUS)
  172. return get_hard_smp_processor_id(server);
  173. if (strict_check)
  174. return -1;
  175. }
  176. if (cpus_equal(cpu_online_map, cpu_present_map))
  177. return default_distrib_server;
  178. return default_server;
  179. }
  180. #else
  181. static int get_irq_server(unsigned int virq, unsigned int strict_check)
  182. {
  183. return default_server;
  184. }
  185. #endif
  186. static void xics_unmask_irq(unsigned int virq)
  187. {
  188. unsigned int irq;
  189. int call_status;
  190. int server;
  191. pr_debug("xics: unmask virq %d\n", virq);
  192. irq = (unsigned int)irq_map[virq].hwirq;
  193. pr_debug(" -> map to hwirq 0x%x\n", irq);
  194. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  195. return;
  196. server = get_irq_server(virq, 0);
  197. call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, server,
  198. DEFAULT_PRIORITY);
  199. if (call_status != 0) {
  200. printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_set_xive "
  201. "returned %d\n", irq, call_status);
  202. printk("set_xive %x, server %x\n", ibm_set_xive, server);
  203. return;
  204. }
  205. /* Now unmask the interrupt (often a no-op) */
  206. call_status = rtas_call(ibm_int_on, 1, 1, NULL, irq);
  207. if (call_status != 0) {
  208. printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_int_on "
  209. "returned %d\n", irq, call_status);
  210. return;
  211. }
  212. }
  213. static void xics_mask_real_irq(unsigned int irq)
  214. {
  215. int call_status;
  216. if (irq == XICS_IPI)
  217. return;
  218. call_status = rtas_call(ibm_int_off, 1, 1, NULL, irq);
  219. if (call_status != 0) {
  220. printk(KERN_ERR "xics_disable_real_irq: irq=%u: "
  221. "ibm_int_off returned %d\n", irq, call_status);
  222. return;
  223. }
  224. /* Have to set XIVE to 0xff to be able to remove a slot */
  225. call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq,
  226. default_server, 0xff);
  227. if (call_status != 0) {
  228. printk(KERN_ERR "xics_disable_irq: irq=%u: ibm_set_xive(0xff)"
  229. " returned %d\n", irq, call_status);
  230. return;
  231. }
  232. }
  233. static void xics_mask_irq(unsigned int virq)
  234. {
  235. unsigned int irq;
  236. pr_debug("xics: mask virq %d\n", virq);
  237. irq = (unsigned int)irq_map[virq].hwirq;
  238. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  239. return;
  240. xics_mask_real_irq(irq);
  241. }
  242. static unsigned int xics_startup(unsigned int virq)
  243. {
  244. /* unmask it */
  245. xics_unmask_irq(virq);
  246. return 0;
  247. }
  248. static void xics_eoi_direct(unsigned int virq)
  249. {
  250. unsigned int irq = (unsigned int)irq_map[virq].hwirq;
  251. iosync();
  252. direct_xirr_info_set((0xff << 24) | irq);
  253. }
  254. static void xics_eoi_lpar(unsigned int virq)
  255. {
  256. unsigned int irq = (unsigned int)irq_map[virq].hwirq;
  257. iosync();
  258. lpar_xirr_info_set((0xff << 24) | irq);
  259. }
  260. static inline unsigned int xics_xirr_vector(unsigned int xirr)
  261. {
  262. /*
  263. * The top byte is the old cppr, to be restored on EOI.
  264. * The remaining 24 bits are the vector.
  265. */
  266. return xirr & 0x00ffffff;
  267. }
  268. static void xics_mask_unknown_vec(unsigned int vec)
  269. {
  270. printk(KERN_ERR "Interrupt %u (real) is invalid, disabling it.\n", vec);
  271. xics_mask_real_irq(vec);
  272. }
  273. static unsigned int xics_get_irq_direct(void)
  274. {
  275. unsigned int xirr = direct_xirr_info_get();
  276. unsigned int vec = xics_xirr_vector(xirr);
  277. unsigned int irq;
  278. if (vec == XICS_IRQ_SPURIOUS)
  279. return NO_IRQ;
  280. irq = irq_radix_revmap_lookup(xics_host, vec);
  281. if (likely(irq != NO_IRQ))
  282. return irq;
  283. /* We don't have a linux mapping, so have rtas mask it. */
  284. xics_mask_unknown_vec(vec);
  285. /* We might learn about it later, so EOI it */
  286. direct_xirr_info_set(xirr);
  287. return NO_IRQ;
  288. }
  289. static unsigned int xics_get_irq_lpar(void)
  290. {
  291. unsigned int xirr = lpar_xirr_info_get();
  292. unsigned int vec = xics_xirr_vector(xirr);
  293. unsigned int irq;
  294. if (vec == XICS_IRQ_SPURIOUS)
  295. return NO_IRQ;
  296. irq = irq_radix_revmap_lookup(xics_host, vec);
  297. if (likely(irq != NO_IRQ))
  298. return irq;
  299. /* We don't have a linux mapping, so have RTAS mask it. */
  300. xics_mask_unknown_vec(vec);
  301. /* We might learn about it later, so EOI it */
  302. lpar_xirr_info_set(xirr);
  303. return NO_IRQ;
  304. }
  305. #ifdef CONFIG_SMP
  306. static irqreturn_t xics_ipi_dispatch(int cpu)
  307. {
  308. WARN_ON(cpu_is_offline(cpu));
  309. while (xics_ipi_message[cpu].value) {
  310. if (test_and_clear_bit(PPC_MSG_CALL_FUNCTION,
  311. &xics_ipi_message[cpu].value)) {
  312. mb();
  313. smp_message_recv(PPC_MSG_CALL_FUNCTION);
  314. }
  315. if (test_and_clear_bit(PPC_MSG_RESCHEDULE,
  316. &xics_ipi_message[cpu].value)) {
  317. mb();
  318. smp_message_recv(PPC_MSG_RESCHEDULE);
  319. }
  320. if (test_and_clear_bit(PPC_MSG_CALL_FUNC_SINGLE,
  321. &xics_ipi_message[cpu].value)) {
  322. mb();
  323. smp_message_recv(PPC_MSG_CALL_FUNC_SINGLE);
  324. }
  325. #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
  326. if (test_and_clear_bit(PPC_MSG_DEBUGGER_BREAK,
  327. &xics_ipi_message[cpu].value)) {
  328. mb();
  329. smp_message_recv(PPC_MSG_DEBUGGER_BREAK);
  330. }
  331. #endif
  332. }
  333. return IRQ_HANDLED;
  334. }
  335. static irqreturn_t xics_ipi_action_direct(int irq, void *dev_id)
  336. {
  337. int cpu = smp_processor_id();
  338. direct_qirr_info(cpu, 0xff);
  339. return xics_ipi_dispatch(cpu);
  340. }
  341. static irqreturn_t xics_ipi_action_lpar(int irq, void *dev_id)
  342. {
  343. int cpu = smp_processor_id();
  344. lpar_qirr_info(cpu, 0xff);
  345. return xics_ipi_dispatch(cpu);
  346. }
  347. void xics_cause_IPI(int cpu)
  348. {
  349. if (firmware_has_feature(FW_FEATURE_LPAR))
  350. lpar_qirr_info(cpu, IPI_PRIORITY);
  351. else
  352. direct_qirr_info(cpu, IPI_PRIORITY);
  353. }
  354. #endif /* CONFIG_SMP */
  355. static void xics_set_cpu_priority(unsigned char cppr)
  356. {
  357. if (firmware_has_feature(FW_FEATURE_LPAR))
  358. lpar_cppr_info(cppr);
  359. else
  360. direct_cppr_info(cppr);
  361. iosync();
  362. }
  363. static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
  364. {
  365. unsigned int irq;
  366. int status;
  367. int xics_status[2];
  368. int irq_server;
  369. irq = (unsigned int)irq_map[virq].hwirq;
  370. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  371. return;
  372. status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
  373. if (status) {
  374. printk(KERN_ERR "xics_set_affinity: irq=%u ibm,get-xive "
  375. "returns %d\n", irq, status);
  376. return;
  377. }
  378. /*
  379. * For the moment only implement delivery to all cpus or one cpu.
  380. * Get current irq_server for the given irq
  381. */
  382. irq_server = get_irq_server(virq, 1);
  383. if (irq_server == -1) {
  384. char cpulist[128];
  385. cpumask_scnprintf(cpulist, sizeof(cpulist), cpumask);
  386. printk(KERN_WARNING "xics_set_affinity: No online cpus in "
  387. "the mask %s for irq %d\n", cpulist, virq);
  388. return;
  389. }
  390. status = rtas_call(ibm_set_xive, 3, 1, NULL,
  391. irq, irq_server, xics_status[1]);
  392. if (status) {
  393. printk(KERN_ERR "xics_set_affinity: irq=%u ibm,set-xive "
  394. "returns %d\n", irq, status);
  395. return;
  396. }
  397. }
  398. void xics_setup_cpu(void)
  399. {
  400. xics_set_cpu_priority(0xff);
  401. /*
  402. * Put the calling processor into the GIQ. This is really only
  403. * necessary from a secondary thread as the OF start-cpu interface
  404. * performs this function for us on primary threads.
  405. *
  406. * XXX: undo of teardown on kexec needs this too, as may hotplug
  407. */
  408. rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  409. (1UL << interrupt_server_size) - 1 - default_distrib_server, 1);
  410. }
  411. static struct irq_chip xics_pic_direct = {
  412. .typename = " XICS ",
  413. .startup = xics_startup,
  414. .mask = xics_mask_irq,
  415. .unmask = xics_unmask_irq,
  416. .eoi = xics_eoi_direct,
  417. .set_affinity = xics_set_affinity
  418. };
  419. static struct irq_chip xics_pic_lpar = {
  420. .typename = " XICS ",
  421. .startup = xics_startup,
  422. .mask = xics_mask_irq,
  423. .unmask = xics_unmask_irq,
  424. .eoi = xics_eoi_lpar,
  425. .set_affinity = xics_set_affinity
  426. };
  427. /* Points to the irq_chip we're actually using */
  428. static struct irq_chip *xics_irq_chip;
  429. static int xics_host_match(struct irq_host *h, struct device_node *node)
  430. {
  431. /* IBM machines have interrupt parents of various funky types for things
  432. * like vdevices, events, etc... The trick we use here is to match
  433. * everything here except the legacy 8259 which is compatible "chrp,iic"
  434. */
  435. return !of_device_is_compatible(node, "chrp,iic");
  436. }
  437. static int xics_host_map(struct irq_host *h, unsigned int virq,
  438. irq_hw_number_t hw)
  439. {
  440. pr_debug("xics: map virq %d, hwirq 0x%lx\n", virq, hw);
  441. /* Insert the interrupt mapping into the radix tree for fast lookup */
  442. irq_radix_revmap_insert(xics_host, virq, hw);
  443. get_irq_desc(virq)->status |= IRQ_LEVEL;
  444. set_irq_chip_and_handler(virq, xics_irq_chip, handle_fasteoi_irq);
  445. return 0;
  446. }
  447. static int xics_host_xlate(struct irq_host *h, struct device_node *ct,
  448. u32 *intspec, unsigned int intsize,
  449. irq_hw_number_t *out_hwirq, unsigned int *out_flags)
  450. {
  451. /* Current xics implementation translates everything
  452. * to level. It is not technically right for MSIs but this
  453. * is irrelevant at this point. We might get smarter in the future
  454. */
  455. *out_hwirq = intspec[0];
  456. *out_flags = IRQ_TYPE_LEVEL_LOW;
  457. return 0;
  458. }
  459. static struct irq_host_ops xics_host_ops = {
  460. .match = xics_host_match,
  461. .map = xics_host_map,
  462. .xlate = xics_host_xlate,
  463. };
  464. static void __init xics_init_host(void)
  465. {
  466. if (firmware_has_feature(FW_FEATURE_LPAR))
  467. xics_irq_chip = &xics_pic_lpar;
  468. else
  469. xics_irq_chip = &xics_pic_direct;
  470. xics_host = irq_alloc_host(NULL, IRQ_HOST_MAP_TREE, 0, &xics_host_ops,
  471. XICS_IRQ_SPURIOUS);
  472. BUG_ON(xics_host == NULL);
  473. irq_set_default_host(xics_host);
  474. }
  475. static void __init xics_map_one_cpu(int hw_id, unsigned long addr,
  476. unsigned long size)
  477. {
  478. #ifdef CONFIG_SMP
  479. int i;
  480. /* This may look gross but it's good enough for now, we don't quite
  481. * have a hard -> linux processor id matching.
  482. */
  483. for_each_possible_cpu(i) {
  484. if (!cpu_present(i))
  485. continue;
  486. if (hw_id == get_hard_smp_processor_id(i)) {
  487. xics_per_cpu[i] = ioremap(addr, size);
  488. return;
  489. }
  490. }
  491. #else
  492. if (hw_id != 0)
  493. return;
  494. xics_per_cpu[0] = ioremap(addr, size);
  495. #endif /* CONFIG_SMP */
  496. }
  497. static void __init xics_init_one_node(struct device_node *np,
  498. unsigned int *indx)
  499. {
  500. unsigned int ilen;
  501. const u32 *ireg;
  502. /* This code does the theorically broken assumption that the interrupt
  503. * server numbers are the same as the hard CPU numbers.
  504. * This happens to be the case so far but we are playing with fire...
  505. * should be fixed one of these days. -BenH.
  506. */
  507. ireg = of_get_property(np, "ibm,interrupt-server-ranges", NULL);
  508. /* Do that ever happen ? we'll know soon enough... but even good'old
  509. * f80 does have that property ..
  510. */
  511. WARN_ON(ireg == NULL);
  512. if (ireg) {
  513. /*
  514. * set node starting index for this node
  515. */
  516. *indx = *ireg;
  517. }
  518. ireg = of_get_property(np, "reg", &ilen);
  519. if (!ireg)
  520. panic("xics_init_IRQ: can't find interrupt reg property");
  521. while (ilen >= (4 * sizeof(u32))) {
  522. unsigned long addr, size;
  523. /* XXX Use proper OF parsing code here !!! */
  524. addr = (unsigned long)*ireg++ << 32;
  525. ilen -= sizeof(u32);
  526. addr |= *ireg++;
  527. ilen -= sizeof(u32);
  528. size = (unsigned long)*ireg++ << 32;
  529. ilen -= sizeof(u32);
  530. size |= *ireg++;
  531. ilen -= sizeof(u32);
  532. xics_map_one_cpu(*indx, addr, size);
  533. (*indx)++;
  534. }
  535. }
  536. void __init xics_init_IRQ(void)
  537. {
  538. struct device_node *np;
  539. u32 indx = 0;
  540. int found = 0;
  541. ppc64_boot_msg(0x20, "XICS Init");
  542. ibm_get_xive = rtas_token("ibm,get-xive");
  543. ibm_set_xive = rtas_token("ibm,set-xive");
  544. ibm_int_on = rtas_token("ibm,int-on");
  545. ibm_int_off = rtas_token("ibm,int-off");
  546. for_each_node_by_type(np, "PowerPC-External-Interrupt-Presentation") {
  547. found = 1;
  548. if (firmware_has_feature(FW_FEATURE_LPAR))
  549. break;
  550. xics_init_one_node(np, &indx);
  551. }
  552. if (found == 0)
  553. return;
  554. xics_update_irq_servers();
  555. xics_init_host();
  556. if (firmware_has_feature(FW_FEATURE_LPAR))
  557. ppc_md.get_irq = xics_get_irq_lpar;
  558. else
  559. ppc_md.get_irq = xics_get_irq_direct;
  560. xics_setup_cpu();
  561. ppc64_boot_msg(0x21, "XICS Done");
  562. }
  563. #ifdef CONFIG_SMP
  564. void xics_request_IPIs(void)
  565. {
  566. unsigned int ipi;
  567. int rc;
  568. ipi = irq_create_mapping(xics_host, XICS_IPI);
  569. BUG_ON(ipi == NO_IRQ);
  570. /*
  571. * IPIs are marked IRQF_DISABLED as they must run with irqs
  572. * disabled
  573. */
  574. set_irq_handler(ipi, handle_percpu_irq);
  575. if (firmware_has_feature(FW_FEATURE_LPAR))
  576. rc = request_irq(ipi, xics_ipi_action_lpar, IRQF_DISABLED,
  577. "IPI", NULL);
  578. else
  579. rc = request_irq(ipi, xics_ipi_action_direct, IRQF_DISABLED,
  580. "IPI", NULL);
  581. BUG_ON(rc);
  582. }
  583. #endif /* CONFIG_SMP */
  584. void xics_teardown_cpu(void)
  585. {
  586. int cpu = smp_processor_id();
  587. xics_set_cpu_priority(0);
  588. /*
  589. * Clear IPI
  590. */
  591. if (firmware_has_feature(FW_FEATURE_LPAR))
  592. lpar_qirr_info(cpu, 0xff);
  593. else
  594. direct_qirr_info(cpu, 0xff);
  595. }
  596. void xics_kexec_teardown_cpu(int secondary)
  597. {
  598. unsigned int ipi;
  599. struct irq_desc *desc;
  600. xics_teardown_cpu();
  601. /*
  602. * we need to EOI the IPI
  603. *
  604. * probably need to check all the other interrupts too
  605. * should we be flagging idle loop instead?
  606. * or creating some task to be scheduled?
  607. */
  608. ipi = irq_find_mapping(xics_host, XICS_IPI);
  609. if (ipi == XICS_IRQ_SPURIOUS)
  610. return;
  611. desc = get_irq_desc(ipi);
  612. if (desc->chip && desc->chip->eoi)
  613. desc->chip->eoi(ipi);
  614. /*
  615. * Some machines need to have at least one cpu in the GIQ,
  616. * so leave the master cpu in the group.
  617. */
  618. if (secondary)
  619. rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  620. (1UL << interrupt_server_size) - 1 -
  621. default_distrib_server, 0);
  622. }
  623. #ifdef CONFIG_HOTPLUG_CPU
  624. /* Interrupts are disabled. */
  625. void xics_migrate_irqs_away(void)
  626. {
  627. int status;
  628. int cpu = smp_processor_id(), hw_cpu = hard_smp_processor_id();
  629. unsigned int irq, virq;
  630. /* If we used to be the default server, move to the new "boot_cpuid" */
  631. if (hw_cpu == default_server)
  632. xics_update_irq_servers();
  633. /* Reject any interrupt that was queued to us... */
  634. xics_set_cpu_priority(0);
  635. /* remove ourselves from the global interrupt queue */
  636. status = rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  637. (1UL << interrupt_server_size) - 1 - default_distrib_server, 0);
  638. WARN_ON(status < 0);
  639. /* Allow IPIs again... */
  640. xics_set_cpu_priority(DEFAULT_PRIORITY);
  641. for_each_irq(virq) {
  642. struct irq_desc *desc;
  643. int xics_status[2];
  644. unsigned long flags;
  645. /* We cant set affinity on ISA interrupts */
  646. if (virq < NUM_ISA_INTERRUPTS)
  647. continue;
  648. if (irq_map[virq].host != xics_host)
  649. continue;
  650. irq = (unsigned int)irq_map[virq].hwirq;
  651. /* We need to get IPIs still. */
  652. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  653. continue;
  654. desc = get_irq_desc(virq);
  655. /* We only need to migrate enabled IRQS */
  656. if (desc == NULL || desc->chip == NULL
  657. || desc->action == NULL
  658. || desc->chip->set_affinity == NULL)
  659. continue;
  660. spin_lock_irqsave(&desc->lock, flags);
  661. status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
  662. if (status) {
  663. printk(KERN_ERR "migrate_irqs_away: irq=%u "
  664. "ibm,get-xive returns %d\n",
  665. virq, status);
  666. goto unlock;
  667. }
  668. /*
  669. * We only support delivery to all cpus or to one cpu.
  670. * The irq has to be migrated only in the single cpu
  671. * case.
  672. */
  673. if (xics_status[0] != hw_cpu)
  674. goto unlock;
  675. printk(KERN_WARNING "IRQ %u affinity broken off cpu %u\n",
  676. virq, cpu);
  677. /* Reset affinity to all cpus */
  678. irq_desc[virq].affinity = CPU_MASK_ALL;
  679. desc->chip->set_affinity(virq, CPU_MASK_ALL);
  680. unlock:
  681. spin_unlock_irqrestore(&desc->lock, flags);
  682. }
  683. }
  684. #endif