mpic.c 42 KB

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