mpic.h 13 KB

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