mpic.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. /*
  2. * arch/powerpc/kernel/mpic.c
  3. *
  4. * Driver for interrupt controllers following the OpenPIC standard, the
  5. * common implementation beeing IBM's MPIC. This driver also can deal
  6. * with various broken implementations of this HW.
  7. *
  8. * Copyright (C) 2004 Benjamin Herrenschmidt, IBM Corp.
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file COPYING in the main directory of this archive
  12. * for more details.
  13. */
  14. #undef DEBUG
  15. #undef DEBUG_IPI
  16. #undef DEBUG_IRQ
  17. #undef DEBUG_LOW
  18. #include <linux/types.h>
  19. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <linux/irq.h>
  22. #include <linux/smp.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/bootmem.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/pci.h>
  27. #include <asm/ptrace.h>
  28. #include <asm/signal.h>
  29. #include <asm/io.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/irq.h>
  32. #include <asm/machdep.h>
  33. #include <asm/mpic.h>
  34. #include <asm/smp.h>
  35. #ifdef DEBUG
  36. #define DBG(fmt...) printk(fmt)
  37. #else
  38. #define DBG(fmt...)
  39. #endif
  40. static struct mpic *mpics;
  41. static struct mpic *mpic_primary;
  42. static DEFINE_SPINLOCK(mpic_lock);
  43. #ifdef CONFIG_PPC32 /* XXX for now */
  44. #ifdef CONFIG_IRQ_ALL_CPUS
  45. #define distribute_irqs (1)
  46. #else
  47. #define distribute_irqs (0)
  48. #endif
  49. #endif
  50. /*
  51. * Register accessor functions
  52. */
  53. static inline u32 _mpic_read(unsigned int be, volatile u32 __iomem *base,
  54. unsigned int reg)
  55. {
  56. if (be)
  57. return in_be32(base + (reg >> 2));
  58. else
  59. return in_le32(base + (reg >> 2));
  60. }
  61. static inline void _mpic_write(unsigned int be, volatile u32 __iomem *base,
  62. unsigned int reg, u32 value)
  63. {
  64. if (be)
  65. out_be32(base + (reg >> 2), value);
  66. else
  67. out_le32(base + (reg >> 2), value);
  68. }
  69. static inline u32 _mpic_ipi_read(struct mpic *mpic, unsigned int ipi)
  70. {
  71. unsigned int be = (mpic->flags & MPIC_BIG_ENDIAN) != 0;
  72. unsigned int offset = MPIC_GREG_IPI_VECTOR_PRI_0 + (ipi * 0x10);
  73. if (mpic->flags & MPIC_BROKEN_IPI)
  74. be = !be;
  75. return _mpic_read(be, mpic->gregs, offset);
  76. }
  77. static inline void _mpic_ipi_write(struct mpic *mpic, unsigned int ipi, u32 value)
  78. {
  79. unsigned int offset = MPIC_GREG_IPI_VECTOR_PRI_0 + (ipi * 0x10);
  80. _mpic_write(mpic->flags & MPIC_BIG_ENDIAN, mpic->gregs, offset, value);
  81. }
  82. static inline u32 _mpic_cpu_read(struct mpic *mpic, unsigned int reg)
  83. {
  84. unsigned int cpu = 0;
  85. if (mpic->flags & MPIC_PRIMARY)
  86. cpu = hard_smp_processor_id();
  87. return _mpic_read(mpic->flags & MPIC_BIG_ENDIAN,
  88. mpic->cpuregs[cpu], reg);
  89. }
  90. static inline void _mpic_cpu_write(struct mpic *mpic, unsigned int reg, u32 value)
  91. {
  92. unsigned int cpu = 0;
  93. if (mpic->flags & MPIC_PRIMARY)
  94. cpu = hard_smp_processor_id();
  95. _mpic_write(mpic->flags & MPIC_BIG_ENDIAN, mpic->cpuregs[cpu], reg, value);
  96. }
  97. static inline u32 _mpic_irq_read(struct mpic *mpic, unsigned int src_no, unsigned int reg)
  98. {
  99. unsigned int isu = src_no >> mpic->isu_shift;
  100. unsigned int idx = src_no & mpic->isu_mask;
  101. return _mpic_read(mpic->flags & MPIC_BIG_ENDIAN, mpic->isus[isu],
  102. reg + (idx * MPIC_IRQ_STRIDE));
  103. }
  104. static inline void _mpic_irq_write(struct mpic *mpic, unsigned int src_no,
  105. unsigned int reg, u32 value)
  106. {
  107. unsigned int isu = src_no >> mpic->isu_shift;
  108. unsigned int idx = src_no & mpic->isu_mask;
  109. _mpic_write(mpic->flags & MPIC_BIG_ENDIAN, mpic->isus[isu],
  110. reg + (idx * MPIC_IRQ_STRIDE), value);
  111. }
  112. #define mpic_read(b,r) _mpic_read(mpic->flags & MPIC_BIG_ENDIAN,(b),(r))
  113. #define mpic_write(b,r,v) _mpic_write(mpic->flags & MPIC_BIG_ENDIAN,(b),(r),(v))
  114. #define mpic_ipi_read(i) _mpic_ipi_read(mpic,(i))
  115. #define mpic_ipi_write(i,v) _mpic_ipi_write(mpic,(i),(v))
  116. #define mpic_cpu_read(i) _mpic_cpu_read(mpic,(i))
  117. #define mpic_cpu_write(i,v) _mpic_cpu_write(mpic,(i),(v))
  118. #define mpic_irq_read(s,r) _mpic_irq_read(mpic,(s),(r))
  119. #define mpic_irq_write(s,r,v) _mpic_irq_write(mpic,(s),(r),(v))
  120. /*
  121. * Low level utility functions
  122. */
  123. /* Check if we have one of those nice broken MPICs with a flipped endian on
  124. * reads from IPI registers
  125. */
  126. static void __init mpic_test_broken_ipi(struct mpic *mpic)
  127. {
  128. u32 r;
  129. mpic_write(mpic->gregs, MPIC_GREG_IPI_VECTOR_PRI_0, MPIC_VECPRI_MASK);
  130. r = mpic_read(mpic->gregs, MPIC_GREG_IPI_VECTOR_PRI_0);
  131. if (r == le32_to_cpu(MPIC_VECPRI_MASK)) {
  132. printk(KERN_INFO "mpic: Detected reversed IPI registers\n");
  133. mpic->flags |= MPIC_BROKEN_IPI;
  134. }
  135. }
  136. #ifdef CONFIG_MPIC_BROKEN_U3
  137. /* Test if an interrupt is sourced from HyperTransport (used on broken U3s)
  138. * to force the edge setting on the MPIC and do the ack workaround.
  139. */
  140. static inline int mpic_is_ht_interrupt(struct mpic *mpic, unsigned int source)
  141. {
  142. if (source >= 128 || !mpic->fixups)
  143. return 0;
  144. return mpic->fixups[source].base != NULL;
  145. }
  146. static inline void mpic_ht_end_irq(struct mpic *mpic, unsigned int source)
  147. {
  148. struct mpic_irq_fixup *fixup = &mpic->fixups[source];
  149. if (fixup->applebase) {
  150. unsigned int soff = (fixup->index >> 3) & ~3;
  151. unsigned int mask = 1U << (fixup->index & 0x1f);
  152. writel(mask, fixup->applebase + soff);
  153. } else {
  154. spin_lock(&mpic->fixup_lock);
  155. writeb(0x11 + 2 * fixup->index, fixup->base + 2);
  156. writel(fixup->data, fixup->base + 4);
  157. spin_unlock(&mpic->fixup_lock);
  158. }
  159. }
  160. static void mpic_startup_ht_interrupt(struct mpic *mpic, unsigned int source,
  161. unsigned int irqflags)
  162. {
  163. struct mpic_irq_fixup *fixup = &mpic->fixups[source];
  164. unsigned long flags;
  165. u32 tmp;
  166. if (fixup->base == NULL)
  167. return;
  168. DBG("startup_ht_interrupt(0x%x, 0x%x) index: %d\n",
  169. source, irqflags, fixup->index);
  170. spin_lock_irqsave(&mpic->fixup_lock, flags);
  171. /* Enable and configure */
  172. writeb(0x10 + 2 * fixup->index, fixup->base + 2);
  173. tmp = readl(fixup->base + 4);
  174. tmp &= ~(0x23U);
  175. if (irqflags & IRQ_LEVEL)
  176. tmp |= 0x22;
  177. writel(tmp, fixup->base + 4);
  178. spin_unlock_irqrestore(&mpic->fixup_lock, flags);
  179. }
  180. static void mpic_shutdown_ht_interrupt(struct mpic *mpic, unsigned int source,
  181. unsigned int irqflags)
  182. {
  183. struct mpic_irq_fixup *fixup = &mpic->fixups[source];
  184. unsigned long flags;
  185. u32 tmp;
  186. if (fixup->base == NULL)
  187. return;
  188. DBG("shutdown_ht_interrupt(0x%x, 0x%x)\n", source, irqflags);
  189. /* Disable */
  190. spin_lock_irqsave(&mpic->fixup_lock, flags);
  191. writeb(0x10 + 2 * fixup->index, fixup->base + 2);
  192. tmp = readl(fixup->base + 4);
  193. tmp |= 1;
  194. writel(tmp, fixup->base + 4);
  195. spin_unlock_irqrestore(&mpic->fixup_lock, flags);
  196. }
  197. static void __init mpic_scan_ht_pic(struct mpic *mpic, u8 __iomem *devbase,
  198. unsigned int devfn, u32 vdid)
  199. {
  200. int i, irq, n;
  201. u8 __iomem *base;
  202. u32 tmp;
  203. u8 pos;
  204. for (pos = readb(devbase + PCI_CAPABILITY_LIST); pos != 0;
  205. pos = readb(devbase + pos + PCI_CAP_LIST_NEXT)) {
  206. u8 id = readb(devbase + pos + PCI_CAP_LIST_ID);
  207. if (id == PCI_CAP_ID_HT_IRQCONF) {
  208. id = readb(devbase + pos + 3);
  209. if (id == 0x80)
  210. break;
  211. }
  212. }
  213. if (pos == 0)
  214. return;
  215. base = devbase + pos;
  216. writeb(0x01, base + 2);
  217. n = (readl(base + 4) >> 16) & 0xff;
  218. printk(KERN_INFO "mpic: - HT:%02x.%x [0x%02x] vendor %04x device %04x"
  219. " has %d irqs\n",
  220. devfn >> 3, devfn & 0x7, pos, vdid & 0xffff, vdid >> 16, n + 1);
  221. for (i = 0; i <= n; i++) {
  222. writeb(0x10 + 2 * i, base + 2);
  223. tmp = readl(base + 4);
  224. irq = (tmp >> 16) & 0xff;
  225. DBG("HT PIC index 0x%x, irq 0x%x, tmp: %08x\n", i, irq, tmp);
  226. /* mask it , will be unmasked later */
  227. tmp |= 0x1;
  228. writel(tmp, base + 4);
  229. mpic->fixups[irq].index = i;
  230. mpic->fixups[irq].base = base;
  231. /* Apple HT PIC has a non-standard way of doing EOIs */
  232. if ((vdid & 0xffff) == 0x106b)
  233. mpic->fixups[irq].applebase = devbase + 0x60;
  234. else
  235. mpic->fixups[irq].applebase = NULL;
  236. writeb(0x11 + 2 * i, base + 2);
  237. mpic->fixups[irq].data = readl(base + 4) | 0x80000000;
  238. }
  239. }
  240. static void __init mpic_scan_ht_pics(struct mpic *mpic)
  241. {
  242. unsigned int devfn;
  243. u8 __iomem *cfgspace;
  244. printk(KERN_INFO "mpic: Setting up HT PICs workarounds for U3/U4\n");
  245. /* Allocate fixups array */
  246. mpic->fixups = alloc_bootmem(128 * sizeof(struct mpic_irq_fixup));
  247. BUG_ON(mpic->fixups == NULL);
  248. memset(mpic->fixups, 0, 128 * sizeof(struct mpic_irq_fixup));
  249. /* Init spinlock */
  250. spin_lock_init(&mpic->fixup_lock);
  251. /* Map U3 config space. We assume all IO-APICs are on the primary bus
  252. * so we only need to map 64kB.
  253. */
  254. cfgspace = ioremap(0xf2000000, 0x10000);
  255. BUG_ON(cfgspace == NULL);
  256. /* Now we scan all slots. We do a very quick scan, we read the header
  257. * type, vendor ID and device ID only, that's plenty enough
  258. */
  259. for (devfn = 0; devfn < 0x100; devfn++) {
  260. u8 __iomem *devbase = cfgspace + (devfn << 8);
  261. u8 hdr_type = readb(devbase + PCI_HEADER_TYPE);
  262. u32 l = readl(devbase + PCI_VENDOR_ID);
  263. u16 s;
  264. DBG("devfn %x, l: %x\n", devfn, l);
  265. /* If no device, skip */
  266. if (l == 0xffffffff || l == 0x00000000 ||
  267. l == 0x0000ffff || l == 0xffff0000)
  268. goto next;
  269. /* Check if is supports capability lists */
  270. s = readw(devbase + PCI_STATUS);
  271. if (!(s & PCI_STATUS_CAP_LIST))
  272. goto next;
  273. mpic_scan_ht_pic(mpic, devbase, devfn, l);
  274. next:
  275. /* next device, if function 0 */
  276. if (PCI_FUNC(devfn) == 0 && (hdr_type & 0x80) == 0)
  277. devfn += 7;
  278. }
  279. }
  280. #else /* CONFIG_MPIC_BROKEN_U3 */
  281. static inline int mpic_is_ht_interrupt(struct mpic *mpic, unsigned int source)
  282. {
  283. return 0;
  284. }
  285. static void __init mpic_scan_ht_pics(struct mpic *mpic)
  286. {
  287. }
  288. #endif /* CONFIG_MPIC_BROKEN_U3 */
  289. #define mpic_irq_to_hw(virq) ((unsigned int)irq_map[virq].hwirq)
  290. /* Find an mpic associated with a given linux interrupt */
  291. static struct mpic *mpic_find(unsigned int irq, unsigned int *is_ipi)
  292. {
  293. unsigned int src = mpic_irq_to_hw(irq);
  294. if (irq < NUM_ISA_INTERRUPTS)
  295. return NULL;
  296. if (is_ipi)
  297. *is_ipi = (src >= MPIC_VEC_IPI_0 && src <= MPIC_VEC_IPI_3);
  298. return irq_desc[irq].chip_data;
  299. }
  300. /* Convert a cpu mask from logical to physical cpu numbers. */
  301. static inline u32 mpic_physmask(u32 cpumask)
  302. {
  303. int i;
  304. u32 mask = 0;
  305. for (i = 0; i < NR_CPUS; ++i, cpumask >>= 1)
  306. mask |= (cpumask & 1) << get_hard_smp_processor_id(i);
  307. return mask;
  308. }
  309. #ifdef CONFIG_SMP
  310. /* Get the mpic structure from the IPI number */
  311. static inline struct mpic * mpic_from_ipi(unsigned int ipi)
  312. {
  313. return irq_desc[ipi].chip_data;
  314. }
  315. #endif
  316. /* Get the mpic structure from the irq number */
  317. static inline struct mpic * mpic_from_irq(unsigned int irq)
  318. {
  319. return irq_desc[irq].chip_data;
  320. }
  321. /* Send an EOI */
  322. static inline void mpic_eoi(struct mpic *mpic)
  323. {
  324. mpic_cpu_write(MPIC_CPU_EOI, 0);
  325. (void)mpic_cpu_read(MPIC_CPU_WHOAMI);
  326. }
  327. #ifdef CONFIG_SMP
  328. static irqreturn_t mpic_ipi_action(int irq, void *dev_id, struct pt_regs *regs)
  329. {
  330. smp_message_recv(mpic_irq_to_hw(irq) - MPIC_VEC_IPI_0, regs);
  331. return IRQ_HANDLED;
  332. }
  333. #endif /* CONFIG_SMP */
  334. /*
  335. * Linux descriptor level callbacks
  336. */
  337. static void mpic_unmask_irq(unsigned int irq)
  338. {
  339. unsigned int loops = 100000;
  340. struct mpic *mpic = mpic_from_irq(irq);
  341. unsigned int src = mpic_irq_to_hw(irq);
  342. DBG("%p: %s: enable_irq: %d (src %d)\n", mpic, mpic->name, irq, src);
  343. mpic_irq_write(src, MPIC_IRQ_VECTOR_PRI,
  344. mpic_irq_read(src, MPIC_IRQ_VECTOR_PRI) &
  345. ~MPIC_VECPRI_MASK);
  346. /* make sure mask gets to controller before we return to user */
  347. do {
  348. if (!loops--) {
  349. printk(KERN_ERR "mpic_enable_irq timeout\n");
  350. break;
  351. }
  352. } while(mpic_irq_read(src, MPIC_IRQ_VECTOR_PRI) & MPIC_VECPRI_MASK);
  353. }
  354. static void mpic_mask_irq(unsigned int irq)
  355. {
  356. unsigned int loops = 100000;
  357. struct mpic *mpic = mpic_from_irq(irq);
  358. unsigned int src = mpic_irq_to_hw(irq);
  359. DBG("%s: disable_irq: %d (src %d)\n", mpic->name, irq, src);
  360. mpic_irq_write(src, MPIC_IRQ_VECTOR_PRI,
  361. mpic_irq_read(src, MPIC_IRQ_VECTOR_PRI) |
  362. MPIC_VECPRI_MASK);
  363. /* make sure mask gets to controller before we return to user */
  364. do {
  365. if (!loops--) {
  366. printk(KERN_ERR "mpic_enable_irq timeout\n");
  367. break;
  368. }
  369. } while(!(mpic_irq_read(src, MPIC_IRQ_VECTOR_PRI) & MPIC_VECPRI_MASK));
  370. }
  371. static void mpic_end_irq(unsigned int irq)
  372. {
  373. struct mpic *mpic = mpic_from_irq(irq);
  374. #ifdef DEBUG_IRQ
  375. DBG("%s: end_irq: %d\n", mpic->name, irq);
  376. #endif
  377. /* We always EOI on end_irq() even for edge interrupts since that
  378. * should only lower the priority, the MPIC should have properly
  379. * latched another edge interrupt coming in anyway
  380. */
  381. mpic_eoi(mpic);
  382. }
  383. #ifdef CONFIG_MPIC_BROKEN_U3
  384. static void mpic_unmask_ht_irq(unsigned int irq)
  385. {
  386. struct mpic *mpic = mpic_from_irq(irq);
  387. unsigned int src = mpic_irq_to_hw(irq);
  388. mpic_unmask_irq(irq);
  389. if (irq_desc[irq].status & IRQ_LEVEL)
  390. mpic_ht_end_irq(mpic, src);
  391. }
  392. static unsigned int mpic_startup_ht_irq(unsigned int irq)
  393. {
  394. struct mpic *mpic = mpic_from_irq(irq);
  395. unsigned int src = mpic_irq_to_hw(irq);
  396. mpic_unmask_irq(irq);
  397. mpic_startup_ht_interrupt(mpic, src, irq_desc[irq].status);
  398. return 0;
  399. }
  400. static void mpic_shutdown_ht_irq(unsigned int irq)
  401. {
  402. struct mpic *mpic = mpic_from_irq(irq);
  403. unsigned int src = mpic_irq_to_hw(irq);
  404. mpic_shutdown_ht_interrupt(mpic, src, irq_desc[irq].status);
  405. mpic_mask_irq(irq);
  406. }
  407. static void mpic_end_ht_irq(unsigned int irq)
  408. {
  409. struct mpic *mpic = mpic_from_irq(irq);
  410. unsigned int src = mpic_irq_to_hw(irq);
  411. #ifdef DEBUG_IRQ
  412. DBG("%s: end_irq: %d\n", mpic->name, irq);
  413. #endif
  414. /* We always EOI on end_irq() even for edge interrupts since that
  415. * should only lower the priority, the MPIC should have properly
  416. * latched another edge interrupt coming in anyway
  417. */
  418. if (irq_desc[irq].status & IRQ_LEVEL)
  419. mpic_ht_end_irq(mpic, src);
  420. mpic_eoi(mpic);
  421. }
  422. #endif /* !CONFIG_MPIC_BROKEN_U3 */
  423. #ifdef CONFIG_SMP
  424. static void mpic_unmask_ipi(unsigned int irq)
  425. {
  426. struct mpic *mpic = mpic_from_ipi(irq);
  427. unsigned int src = mpic_irq_to_hw(irq) - MPIC_VEC_IPI_0;
  428. DBG("%s: enable_ipi: %d (ipi %d)\n", mpic->name, irq, src);
  429. mpic_ipi_write(src, mpic_ipi_read(src) & ~MPIC_VECPRI_MASK);
  430. }
  431. static void mpic_mask_ipi(unsigned int irq)
  432. {
  433. /* NEVER disable an IPI... that's just plain wrong! */
  434. }
  435. static void mpic_end_ipi(unsigned int irq)
  436. {
  437. struct mpic *mpic = mpic_from_ipi(irq);
  438. /*
  439. * IPIs are marked IRQ_PER_CPU. This has the side effect of
  440. * preventing the IRQ_PENDING/IRQ_INPROGRESS logic from
  441. * applying to them. We EOI them late to avoid re-entering.
  442. * We mark IPI's with IRQF_DISABLED as they must run with
  443. * irqs disabled.
  444. */
  445. mpic_eoi(mpic);
  446. }
  447. #endif /* CONFIG_SMP */
  448. static void mpic_set_affinity(unsigned int irq, cpumask_t cpumask)
  449. {
  450. struct mpic *mpic = mpic_from_irq(irq);
  451. unsigned int src = mpic_irq_to_hw(irq);
  452. cpumask_t tmp;
  453. cpus_and(tmp, cpumask, cpu_online_map);
  454. mpic_irq_write(src, MPIC_IRQ_DESTINATION,
  455. mpic_physmask(cpus_addr(tmp)[0]));
  456. }
  457. static unsigned int mpic_type_to_vecpri(unsigned int type)
  458. {
  459. /* Now convert sense value */
  460. switch(type & IRQ_TYPE_SENSE_MASK) {
  461. case IRQ_TYPE_EDGE_RISING:
  462. return MPIC_VECPRI_SENSE_EDGE | MPIC_VECPRI_POLARITY_POSITIVE;
  463. case IRQ_TYPE_EDGE_FALLING:
  464. case IRQ_TYPE_EDGE_BOTH:
  465. return MPIC_VECPRI_SENSE_EDGE | MPIC_VECPRI_POLARITY_NEGATIVE;
  466. case IRQ_TYPE_LEVEL_HIGH:
  467. return MPIC_VECPRI_SENSE_LEVEL | MPIC_VECPRI_POLARITY_POSITIVE;
  468. case IRQ_TYPE_LEVEL_LOW:
  469. default:
  470. return MPIC_VECPRI_SENSE_LEVEL | MPIC_VECPRI_POLARITY_NEGATIVE;
  471. }
  472. }
  473. static int mpic_set_irq_type(unsigned int virq, unsigned int flow_type)
  474. {
  475. struct mpic *mpic = mpic_from_irq(virq);
  476. unsigned int src = mpic_irq_to_hw(virq);
  477. struct irq_desc *desc = get_irq_desc(virq);
  478. unsigned int vecpri, vold, vnew;
  479. DBG("mpic: set_irq_type(mpic:@%p,virq:%d,src:0x%x,type:0x%x)\n",
  480. mpic, virq, src, flow_type);
  481. if (src >= mpic->irq_count)
  482. return -EINVAL;
  483. if (flow_type == IRQ_TYPE_NONE)
  484. if (mpic->senses && src < mpic->senses_count)
  485. flow_type = mpic->senses[src];
  486. if (flow_type == IRQ_TYPE_NONE)
  487. flow_type = IRQ_TYPE_LEVEL_LOW;
  488. desc->status &= ~(IRQ_TYPE_SENSE_MASK | IRQ_LEVEL);
  489. desc->status |= flow_type & IRQ_TYPE_SENSE_MASK;
  490. if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW))
  491. desc->status |= IRQ_LEVEL;
  492. if (mpic_is_ht_interrupt(mpic, src))
  493. vecpri = MPIC_VECPRI_POLARITY_POSITIVE |
  494. MPIC_VECPRI_SENSE_EDGE;
  495. else
  496. vecpri = mpic_type_to_vecpri(flow_type);
  497. vold = mpic_irq_read(src, MPIC_IRQ_VECTOR_PRI);
  498. vnew = vold & ~(MPIC_VECPRI_POLARITY_MASK | MPIC_VECPRI_SENSE_MASK);
  499. vnew |= vecpri;
  500. if (vold != vnew)
  501. mpic_irq_write(src, MPIC_IRQ_VECTOR_PRI, vnew);
  502. return 0;
  503. }
  504. static struct irq_chip mpic_irq_chip = {
  505. .mask = mpic_mask_irq,
  506. .unmask = mpic_unmask_irq,
  507. .eoi = mpic_end_irq,
  508. .set_type = mpic_set_irq_type,
  509. };
  510. #ifdef CONFIG_SMP
  511. static struct irq_chip mpic_ipi_chip = {
  512. .mask = mpic_mask_ipi,
  513. .unmask = mpic_unmask_ipi,
  514. .eoi = mpic_end_ipi,
  515. };
  516. #endif /* CONFIG_SMP */
  517. #ifdef CONFIG_MPIC_BROKEN_U3
  518. static struct irq_chip mpic_irq_ht_chip = {
  519. .startup = mpic_startup_ht_irq,
  520. .shutdown = mpic_shutdown_ht_irq,
  521. .mask = mpic_mask_irq,
  522. .unmask = mpic_unmask_ht_irq,
  523. .eoi = mpic_end_ht_irq,
  524. .set_type = mpic_set_irq_type,
  525. };
  526. #endif /* CONFIG_MPIC_BROKEN_U3 */
  527. static int mpic_host_match(struct irq_host *h, struct device_node *node)
  528. {
  529. struct mpic *mpic = h->host_data;
  530. /* Exact match, unless mpic node is NULL */
  531. return mpic->of_node == NULL || mpic->of_node == node;
  532. }
  533. static int mpic_host_map(struct irq_host *h, unsigned int virq,
  534. irq_hw_number_t hw)
  535. {
  536. struct mpic *mpic = h->host_data;
  537. struct irq_chip *chip;
  538. DBG("mpic: map virq %d, hwirq 0x%lx\n", virq, hw);
  539. if (hw == MPIC_VEC_SPURRIOUS)
  540. return -EINVAL;
  541. #ifdef CONFIG_SMP
  542. else if (hw >= MPIC_VEC_IPI_0) {
  543. WARN_ON(!(mpic->flags & MPIC_PRIMARY));
  544. DBG("mpic: mapping as IPI\n");
  545. set_irq_chip_data(virq, mpic);
  546. set_irq_chip_and_handler(virq, &mpic->hc_ipi,
  547. handle_percpu_irq);
  548. return 0;
  549. }
  550. #endif /* CONFIG_SMP */
  551. if (hw >= mpic->irq_count)
  552. return -EINVAL;
  553. /* Default chip */
  554. chip = &mpic->hc_irq;
  555. #ifdef CONFIG_MPIC_BROKEN_U3
  556. /* Check for HT interrupts, override vecpri */
  557. if (mpic_is_ht_interrupt(mpic, hw))
  558. chip = &mpic->hc_ht_irq;
  559. #endif /* CONFIG_MPIC_BROKEN_U3 */
  560. DBG("mpic: mapping to irq chip @%p\n", chip);
  561. set_irq_chip_data(virq, mpic);
  562. set_irq_chip_and_handler(virq, chip, handle_fasteoi_irq);
  563. /* Set default irq type */
  564. set_irq_type(virq, IRQ_TYPE_NONE);
  565. return 0;
  566. }
  567. static int mpic_host_xlate(struct irq_host *h, struct device_node *ct,
  568. u32 *intspec, unsigned int intsize,
  569. irq_hw_number_t *out_hwirq, unsigned int *out_flags)
  570. {
  571. static unsigned char map_mpic_senses[4] = {
  572. IRQ_TYPE_EDGE_RISING,
  573. IRQ_TYPE_LEVEL_LOW,
  574. IRQ_TYPE_LEVEL_HIGH,
  575. IRQ_TYPE_EDGE_FALLING,
  576. };
  577. *out_hwirq = intspec[0];
  578. if (intsize > 1) {
  579. u32 mask = 0x3;
  580. /* Apple invented a new race of encoding on machines with
  581. * an HT APIC. They encode, among others, the index within
  582. * the HT APIC. We don't care about it here since thankfully,
  583. * it appears that they have the APIC already properly
  584. * configured, and thus our current fixup code that reads the
  585. * APIC config works fine. However, we still need to mask out
  586. * bits in the specifier to make sure we only get bit 0 which
  587. * is the level/edge bit (the only sense bit exposed by Apple),
  588. * as their bit 1 means something else.
  589. */
  590. if (machine_is(powermac))
  591. mask = 0x1;
  592. *out_flags = map_mpic_senses[intspec[1] & mask];
  593. } else
  594. *out_flags = IRQ_TYPE_NONE;
  595. DBG("mpic: xlate (%d cells: 0x%08x 0x%08x) to line 0x%lx sense 0x%x\n",
  596. intsize, intspec[0], intspec[1], *out_hwirq, *out_flags);
  597. return 0;
  598. }
  599. static struct irq_host_ops mpic_host_ops = {
  600. .match = mpic_host_match,
  601. .map = mpic_host_map,
  602. .xlate = mpic_host_xlate,
  603. };
  604. /*
  605. * Exported functions
  606. */
  607. struct mpic * __init mpic_alloc(struct device_node *node,
  608. unsigned long phys_addr,
  609. unsigned int flags,
  610. unsigned int isu_size,
  611. unsigned int irq_count,
  612. const char *name)
  613. {
  614. struct mpic *mpic;
  615. u32 reg;
  616. const char *vers;
  617. int i;
  618. mpic = alloc_bootmem(sizeof(struct mpic));
  619. if (mpic == NULL)
  620. return NULL;
  621. memset(mpic, 0, sizeof(struct mpic));
  622. mpic->name = name;
  623. mpic->of_node = node ? of_node_get(node) : NULL;
  624. mpic->irqhost = irq_alloc_host(IRQ_HOST_MAP_LINEAR, 256,
  625. &mpic_host_ops,
  626. MPIC_VEC_SPURRIOUS);
  627. if (mpic->irqhost == NULL) {
  628. of_node_put(node);
  629. return NULL;
  630. }
  631. mpic->irqhost->host_data = mpic;
  632. mpic->hc_irq = mpic_irq_chip;
  633. mpic->hc_irq.typename = name;
  634. if (flags & MPIC_PRIMARY)
  635. mpic->hc_irq.set_affinity = mpic_set_affinity;
  636. #ifdef CONFIG_MPIC_BROKEN_U3
  637. mpic->hc_ht_irq = mpic_irq_ht_chip;
  638. mpic->hc_ht_irq.typename = name;
  639. if (flags & MPIC_PRIMARY)
  640. mpic->hc_ht_irq.set_affinity = mpic_set_affinity;
  641. #endif /* CONFIG_MPIC_BROKEN_U3 */
  642. #ifdef CONFIG_SMP
  643. mpic->hc_ipi = mpic_ipi_chip;
  644. mpic->hc_ipi.typename = name;
  645. #endif /* CONFIG_SMP */
  646. mpic->flags = flags;
  647. mpic->isu_size = isu_size;
  648. mpic->irq_count = irq_count;
  649. mpic->num_sources = 0; /* so far */
  650. /* Map the global registers */
  651. mpic->gregs = ioremap(phys_addr + MPIC_GREG_BASE, 0x1000);
  652. mpic->tmregs = mpic->gregs + ((MPIC_TIMER_BASE - MPIC_GREG_BASE) >> 2);
  653. BUG_ON(mpic->gregs == NULL);
  654. /* Reset */
  655. if (flags & MPIC_WANTS_RESET) {
  656. mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_0,
  657. mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_0)
  658. | MPIC_GREG_GCONF_RESET);
  659. while( mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_0)
  660. & MPIC_GREG_GCONF_RESET)
  661. mb();
  662. }
  663. /* Read feature register, calculate num CPUs and, for non-ISU
  664. * MPICs, num sources as well. On ISU MPICs, sources are counted
  665. * as ISUs are added
  666. */
  667. reg = mpic_read(mpic->gregs, MPIC_GREG_FEATURE_0);
  668. mpic->num_cpus = ((reg & MPIC_GREG_FEATURE_LAST_CPU_MASK)
  669. >> MPIC_GREG_FEATURE_LAST_CPU_SHIFT) + 1;
  670. if (isu_size == 0)
  671. mpic->num_sources = ((reg & MPIC_GREG_FEATURE_LAST_SRC_MASK)
  672. >> MPIC_GREG_FEATURE_LAST_SRC_SHIFT) + 1;
  673. /* Map the per-CPU registers */
  674. for (i = 0; i < mpic->num_cpus; i++) {
  675. mpic->cpuregs[i] = ioremap(phys_addr + MPIC_CPU_BASE +
  676. i * MPIC_CPU_STRIDE, 0x1000);
  677. BUG_ON(mpic->cpuregs[i] == NULL);
  678. }
  679. /* Initialize main ISU if none provided */
  680. if (mpic->isu_size == 0) {
  681. mpic->isu_size = mpic->num_sources;
  682. mpic->isus[0] = ioremap(phys_addr + MPIC_IRQ_BASE,
  683. MPIC_IRQ_STRIDE * mpic->isu_size);
  684. BUG_ON(mpic->isus[0] == NULL);
  685. }
  686. mpic->isu_shift = 1 + __ilog2(mpic->isu_size - 1);
  687. mpic->isu_mask = (1 << mpic->isu_shift) - 1;
  688. /* Display version */
  689. switch (reg & MPIC_GREG_FEATURE_VERSION_MASK) {
  690. case 1:
  691. vers = "1.0";
  692. break;
  693. case 2:
  694. vers = "1.2";
  695. break;
  696. case 3:
  697. vers = "1.3";
  698. break;
  699. default:
  700. vers = "<unknown>";
  701. break;
  702. }
  703. printk(KERN_INFO "mpic: Setting up MPIC \"%s\" version %s at %lx, max %d CPUs\n",
  704. name, vers, phys_addr, mpic->num_cpus);
  705. printk(KERN_INFO "mpic: ISU size: %d, shift: %d, mask: %x\n", mpic->isu_size,
  706. mpic->isu_shift, mpic->isu_mask);
  707. mpic->next = mpics;
  708. mpics = mpic;
  709. if (flags & MPIC_PRIMARY) {
  710. mpic_primary = mpic;
  711. irq_set_default_host(mpic->irqhost);
  712. }
  713. return mpic;
  714. }
  715. void __init mpic_assign_isu(struct mpic *mpic, unsigned int isu_num,
  716. unsigned long phys_addr)
  717. {
  718. unsigned int isu_first = isu_num * mpic->isu_size;
  719. BUG_ON(isu_num >= MPIC_MAX_ISU);
  720. mpic->isus[isu_num] = ioremap(phys_addr, MPIC_IRQ_STRIDE * mpic->isu_size);
  721. if ((isu_first + mpic->isu_size) > mpic->num_sources)
  722. mpic->num_sources = isu_first + mpic->isu_size;
  723. }
  724. void __init mpic_set_default_senses(struct mpic *mpic, u8 *senses, int count)
  725. {
  726. mpic->senses = senses;
  727. mpic->senses_count = count;
  728. }
  729. void __init mpic_init(struct mpic *mpic)
  730. {
  731. int i;
  732. BUG_ON(mpic->num_sources == 0);
  733. WARN_ON(mpic->num_sources > MPIC_VEC_IPI_0);
  734. /* Sanitize source count */
  735. if (mpic->num_sources > MPIC_VEC_IPI_0)
  736. mpic->num_sources = MPIC_VEC_IPI_0;
  737. printk(KERN_INFO "mpic: Initializing for %d sources\n", mpic->num_sources);
  738. /* Set current processor priority to max */
  739. mpic_cpu_write(MPIC_CPU_CURRENT_TASK_PRI, 0xf);
  740. /* Initialize timers: just disable them all */
  741. for (i = 0; i < 4; i++) {
  742. mpic_write(mpic->tmregs,
  743. i * MPIC_TIMER_STRIDE + MPIC_TIMER_DESTINATION, 0);
  744. mpic_write(mpic->tmregs,
  745. i * MPIC_TIMER_STRIDE + MPIC_TIMER_VECTOR_PRI,
  746. MPIC_VECPRI_MASK |
  747. (MPIC_VEC_TIMER_0 + i));
  748. }
  749. /* Initialize IPIs to our reserved vectors and mark them disabled for now */
  750. mpic_test_broken_ipi(mpic);
  751. for (i = 0; i < 4; i++) {
  752. mpic_ipi_write(i,
  753. MPIC_VECPRI_MASK |
  754. (10 << MPIC_VECPRI_PRIORITY_SHIFT) |
  755. (MPIC_VEC_IPI_0 + i));
  756. }
  757. /* Initialize interrupt sources */
  758. if (mpic->irq_count == 0)
  759. mpic->irq_count = mpic->num_sources;
  760. /* Do the HT PIC fixups on U3 broken mpic */
  761. DBG("MPIC flags: %x\n", mpic->flags);
  762. if ((mpic->flags & MPIC_BROKEN_U3) && (mpic->flags & MPIC_PRIMARY))
  763. mpic_scan_ht_pics(mpic);
  764. for (i = 0; i < mpic->num_sources; i++) {
  765. /* start with vector = source number, and masked */
  766. u32 vecpri = MPIC_VECPRI_MASK | i |
  767. (8 << MPIC_VECPRI_PRIORITY_SHIFT);
  768. /* init hw */
  769. mpic_irq_write(i, MPIC_IRQ_VECTOR_PRI, vecpri);
  770. mpic_irq_write(i, MPIC_IRQ_DESTINATION,
  771. 1 << hard_smp_processor_id());
  772. }
  773. /* Init spurrious vector */
  774. mpic_write(mpic->gregs, MPIC_GREG_SPURIOUS, MPIC_VEC_SPURRIOUS);
  775. /* Disable 8259 passthrough */
  776. mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_0,
  777. mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_0)
  778. | MPIC_GREG_GCONF_8259_PTHROU_DIS);
  779. /* Set current processor priority to 0 */
  780. mpic_cpu_write(MPIC_CPU_CURRENT_TASK_PRI, 0);
  781. }
  782. void __init mpic_set_clk_ratio(struct mpic *mpic, u32 clock_ratio)
  783. {
  784. u32 v;
  785. v = mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1);
  786. v &= ~MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO_MASK;
  787. v |= MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO(clock_ratio);
  788. mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v);
  789. }
  790. void __init mpic_set_serial_int(struct mpic *mpic, int enable)
  791. {
  792. unsigned long flags;
  793. u32 v;
  794. spin_lock_irqsave(&mpic_lock, flags);
  795. v = mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1);
  796. if (enable)
  797. v |= MPIC_GREG_GLOBAL_CONF_1_SIE;
  798. else
  799. v &= ~MPIC_GREG_GLOBAL_CONF_1_SIE;
  800. mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v);
  801. spin_unlock_irqrestore(&mpic_lock, flags);
  802. }
  803. void mpic_irq_set_priority(unsigned int irq, unsigned int pri)
  804. {
  805. int is_ipi;
  806. struct mpic *mpic = mpic_find(irq, &is_ipi);
  807. unsigned int src = mpic_irq_to_hw(irq);
  808. unsigned long flags;
  809. u32 reg;
  810. spin_lock_irqsave(&mpic_lock, flags);
  811. if (is_ipi) {
  812. reg = mpic_ipi_read(src - MPIC_VEC_IPI_0) &
  813. ~MPIC_VECPRI_PRIORITY_MASK;
  814. mpic_ipi_write(src - MPIC_VEC_IPI_0,
  815. reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
  816. } else {
  817. reg = mpic_irq_read(src, MPIC_IRQ_VECTOR_PRI)
  818. & ~MPIC_VECPRI_PRIORITY_MASK;
  819. mpic_irq_write(src, MPIC_IRQ_VECTOR_PRI,
  820. reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
  821. }
  822. spin_unlock_irqrestore(&mpic_lock, flags);
  823. }
  824. unsigned int mpic_irq_get_priority(unsigned int irq)
  825. {
  826. int is_ipi;
  827. struct mpic *mpic = mpic_find(irq, &is_ipi);
  828. unsigned int src = mpic_irq_to_hw(irq);
  829. unsigned long flags;
  830. u32 reg;
  831. spin_lock_irqsave(&mpic_lock, flags);
  832. if (is_ipi)
  833. reg = mpic_ipi_read(src = MPIC_VEC_IPI_0);
  834. else
  835. reg = mpic_irq_read(src, MPIC_IRQ_VECTOR_PRI);
  836. spin_unlock_irqrestore(&mpic_lock, flags);
  837. return (reg & MPIC_VECPRI_PRIORITY_MASK) >> MPIC_VECPRI_PRIORITY_SHIFT;
  838. }
  839. void mpic_setup_this_cpu(void)
  840. {
  841. #ifdef CONFIG_SMP
  842. struct mpic *mpic = mpic_primary;
  843. unsigned long flags;
  844. u32 msk = 1 << hard_smp_processor_id();
  845. unsigned int i;
  846. BUG_ON(mpic == NULL);
  847. DBG("%s: setup_this_cpu(%d)\n", mpic->name, hard_smp_processor_id());
  848. spin_lock_irqsave(&mpic_lock, flags);
  849. /* let the mpic know we want intrs. default affinity is 0xffffffff
  850. * until changed via /proc. That's how it's done on x86. If we want
  851. * it differently, then we should make sure we also change the default
  852. * values of irq_desc[].affinity in irq.c.
  853. */
  854. if (distribute_irqs) {
  855. for (i = 0; i < mpic->num_sources ; i++)
  856. mpic_irq_write(i, MPIC_IRQ_DESTINATION,
  857. mpic_irq_read(i, MPIC_IRQ_DESTINATION) | msk);
  858. }
  859. /* Set current processor priority to 0 */
  860. mpic_cpu_write(MPIC_CPU_CURRENT_TASK_PRI, 0);
  861. spin_unlock_irqrestore(&mpic_lock, flags);
  862. #endif /* CONFIG_SMP */
  863. }
  864. int mpic_cpu_get_priority(void)
  865. {
  866. struct mpic *mpic = mpic_primary;
  867. return mpic_cpu_read(MPIC_CPU_CURRENT_TASK_PRI);
  868. }
  869. void mpic_cpu_set_priority(int prio)
  870. {
  871. struct mpic *mpic = mpic_primary;
  872. prio &= MPIC_CPU_TASKPRI_MASK;
  873. mpic_cpu_write(MPIC_CPU_CURRENT_TASK_PRI, prio);
  874. }
  875. /*
  876. * XXX: someone who knows mpic should check this.
  877. * do we need to eoi the ipi including for kexec cpu here (see xics comments)?
  878. * or can we reset the mpic in the new kernel?
  879. */
  880. void mpic_teardown_this_cpu(int secondary)
  881. {
  882. struct mpic *mpic = mpic_primary;
  883. unsigned long flags;
  884. u32 msk = 1 << hard_smp_processor_id();
  885. unsigned int i;
  886. BUG_ON(mpic == NULL);
  887. DBG("%s: teardown_this_cpu(%d)\n", mpic->name, hard_smp_processor_id());
  888. spin_lock_irqsave(&mpic_lock, flags);
  889. /* let the mpic know we don't want intrs. */
  890. for (i = 0; i < mpic->num_sources ; i++)
  891. mpic_irq_write(i, MPIC_IRQ_DESTINATION,
  892. mpic_irq_read(i, MPIC_IRQ_DESTINATION) & ~msk);
  893. /* Set current processor priority to max */
  894. mpic_cpu_write(MPIC_CPU_CURRENT_TASK_PRI, 0xf);
  895. spin_unlock_irqrestore(&mpic_lock, flags);
  896. }
  897. void mpic_send_ipi(unsigned int ipi_no, unsigned int cpu_mask)
  898. {
  899. struct mpic *mpic = mpic_primary;
  900. BUG_ON(mpic == NULL);
  901. #ifdef DEBUG_IPI
  902. DBG("%s: send_ipi(ipi_no: %d)\n", mpic->name, ipi_no);
  903. #endif
  904. mpic_cpu_write(MPIC_CPU_IPI_DISPATCH_0 + ipi_no * 0x10,
  905. mpic_physmask(cpu_mask & cpus_addr(cpu_online_map)[0]));
  906. }
  907. unsigned int mpic_get_one_irq(struct mpic *mpic, struct pt_regs *regs)
  908. {
  909. u32 src;
  910. src = mpic_cpu_read(MPIC_CPU_INTACK) & MPIC_VECPRI_VECTOR_MASK;
  911. #ifdef DEBUG_LOW
  912. DBG("%s: get_one_irq(): %d\n", mpic->name, src);
  913. #endif
  914. if (unlikely(src == MPIC_VEC_SPURRIOUS))
  915. return NO_IRQ;
  916. return irq_linear_revmap(mpic->irqhost, src);
  917. }
  918. unsigned int mpic_get_irq(struct pt_regs *regs)
  919. {
  920. struct mpic *mpic = mpic_primary;
  921. BUG_ON(mpic == NULL);
  922. return mpic_get_one_irq(mpic, regs);
  923. }
  924. #ifdef CONFIG_SMP
  925. void mpic_request_ipis(void)
  926. {
  927. struct mpic *mpic = mpic_primary;
  928. int i;
  929. static char *ipi_names[] = {
  930. "IPI0 (call function)",
  931. "IPI1 (reschedule)",
  932. "IPI2 (unused)",
  933. "IPI3 (debugger break)",
  934. };
  935. BUG_ON(mpic == NULL);
  936. printk(KERN_INFO "mpic: requesting IPIs ... \n");
  937. for (i = 0; i < 4; i++) {
  938. unsigned int vipi = irq_create_mapping(mpic->irqhost,
  939. MPIC_VEC_IPI_0 + i);
  940. if (vipi == NO_IRQ) {
  941. printk(KERN_ERR "Failed to map IPI %d\n", i);
  942. break;
  943. }
  944. request_irq(vipi, mpic_ipi_action, IRQF_DISABLED,
  945. ipi_names[i], mpic);
  946. }
  947. }
  948. void smp_mpic_message_pass(int target, int msg)
  949. {
  950. /* make sure we're sending something that translates to an IPI */
  951. if ((unsigned int)msg > 3) {
  952. printk("SMP %d: smp_message_pass: unknown msg %d\n",
  953. smp_processor_id(), msg);
  954. return;
  955. }
  956. switch (target) {
  957. case MSG_ALL:
  958. mpic_send_ipi(msg, 0xffffffff);
  959. break;
  960. case MSG_ALL_BUT_SELF:
  961. mpic_send_ipi(msg, 0xffffffff & ~(1 << smp_processor_id()));
  962. break;
  963. default:
  964. mpic_send_ipi(msg, 1 << target);
  965. break;
  966. }
  967. }
  968. #endif /* CONFIG_SMP */