mpic.c 42 KB

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