xics.c 20 KB

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