mpic.c 45 KB

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