mpic.c 43 KB

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