xics.c 21 KB

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