mpic.c 47 KB

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