mpic.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782
  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 <linux/syscore_ops.h>
  29. #include <asm/ptrace.h>
  30. #include <asm/signal.h>
  31. #include <asm/io.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/irq.h>
  34. #include <asm/machdep.h>
  35. #include <asm/mpic.h>
  36. #include <asm/smp.h>
  37. #include "mpic.h"
  38. #ifdef DEBUG
  39. #define DBG(fmt...) printk(fmt)
  40. #else
  41. #define DBG(fmt...)
  42. #endif
  43. static struct mpic *mpics;
  44. static struct mpic *mpic_primary;
  45. static DEFINE_RAW_SPINLOCK(mpic_lock);
  46. #ifdef CONFIG_PPC32 /* XXX for now */
  47. #ifdef CONFIG_IRQ_ALL_CPUS
  48. #define distribute_irqs (1)
  49. #else
  50. #define distribute_irqs (0)
  51. #endif
  52. #endif
  53. #ifdef CONFIG_MPIC_WEIRD
  54. static u32 mpic_infos[][MPIC_IDX_END] = {
  55. [0] = { /* Original OpenPIC compatible MPIC */
  56. MPIC_GREG_BASE,
  57. MPIC_GREG_FEATURE_0,
  58. MPIC_GREG_GLOBAL_CONF_0,
  59. MPIC_GREG_VENDOR_ID,
  60. MPIC_GREG_IPI_VECTOR_PRI_0,
  61. MPIC_GREG_IPI_STRIDE,
  62. MPIC_GREG_SPURIOUS,
  63. MPIC_GREG_TIMER_FREQ,
  64. MPIC_TIMER_BASE,
  65. MPIC_TIMER_STRIDE,
  66. MPIC_TIMER_CURRENT_CNT,
  67. MPIC_TIMER_BASE_CNT,
  68. MPIC_TIMER_VECTOR_PRI,
  69. MPIC_TIMER_DESTINATION,
  70. MPIC_CPU_BASE,
  71. MPIC_CPU_STRIDE,
  72. MPIC_CPU_IPI_DISPATCH_0,
  73. MPIC_CPU_IPI_DISPATCH_STRIDE,
  74. MPIC_CPU_CURRENT_TASK_PRI,
  75. MPIC_CPU_WHOAMI,
  76. MPIC_CPU_INTACK,
  77. MPIC_CPU_EOI,
  78. MPIC_CPU_MCACK,
  79. MPIC_IRQ_BASE,
  80. MPIC_IRQ_STRIDE,
  81. MPIC_IRQ_VECTOR_PRI,
  82. MPIC_VECPRI_VECTOR_MASK,
  83. MPIC_VECPRI_POLARITY_POSITIVE,
  84. MPIC_VECPRI_POLARITY_NEGATIVE,
  85. MPIC_VECPRI_SENSE_LEVEL,
  86. MPIC_VECPRI_SENSE_EDGE,
  87. MPIC_VECPRI_POLARITY_MASK,
  88. MPIC_VECPRI_SENSE_MASK,
  89. MPIC_IRQ_DESTINATION
  90. },
  91. [1] = { /* Tsi108/109 PIC */
  92. TSI108_GREG_BASE,
  93. TSI108_GREG_FEATURE_0,
  94. TSI108_GREG_GLOBAL_CONF_0,
  95. TSI108_GREG_VENDOR_ID,
  96. TSI108_GREG_IPI_VECTOR_PRI_0,
  97. TSI108_GREG_IPI_STRIDE,
  98. TSI108_GREG_SPURIOUS,
  99. TSI108_GREG_TIMER_FREQ,
  100. TSI108_TIMER_BASE,
  101. TSI108_TIMER_STRIDE,
  102. TSI108_TIMER_CURRENT_CNT,
  103. TSI108_TIMER_BASE_CNT,
  104. TSI108_TIMER_VECTOR_PRI,
  105. TSI108_TIMER_DESTINATION,
  106. TSI108_CPU_BASE,
  107. TSI108_CPU_STRIDE,
  108. TSI108_CPU_IPI_DISPATCH_0,
  109. TSI108_CPU_IPI_DISPATCH_STRIDE,
  110. TSI108_CPU_CURRENT_TASK_PRI,
  111. TSI108_CPU_WHOAMI,
  112. TSI108_CPU_INTACK,
  113. TSI108_CPU_EOI,
  114. TSI108_CPU_MCACK,
  115. TSI108_IRQ_BASE,
  116. TSI108_IRQ_STRIDE,
  117. TSI108_IRQ_VECTOR_PRI,
  118. TSI108_VECPRI_VECTOR_MASK,
  119. TSI108_VECPRI_POLARITY_POSITIVE,
  120. TSI108_VECPRI_POLARITY_NEGATIVE,
  121. TSI108_VECPRI_SENSE_LEVEL,
  122. TSI108_VECPRI_SENSE_EDGE,
  123. TSI108_VECPRI_POLARITY_MASK,
  124. TSI108_VECPRI_SENSE_MASK,
  125. TSI108_IRQ_DESTINATION
  126. },
  127. };
  128. #define MPIC_INFO(name) mpic->hw_set[MPIC_IDX_##name]
  129. #else /* CONFIG_MPIC_WEIRD */
  130. #define MPIC_INFO(name) MPIC_##name
  131. #endif /* CONFIG_MPIC_WEIRD */
  132. static inline unsigned int mpic_processor_id(struct mpic *mpic)
  133. {
  134. unsigned int cpu = 0;
  135. if (mpic->flags & MPIC_PRIMARY)
  136. cpu = hard_smp_processor_id();
  137. return cpu;
  138. }
  139. /*
  140. * Register accessor functions
  141. */
  142. static inline u32 _mpic_read(enum mpic_reg_type type,
  143. struct mpic_reg_bank *rb,
  144. unsigned int reg)
  145. {
  146. switch(type) {
  147. #ifdef CONFIG_PPC_DCR
  148. case mpic_access_dcr:
  149. return dcr_read(rb->dhost, reg);
  150. #endif
  151. case mpic_access_mmio_be:
  152. return in_be32(rb->base + (reg >> 2));
  153. case mpic_access_mmio_le:
  154. default:
  155. return in_le32(rb->base + (reg >> 2));
  156. }
  157. }
  158. static inline void _mpic_write(enum mpic_reg_type type,
  159. struct mpic_reg_bank *rb,
  160. unsigned int reg, u32 value)
  161. {
  162. switch(type) {
  163. #ifdef CONFIG_PPC_DCR
  164. case mpic_access_dcr:
  165. dcr_write(rb->dhost, reg, value);
  166. break;
  167. #endif
  168. case mpic_access_mmio_be:
  169. out_be32(rb->base + (reg >> 2), value);
  170. break;
  171. case mpic_access_mmio_le:
  172. default:
  173. out_le32(rb->base + (reg >> 2), value);
  174. break;
  175. }
  176. }
  177. static inline u32 _mpic_ipi_read(struct mpic *mpic, unsigned int ipi)
  178. {
  179. enum mpic_reg_type type = mpic->reg_type;
  180. unsigned int offset = MPIC_INFO(GREG_IPI_VECTOR_PRI_0) +
  181. (ipi * MPIC_INFO(GREG_IPI_STRIDE));
  182. if ((mpic->flags & MPIC_BROKEN_IPI) && type == mpic_access_mmio_le)
  183. type = mpic_access_mmio_be;
  184. return _mpic_read(type, &mpic->gregs, offset);
  185. }
  186. static inline void _mpic_ipi_write(struct mpic *mpic, unsigned int ipi, u32 value)
  187. {
  188. unsigned int offset = MPIC_INFO(GREG_IPI_VECTOR_PRI_0) +
  189. (ipi * MPIC_INFO(GREG_IPI_STRIDE));
  190. _mpic_write(mpic->reg_type, &mpic->gregs, offset, value);
  191. }
  192. static inline u32 _mpic_cpu_read(struct mpic *mpic, unsigned int reg)
  193. {
  194. unsigned int cpu = mpic_processor_id(mpic);
  195. return _mpic_read(mpic->reg_type, &mpic->cpuregs[cpu], reg);
  196. }
  197. static inline void _mpic_cpu_write(struct mpic *mpic, unsigned int reg, u32 value)
  198. {
  199. unsigned int cpu = mpic_processor_id(mpic);
  200. _mpic_write(mpic->reg_type, &mpic->cpuregs[cpu], reg, value);
  201. }
  202. static inline u32 _mpic_irq_read(struct mpic *mpic, unsigned int src_no, unsigned int reg)
  203. {
  204. unsigned int isu = src_no >> mpic->isu_shift;
  205. unsigned int idx = src_no & mpic->isu_mask;
  206. unsigned int val;
  207. val = _mpic_read(mpic->reg_type, &mpic->isus[isu],
  208. reg + (idx * MPIC_INFO(IRQ_STRIDE)));
  209. #ifdef CONFIG_MPIC_BROKEN_REGREAD
  210. if (reg == 0)
  211. val = (val & (MPIC_VECPRI_MASK | MPIC_VECPRI_ACTIVITY)) |
  212. mpic->isu_reg0_shadow[src_no];
  213. #endif
  214. return val;
  215. }
  216. static inline void _mpic_irq_write(struct mpic *mpic, unsigned int src_no,
  217. unsigned int reg, u32 value)
  218. {
  219. unsigned int isu = src_no >> mpic->isu_shift;
  220. unsigned int idx = src_no & mpic->isu_mask;
  221. _mpic_write(mpic->reg_type, &mpic->isus[isu],
  222. reg + (idx * MPIC_INFO(IRQ_STRIDE)), value);
  223. #ifdef CONFIG_MPIC_BROKEN_REGREAD
  224. if (reg == 0)
  225. mpic->isu_reg0_shadow[src_no] =
  226. value & ~(MPIC_VECPRI_MASK | MPIC_VECPRI_ACTIVITY);
  227. #endif
  228. }
  229. #define mpic_read(b,r) _mpic_read(mpic->reg_type,&(b),(r))
  230. #define mpic_write(b,r,v) _mpic_write(mpic->reg_type,&(b),(r),(v))
  231. #define mpic_ipi_read(i) _mpic_ipi_read(mpic,(i))
  232. #define mpic_ipi_write(i,v) _mpic_ipi_write(mpic,(i),(v))
  233. #define mpic_cpu_read(i) _mpic_cpu_read(mpic,(i))
  234. #define mpic_cpu_write(i,v) _mpic_cpu_write(mpic,(i),(v))
  235. #define mpic_irq_read(s,r) _mpic_irq_read(mpic,(s),(r))
  236. #define mpic_irq_write(s,r,v) _mpic_irq_write(mpic,(s),(r),(v))
  237. /*
  238. * Low level utility functions
  239. */
  240. static void _mpic_map_mmio(struct mpic *mpic, phys_addr_t phys_addr,
  241. struct mpic_reg_bank *rb, unsigned int offset,
  242. unsigned int size)
  243. {
  244. rb->base = ioremap(phys_addr + offset, size);
  245. BUG_ON(rb->base == NULL);
  246. }
  247. #ifdef CONFIG_PPC_DCR
  248. static void _mpic_map_dcr(struct mpic *mpic, struct device_node *node,
  249. struct mpic_reg_bank *rb,
  250. unsigned int offset, unsigned int size)
  251. {
  252. const u32 *dbasep;
  253. dbasep = of_get_property(node, "dcr-reg", NULL);
  254. rb->dhost = dcr_map(node, *dbasep + offset, size);
  255. BUG_ON(!DCR_MAP_OK(rb->dhost));
  256. }
  257. static inline void mpic_map(struct mpic *mpic, struct device_node *node,
  258. phys_addr_t phys_addr, struct mpic_reg_bank *rb,
  259. unsigned int offset, unsigned int size)
  260. {
  261. if (mpic->flags & MPIC_USES_DCR)
  262. _mpic_map_dcr(mpic, node, rb, offset, size);
  263. else
  264. _mpic_map_mmio(mpic, phys_addr, rb, offset, size);
  265. }
  266. #else /* CONFIG_PPC_DCR */
  267. #define mpic_map(m,n,p,b,o,s) _mpic_map_mmio(m,p,b,o,s)
  268. #endif /* !CONFIG_PPC_DCR */
  269. /* Check if we have one of those nice broken MPICs with a flipped endian on
  270. * reads from IPI registers
  271. */
  272. static void __init mpic_test_broken_ipi(struct mpic *mpic)
  273. {
  274. u32 r;
  275. mpic_write(mpic->gregs, MPIC_INFO(GREG_IPI_VECTOR_PRI_0), MPIC_VECPRI_MASK);
  276. r = mpic_read(mpic->gregs, MPIC_INFO(GREG_IPI_VECTOR_PRI_0));
  277. if (r == le32_to_cpu(MPIC_VECPRI_MASK)) {
  278. printk(KERN_INFO "mpic: Detected reversed IPI registers\n");
  279. mpic->flags |= MPIC_BROKEN_IPI;
  280. }
  281. }
  282. #ifdef CONFIG_MPIC_U3_HT_IRQS
  283. /* Test if an interrupt is sourced from HyperTransport (used on broken U3s)
  284. * to force the edge setting on the MPIC and do the ack workaround.
  285. */
  286. static inline int mpic_is_ht_interrupt(struct mpic *mpic, unsigned int source)
  287. {
  288. if (source >= 128 || !mpic->fixups)
  289. return 0;
  290. return mpic->fixups[source].base != NULL;
  291. }
  292. static inline void mpic_ht_end_irq(struct mpic *mpic, unsigned int source)
  293. {
  294. struct mpic_irq_fixup *fixup = &mpic->fixups[source];
  295. if (fixup->applebase) {
  296. unsigned int soff = (fixup->index >> 3) & ~3;
  297. unsigned int mask = 1U << (fixup->index & 0x1f);
  298. writel(mask, fixup->applebase + soff);
  299. } else {
  300. raw_spin_lock(&mpic->fixup_lock);
  301. writeb(0x11 + 2 * fixup->index, fixup->base + 2);
  302. writel(fixup->data, fixup->base + 4);
  303. raw_spin_unlock(&mpic->fixup_lock);
  304. }
  305. }
  306. static void mpic_startup_ht_interrupt(struct mpic *mpic, unsigned int source,
  307. bool level)
  308. {
  309. struct mpic_irq_fixup *fixup = &mpic->fixups[source];
  310. unsigned long flags;
  311. u32 tmp;
  312. if (fixup->base == NULL)
  313. return;
  314. DBG("startup_ht_interrupt(0x%x) index: %d\n",
  315. source, fixup->index);
  316. raw_spin_lock_irqsave(&mpic->fixup_lock, flags);
  317. /* Enable and configure */
  318. writeb(0x10 + 2 * fixup->index, fixup->base + 2);
  319. tmp = readl(fixup->base + 4);
  320. tmp &= ~(0x23U);
  321. if (level)
  322. tmp |= 0x22;
  323. writel(tmp, fixup->base + 4);
  324. raw_spin_unlock_irqrestore(&mpic->fixup_lock, flags);
  325. #ifdef CONFIG_PM
  326. /* use the lowest bit inverted to the actual HW,
  327. * set if this fixup was enabled, clear otherwise */
  328. mpic->save_data[source].fixup_data = tmp | 1;
  329. #endif
  330. }
  331. static void mpic_shutdown_ht_interrupt(struct mpic *mpic, unsigned int source)
  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)\n", source);
  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 irq_get_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 irq_get_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 (irqd_is_level_type(d))
  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, irqd_is_level_type(d));
  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);
  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 (irqd_is_level_type(d))
  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. unsigned int vecpri, vold, vnew;
  715. DBG("mpic: set_irq_type(mpic:@%p,virq:%d,src:0x%x,type:0x%x)\n",
  716. mpic, d->irq, src, flow_type);
  717. if (src >= mpic->irq_count)
  718. return -EINVAL;
  719. if (flow_type == IRQ_TYPE_NONE)
  720. if (mpic->senses && src < mpic->senses_count)
  721. flow_type = mpic->senses[src];
  722. if (flow_type == IRQ_TYPE_NONE)
  723. flow_type = IRQ_TYPE_LEVEL_LOW;
  724. irqd_set_trigger_type(d, flow_type);
  725. if (mpic_is_ht_interrupt(mpic, src))
  726. vecpri = MPIC_VECPRI_POLARITY_POSITIVE |
  727. MPIC_VECPRI_SENSE_EDGE;
  728. else
  729. vecpri = mpic_type_to_vecpri(mpic, flow_type);
  730. vold = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI));
  731. vnew = vold & ~(MPIC_INFO(VECPRI_POLARITY_MASK) |
  732. MPIC_INFO(VECPRI_SENSE_MASK));
  733. vnew |= vecpri;
  734. if (vold != vnew)
  735. mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), vnew);
  736. return IRQ_SET_MASK_OK_NOCOPY;;
  737. }
  738. void mpic_set_vector(unsigned int virq, unsigned int vector)
  739. {
  740. struct mpic *mpic = mpic_from_irq(virq);
  741. unsigned int src = mpic_irq_to_hw(virq);
  742. unsigned int vecpri;
  743. DBG("mpic: set_vector(mpic:@%p,virq:%d,src:%d,vector:0x%x)\n",
  744. mpic, virq, src, vector);
  745. if (src >= mpic->irq_count)
  746. return;
  747. vecpri = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI));
  748. vecpri = vecpri & ~MPIC_INFO(VECPRI_VECTOR_MASK);
  749. vecpri |= vector;
  750. mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), vecpri);
  751. }
  752. void mpic_set_destination(unsigned int virq, unsigned int cpuid)
  753. {
  754. struct mpic *mpic = mpic_from_irq(virq);
  755. unsigned int src = mpic_irq_to_hw(virq);
  756. DBG("mpic: set_destination(mpic:@%p,virq:%d,src:%d,cpuid:0x%x)\n",
  757. mpic, virq, src, cpuid);
  758. if (src >= mpic->irq_count)
  759. return;
  760. mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION), 1 << cpuid);
  761. }
  762. static struct irq_chip mpic_irq_chip = {
  763. .irq_mask = mpic_mask_irq,
  764. .irq_unmask = mpic_unmask_irq,
  765. .irq_eoi = mpic_end_irq,
  766. .irq_set_type = mpic_set_irq_type,
  767. };
  768. #ifdef CONFIG_SMP
  769. static struct irq_chip mpic_ipi_chip = {
  770. .irq_mask = mpic_mask_ipi,
  771. .irq_unmask = mpic_unmask_ipi,
  772. .irq_eoi = mpic_end_ipi,
  773. };
  774. #endif /* CONFIG_SMP */
  775. #ifdef CONFIG_MPIC_U3_HT_IRQS
  776. static struct irq_chip mpic_irq_ht_chip = {
  777. .irq_startup = mpic_startup_ht_irq,
  778. .irq_shutdown = mpic_shutdown_ht_irq,
  779. .irq_mask = mpic_mask_irq,
  780. .irq_unmask = mpic_unmask_ht_irq,
  781. .irq_eoi = mpic_end_ht_irq,
  782. .irq_set_type = mpic_set_irq_type,
  783. };
  784. #endif /* CONFIG_MPIC_U3_HT_IRQS */
  785. static int mpic_host_match(struct irq_host *h, struct device_node *node)
  786. {
  787. /* Exact match, unless mpic node is NULL */
  788. return h->of_node == NULL || h->of_node == node;
  789. }
  790. static int mpic_host_map(struct irq_host *h, unsigned int virq,
  791. irq_hw_number_t hw)
  792. {
  793. struct mpic *mpic = h->host_data;
  794. struct irq_chip *chip;
  795. DBG("mpic: map virq %d, hwirq 0x%lx\n", virq, hw);
  796. if (hw == mpic->spurious_vec)
  797. return -EINVAL;
  798. if (mpic->protected && test_bit(hw, mpic->protected))
  799. return -EINVAL;
  800. #ifdef CONFIG_SMP
  801. else if (hw >= mpic->ipi_vecs[0]) {
  802. WARN_ON(!(mpic->flags & MPIC_PRIMARY));
  803. DBG("mpic: mapping as IPI\n");
  804. irq_set_chip_data(virq, mpic);
  805. irq_set_chip_and_handler(virq, &mpic->hc_ipi,
  806. handle_percpu_irq);
  807. return 0;
  808. }
  809. #endif /* CONFIG_SMP */
  810. if (hw >= mpic->irq_count)
  811. return -EINVAL;
  812. mpic_msi_reserve_hwirq(mpic, hw);
  813. /* Default chip */
  814. chip = &mpic->hc_irq;
  815. #ifdef CONFIG_MPIC_U3_HT_IRQS
  816. /* Check for HT interrupts, override vecpri */
  817. if (mpic_is_ht_interrupt(mpic, hw))
  818. chip = &mpic->hc_ht_irq;
  819. #endif /* CONFIG_MPIC_U3_HT_IRQS */
  820. DBG("mpic: mapping to irq chip @%p\n", chip);
  821. irq_set_chip_data(virq, mpic);
  822. irq_set_chip_and_handler(virq, chip, handle_fasteoi_irq);
  823. /* Set default irq type */
  824. irq_set_irq_type(virq, IRQ_TYPE_NONE);
  825. /* If the MPIC was reset, then all vectors have already been
  826. * initialized. Otherwise, a per source lazy initialization
  827. * is done here.
  828. */
  829. if (!mpic_is_ipi(mpic, hw) && (mpic->flags & MPIC_NO_RESET)) {
  830. mpic_set_vector(virq, hw);
  831. mpic_set_destination(virq, mpic_processor_id(mpic));
  832. mpic_irq_set_priority(virq, 8);
  833. }
  834. return 0;
  835. }
  836. static int mpic_host_xlate(struct irq_host *h, struct device_node *ct,
  837. const u32 *intspec, unsigned int intsize,
  838. irq_hw_number_t *out_hwirq, unsigned int *out_flags)
  839. {
  840. static unsigned char map_mpic_senses[4] = {
  841. IRQ_TYPE_EDGE_RISING,
  842. IRQ_TYPE_LEVEL_LOW,
  843. IRQ_TYPE_LEVEL_HIGH,
  844. IRQ_TYPE_EDGE_FALLING,
  845. };
  846. *out_hwirq = intspec[0];
  847. if (intsize > 1) {
  848. u32 mask = 0x3;
  849. /* Apple invented a new race of encoding on machines with
  850. * an HT APIC. They encode, among others, the index within
  851. * the HT APIC. We don't care about it here since thankfully,
  852. * it appears that they have the APIC already properly
  853. * configured, and thus our current fixup code that reads the
  854. * APIC config works fine. However, we still need to mask out
  855. * bits in the specifier to make sure we only get bit 0 which
  856. * is the level/edge bit (the only sense bit exposed by Apple),
  857. * as their bit 1 means something else.
  858. */
  859. if (machine_is(powermac))
  860. mask = 0x1;
  861. *out_flags = map_mpic_senses[intspec[1] & mask];
  862. } else
  863. *out_flags = IRQ_TYPE_NONE;
  864. DBG("mpic: xlate (%d cells: 0x%08x 0x%08x) to line 0x%lx sense 0x%x\n",
  865. intsize, intspec[0], intspec[1], *out_hwirq, *out_flags);
  866. return 0;
  867. }
  868. static struct irq_host_ops mpic_host_ops = {
  869. .match = mpic_host_match,
  870. .map = mpic_host_map,
  871. .xlate = mpic_host_xlate,
  872. };
  873. static int mpic_reset_prohibited(struct device_node *node)
  874. {
  875. return node && of_get_property(node, "pic-no-reset", NULL);
  876. }
  877. /*
  878. * Exported functions
  879. */
  880. struct mpic * __init mpic_alloc(struct device_node *node,
  881. phys_addr_t phys_addr,
  882. unsigned int flags,
  883. unsigned int isu_size,
  884. unsigned int irq_count,
  885. const char *name)
  886. {
  887. struct mpic *mpic;
  888. u32 greg_feature;
  889. const char *vers;
  890. int i;
  891. int intvec_top;
  892. u64 paddr = phys_addr;
  893. mpic = kzalloc(sizeof(struct mpic), GFP_KERNEL);
  894. if (mpic == NULL)
  895. return NULL;
  896. mpic->name = name;
  897. mpic->hc_irq = mpic_irq_chip;
  898. mpic->hc_irq.name = name;
  899. if (flags & MPIC_PRIMARY)
  900. mpic->hc_irq.irq_set_affinity = mpic_set_affinity;
  901. #ifdef CONFIG_MPIC_U3_HT_IRQS
  902. mpic->hc_ht_irq = mpic_irq_ht_chip;
  903. mpic->hc_ht_irq.name = name;
  904. if (flags & MPIC_PRIMARY)
  905. mpic->hc_ht_irq.irq_set_affinity = mpic_set_affinity;
  906. #endif /* CONFIG_MPIC_U3_HT_IRQS */
  907. #ifdef CONFIG_SMP
  908. mpic->hc_ipi = mpic_ipi_chip;
  909. mpic->hc_ipi.name = name;
  910. #endif /* CONFIG_SMP */
  911. mpic->flags = flags;
  912. mpic->isu_size = isu_size;
  913. mpic->irq_count = irq_count;
  914. mpic->num_sources = 0; /* so far */
  915. if (flags & MPIC_LARGE_VECTORS)
  916. intvec_top = 2047;
  917. else
  918. intvec_top = 255;
  919. mpic->timer_vecs[0] = intvec_top - 8;
  920. mpic->timer_vecs[1] = intvec_top - 7;
  921. mpic->timer_vecs[2] = intvec_top - 6;
  922. mpic->timer_vecs[3] = intvec_top - 5;
  923. mpic->ipi_vecs[0] = intvec_top - 4;
  924. mpic->ipi_vecs[1] = intvec_top - 3;
  925. mpic->ipi_vecs[2] = intvec_top - 2;
  926. mpic->ipi_vecs[3] = intvec_top - 1;
  927. mpic->spurious_vec = intvec_top;
  928. /* Check for "big-endian" in device-tree */
  929. if (node && of_get_property(node, "big-endian", NULL) != NULL)
  930. mpic->flags |= MPIC_BIG_ENDIAN;
  931. /* Look for protected sources */
  932. if (node) {
  933. int psize;
  934. unsigned int bits, mapsize;
  935. const u32 *psrc =
  936. of_get_property(node, "protected-sources", &psize);
  937. if (psrc) {
  938. psize /= 4;
  939. bits = intvec_top + 1;
  940. mapsize = BITS_TO_LONGS(bits) * sizeof(unsigned long);
  941. mpic->protected = kzalloc(mapsize, GFP_KERNEL);
  942. BUG_ON(mpic->protected == NULL);
  943. for (i = 0; i < psize; i++) {
  944. if (psrc[i] > intvec_top)
  945. continue;
  946. __set_bit(psrc[i], mpic->protected);
  947. }
  948. }
  949. }
  950. #ifdef CONFIG_MPIC_WEIRD
  951. mpic->hw_set = mpic_infos[MPIC_GET_REGSET(flags)];
  952. #endif
  953. /* default register type */
  954. mpic->reg_type = (flags & MPIC_BIG_ENDIAN) ?
  955. mpic_access_mmio_be : mpic_access_mmio_le;
  956. /* If no physical address is passed in, a device-node is mandatory */
  957. BUG_ON(paddr == 0 && node == NULL);
  958. /* If no physical address passed in, check if it's dcr based */
  959. if (paddr == 0 && of_get_property(node, "dcr-reg", NULL) != NULL) {
  960. #ifdef CONFIG_PPC_DCR
  961. mpic->flags |= MPIC_USES_DCR;
  962. mpic->reg_type = mpic_access_dcr;
  963. #else
  964. BUG();
  965. #endif /* CONFIG_PPC_DCR */
  966. }
  967. /* If the MPIC is not DCR based, and no physical address was passed
  968. * in, try to obtain one
  969. */
  970. if (paddr == 0 && !(mpic->flags & MPIC_USES_DCR)) {
  971. const u32 *reg = of_get_property(node, "reg", NULL);
  972. BUG_ON(reg == NULL);
  973. paddr = of_translate_address(node, reg);
  974. BUG_ON(paddr == OF_BAD_ADDR);
  975. }
  976. /* Map the global registers */
  977. mpic_map(mpic, node, paddr, &mpic->gregs, MPIC_INFO(GREG_BASE), 0x1000);
  978. mpic_map(mpic, node, paddr, &mpic->tmregs, MPIC_INFO(TIMER_BASE), 0x1000);
  979. /* Reset */
  980. /* When using a device-node, reset requests are only honored if the MPIC
  981. * is allowed to reset.
  982. */
  983. if (mpic_reset_prohibited(node))
  984. mpic->flags |= MPIC_NO_RESET;
  985. if ((flags & MPIC_WANTS_RESET) && !(mpic->flags & MPIC_NO_RESET)) {
  986. printk(KERN_DEBUG "mpic: Resetting\n");
  987. mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
  988. mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  989. | MPIC_GREG_GCONF_RESET);
  990. while( mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  991. & MPIC_GREG_GCONF_RESET)
  992. mb();
  993. }
  994. /* CoreInt */
  995. if (flags & MPIC_ENABLE_COREINT)
  996. mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
  997. mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  998. | MPIC_GREG_GCONF_COREINT);
  999. if (flags & MPIC_ENABLE_MCK)
  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_MCK);
  1003. /* Read feature register, calculate num CPUs and, for non-ISU
  1004. * MPICs, num sources as well. On ISU MPICs, sources are counted
  1005. * as ISUs are added
  1006. */
  1007. greg_feature = mpic_read(mpic->gregs, MPIC_INFO(GREG_FEATURE_0));
  1008. mpic->num_cpus = ((greg_feature & MPIC_GREG_FEATURE_LAST_CPU_MASK)
  1009. >> MPIC_GREG_FEATURE_LAST_CPU_SHIFT) + 1;
  1010. if (isu_size == 0) {
  1011. if (flags & MPIC_BROKEN_FRR_NIRQS)
  1012. mpic->num_sources = mpic->irq_count;
  1013. else
  1014. mpic->num_sources =
  1015. ((greg_feature & MPIC_GREG_FEATURE_LAST_SRC_MASK)
  1016. >> MPIC_GREG_FEATURE_LAST_SRC_SHIFT) + 1;
  1017. }
  1018. /* Map the per-CPU registers */
  1019. for (i = 0; i < mpic->num_cpus; i++) {
  1020. mpic_map(mpic, node, paddr, &mpic->cpuregs[i],
  1021. MPIC_INFO(CPU_BASE) + i * MPIC_INFO(CPU_STRIDE),
  1022. 0x1000);
  1023. }
  1024. /* Initialize main ISU if none provided */
  1025. if (mpic->isu_size == 0) {
  1026. mpic->isu_size = mpic->num_sources;
  1027. mpic_map(mpic, node, paddr, &mpic->isus[0],
  1028. MPIC_INFO(IRQ_BASE), MPIC_INFO(IRQ_STRIDE) * mpic->isu_size);
  1029. }
  1030. mpic->isu_shift = 1 + __ilog2(mpic->isu_size - 1);
  1031. mpic->isu_mask = (1 << mpic->isu_shift) - 1;
  1032. mpic->irqhost = irq_alloc_host(node, IRQ_HOST_MAP_LINEAR,
  1033. isu_size ? isu_size : mpic->num_sources,
  1034. &mpic_host_ops,
  1035. flags & MPIC_LARGE_VECTORS ? 2048 : 256);
  1036. if (mpic->irqhost == NULL)
  1037. return NULL;
  1038. mpic->irqhost->host_data = mpic;
  1039. /* Display version */
  1040. switch (greg_feature & MPIC_GREG_FEATURE_VERSION_MASK) {
  1041. case 1:
  1042. vers = "1.0";
  1043. break;
  1044. case 2:
  1045. vers = "1.2";
  1046. break;
  1047. case 3:
  1048. vers = "1.3";
  1049. break;
  1050. default:
  1051. vers = "<unknown>";
  1052. break;
  1053. }
  1054. printk(KERN_INFO "mpic: Setting up MPIC \"%s\" version %s at %llx,"
  1055. " max %d CPUs\n",
  1056. name, vers, (unsigned long long)paddr, mpic->num_cpus);
  1057. printk(KERN_INFO "mpic: ISU size: %d, shift: %d, mask: %x\n",
  1058. mpic->isu_size, mpic->isu_shift, mpic->isu_mask);
  1059. mpic->next = mpics;
  1060. mpics = mpic;
  1061. if (flags & MPIC_PRIMARY) {
  1062. mpic_primary = mpic;
  1063. irq_set_default_host(mpic->irqhost);
  1064. }
  1065. return mpic;
  1066. }
  1067. void __init mpic_assign_isu(struct mpic *mpic, unsigned int isu_num,
  1068. phys_addr_t paddr)
  1069. {
  1070. unsigned int isu_first = isu_num * mpic->isu_size;
  1071. BUG_ON(isu_num >= MPIC_MAX_ISU);
  1072. mpic_map(mpic, mpic->irqhost->of_node,
  1073. paddr, &mpic->isus[isu_num], 0,
  1074. MPIC_INFO(IRQ_STRIDE) * mpic->isu_size);
  1075. if ((isu_first + mpic->isu_size) > mpic->num_sources)
  1076. mpic->num_sources = isu_first + mpic->isu_size;
  1077. }
  1078. void __init mpic_set_default_senses(struct mpic *mpic, u8 *senses, int count)
  1079. {
  1080. mpic->senses = senses;
  1081. mpic->senses_count = count;
  1082. }
  1083. void __init mpic_init(struct mpic *mpic)
  1084. {
  1085. int i;
  1086. int cpu;
  1087. BUG_ON(mpic->num_sources == 0);
  1088. printk(KERN_INFO "mpic: Initializing for %d sources\n", mpic->num_sources);
  1089. /* Set current processor priority to max */
  1090. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0xf);
  1091. /* Initialize timers: just disable them all */
  1092. for (i = 0; i < 4; i++) {
  1093. mpic_write(mpic->tmregs,
  1094. i * MPIC_INFO(TIMER_STRIDE) +
  1095. MPIC_INFO(TIMER_DESTINATION), 0);
  1096. mpic_write(mpic->tmregs,
  1097. i * MPIC_INFO(TIMER_STRIDE) +
  1098. MPIC_INFO(TIMER_VECTOR_PRI),
  1099. MPIC_VECPRI_MASK |
  1100. (mpic->timer_vecs[0] + i));
  1101. }
  1102. /* Initialize IPIs to our reserved vectors and mark them disabled for now */
  1103. mpic_test_broken_ipi(mpic);
  1104. for (i = 0; i < 4; i++) {
  1105. mpic_ipi_write(i,
  1106. MPIC_VECPRI_MASK |
  1107. (10 << MPIC_VECPRI_PRIORITY_SHIFT) |
  1108. (mpic->ipi_vecs[0] + i));
  1109. }
  1110. /* Initialize interrupt sources */
  1111. if (mpic->irq_count == 0)
  1112. mpic->irq_count = mpic->num_sources;
  1113. /* Do the HT PIC fixups on U3 broken mpic */
  1114. DBG("MPIC flags: %x\n", mpic->flags);
  1115. if ((mpic->flags & MPIC_U3_HT_IRQS) && (mpic->flags & MPIC_PRIMARY)) {
  1116. mpic_scan_ht_pics(mpic);
  1117. mpic_u3msi_init(mpic);
  1118. }
  1119. mpic_pasemi_msi_init(mpic);
  1120. cpu = mpic_processor_id(mpic);
  1121. if (!(mpic->flags & MPIC_NO_RESET)) {
  1122. for (i = 0; i < mpic->num_sources; i++) {
  1123. /* start with vector = source number, and masked */
  1124. u32 vecpri = MPIC_VECPRI_MASK | i |
  1125. (8 << MPIC_VECPRI_PRIORITY_SHIFT);
  1126. /* check if protected */
  1127. if (mpic->protected && test_bit(i, mpic->protected))
  1128. continue;
  1129. /* init hw */
  1130. mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI), vecpri);
  1131. mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION), 1 << cpu);
  1132. }
  1133. }
  1134. /* Init spurious vector */
  1135. mpic_write(mpic->gregs, MPIC_INFO(GREG_SPURIOUS), mpic->spurious_vec);
  1136. /* Disable 8259 passthrough, if supported */
  1137. if (!(mpic->flags & MPIC_NO_PTHROU_DIS))
  1138. mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
  1139. mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
  1140. | MPIC_GREG_GCONF_8259_PTHROU_DIS);
  1141. if (mpic->flags & MPIC_NO_BIAS)
  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_NO_BIAS);
  1145. /* Set current processor priority to 0 */
  1146. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0);
  1147. #ifdef CONFIG_PM
  1148. /* allocate memory to save mpic state */
  1149. mpic->save_data = kmalloc(mpic->num_sources * sizeof(*mpic->save_data),
  1150. GFP_KERNEL);
  1151. BUG_ON(mpic->save_data == NULL);
  1152. #endif
  1153. }
  1154. void __init mpic_set_clk_ratio(struct mpic *mpic, u32 clock_ratio)
  1155. {
  1156. u32 v;
  1157. v = mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1);
  1158. v &= ~MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO_MASK;
  1159. v |= MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO(clock_ratio);
  1160. mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v);
  1161. }
  1162. void __init mpic_set_serial_int(struct mpic *mpic, int enable)
  1163. {
  1164. unsigned long flags;
  1165. u32 v;
  1166. raw_spin_lock_irqsave(&mpic_lock, flags);
  1167. v = mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1);
  1168. if (enable)
  1169. v |= MPIC_GREG_GLOBAL_CONF_1_SIE;
  1170. else
  1171. v &= ~MPIC_GREG_GLOBAL_CONF_1_SIE;
  1172. mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v);
  1173. raw_spin_unlock_irqrestore(&mpic_lock, flags);
  1174. }
  1175. void mpic_irq_set_priority(unsigned int irq, unsigned int pri)
  1176. {
  1177. struct mpic *mpic = mpic_find(irq);
  1178. unsigned int src = mpic_irq_to_hw(irq);
  1179. unsigned long flags;
  1180. u32 reg;
  1181. if (!mpic)
  1182. return;
  1183. raw_spin_lock_irqsave(&mpic_lock, flags);
  1184. if (mpic_is_ipi(mpic, irq)) {
  1185. reg = mpic_ipi_read(src - mpic->ipi_vecs[0]) &
  1186. ~MPIC_VECPRI_PRIORITY_MASK;
  1187. mpic_ipi_write(src - mpic->ipi_vecs[0],
  1188. reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
  1189. } else {
  1190. reg = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI))
  1191. & ~MPIC_VECPRI_PRIORITY_MASK;
  1192. mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI),
  1193. reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
  1194. }
  1195. raw_spin_unlock_irqrestore(&mpic_lock, flags);
  1196. }
  1197. void mpic_setup_this_cpu(void)
  1198. {
  1199. #ifdef CONFIG_SMP
  1200. struct mpic *mpic = mpic_primary;
  1201. unsigned long flags;
  1202. u32 msk = 1 << hard_smp_processor_id();
  1203. unsigned int i;
  1204. BUG_ON(mpic == NULL);
  1205. DBG("%s: setup_this_cpu(%d)\n", mpic->name, hard_smp_processor_id());
  1206. raw_spin_lock_irqsave(&mpic_lock, flags);
  1207. /* let the mpic know we want intrs. default affinity is 0xffffffff
  1208. * until changed via /proc. That's how it's done on x86. If we want
  1209. * it differently, then we should make sure we also change the default
  1210. * values of irq_desc[].affinity in irq.c.
  1211. */
  1212. if (distribute_irqs) {
  1213. for (i = 0; i < mpic->num_sources ; i++)
  1214. mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION),
  1215. mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION)) | msk);
  1216. }
  1217. /* Set current processor priority to 0 */
  1218. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0);
  1219. raw_spin_unlock_irqrestore(&mpic_lock, flags);
  1220. #endif /* CONFIG_SMP */
  1221. }
  1222. int mpic_cpu_get_priority(void)
  1223. {
  1224. struct mpic *mpic = mpic_primary;
  1225. return mpic_cpu_read(MPIC_INFO(CPU_CURRENT_TASK_PRI));
  1226. }
  1227. void mpic_cpu_set_priority(int prio)
  1228. {
  1229. struct mpic *mpic = mpic_primary;
  1230. prio &= MPIC_CPU_TASKPRI_MASK;
  1231. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), prio);
  1232. }
  1233. void mpic_teardown_this_cpu(int secondary)
  1234. {
  1235. struct mpic *mpic = mpic_primary;
  1236. unsigned long flags;
  1237. u32 msk = 1 << hard_smp_processor_id();
  1238. unsigned int i;
  1239. BUG_ON(mpic == NULL);
  1240. DBG("%s: teardown_this_cpu(%d)\n", mpic->name, hard_smp_processor_id());
  1241. raw_spin_lock_irqsave(&mpic_lock, flags);
  1242. /* let the mpic know we don't want intrs. */
  1243. for (i = 0; i < mpic->num_sources ; i++)
  1244. mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION),
  1245. mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION)) & ~msk);
  1246. /* Set current processor priority to max */
  1247. mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0xf);
  1248. /* We need to EOI the IPI since not all platforms reset the MPIC
  1249. * on boot and new interrupts wouldn't get delivered otherwise.
  1250. */
  1251. mpic_eoi(mpic);
  1252. raw_spin_unlock_irqrestore(&mpic_lock, flags);
  1253. }
  1254. static unsigned int _mpic_get_one_irq(struct mpic *mpic, int reg)
  1255. {
  1256. u32 src;
  1257. src = mpic_cpu_read(reg) & MPIC_INFO(VECPRI_VECTOR_MASK);
  1258. #ifdef DEBUG_LOW
  1259. DBG("%s: get_one_irq(reg 0x%x): %d\n", mpic->name, reg, src);
  1260. #endif
  1261. if (unlikely(src == mpic->spurious_vec)) {
  1262. if (mpic->flags & MPIC_SPV_EOI)
  1263. mpic_eoi(mpic);
  1264. return NO_IRQ;
  1265. }
  1266. if (unlikely(mpic->protected && test_bit(src, mpic->protected))) {
  1267. if (printk_ratelimit())
  1268. printk(KERN_WARNING "%s: Got protected source %d !\n",
  1269. mpic->name, (int)src);
  1270. mpic_eoi(mpic);
  1271. return NO_IRQ;
  1272. }
  1273. return irq_linear_revmap(mpic->irqhost, src);
  1274. }
  1275. unsigned int mpic_get_one_irq(struct mpic *mpic)
  1276. {
  1277. return _mpic_get_one_irq(mpic, MPIC_INFO(CPU_INTACK));
  1278. }
  1279. unsigned int mpic_get_irq(void)
  1280. {
  1281. struct mpic *mpic = mpic_primary;
  1282. BUG_ON(mpic == NULL);
  1283. return mpic_get_one_irq(mpic);
  1284. }
  1285. unsigned int mpic_get_coreint_irq(void)
  1286. {
  1287. #ifdef CONFIG_BOOKE
  1288. struct mpic *mpic = mpic_primary;
  1289. u32 src;
  1290. BUG_ON(mpic == NULL);
  1291. src = mfspr(SPRN_EPR);
  1292. if (unlikely(src == mpic->spurious_vec)) {
  1293. if (mpic->flags & MPIC_SPV_EOI)
  1294. mpic_eoi(mpic);
  1295. return NO_IRQ;
  1296. }
  1297. if (unlikely(mpic->protected && test_bit(src, mpic->protected))) {
  1298. if (printk_ratelimit())
  1299. printk(KERN_WARNING "%s: Got protected source %d !\n",
  1300. mpic->name, (int)src);
  1301. return NO_IRQ;
  1302. }
  1303. return irq_linear_revmap(mpic->irqhost, src);
  1304. #else
  1305. return NO_IRQ;
  1306. #endif
  1307. }
  1308. unsigned int mpic_get_mcirq(void)
  1309. {
  1310. struct mpic *mpic = mpic_primary;
  1311. BUG_ON(mpic == NULL);
  1312. return _mpic_get_one_irq(mpic, MPIC_INFO(CPU_MCACK));
  1313. }
  1314. #ifdef CONFIG_SMP
  1315. void mpic_request_ipis(void)
  1316. {
  1317. struct mpic *mpic = mpic_primary;
  1318. int i;
  1319. BUG_ON(mpic == NULL);
  1320. printk(KERN_INFO "mpic: requesting IPIs...\n");
  1321. for (i = 0; i < 4; i++) {
  1322. unsigned int vipi = irq_create_mapping(mpic->irqhost,
  1323. mpic->ipi_vecs[0] + i);
  1324. if (vipi == NO_IRQ) {
  1325. printk(KERN_ERR "Failed to map %s\n", smp_ipi_name[i]);
  1326. continue;
  1327. }
  1328. smp_request_message_ipi(vipi, i);
  1329. }
  1330. }
  1331. static void mpic_send_ipi(unsigned int ipi_no, const struct cpumask *cpu_mask)
  1332. {
  1333. struct mpic *mpic = mpic_primary;
  1334. BUG_ON(mpic == NULL);
  1335. #ifdef DEBUG_IPI
  1336. DBG("%s: send_ipi(ipi_no: %d)\n", mpic->name, ipi_no);
  1337. #endif
  1338. mpic_cpu_write(MPIC_INFO(CPU_IPI_DISPATCH_0) +
  1339. ipi_no * MPIC_INFO(CPU_IPI_DISPATCH_STRIDE),
  1340. mpic_physmask(cpumask_bits(cpu_mask)[0]));
  1341. }
  1342. void smp_mpic_message_pass(int target, int msg)
  1343. {
  1344. cpumask_var_t tmp;
  1345. /* make sure we're sending something that translates to an IPI */
  1346. if ((unsigned int)msg > 3) {
  1347. printk("SMP %d: smp_message_pass: unknown msg %d\n",
  1348. smp_processor_id(), msg);
  1349. return;
  1350. }
  1351. switch (target) {
  1352. case MSG_ALL:
  1353. mpic_send_ipi(msg, cpu_online_mask);
  1354. break;
  1355. case MSG_ALL_BUT_SELF:
  1356. alloc_cpumask_var(&tmp, GFP_NOWAIT);
  1357. cpumask_andnot(tmp, cpu_online_mask,
  1358. cpumask_of(smp_processor_id()));
  1359. mpic_send_ipi(msg, tmp);
  1360. free_cpumask_var(tmp);
  1361. break;
  1362. default:
  1363. mpic_send_ipi(msg, cpumask_of(target));
  1364. break;
  1365. }
  1366. }
  1367. int __init smp_mpic_probe(void)
  1368. {
  1369. int nr_cpus;
  1370. DBG("smp_mpic_probe()...\n");
  1371. nr_cpus = cpumask_weight(cpu_possible_mask);
  1372. DBG("nr_cpus: %d\n", nr_cpus);
  1373. if (nr_cpus > 1)
  1374. mpic_request_ipis();
  1375. return nr_cpus;
  1376. }
  1377. void __devinit smp_mpic_setup_cpu(int cpu)
  1378. {
  1379. mpic_setup_this_cpu();
  1380. }
  1381. void mpic_reset_core(int cpu)
  1382. {
  1383. struct mpic *mpic = mpic_primary;
  1384. u32 pir;
  1385. int cpuid = get_hard_smp_processor_id(cpu);
  1386. /* Set target bit for core reset */
  1387. pir = mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
  1388. pir |= (1 << cpuid);
  1389. mpic_write(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT), pir);
  1390. mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
  1391. /* Restore target bit after reset complete */
  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. }
  1396. #endif /* CONFIG_SMP */
  1397. #ifdef CONFIG_PM
  1398. static void mpic_suspend_one(struct mpic *mpic)
  1399. {
  1400. int i;
  1401. for (i = 0; i < mpic->num_sources; i++) {
  1402. mpic->save_data[i].vecprio =
  1403. mpic_irq_read(i, MPIC_INFO(IRQ_VECTOR_PRI));
  1404. mpic->save_data[i].dest =
  1405. mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION));
  1406. }
  1407. }
  1408. static int mpic_suspend(void)
  1409. {
  1410. struct mpic *mpic = mpics;
  1411. while (mpic) {
  1412. mpic_suspend_one(mpic);
  1413. mpic = mpic->next;
  1414. }
  1415. return 0;
  1416. }
  1417. static void mpic_resume_one(struct mpic *mpic)
  1418. {
  1419. int i;
  1420. for (i = 0; i < mpic->num_sources; i++) {
  1421. mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI),
  1422. mpic->save_data[i].vecprio);
  1423. mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION),
  1424. mpic->save_data[i].dest);
  1425. #ifdef CONFIG_MPIC_U3_HT_IRQS
  1426. if (mpic->fixups) {
  1427. struct mpic_irq_fixup *fixup = &mpic->fixups[i];
  1428. if (fixup->base) {
  1429. /* we use the lowest bit in an inverted meaning */
  1430. if ((mpic->save_data[i].fixup_data & 1) == 0)
  1431. continue;
  1432. /* Enable and configure */
  1433. writeb(0x10 + 2 * fixup->index, fixup->base + 2);
  1434. writel(mpic->save_data[i].fixup_data & ~1,
  1435. fixup->base + 4);
  1436. }
  1437. }
  1438. #endif
  1439. } /* end for loop */
  1440. }
  1441. static void mpic_resume(void)
  1442. {
  1443. struct mpic *mpic = mpics;
  1444. while (mpic) {
  1445. mpic_resume_one(mpic);
  1446. mpic = mpic->next;
  1447. }
  1448. }
  1449. static struct syscore_ops mpic_syscore_ops = {
  1450. .resume = mpic_resume,
  1451. .suspend = mpic_suspend,
  1452. };
  1453. static int mpic_init_sys(void)
  1454. {
  1455. register_syscore_ops(&mpic_syscore_ops);
  1456. return 0;
  1457. }
  1458. device_initcall(mpic_init_sys);
  1459. #endif