xics.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  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/signal.h>
  18. #include <linux/init.h>
  19. #include <linux/gfp.h>
  20. #include <linux/radix-tree.h>
  21. #include <linux/cpu.h>
  22. #include <asm/firmware.h>
  23. #include <asm/prom.h>
  24. #include <asm/io.h>
  25. #include <asm/pgtable.h>
  26. #include <asm/smp.h>
  27. #include <asm/rtas.h>
  28. #include <asm/hvcall.h>
  29. #include <asm/machdep.h>
  30. #include <asm/i8259.h>
  31. #include "xics.h"
  32. #include "plpar_wrappers.h"
  33. static struct irq_host *xics_host;
  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. static unsigned int default_server = 0xFF;
  44. static unsigned int default_distrib_server = 0;
  45. static unsigned int interrupt_server_size = 8;
  46. /* RTAS service tokens */
  47. static int ibm_get_xive;
  48. static int ibm_set_xive;
  49. static int ibm_int_on;
  50. static int ibm_int_off;
  51. /* Direct hardware low level accessors */
  52. /* The part of the interrupt presentation layer that we care about */
  53. struct xics_ipl {
  54. union {
  55. u32 word;
  56. u8 bytes[4];
  57. } xirr_poll;
  58. union {
  59. u32 word;
  60. u8 bytes[4];
  61. } xirr;
  62. u32 dummy;
  63. union {
  64. u32 word;
  65. u8 bytes[4];
  66. } qirr;
  67. };
  68. static struct xics_ipl __iomem *xics_per_cpu[NR_CPUS];
  69. static inline unsigned int direct_xirr_info_get(void)
  70. {
  71. int cpu = smp_processor_id();
  72. return in_be32(&xics_per_cpu[cpu]->xirr.word);
  73. }
  74. static inline void direct_xirr_info_set(unsigned int value)
  75. {
  76. int cpu = smp_processor_id();
  77. out_be32(&xics_per_cpu[cpu]->xirr.word, value);
  78. }
  79. static inline void direct_cppr_info(u8 value)
  80. {
  81. int cpu = smp_processor_id();
  82. out_8(&xics_per_cpu[cpu]->xirr.bytes[0], value);
  83. }
  84. static inline void direct_qirr_info(int n_cpu, u8 value)
  85. {
  86. out_8(&xics_per_cpu[n_cpu]->qirr.bytes[0], value);
  87. }
  88. /* LPAR low level accessors */
  89. static inline unsigned int lpar_xirr_info_get(void)
  90. {
  91. unsigned long lpar_rc;
  92. unsigned long return_value;
  93. lpar_rc = plpar_xirr(&return_value);
  94. if (lpar_rc != H_SUCCESS)
  95. panic(" bad return code xirr - rc = %lx \n", lpar_rc);
  96. return (unsigned int)return_value;
  97. }
  98. static inline void lpar_xirr_info_set(unsigned int value)
  99. {
  100. unsigned long lpar_rc;
  101. lpar_rc = plpar_eoi(value);
  102. if (lpar_rc != H_SUCCESS)
  103. panic("bad return code EOI - rc = %ld, value=%x\n", lpar_rc,
  104. value);
  105. }
  106. static inline void lpar_cppr_info(u8 value)
  107. {
  108. unsigned long lpar_rc;
  109. lpar_rc = plpar_cppr(value);
  110. if (lpar_rc != H_SUCCESS)
  111. panic("bad return code cppr - rc = %lx\n", lpar_rc);
  112. }
  113. static inline void lpar_qirr_info(int n_cpu , u8 value)
  114. {
  115. unsigned long lpar_rc;
  116. lpar_rc = plpar_ipi(get_hard_smp_processor_id(n_cpu), value);
  117. if (lpar_rc != H_SUCCESS)
  118. panic("bad return code qirr - rc = %lx\n", lpar_rc);
  119. }
  120. /* Interface to generic irq subsystem */
  121. #ifdef CONFIG_SMP
  122. static int get_irq_server(unsigned int virq, unsigned int strict_check)
  123. {
  124. int server;
  125. /* For the moment only implement delivery to all cpus or one cpu */
  126. cpumask_t cpumask = irq_desc[virq].affinity;
  127. cpumask_t tmp = CPU_MASK_NONE;
  128. if (!distribute_irqs)
  129. return default_server;
  130. if (!cpus_equal(cpumask, CPU_MASK_ALL)) {
  131. cpus_and(tmp, cpu_online_map, cpumask);
  132. server = first_cpu(tmp);
  133. if (server < NR_CPUS)
  134. return get_hard_smp_processor_id(server);
  135. if (strict_check)
  136. return -1;
  137. }
  138. if (cpus_equal(cpu_online_map, cpu_present_map))
  139. return default_distrib_server;
  140. return default_server;
  141. }
  142. #else
  143. static int get_irq_server(unsigned int virq, unsigned int strict_check)
  144. {
  145. return default_server;
  146. }
  147. #endif
  148. static void xics_unmask_irq(unsigned int virq)
  149. {
  150. unsigned int irq;
  151. int call_status;
  152. int server;
  153. pr_debug("xics: unmask virq %d\n", virq);
  154. irq = (unsigned int)irq_map[virq].hwirq;
  155. pr_debug(" -> map to hwirq 0x%x\n", irq);
  156. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  157. return;
  158. server = get_irq_server(virq, 0);
  159. call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, server,
  160. DEFAULT_PRIORITY);
  161. if (call_status != 0) {
  162. printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_set_xive "
  163. "returned %d\n", irq, call_status);
  164. printk("set_xive %x, server %x\n", ibm_set_xive, server);
  165. return;
  166. }
  167. /* Now unmask the interrupt (often a no-op) */
  168. call_status = rtas_call(ibm_int_on, 1, 1, NULL, irq);
  169. if (call_status != 0) {
  170. printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_int_on "
  171. "returned %d\n", irq, call_status);
  172. return;
  173. }
  174. }
  175. static unsigned int xics_startup(unsigned int virq)
  176. {
  177. /* unmask it */
  178. xics_unmask_irq(virq);
  179. return 0;
  180. }
  181. static void xics_mask_real_irq(unsigned int irq)
  182. {
  183. int call_status;
  184. if (irq == XICS_IPI)
  185. return;
  186. call_status = rtas_call(ibm_int_off, 1, 1, NULL, irq);
  187. if (call_status != 0) {
  188. printk(KERN_ERR "xics_disable_real_irq: irq=%u: "
  189. "ibm_int_off returned %d\n", irq, call_status);
  190. return;
  191. }
  192. /* Have to set XIVE to 0xff to be able to remove a slot */
  193. call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq,
  194. default_server, 0xff);
  195. if (call_status != 0) {
  196. printk(KERN_ERR "xics_disable_irq: irq=%u: ibm_set_xive(0xff)"
  197. " returned %d\n", irq, call_status);
  198. return;
  199. }
  200. }
  201. static void xics_mask_irq(unsigned int virq)
  202. {
  203. unsigned int irq;
  204. pr_debug("xics: mask virq %d\n", virq);
  205. irq = (unsigned int)irq_map[virq].hwirq;
  206. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  207. return;
  208. xics_mask_real_irq(irq);
  209. }
  210. static void xics_mask_unknown_vec(unsigned int vec)
  211. {
  212. printk(KERN_ERR "Interrupt %u (real) is invalid, disabling it.\n", vec);
  213. xics_mask_real_irq(vec);
  214. }
  215. static inline unsigned int xics_xirr_vector(unsigned int xirr)
  216. {
  217. /*
  218. * The top byte is the old cppr, to be restored on EOI.
  219. * The remaining 24 bits are the vector.
  220. */
  221. return xirr & 0x00ffffff;
  222. }
  223. static unsigned int xics_get_irq_direct(void)
  224. {
  225. unsigned int xirr = direct_xirr_info_get();
  226. unsigned int vec = xics_xirr_vector(xirr);
  227. unsigned int irq;
  228. if (vec == XICS_IRQ_SPURIOUS)
  229. return NO_IRQ;
  230. irq = irq_radix_revmap_lookup(xics_host, vec);
  231. if (likely(irq != NO_IRQ))
  232. return irq;
  233. /* We don't have a linux mapping, so have rtas mask it. */
  234. xics_mask_unknown_vec(vec);
  235. /* We might learn about it later, so EOI it */
  236. direct_xirr_info_set(xirr);
  237. return NO_IRQ;
  238. }
  239. static unsigned int xics_get_irq_lpar(void)
  240. {
  241. unsigned int xirr = lpar_xirr_info_get();
  242. unsigned int vec = xics_xirr_vector(xirr);
  243. unsigned int irq;
  244. if (vec == XICS_IRQ_SPURIOUS)
  245. return NO_IRQ;
  246. irq = irq_radix_revmap_lookup(xics_host, vec);
  247. if (likely(irq != NO_IRQ))
  248. return irq;
  249. /* We don't have a linux mapping, so have RTAS mask it. */
  250. xics_mask_unknown_vec(vec);
  251. /* We might learn about it later, so EOI it */
  252. lpar_xirr_info_set(xirr);
  253. return NO_IRQ;
  254. }
  255. static void xics_eoi_direct(unsigned int virq)
  256. {
  257. unsigned int irq = (unsigned int)irq_map[virq].hwirq;
  258. iosync();
  259. direct_xirr_info_set((0xff << 24) | irq);
  260. }
  261. static void xics_eoi_lpar(unsigned int virq)
  262. {
  263. unsigned int irq = (unsigned int)irq_map[virq].hwirq;
  264. iosync();
  265. lpar_xirr_info_set((0xff << 24) | irq);
  266. }
  267. static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
  268. {
  269. unsigned int irq;
  270. int status;
  271. int xics_status[2];
  272. int irq_server;
  273. irq = (unsigned int)irq_map[virq].hwirq;
  274. if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS)
  275. return;
  276. status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
  277. if (status) {
  278. printk(KERN_ERR "xics_set_affinity: irq=%u ibm,get-xive "
  279. "returns %d\n", irq, status);
  280. return;
  281. }
  282. /*
  283. * For the moment only implement delivery to all cpus or one cpu.
  284. * Get current irq_server for the given irq
  285. */
  286. irq_server = get_irq_server(virq, 1);
  287. if (irq_server == -1) {
  288. char cpulist[128];
  289. cpumask_scnprintf(cpulist, sizeof(cpulist), cpumask);
  290. printk(KERN_WARNING "xics_set_affinity: No online cpus in "
  291. "the mask %s for irq %d\n", cpulist, virq);
  292. return;
  293. }
  294. status = rtas_call(ibm_set_xive, 3, 1, NULL,
  295. irq, irq_server, xics_status[1]);
  296. if (status) {
  297. printk(KERN_ERR "xics_set_affinity: irq=%u ibm,set-xive "
  298. "returns %d\n", irq, status);
  299. return;
  300. }
  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. while (xics_ipi_message[cpu].value) {
  403. if (test_and_clear_bit(PPC_MSG_CALL_FUNCTION,
  404. &xics_ipi_message[cpu].value)) {
  405. mb();
  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. mb();
  411. smp_message_recv(PPC_MSG_RESCHEDULE);
  412. }
  413. if (test_and_clear_bit(PPC_MSG_CALL_FUNC_SINGLE,
  414. &xics_ipi_message[cpu].value)) {
  415. mb();
  416. smp_message_recv(PPC_MSG_CALL_FUNC_SINGLE);
  417. }
  418. #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
  419. if (test_and_clear_bit(PPC_MSG_DEBUGGER_BREAK,
  420. &xics_ipi_message[cpu].value)) {
  421. mb();
  422. smp_message_recv(PPC_MSG_DEBUGGER_BREAK);
  423. }
  424. #endif
  425. }
  426. return IRQ_HANDLED;
  427. }
  428. static irqreturn_t xics_ipi_action_direct(int irq, void *dev_id)
  429. {
  430. int cpu = smp_processor_id();
  431. direct_qirr_info(cpu, 0xff);
  432. return xics_ipi_dispatch(cpu);
  433. }
  434. static irqreturn_t xics_ipi_action_lpar(int irq, void *dev_id)
  435. {
  436. int cpu = smp_processor_id();
  437. lpar_qirr_info(cpu, 0xff);
  438. return xics_ipi_dispatch(cpu);
  439. }
  440. static void xics_request_ipi(void)
  441. {
  442. unsigned int ipi;
  443. int rc;
  444. ipi = irq_create_mapping(xics_host, XICS_IPI);
  445. BUG_ON(ipi == NO_IRQ);
  446. /*
  447. * IPIs are marked IRQF_DISABLED as they must run with irqs
  448. * disabled
  449. */
  450. set_irq_handler(ipi, handle_percpu_irq);
  451. if (firmware_has_feature(FW_FEATURE_LPAR))
  452. rc = request_irq(ipi, xics_ipi_action_lpar, IRQF_DISABLED,
  453. "IPI", NULL);
  454. else
  455. rc = request_irq(ipi, xics_ipi_action_direct, IRQF_DISABLED,
  456. "IPI", NULL);
  457. BUG_ON(rc);
  458. }
  459. int __init smp_xics_probe(void)
  460. {
  461. xics_request_ipi();
  462. return cpus_weight(cpu_possible_map);
  463. }
  464. #endif /* CONFIG_SMP */
  465. /* Initialization */
  466. static void xics_update_irq_servers(void)
  467. {
  468. int i, j;
  469. struct device_node *np;
  470. u32 ilen;
  471. const u32 *ireg, *isize;
  472. u32 hcpuid;
  473. /* Find the server numbers for the boot cpu. */
  474. np = of_get_cpu_node(boot_cpuid, NULL);
  475. BUG_ON(!np);
  476. ireg = of_get_property(np, "ibm,ppc-interrupt-gserver#s", &ilen);
  477. if (!ireg) {
  478. of_node_put(np);
  479. return;
  480. }
  481. i = ilen / sizeof(int);
  482. hcpuid = get_hard_smp_processor_id(boot_cpuid);
  483. /* Global interrupt distribution server is specified in the last
  484. * entry of "ibm,ppc-interrupt-gserver#s" property. Get the last
  485. * entry fom this property for current boot cpu id and use it as
  486. * default distribution server
  487. */
  488. for (j = 0; j < i; j += 2) {
  489. if (ireg[j] == hcpuid) {
  490. default_server = hcpuid;
  491. default_distrib_server = ireg[j+1];
  492. isize = of_get_property(np,
  493. "ibm,interrupt-server#-size", NULL);
  494. if (isize)
  495. interrupt_server_size = *isize;
  496. }
  497. }
  498. of_node_put(np);
  499. }
  500. static void __init xics_map_one_cpu(int hw_id, unsigned long addr,
  501. unsigned long size)
  502. {
  503. #ifdef CONFIG_SMP
  504. int i;
  505. /* This may look gross but it's good enough for now, we don't quite
  506. * have a hard -> linux processor id matching.
  507. */
  508. for_each_possible_cpu(i) {
  509. if (!cpu_present(i))
  510. continue;
  511. if (hw_id == get_hard_smp_processor_id(i)) {
  512. xics_per_cpu[i] = ioremap(addr, size);
  513. return;
  514. }
  515. }
  516. #else
  517. if (hw_id != 0)
  518. return;
  519. xics_per_cpu[0] = ioremap(addr, size);
  520. #endif /* CONFIG_SMP */
  521. }
  522. static void __init xics_init_one_node(struct device_node *np,
  523. unsigned int *indx)
  524. {
  525. unsigned int ilen;
  526. const u32 *ireg;
  527. /* This code does the theorically broken assumption that the interrupt
  528. * server numbers are the same as the hard CPU numbers.
  529. * This happens to be the case so far but we are playing with fire...
  530. * should be fixed one of these days. -BenH.
  531. */
  532. ireg = of_get_property(np, "ibm,interrupt-server-ranges", NULL);
  533. /* Do that ever happen ? we'll know soon enough... but even good'old
  534. * f80 does have that property ..
  535. */
  536. WARN_ON(ireg == NULL);
  537. if (ireg) {
  538. /*
  539. * set node starting index for this node
  540. */
  541. *indx = *ireg;
  542. }
  543. ireg = of_get_property(np, "reg", &ilen);
  544. if (!ireg)
  545. panic("xics_init_IRQ: can't find interrupt reg property");
  546. while (ilen >= (4 * sizeof(u32))) {
  547. unsigned long addr, size;
  548. /* XXX Use proper OF parsing code here !!! */
  549. addr = (unsigned long)*ireg++ << 32;
  550. ilen -= sizeof(u32);
  551. addr |= *ireg++;
  552. ilen -= sizeof(u32);
  553. size = (unsigned long)*ireg++ << 32;
  554. ilen -= sizeof(u32);
  555. size |= *ireg++;
  556. ilen -= sizeof(u32);
  557. xics_map_one_cpu(*indx, addr, size);
  558. (*indx)++;
  559. }
  560. }
  561. void __init xics_init_IRQ(void)
  562. {
  563. struct device_node *np;
  564. u32 indx = 0;
  565. int found = 0;
  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_update_irq_servers();
  580. xics_init_host();
  581. if (firmware_has_feature(FW_FEATURE_LPAR))
  582. ppc_md.get_irq = xics_get_irq_lpar;
  583. else
  584. ppc_md.get_irq = xics_get_irq_direct;
  585. xics_setup_cpu();
  586. ppc64_boot_msg(0x21, "XICS Done");
  587. }
  588. /* Cpu startup, shutdown, and hotplug */
  589. static void xics_set_cpu_priority(unsigned char cppr)
  590. {
  591. if (firmware_has_feature(FW_FEATURE_LPAR))
  592. lpar_cppr_info(cppr);
  593. else
  594. direct_cppr_info(cppr);
  595. iosync();
  596. }
  597. void xics_setup_cpu(void)
  598. {
  599. xics_set_cpu_priority(0xff);
  600. /*
  601. * Put the calling processor into the GIQ. This is really only
  602. * necessary from a secondary thread as the OF start-cpu interface
  603. * performs this function for us on primary threads.
  604. *
  605. * XXX: undo of teardown on kexec needs this too, as may hotplug
  606. */
  607. rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  608. (1UL << interrupt_server_size) - 1 - default_distrib_server, 1);
  609. }
  610. void xics_teardown_cpu(void)
  611. {
  612. int cpu = smp_processor_id();
  613. xics_set_cpu_priority(0);
  614. /*
  615. * Clear IPI
  616. */
  617. if (firmware_has_feature(FW_FEATURE_LPAR))
  618. lpar_qirr_info(cpu, 0xff);
  619. else
  620. direct_qirr_info(cpu, 0xff);
  621. }
  622. void xics_kexec_teardown_cpu(int secondary)
  623. {
  624. unsigned int ipi;
  625. struct irq_desc *desc;
  626. xics_teardown_cpu();
  627. /*
  628. * we need to EOI the IPI
  629. *
  630. * probably need to check all the other interrupts too
  631. * should we be flagging idle loop instead?
  632. * or creating some task to be scheduled?
  633. */
  634. ipi = irq_find_mapping(xics_host, XICS_IPI);
  635. if (ipi == XICS_IRQ_SPURIOUS)
  636. return;
  637. desc = get_irq_desc(ipi);
  638. if (desc->chip && desc->chip->eoi)
  639. desc->chip->eoi(ipi);
  640. /*
  641. * Some machines need to have at least one cpu in the GIQ,
  642. * so leave the master cpu in the group.
  643. */
  644. if (secondary)
  645. rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  646. (1UL << interrupt_server_size) - 1 -
  647. default_distrib_server, 0);
  648. }
  649. #ifdef CONFIG_HOTPLUG_CPU
  650. /* Interrupts are disabled. */
  651. void xics_migrate_irqs_away(void)
  652. {
  653. int status;
  654. int cpu = smp_processor_id(), hw_cpu = hard_smp_processor_id();
  655. unsigned int irq, virq;
  656. /* If we used to be the default server, move to the new "boot_cpuid" */
  657. if (hw_cpu == default_server)
  658. xics_update_irq_servers();
  659. /* Reject any interrupt that was queued to us... */
  660. xics_set_cpu_priority(0);
  661. /* remove ourselves from the global interrupt queue */
  662. status = rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE,
  663. (1UL << interrupt_server_size) - 1 - default_distrib_server, 0);
  664. WARN_ON(status < 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. 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 "migrate_irqs_away: irq=%u "
  690. "ibm,get-xive returns %d\n",
  691. virq, 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. irq_desc[virq].affinity = CPU_MASK_ALL;
  705. desc->chip->set_affinity(virq, CPU_MASK_ALL);
  706. unlock:
  707. spin_unlock_irqrestore(&desc->lock, flags);
  708. }
  709. }
  710. #endif