mpic.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. #ifndef _ASM_POWERPC_MPIC_H
  2. #define _ASM_POWERPC_MPIC_H
  3. #ifdef __KERNEL__
  4. #include <linux/irq.h>
  5. #include <asm/dcr.h>
  6. #include <asm/msi_bitmap.h>
  7. /*
  8. * Global registers
  9. */
  10. #define MPIC_GREG_BASE 0x01000
  11. #define MPIC_GREG_FEATURE_0 0x00000
  12. #define MPIC_GREG_FEATURE_LAST_SRC_MASK 0x07ff0000
  13. #define MPIC_GREG_FEATURE_LAST_SRC_SHIFT 16
  14. #define MPIC_GREG_FEATURE_LAST_CPU_MASK 0x00001f00
  15. #define MPIC_GREG_FEATURE_LAST_CPU_SHIFT 8
  16. #define MPIC_GREG_FEATURE_VERSION_MASK 0xff
  17. #define MPIC_GREG_FEATURE_1 0x00010
  18. #define MPIC_GREG_GLOBAL_CONF_0 0x00020
  19. #define MPIC_GREG_GCONF_RESET 0x80000000
  20. /* On the FSL mpic implementations the Mode field is expand to be
  21. * 2 bits wide:
  22. * 0b00 = pass through (interrupts routed to IRQ0)
  23. * 0b01 = Mixed mode
  24. * 0b10 = reserved
  25. * 0b11 = External proxy / coreint
  26. */
  27. #define MPIC_GREG_GCONF_COREINT 0x60000000
  28. #define MPIC_GREG_GCONF_8259_PTHROU_DIS 0x20000000
  29. #define MPIC_GREG_GCONF_NO_BIAS 0x10000000
  30. #define MPIC_GREG_GCONF_BASE_MASK 0x000fffff
  31. #define MPIC_GREG_GCONF_MCK 0x08000000
  32. #define MPIC_GREG_GLOBAL_CONF_1 0x00030
  33. #define MPIC_GREG_GLOBAL_CONF_1_SIE 0x08000000
  34. #define MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO_MASK 0x70000000
  35. #define MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO(r) \
  36. (((r) << 28) & MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO_MASK)
  37. #define MPIC_GREG_VENDOR_0 0x00040
  38. #define MPIC_GREG_VENDOR_1 0x00050
  39. #define MPIC_GREG_VENDOR_2 0x00060
  40. #define MPIC_GREG_VENDOR_3 0x00070
  41. #define MPIC_GREG_VENDOR_ID 0x00080
  42. #define MPIC_GREG_VENDOR_ID_STEPPING_MASK 0x00ff0000
  43. #define MPIC_GREG_VENDOR_ID_STEPPING_SHIFT 16
  44. #define MPIC_GREG_VENDOR_ID_DEVICE_ID_MASK 0x0000ff00
  45. #define MPIC_GREG_VENDOR_ID_DEVICE_ID_SHIFT 8
  46. #define MPIC_GREG_VENDOR_ID_VENDOR_ID_MASK 0x000000ff
  47. #define MPIC_GREG_PROCESSOR_INIT 0x00090
  48. #define MPIC_GREG_IPI_VECTOR_PRI_0 0x000a0
  49. #define MPIC_GREG_IPI_VECTOR_PRI_1 0x000b0
  50. #define MPIC_GREG_IPI_VECTOR_PRI_2 0x000c0
  51. #define MPIC_GREG_IPI_VECTOR_PRI_3 0x000d0
  52. #define MPIC_GREG_IPI_STRIDE 0x10
  53. #define MPIC_GREG_SPURIOUS 0x000e0
  54. #define MPIC_GREG_TIMER_FREQ 0x000f0
  55. /*
  56. *
  57. * Timer registers
  58. */
  59. #define MPIC_TIMER_BASE 0x01100
  60. #define MPIC_TIMER_STRIDE 0x40
  61. #define MPIC_TIMER_CURRENT_CNT 0x00000
  62. #define MPIC_TIMER_BASE_CNT 0x00010
  63. #define MPIC_TIMER_VECTOR_PRI 0x00020
  64. #define MPIC_TIMER_DESTINATION 0x00030
  65. /*
  66. * Per-Processor registers
  67. */
  68. #define MPIC_CPU_THISBASE 0x00000
  69. #define MPIC_CPU_BASE 0x20000
  70. #define MPIC_CPU_STRIDE 0x01000
  71. #define MPIC_CPU_IPI_DISPATCH_0 0x00040
  72. #define MPIC_CPU_IPI_DISPATCH_1 0x00050
  73. #define MPIC_CPU_IPI_DISPATCH_2 0x00060
  74. #define MPIC_CPU_IPI_DISPATCH_3 0x00070
  75. #define MPIC_CPU_IPI_DISPATCH_STRIDE 0x00010
  76. #define MPIC_CPU_CURRENT_TASK_PRI 0x00080
  77. #define MPIC_CPU_TASKPRI_MASK 0x0000000f
  78. #define MPIC_CPU_WHOAMI 0x00090
  79. #define MPIC_CPU_WHOAMI_MASK 0x0000001f
  80. #define MPIC_CPU_INTACK 0x000a0
  81. #define MPIC_CPU_EOI 0x000b0
  82. #define MPIC_CPU_MCACK 0x000c0
  83. /*
  84. * Per-source registers
  85. */
  86. #define MPIC_IRQ_BASE 0x10000
  87. #define MPIC_IRQ_STRIDE 0x00020
  88. #define MPIC_IRQ_VECTOR_PRI 0x00000
  89. #define MPIC_VECPRI_MASK 0x80000000
  90. #define MPIC_VECPRI_ACTIVITY 0x40000000 /* Read Only */
  91. #define MPIC_VECPRI_PRIORITY_MASK 0x000f0000
  92. #define MPIC_VECPRI_PRIORITY_SHIFT 16
  93. #define MPIC_VECPRI_VECTOR_MASK 0x000007ff
  94. #define MPIC_VECPRI_POLARITY_POSITIVE 0x00800000
  95. #define MPIC_VECPRI_POLARITY_NEGATIVE 0x00000000
  96. #define MPIC_VECPRI_POLARITY_MASK 0x00800000
  97. #define MPIC_VECPRI_SENSE_LEVEL 0x00400000
  98. #define MPIC_VECPRI_SENSE_EDGE 0x00000000
  99. #define MPIC_VECPRI_SENSE_MASK 0x00400000
  100. #define MPIC_IRQ_DESTINATION 0x00010
  101. #define MPIC_MAX_IRQ_SOURCES 2048
  102. #define MPIC_MAX_CPUS 32
  103. #define MPIC_MAX_ISU 32
  104. /*
  105. * Tsi108 implementation of MPIC has many differences from the original one
  106. */
  107. /*
  108. * Global registers
  109. */
  110. #define TSI108_GREG_BASE 0x00000
  111. #define TSI108_GREG_FEATURE_0 0x00000
  112. #define TSI108_GREG_GLOBAL_CONF_0 0x00004
  113. #define TSI108_GREG_VENDOR_ID 0x0000c
  114. #define TSI108_GREG_IPI_VECTOR_PRI_0 0x00204 /* Doorbell 0 */
  115. #define TSI108_GREG_IPI_STRIDE 0x0c
  116. #define TSI108_GREG_SPURIOUS 0x00010
  117. #define TSI108_GREG_TIMER_FREQ 0x00014
  118. /*
  119. * Timer registers
  120. */
  121. #define TSI108_TIMER_BASE 0x0030
  122. #define TSI108_TIMER_STRIDE 0x10
  123. #define TSI108_TIMER_CURRENT_CNT 0x00000
  124. #define TSI108_TIMER_BASE_CNT 0x00004
  125. #define TSI108_TIMER_VECTOR_PRI 0x00008
  126. #define TSI108_TIMER_DESTINATION 0x0000c
  127. /*
  128. * Per-Processor registers
  129. */
  130. #define TSI108_CPU_BASE 0x00300
  131. #define TSI108_CPU_STRIDE 0x00040
  132. #define TSI108_CPU_IPI_DISPATCH_0 0x00200
  133. #define TSI108_CPU_IPI_DISPATCH_STRIDE 0x00000
  134. #define TSI108_CPU_CURRENT_TASK_PRI 0x00000
  135. #define TSI108_CPU_WHOAMI 0xffffffff
  136. #define TSI108_CPU_INTACK 0x00004
  137. #define TSI108_CPU_EOI 0x00008
  138. #define TSI108_CPU_MCACK 0x00004 /* Doesn't really exist here */
  139. /*
  140. * Per-source registers
  141. */
  142. #define TSI108_IRQ_BASE 0x00100
  143. #define TSI108_IRQ_STRIDE 0x00008
  144. #define TSI108_IRQ_VECTOR_PRI 0x00000
  145. #define TSI108_VECPRI_VECTOR_MASK 0x000000ff
  146. #define TSI108_VECPRI_POLARITY_POSITIVE 0x01000000
  147. #define TSI108_VECPRI_POLARITY_NEGATIVE 0x00000000
  148. #define TSI108_VECPRI_SENSE_LEVEL 0x02000000
  149. #define TSI108_VECPRI_SENSE_EDGE 0x00000000
  150. #define TSI108_VECPRI_POLARITY_MASK 0x01000000
  151. #define TSI108_VECPRI_SENSE_MASK 0x02000000
  152. #define TSI108_IRQ_DESTINATION 0x00004
  153. /* weird mpic register indices and mask bits in the HW info array */
  154. enum {
  155. MPIC_IDX_GREG_BASE = 0,
  156. MPIC_IDX_GREG_FEATURE_0,
  157. MPIC_IDX_GREG_GLOBAL_CONF_0,
  158. MPIC_IDX_GREG_VENDOR_ID,
  159. MPIC_IDX_GREG_IPI_VECTOR_PRI_0,
  160. MPIC_IDX_GREG_IPI_STRIDE,
  161. MPIC_IDX_GREG_SPURIOUS,
  162. MPIC_IDX_GREG_TIMER_FREQ,
  163. MPIC_IDX_TIMER_BASE,
  164. MPIC_IDX_TIMER_STRIDE,
  165. MPIC_IDX_TIMER_CURRENT_CNT,
  166. MPIC_IDX_TIMER_BASE_CNT,
  167. MPIC_IDX_TIMER_VECTOR_PRI,
  168. MPIC_IDX_TIMER_DESTINATION,
  169. MPIC_IDX_CPU_BASE,
  170. MPIC_IDX_CPU_STRIDE,
  171. MPIC_IDX_CPU_IPI_DISPATCH_0,
  172. MPIC_IDX_CPU_IPI_DISPATCH_STRIDE,
  173. MPIC_IDX_CPU_CURRENT_TASK_PRI,
  174. MPIC_IDX_CPU_WHOAMI,
  175. MPIC_IDX_CPU_INTACK,
  176. MPIC_IDX_CPU_EOI,
  177. MPIC_IDX_CPU_MCACK,
  178. MPIC_IDX_IRQ_BASE,
  179. MPIC_IDX_IRQ_STRIDE,
  180. MPIC_IDX_IRQ_VECTOR_PRI,
  181. MPIC_IDX_VECPRI_VECTOR_MASK,
  182. MPIC_IDX_VECPRI_POLARITY_POSITIVE,
  183. MPIC_IDX_VECPRI_POLARITY_NEGATIVE,
  184. MPIC_IDX_VECPRI_SENSE_LEVEL,
  185. MPIC_IDX_VECPRI_SENSE_EDGE,
  186. MPIC_IDX_VECPRI_POLARITY_MASK,
  187. MPIC_IDX_VECPRI_SENSE_MASK,
  188. MPIC_IDX_IRQ_DESTINATION,
  189. MPIC_IDX_END
  190. };
  191. #ifdef CONFIG_MPIC_U3_HT_IRQS
  192. /* Fixup table entry */
  193. struct mpic_irq_fixup
  194. {
  195. u8 __iomem *base;
  196. u8 __iomem *applebase;
  197. u32 data;
  198. unsigned int index;
  199. };
  200. #endif /* CONFIG_MPIC_U3_HT_IRQS */
  201. enum mpic_reg_type {
  202. mpic_access_mmio_le,
  203. mpic_access_mmio_be,
  204. #ifdef CONFIG_PPC_DCR
  205. mpic_access_dcr
  206. #endif
  207. };
  208. struct mpic_reg_bank {
  209. u32 __iomem *base;
  210. #ifdef CONFIG_PPC_DCR
  211. dcr_host_t dhost;
  212. #endif /* CONFIG_PPC_DCR */
  213. };
  214. struct mpic_irq_save {
  215. u32 vecprio,
  216. dest;
  217. #ifdef CONFIG_MPIC_U3_HT_IRQS
  218. u32 fixup_data;
  219. #endif
  220. };
  221. /* The instance data of a given MPIC */
  222. struct mpic
  223. {
  224. /* The OpenFirmware dt node for this MPIC */
  225. struct device_node *node;
  226. /* The remapper for this MPIC */
  227. struct irq_host *irqhost;
  228. /* The "linux" controller struct */
  229. struct irq_chip hc_irq;
  230. #ifdef CONFIG_MPIC_U3_HT_IRQS
  231. struct irq_chip hc_ht_irq;
  232. #endif
  233. #ifdef CONFIG_SMP
  234. struct irq_chip hc_ipi;
  235. #endif
  236. struct irq_chip hc_tm;
  237. const char *name;
  238. /* Flags */
  239. unsigned int flags;
  240. /* How many irq sources in a given ISU */
  241. unsigned int isu_size;
  242. unsigned int isu_shift;
  243. unsigned int isu_mask;
  244. unsigned int irq_count;
  245. /* Number of sources */
  246. unsigned int num_sources;
  247. /* default senses array */
  248. unsigned char *senses;
  249. unsigned int senses_count;
  250. /* vector numbers used for internal sources (ipi/timers) */
  251. unsigned int ipi_vecs[4];
  252. unsigned int timer_vecs[8];
  253. /* Spurious vector to program into unused sources */
  254. unsigned int spurious_vec;
  255. #ifdef CONFIG_MPIC_U3_HT_IRQS
  256. /* The fixup table */
  257. struct mpic_irq_fixup *fixups;
  258. raw_spinlock_t fixup_lock;
  259. #endif
  260. /* Register access method */
  261. enum mpic_reg_type reg_type;
  262. /* The physical base address of the MPIC */
  263. phys_addr_t paddr;
  264. /* The various ioremap'ed bases */
  265. struct mpic_reg_bank gregs;
  266. struct mpic_reg_bank tmregs;
  267. struct mpic_reg_bank cpuregs[MPIC_MAX_CPUS];
  268. struct mpic_reg_bank isus[MPIC_MAX_ISU];
  269. /* Protected sources */
  270. unsigned long *protected;
  271. #ifdef CONFIG_MPIC_WEIRD
  272. /* Pointer to HW info array */
  273. u32 *hw_set;
  274. #endif
  275. #ifdef CONFIG_PCI_MSI
  276. struct msi_bitmap msi_bitmap;
  277. #endif
  278. #ifdef CONFIG_MPIC_BROKEN_REGREAD
  279. u32 isu_reg0_shadow[MPIC_MAX_IRQ_SOURCES];
  280. #endif
  281. /* link */
  282. struct mpic *next;
  283. #ifdef CONFIG_PM
  284. struct mpic_irq_save *save_data;
  285. #endif
  286. };
  287. /*
  288. * MPIC flags (passed to mpic_alloc)
  289. *
  290. * The top 4 bits contain an MPIC bhw id that is used to index the
  291. * register offsets and some masks when CONFIG_MPIC_WEIRD is set.
  292. * Note setting any ID (leaving those bits to 0) means standard MPIC
  293. */
  294. /*
  295. * This is a secondary ("chained") controller; it only uses the CPU0
  296. * registers. Primary controllers have IPIs and affinity control.
  297. */
  298. #define MPIC_SECONDARY 0x00000001
  299. /* Set this for a big-endian MPIC */
  300. #define MPIC_BIG_ENDIAN 0x00000002
  301. /* Broken U3 MPIC */
  302. #define MPIC_U3_HT_IRQS 0x00000004
  303. /* Broken IPI registers (autodetected) */
  304. #define MPIC_BROKEN_IPI 0x00000008
  305. /* MPIC wants a reset */
  306. #define MPIC_WANTS_RESET 0x00000010
  307. /* Spurious vector requires EOI */
  308. #define MPIC_SPV_EOI 0x00000020
  309. /* No passthrough disable */
  310. #define MPIC_NO_PTHROU_DIS 0x00000040
  311. /* DCR based MPIC */
  312. #define MPIC_USES_DCR 0x00000080
  313. /* MPIC has 11-bit vector fields (or larger) */
  314. #define MPIC_LARGE_VECTORS 0x00000100
  315. /* Enable delivery of prio 15 interrupts as MCK instead of EE */
  316. #define MPIC_ENABLE_MCK 0x00000200
  317. /* Disable bias among target selection, spread interrupts evenly */
  318. #define MPIC_NO_BIAS 0x00000400
  319. /* Ignore NIRQS as reported by FRR */
  320. #define MPIC_BROKEN_FRR_NIRQS 0x00000800
  321. /* Destination only supports a single CPU at a time */
  322. #define MPIC_SINGLE_DEST_CPU 0x00001000
  323. /* Enable CoreInt delivery of interrupts */
  324. #define MPIC_ENABLE_COREINT 0x00002000
  325. /* Disable resetting of the MPIC.
  326. * NOTE: This flag trumps MPIC_WANTS_RESET.
  327. */
  328. #define MPIC_NO_RESET 0x00004000
  329. /* Freescale MPIC (compatible includes "fsl,mpic") */
  330. #define MPIC_FSL 0x00008000
  331. /* MPIC HW modification ID */
  332. #define MPIC_REGSET_MASK 0xf0000000
  333. #define MPIC_REGSET(val) (((val) & 0xf ) << 28)
  334. #define MPIC_GET_REGSET(flags) (((flags) >> 28) & 0xf)
  335. #define MPIC_REGSET_STANDARD MPIC_REGSET(0) /* Original MPIC */
  336. #define MPIC_REGSET_TSI108 MPIC_REGSET(1) /* Tsi108/109 PIC */
  337. /* Allocate the controller structure and setup the linux irq descs
  338. * for the range if interrupts passed in. No HW initialization is
  339. * actually performed.
  340. *
  341. * @phys_addr: physial base address of the MPIC
  342. * @flags: flags, see constants above
  343. * @isu_size: number of interrupts in an ISU. Use 0 to use a
  344. * standard ISU-less setup (aka powermac)
  345. * @irq_offset: first irq number to assign to this mpic
  346. * @irq_count: number of irqs to use with this mpic IRQ sources. Pass 0
  347. * to match the number of sources
  348. * @ipi_offset: first irq number to assign to this mpic IPI sources,
  349. * used only on primary mpic
  350. * @senses: array of sense values
  351. * @senses_num: number of entries in the array
  352. *
  353. * Note about the sense array. If none is passed, all interrupts are
  354. * setup to be level negative unless MPIC_U3_HT_IRQS is set in which
  355. * case they are edge positive (and the array is ignored anyway).
  356. * The values in the array start at the first source of the MPIC,
  357. * that is senses[0] correspond to linux irq "irq_offset".
  358. */
  359. extern struct mpic *mpic_alloc(struct device_node *node,
  360. phys_addr_t phys_addr,
  361. unsigned int flags,
  362. unsigned int isu_size,
  363. unsigned int irq_count,
  364. const char *name);
  365. /* Assign ISUs, to call before mpic_init()
  366. *
  367. * @mpic: controller structure as returned by mpic_alloc()
  368. * @isu_num: ISU number
  369. * @phys_addr: physical address of the ISU
  370. */
  371. extern void mpic_assign_isu(struct mpic *mpic, unsigned int isu_num,
  372. phys_addr_t phys_addr);
  373. /* Set default sense codes
  374. *
  375. * @mpic: controller
  376. * @senses: array of sense codes
  377. * @count: size of above array
  378. *
  379. * Optionally provide an array (indexed on hardware interrupt numbers
  380. * for this MPIC) of default sense codes for the chip. Those are linux
  381. * sense codes IRQ_TYPE_*
  382. *
  383. * The driver gets ownership of the pointer, don't dispose of it or
  384. * anything like that. __init only.
  385. */
  386. extern void mpic_set_default_senses(struct mpic *mpic, u8 *senses, int count);
  387. /* Initialize the controller. After this has been called, none of the above
  388. * should be called again for this mpic
  389. */
  390. extern void mpic_init(struct mpic *mpic);
  391. /*
  392. * All of the following functions must only be used after the
  393. * ISUs have been assigned and the controller fully initialized
  394. * with mpic_init()
  395. */
  396. /* Change the priority of an interrupt. Default is 8 for irqs and
  397. * 10 for IPIs. You can call this on both IPIs and IRQ numbers, but the
  398. * IPI number is then the offset'ed (linux irq number mapped to the IPI)
  399. */
  400. extern void mpic_irq_set_priority(unsigned int irq, unsigned int pri);
  401. /* Setup a non-boot CPU */
  402. extern void mpic_setup_this_cpu(void);
  403. /* Clean up for kexec (or cpu offline or ...) */
  404. extern void mpic_teardown_this_cpu(int secondary);
  405. /* Get the current cpu priority for this cpu (0..15) */
  406. extern int mpic_cpu_get_priority(void);
  407. /* Set the current cpu priority for this cpu */
  408. extern void mpic_cpu_set_priority(int prio);
  409. /* Request IPIs on primary mpic */
  410. extern void mpic_request_ipis(void);
  411. /* Send a message (IPI) to a given target (cpu number or MSG_*) */
  412. void smp_mpic_message_pass(int target, int msg);
  413. /* Unmask a specific virq */
  414. extern void mpic_unmask_irq(struct irq_data *d);
  415. /* Mask a specific virq */
  416. extern void mpic_mask_irq(struct irq_data *d);
  417. /* EOI a specific virq */
  418. extern void mpic_end_irq(struct irq_data *d);
  419. /* Fetch interrupt from a given mpic */
  420. extern unsigned int mpic_get_one_irq(struct mpic *mpic);
  421. /* This one gets from the primary mpic */
  422. extern unsigned int mpic_get_irq(void);
  423. /* This one gets from the primary mpic via CoreInt*/
  424. extern unsigned int mpic_get_coreint_irq(void);
  425. /* Fetch Machine Check interrupt from primary mpic */
  426. extern unsigned int mpic_get_mcirq(void);
  427. /* Set the EPIC clock ratio */
  428. void mpic_set_clk_ratio(struct mpic *mpic, u32 clock_ratio);
  429. /* Enable/Disable EPIC serial interrupt mode */
  430. void mpic_set_serial_int(struct mpic *mpic, int enable);
  431. #endif /* __KERNEL__ */
  432. #endif /* _ASM_POWERPC_MPIC_H */