mpic.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850
  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. * Copyright 2010-2011 Freescale Semiconductor, Inc.
  10. *
  11. * This file is subject to the terms and conditions of the GNU General Public
  12. * License. See the file COPYING in the main directory of this archive
  13. * for more details.
  14. */
  15. #undef DEBUG
  16. #undef DEBUG_IPI
  17. #undef DEBUG_IRQ
  18. #undef DEBUG_LOW
  19. #include <linux/types.h>
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/irq.h>
  23. #include <linux/smp.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/bootmem.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/pci.h>
  28. #include <linux/slab.h>
  29. #include <linux/syscore_ops.h>
  30. #include <linux/ratelimit.h>
  31. #include <asm/ptrace.h>
  32. #include <asm/signal.h>
  33. #include <asm/io.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/irq.h>
  36. #include <asm/machdep.h>
  37. #include <asm/mpic.h>
  38. #include <asm/smp.h>
  39. #include "mpic.h"
  40. #ifdef DEBUG
  41. #define DBG(fmt...) printk(fmt)
  42. #else
  43. #define DBG(fmt...)
  44. #endif
  45. static struct mpic *mpics;
  46. static struct mpic *mpic_primary;
  47. static DEFINE_RAW_SPINLOCK(mpic_lock);
  48. #ifdef CONFIG_PPC32 /* XXX for now */
  49. #ifdef CONFIG_IRQ_ALL_CPUS
  50. #define distribute_irqs (1)
  51. #else
  52. #define distribute_irqs (0)
  53. #endif
  54. #endif
  55. #ifdef CONFIG_MPIC_WEIRD
  56. static u32 mpic_infos[][MPIC_IDX_END] = {
  57. [0] = { /* Original OpenPIC compatible MPIC */
  58. MPIC_GREG_BASE,
  59. MPIC_GREG_FEATURE_0,
  60. MPIC_GREG_GLOBAL_CONF_0,
  61. MPIC_GREG_VENDOR_ID,
  62. MPIC_GREG_IPI_VECTOR_PRI_0,
  63. MPIC_GREG_IPI_STRIDE,
  64. MPIC_GREG_SPURIOUS,
  65. MPIC_GREG_TIMER_FREQ,
  66. MPIC_TIMER_BASE,
  67. MPIC_TIMER_STRIDE,
  68. MPIC_TIMER_CURRENT_CNT,
  69. MPIC_TIMER_BASE_CNT,
  70. MPIC_TIMER_VECTOR_PRI,
  71. MPIC_TIMER_DESTINATION,
  72. MPIC_CPU_BASE,
  73. MPIC_CPU_STRIDE,
  74. MPIC_CPU_IPI_DISPATCH_0,
  75. MPIC_CPU_IPI_DISPATCH_STRIDE,
  76. MPIC_CPU_CURRENT_TASK_PRI,
  77. MPIC_CPU_WHOAMI,
  78. MPIC_CPU_INTACK,
  79. MPIC_CPU_EOI,
  80. MPIC_CPU_MCACK,
  81. MPIC_IRQ_BASE,
  82. MPIC_IRQ_STRIDE,
  83. MPIC_IRQ_VECTOR_PRI,
  84. MPIC_VECPRI_VECTOR_MASK,
  85. MPIC_VECPRI_POLARITY_POSITIVE,
  86. MPIC_VECPRI_POLARITY_NEGATIVE,
  87. MPIC_VECPRI_SENSE_LEVEL,
  88. MPIC_VECPRI_SENSE_EDGE,
  89. MPIC_VECPRI_POLARITY_MASK,
  90. MPIC_VECPRI_SENSE_MASK,
  91. MPIC_IRQ_DESTINATION
  92. },
  93. [1] = { /* Tsi108/109 PIC */
  94. TSI108_GREG_BASE,
  95. TSI108_GREG_FEATURE_0,
  96. TSI108_GREG_GLOBAL_CONF_0,
  97. TSI108_GREG_VENDOR_ID,
  98. TSI108_GREG_IPI_VECTOR_PRI_0,
  99. TSI108_GREG_IPI_STRIDE,
  100. TSI108_GREG_SPURIOUS,
  101. TSI108_GREG_TIMER_FREQ,
  102. TSI108_TIMER_BASE,
  103. TSI108_TIMER_STRIDE,
  104. TSI108_TIMER_CURRENT_CNT,
  105. TSI108_TIMER_BASE_CNT,
  106. TSI108_TIMER_VECTOR_PRI,
  107. TSI108_TIMER_DESTINATION,
  108. TSI108_CPU_BASE,
  109. TSI108_CPU_STRIDE,
  110. TSI108_CPU_IPI_DISPATCH_0,
  111. TSI108_CPU_IPI_DISPATCH_STRIDE,
  112. TSI108_CPU_CURRENT_TASK_PRI,
  113. TSI108_CPU_WHOAMI,
  114. TSI108_CPU_INTACK,
  115. TSI108_CPU_EOI,
  116. TSI108_CPU_MCACK,
  117. TSI108_IRQ_BASE,
  118. TSI108_IRQ_STRIDE,
  119. TSI108_IRQ_VECTOR_PRI,
  120. TSI108_VECPRI_VECTOR_MASK,
  121. TSI108_VECPRI_POLARITY_POSITIVE,
  122. TSI108_VECPRI_POLARITY_NEGATIVE,
  123. TSI108_VECPRI_SENSE_LEVEL,
  124. TSI108_VECPRI_SENSE_EDGE,
  125. TSI108_VECPRI_POLARITY_MASK,
  126. TSI108_VECPRI_SENSE_MASK,
  127. TSI108_IRQ_DESTINATION
  128. },
  129. };
  130. #define MPIC_INFO(name) mpic->hw_set[MPIC_IDX_##name]
  131. #else /* CONFIG_MPIC_WEIRD */
  132. #define MPIC_INFO(name) MPIC_##name
  133. #endif /* CONFIG_MPIC_WEIRD */
  134. static inline unsigned int mpic_processor_id(struct mpic *mpic)
  135. {
  136. unsigned int cpu = 0;
  137. if (mpic->flags & MPIC_PRIMARY)
  138. cpu = hard_smp_processor_id();
  139. return cpu;
  140. }
  141. /*
  142. * Register accessor functions
  143. */
  144. static inline u32 _mpic_read(enum mpic_reg_type type,
  145. struct mpic_reg_bank *rb,
  146. unsigned int reg)
  147. {
  148. switch(type) {
  149. #ifdef CONFIG_PPC_DCR
  150. case mpic_access_dcr:
  151. return dcr_read(rb->dhost, reg);
  152. #endif
  153. case mpic_access_mmio_be:
  154. return in_be32(rb->base + (reg >> 2));
  155. case mpic_access_mmio_le:
  156. default:
  157. return in_le32(rb->base + (reg >> 2));
  158. }
  159. }
  160. static inline void _mpic_write(enum mpic_reg_type type,
  161. struct mpic_reg_bank *rb,
  162. unsigned int reg, u32 value)
  163. {
  164. switch(type) {
  165. #ifdef CONFIG_PPC_DCR
  166. case mpic_access_dcr:
  167. dcr_write(rb->dhost, reg, value);
  168. break;
  169. #endif
  170. case mpic_access_mmio_be:
  171. out_be32(rb->base + (reg >> 2), value);
  172. break;
  173. case mpic_access_mmio_le:
  174. default:
  175. out_le32(rb->base + (reg >> 2), value);
  176. break;
  177. }
  178. }
  179. static inline u32 _mpic_ipi_read(struct mpic *mpic, unsigned int ipi)
  180. {
  181. enum mpic_reg_type type = mpic->reg_type;
  182. unsigned int offset = MPIC_INFO(GREG_IPI_VECTOR_PRI_0) +
  183. (ipi * MPIC_INFO(GREG_IPI_STRIDE));
  184. if ((mpic->flags & MPIC_BROKEN_IPI) && type == mpic_access_mmio_le)
  185. type = mpic_access_mmio_be;
  186. return _mpic_read(type, &mpic->gregs, offset);
  187. }
  188. static inline void _mpic_ipi_write(struct mpic *mpic, unsigned int ipi, u32 value)
  189. {
  190. unsigned int offset = MPIC_INFO(GREG_IPI_VECTOR_PRI_0) +
  191. (ipi * MPIC_INFO(GREG_IPI_STRIDE));
  192. _mpic_write(mpic->reg_type, &mpic->gregs, offset, value);
  193. }
  194. static inline u32 _mpic_tm_read(struct mpic *mpic, unsigned int tm)
  195. {
  196. unsigned int offset = MPIC_INFO(TIMER_VECTOR_PRI) +
  197. ((tm & 3) * MPIC_INFO(TIMER_STRIDE));
  198. if (tm >= 4)
  199. offset += 0x1000 / 4;
  200. return _mpic_read(mpic->reg_type, &mpic->tmregs, offset);
  201. }
  202. static inline void _mpic_tm_write(struct mpic *mpic, unsigned int tm, u32 value)
  203. {
  204. unsigned int offset = MPIC_INFO(TIMER_VECTOR_PRI) +
  205. ((tm & 3) * MPIC_INFO(TIMER_STRIDE));
  206. if (tm >= 4)
  207. offset += 0x1000 / 4;
  208. _mpic_write(mpic->reg_type, &mpic->tmregs, offset, value);
  209. }
  210. static inline u32 _mpic_cpu_read(struct mpic *mpic, unsigned int reg)
  211. {
  212. unsigned int cpu = mpic_processor_id(mpic);
  213. return _mpic_read(mpic->reg_type, &mpic->cpuregs[cpu], reg);
  214. }
  215. static inline void _mpic_cpu_write(struct mpic *mpic, unsigned int reg, u32 value)
  216. {
  217. unsigned int cpu = mpic_processor_id(mpic);
  218. _mpic_write(mpic->reg_type, &mpic->cpuregs[cpu], reg, value);
  219. }
  220. static inline u32 _mpic_irq_read(struct mpic *mpic, unsigned int src_no, unsigned int reg)
  221. {
  222. unsigned int isu = src_no >> mpic->isu_shift;
  223. unsigned int idx = src_no & mpic->isu_mask;
  224. unsigned int val;
  225. val = _mpic_read(mpic->reg_type, &mpic->isus[isu],
  226. reg + (idx * MPIC_INFO(IRQ_STRIDE)));
  227. #ifdef CONFIG_MPIC_BROKEN_REGREAD
  228. if (reg == 0)
  229. val = (val & (MPIC_VECPRI_MASK | MPIC_VECPRI_ACTIVITY)) |
  230. mpic->isu_reg0_shadow[src_no];
  231. #endif
  232. return val;
  233. }
  234. static inline void _mpic_irq_write(struct mpic *mpic, unsigned int src_no,
  235. unsigned int reg, u32 value)
  236. {
  237. unsigned int isu = src_no >> mpic->isu_shift;
  238. unsigned int idx = src_no & mpic->isu_mask;
  239. _mpic_write(mpic->reg_type, &mpic->isus[isu],
  240. reg + (idx * MPIC_INFO(IRQ_STRIDE)), value);
  241. #ifdef CONFIG_MPIC_BROKEN_REGREAD
  242. if (reg == 0)
  243. mpic->isu_reg0_shadow[src_no] =
  244. value & ~(MPIC_VECPRI_MASK | MPIC_VECPRI_ACTIVITY);
  245. #endif
  246. }
  247. #define mpic_read(b,r) _mpic_read(mpic->reg_type,&(b),(r))
  248. #define mpic_write(b,r,v) _mpic_write(mpic->reg_type,&(b),(r),(v))
  249. #define mpic_ipi_read(i) _mpic_ipi_read(mpic,(i))
  250. #define mpic_ipi_write(i,v) _mpic_ipi_write(mpic,(i),(v))
  251. #define mpic_tm_read(i) _mpic_tm_read(mpic,(i))
  252. #define mpic_tm_write(i,v) _mpic_tm_write(mpic,(i),(v))
  253. #define mpic_cpu_read(i) _mpic_cpu_read(mpic,(i))
  254. #define mpic_cpu_write(i,v) _mpic_cpu_write(mpic,(i),(v))
  255. #define mpic_irq_read(s,r) _mpic_irq_read(mpic,(s),(r))
  256. #define mpic_irq_write(s,r,v) _mpic_irq_write(mpic,(s),(r),(v))
  257. /*
  258. * Low level utility functions
  259. */
  260. static void _mpic_map_mmio(struct mpic *mpic, phys_addr_t phys_addr,
  261. struct mpic_reg_bank *rb, unsigned int offset,
  262. unsigned int size)
  263. {
  264. rb->base = ioremap(phys_addr + offset, size);
  265. BUG_ON(rb->base == NULL);
  266. }
  267. #ifdef CONFIG_PPC_DCR
  268. static void _mpic_map_dcr(struct mpic *mpic, struct device_node *node,
  269. struct mpic_reg_bank *rb,
  270. unsigned int offset, unsigned int size)
  271. {
  272. const u32 *dbasep;
  273. dbasep = of_get_property(node, "dcr-reg", NULL);
  274. rb->dhost = dcr_map(node, *dbasep + offset, size);
  275. BUG_ON(!DCR_MAP_OK(rb->dhost));
  276. }
  277. static inline void mpic_map(struct mpic *mpic, struct device_node *node,
  278. phys_addr_t phys_addr, struct mpic_reg_bank *rb,
  279. unsigned int offset, unsigned int size)
  280. {
  281. if (mpic->flags & MPIC_USES_DCR)
  282. _mpic_map_dcr(mpic, node, rb, offset, size);
  283. else
  284. _mpic_map_mmio(mpic, phys_addr, rb, offset, size);
  285. }
  286. #else /* CONFIG_PPC_DCR */
  287. #define mpic_map(m,n,p,b,o,s) _mpic_map_mmio(m,p,b,o,s)
  288. #endif /* !CONFIG_PPC_DCR */
  289. /* Check if we have one of those nice broken MPICs with a flipped endian on
  290. * reads from IPI registers
  291. */
  292. static void __init mpic_test_broken_ipi(struct mpic *mpic)
  293. {
  294. u32 r;
  295. mpic_write(mpic->gregs, MPIC_INFO(GREG_IPI_VECTOR_PRI_0), MPIC_VECPRI_MASK);
  296. r = mpic_read(mpic->gregs, MPIC_INFO(GREG_IPI_VECTOR_PRI_0));
  297. if (r == le32_to_cpu(MPIC_VECPRI_MASK)) {
  298. printk(KERN_INFO "mpic: Detected reversed IPI registers\n");
  299. mpic->flags |= MPIC_BROKEN_IPI;
  300. }
  301. }
  302. #ifdef CONFIG_MPIC_U3_HT_IRQS
  303. /* Test if an interrupt is sourced from HyperTransport (used on broken U3s)
  304. * to force the edge setting on the MPIC and do the ack workaround.
  305. */
  306. static inline int mpic_is_ht_interrupt(struct mpic *mpic, unsigned int source)
  307. {
  308. if (source >= 128 || !mpic->fixups)
  309. return 0;
  310. return mpic->fixups[source].base != NULL;
  311. }
  312. static inline void mpic_ht_end_irq(struct mpic *mpic, unsigned int source)
  313. {
  314. struct mpic_irq_fixup *fixup = &mpic->fixups[source];
  315. if (fixup->applebase) {
  316. unsigned int soff = (fixup->index >> 3) & ~3;
  317. unsigned int mask = 1U << (fixup->index & 0x1f);
  318. writel(mask, fixup->applebase + soff);
  319. } else {
  320. raw_spin_lock(&mpic->fixup_lock);
  321. writeb(0x11 + 2 * fixup->index, fixup->base + 2);
  322. writel(fixup->data, fixup->base + 4);
  323. raw_spin_unlock(&mpic->fixup_lock);
  324. }
  325. }
  326. static void mpic_startup_ht_interrupt(struct mpic *mpic, unsigned int source,
  327. bool level)
  328. {
  329. struct mpic_irq_fixup *fixup = &mpic->fixups[source];
  330. unsigned long flags;
  331. u32 tmp;
  332. if (fixup->base == NULL)
  333. return;
  334. DBG("startup_ht_interrupt(0x%x) index: %d\n",
  335. source, fixup->index);
  336. raw_spin_lock_irqsave(&mpic->fixup_lock, flags);
  337. /* Enable and configure */
  338. writeb(0x10 + 2 * fixup->index, fixup->base + 2);
  339. tmp = readl(fixup->base + 4);
  340. tmp &= ~(0x23U);
  341. if (level)
  342. tmp |= 0x22;
  343. writel(tmp, fixup->base + 4);
  344. raw_spin_unlock_irqrestore(&mpic->fixup_lock, flags);
  345. #ifdef CONFIG_PM
  346. /* use the lowest bit inverted to the actual HW,
  347. * set if this fixup was enabled, clear otherwise */
  348. mpic->save_data[source].fixup_data = tmp | 1;
  349. #endif
  350. }
  351. static void mpic_shutdown_ht_interrupt(struct mpic *mpic, unsigned int source)
  352. {
  353. struct mpic_irq_fixup *fixup = &mpic->fixups[source];
  354. unsigned long flags;
  355. u32 tmp;
  356. if (fixup->base == NULL)
  357. return;
  358. DBG("shutdown_ht_interrupt(0x%x)\n", source);
  359. /* Disable */
  360. raw_spin_lock_irqsave(&mpic->fixup_lock, flags);
  361. writeb(0x10 + 2 * fixup->index, fixup->base + 2);
  362. tmp = readl(fixup->base + 4);
  363. tmp |= 1;
  364. writel(tmp, fixup->base + 4);
  365. raw_spin_unlock_irqrestore(&mpic->fixup_lock, flags);
  366. #ifdef CONFIG_PM
  367. /* use the lowest bit inverted to the actual HW,
  368. * set if this fixup was enabled, clear otherwise */
  369. mpic->save_data[source].fixup_data = tmp & ~1;
  370. #endif
  371. }
  372. #ifdef CONFIG_PCI_MSI
  373. static void __init mpic_scan_ht_msi(struct mpic *mpic, u8 __iomem *devbase,
  374. unsigned int devfn)
  375. {
  376. u8 __iomem *base;
  377. u8 pos, flags;
  378. u64 addr = 0;
  379. for (pos = readb(devbase + PCI_CAPABILITY_LIST); pos != 0;
  380. pos = readb(devbase + pos + PCI_CAP_LIST_NEXT)) {
  381. u8 id = readb(devbase + pos + PCI_CAP_LIST_ID);
  382. if (id == PCI_CAP_ID_HT) {
  383. id = readb(devbase + pos + 3);
  384. if ((id & HT_5BIT_CAP_MASK) == HT_CAPTYPE_MSI_MAPPING)
  385. break;
  386. }
  387. }
  388. if (pos == 0)
  389. return;
  390. base = devbase + pos;
  391. flags = readb(base + HT_MSI_FLAGS);
  392. if (!(flags & HT_MSI_FLAGS_FIXED)) {
  393. addr = readl(base + HT_MSI_ADDR_LO) & HT_MSI_ADDR_LO_MASK;
  394. addr = addr | ((u64)readl(base + HT_MSI_ADDR_HI) << 32);
  395. }
  396. printk(KERN_DEBUG "mpic: - HT:%02x.%x %s MSI mapping found @ 0x%llx\n",
  397. PCI_SLOT(devfn), PCI_FUNC(devfn),
  398. flags & HT_MSI_FLAGS_ENABLE ? "enabled" : "disabled", addr);
  399. if (!(flags & HT_MSI_FLAGS_ENABLE))
  400. writeb(flags | HT_MSI_FLAGS_ENABLE, base + HT_MSI_FLAGS);
  401. }
  402. #else
  403. static void __init mpic_scan_ht_msi(struct mpic *mpic, u8 __iomem *devbase,
  404. unsigned int devfn)
  405. {
  406. return;
  407. }
  408. #endif
  409. static void __init mpic_scan_ht_pic(struct mpic *mpic, u8 __iomem *devbase,
  410. unsigned int devfn, u32 vdid)
  411. {
  412. int i, irq, n;
  413. u8 __iomem *base;
  414. u32 tmp;
  415. u8 pos;
  416. for (pos = readb(devbase + PCI_CAPABILITY_LIST); pos != 0;
  417. pos = readb(devbase + pos + PCI_CAP_LIST_NEXT)) {
  418. u8 id = readb(devbase + pos + PCI_CAP_LIST_ID);
  419. if (id == PCI_CAP_ID_HT) {
  420. id = readb(devbase + pos + 3);
  421. if ((id & HT_5BIT_CAP_MASK) == HT_CAPTYPE_IRQ)
  422. break;
  423. }
  424. }
  425. if (pos == 0)
  426. return;
  427. base = devbase + pos;
  428. writeb(0x01, base + 2);
  429. n = (readl(base + 4) >> 16) & 0xff;
  430. printk(KERN_INFO "mpic: - HT:%02x.%x [0x%02x] vendor %04x device %04x"
  431. " has %d irqs\n",
  432. devfn >> 3, devfn & 0x7, pos, vdid & 0xffff, vdid >> 16, n + 1);
  433. for (i = 0; i <= n; i++) {
  434. writeb(0x10 + 2 * i, base + 2);
  435. tmp = readl(base + 4);
  436. irq = (tmp >> 16) & 0xff;
  437. DBG("HT PIC index 0x%x, irq 0x%x, tmp: %08x\n", i, irq, tmp);
  438. /* mask it , will be unmasked later */
  439. tmp |= 0x1;
  440. writel(tmp, base + 4);
  441. mpic->fixups[irq].index = i;
  442. mpic->fixups[irq].base = base;
  443. /* Apple HT PIC has a non-standard way of doing EOIs */
  444. if ((vdid & 0xffff) == 0x106b)
  445. mpic->fixups[irq].applebase = devbase + 0x60;
  446. else
  447. mpic->fixups[irq].applebase = NULL;
  448. writeb(0x11 + 2 * i, base + 2);
  449. mpic->fixups[irq].data = readl(base + 4) | 0x80000000;
  450. }
  451. }
  452. static void __init mpic_scan_ht_pics(struct mpic *mpic)
  453. {
  454. unsigned int devfn;
  455. u8 __iomem *cfgspace;
  456. printk(KERN_INFO "mpic: Setting up HT PICs workarounds for U3/U4\n");
  457. /* Allocate fixups array */
  458. mpic->fixups = kzalloc(128 * sizeof(*mpic->fixups), GFP_KERNEL);
  459. BUG_ON(mpic->fixups == NULL);
  460. /* Init spinlock */
  461. raw_spin_lock_init(&mpic->fixup_lock);
  462. /* Map U3 config space. We assume all IO-APICs are on the primary bus
  463. * so we only need to map 64kB.
  464. */
  465. cfgspace = ioremap(0xf2000000, 0x10000);
  466. BUG_ON(cfgspace == NULL);
  467. /* Now we scan all slots. We do a very quick scan, we read the header
  468. * type, vendor ID and device ID only, that's plenty enough
  469. */
  470. for (devfn = 0; devfn < 0x100; devfn++) {
  471. u8 __iomem *devbase = cfgspace + (devfn << 8);
  472. u8 hdr_type = readb(devbase + PCI_HEADER_TYPE);
  473. u32 l = readl(devbase + PCI_VENDOR_ID);
  474. u16 s;
  475. DBG("devfn %x, l: %x\n", devfn, l);
  476. /* If no device, skip */
  477. if (l == 0xffffffff || l == 0x00000000 ||
  478. l == 0x0000ffff || l == 0xffff0000)
  479. goto next;
  480. /* Check if is supports capability lists */
  481. s = readw(devbase + PCI_STATUS);
  482. if (!(s & PCI_STATUS_CAP_LIST))
  483. goto next;
  484. mpic_scan_ht_pic(mpic, devbase, devfn, l);
  485. mpic_scan_ht_msi(mpic, devbase, devfn);
  486. next:
  487. /* next device, if function 0 */
  488. if (PCI_FUNC(devfn) == 0 && (hdr_type & 0x80) == 0)
  489. devfn += 7;
  490. }
  491. }
  492. #else /* CONFIG_MPIC_U3_HT_IRQS */
  493. static inline int mpic_is_ht_interrupt(struct mpic *mpic, unsigned int source)
  494. {
  495. return 0;
  496. }
  497. static void __init mpic_scan_ht_pics(struct mpic *mpic)
  498. {
  499. }
  500. #endif /* CONFIG_MPIC_U3_HT_IRQS */
  501. /* Find an mpic associated with a given linux interrupt */
  502. static struct mpic *mpic_find(unsigned int irq)
  503. {
  504. if (irq < NUM_ISA_INTERRUPTS)
  505. return NULL;
  506. return irq_get_chip_data(irq);
  507. }
  508. /* Determine if the linux irq is an IPI */
  509. static unsigned int mpic_is_ipi(struct mpic *mpic, unsigned int irq)
  510. {
  511. unsigned int src = virq_to_hw(irq);
  512. return (src >= mpic->ipi_vecs[0] && src <= mpic->ipi_vecs[3]);
  513. }
  514. /* Determine if the linux irq is a timer */
  515. static unsigned int mpic_is_tm(struct mpic *mpic, unsigned int irq)
  516. {
  517. unsigned int src = virq_to_hw(irq);
  518. return (src >= mpic->timer_vecs[0] && src <= mpic->timer_vecs[7]);
  519. }
  520. /* Convert a cpu mask from logical to physical cpu numbers. */
  521. static inline u32 mpic_physmask(u32 cpumask)
  522. {
  523. int i;
  524. u32 mask = 0;
  525. for (i = 0; i < min(32, NR_CPUS); ++i, cpumask >>= 1)
  526. mask |= (cpumask & 1) << get_hard_smp_processor_id(i);
  527. return mask;
  528. }
  529. #ifdef CONFIG_SMP
  530. /* Get the mpic structure from the IPI number */
  531. static inline struct mpic * mpic_from_ipi(struct irq_data *d)
  532. {
  533. return irq_data_get_irq_chip_data(d);
  534. }
  535. #endif
  536. /* Get the mpic structure from the irq number */
  537. static inline struct mpic * mpic_from_irq(unsigned int irq)
  538. {
  539. return irq_get_chip_data(irq);
  540. }
  541. /* Get the mpic structure from the irq data */
  542. static inline struct mpic * mpic_from_irq_data(struct irq_data *d)
  543. {
  544. return irq_data_get_irq_chip_data(d);
  545. }
  546. /* Send an EOI */
  547. static inline void mpic_eoi(struct mpic *mpic)
  548. {
  549. mpic_cpu_write(MPIC_INFO(CPU_EOI), 0);
  550. (void)mpic_cpu_read(MPIC_INFO(CPU_WHOAMI));
  551. }
  552. /*
  553. * Linux descriptor level callbacks
  554. */
  555. void mpic_unmask_irq(struct irq_data *d)
  556. {
  557. unsigned int loops = 100000;
  558. struct mpic *mpic = mpic_from_irq_data(d);
  559. unsigned int src = irqd_to_hwirq(d);
  560. DBG("%p: %s: enable_irq: %d (src %d)\n", mpic, mpic->name, d->irq, src);
  561. mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI),
  562. mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) &
  563. ~MPIC_VECPRI_MASK);
  564. /* make sure mask gets to controller before we return to user */
  565. do {
  566. if (!loops--) {
  567. printk(KERN_ERR "%s: timeout on hwirq %u\n",
  568. __func__, src);
  569. break;
  570. }
  571. } while(mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) & MPIC_VECPRI_MASK);
  572. }
  573. void mpic_mask_irq(struct irq_data *d)
  574. {
  575. unsigned int loops = 100000;
  576. struct mpic *mpic = mpic_from_irq_data(d);
  577. unsigned int src = irqd_to_hwirq(d);
  578. DBG("%s: disable_irq: %d (src %d)\n", mpic->name, d->irq, src);
  579. mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI),
  580. mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) |
  581. MPIC_VECPRI_MASK);
  582. /* make sure mask gets to controller before we return to user */
  583. do {
  584. if (!loops--) {
  585. printk(KERN_ERR "%s: timeout on hwirq %u\n",
  586. __func__, src);
  587. break;
  588. }
  589. } while(!(mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) & MPIC_VECPRI_MASK));
  590. }
  591. void mpic_end_irq(struct irq_data *d)
  592. {
  593. struct mpic *mpic = mpic_from_irq_data(d);
  594. #ifdef DEBUG_IRQ
  595. DBG("%s: end_irq: %d\n", mpic->name, d->irq);
  596. #endif
  597. /* We always EOI on end_irq() even for edge interrupts since that
  598. * should only lower the priority, the MPIC should have properly
  599. * latched another edge interrupt coming in anyway
  600. */
  601. mpic_eoi(mpic);
  602. }
  603. #ifdef CONFIG_MPIC_U3_HT_IRQS
  604. static void mpic_unmask_ht_irq(struct irq_data *d)
  605. {
  606. struct mpic *mpic = mpic_from_irq_data(d);
  607. unsigned int src = irqd_to_hwirq(d);
  608. mpic_unmask_irq(d);
  609. if (irqd_is_level_type(d))
  610. mpic_ht_end_irq(mpic, src);
  611. }
  612. static unsigned int mpic_startup_ht_irq(struct irq_data *d)
  613. {
  614. struct mpic *mpic = mpic_from_irq_data(d);
  615. unsigned int src = irqd_to_hwirq(d);
  616. mpic_unmask_irq(d);
  617. mpic_startup_ht_interrupt(mpic, src, irqd_is_level_type(d));
  618. return 0;
  619. }
  620. static void mpic_shutdown_ht_irq(struct irq_data *d)
  621. {
  622. struct mpic *mpic = mpic_from_irq_data(d);
  623. unsigned int src = irqd_to_hwirq(d);
  624. mpic_shutdown_ht_interrupt(mpic, src);
  625. mpic_mask_irq(d);
  626. }
  627. static void mpic_end_ht_irq(struct irq_data *d)
  628. {
  629. struct mpic *mpic = mpic_from_irq_data(d);
  630. unsigned int src = irqd_to_hwirq(d);
  631. #ifdef DEBUG_IRQ
  632. DBG("%s: end_irq: %d\n", mpic->name, d->irq);
  633. #endif
  634. /* We always EOI on end_irq() even for edge interrupts since that
  635. * should only lower the priority, the MPIC should have properly
  636. * latched another edge interrupt coming in anyway
  637. */
  638. if (irqd_is_level_type(d))
  639. mpic_ht_end_irq(mpic, src);
  640. mpic_eoi(mpic);
  641. }
  642. #endif /* !CONFIG_MPIC_U3_HT_IRQS */
  643. #ifdef CONFIG_SMP
  644. static void mpic_unmask_ipi(struct irq_data *d)
  645. {
  646. struct mpic *mpic = mpic_from_ipi(d);
  647. unsigned int src = virq_to_hw(d->irq) - mpic->ipi_vecs[0];
  648. DBG("%s: enable_ipi: %d (ipi %d)\n", mpic->name, d->irq, src);
  649. mpic_ipi_write(src, mpic_ipi_read(src) & ~MPIC_VECPRI_MASK);
  650. }
  651. static void mpic_mask_ipi(struct irq_data *d)
  652. {
  653. /* NEVER disable an IPI... that's just plain wrong! */
  654. }
  655. static void mpic_end_ipi(struct irq_data *d)
  656. {
  657. struct mpic *mpic = mpic_from_ipi(d);
  658. /*
  659. * IPIs are marked IRQ_PER_CPU. This has the side effect of
  660. * preventing the IRQ_PENDING/IRQ_INPROGRESS logic from
  661. * applying to them. We EOI them late to avoid re-entering.
  662. */
  663. mpic_eoi(mpic);
  664. }
  665. #endif /* CONFIG_SMP */
  666. static void mpic_unmask_tm(struct irq_data *d)
  667. {
  668. struct mpic *mpic = mpic_from_irq_data(d);
  669. unsigned int src = virq_to_hw(d->irq) - mpic->timer_vecs[0];
  670. DBG("%s: enable_tm: %d (tm %d)\n", mpic->name, d->irq, src);
  671. mpic_tm_write(src, mpic_tm_read(src) & ~MPIC_VECPRI_MASK);
  672. mpic_tm_read(src);
  673. }
  674. static void mpic_mask_tm(struct irq_data *d)
  675. {
  676. struct mpic *mpic = mpic_from_irq_data(d);
  677. unsigned int src = virq_to_hw(d->irq) - mpic->timer_vecs[0];
  678. mpic_tm_write(src, mpic_tm_read(src) | MPIC_VECPRI_MASK);
  679. mpic_tm_read(src);
  680. }
  681. int mpic_set_affinity(struct irq_data *d, const struct cpumask *cpumask,
  682. bool force)
  683. {
  684. struct mpic *mpic = mpic_from_irq_data(d);
  685. unsigned int src = irqd_to_hwirq(d);
  686. if (mpic->flags & MPIC_SINGLE_DEST_CPU) {
  687. int cpuid = irq_choose_cpu(cpumask);
  688. mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION), 1 << cpuid);
  689. } else {
  690. u32 mask = cpumask_bits(cpumask)[0];
  691. mask &= cpumask_bits(cpu_online_mask)[0];
  692. mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION),
  693. mpic_physmask(mask));
  694. }
  695. return 0;
  696. }
  697. static unsigned int mpic_type_to_vecpri(struct mpic *mpic, unsigned int type)
  698. {
  699. /* Now convert sense value */
  700. switch(type & IRQ_TYPE_SENSE_MASK) {
  701. case IRQ_TYPE_EDGE_RISING:
  702. return MPIC_INFO(VECPRI_SENSE_EDGE) |
  703. MPIC_INFO(VECPRI_POLARITY_POSITIVE);
  704. case IRQ_TYPE_EDGE_FALLING:
  705. case IRQ_TYPE_EDGE_BOTH:
  706. return MPIC_INFO(VECPRI_SENSE_EDGE) |
  707. MPIC_INFO(VECPRI_POLARITY_NEGATIVE);
  708. case IRQ_TYPE_LEVEL_HIGH:
  709. return MPIC_INFO(VECPRI_SENSE_LEVEL) |
  710. MPIC_INFO(VECPRI_POLARITY_POSITIVE);
  711. case IRQ_TYPE_LEVEL_LOW:
  712. default:
  713. return MPIC_INFO(VECPRI_SENSE_LEVEL) |
  714. MPIC_INFO(VECPRI_POLARITY_NEGATIVE);
  715. }
  716. }
  717. int mpic_set_irq_type(struct irq_data *d, unsigned int flow_type)
  718. {
  719. struct mpic *mpic = mpic_from_irq_data(d);
  720. unsigned int src = irqd_to_hwirq(d);
  721. unsigned int vecpri, vold, vnew;
  722. DBG("mpic: set_irq_type(mpic:@%p,virq:%d,src:0x%x,type:0x%x)\n",
  723. mpic, d->irq, src, flow_type);
  724. if (src >= mpic->irq_count)
  725. return -EINVAL;
  726. if (flow_type == IRQ_TYPE_NONE)
  727. if (mpic->senses && src < mpic->senses_count)
  728. flow_type = mpic->senses[src];
  729. if (flow_type == IRQ_TYPE_NONE)
  730. flow_type = IRQ_TYPE_LEVEL_LOW;
  731. irqd_set_trigger_type(d, flow_type);
  732. if (mpic_is_ht_interrupt(mpic, src))
  733. vecpri = MPIC_VECPRI_POLARITY_POSITIVE |
  734. MPIC_VECPRI_SENSE_EDGE;
  735. else
  736. vecpri = mpic_type_to_vecpri(mpic, flow_type);
  737. vold = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI));
  738. vnew = vold & ~(MPIC_INFO(VECPRI_POLARITY_MASK) |
  739. MPIC_INFO(VECPRI_SENSE_MASK));
  740. vnew |= vecpri;
  741. if (vold != vnew)
  742. mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), vnew);
  743. return IRQ_SET_MASK_OK_NOCOPY;;
  744. }
  745. void mpic_set_vector(unsigned int virq, unsigned int vector)
  746. {
  747. struct mpic *mpic = mpic_from_irq(virq);
  748. unsigned int src = virq_to_hw(virq);
  749. unsigned int vecpri;
  750. DBG("mpic: set_vector(mpic:@%p,virq:%d,src:%d,vector:0x%x)\n",
  751. mpic, virq, src, vector);
  752. if (src >= mpic->irq_count)
  753. return;
  754. vecpri = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI));
  755. vecpri = vecpri & ~MPIC_INFO(VECPRI_VECTOR_MASK);
  756. vecpri |= vector;
  757. mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), vecpri);
  758. }
  759. void mpic_set_destination(unsigned int virq, unsigned int cpuid)
  760. {
  761. struct mpic *mpic = mpic_from_irq(virq);
  762. unsigned int src = virq_to_hw(virq);
  763. DBG("mpic: set_destination(mpic:@%p,virq:%d,src:%d,cpuid:0x%x)\n",
  764. mpic, virq, src, cpuid);
  765. if (src >= mpic->irq_count)
  766. return;
  767. mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION), 1 << cpuid);
  768. }
  769. static struct irq_chip mpic_irq_chip = {
  770. .irq_mask = mpic_mask_irq,
  771. .irq_unmask = mpic_unmask_irq,
  772. .irq_eoi = mpic_end_irq,
  773. .irq_set_type = mpic_set_irq_type,
  774. };
  775. #ifdef CONFIG_SMP
  776. static struct irq_chip mpic_ipi_chip = {
  777. .irq_mask = mpic_mask_ipi,
  778. .irq_unmask = mpic_unmask_ipi,
  779. .irq_eoi = mpic_end_ipi,
  780. };
  781. #endif /* CONFIG_SMP */
  782. static struct irq_chip mpic_tm_chip = {
  783. .irq_mask = mpic_mask_tm,
  784. .irq_unmask = mpic_unmask_tm,
  785. .irq_eoi = mpic_end_irq,
  786. };
  787. #ifdef CONFIG_MPIC_U3_HT_IRQS
  788. static struct irq_chip mpic_irq_ht_chip = {
  789. .irq_startup = mpic_startup_ht_irq,
  790. .irq_shutdown = mpic_shutdown_ht_irq,
  791. .irq_mask = mpic_mask_irq,
  792. .irq_unmask = mpic_unmask_ht_irq,
  793. .irq_eoi = mpic_end_ht_irq,
  794. .irq_set_type = mpic_set_irq_type,
  795. };
  796. #endif /* CONFIG_MPIC_U3_HT_IRQS */
  797. static int mpic_host_match(struct irq_host *h, struct device_node *node)
  798. {
  799. /* Exact match, unless mpic node is NULL */
  800. return h->of_node == NULL || h->of_node == node;
  801. }
  802. static int mpic_host_map(struct irq_host *h, unsigned int virq,
  803. irq_hw_number_t hw)
  804. {
  805. struct mpic *mpic = h->host_data;
  806. struct irq_chip *chip;
  807. DBG("mpic: map virq %d, hwirq 0x%lx\n", virq, hw);
  808. if (hw == mpic->spurious_vec)
  809. return -EINVAL;
  810. if (mpic->protected && test_bit(hw, mpic->protected))
  811. return -EINVAL;
  812. #ifdef CONFIG_SMP
  813. else if (hw >= mpic->ipi_vecs[0]) {
  814. WARN_ON(!(mpic->flags & MPIC_PRIMARY));
  815. DBG("mpic: mapping as IPI\n");
  816. irq_set_chip_data(virq, mpic);
  817. irq_set_chip_and_handler(virq, &mpic->hc_ipi,
  818. handle_percpu_irq);
  819. return 0;
  820. }
  821. #endif /* CONFIG_SMP */
  822. if (hw >= mpic->timer_vecs[0] && hw <= mpic->timer_vecs[7]) {
  823. WARN_ON(!(mpic->flags & MPIC_PRIMARY));
  824. DBG("mpic: mapping as timer\n");
  825. irq_set_chip_data(virq, mpic);
  826. irq_set_chip_and_handler(virq, &mpic->hc_tm,
  827. handle_fasteoi_irq);
  828. return 0;
  829. }
  830. if (hw >= mpic->irq_count)
  831. return -EINVAL;
  832. mpic_msi_reserve_hwirq(mpic, hw);
  833. /* Default chip */
  834. chip = &mpic->hc_irq;
  835. #ifdef CONFIG_MPIC_U3_HT_IRQS
  836. /* Check for HT interrupts, override vecpri */
  837. if (mpic_is_ht_interrupt(mpic, hw))
  838. chip = &mpic->hc_ht_irq;
  839. #endif /* CONFIG_MPIC_U3_HT_IRQS */
  840. DBG("mpic: mapping to irq chip @%p\n", chip);
  841. irq_set_chip_data(virq, mpic);
  842. irq_set_chip_and_handler(virq, chip, handle_fasteoi_irq);
  843. /* Set default irq type */
  844. irq_set_irq_type(virq, IRQ_TYPE_NONE);
  845. /* If the MPIC was reset, then all vectors have already been
  846. * initialized. Otherwise, a per source lazy initialization
  847. * is done here.
  848. */
  849. if (!mpic_is_ipi(mpic, hw) && (mpic->flags & MPIC_NO_RESET)) {
  850. mpic_set_vector(virq, hw);
  851. mpic_set_destination(virq, mpic_processor_id(mpic));
  852. mpic_irq_set_priority(virq, 8);
  853. }
  854. return 0;
  855. }
  856. static int mpic_host_xlate(struct irq_host *h, struct device_node *ct,
  857. const u32 *intspec, unsigned int intsize,
  858. irq_hw_number_t *out_hwirq, unsigned int *out_flags)
  859. {
  860. struct mpic *mpic = h->host_data;
  861. static unsigned char map_mpic_senses[4] = {
  862. IRQ_TYPE_EDGE_RISING,
  863. IRQ_TYPE_LEVEL_LOW,
  864. IRQ_TYPE_LEVEL_HIGH,
  865. IRQ_TYPE_EDGE_FALLING,
  866. };
  867. *out_hwirq = intspec[0];
  868. if (intsize >= 4 && (mpic->flags & MPIC_FSL)) {
  869. /*
  870. * Freescale MPIC with extended intspec:
  871. * First two cells are as usual. Third specifies
  872. * an "interrupt type". Fourth is type-specific data.
  873. *
  874. * See Documentation/devicetree/bindings/powerpc/fsl/mpic.txt
  875. */
  876. switch (intspec[2]) {
  877. case 0:
  878. case 1: /* no EISR/EIMR support for now, treat as shared IRQ */
  879. break;
  880. case 2:
  881. if (intspec[0] >= ARRAY_SIZE(mpic->ipi_vecs))
  882. return -EINVAL;
  883. *out_hwirq = mpic->ipi_vecs[intspec[0]];
  884. break;
  885. case 3:
  886. if (intspec[0] >= ARRAY_SIZE(mpic->timer_vecs))
  887. return -EINVAL;
  888. *out_hwirq = mpic->timer_vecs[intspec[0]];
  889. break;
  890. default:
  891. pr_debug("%s: unknown irq type %u\n",
  892. __func__, intspec[2]);
  893. return -EINVAL;
  894. }
  895. *out_flags = map_mpic_senses[intspec[1] & 3];
  896. } else if (intsize > 1) {
  897. u32 mask = 0x3;
  898. /* Apple invented a new race of encoding on machines with
  899. * an HT APIC. They encode, among others, the index within
  900. * the HT APIC. We don't care about it here since thankfully,
  901. * it appears that they have the APIC already properly
  902. * configured, and thus our current fixup code that reads the
  903. * APIC config works fine. However, we still need to mask out
  904. * bits in the specifier to make sure we only get bit 0 which
  905. * is the level/edge bit (the only sense bit exposed by Apple),
  906. * as their bit 1 means something else.
  907. */
  908. if (machine_is(powermac))
  909. mask = 0x1;
  910. *out_flags = map_mpic_senses[intspec[1] & mask];
  911. } else
  912. *out_flags = IRQ_TYPE_NONE;
  913. DBG("mpic: xlate (%d cells: 0x%08x 0x%08x) to line 0x%lx sense 0x%x\n",
  914. intsize, intspec[0], intspec[1], *out_hwirq, *out_flags);
  915. return 0;
  916. }
  917. static struct irq_host_ops mpic_host_ops = {
  918. .match = mpic_host_match,
  919. .map = mpic_host_map,
  920. .xlate = mpic_host_xlate,
  921. };
  922. static int mpic_reset_prohibited(struct device_node *node)
  923. {
  924. return node && of_get_property(node, "pic-no-reset", NULL);
  925. }
  926. /*
  927. * Exported functions
  928. */
  929. struct mpic * __init mpic_alloc(struct device_node *node,
  930. phys_addr_t phys_addr,
  931. unsigned int flags,
  932. unsigned int isu_size,
  933. unsigned int irq_count,
  934. const char *name)
  935. {
  936. struct mpic *mpic;
  937. u32 greg_feature;
  938. const char *vers;
  939. int i;
  940. int intvec_top;
  941. u64 paddr = phys_addr;
  942. mpic = kzalloc(sizeof(struct mpic), GFP_KERNEL);
  943. if (mpic == NULL)
  944. return NULL;
  945. mpic->name = name;
  946. mpic->hc_irq = mpic_irq_chip;
  947. mpic->hc_irq.name = name;
  948. if (flags & MPIC_PRIMARY)
  949. mpic->hc_irq.irq_set_affinity = mpic_set_affinity;
  950. #ifdef CONFIG_MPIC_U3_HT_IRQS
  951. mpic->hc_ht_irq = mpic_irq_ht_chip;
  952. mpic->hc_ht_irq.name = name;
  953. if (flags & MPIC_PRIMARY)
  954. mpic->hc_ht_irq.irq_set_affinity = mpic_set_affinity;
  955. #endif /* CONFIG_MPIC_U3_HT_IRQS */
  956. #ifdef CONFIG_SMP
  957. mpic->hc_ipi = mpic_ipi_chip;
  958. mpic->hc_ipi.name = name;
  959. #endif /* CONFIG_SMP */
  960. mpic->hc_tm = mpic_tm_chip;
  961. mpic->hc_tm.name = name;
  962. mpic->flags = flags;
  963. mpic->isu_size = isu_size;
  964. mpic->irq_count = irq_count;
  965. mpic->num_sources = 0; /* so far */
  966. if (flags & MPIC_LARGE_VECTORS)
  967. intvec_top = 2047;
  968. else
  969. intvec_top = 255;
  970. mpic->timer_vecs[0] = intvec_top - 12;
  971. mpic->timer_vecs[1] = intvec_top - 11;
  972. mpic->timer_vecs[2] = intvec_top - 10;
  973. mpic->timer_vecs[3] = intvec_top - 9;
  974. mpic->timer_vecs[4] = intvec_top - 8;
  975. mpic->timer_vecs[5] = intvec_top - 7;
  976. mpic->timer_vecs[6] = intvec_top - 6;
  977. mpic->timer_vecs[7] = intvec_top - 5;
  978. mpic->ipi_vecs[0] = intvec_top - 4;
  979. mpic->ipi_vecs[1] = intvec_top - 3;
  980. mpic->ipi_vecs[2] = intvec_top - 2;
  981. mpic->ipi_vecs[3] = intvec_top - 1;
  982. mpic->spurious_vec = intvec_top;
  983. /* Check for "big-endian" in device-tree */
  984. if (node && of_get_property(node, "big-endian", NULL) != NULL)
  985. mpic->flags |= MPIC_BIG_ENDIAN;
  986. if (node && of_device_is_compatible(node, "fsl,mpic"))
  987. mpic->flags |= MPIC_FSL;
  988. /* Look for protected sources */
  989. if (node) {
  990. int psize;
  991. unsigned int bits, mapsize;
  992. const u32 *psrc =
  993. of_get_property(node, "protected-sources", &psize);
  994. if (psrc) {
  995. psize /= 4;
  996. bits = intvec_top + 1;
  997. mapsize = BITS_TO_LONGS(bits) * sizeof(unsigned long);
  998. mpic->protected = kzalloc(mapsize, GFP_KERNEL);
  999. BUG_ON(mpic->protected == NULL);
  1000. for (i = 0; i < psize; i++) {
  1001. if (psrc[i] > intvec_top)
  1002. continue;
  1003. __set_bit(psrc[i], mpic->protected);
  1004. }
  1005. }
  1006. }
  1007. #ifdef CONFIG_MPIC_WEIRD
  1008. mpic->hw_set = mpic_infos[MPIC_GET_REGSET(flags)];
  1009. #endif
  1010. /* default register type */
  1011. mpic->reg_type = (flags & MPIC_BIG_ENDIAN) ?
  1012. mpic_access_mmio_be : mpic_access_mmio_le;
  1013. /* If no physical address is passed in, a device-node is mandatory */
  1014. BUG_ON(paddr == 0 && node == NULL);
  1015. /* If no physical address passed in, check if it's dcr based */
  1016. if (paddr == 0 && of_get_property(node, "dcr-reg", NULL) != NULL) {
  1017. #ifdef CONFIG_PPC_DCR
  1018. mpic->flags |= MPIC_USES_DCR;
  1019. mpic->reg_type = mpic_access_dcr;
  1020. #else
  1021. BUG();
  1022. #endif /* CONFIG_PPC_DCR */
  1023. }
  1024. /* If the MPIC is not DCR based, and no physical address was passed
  1025. * in, try to obtain one
  1026. */
  1027. if (paddr == 0 && !(mpic->flags & MPIC_USES_DCR)) {
  1028. const u32 *reg = of_get_property(node, "reg", NULL);
  1029. BUG_ON(reg == NULL);
  1030. paddr = of_translate_address(node, reg);
  1031. BUG_ON(paddr == OF_BAD_ADDR);
  1032. }
  1033. /* Map the global registers */
  1034. mpic_map(mpic, node, paddr, &mpic->gregs, MPIC_INFO(GREG_BASE), 0x1000);
  1035. mpic_map(mpic, node, paddr, &mpic->tmregs, MPIC_INFO(TIMER_BASE), 0x1000);
  1036. /* Reset */
  1037. /* When using a device-node, reset requests are only honored if the MPIC
  1038. * is allowed to reset.
  1039. */
  1040. if (mpic_reset_prohibited(node))
  1041. mpic->flags |= MPIC_NO_RESET;
  1042. if ((flags & MPIC_WANTS_RESET) && !(mpic->flags & MPIC_NO_RESET)) {
  1043. printk(KERN_DEBUG "mpic: Resetting\n");
  1044. mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
  1045. mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  1046. | MPIC_GREG_GCONF_RESET);
  1047. while( mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  1048. & MPIC_GREG_GCONF_RESET)
  1049. mb();
  1050. }
  1051. /* CoreInt */
  1052. if (flags & MPIC_ENABLE_COREINT)
  1053. mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
  1054. mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  1055. | MPIC_GREG_GCONF_COREINT);
  1056. if (flags & MPIC_ENABLE_MCK)
  1057. mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
  1058. mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  1059. | MPIC_GREG_GCONF_MCK);
  1060. /*
  1061. * Read feature register. For non-ISU MPICs, num sources as well. On
  1062. * ISU MPICs, sources are counted as ISUs are added
  1063. */
  1064. greg_feature = mpic_read(mpic->gregs, MPIC_INFO(GREG_FEATURE_0));
  1065. if (isu_size == 0) {
  1066. if (flags & MPIC_BROKEN_FRR_NIRQS)
  1067. mpic->num_sources = mpic->irq_count;
  1068. else
  1069. mpic->num_sources =
  1070. ((greg_feature & MPIC_GREG_FEATURE_LAST_SRC_MASK)
  1071. >> MPIC_GREG_FEATURE_LAST_SRC_SHIFT) + 1;
  1072. }
  1073. /*
  1074. * The MPIC driver will crash if there are more cores than we
  1075. * can initialize, so we may as well catch that problem here.
  1076. */
  1077. BUG_ON(num_possible_cpus() > MPIC_MAX_CPUS);
  1078. /* Map the per-CPU registers */
  1079. for_each_possible_cpu(i) {
  1080. unsigned int cpu = get_hard_smp_processor_id(i);
  1081. mpic_map(mpic, node, paddr, &mpic->cpuregs[cpu],
  1082. MPIC_INFO(CPU_BASE) + cpu * MPIC_INFO(CPU_STRIDE),
  1083. 0x1000);
  1084. }
  1085. /* Initialize main ISU if none provided */
  1086. if (mpic->isu_size == 0) {
  1087. mpic->isu_size = mpic->num_sources;
  1088. mpic_map(mpic, node, paddr, &mpic->isus[0],
  1089. MPIC_INFO(IRQ_BASE), MPIC_INFO(IRQ_STRIDE) * mpic->isu_size);
  1090. }
  1091. mpic->isu_shift = 1 + __ilog2(mpic->isu_size - 1);
  1092. mpic->isu_mask = (1 << mpic->isu_shift) - 1;
  1093. mpic->irqhost = irq_alloc_host(node, IRQ_HOST_MAP_LINEAR,
  1094. isu_size ? isu_size : mpic->num_sources,
  1095. &mpic_host_ops,
  1096. flags & MPIC_LARGE_VECTORS ? 2048 : 256);
  1097. if (mpic->irqhost == NULL)
  1098. return NULL;
  1099. mpic->irqhost->host_data = mpic;
  1100. /* Display version */
  1101. switch (greg_feature & MPIC_GREG_FEATURE_VERSION_MASK) {
  1102. case 1:
  1103. vers = "1.0";
  1104. break;
  1105. case 2:
  1106. vers = "1.2";
  1107. break;
  1108. case 3:
  1109. vers = "1.3";
  1110. break;
  1111. default:
  1112. vers = "<unknown>";
  1113. break;
  1114. }
  1115. printk(KERN_INFO "mpic: Setting up MPIC \"%s\" version %s at %llx,"
  1116. " max %d CPUs\n",
  1117. name, vers, (unsigned long long)paddr, num_possible_cpus());
  1118. printk(KERN_INFO "mpic: ISU size: %d, shift: %d, mask: %x\n",
  1119. mpic->isu_size, mpic->isu_shift, mpic->isu_mask);
  1120. mpic->next = mpics;
  1121. mpics = mpic;
  1122. if (flags & MPIC_PRIMARY) {
  1123. mpic_primary = mpic;
  1124. irq_set_default_host(mpic->irqhost);
  1125. }
  1126. return mpic;
  1127. }
  1128. void __init mpic_assign_isu(struct mpic *mpic, unsigned int isu_num,
  1129. phys_addr_t paddr)
  1130. {
  1131. unsigned int isu_first = isu_num * mpic->isu_size;
  1132. BUG_ON(isu_num >= MPIC_MAX_ISU);
  1133. mpic_map(mpic, mpic->irqhost->of_node,
  1134. paddr, &mpic->isus[isu_num], 0,
  1135. MPIC_INFO(IRQ_STRIDE) * mpic->isu_size);
  1136. if ((isu_first + mpic->isu_size) > mpic->num_sources)
  1137. mpic->num_sources = isu_first + mpic->isu_size;
  1138. }
  1139. void __init mpic_set_default_senses(struct mpic *mpic, u8 *senses, int count)
  1140. {
  1141. mpic->senses = senses;
  1142. mpic->senses_count = count;
  1143. }
  1144. void __init mpic_init(struct mpic *mpic)
  1145. {
  1146. int i;
  1147. int cpu;
  1148. BUG_ON(mpic->num_sources == 0);
  1149. printk(KERN_INFO "mpic: Initializing for %d sources\n", mpic->num_sources);
  1150. /* Set current processor priority to max */
  1151. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0xf);
  1152. /* Initialize timers to our reserved vectors and mask them for now */
  1153. for (i = 0; i < 4; i++) {
  1154. mpic_write(mpic->tmregs,
  1155. i * MPIC_INFO(TIMER_STRIDE) +
  1156. MPIC_INFO(TIMER_DESTINATION),
  1157. 1 << hard_smp_processor_id());
  1158. mpic_write(mpic->tmregs,
  1159. i * MPIC_INFO(TIMER_STRIDE) +
  1160. MPIC_INFO(TIMER_VECTOR_PRI),
  1161. MPIC_VECPRI_MASK |
  1162. (9 << MPIC_VECPRI_PRIORITY_SHIFT) |
  1163. (mpic->timer_vecs[0] + i));
  1164. }
  1165. /* Initialize IPIs to our reserved vectors and mark them disabled for now */
  1166. mpic_test_broken_ipi(mpic);
  1167. for (i = 0; i < 4; i++) {
  1168. mpic_ipi_write(i,
  1169. MPIC_VECPRI_MASK |
  1170. (10 << MPIC_VECPRI_PRIORITY_SHIFT) |
  1171. (mpic->ipi_vecs[0] + i));
  1172. }
  1173. /* Initialize interrupt sources */
  1174. if (mpic->irq_count == 0)
  1175. mpic->irq_count = mpic->num_sources;
  1176. /* Do the HT PIC fixups on U3 broken mpic */
  1177. DBG("MPIC flags: %x\n", mpic->flags);
  1178. if ((mpic->flags & MPIC_U3_HT_IRQS) && (mpic->flags & MPIC_PRIMARY)) {
  1179. mpic_scan_ht_pics(mpic);
  1180. mpic_u3msi_init(mpic);
  1181. }
  1182. mpic_pasemi_msi_init(mpic);
  1183. cpu = mpic_processor_id(mpic);
  1184. if (!(mpic->flags & MPIC_NO_RESET)) {
  1185. for (i = 0; i < mpic->num_sources; i++) {
  1186. /* start with vector = source number, and masked */
  1187. u32 vecpri = MPIC_VECPRI_MASK | i |
  1188. (8 << MPIC_VECPRI_PRIORITY_SHIFT);
  1189. /* check if protected */
  1190. if (mpic->protected && test_bit(i, mpic->protected))
  1191. continue;
  1192. /* init hw */
  1193. mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI), vecpri);
  1194. mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION), 1 << cpu);
  1195. }
  1196. }
  1197. /* Init spurious vector */
  1198. mpic_write(mpic->gregs, MPIC_INFO(GREG_SPURIOUS), mpic->spurious_vec);
  1199. /* Disable 8259 passthrough, if supported */
  1200. if (!(mpic->flags & MPIC_NO_PTHROU_DIS))
  1201. mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
  1202. mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  1203. | MPIC_GREG_GCONF_8259_PTHROU_DIS);
  1204. if (mpic->flags & MPIC_NO_BIAS)
  1205. mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
  1206. mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  1207. | MPIC_GREG_GCONF_NO_BIAS);
  1208. /* Set current processor priority to 0 */
  1209. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0);
  1210. #ifdef CONFIG_PM
  1211. /* allocate memory to save mpic state */
  1212. mpic->save_data = kmalloc(mpic->num_sources * sizeof(*mpic->save_data),
  1213. GFP_KERNEL);
  1214. BUG_ON(mpic->save_data == NULL);
  1215. #endif
  1216. }
  1217. void __init mpic_set_clk_ratio(struct mpic *mpic, u32 clock_ratio)
  1218. {
  1219. u32 v;
  1220. v = mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1);
  1221. v &= ~MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO_MASK;
  1222. v |= MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO(clock_ratio);
  1223. mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v);
  1224. }
  1225. void __init mpic_set_serial_int(struct mpic *mpic, int enable)
  1226. {
  1227. unsigned long flags;
  1228. u32 v;
  1229. raw_spin_lock_irqsave(&mpic_lock, flags);
  1230. v = mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1);
  1231. if (enable)
  1232. v |= MPIC_GREG_GLOBAL_CONF_1_SIE;
  1233. else
  1234. v &= ~MPIC_GREG_GLOBAL_CONF_1_SIE;
  1235. mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v);
  1236. raw_spin_unlock_irqrestore(&mpic_lock, flags);
  1237. }
  1238. void mpic_irq_set_priority(unsigned int irq, unsigned int pri)
  1239. {
  1240. struct mpic *mpic = mpic_find(irq);
  1241. unsigned int src = virq_to_hw(irq);
  1242. unsigned long flags;
  1243. u32 reg;
  1244. if (!mpic)
  1245. return;
  1246. raw_spin_lock_irqsave(&mpic_lock, flags);
  1247. if (mpic_is_ipi(mpic, irq)) {
  1248. reg = mpic_ipi_read(src - mpic->ipi_vecs[0]) &
  1249. ~MPIC_VECPRI_PRIORITY_MASK;
  1250. mpic_ipi_write(src - mpic->ipi_vecs[0],
  1251. reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
  1252. } else if (mpic_is_tm(mpic, irq)) {
  1253. reg = mpic_tm_read(src - mpic->timer_vecs[0]) &
  1254. ~MPIC_VECPRI_PRIORITY_MASK;
  1255. mpic_tm_write(src - mpic->timer_vecs[0],
  1256. reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
  1257. } else {
  1258. reg = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI))
  1259. & ~MPIC_VECPRI_PRIORITY_MASK;
  1260. mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI),
  1261. reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
  1262. }
  1263. raw_spin_unlock_irqrestore(&mpic_lock, flags);
  1264. }
  1265. void mpic_setup_this_cpu(void)
  1266. {
  1267. #ifdef CONFIG_SMP
  1268. struct mpic *mpic = mpic_primary;
  1269. unsigned long flags;
  1270. u32 msk = 1 << hard_smp_processor_id();
  1271. unsigned int i;
  1272. BUG_ON(mpic == NULL);
  1273. DBG("%s: setup_this_cpu(%d)\n", mpic->name, hard_smp_processor_id());
  1274. raw_spin_lock_irqsave(&mpic_lock, flags);
  1275. /* let the mpic know we want intrs. default affinity is 0xffffffff
  1276. * until changed via /proc. That's how it's done on x86. If we want
  1277. * it differently, then we should make sure we also change the default
  1278. * values of irq_desc[].affinity in irq.c.
  1279. */
  1280. if (distribute_irqs) {
  1281. for (i = 0; i < mpic->num_sources ; i++)
  1282. mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION),
  1283. mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION)) | msk);
  1284. }
  1285. /* Set current processor priority to 0 */
  1286. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0);
  1287. raw_spin_unlock_irqrestore(&mpic_lock, flags);
  1288. #endif /* CONFIG_SMP */
  1289. }
  1290. int mpic_cpu_get_priority(void)
  1291. {
  1292. struct mpic *mpic = mpic_primary;
  1293. return mpic_cpu_read(MPIC_INFO(CPU_CURRENT_TASK_PRI));
  1294. }
  1295. void mpic_cpu_set_priority(int prio)
  1296. {
  1297. struct mpic *mpic = mpic_primary;
  1298. prio &= MPIC_CPU_TASKPRI_MASK;
  1299. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), prio);
  1300. }
  1301. void mpic_teardown_this_cpu(int secondary)
  1302. {
  1303. struct mpic *mpic = mpic_primary;
  1304. unsigned long flags;
  1305. u32 msk = 1 << hard_smp_processor_id();
  1306. unsigned int i;
  1307. BUG_ON(mpic == NULL);
  1308. DBG("%s: teardown_this_cpu(%d)\n", mpic->name, hard_smp_processor_id());
  1309. raw_spin_lock_irqsave(&mpic_lock, flags);
  1310. /* let the mpic know we don't want intrs. */
  1311. for (i = 0; i < mpic->num_sources ; i++)
  1312. mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION),
  1313. mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION)) & ~msk);
  1314. /* Set current processor priority to max */
  1315. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0xf);
  1316. /* We need to EOI the IPI since not all platforms reset the MPIC
  1317. * on boot and new interrupts wouldn't get delivered otherwise.
  1318. */
  1319. mpic_eoi(mpic);
  1320. raw_spin_unlock_irqrestore(&mpic_lock, flags);
  1321. }
  1322. static unsigned int _mpic_get_one_irq(struct mpic *mpic, int reg)
  1323. {
  1324. u32 src;
  1325. src = mpic_cpu_read(reg) & MPIC_INFO(VECPRI_VECTOR_MASK);
  1326. #ifdef DEBUG_LOW
  1327. DBG("%s: get_one_irq(reg 0x%x): %d\n", mpic->name, reg, src);
  1328. #endif
  1329. if (unlikely(src == mpic->spurious_vec)) {
  1330. if (mpic->flags & MPIC_SPV_EOI)
  1331. mpic_eoi(mpic);
  1332. return NO_IRQ;
  1333. }
  1334. if (unlikely(mpic->protected && test_bit(src, mpic->protected))) {
  1335. printk_ratelimited(KERN_WARNING "%s: Got protected source %d !\n",
  1336. mpic->name, (int)src);
  1337. mpic_eoi(mpic);
  1338. return NO_IRQ;
  1339. }
  1340. return irq_linear_revmap(mpic->irqhost, src);
  1341. }
  1342. unsigned int mpic_get_one_irq(struct mpic *mpic)
  1343. {
  1344. return _mpic_get_one_irq(mpic, MPIC_INFO(CPU_INTACK));
  1345. }
  1346. unsigned int mpic_get_irq(void)
  1347. {
  1348. struct mpic *mpic = mpic_primary;
  1349. BUG_ON(mpic == NULL);
  1350. return mpic_get_one_irq(mpic);
  1351. }
  1352. unsigned int mpic_get_coreint_irq(void)
  1353. {
  1354. #ifdef CONFIG_BOOKE
  1355. struct mpic *mpic = mpic_primary;
  1356. u32 src;
  1357. BUG_ON(mpic == NULL);
  1358. src = mfspr(SPRN_EPR);
  1359. if (unlikely(src == mpic->spurious_vec)) {
  1360. if (mpic->flags & MPIC_SPV_EOI)
  1361. mpic_eoi(mpic);
  1362. return NO_IRQ;
  1363. }
  1364. if (unlikely(mpic->protected && test_bit(src, mpic->protected))) {
  1365. printk_ratelimited(KERN_WARNING "%s: Got protected source %d !\n",
  1366. mpic->name, (int)src);
  1367. return NO_IRQ;
  1368. }
  1369. return irq_linear_revmap(mpic->irqhost, src);
  1370. #else
  1371. return NO_IRQ;
  1372. #endif
  1373. }
  1374. unsigned int mpic_get_mcirq(void)
  1375. {
  1376. struct mpic *mpic = mpic_primary;
  1377. BUG_ON(mpic == NULL);
  1378. return _mpic_get_one_irq(mpic, MPIC_INFO(CPU_MCACK));
  1379. }
  1380. #ifdef CONFIG_SMP
  1381. void mpic_request_ipis(void)
  1382. {
  1383. struct mpic *mpic = mpic_primary;
  1384. int i;
  1385. BUG_ON(mpic == NULL);
  1386. printk(KERN_INFO "mpic: requesting IPIs...\n");
  1387. for (i = 0; i < 4; i++) {
  1388. unsigned int vipi = irq_create_mapping(mpic->irqhost,
  1389. mpic->ipi_vecs[0] + i);
  1390. if (vipi == NO_IRQ) {
  1391. printk(KERN_ERR "Failed to map %s\n", smp_ipi_name[i]);
  1392. continue;
  1393. }
  1394. smp_request_message_ipi(vipi, i);
  1395. }
  1396. }
  1397. void smp_mpic_message_pass(int cpu, int msg)
  1398. {
  1399. struct mpic *mpic = mpic_primary;
  1400. u32 physmask;
  1401. BUG_ON(mpic == NULL);
  1402. /* make sure we're sending something that translates to an IPI */
  1403. if ((unsigned int)msg > 3) {
  1404. printk("SMP %d: smp_message_pass: unknown msg %d\n",
  1405. smp_processor_id(), msg);
  1406. return;
  1407. }
  1408. #ifdef DEBUG_IPI
  1409. DBG("%s: send_ipi(ipi_no: %d)\n", mpic->name, msg);
  1410. #endif
  1411. physmask = 1 << get_hard_smp_processor_id(cpu);
  1412. mpic_cpu_write(MPIC_INFO(CPU_IPI_DISPATCH_0) +
  1413. msg * MPIC_INFO(CPU_IPI_DISPATCH_STRIDE), physmask);
  1414. }
  1415. int __init smp_mpic_probe(void)
  1416. {
  1417. int nr_cpus;
  1418. DBG("smp_mpic_probe()...\n");
  1419. nr_cpus = cpumask_weight(cpu_possible_mask);
  1420. DBG("nr_cpus: %d\n", nr_cpus);
  1421. if (nr_cpus > 1)
  1422. mpic_request_ipis();
  1423. return nr_cpus;
  1424. }
  1425. void __devinit smp_mpic_setup_cpu(int cpu)
  1426. {
  1427. mpic_setup_this_cpu();
  1428. }
  1429. void mpic_reset_core(int cpu)
  1430. {
  1431. struct mpic *mpic = mpic_primary;
  1432. u32 pir;
  1433. int cpuid = get_hard_smp_processor_id(cpu);
  1434. int i;
  1435. /* Set target bit for core reset */
  1436. pir = mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
  1437. pir |= (1 << cpuid);
  1438. mpic_write(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT), pir);
  1439. mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
  1440. /* Restore target bit after reset complete */
  1441. pir &= ~(1 << cpuid);
  1442. mpic_write(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT), pir);
  1443. mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
  1444. /* Perform 15 EOI on each reset core to clear pending interrupts.
  1445. * This is required for FSL CoreNet based devices */
  1446. if (mpic->flags & MPIC_FSL) {
  1447. for (i = 0; i < 15; i++) {
  1448. _mpic_write(mpic->reg_type, &mpic->cpuregs[cpuid],
  1449. MPIC_CPU_EOI, 0);
  1450. }
  1451. }
  1452. }
  1453. #endif /* CONFIG_SMP */
  1454. #ifdef CONFIG_PM
  1455. static void mpic_suspend_one(struct mpic *mpic)
  1456. {
  1457. int i;
  1458. for (i = 0; i < mpic->num_sources; i++) {
  1459. mpic->save_data[i].vecprio =
  1460. mpic_irq_read(i, MPIC_INFO(IRQ_VECTOR_PRI));
  1461. mpic->save_data[i].dest =
  1462. mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION));
  1463. }
  1464. }
  1465. static int mpic_suspend(void)
  1466. {
  1467. struct mpic *mpic = mpics;
  1468. while (mpic) {
  1469. mpic_suspend_one(mpic);
  1470. mpic = mpic->next;
  1471. }
  1472. return 0;
  1473. }
  1474. static void mpic_resume_one(struct mpic *mpic)
  1475. {
  1476. int i;
  1477. for (i = 0; i < mpic->num_sources; i++) {
  1478. mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI),
  1479. mpic->save_data[i].vecprio);
  1480. mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION),
  1481. mpic->save_data[i].dest);
  1482. #ifdef CONFIG_MPIC_U3_HT_IRQS
  1483. if (mpic->fixups) {
  1484. struct mpic_irq_fixup *fixup = &mpic->fixups[i];
  1485. if (fixup->base) {
  1486. /* we use the lowest bit in an inverted meaning */
  1487. if ((mpic->save_data[i].fixup_data & 1) == 0)
  1488. continue;
  1489. /* Enable and configure */
  1490. writeb(0x10 + 2 * fixup->index, fixup->base + 2);
  1491. writel(mpic->save_data[i].fixup_data & ~1,
  1492. fixup->base + 4);
  1493. }
  1494. }
  1495. #endif
  1496. } /* end for loop */
  1497. }
  1498. static void mpic_resume(void)
  1499. {
  1500. struct mpic *mpic = mpics;
  1501. while (mpic) {
  1502. mpic_resume_one(mpic);
  1503. mpic = mpic->next;
  1504. }
  1505. }
  1506. static struct syscore_ops mpic_syscore_ops = {
  1507. .resume = mpic_resume,
  1508. .suspend = mpic_suspend,
  1509. };
  1510. static int mpic_init_sys(void)
  1511. {
  1512. register_syscore_ops(&mpic_syscore_ops);
  1513. return 0;
  1514. }
  1515. device_initcall(mpic_init_sys);
  1516. #endif