mpic.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778
  1. /*
  2. * arch/powerpc/kernel/mpic.c
  3. *
  4. * Driver for interrupt controllers following the OpenPIC standard, the
  5. * common implementation beeing IBM's MPIC. This driver also can deal
  6. * with various broken implementations of this HW.
  7. *
  8. * Copyright (C) 2004 Benjamin Herrenschmidt, IBM Corp.
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file COPYING in the main directory of this archive
  12. * for more details.
  13. */
  14. #undef DEBUG
  15. #undef DEBUG_IPI
  16. #undef DEBUG_IRQ
  17. #undef DEBUG_LOW
  18. #include <linux/types.h>
  19. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <linux/irq.h>
  22. #include <linux/smp.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/bootmem.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/pci.h>
  27. #include <linux/slab.h>
  28. #include <asm/ptrace.h>
  29. #include <asm/signal.h>
  30. #include <asm/io.h>
  31. #include <asm/pgtable.h>
  32. #include <asm/irq.h>
  33. #include <asm/machdep.h>
  34. #include <asm/mpic.h>
  35. #include <asm/smp.h>
  36. #include "mpic.h"
  37. #ifdef DEBUG
  38. #define DBG(fmt...) printk(fmt)
  39. #else
  40. #define DBG(fmt...)
  41. #endif
  42. static struct mpic *mpics;
  43. static struct mpic *mpic_primary;
  44. static DEFINE_RAW_SPINLOCK(mpic_lock);
  45. #ifdef CONFIG_PPC32 /* XXX for now */
  46. #ifdef CONFIG_IRQ_ALL_CPUS
  47. #define distribute_irqs (1)
  48. #else
  49. #define distribute_irqs (0)
  50. #endif
  51. #endif
  52. #ifdef CONFIG_MPIC_WEIRD
  53. static u32 mpic_infos[][MPIC_IDX_END] = {
  54. [0] = { /* Original OpenPIC compatible MPIC */
  55. MPIC_GREG_BASE,
  56. MPIC_GREG_FEATURE_0,
  57. MPIC_GREG_GLOBAL_CONF_0,
  58. MPIC_GREG_VENDOR_ID,
  59. MPIC_GREG_IPI_VECTOR_PRI_0,
  60. MPIC_GREG_IPI_STRIDE,
  61. MPIC_GREG_SPURIOUS,
  62. MPIC_GREG_TIMER_FREQ,
  63. MPIC_TIMER_BASE,
  64. MPIC_TIMER_STRIDE,
  65. MPIC_TIMER_CURRENT_CNT,
  66. MPIC_TIMER_BASE_CNT,
  67. MPIC_TIMER_VECTOR_PRI,
  68. MPIC_TIMER_DESTINATION,
  69. MPIC_CPU_BASE,
  70. MPIC_CPU_STRIDE,
  71. MPIC_CPU_IPI_DISPATCH_0,
  72. MPIC_CPU_IPI_DISPATCH_STRIDE,
  73. MPIC_CPU_CURRENT_TASK_PRI,
  74. MPIC_CPU_WHOAMI,
  75. MPIC_CPU_INTACK,
  76. MPIC_CPU_EOI,
  77. MPIC_CPU_MCACK,
  78. MPIC_IRQ_BASE,
  79. MPIC_IRQ_STRIDE,
  80. MPIC_IRQ_VECTOR_PRI,
  81. MPIC_VECPRI_VECTOR_MASK,
  82. MPIC_VECPRI_POLARITY_POSITIVE,
  83. MPIC_VECPRI_POLARITY_NEGATIVE,
  84. MPIC_VECPRI_SENSE_LEVEL,
  85. MPIC_VECPRI_SENSE_EDGE,
  86. MPIC_VECPRI_POLARITY_MASK,
  87. MPIC_VECPRI_SENSE_MASK,
  88. MPIC_IRQ_DESTINATION
  89. },
  90. [1] = { /* Tsi108/109 PIC */
  91. TSI108_GREG_BASE,
  92. TSI108_GREG_FEATURE_0,
  93. TSI108_GREG_GLOBAL_CONF_0,
  94. TSI108_GREG_VENDOR_ID,
  95. TSI108_GREG_IPI_VECTOR_PRI_0,
  96. TSI108_GREG_IPI_STRIDE,
  97. TSI108_GREG_SPURIOUS,
  98. TSI108_GREG_TIMER_FREQ,
  99. TSI108_TIMER_BASE,
  100. TSI108_TIMER_STRIDE,
  101. TSI108_TIMER_CURRENT_CNT,
  102. TSI108_TIMER_BASE_CNT,
  103. TSI108_TIMER_VECTOR_PRI,
  104. TSI108_TIMER_DESTINATION,
  105. TSI108_CPU_BASE,
  106. TSI108_CPU_STRIDE,
  107. TSI108_CPU_IPI_DISPATCH_0,
  108. TSI108_CPU_IPI_DISPATCH_STRIDE,
  109. TSI108_CPU_CURRENT_TASK_PRI,
  110. TSI108_CPU_WHOAMI,
  111. TSI108_CPU_INTACK,
  112. TSI108_CPU_EOI,
  113. TSI108_CPU_MCACK,
  114. TSI108_IRQ_BASE,
  115. TSI108_IRQ_STRIDE,
  116. TSI108_IRQ_VECTOR_PRI,
  117. TSI108_VECPRI_VECTOR_MASK,
  118. TSI108_VECPRI_POLARITY_POSITIVE,
  119. TSI108_VECPRI_POLARITY_NEGATIVE,
  120. TSI108_VECPRI_SENSE_LEVEL,
  121. TSI108_VECPRI_SENSE_EDGE,
  122. TSI108_VECPRI_POLARITY_MASK,
  123. TSI108_VECPRI_SENSE_MASK,
  124. TSI108_IRQ_DESTINATION
  125. },
  126. };
  127. #define MPIC_INFO(name) mpic->hw_set[MPIC_IDX_##name]
  128. #else /* CONFIG_MPIC_WEIRD */
  129. #define MPIC_INFO(name) MPIC_##name
  130. #endif /* CONFIG_MPIC_WEIRD */
  131. static inline unsigned int mpic_processor_id(struct mpic *mpic)
  132. {
  133. unsigned int cpu = 0;
  134. if (mpic->flags & MPIC_PRIMARY)
  135. cpu = hard_smp_processor_id();
  136. return cpu;
  137. }
  138. /*
  139. * Register accessor functions
  140. */
  141. static inline u32 _mpic_read(enum mpic_reg_type type,
  142. struct mpic_reg_bank *rb,
  143. unsigned int reg)
  144. {
  145. switch(type) {
  146. #ifdef CONFIG_PPC_DCR
  147. case mpic_access_dcr:
  148. return dcr_read(rb->dhost, reg);
  149. #endif
  150. case mpic_access_mmio_be:
  151. return in_be32(rb->base + (reg >> 2));
  152. case mpic_access_mmio_le:
  153. default:
  154. return in_le32(rb->base + (reg >> 2));
  155. }
  156. }
  157. static inline void _mpic_write(enum mpic_reg_type type,
  158. struct mpic_reg_bank *rb,
  159. unsigned int reg, u32 value)
  160. {
  161. switch(type) {
  162. #ifdef CONFIG_PPC_DCR
  163. case mpic_access_dcr:
  164. dcr_write(rb->dhost, reg, value);
  165. break;
  166. #endif
  167. case mpic_access_mmio_be:
  168. out_be32(rb->base + (reg >> 2), value);
  169. break;
  170. case mpic_access_mmio_le:
  171. default:
  172. out_le32(rb->base + (reg >> 2), value);
  173. break;
  174. }
  175. }
  176. static inline u32 _mpic_ipi_read(struct mpic *mpic, unsigned int ipi)
  177. {
  178. enum mpic_reg_type type = mpic->reg_type;
  179. unsigned int offset = MPIC_INFO(GREG_IPI_VECTOR_PRI_0) +
  180. (ipi * MPIC_INFO(GREG_IPI_STRIDE));
  181. if ((mpic->flags & MPIC_BROKEN_IPI) && type == mpic_access_mmio_le)
  182. type = mpic_access_mmio_be;
  183. return _mpic_read(type, &mpic->gregs, offset);
  184. }
  185. static inline void _mpic_ipi_write(struct mpic *mpic, unsigned int ipi, u32 value)
  186. {
  187. unsigned int offset = MPIC_INFO(GREG_IPI_VECTOR_PRI_0) +
  188. (ipi * MPIC_INFO(GREG_IPI_STRIDE));
  189. _mpic_write(mpic->reg_type, &mpic->gregs, offset, value);
  190. }
  191. static inline u32 _mpic_cpu_read(struct mpic *mpic, unsigned int reg)
  192. {
  193. unsigned int cpu = mpic_processor_id(mpic);
  194. return _mpic_read(mpic->reg_type, &mpic->cpuregs[cpu], reg);
  195. }
  196. static inline void _mpic_cpu_write(struct mpic *mpic, unsigned int reg, u32 value)
  197. {
  198. unsigned int cpu = mpic_processor_id(mpic);
  199. _mpic_write(mpic->reg_type, &mpic->cpuregs[cpu], reg, value);
  200. }
  201. static inline u32 _mpic_irq_read(struct mpic *mpic, unsigned int src_no, unsigned int reg)
  202. {
  203. unsigned int isu = src_no >> mpic->isu_shift;
  204. unsigned int idx = src_no & mpic->isu_mask;
  205. unsigned int val;
  206. val = _mpic_read(mpic->reg_type, &mpic->isus[isu],
  207. reg + (idx * MPIC_INFO(IRQ_STRIDE)));
  208. #ifdef CONFIG_MPIC_BROKEN_REGREAD
  209. if (reg == 0)
  210. val = (val & (MPIC_VECPRI_MASK | MPIC_VECPRI_ACTIVITY)) |
  211. mpic->isu_reg0_shadow[src_no];
  212. #endif
  213. return val;
  214. }
  215. static inline void _mpic_irq_write(struct mpic *mpic, unsigned int src_no,
  216. unsigned int reg, u32 value)
  217. {
  218. unsigned int isu = src_no >> mpic->isu_shift;
  219. unsigned int idx = src_no & mpic->isu_mask;
  220. _mpic_write(mpic->reg_type, &mpic->isus[isu],
  221. reg + (idx * MPIC_INFO(IRQ_STRIDE)), value);
  222. #ifdef CONFIG_MPIC_BROKEN_REGREAD
  223. if (reg == 0)
  224. mpic->isu_reg0_shadow[src_no] =
  225. value & ~(MPIC_VECPRI_MASK | MPIC_VECPRI_ACTIVITY);
  226. #endif
  227. }
  228. #define mpic_read(b,r) _mpic_read(mpic->reg_type,&(b),(r))
  229. #define mpic_write(b,r,v) _mpic_write(mpic->reg_type,&(b),(r),(v))
  230. #define mpic_ipi_read(i) _mpic_ipi_read(mpic,(i))
  231. #define mpic_ipi_write(i,v) _mpic_ipi_write(mpic,(i),(v))
  232. #define mpic_cpu_read(i) _mpic_cpu_read(mpic,(i))
  233. #define mpic_cpu_write(i,v) _mpic_cpu_write(mpic,(i),(v))
  234. #define mpic_irq_read(s,r) _mpic_irq_read(mpic,(s),(r))
  235. #define mpic_irq_write(s,r,v) _mpic_irq_write(mpic,(s),(r),(v))
  236. /*
  237. * Low level utility functions
  238. */
  239. static void _mpic_map_mmio(struct mpic *mpic, phys_addr_t phys_addr,
  240. struct mpic_reg_bank *rb, unsigned int offset,
  241. unsigned int size)
  242. {
  243. rb->base = ioremap(phys_addr + offset, size);
  244. BUG_ON(rb->base == NULL);
  245. }
  246. #ifdef CONFIG_PPC_DCR
  247. static void _mpic_map_dcr(struct mpic *mpic, struct device_node *node,
  248. struct mpic_reg_bank *rb,
  249. unsigned int offset, unsigned int size)
  250. {
  251. const u32 *dbasep;
  252. dbasep = of_get_property(node, "dcr-reg", NULL);
  253. rb->dhost = dcr_map(node, *dbasep + offset, size);
  254. BUG_ON(!DCR_MAP_OK(rb->dhost));
  255. }
  256. static inline void mpic_map(struct mpic *mpic, struct device_node *node,
  257. phys_addr_t phys_addr, struct mpic_reg_bank *rb,
  258. unsigned int offset, unsigned int size)
  259. {
  260. if (mpic->flags & MPIC_USES_DCR)
  261. _mpic_map_dcr(mpic, node, rb, offset, size);
  262. else
  263. _mpic_map_mmio(mpic, phys_addr, rb, offset, size);
  264. }
  265. #else /* CONFIG_PPC_DCR */
  266. #define mpic_map(m,n,p,b,o,s) _mpic_map_mmio(m,p,b,o,s)
  267. #endif /* !CONFIG_PPC_DCR */
  268. /* Check if we have one of those nice broken MPICs with a flipped endian on
  269. * reads from IPI registers
  270. */
  271. static void __init mpic_test_broken_ipi(struct mpic *mpic)
  272. {
  273. u32 r;
  274. mpic_write(mpic->gregs, MPIC_INFO(GREG_IPI_VECTOR_PRI_0), MPIC_VECPRI_MASK);
  275. r = mpic_read(mpic->gregs, MPIC_INFO(GREG_IPI_VECTOR_PRI_0));
  276. if (r == le32_to_cpu(MPIC_VECPRI_MASK)) {
  277. printk(KERN_INFO "mpic: Detected reversed IPI registers\n");
  278. mpic->flags |= MPIC_BROKEN_IPI;
  279. }
  280. }
  281. #ifdef CONFIG_MPIC_U3_HT_IRQS
  282. /* Test if an interrupt is sourced from HyperTransport (used on broken U3s)
  283. * to force the edge setting on the MPIC and do the ack workaround.
  284. */
  285. static inline int mpic_is_ht_interrupt(struct mpic *mpic, unsigned int source)
  286. {
  287. if (source >= 128 || !mpic->fixups)
  288. return 0;
  289. return mpic->fixups[source].base != NULL;
  290. }
  291. static inline void mpic_ht_end_irq(struct mpic *mpic, unsigned int source)
  292. {
  293. struct mpic_irq_fixup *fixup = &mpic->fixups[source];
  294. if (fixup->applebase) {
  295. unsigned int soff = (fixup->index >> 3) & ~3;
  296. unsigned int mask = 1U << (fixup->index & 0x1f);
  297. writel(mask, fixup->applebase + soff);
  298. } else {
  299. raw_spin_lock(&mpic->fixup_lock);
  300. writeb(0x11 + 2 * fixup->index, fixup->base + 2);
  301. writel(fixup->data, fixup->base + 4);
  302. raw_spin_unlock(&mpic->fixup_lock);
  303. }
  304. }
  305. static void mpic_startup_ht_interrupt(struct mpic *mpic, unsigned int source,
  306. bool level)
  307. {
  308. struct mpic_irq_fixup *fixup = &mpic->fixups[source];
  309. unsigned long flags;
  310. u32 tmp;
  311. if (fixup->base == NULL)
  312. return;
  313. DBG("startup_ht_interrupt(0x%x) index: %d\n",
  314. source, fixup->index);
  315. raw_spin_lock_irqsave(&mpic->fixup_lock, flags);
  316. /* Enable and configure */
  317. writeb(0x10 + 2 * fixup->index, fixup->base + 2);
  318. tmp = readl(fixup->base + 4);
  319. tmp &= ~(0x23U);
  320. if (level)
  321. tmp |= 0x22;
  322. writel(tmp, fixup->base + 4);
  323. raw_spin_unlock_irqrestore(&mpic->fixup_lock, flags);
  324. #ifdef CONFIG_PM
  325. /* use the lowest bit inverted to the actual HW,
  326. * set if this fixup was enabled, clear otherwise */
  327. mpic->save_data[source].fixup_data = tmp | 1;
  328. #endif
  329. }
  330. static void mpic_shutdown_ht_interrupt(struct mpic *mpic, unsigned int source)
  331. {
  332. struct mpic_irq_fixup *fixup = &mpic->fixups[source];
  333. unsigned long flags;
  334. u32 tmp;
  335. if (fixup->base == NULL)
  336. return;
  337. DBG("shutdown_ht_interrupt(0x%x)\n", source);
  338. /* Disable */
  339. raw_spin_lock_irqsave(&mpic->fixup_lock, flags);
  340. writeb(0x10 + 2 * fixup->index, fixup->base + 2);
  341. tmp = readl(fixup->base + 4);
  342. tmp |= 1;
  343. writel(tmp, fixup->base + 4);
  344. raw_spin_unlock_irqrestore(&mpic->fixup_lock, flags);
  345. #ifdef CONFIG_PM
  346. /* use the lowest bit inverted to the actual HW,
  347. * set if this fixup was enabled, clear otherwise */
  348. mpic->save_data[source].fixup_data = tmp & ~1;
  349. #endif
  350. }
  351. #ifdef CONFIG_PCI_MSI
  352. static void __init mpic_scan_ht_msi(struct mpic *mpic, u8 __iomem *devbase,
  353. unsigned int devfn)
  354. {
  355. u8 __iomem *base;
  356. u8 pos, flags;
  357. u64 addr = 0;
  358. for (pos = readb(devbase + PCI_CAPABILITY_LIST); pos != 0;
  359. pos = readb(devbase + pos + PCI_CAP_LIST_NEXT)) {
  360. u8 id = readb(devbase + pos + PCI_CAP_LIST_ID);
  361. if (id == PCI_CAP_ID_HT) {
  362. id = readb(devbase + pos + 3);
  363. if ((id & HT_5BIT_CAP_MASK) == HT_CAPTYPE_MSI_MAPPING)
  364. break;
  365. }
  366. }
  367. if (pos == 0)
  368. return;
  369. base = devbase + pos;
  370. flags = readb(base + HT_MSI_FLAGS);
  371. if (!(flags & HT_MSI_FLAGS_FIXED)) {
  372. addr = readl(base + HT_MSI_ADDR_LO) & HT_MSI_ADDR_LO_MASK;
  373. addr = addr | ((u64)readl(base + HT_MSI_ADDR_HI) << 32);
  374. }
  375. printk(KERN_DEBUG "mpic: - HT:%02x.%x %s MSI mapping found @ 0x%llx\n",
  376. PCI_SLOT(devfn), PCI_FUNC(devfn),
  377. flags & HT_MSI_FLAGS_ENABLE ? "enabled" : "disabled", addr);
  378. if (!(flags & HT_MSI_FLAGS_ENABLE))
  379. writeb(flags | HT_MSI_FLAGS_ENABLE, base + HT_MSI_FLAGS);
  380. }
  381. #else
  382. static void __init mpic_scan_ht_msi(struct mpic *mpic, u8 __iomem *devbase,
  383. unsigned int devfn)
  384. {
  385. return;
  386. }
  387. #endif
  388. static void __init mpic_scan_ht_pic(struct mpic *mpic, u8 __iomem *devbase,
  389. unsigned int devfn, u32 vdid)
  390. {
  391. int i, irq, n;
  392. u8 __iomem *base;
  393. u32 tmp;
  394. u8 pos;
  395. for (pos = readb(devbase + PCI_CAPABILITY_LIST); pos != 0;
  396. pos = readb(devbase + pos + PCI_CAP_LIST_NEXT)) {
  397. u8 id = readb(devbase + pos + PCI_CAP_LIST_ID);
  398. if (id == PCI_CAP_ID_HT) {
  399. id = readb(devbase + pos + 3);
  400. if ((id & HT_5BIT_CAP_MASK) == HT_CAPTYPE_IRQ)
  401. break;
  402. }
  403. }
  404. if (pos == 0)
  405. return;
  406. base = devbase + pos;
  407. writeb(0x01, base + 2);
  408. n = (readl(base + 4) >> 16) & 0xff;
  409. printk(KERN_INFO "mpic: - HT:%02x.%x [0x%02x] vendor %04x device %04x"
  410. " has %d irqs\n",
  411. devfn >> 3, devfn & 0x7, pos, vdid & 0xffff, vdid >> 16, n + 1);
  412. for (i = 0; i <= n; i++) {
  413. writeb(0x10 + 2 * i, base + 2);
  414. tmp = readl(base + 4);
  415. irq = (tmp >> 16) & 0xff;
  416. DBG("HT PIC index 0x%x, irq 0x%x, tmp: %08x\n", i, irq, tmp);
  417. /* mask it , will be unmasked later */
  418. tmp |= 0x1;
  419. writel(tmp, base + 4);
  420. mpic->fixups[irq].index = i;
  421. mpic->fixups[irq].base = base;
  422. /* Apple HT PIC has a non-standard way of doing EOIs */
  423. if ((vdid & 0xffff) == 0x106b)
  424. mpic->fixups[irq].applebase = devbase + 0x60;
  425. else
  426. mpic->fixups[irq].applebase = NULL;
  427. writeb(0x11 + 2 * i, base + 2);
  428. mpic->fixups[irq].data = readl(base + 4) | 0x80000000;
  429. }
  430. }
  431. static void __init mpic_scan_ht_pics(struct mpic *mpic)
  432. {
  433. unsigned int devfn;
  434. u8 __iomem *cfgspace;
  435. printk(KERN_INFO "mpic: Setting up HT PICs workarounds for U3/U4\n");
  436. /* Allocate fixups array */
  437. mpic->fixups = kzalloc(128 * sizeof(*mpic->fixups), GFP_KERNEL);
  438. BUG_ON(mpic->fixups == NULL);
  439. /* Init spinlock */
  440. raw_spin_lock_init(&mpic->fixup_lock);
  441. /* Map U3 config space. We assume all IO-APICs are on the primary bus
  442. * so we only need to map 64kB.
  443. */
  444. cfgspace = ioremap(0xf2000000, 0x10000);
  445. BUG_ON(cfgspace == NULL);
  446. /* Now we scan all slots. We do a very quick scan, we read the header
  447. * type, vendor ID and device ID only, that's plenty enough
  448. */
  449. for (devfn = 0; devfn < 0x100; devfn++) {
  450. u8 __iomem *devbase = cfgspace + (devfn << 8);
  451. u8 hdr_type = readb(devbase + PCI_HEADER_TYPE);
  452. u32 l = readl(devbase + PCI_VENDOR_ID);
  453. u16 s;
  454. DBG("devfn %x, l: %x\n", devfn, l);
  455. /* If no device, skip */
  456. if (l == 0xffffffff || l == 0x00000000 ||
  457. l == 0x0000ffff || l == 0xffff0000)
  458. goto next;
  459. /* Check if is supports capability lists */
  460. s = readw(devbase + PCI_STATUS);
  461. if (!(s & PCI_STATUS_CAP_LIST))
  462. goto next;
  463. mpic_scan_ht_pic(mpic, devbase, devfn, l);
  464. mpic_scan_ht_msi(mpic, devbase, devfn);
  465. next:
  466. /* next device, if function 0 */
  467. if (PCI_FUNC(devfn) == 0 && (hdr_type & 0x80) == 0)
  468. devfn += 7;
  469. }
  470. }
  471. #else /* CONFIG_MPIC_U3_HT_IRQS */
  472. static inline int mpic_is_ht_interrupt(struct mpic *mpic, unsigned int source)
  473. {
  474. return 0;
  475. }
  476. static void __init mpic_scan_ht_pics(struct mpic *mpic)
  477. {
  478. }
  479. #endif /* CONFIG_MPIC_U3_HT_IRQS */
  480. #ifdef CONFIG_SMP
  481. static int irq_choose_cpu(const struct cpumask *mask)
  482. {
  483. int cpuid;
  484. if (cpumask_equal(mask, cpu_all_mask)) {
  485. static int irq_rover = 0;
  486. static DEFINE_RAW_SPINLOCK(irq_rover_lock);
  487. unsigned long flags;
  488. /* Round-robin distribution... */
  489. do_round_robin:
  490. raw_spin_lock_irqsave(&irq_rover_lock, flags);
  491. irq_rover = cpumask_next(irq_rover, cpu_online_mask);
  492. if (irq_rover >= nr_cpu_ids)
  493. irq_rover = cpumask_first(cpu_online_mask);
  494. cpuid = irq_rover;
  495. raw_spin_unlock_irqrestore(&irq_rover_lock, flags);
  496. } else {
  497. cpuid = cpumask_first_and(mask, cpu_online_mask);
  498. if (cpuid >= nr_cpu_ids)
  499. goto do_round_robin;
  500. }
  501. return get_hard_smp_processor_id(cpuid);
  502. }
  503. #else
  504. static int irq_choose_cpu(const struct cpumask *mask)
  505. {
  506. return hard_smp_processor_id();
  507. }
  508. #endif
  509. #define mpic_irq_to_hw(virq) ((unsigned int)irq_map[virq].hwirq)
  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 = mpic_irq_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 = mpic_irq_to_hw(d->irq);
  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 = mpic_irq_to_hw(d->irq);
  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 = mpic_irq_to_hw(d->irq);
  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 = mpic_irq_to_hw(d->irq);
  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 = mpic_irq_to_hw(d->irq);
  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 = mpic_irq_to_hw(d->irq);
  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 = mpic_irq_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 = mpic_irq_to_hw(d->irq);
  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 = mpic_irq_to_hw(d->irq);
  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 = mpic_irq_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 = mpic_irq_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. static unsigned char map_mpic_senses[4] = {
  840. IRQ_TYPE_EDGE_RISING,
  841. IRQ_TYPE_LEVEL_LOW,
  842. IRQ_TYPE_LEVEL_HIGH,
  843. IRQ_TYPE_EDGE_FALLING,
  844. };
  845. *out_hwirq = intspec[0];
  846. if (intsize > 1) {
  847. u32 mask = 0x3;
  848. /* Apple invented a new race of encoding on machines with
  849. * an HT APIC. They encode, among others, the index within
  850. * the HT APIC. We don't care about it here since thankfully,
  851. * it appears that they have the APIC already properly
  852. * configured, and thus our current fixup code that reads the
  853. * APIC config works fine. However, we still need to mask out
  854. * bits in the specifier to make sure we only get bit 0 which
  855. * is the level/edge bit (the only sense bit exposed by Apple),
  856. * as their bit 1 means something else.
  857. */
  858. if (machine_is(powermac))
  859. mask = 0x1;
  860. *out_flags = map_mpic_senses[intspec[1] & mask];
  861. } else
  862. *out_flags = IRQ_TYPE_NONE;
  863. DBG("mpic: xlate (%d cells: 0x%08x 0x%08x) to line 0x%lx sense 0x%x\n",
  864. intsize, intspec[0], intspec[1], *out_hwirq, *out_flags);
  865. return 0;
  866. }
  867. static struct irq_host_ops mpic_host_ops = {
  868. .match = mpic_host_match,
  869. .map = mpic_host_map,
  870. .xlate = mpic_host_xlate,
  871. };
  872. static int mpic_reset_prohibited(struct device_node *node)
  873. {
  874. return node && of_get_property(node, "pic-no-reset", NULL);
  875. }
  876. /*
  877. * Exported functions
  878. */
  879. struct mpic * __init mpic_alloc(struct device_node *node,
  880. phys_addr_t phys_addr,
  881. unsigned int flags,
  882. unsigned int isu_size,
  883. unsigned int irq_count,
  884. const char *name)
  885. {
  886. struct mpic *mpic;
  887. u32 greg_feature;
  888. const char *vers;
  889. int i;
  890. int intvec_top;
  891. u64 paddr = phys_addr;
  892. mpic = kzalloc(sizeof(struct mpic), GFP_KERNEL);
  893. if (mpic == NULL)
  894. return NULL;
  895. mpic->name = name;
  896. mpic->hc_irq = mpic_irq_chip;
  897. mpic->hc_irq.name = name;
  898. if (flags & MPIC_PRIMARY)
  899. mpic->hc_irq.irq_set_affinity = mpic_set_affinity;
  900. #ifdef CONFIG_MPIC_U3_HT_IRQS
  901. mpic->hc_ht_irq = mpic_irq_ht_chip;
  902. mpic->hc_ht_irq.name = name;
  903. if (flags & MPIC_PRIMARY)
  904. mpic->hc_ht_irq.irq_set_affinity = mpic_set_affinity;
  905. #endif /* CONFIG_MPIC_U3_HT_IRQS */
  906. #ifdef CONFIG_SMP
  907. mpic->hc_ipi = mpic_ipi_chip;
  908. mpic->hc_ipi.name = name;
  909. #endif /* CONFIG_SMP */
  910. mpic->flags = flags;
  911. mpic->isu_size = isu_size;
  912. mpic->irq_count = irq_count;
  913. mpic->num_sources = 0; /* so far */
  914. if (flags & MPIC_LARGE_VECTORS)
  915. intvec_top = 2047;
  916. else
  917. intvec_top = 255;
  918. mpic->timer_vecs[0] = intvec_top - 8;
  919. mpic->timer_vecs[1] = intvec_top - 7;
  920. mpic->timer_vecs[2] = intvec_top - 6;
  921. mpic->timer_vecs[3] = intvec_top - 5;
  922. mpic->ipi_vecs[0] = intvec_top - 4;
  923. mpic->ipi_vecs[1] = intvec_top - 3;
  924. mpic->ipi_vecs[2] = intvec_top - 2;
  925. mpic->ipi_vecs[3] = intvec_top - 1;
  926. mpic->spurious_vec = intvec_top;
  927. /* Check for "big-endian" in device-tree */
  928. if (node && of_get_property(node, "big-endian", NULL) != NULL)
  929. mpic->flags |= MPIC_BIG_ENDIAN;
  930. /* Look for protected sources */
  931. if (node) {
  932. int psize;
  933. unsigned int bits, mapsize;
  934. const u32 *psrc =
  935. of_get_property(node, "protected-sources", &psize);
  936. if (psrc) {
  937. psize /= 4;
  938. bits = intvec_top + 1;
  939. mapsize = BITS_TO_LONGS(bits) * sizeof(unsigned long);
  940. mpic->protected = kzalloc(mapsize, GFP_KERNEL);
  941. BUG_ON(mpic->protected == NULL);
  942. for (i = 0; i < psize; i++) {
  943. if (psrc[i] > intvec_top)
  944. continue;
  945. __set_bit(psrc[i], mpic->protected);
  946. }
  947. }
  948. }
  949. #ifdef CONFIG_MPIC_WEIRD
  950. mpic->hw_set = mpic_infos[MPIC_GET_REGSET(flags)];
  951. #endif
  952. /* default register type */
  953. mpic->reg_type = (flags & MPIC_BIG_ENDIAN) ?
  954. mpic_access_mmio_be : mpic_access_mmio_le;
  955. /* If no physical address is passed in, a device-node is mandatory */
  956. BUG_ON(paddr == 0 && node == NULL);
  957. /* If no physical address passed in, check if it's dcr based */
  958. if (paddr == 0 && of_get_property(node, "dcr-reg", NULL) != NULL) {
  959. #ifdef CONFIG_PPC_DCR
  960. mpic->flags |= MPIC_USES_DCR;
  961. mpic->reg_type = mpic_access_dcr;
  962. #else
  963. BUG();
  964. #endif /* CONFIG_PPC_DCR */
  965. }
  966. /* If the MPIC is not DCR based, and no physical address was passed
  967. * in, try to obtain one
  968. */
  969. if (paddr == 0 && !(mpic->flags & MPIC_USES_DCR)) {
  970. const u32 *reg = of_get_property(node, "reg", NULL);
  971. BUG_ON(reg == NULL);
  972. paddr = of_translate_address(node, reg);
  973. BUG_ON(paddr == OF_BAD_ADDR);
  974. }
  975. /* Map the global registers */
  976. mpic_map(mpic, node, paddr, &mpic->gregs, MPIC_INFO(GREG_BASE), 0x1000);
  977. mpic_map(mpic, node, paddr, &mpic->tmregs, MPIC_INFO(TIMER_BASE), 0x1000);
  978. /* Reset */
  979. /* When using a device-node, reset requests are only honored if the MPIC
  980. * is allowed to reset.
  981. */
  982. if (mpic_reset_prohibited(node))
  983. mpic->flags |= MPIC_NO_RESET;
  984. if ((flags & MPIC_WANTS_RESET) && !(mpic->flags & MPIC_NO_RESET)) {
  985. printk(KERN_DEBUG "mpic: Resetting\n");
  986. mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
  987. mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  988. | MPIC_GREG_GCONF_RESET);
  989. while( mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  990. & MPIC_GREG_GCONF_RESET)
  991. mb();
  992. }
  993. /* CoreInt */
  994. if (flags & MPIC_ENABLE_COREINT)
  995. mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
  996. mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  997. | MPIC_GREG_GCONF_COREINT);
  998. if (flags & MPIC_ENABLE_MCK)
  999. mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
  1000. mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  1001. | MPIC_GREG_GCONF_MCK);
  1002. /* Read feature register, calculate num CPUs and, for non-ISU
  1003. * MPICs, num sources as well. On ISU MPICs, sources are counted
  1004. * as ISUs are added
  1005. */
  1006. greg_feature = mpic_read(mpic->gregs, MPIC_INFO(GREG_FEATURE_0));
  1007. mpic->num_cpus = ((greg_feature & MPIC_GREG_FEATURE_LAST_CPU_MASK)
  1008. >> MPIC_GREG_FEATURE_LAST_CPU_SHIFT) + 1;
  1009. if (isu_size == 0) {
  1010. if (flags & MPIC_BROKEN_FRR_NIRQS)
  1011. mpic->num_sources = mpic->irq_count;
  1012. else
  1013. mpic->num_sources =
  1014. ((greg_feature & MPIC_GREG_FEATURE_LAST_SRC_MASK)
  1015. >> MPIC_GREG_FEATURE_LAST_SRC_SHIFT) + 1;
  1016. }
  1017. /* Map the per-CPU registers */
  1018. for (i = 0; i < mpic->num_cpus; i++) {
  1019. mpic_map(mpic, node, paddr, &mpic->cpuregs[i],
  1020. MPIC_INFO(CPU_BASE) + i * MPIC_INFO(CPU_STRIDE),
  1021. 0x1000);
  1022. }
  1023. /* Initialize main ISU if none provided */
  1024. if (mpic->isu_size == 0) {
  1025. mpic->isu_size = mpic->num_sources;
  1026. mpic_map(mpic, node, paddr, &mpic->isus[0],
  1027. MPIC_INFO(IRQ_BASE), MPIC_INFO(IRQ_STRIDE) * mpic->isu_size);
  1028. }
  1029. mpic->isu_shift = 1 + __ilog2(mpic->isu_size - 1);
  1030. mpic->isu_mask = (1 << mpic->isu_shift) - 1;
  1031. mpic->irqhost = irq_alloc_host(node, IRQ_HOST_MAP_LINEAR,
  1032. isu_size ? isu_size : mpic->num_sources,
  1033. &mpic_host_ops,
  1034. flags & MPIC_LARGE_VECTORS ? 2048 : 256);
  1035. if (mpic->irqhost == NULL)
  1036. return NULL;
  1037. mpic->irqhost->host_data = mpic;
  1038. /* Display version */
  1039. switch (greg_feature & MPIC_GREG_FEATURE_VERSION_MASK) {
  1040. case 1:
  1041. vers = "1.0";
  1042. break;
  1043. case 2:
  1044. vers = "1.2";
  1045. break;
  1046. case 3:
  1047. vers = "1.3";
  1048. break;
  1049. default:
  1050. vers = "<unknown>";
  1051. break;
  1052. }
  1053. printk(KERN_INFO "mpic: Setting up MPIC \"%s\" version %s at %llx,"
  1054. " max %d CPUs\n",
  1055. name, vers, (unsigned long long)paddr, mpic->num_cpus);
  1056. printk(KERN_INFO "mpic: ISU size: %d, shift: %d, mask: %x\n",
  1057. mpic->isu_size, mpic->isu_shift, mpic->isu_mask);
  1058. mpic->next = mpics;
  1059. mpics = mpic;
  1060. if (flags & MPIC_PRIMARY) {
  1061. mpic_primary = mpic;
  1062. irq_set_default_host(mpic->irqhost);
  1063. }
  1064. return mpic;
  1065. }
  1066. void __init mpic_assign_isu(struct mpic *mpic, unsigned int isu_num,
  1067. phys_addr_t paddr)
  1068. {
  1069. unsigned int isu_first = isu_num * mpic->isu_size;
  1070. BUG_ON(isu_num >= MPIC_MAX_ISU);
  1071. mpic_map(mpic, mpic->irqhost->of_node,
  1072. paddr, &mpic->isus[isu_num], 0,
  1073. MPIC_INFO(IRQ_STRIDE) * mpic->isu_size);
  1074. if ((isu_first + mpic->isu_size) > mpic->num_sources)
  1075. mpic->num_sources = isu_first + mpic->isu_size;
  1076. }
  1077. void __init mpic_set_default_senses(struct mpic *mpic, u8 *senses, int count)
  1078. {
  1079. mpic->senses = senses;
  1080. mpic->senses_count = count;
  1081. }
  1082. void __init mpic_init(struct mpic *mpic)
  1083. {
  1084. int i;
  1085. int cpu;
  1086. BUG_ON(mpic->num_sources == 0);
  1087. printk(KERN_INFO "mpic: Initializing for %d sources\n", mpic->num_sources);
  1088. /* Set current processor priority to max */
  1089. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0xf);
  1090. /* Initialize timers: just disable them all */
  1091. for (i = 0; i < 4; i++) {
  1092. mpic_write(mpic->tmregs,
  1093. i * MPIC_INFO(TIMER_STRIDE) +
  1094. MPIC_INFO(TIMER_DESTINATION), 0);
  1095. mpic_write(mpic->tmregs,
  1096. i * MPIC_INFO(TIMER_STRIDE) +
  1097. MPIC_INFO(TIMER_VECTOR_PRI),
  1098. MPIC_VECPRI_MASK |
  1099. (mpic->timer_vecs[0] + i));
  1100. }
  1101. /* Initialize IPIs to our reserved vectors and mark them disabled for now */
  1102. mpic_test_broken_ipi(mpic);
  1103. for (i = 0; i < 4; i++) {
  1104. mpic_ipi_write(i,
  1105. MPIC_VECPRI_MASK |
  1106. (10 << MPIC_VECPRI_PRIORITY_SHIFT) |
  1107. (mpic->ipi_vecs[0] + i));
  1108. }
  1109. /* Initialize interrupt sources */
  1110. if (mpic->irq_count == 0)
  1111. mpic->irq_count = mpic->num_sources;
  1112. /* Do the HT PIC fixups on U3 broken mpic */
  1113. DBG("MPIC flags: %x\n", mpic->flags);
  1114. if ((mpic->flags & MPIC_U3_HT_IRQS) && (mpic->flags & MPIC_PRIMARY)) {
  1115. mpic_scan_ht_pics(mpic);
  1116. mpic_u3msi_init(mpic);
  1117. }
  1118. mpic_pasemi_msi_init(mpic);
  1119. cpu = mpic_processor_id(mpic);
  1120. if (!(mpic->flags & MPIC_NO_RESET)) {
  1121. for (i = 0; i < mpic->num_sources; i++) {
  1122. /* start with vector = source number, and masked */
  1123. u32 vecpri = MPIC_VECPRI_MASK | i |
  1124. (8 << MPIC_VECPRI_PRIORITY_SHIFT);
  1125. /* check if protected */
  1126. if (mpic->protected && test_bit(i, mpic->protected))
  1127. continue;
  1128. /* init hw */
  1129. mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI), vecpri);
  1130. mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION), 1 << cpu);
  1131. }
  1132. }
  1133. /* Init spurious vector */
  1134. mpic_write(mpic->gregs, MPIC_INFO(GREG_SPURIOUS), mpic->spurious_vec);
  1135. /* Disable 8259 passthrough, if supported */
  1136. if (!(mpic->flags & MPIC_NO_PTHROU_DIS))
  1137. mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
  1138. mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  1139. | MPIC_GREG_GCONF_8259_PTHROU_DIS);
  1140. if (mpic->flags & MPIC_NO_BIAS)
  1141. mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
  1142. mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  1143. | MPIC_GREG_GCONF_NO_BIAS);
  1144. /* Set current processor priority to 0 */
  1145. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0);
  1146. #ifdef CONFIG_PM
  1147. /* allocate memory to save mpic state */
  1148. mpic->save_data = kmalloc(mpic->num_sources * sizeof(*mpic->save_data),
  1149. GFP_KERNEL);
  1150. BUG_ON(mpic->save_data == NULL);
  1151. #endif
  1152. }
  1153. void __init mpic_set_clk_ratio(struct mpic *mpic, u32 clock_ratio)
  1154. {
  1155. u32 v;
  1156. v = mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1);
  1157. v &= ~MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO_MASK;
  1158. v |= MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO(clock_ratio);
  1159. mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v);
  1160. }
  1161. void __init mpic_set_serial_int(struct mpic *mpic, int enable)
  1162. {
  1163. unsigned long flags;
  1164. u32 v;
  1165. raw_spin_lock_irqsave(&mpic_lock, flags);
  1166. v = mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1);
  1167. if (enable)
  1168. v |= MPIC_GREG_GLOBAL_CONF_1_SIE;
  1169. else
  1170. v &= ~MPIC_GREG_GLOBAL_CONF_1_SIE;
  1171. mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v);
  1172. raw_spin_unlock_irqrestore(&mpic_lock, flags);
  1173. }
  1174. void mpic_irq_set_priority(unsigned int irq, unsigned int pri)
  1175. {
  1176. struct mpic *mpic = mpic_find(irq);
  1177. unsigned int src = mpic_irq_to_hw(irq);
  1178. unsigned long flags;
  1179. u32 reg;
  1180. if (!mpic)
  1181. return;
  1182. raw_spin_lock_irqsave(&mpic_lock, flags);
  1183. if (mpic_is_ipi(mpic, irq)) {
  1184. reg = mpic_ipi_read(src - mpic->ipi_vecs[0]) &
  1185. ~MPIC_VECPRI_PRIORITY_MASK;
  1186. mpic_ipi_write(src - mpic->ipi_vecs[0],
  1187. reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
  1188. } else {
  1189. reg = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI))
  1190. & ~MPIC_VECPRI_PRIORITY_MASK;
  1191. mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI),
  1192. reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
  1193. }
  1194. raw_spin_unlock_irqrestore(&mpic_lock, flags);
  1195. }
  1196. void mpic_setup_this_cpu(void)
  1197. {
  1198. #ifdef CONFIG_SMP
  1199. struct mpic *mpic = mpic_primary;
  1200. unsigned long flags;
  1201. u32 msk = 1 << hard_smp_processor_id();
  1202. unsigned int i;
  1203. BUG_ON(mpic == NULL);
  1204. DBG("%s: setup_this_cpu(%d)\n", mpic->name, hard_smp_processor_id());
  1205. raw_spin_lock_irqsave(&mpic_lock, flags);
  1206. /* let the mpic know we want intrs. default affinity is 0xffffffff
  1207. * until changed via /proc. That's how it's done on x86. If we want
  1208. * it differently, then we should make sure we also change the default
  1209. * values of irq_desc[].affinity in irq.c.
  1210. */
  1211. if (distribute_irqs) {
  1212. for (i = 0; i < mpic->num_sources ; i++)
  1213. mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION),
  1214. mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION)) | msk);
  1215. }
  1216. /* Set current processor priority to 0 */
  1217. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0);
  1218. raw_spin_unlock_irqrestore(&mpic_lock, flags);
  1219. #endif /* CONFIG_SMP */
  1220. }
  1221. int mpic_cpu_get_priority(void)
  1222. {
  1223. struct mpic *mpic = mpic_primary;
  1224. return mpic_cpu_read(MPIC_INFO(CPU_CURRENT_TASK_PRI));
  1225. }
  1226. void mpic_cpu_set_priority(int prio)
  1227. {
  1228. struct mpic *mpic = mpic_primary;
  1229. prio &= MPIC_CPU_TASKPRI_MASK;
  1230. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), prio);
  1231. }
  1232. void mpic_teardown_this_cpu(int secondary)
  1233. {
  1234. struct mpic *mpic = mpic_primary;
  1235. unsigned long flags;
  1236. u32 msk = 1 << hard_smp_processor_id();
  1237. unsigned int i;
  1238. BUG_ON(mpic == NULL);
  1239. DBG("%s: teardown_this_cpu(%d)\n", mpic->name, hard_smp_processor_id());
  1240. raw_spin_lock_irqsave(&mpic_lock, flags);
  1241. /* let the mpic know we don't want intrs. */
  1242. for (i = 0; i < mpic->num_sources ; i++)
  1243. mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION),
  1244. mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION)) & ~msk);
  1245. /* Set current processor priority to max */
  1246. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0xf);
  1247. /* We need to EOI the IPI since not all platforms reset the MPIC
  1248. * on boot and new interrupts wouldn't get delivered otherwise.
  1249. */
  1250. mpic_eoi(mpic);
  1251. raw_spin_unlock_irqrestore(&mpic_lock, flags);
  1252. }
  1253. static unsigned int _mpic_get_one_irq(struct mpic *mpic, int reg)
  1254. {
  1255. u32 src;
  1256. src = mpic_cpu_read(reg) & MPIC_INFO(VECPRI_VECTOR_MASK);
  1257. #ifdef DEBUG_LOW
  1258. DBG("%s: get_one_irq(reg 0x%x): %d\n", mpic->name, reg, src);
  1259. #endif
  1260. if (unlikely(src == mpic->spurious_vec)) {
  1261. if (mpic->flags & MPIC_SPV_EOI)
  1262. mpic_eoi(mpic);
  1263. return NO_IRQ;
  1264. }
  1265. if (unlikely(mpic->protected && test_bit(src, mpic->protected))) {
  1266. if (printk_ratelimit())
  1267. printk(KERN_WARNING "%s: Got protected source %d !\n",
  1268. mpic->name, (int)src);
  1269. mpic_eoi(mpic);
  1270. return NO_IRQ;
  1271. }
  1272. return irq_linear_revmap(mpic->irqhost, src);
  1273. }
  1274. unsigned int mpic_get_one_irq(struct mpic *mpic)
  1275. {
  1276. return _mpic_get_one_irq(mpic, MPIC_INFO(CPU_INTACK));
  1277. }
  1278. unsigned int mpic_get_irq(void)
  1279. {
  1280. struct mpic *mpic = mpic_primary;
  1281. BUG_ON(mpic == NULL);
  1282. return mpic_get_one_irq(mpic);
  1283. }
  1284. unsigned int mpic_get_coreint_irq(void)
  1285. {
  1286. #ifdef CONFIG_BOOKE
  1287. struct mpic *mpic = mpic_primary;
  1288. u32 src;
  1289. BUG_ON(mpic == NULL);
  1290. src = mfspr(SPRN_EPR);
  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. return NO_IRQ;
  1301. }
  1302. return irq_linear_revmap(mpic->irqhost, src);
  1303. #else
  1304. return NO_IRQ;
  1305. #endif
  1306. }
  1307. unsigned int mpic_get_mcirq(void)
  1308. {
  1309. struct mpic *mpic = mpic_primary;
  1310. BUG_ON(mpic == NULL);
  1311. return _mpic_get_one_irq(mpic, MPIC_INFO(CPU_MCACK));
  1312. }
  1313. #ifdef CONFIG_SMP
  1314. void mpic_request_ipis(void)
  1315. {
  1316. struct mpic *mpic = mpic_primary;
  1317. int i;
  1318. BUG_ON(mpic == NULL);
  1319. printk(KERN_INFO "mpic: requesting IPIs...\n");
  1320. for (i = 0; i < 4; i++) {
  1321. unsigned int vipi = irq_create_mapping(mpic->irqhost,
  1322. mpic->ipi_vecs[0] + i);
  1323. if (vipi == NO_IRQ) {
  1324. printk(KERN_ERR "Failed to map %s\n", smp_ipi_name[i]);
  1325. continue;
  1326. }
  1327. smp_request_message_ipi(vipi, i);
  1328. }
  1329. }
  1330. static void mpic_send_ipi(unsigned int ipi_no, const struct cpumask *cpu_mask)
  1331. {
  1332. struct mpic *mpic = mpic_primary;
  1333. BUG_ON(mpic == NULL);
  1334. #ifdef DEBUG_IPI
  1335. DBG("%s: send_ipi(ipi_no: %d)\n", mpic->name, ipi_no);
  1336. #endif
  1337. mpic_cpu_write(MPIC_INFO(CPU_IPI_DISPATCH_0) +
  1338. ipi_no * MPIC_INFO(CPU_IPI_DISPATCH_STRIDE),
  1339. mpic_physmask(cpumask_bits(cpu_mask)[0]));
  1340. }
  1341. void smp_mpic_message_pass(int target, int msg)
  1342. {
  1343. cpumask_var_t tmp;
  1344. /* make sure we're sending something that translates to an IPI */
  1345. if ((unsigned int)msg > 3) {
  1346. printk("SMP %d: smp_message_pass: unknown msg %d\n",
  1347. smp_processor_id(), msg);
  1348. return;
  1349. }
  1350. switch (target) {
  1351. case MSG_ALL:
  1352. mpic_send_ipi(msg, cpu_online_mask);
  1353. break;
  1354. case MSG_ALL_BUT_SELF:
  1355. alloc_cpumask_var(&tmp, GFP_NOWAIT);
  1356. cpumask_andnot(tmp, cpu_online_mask,
  1357. cpumask_of(smp_processor_id()));
  1358. mpic_send_ipi(msg, tmp);
  1359. free_cpumask_var(tmp);
  1360. break;
  1361. default:
  1362. mpic_send_ipi(msg, cpumask_of(target));
  1363. break;
  1364. }
  1365. }
  1366. int __init smp_mpic_probe(void)
  1367. {
  1368. int nr_cpus;
  1369. DBG("smp_mpic_probe()...\n");
  1370. nr_cpus = cpumask_weight(cpu_possible_mask);
  1371. DBG("nr_cpus: %d\n", nr_cpus);
  1372. if (nr_cpus > 1)
  1373. mpic_request_ipis();
  1374. return nr_cpus;
  1375. }
  1376. void __devinit smp_mpic_setup_cpu(int cpu)
  1377. {
  1378. mpic_setup_this_cpu();
  1379. }
  1380. void mpic_reset_core(int cpu)
  1381. {
  1382. struct mpic *mpic = mpic_primary;
  1383. u32 pir;
  1384. int cpuid = get_hard_smp_processor_id(cpu);
  1385. /* Set target bit for core reset */
  1386. pir = mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
  1387. pir |= (1 << cpuid);
  1388. mpic_write(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT), pir);
  1389. mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
  1390. /* Restore target bit after reset complete */
  1391. pir &= ~(1 << cpuid);
  1392. mpic_write(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT), pir);
  1393. mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
  1394. }
  1395. #endif /* CONFIG_SMP */
  1396. #ifdef CONFIG_PM
  1397. static int mpic_suspend(struct sys_device *dev, pm_message_t state)
  1398. {
  1399. struct mpic *mpic = container_of(dev, struct mpic, sysdev);
  1400. int i;
  1401. for (i = 0; i < mpic->num_sources; i++) {
  1402. mpic->save_data[i].vecprio =
  1403. mpic_irq_read(i, MPIC_INFO(IRQ_VECTOR_PRI));
  1404. mpic->save_data[i].dest =
  1405. mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION));
  1406. }
  1407. return 0;
  1408. }
  1409. static int mpic_resume(struct sys_device *dev)
  1410. {
  1411. struct mpic *mpic = container_of(dev, struct mpic, sysdev);
  1412. int i;
  1413. for (i = 0; i < mpic->num_sources; i++) {
  1414. mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI),
  1415. mpic->save_data[i].vecprio);
  1416. mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION),
  1417. mpic->save_data[i].dest);
  1418. #ifdef CONFIG_MPIC_U3_HT_IRQS
  1419. if (mpic->fixups) {
  1420. struct mpic_irq_fixup *fixup = &mpic->fixups[i];
  1421. if (fixup->base) {
  1422. /* we use the lowest bit in an inverted meaning */
  1423. if ((mpic->save_data[i].fixup_data & 1) == 0)
  1424. continue;
  1425. /* Enable and configure */
  1426. writeb(0x10 + 2 * fixup->index, fixup->base + 2);
  1427. writel(mpic->save_data[i].fixup_data & ~1,
  1428. fixup->base + 4);
  1429. }
  1430. }
  1431. #endif
  1432. } /* end for loop */
  1433. return 0;
  1434. }
  1435. #endif
  1436. static struct sysdev_class mpic_sysclass = {
  1437. #ifdef CONFIG_PM
  1438. .resume = mpic_resume,
  1439. .suspend = mpic_suspend,
  1440. #endif
  1441. .name = "mpic",
  1442. };
  1443. static int mpic_init_sys(void)
  1444. {
  1445. struct mpic *mpic = mpics;
  1446. int error, id = 0;
  1447. error = sysdev_class_register(&mpic_sysclass);
  1448. while (mpic && !error) {
  1449. mpic->sysdev.cls = &mpic_sysclass;
  1450. mpic->sysdev.id = id++;
  1451. error = sysdev_register(&mpic->sysdev);
  1452. mpic = mpic->next;
  1453. }
  1454. return error;
  1455. }
  1456. device_initcall(mpic_init_sys);