xics.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. /*
  2. * arch/powerpc/platforms/pseries/xics.c
  3. *
  4. * Copyright 2000 IBM Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #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 void 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;
  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;
  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;
  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;
  299. }
  300. }
  301. static struct irq_chip xics_pic_direct = {
  302. .typename = " XICS ",
  303. .startup = xics_startup,
  304. .mask = xics_mask_irq,
  305. .unmask = xics_unmask_irq,
  306. .eoi = xics_eoi_direct,
  307. .set_affinity = xics_set_affinity
  308. };
  309. static struct irq_chip xics_pic_lpar = {
  310. .typename = " XICS ",
  311. .startup = xics_startup,
  312. .mask = xics_mask_irq,
  313. .unmask = xics_unmask_irq,
  314. .eoi = xics_eoi_lpar,
  315. .set_affinity = xics_set_affinity
  316. };
  317. /* Interface to arch irq controller subsystem layer */
  318. /* Points to the irq_chip we're actually using */
  319. static struct irq_chip *xics_irq_chip;
  320. static int xics_host_match(struct irq_host *h, struct device_node *node)
  321. {
  322. /* IBM machines have interrupt parents of various funky types for things
  323. * like vdevices, events, etc... The trick we use here is to match
  324. * everything here except the legacy 8259 which is compatible "chrp,iic"
  325. */
  326. return !of_device_is_compatible(node, "chrp,iic");
  327. }
  328. static int xics_host_map(struct irq_host *h, unsigned int virq,
  329. irq_hw_number_t hw)
  330. {
  331. pr_debug("xics: map virq %d, hwirq 0x%lx\n", virq, hw);
  332. /* Insert the interrupt mapping into the radix tree for fast lookup */
  333. irq_radix_revmap_insert(xics_host, virq, hw);
  334. get_irq_desc(virq)->status |= IRQ_LEVEL;
  335. set_irq_chip_and_handler(virq, xics_irq_chip, handle_fasteoi_irq);
  336. return 0;
  337. }
  338. static int xics_host_xlate(struct irq_host *h, struct device_node *ct,
  339. u32 *intspec, unsigned int intsize,
  340. irq_hw_number_t *out_hwirq, unsigned int *out_flags)
  341. {
  342. /* Current xics implementation translates everything
  343. * to level. It is not technically right for MSIs but this
  344. * is irrelevant at this point. We might get smarter in the future
  345. */
  346. *out_hwirq = intspec[0];
  347. *out_flags = IRQ_TYPE_LEVEL_LOW;
  348. return 0;
  349. }
  350. static struct irq_host_ops xics_host_ops = {
  351. .match = xics_host_match,
  352. .map = xics_host_map,
  353. .xlate = xics_host_xlate,
  354. };
  355. static void __init xics_init_host(void)
  356. {
  357. if (firmware_has_feature(FW_FEATURE_LPAR))
  358. xics_irq_chip = &xics_pic_lpar;
  359. else
  360. xics_irq_chip = &xics_pic_direct;
  361. xics_host = irq_alloc_host(NULL, IRQ_HOST_MAP_TREE, 0, &xics_host_ops,
  362. XICS_IRQ_SPURIOUS);
  363. BUG_ON(xics_host == NULL);
  364. irq_set_default_host(xics_host);
  365. }
  366. /* Inter-processor interrupt support */
  367. #ifdef CONFIG_SMP
  368. /*
  369. * XICS only has a single IPI, so encode the messages per CPU
  370. */
  371. struct xics_ipi_struct {
  372. unsigned long value;
  373. } ____cacheline_aligned;
  374. static struct xics_ipi_struct xics_ipi_message[NR_CPUS] __cacheline_aligned;
  375. static inline void smp_xics_do_message(int cpu, int msg)
  376. {
  377. set_bit(msg, &xics_ipi_message[cpu].value);
  378. mb();
  379. if (firmware_has_feature(FW_FEATURE_LPAR))
  380. lpar_qirr_info(cpu, IPI_PRIORITY);
  381. else
  382. direct_qirr_info(cpu, IPI_PRIORITY);
  383. }
  384. void smp_xics_message_pass(int target, int msg)
  385. {
  386. unsigned int i;
  387. if (target < NR_CPUS) {
  388. smp_xics_do_message(target, msg);
  389. } else {
  390. for_each_online_cpu(i) {
  391. if (target == MSG_ALL_BUT_SELF
  392. && i == smp_processor_id())
  393. continue;
  394. smp_xics_do_message(i, msg);
  395. }
  396. }
  397. }
  398. static irqreturn_t xics_ipi_dispatch(int cpu)
  399. {
  400. WARN_ON(cpu_is_offline(cpu));
  401. mb(); /* order mmio clearing qirr */
  402. while (xics_ipi_message[cpu].value) {
  403. if (test_and_clear_bit(PPC_MSG_CALL_FUNCTION,
  404. &xics_ipi_message[cpu].value)) {
  405. smp_message_recv(PPC_MSG_CALL_FUNCTION);
  406. }
  407. if (test_and_clear_bit(PPC_MSG_RESCHEDULE,
  408. &xics_ipi_message[cpu].value)) {
  409. smp_message_recv(PPC_MSG_RESCHEDULE);
  410. }
  411. if (test_and_clear_bit(PPC_MSG_CALL_FUNC_SINGLE,
  412. &xics_ipi_message[cpu].value)) {
  413. smp_message_recv(PPC_MSG_CALL_FUNC_SINGLE);
  414. }
  415. #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
  416. if (test_and_clear_bit(PPC_MSG_DEBUGGER_BREAK,
  417. &xics_ipi_message[cpu].value)) {
  418. smp_message_recv(PPC_MSG_DEBUGGER_BREAK);
  419. }
  420. #endif
  421. }
  422. return IRQ_HANDLED;
  423. }
  424. static irqreturn_t xics_ipi_action_direct(int irq, void *dev_id)
  425. {
  426. int cpu = smp_processor_id();
  427. direct_qirr_info(cpu, 0xff);
  428. return xics_ipi_dispatch(cpu);
  429. }
  430. static irqreturn_t xics_ipi_action_lpar(int irq, void *dev_id)
  431. {
  432. int cpu = smp_processor_id();
  433. lpar_qirr_info(cpu, 0xff);
  434. return xics_ipi_dispatch(cpu);
  435. }
  436. static void xics_request_ipi(void)
  437. {
  438. unsigned int ipi;
  439. int rc;
  440. ipi = irq_create_mapping(xics_host, XICS_IPI);
  441. BUG_ON(ipi == NO_IRQ);
  442. /*
  443. * IPIs are marked IRQF_DISABLED as they must run with irqs
  444. * disabled
  445. */
  446. set_irq_handler(ipi, handle_percpu_irq);
  447. if (firmware_has_feature(FW_FEATURE_LPAR))
  448. rc = request_irq(ipi, xics_ipi_action_lpar,
  449. IRQF_DISABLED|IRQF_PERCPU, "IPI", NULL);
  450. else
  451. rc = request_irq(ipi, xics_ipi_action_direct,
  452. IRQF_DISABLED|IRQF_PERCPU, "IPI", NULL);
  453. BUG_ON(rc);
  454. }
  455. int __init smp_xics_probe(void)
  456. {
  457. xics_request_ipi();
  458. return cpus_weight(cpu_possible_map);
  459. }
  460. #endif /* CONFIG_SMP */
  461. /* Initialization */
  462. static void xics_update_irq_servers(void)
  463. {
  464. int i, j;
  465. struct device_node *np;
  466. u32 ilen;
  467. const u32 *ireg;
  468. u32 hcpuid;
  469. /* Find the server numbers for the boot cpu. */
  470. np = of_get_cpu_node(boot_cpuid, NULL);
  471. BUG_ON(!np);
  472. ireg = of_get_property(np, "ibm,ppc-interrupt-gserver#s", &ilen);
  473. if (!ireg) {
  474. of_node_put(np);
  475. return;
  476. }
  477. i = ilen / sizeof(int);
  478. hcpuid = get_hard_smp_processor_id(boot_cpuid);
  479. /* Global interrupt distribution server is specified in the last
  480. * entry of "ibm,ppc-interrupt-gserver#s" property. Get the last
  481. * entry fom this property for current boot cpu id and use it as
  482. * default distribution server
  483. */
  484. for (j = 0; j < i; j += 2) {
  485. if (ireg[j] == hcpuid) {
  486. default_server = hcpuid;
  487. default_distrib_server = ireg[j+1];
  488. }
  489. }
  490. of_node_put(np);
  491. }
  492. static void __init xics_map_one_cpu(int hw_id, unsigned long addr,
  493. unsigned long size)
  494. {
  495. int i;
  496. /* This may look gross but it's good enough for now, we don't quite
  497. * have a hard -> linux processor id matching.
  498. */
  499. for_each_possible_cpu(i) {
  500. if (!cpu_present(i))
  501. continue;
  502. if (hw_id == get_hard_smp_processor_id(i)) {
  503. xics_per_cpu[i] = ioremap(addr, size);
  504. return;
  505. }
  506. }
  507. }
  508. static void __init xics_init_one_node(struct device_node *np,
  509. unsigned int *indx)
  510. {
  511. unsigned int ilen;
  512. const u32 *ireg;
  513. /* This code does the theorically broken assumption that the interrupt
  514. * server numbers are the same as the hard CPU numbers.
  515. * This happens to be the case so far but we are playing with fire...
  516. * should be fixed one of these days. -BenH.
  517. */
  518. ireg = of_get_property(np, "ibm,interrupt-server-ranges", NULL);
  519. /* Do that ever happen ? we'll know soon enough... but even good'old
  520. * f80 does have that property ..
  521. */
  522. WARN_ON(ireg == NULL);
  523. if (ireg) {
  524. /*
  525. * set node starting index for this node
  526. */
  527. *indx = *ireg;
  528. }
  529. ireg = of_get_property(np, "reg", &ilen);
  530. if (!ireg)
  531. panic("xics_init_IRQ: can't find interrupt reg property");
  532. while (ilen >= (4 * sizeof(u32))) {
  533. unsigned long addr, size;
  534. /* XXX Use proper OF parsing code here !!! */
  535. addr = (unsigned long)*ireg++ << 32;
  536. ilen -= sizeof(u32);
  537. addr |= *ireg++;
  538. ilen -= sizeof(u32);
  539. size = (unsigned long)*ireg++ << 32;
  540. ilen -= sizeof(u32);
  541. size |= *ireg++;
  542. ilen -= sizeof(u32);
  543. xics_map_one_cpu(*indx, addr, size);
  544. (*indx)++;
  545. }
  546. }
  547. void __init xics_init_IRQ(void)
  548. {
  549. struct device_node *np;
  550. u32 indx = 0;
  551. int found = 0;
  552. const u32 *isize;
  553. ppc64_boot_msg(0x20, "XICS Init");
  554. ibm_get_xive = rtas_token("ibm,get-xive");
  555. ibm_set_xive = rtas_token("ibm,set-xive");
  556. ibm_int_on = rtas_token("ibm,int-on");
  557. ibm_int_off = rtas_token("ibm,int-off");
  558. for_each_node_by_type(np, "PowerPC-External-Interrupt-Presentation") {
  559. found = 1;
  560. if (firmware_has_feature(FW_FEATURE_LPAR)) {
  561. of_node_put(np);
  562. break;
  563. }
  564. xics_init_one_node(np, &indx);
  565. }
  566. if (found == 0)
  567. return;
  568. /* get the bit size of server numbers */
  569. found = 0;
  570. for_each_compatible_node(np, NULL, "ibm,ppc-xics") {
  571. isize = of_get_property(np, "ibm,interrupt-server#-size", NULL);
  572. if (!isize)
  573. continue;
  574. if (!found) {
  575. interrupt_server_size = *isize;
  576. found = 1;
  577. } else if (*isize != interrupt_server_size) {
  578. printk(KERN_WARNING "XICS: "
  579. "mismatched ibm,interrupt-server#-size\n");
  580. interrupt_server_size = max(*isize,
  581. interrupt_server_size);
  582. }
  583. }
  584. xics_update_irq_servers();
  585. xics_init_host();
  586. if (firmware_has_feature(FW_FEATURE_LPAR))
  587. ppc_md.get_irq = xics_get_irq_lpar;
  588. else
  589. ppc_md.get_irq = xics_get_irq_direct;
  590. xics_setup_cpu();
  591. ppc64_boot_msg(0x21, "XICS Done");
  592. }
  593. /* Cpu startup, shutdown, and hotplug */
  594. static void xics_set_cpu_priority(unsigned char cppr)
  595. {
  596. if (firmware_has_feature(FW_FEATURE_LPAR))
  597. lpar_cppr_info(cppr);
  598. else
  599. direct_cppr_info(cppr);
  600. iosync();
  601. }
  602. /* Have the calling processor join or leave the specified global queue */
  603. static void xics_set_cpu_giq(unsigned int gserver, unsigned int join)
  604. {
  605. int index;
  606. int status;
  607. if (!rtas_indicator_present(GLOBAL_INTERRUPT_QUEUE, NULL))
  608. return;
  609. index = (1UL << interrupt_server_size) - 1 - gserver;
  610. status = rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE, index, join);
  611. WARN(status < 0, "set-indicator(%d, %d, %u) returned %d\n",
  612. GLOBAL_INTERRUPT_QUEUE, index, join, status);
  613. }
  614. void xics_setup_cpu(void)
  615. {
  616. xics_set_cpu_priority(0xff);
  617. xics_set_cpu_giq(default_distrib_server, 1);
  618. }
  619. void xics_teardown_cpu(void)
  620. {
  621. int cpu = smp_processor_id();
  622. xics_set_cpu_priority(0);
  623. /* Clear any pending IPI request */
  624. if (firmware_has_feature(FW_FEATURE_LPAR))
  625. lpar_qirr_info(cpu, 0xff);
  626. else
  627. direct_qirr_info(cpu, 0xff);
  628. }
  629. void xics_kexec_teardown_cpu(int secondary)
  630. {
  631. xics_teardown_cpu();
  632. /*
  633. * we take the ipi irq but and never return so we
  634. * need to EOI the IPI, but want to leave our priority 0
  635. *
  636. * should we check all the other interrupts too?
  637. * should we be flagging idle loop instead?
  638. * or creating some task to be scheduled?
  639. */
  640. if (firmware_has_feature(FW_FEATURE_LPAR))
  641. lpar_xirr_info_set((0x00 << 24) | XICS_IPI);
  642. else
  643. direct_xirr_info_set((0x00 << 24) | XICS_IPI);
  644. /*
  645. * Some machines need to have at least one cpu in the GIQ,
  646. * so leave the master cpu in the group.
  647. */
  648. if (secondary)
  649. xics_set_cpu_giq(default_distrib_server, 0);
  650. }
  651. #ifdef CONFIG_HOTPLUG_CPU
  652. /* Interrupts are disabled. */
  653. void xics_migrate_irqs_away(void)
  654. {
  655. int cpu = smp_processor_id(), hw_cpu = hard_smp_processor_id();
  656. unsigned int irq, virq;
  657. /* If we used to be the default server, move to the new "boot_cpuid" */
  658. if (hw_cpu == default_server)
  659. xics_update_irq_servers();
  660. /* Reject any interrupt that was queued to us... */
  661. xics_set_cpu_priority(0);
  662. /* Remove ourselves from the global interrupt queue */
  663. xics_set_cpu_giq(default_distrib_server, 0);
  664. /* Allow IPIs again... */
  665. xics_set_cpu_priority(DEFAULT_PRIORITY);
  666. for_each_irq(virq) {
  667. struct irq_desc *desc;
  668. int xics_status[2];
  669. int status;
  670. unsigned long flags;
  671. /* We cant set affinity on ISA interrupts */
  672. if (virq < NUM_ISA_INTERRUPTS)
  673. continue;
  674. if (irq_map[virq].host != xics_host)
  675. continue;
  676. irq = (unsigned int)irq_map[virq].hwirq;
  677. /* We need to get IPIs still. */
  678. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  679. continue;
  680. desc = get_irq_desc(virq);
  681. /* We only need to migrate enabled IRQS */
  682. if (desc == NULL || desc->chip == NULL
  683. || desc->action == NULL
  684. || desc->chip->set_affinity == NULL)
  685. continue;
  686. spin_lock_irqsave(&desc->lock, flags);
  687. status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
  688. if (status) {
  689. printk(KERN_ERR "%s: ibm,get-xive irq=%u returns %d\n",
  690. __func__, irq, status);
  691. goto unlock;
  692. }
  693. /*
  694. * We only support delivery to all cpus or to one cpu.
  695. * The irq has to be migrated only in the single cpu
  696. * case.
  697. */
  698. if (xics_status[0] != hw_cpu)
  699. goto unlock;
  700. printk(KERN_WARNING "IRQ %u affinity broken off cpu %u\n",
  701. virq, cpu);
  702. /* Reset affinity to all cpus */
  703. cpumask_setall(irq_desc[virq].affinity);
  704. desc->chip->set_affinity(virq, cpu_all_mask);
  705. unlock:
  706. spin_unlock_irqrestore(&desc->lock, flags);
  707. }
  708. }
  709. #endif