mpic.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. /*
  7. * Global registers
  8. */
  9. #define MPIC_GREG_BASE 0x01000
  10. #define MPIC_GREG_FEATURE_0 0x00000
  11. #define MPIC_GREG_FEATURE_LAST_SRC_MASK 0x07ff0000
  12. #define MPIC_GREG_FEATURE_LAST_SRC_SHIFT 16
  13. #define MPIC_GREG_FEATURE_LAST_CPU_MASK 0x00001f00
  14. #define MPIC_GREG_FEATURE_LAST_CPU_SHIFT 8
  15. #define MPIC_GREG_FEATURE_VERSION_MASK 0xff
  16. #define MPIC_GREG_FEATURE_1 0x00010
  17. #define MPIC_GREG_GLOBAL_CONF_0 0x00020
  18. #define MPIC_GREG_GCONF_RESET 0x80000000
  19. #define MPIC_GREG_GCONF_8259_PTHROU_DIS 0x20000000
  20. #define MPIC_GREG_GCONF_BASE_MASK 0x000fffff
  21. #define MPIC_GREG_GLOBAL_CONF_1 0x00030
  22. #define MPIC_GREG_GLOBAL_CONF_1_SIE 0x08000000
  23. #define MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO_MASK 0x70000000
  24. #define MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO(r) \
  25. (((r) << 28) & MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO_MASK)
  26. #define MPIC_GREG_VENDOR_0 0x00040
  27. #define MPIC_GREG_VENDOR_1 0x00050
  28. #define MPIC_GREG_VENDOR_2 0x00060
  29. #define MPIC_GREG_VENDOR_3 0x00070
  30. #define MPIC_GREG_VENDOR_ID 0x00080
  31. #define MPIC_GREG_VENDOR_ID_STEPPING_MASK 0x00ff0000
  32. #define MPIC_GREG_VENDOR_ID_STEPPING_SHIFT 16
  33. #define MPIC_GREG_VENDOR_ID_DEVICE_ID_MASK 0x0000ff00
  34. #define MPIC_GREG_VENDOR_ID_DEVICE_ID_SHIFT 8
  35. #define MPIC_GREG_VENDOR_ID_VENDOR_ID_MASK 0x000000ff
  36. #define MPIC_GREG_PROCESSOR_INIT 0x00090
  37. #define MPIC_GREG_IPI_VECTOR_PRI_0 0x000a0
  38. #define MPIC_GREG_IPI_VECTOR_PRI_1 0x000b0
  39. #define MPIC_GREG_IPI_VECTOR_PRI_2 0x000c0
  40. #define MPIC_GREG_IPI_VECTOR_PRI_3 0x000d0
  41. #define MPIC_GREG_IPI_STRIDE 0x10
  42. #define MPIC_GREG_SPURIOUS 0x000e0
  43. #define MPIC_GREG_TIMER_FREQ 0x000f0
  44. /*
  45. *
  46. * Timer registers
  47. */
  48. #define MPIC_TIMER_BASE 0x01100
  49. #define MPIC_TIMER_STRIDE 0x40
  50. #define MPIC_TIMER_CURRENT_CNT 0x00000
  51. #define MPIC_TIMER_BASE_CNT 0x00010
  52. #define MPIC_TIMER_VECTOR_PRI 0x00020
  53. #define MPIC_TIMER_DESTINATION 0x00030
  54. /*
  55. * Per-Processor registers
  56. */
  57. #define MPIC_CPU_THISBASE 0x00000
  58. #define MPIC_CPU_BASE 0x20000
  59. #define MPIC_CPU_STRIDE 0x01000
  60. #define MPIC_CPU_IPI_DISPATCH_0 0x00040
  61. #define MPIC_CPU_IPI_DISPATCH_1 0x00050
  62. #define MPIC_CPU_IPI_DISPATCH_2 0x00060
  63. #define MPIC_CPU_IPI_DISPATCH_3 0x00070
  64. #define MPIC_CPU_IPI_DISPATCH_STRIDE 0x00010
  65. #define MPIC_CPU_CURRENT_TASK_PRI 0x00080
  66. #define MPIC_CPU_TASKPRI_MASK 0x0000000f
  67. #define MPIC_CPU_WHOAMI 0x00090
  68. #define MPIC_CPU_WHOAMI_MASK 0x0000001f
  69. #define MPIC_CPU_INTACK 0x000a0
  70. #define MPIC_CPU_EOI 0x000b0
  71. /*
  72. * Per-source registers
  73. */
  74. #define MPIC_IRQ_BASE 0x10000
  75. #define MPIC_IRQ_STRIDE 0x00020
  76. #define MPIC_IRQ_VECTOR_PRI 0x00000
  77. #define MPIC_VECPRI_MASK 0x80000000
  78. #define MPIC_VECPRI_ACTIVITY 0x40000000 /* Read Only */
  79. #define MPIC_VECPRI_PRIORITY_MASK 0x000f0000
  80. #define MPIC_VECPRI_PRIORITY_SHIFT 16
  81. #define MPIC_VECPRI_VECTOR_MASK 0x000007ff
  82. #define MPIC_VECPRI_POLARITY_POSITIVE 0x00800000
  83. #define MPIC_VECPRI_POLARITY_NEGATIVE 0x00000000
  84. #define MPIC_VECPRI_POLARITY_MASK 0x00800000
  85. #define MPIC_VECPRI_SENSE_LEVEL 0x00400000
  86. #define MPIC_VECPRI_SENSE_EDGE 0x00000000
  87. #define MPIC_VECPRI_SENSE_MASK 0x00400000
  88. #define MPIC_IRQ_DESTINATION 0x00010
  89. #define MPIC_MAX_IRQ_SOURCES 2048
  90. #define MPIC_MAX_CPUS 32
  91. #define MPIC_MAX_ISU 32
  92. /*
  93. * Special vector numbers (internal use only)
  94. */
  95. #define MPIC_VEC_SPURRIOUS 255
  96. #define MPIC_VEC_IPI_3 254
  97. #define MPIC_VEC_IPI_2 253
  98. #define MPIC_VEC_IPI_1 252
  99. #define MPIC_VEC_IPI_0 251
  100. /* unused */
  101. #define MPIC_VEC_TIMER_3 250
  102. #define MPIC_VEC_TIMER_2 249
  103. #define MPIC_VEC_TIMER_1 248
  104. #define MPIC_VEC_TIMER_0 247
  105. /*
  106. * Tsi108 implementation of MPIC has many differences from the original one
  107. */
  108. /*
  109. * Global registers
  110. */
  111. #define TSI108_GREG_BASE 0x00000
  112. #define TSI108_GREG_FEATURE_0 0x00000
  113. #define TSI108_GREG_GLOBAL_CONF_0 0x00004
  114. #define TSI108_GREG_VENDOR_ID 0x0000c
  115. #define TSI108_GREG_IPI_VECTOR_PRI_0 0x00204 /* Doorbell 0 */
  116. #define TSI108_GREG_IPI_STRIDE 0x0c
  117. #define TSI108_GREG_SPURIOUS 0x00010
  118. #define TSI108_GREG_TIMER_FREQ 0x00014
  119. /*
  120. * Timer registers
  121. */
  122. #define TSI108_TIMER_BASE 0x0030
  123. #define TSI108_TIMER_STRIDE 0x10
  124. #define TSI108_TIMER_CURRENT_CNT 0x00000
  125. #define TSI108_TIMER_BASE_CNT 0x00004
  126. #define TSI108_TIMER_VECTOR_PRI 0x00008
  127. #define TSI108_TIMER_DESTINATION 0x0000c
  128. /*
  129. * Per-Processor registers
  130. */
  131. #define TSI108_CPU_BASE 0x00300
  132. #define TSI108_CPU_STRIDE 0x00040
  133. #define TSI108_CPU_IPI_DISPATCH_0 0x00200
  134. #define TSI108_CPU_IPI_DISPATCH_STRIDE 0x00000
  135. #define TSI108_CPU_CURRENT_TASK_PRI 0x00000
  136. #define TSI108_CPU_WHOAMI 0xffffffff
  137. #define TSI108_CPU_INTACK 0x00004
  138. #define TSI108_CPU_EOI 0x00008
  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_IRQ_BASE,
  178. MPIC_IDX_IRQ_STRIDE,
  179. MPIC_IDX_IRQ_VECTOR_PRI,
  180. MPIC_IDX_VECPRI_VECTOR_MASK,
  181. MPIC_IDX_VECPRI_POLARITY_POSITIVE,
  182. MPIC_IDX_VECPRI_POLARITY_NEGATIVE,
  183. MPIC_IDX_VECPRI_SENSE_LEVEL,
  184. MPIC_IDX_VECPRI_SENSE_EDGE,
  185. MPIC_IDX_VECPRI_POLARITY_MASK,
  186. MPIC_IDX_VECPRI_SENSE_MASK,
  187. MPIC_IDX_IRQ_DESTINATION,
  188. MPIC_IDX_END
  189. };
  190. #ifdef CONFIG_MPIC_BROKEN_U3
  191. /* Fixup table entry */
  192. struct mpic_irq_fixup
  193. {
  194. u8 __iomem *base;
  195. u8 __iomem *applebase;
  196. u32 data;
  197. unsigned int index;
  198. };
  199. #endif /* CONFIG_MPIC_BROKEN_U3 */
  200. enum mpic_reg_type {
  201. mpic_access_mmio_le,
  202. mpic_access_mmio_be,
  203. #ifdef CONFIG_PPC_DCR
  204. mpic_access_dcr
  205. #endif
  206. };
  207. struct mpic_reg_bank {
  208. u32 __iomem *base;
  209. #ifdef CONFIG_PPC_DCR
  210. dcr_host_t dhost;
  211. unsigned int dbase;
  212. unsigned int doff;
  213. #endif /* CONFIG_PPC_DCR */
  214. };
  215. /* The instance data of a given MPIC */
  216. struct mpic
  217. {
  218. /* The device node of the interrupt controller */
  219. struct device_node *of_node;
  220. /* The remapper for this MPIC */
  221. struct irq_host *irqhost;
  222. /* The "linux" controller struct */
  223. struct irq_chip hc_irq;
  224. #ifdef CONFIG_MPIC_BROKEN_U3
  225. struct irq_chip hc_ht_irq;
  226. #endif
  227. #ifdef CONFIG_SMP
  228. struct irq_chip hc_ipi;
  229. #endif
  230. const char *name;
  231. /* Flags */
  232. unsigned int flags;
  233. /* How many irq sources in a given ISU */
  234. unsigned int isu_size;
  235. unsigned int isu_shift;
  236. unsigned int isu_mask;
  237. unsigned int irq_count;
  238. /* Number of sources */
  239. unsigned int num_sources;
  240. /* Number of CPUs */
  241. unsigned int num_cpus;
  242. /* default senses array */
  243. unsigned char *senses;
  244. unsigned int senses_count;
  245. #ifdef CONFIG_MPIC_BROKEN_U3
  246. /* The fixup table */
  247. struct mpic_irq_fixup *fixups;
  248. spinlock_t fixup_lock;
  249. #endif
  250. /* Register access method */
  251. enum mpic_reg_type reg_type;
  252. /* The various ioremap'ed bases */
  253. struct mpic_reg_bank gregs;
  254. struct mpic_reg_bank tmregs;
  255. struct mpic_reg_bank cpuregs[MPIC_MAX_CPUS];
  256. struct mpic_reg_bank isus[MPIC_MAX_ISU];
  257. #ifdef CONFIG_PPC_DCR
  258. unsigned int dcr_base;
  259. #endif
  260. #ifdef CONFIG_MPIC_WEIRD
  261. /* Pointer to HW info array */
  262. u32 *hw_set;
  263. #endif
  264. /* link */
  265. struct mpic *next;
  266. };
  267. /*
  268. * MPIC flags (passed to mpic_alloc)
  269. *
  270. * The top 4 bits contain an MPIC bhw id that is used to index the
  271. * register offsets and some masks when CONFIG_MPIC_WEIRD is set.
  272. * Note setting any ID (leaving those bits to 0) means standard MPIC
  273. */
  274. /* This is the primary controller, only that one has IPIs and
  275. * has afinity control. A non-primary MPIC always uses CPU0
  276. * registers only
  277. */
  278. #define MPIC_PRIMARY 0x00000001
  279. /* Set this for a big-endian MPIC */
  280. #define MPIC_BIG_ENDIAN 0x00000002
  281. /* Broken U3 MPIC */
  282. #define MPIC_BROKEN_U3 0x00000004
  283. /* Broken IPI registers (autodetected) */
  284. #define MPIC_BROKEN_IPI 0x00000008
  285. /* MPIC wants a reset */
  286. #define MPIC_WANTS_RESET 0x00000010
  287. /* Spurious vector requires EOI */
  288. #define MPIC_SPV_EOI 0x00000020
  289. /* No passthrough disable */
  290. #define MPIC_NO_PTHROU_DIS 0x00000040
  291. /* DCR based MPIC */
  292. #define MPIC_USES_DCR 0x00000080
  293. /* MPIC HW modification ID */
  294. #define MPIC_REGSET_MASK 0xf0000000
  295. #define MPIC_REGSET(val) (((val) & 0xf ) << 28)
  296. #define MPIC_GET_REGSET(flags) (((flags) >> 28) & 0xf)
  297. #define MPIC_REGSET_STANDARD MPIC_REGSET(0) /* Original MPIC */
  298. #define MPIC_REGSET_TSI108 MPIC_REGSET(1) /* Tsi108/109 PIC */
  299. /* Allocate the controller structure and setup the linux irq descs
  300. * for the range if interrupts passed in. No HW initialization is
  301. * actually performed.
  302. *
  303. * @phys_addr: physial base address of the MPIC
  304. * @flags: flags, see constants above
  305. * @isu_size: number of interrupts in an ISU. Use 0 to use a
  306. * standard ISU-less setup (aka powermac)
  307. * @irq_offset: first irq number to assign to this mpic
  308. * @irq_count: number of irqs to use with this mpic IRQ sources. Pass 0
  309. * to match the number of sources
  310. * @ipi_offset: first irq number to assign to this mpic IPI sources,
  311. * used only on primary mpic
  312. * @senses: array of sense values
  313. * @senses_num: number of entries in the array
  314. *
  315. * Note about the sense array. If none is passed, all interrupts are
  316. * setup to be level negative unless MPIC_BROKEN_U3 is set in which
  317. * case they are edge positive (and the array is ignored anyway).
  318. * The values in the array start at the first source of the MPIC,
  319. * that is senses[0] correspond to linux irq "irq_offset".
  320. */
  321. extern struct mpic *mpic_alloc(struct device_node *node,
  322. phys_addr_t phys_addr,
  323. unsigned int flags,
  324. unsigned int isu_size,
  325. unsigned int irq_count,
  326. const char *name);
  327. /* Assign ISUs, to call before mpic_init()
  328. *
  329. * @mpic: controller structure as returned by mpic_alloc()
  330. * @isu_num: ISU number
  331. * @phys_addr: physical address of the ISU
  332. */
  333. extern void mpic_assign_isu(struct mpic *mpic, unsigned int isu_num,
  334. phys_addr_t phys_addr);
  335. /* Set default sense codes
  336. *
  337. * @mpic: controller
  338. * @senses: array of sense codes
  339. * @count: size of above array
  340. *
  341. * Optionally provide an array (indexed on hardware interrupt numbers
  342. * for this MPIC) of default sense codes for the chip. Those are linux
  343. * sense codes IRQ_TYPE_*
  344. *
  345. * The driver gets ownership of the pointer, don't dispose of it or
  346. * anything like that. __init only.
  347. */
  348. extern void mpic_set_default_senses(struct mpic *mpic, u8 *senses, int count);
  349. /* Initialize the controller. After this has been called, none of the above
  350. * should be called again for this mpic
  351. */
  352. extern void mpic_init(struct mpic *mpic);
  353. /*
  354. * All of the following functions must only be used after the
  355. * ISUs have been assigned and the controller fully initialized
  356. * with mpic_init()
  357. */
  358. /* Change/Read the priority of an interrupt. Default is 8 for irqs and
  359. * 10 for IPIs. You can call this on both IPIs and IRQ numbers, but the
  360. * IPI number is then the offset'ed (linux irq number mapped to the IPI)
  361. */
  362. extern void mpic_irq_set_priority(unsigned int irq, unsigned int pri);
  363. extern unsigned int mpic_irq_get_priority(unsigned int irq);
  364. /* Setup a non-boot CPU */
  365. extern void mpic_setup_this_cpu(void);
  366. /* Clean up for kexec (or cpu offline or ...) */
  367. extern void mpic_teardown_this_cpu(int secondary);
  368. /* Get the current cpu priority for this cpu (0..15) */
  369. extern int mpic_cpu_get_priority(void);
  370. /* Set the current cpu priority for this cpu */
  371. extern void mpic_cpu_set_priority(int prio);
  372. /* Request IPIs on primary mpic */
  373. extern void mpic_request_ipis(void);
  374. /* Send an IPI (non offseted number 0..3) */
  375. extern void mpic_send_ipi(unsigned int ipi_no, unsigned int cpu_mask);
  376. /* Send a message (IPI) to a given target (cpu number or MSG_*) */
  377. void smp_mpic_message_pass(int target, int msg);
  378. /* Fetch interrupt from a given mpic */
  379. extern unsigned int mpic_get_one_irq(struct mpic *mpic);
  380. /* This one gets to the primary mpic */
  381. extern unsigned int mpic_get_irq(void);
  382. /* Set the EPIC clock ratio */
  383. void mpic_set_clk_ratio(struct mpic *mpic, u32 clock_ratio);
  384. /* Enable/Disable EPIC serial interrupt mode */
  385. void mpic_set_serial_int(struct mpic *mpic, int enable);
  386. #endif /* __KERNEL__ */
  387. #endif /* _ASM_POWERPC_MPIC_H */