xics.c 19 KB

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