mpic.h 14 KB

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