mpic.c 44 KB

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