mpic.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708
  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(const cpumask_t *mask)
  479. {
  480. int cpuid;
  481. if (cpumask_equal(mask, cpu_all_mask)) {
  482. static int irq_rover;
  483. static DEFINE_SPINLOCK(irq_rover_lock);
  484. unsigned long flags;
  485. /* Round-robin distribution... */
  486. do_round_robin:
  487. spin_lock_irqsave(&irq_rover_lock, flags);
  488. while (!cpu_online(irq_rover)) {
  489. if (++irq_rover >= NR_CPUS)
  490. irq_rover = 0;
  491. }
  492. cpuid = irq_rover;
  493. do {
  494. if (++irq_rover >= NR_CPUS)
  495. irq_rover = 0;
  496. } while (!cpu_online(irq_rover));
  497. spin_unlock_irqrestore(&irq_rover_lock, flags);
  498. } else {
  499. cpuid = cpumask_first_and(mask, cpu_online_mask);
  500. if (cpuid >= nr_cpu_ids)
  501. goto do_round_robin;
  502. }
  503. return get_hard_smp_processor_id(cpuid);
  504. }
  505. #else
  506. static int irq_choose_cpu(const cpumask_t *mask)
  507. {
  508. return hard_smp_processor_id();
  509. }
  510. #endif
  511. #define mpic_irq_to_hw(virq) ((unsigned int)irq_map[virq].hwirq)
  512. /* Find an mpic associated with a given linux interrupt */
  513. static struct mpic *mpic_find(unsigned int irq)
  514. {
  515. if (irq < NUM_ISA_INTERRUPTS)
  516. return NULL;
  517. return irq_to_desc(irq)->chip_data;
  518. }
  519. /* Determine if the linux irq is an IPI */
  520. static unsigned int mpic_is_ipi(struct mpic *mpic, unsigned int irq)
  521. {
  522. unsigned int src = mpic_irq_to_hw(irq);
  523. return (src >= mpic->ipi_vecs[0] && src <= mpic->ipi_vecs[3]);
  524. }
  525. /* Convert a cpu mask from logical to physical cpu numbers. */
  526. static inline u32 mpic_physmask(u32 cpumask)
  527. {
  528. int i;
  529. u32 mask = 0;
  530. for (i = 0; i < NR_CPUS; ++i, cpumask >>= 1)
  531. mask |= (cpumask & 1) << get_hard_smp_processor_id(i);
  532. return mask;
  533. }
  534. #ifdef CONFIG_SMP
  535. /* Get the mpic structure from the IPI number */
  536. static inline struct mpic * mpic_from_ipi(unsigned int ipi)
  537. {
  538. return irq_to_desc(ipi)->chip_data;
  539. }
  540. #endif
  541. /* Get the mpic structure from the irq number */
  542. static inline struct mpic * mpic_from_irq(unsigned int irq)
  543. {
  544. return irq_to_desc(irq)->chip_data;
  545. }
  546. /* Send an EOI */
  547. static inline void mpic_eoi(struct mpic *mpic)
  548. {
  549. mpic_cpu_write(MPIC_INFO(CPU_EOI), 0);
  550. (void)mpic_cpu_read(MPIC_INFO(CPU_WHOAMI));
  551. }
  552. /*
  553. * Linux descriptor level callbacks
  554. */
  555. void mpic_unmask_irq(unsigned int irq)
  556. {
  557. unsigned int loops = 100000;
  558. struct mpic *mpic = mpic_from_irq(irq);
  559. unsigned int src = mpic_irq_to_hw(irq);
  560. DBG("%p: %s: enable_irq: %d (src %d)\n", mpic, mpic->name, irq, src);
  561. mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI),
  562. mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) &
  563. ~MPIC_VECPRI_MASK);
  564. /* make sure mask gets to controller before we return to user */
  565. do {
  566. if (!loops--) {
  567. printk(KERN_ERR "mpic_enable_irq timeout\n");
  568. break;
  569. }
  570. } while(mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) & MPIC_VECPRI_MASK);
  571. }
  572. void mpic_mask_irq(unsigned int irq)
  573. {
  574. unsigned int loops = 100000;
  575. struct mpic *mpic = mpic_from_irq(irq);
  576. unsigned int src = mpic_irq_to_hw(irq);
  577. DBG("%s: disable_irq: %d (src %d)\n", mpic->name, irq, src);
  578. mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI),
  579. mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) |
  580. MPIC_VECPRI_MASK);
  581. /* make sure mask gets to controller before we return to user */
  582. do {
  583. if (!loops--) {
  584. printk(KERN_ERR "mpic_enable_irq timeout\n");
  585. break;
  586. }
  587. } while(!(mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) & MPIC_VECPRI_MASK));
  588. }
  589. void mpic_end_irq(unsigned int irq)
  590. {
  591. struct mpic *mpic = mpic_from_irq(irq);
  592. #ifdef DEBUG_IRQ
  593. DBG("%s: end_irq: %d\n", mpic->name, irq);
  594. #endif
  595. /* We always EOI on end_irq() even for edge interrupts since that
  596. * should only lower the priority, the MPIC should have properly
  597. * latched another edge interrupt coming in anyway
  598. */
  599. mpic_eoi(mpic);
  600. }
  601. #ifdef CONFIG_MPIC_U3_HT_IRQS
  602. static void mpic_unmask_ht_irq(unsigned int irq)
  603. {
  604. struct mpic *mpic = mpic_from_irq(irq);
  605. unsigned int src = mpic_irq_to_hw(irq);
  606. mpic_unmask_irq(irq);
  607. if (irq_to_desc(irq)->status & IRQ_LEVEL)
  608. mpic_ht_end_irq(mpic, src);
  609. }
  610. static unsigned int mpic_startup_ht_irq(unsigned int irq)
  611. {
  612. struct mpic *mpic = mpic_from_irq(irq);
  613. unsigned int src = mpic_irq_to_hw(irq);
  614. mpic_unmask_irq(irq);
  615. mpic_startup_ht_interrupt(mpic, src, irq_to_desc(irq)->status);
  616. return 0;
  617. }
  618. static void mpic_shutdown_ht_irq(unsigned int irq)
  619. {
  620. struct mpic *mpic = mpic_from_irq(irq);
  621. unsigned int src = mpic_irq_to_hw(irq);
  622. mpic_shutdown_ht_interrupt(mpic, src, irq_to_desc(irq)->status);
  623. mpic_mask_irq(irq);
  624. }
  625. static void mpic_end_ht_irq(unsigned int irq)
  626. {
  627. struct mpic *mpic = mpic_from_irq(irq);
  628. unsigned int src = mpic_irq_to_hw(irq);
  629. #ifdef DEBUG_IRQ
  630. DBG("%s: end_irq: %d\n", mpic->name, irq);
  631. #endif
  632. /* We always EOI on end_irq() even for edge interrupts since that
  633. * should only lower the priority, the MPIC should have properly
  634. * latched another edge interrupt coming in anyway
  635. */
  636. if (irq_to_desc(irq)->status & IRQ_LEVEL)
  637. mpic_ht_end_irq(mpic, src);
  638. mpic_eoi(mpic);
  639. }
  640. #endif /* !CONFIG_MPIC_U3_HT_IRQS */
  641. #ifdef CONFIG_SMP
  642. static void mpic_unmask_ipi(unsigned int irq)
  643. {
  644. struct mpic *mpic = mpic_from_ipi(irq);
  645. unsigned int src = mpic_irq_to_hw(irq) - mpic->ipi_vecs[0];
  646. DBG("%s: enable_ipi: %d (ipi %d)\n", mpic->name, irq, src);
  647. mpic_ipi_write(src, mpic_ipi_read(src) & ~MPIC_VECPRI_MASK);
  648. }
  649. static void mpic_mask_ipi(unsigned int irq)
  650. {
  651. /* NEVER disable an IPI... that's just plain wrong! */
  652. }
  653. static void mpic_end_ipi(unsigned int irq)
  654. {
  655. struct mpic *mpic = mpic_from_ipi(irq);
  656. /*
  657. * IPIs are marked IRQ_PER_CPU. This has the side effect of
  658. * preventing the IRQ_PENDING/IRQ_INPROGRESS logic from
  659. * applying to them. We EOI them late to avoid re-entering.
  660. * We mark IPI's with IRQF_DISABLED as they must run with
  661. * irqs disabled.
  662. */
  663. mpic_eoi(mpic);
  664. }
  665. #endif /* CONFIG_SMP */
  666. int mpic_set_affinity(unsigned int irq, const struct cpumask *cpumask)
  667. {
  668. struct mpic *mpic = mpic_from_irq(irq);
  669. unsigned int src = mpic_irq_to_hw(irq);
  670. if (mpic->flags & MPIC_SINGLE_DEST_CPU) {
  671. int cpuid = irq_choose_cpu(cpumask);
  672. mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION), 1 << cpuid);
  673. } else {
  674. cpumask_t tmp;
  675. cpumask_and(&tmp, cpumask, cpu_online_mask);
  676. mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION),
  677. mpic_physmask(cpus_addr(tmp)[0]));
  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. 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. 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. 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. 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. 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. 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. 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. spin_unlock_irqrestore(&mpic_lock, flags);
  1220. }
  1221. void mpic_send_ipi(unsigned int ipi_no, unsigned int cpu_mask)
  1222. {
  1223. struct mpic *mpic = mpic_primary;
  1224. BUG_ON(mpic == NULL);
  1225. #ifdef DEBUG_IPI
  1226. DBG("%s: send_ipi(ipi_no: %d)\n", mpic->name, ipi_no);
  1227. #endif
  1228. mpic_cpu_write(MPIC_INFO(CPU_IPI_DISPATCH_0) +
  1229. ipi_no * MPIC_INFO(CPU_IPI_DISPATCH_STRIDE),
  1230. mpic_physmask(cpu_mask & cpus_addr(cpu_online_map)[0]));
  1231. }
  1232. static unsigned int _mpic_get_one_irq(struct mpic *mpic, int reg)
  1233. {
  1234. u32 src;
  1235. src = mpic_cpu_read(reg) & MPIC_INFO(VECPRI_VECTOR_MASK);
  1236. #ifdef DEBUG_LOW
  1237. DBG("%s: get_one_irq(reg 0x%x): %d\n", mpic->name, reg, src);
  1238. #endif
  1239. if (unlikely(src == mpic->spurious_vec)) {
  1240. if (mpic->flags & MPIC_SPV_EOI)
  1241. mpic_eoi(mpic);
  1242. return NO_IRQ;
  1243. }
  1244. if (unlikely(mpic->protected && test_bit(src, mpic->protected))) {
  1245. if (printk_ratelimit())
  1246. printk(KERN_WARNING "%s: Got protected source %d !\n",
  1247. mpic->name, (int)src);
  1248. mpic_eoi(mpic);
  1249. return NO_IRQ;
  1250. }
  1251. return irq_linear_revmap(mpic->irqhost, src);
  1252. }
  1253. unsigned int mpic_get_one_irq(struct mpic *mpic)
  1254. {
  1255. return _mpic_get_one_irq(mpic, MPIC_INFO(CPU_INTACK));
  1256. }
  1257. unsigned int mpic_get_irq(void)
  1258. {
  1259. struct mpic *mpic = mpic_primary;
  1260. BUG_ON(mpic == NULL);
  1261. return mpic_get_one_irq(mpic);
  1262. }
  1263. unsigned int mpic_get_coreint_irq(void)
  1264. {
  1265. #ifdef CONFIG_BOOKE
  1266. struct mpic *mpic = mpic_primary;
  1267. u32 src;
  1268. BUG_ON(mpic == NULL);
  1269. src = mfspr(SPRN_EPR);
  1270. if (unlikely(src == mpic->spurious_vec)) {
  1271. if (mpic->flags & MPIC_SPV_EOI)
  1272. mpic_eoi(mpic);
  1273. return NO_IRQ;
  1274. }
  1275. if (unlikely(mpic->protected && test_bit(src, mpic->protected))) {
  1276. if (printk_ratelimit())
  1277. printk(KERN_WARNING "%s: Got protected source %d !\n",
  1278. mpic->name, (int)src);
  1279. return NO_IRQ;
  1280. }
  1281. return irq_linear_revmap(mpic->irqhost, src);
  1282. #else
  1283. return NO_IRQ;
  1284. #endif
  1285. }
  1286. unsigned int mpic_get_mcirq(void)
  1287. {
  1288. struct mpic *mpic = mpic_primary;
  1289. BUG_ON(mpic == NULL);
  1290. return _mpic_get_one_irq(mpic, MPIC_INFO(CPU_MCACK));
  1291. }
  1292. #ifdef CONFIG_SMP
  1293. void mpic_request_ipis(void)
  1294. {
  1295. struct mpic *mpic = mpic_primary;
  1296. int i;
  1297. BUG_ON(mpic == NULL);
  1298. printk(KERN_INFO "mpic: requesting IPIs ... \n");
  1299. for (i = 0; i < 4; i++) {
  1300. unsigned int vipi = irq_create_mapping(mpic->irqhost,
  1301. mpic->ipi_vecs[0] + i);
  1302. if (vipi == NO_IRQ) {
  1303. printk(KERN_ERR "Failed to map %s\n", smp_ipi_name[i]);
  1304. continue;
  1305. }
  1306. smp_request_message_ipi(vipi, i);
  1307. }
  1308. }
  1309. void smp_mpic_message_pass(int target, int msg)
  1310. {
  1311. /* make sure we're sending something that translates to an IPI */
  1312. if ((unsigned int)msg > 3) {
  1313. printk("SMP %d: smp_message_pass: unknown msg %d\n",
  1314. smp_processor_id(), msg);
  1315. return;
  1316. }
  1317. switch (target) {
  1318. case MSG_ALL:
  1319. mpic_send_ipi(msg, 0xffffffff);
  1320. break;
  1321. case MSG_ALL_BUT_SELF:
  1322. mpic_send_ipi(msg, 0xffffffff & ~(1 << smp_processor_id()));
  1323. break;
  1324. default:
  1325. mpic_send_ipi(msg, 1 << target);
  1326. break;
  1327. }
  1328. }
  1329. int __init smp_mpic_probe(void)
  1330. {
  1331. int nr_cpus;
  1332. DBG("smp_mpic_probe()...\n");
  1333. nr_cpus = cpus_weight(cpu_possible_map);
  1334. DBG("nr_cpus: %d\n", nr_cpus);
  1335. if (nr_cpus > 1)
  1336. mpic_request_ipis();
  1337. return nr_cpus;
  1338. }
  1339. void __devinit smp_mpic_setup_cpu(int cpu)
  1340. {
  1341. mpic_setup_this_cpu();
  1342. }
  1343. #endif /* CONFIG_SMP */
  1344. #ifdef CONFIG_PM
  1345. static int mpic_suspend(struct sys_device *dev, pm_message_t state)
  1346. {
  1347. struct mpic *mpic = container_of(dev, struct mpic, sysdev);
  1348. int i;
  1349. for (i = 0; i < mpic->num_sources; i++) {
  1350. mpic->save_data[i].vecprio =
  1351. mpic_irq_read(i, MPIC_INFO(IRQ_VECTOR_PRI));
  1352. mpic->save_data[i].dest =
  1353. mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION));
  1354. }
  1355. return 0;
  1356. }
  1357. static int mpic_resume(struct sys_device *dev)
  1358. {
  1359. struct mpic *mpic = container_of(dev, struct mpic, sysdev);
  1360. int i;
  1361. for (i = 0; i < mpic->num_sources; i++) {
  1362. mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI),
  1363. mpic->save_data[i].vecprio);
  1364. mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION),
  1365. mpic->save_data[i].dest);
  1366. #ifdef CONFIG_MPIC_U3_HT_IRQS
  1367. {
  1368. struct mpic_irq_fixup *fixup = &mpic->fixups[i];
  1369. if (fixup->base) {
  1370. /* we use the lowest bit in an inverted meaning */
  1371. if ((mpic->save_data[i].fixup_data & 1) == 0)
  1372. continue;
  1373. /* Enable and configure */
  1374. writeb(0x10 + 2 * fixup->index, fixup->base + 2);
  1375. writel(mpic->save_data[i].fixup_data & ~1,
  1376. fixup->base + 4);
  1377. }
  1378. }
  1379. #endif
  1380. } /* end for loop */
  1381. return 0;
  1382. }
  1383. #endif
  1384. static struct sysdev_class mpic_sysclass = {
  1385. #ifdef CONFIG_PM
  1386. .resume = mpic_resume,
  1387. .suspend = mpic_suspend,
  1388. #endif
  1389. .name = "mpic",
  1390. };
  1391. static int mpic_init_sys(void)
  1392. {
  1393. struct mpic *mpic = mpics;
  1394. int error, id = 0;
  1395. error = sysdev_class_register(&mpic_sysclass);
  1396. while (mpic && !error) {
  1397. mpic->sysdev.cls = &mpic_sysclass;
  1398. mpic->sysdev.id = id++;
  1399. error = sysdev_register(&mpic->sysdev);
  1400. mpic = mpic->next;
  1401. }
  1402. return error;
  1403. }
  1404. device_initcall(mpic_init_sys);