mpic.c 45 KB

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