xics.c 20 KB

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