xics.c 20 KB

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