xref: /openbmc/linux/drivers/sh/intc/internals.h (revision 1d6a21b0a672fb29b01ccf397d478e0541e17716)
12be6bb0cSPaul Mundt #include <linux/sh_intc.h>
22be6bb0cSPaul Mundt #include <linux/irq.h>
3*1d6a21b0SPaul Mundt #include <linux/irqdomain.h>
42be6bb0cSPaul Mundt #include <linux/list.h>
52be6bb0cSPaul Mundt #include <linux/kernel.h>
62be6bb0cSPaul Mundt #include <linux/types.h>
72be6bb0cSPaul Mundt #include <linux/radix-tree.h>
8f4e73bfcSKay Sievers #include <linux/device.h>
92be6bb0cSPaul Mundt 
102be6bb0cSPaul Mundt #define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \
112be6bb0cSPaul Mundt 	((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \
122be6bb0cSPaul Mundt 	 ((addr_e) << 16) | ((addr_d << 24)))
132be6bb0cSPaul Mundt 
142be6bb0cSPaul Mundt #define _INTC_SHIFT(h)		(h & 0x1f)
152be6bb0cSPaul Mundt #define _INTC_WIDTH(h)		((h >> 5) & 0xf)
162be6bb0cSPaul Mundt #define _INTC_FN(h)		((h >> 9) & 0xf)
172be6bb0cSPaul Mundt #define _INTC_MODE(h)		((h >> 13) & 0x7)
182be6bb0cSPaul Mundt #define _INTC_ADDR_E(h)		((h >> 16) & 0xff)
192be6bb0cSPaul Mundt #define _INTC_ADDR_D(h)		((h >> 24) & 0xff)
202be6bb0cSPaul Mundt 
212be6bb0cSPaul Mundt #ifdef CONFIG_SMP
222be6bb0cSPaul Mundt #define IS_SMP(x)		(x.smp)
232be6bb0cSPaul Mundt #define INTC_REG(d, x, c)	(d->reg[(x)] + ((d->smp[(x)] & 0xff) * c))
242be6bb0cSPaul Mundt #define SMP_NR(d, x)		((d->smp[(x)] >> 8) ? (d->smp[(x)] >> 8) : 1)
252be6bb0cSPaul Mundt #else
262be6bb0cSPaul Mundt #define IS_SMP(x)		0
272be6bb0cSPaul Mundt #define INTC_REG(d, x, c)	(d->reg[(x)])
282be6bb0cSPaul Mundt #define SMP_NR(d, x)		1
292be6bb0cSPaul Mundt #endif
302be6bb0cSPaul Mundt 
312be6bb0cSPaul Mundt struct intc_handle_int {
322be6bb0cSPaul Mundt 	unsigned int irq;
332be6bb0cSPaul Mundt 	unsigned long handle;
342be6bb0cSPaul Mundt };
352be6bb0cSPaul Mundt 
362be6bb0cSPaul Mundt struct intc_window {
372be6bb0cSPaul Mundt 	phys_addr_t phys;
382be6bb0cSPaul Mundt 	void __iomem *virt;
392be6bb0cSPaul Mundt 	unsigned long size;
402be6bb0cSPaul Mundt };
412be6bb0cSPaul Mundt 
422be6bb0cSPaul Mundt struct intc_map_entry {
432be6bb0cSPaul Mundt 	intc_enum enum_id;
442be6bb0cSPaul Mundt 	struct intc_desc_int *desc;
452be6bb0cSPaul Mundt };
462be6bb0cSPaul Mundt 
472be6bb0cSPaul Mundt struct intc_subgroup_entry {
482be6bb0cSPaul Mundt 	unsigned int pirq;
492be6bb0cSPaul Mundt 	intc_enum enum_id;
502be6bb0cSPaul Mundt 	unsigned long handle;
512be6bb0cSPaul Mundt };
522be6bb0cSPaul Mundt 
532be6bb0cSPaul Mundt struct intc_desc_int {
542be6bb0cSPaul Mundt 	struct list_head list;
55f4e73bfcSKay Sievers 	struct device dev;
562be6bb0cSPaul Mundt 	struct radix_tree_root tree;
572be6bb0cSPaul Mundt 	raw_spinlock_t lock;
582be6bb0cSPaul Mundt 	unsigned int index;
592be6bb0cSPaul Mundt 	unsigned long *reg;
602be6bb0cSPaul Mundt #ifdef CONFIG_SMP
612be6bb0cSPaul Mundt 	unsigned long *smp;
622be6bb0cSPaul Mundt #endif
632be6bb0cSPaul Mundt 	unsigned int nr_reg;
642be6bb0cSPaul Mundt 	struct intc_handle_int *prio;
652be6bb0cSPaul Mundt 	unsigned int nr_prio;
662be6bb0cSPaul Mundt 	struct intc_handle_int *sense;
672be6bb0cSPaul Mundt 	unsigned int nr_sense;
682be6bb0cSPaul Mundt 	struct intc_window *window;
692be6bb0cSPaul Mundt 	unsigned int nr_windows;
70*1d6a21b0SPaul Mundt 	struct irq_domain *domain;
712be6bb0cSPaul Mundt 	struct irq_chip chip;
720f966d74SRafael J. Wysocki 	bool skip_suspend;
732be6bb0cSPaul Mundt };
742be6bb0cSPaul Mundt 
752be6bb0cSPaul Mundt 
762be6bb0cSPaul Mundt enum {
772be6bb0cSPaul Mundt 	REG_FN_ERR = 0,
782be6bb0cSPaul Mundt 	REG_FN_TEST_BASE = 1,
792be6bb0cSPaul Mundt 	REG_FN_WRITE_BASE = 5,
802be6bb0cSPaul Mundt 	REG_FN_MODIFY_BASE = 9
812be6bb0cSPaul Mundt };
822be6bb0cSPaul Mundt 
832be6bb0cSPaul Mundt enum {	MODE_ENABLE_REG = 0, /* Bit(s) set -> interrupt enabled */
842be6bb0cSPaul Mundt 	MODE_MASK_REG,       /* Bit(s) set -> interrupt disabled */
852be6bb0cSPaul Mundt 	MODE_DUAL_REG,       /* Two registers, set bit to enable / disable */
862be6bb0cSPaul Mundt 	MODE_PRIO_REG,       /* Priority value written to enable interrupt */
872be6bb0cSPaul Mundt 	MODE_PCLR_REG,       /* Above plus all bits set to disable interrupt */
882be6bb0cSPaul Mundt };
892be6bb0cSPaul Mundt 
902be6bb0cSPaul Mundt static inline struct intc_desc_int *get_intc_desc(unsigned int irq)
912be6bb0cSPaul Mundt {
92286b9bfeSThomas Gleixner 	struct irq_chip *chip = irq_get_chip(irq);
932be6bb0cSPaul Mundt 
942be6bb0cSPaul Mundt 	return container_of(chip, struct intc_desc_int, chip);
952be6bb0cSPaul Mundt }
962be6bb0cSPaul Mundt 
972be6bb0cSPaul Mundt /*
982be6bb0cSPaul Mundt  * Grumble.
992be6bb0cSPaul Mundt  */
1002be6bb0cSPaul Mundt static inline void activate_irq(int irq)
1012be6bb0cSPaul Mundt {
1022be6bb0cSPaul Mundt #ifdef CONFIG_ARM
1032be6bb0cSPaul Mundt 	/* ARM requires an extra step to clear IRQ_NOREQUEST, which it
1042be6bb0cSPaul Mundt 	 * sets on behalf of every irq_chip.  Also sets IRQ_NOPROBE.
1052be6bb0cSPaul Mundt 	 */
1062be6bb0cSPaul Mundt 	set_irq_flags(irq, IRQF_VALID);
1072be6bb0cSPaul Mundt #else
1082be6bb0cSPaul Mundt 	/* same effect on other architectures */
109286b9bfeSThomas Gleixner 	irq_set_noprobe(irq);
1102be6bb0cSPaul Mundt #endif
1112be6bb0cSPaul Mundt }
1122be6bb0cSPaul Mundt 
113b59f9f97SPaul Mundt static inline int intc_handle_int_cmp(const void *a, const void *b)
114b59f9f97SPaul Mundt {
115b59f9f97SPaul Mundt 	const struct intc_handle_int *_a = a;
116b59f9f97SPaul Mundt 	const struct intc_handle_int *_b = b;
117b59f9f97SPaul Mundt 
118b59f9f97SPaul Mundt 	return _a->irq - _b->irq;
119b59f9f97SPaul Mundt }
120b59f9f97SPaul Mundt 
1212be6bb0cSPaul Mundt /* access.c */
1222be6bb0cSPaul Mundt extern unsigned long
1232be6bb0cSPaul Mundt (*intc_reg_fns[])(unsigned long addr, unsigned long h, unsigned long data);
1242be6bb0cSPaul Mundt 
1252be6bb0cSPaul Mundt extern unsigned long
1262be6bb0cSPaul Mundt (*intc_enable_fns[])(unsigned long addr, unsigned long handle,
1272be6bb0cSPaul Mundt 		     unsigned long (*fn)(unsigned long,
1282be6bb0cSPaul Mundt 				unsigned long, unsigned long),
1292be6bb0cSPaul Mundt 		     unsigned int irq);
1302be6bb0cSPaul Mundt extern unsigned long
1312be6bb0cSPaul Mundt (*intc_disable_fns[])(unsigned long addr, unsigned long handle,
1322be6bb0cSPaul Mundt 		      unsigned long (*fn)(unsigned long,
1332be6bb0cSPaul Mundt 				unsigned long, unsigned long),
1342be6bb0cSPaul Mundt 		      unsigned int irq);
1352be6bb0cSPaul Mundt extern unsigned long
1362be6bb0cSPaul Mundt (*intc_enable_noprio_fns[])(unsigned long addr, unsigned long handle,
1372be6bb0cSPaul Mundt 		            unsigned long (*fn)(unsigned long,
1382be6bb0cSPaul Mundt 				unsigned long, unsigned long),
1392be6bb0cSPaul Mundt 			    unsigned int irq);
1402be6bb0cSPaul Mundt 
1412be6bb0cSPaul Mundt unsigned long intc_phys_to_virt(struct intc_desc_int *d, unsigned long address);
1422be6bb0cSPaul Mundt unsigned int intc_get_reg(struct intc_desc_int *d, unsigned long address);
1432be6bb0cSPaul Mundt unsigned int intc_set_field_from_handle(unsigned int value,
1442be6bb0cSPaul Mundt 			    unsigned int field_value,
1452be6bb0cSPaul Mundt 			    unsigned int handle);
1462be6bb0cSPaul Mundt unsigned long intc_get_field_from_handle(unsigned int value,
1472be6bb0cSPaul Mundt 					 unsigned int handle);
1482be6bb0cSPaul Mundt 
1492be6bb0cSPaul Mundt /* balancing.c */
1502be6bb0cSPaul Mundt #ifdef CONFIG_INTC_BALANCING
1512be6bb0cSPaul Mundt void intc_balancing_enable(unsigned int irq);
1522be6bb0cSPaul Mundt void intc_balancing_disable(unsigned int irq);
1532be6bb0cSPaul Mundt void intc_set_dist_handle(unsigned int irq, struct intc_desc *desc,
1542be6bb0cSPaul Mundt 			  struct intc_desc_int *d, intc_enum id);
1552be6bb0cSPaul Mundt #else
1566966fed9SPaul Mundt static inline void intc_balancing_enable(unsigned int irq) { }
1576966fed9SPaul Mundt static inline void intc_balancing_disable(unsigned int irq) { }
1586966fed9SPaul Mundt static inline void
1596966fed9SPaul Mundt intc_set_dist_handle(unsigned int irq, struct intc_desc *desc,
1602be6bb0cSPaul Mundt 		     struct intc_desc_int *d, intc_enum id) { }
1612be6bb0cSPaul Mundt #endif
1622be6bb0cSPaul Mundt 
1632be6bb0cSPaul Mundt /* chip.c */
1642be6bb0cSPaul Mundt extern struct irq_chip intc_irq_chip;
16526599a94SPaul Mundt void _intc_enable(struct irq_data *data, unsigned long handle);
1662be6bb0cSPaul Mundt 
1672be6bb0cSPaul Mundt /* core.c */
1682be6bb0cSPaul Mundt extern struct list_head intc_list;
1692be6bb0cSPaul Mundt extern raw_spinlock_t intc_big_lock;
170f4e73bfcSKay Sievers extern struct bus_type intc_subsys;
1712be6bb0cSPaul Mundt 
1722be6bb0cSPaul Mundt unsigned int intc_get_dfl_prio_level(void);
1732be6bb0cSPaul Mundt unsigned int intc_get_prio_level(unsigned int irq);
1742be6bb0cSPaul Mundt void intc_set_prio_level(unsigned int irq, unsigned int level);
1752be6bb0cSPaul Mundt 
1762be6bb0cSPaul Mundt /* handle.c */
1772be6bb0cSPaul Mundt unsigned int intc_get_mask_handle(struct intc_desc *desc,
1782be6bb0cSPaul Mundt 				  struct intc_desc_int *d,
1792be6bb0cSPaul Mundt 				  intc_enum enum_id, int do_grps);
1802be6bb0cSPaul Mundt unsigned int intc_get_prio_handle(struct intc_desc *desc,
1812be6bb0cSPaul Mundt 				  struct intc_desc_int *d,
1822be6bb0cSPaul Mundt 				  intc_enum enum_id, int do_grps);
1832be6bb0cSPaul Mundt unsigned int intc_get_sense_handle(struct intc_desc *desc,
1842be6bb0cSPaul Mundt 				   struct intc_desc_int *d,
1852be6bb0cSPaul Mundt 				   intc_enum enum_id);
1862be6bb0cSPaul Mundt void intc_set_ack_handle(unsigned int irq, struct intc_desc *desc,
1872be6bb0cSPaul Mundt 			 struct intc_desc_int *d, intc_enum id);
1882be6bb0cSPaul Mundt unsigned long intc_get_ack_handle(unsigned int irq);
1892be6bb0cSPaul Mundt void intc_enable_disable_enum(struct intc_desc *desc, struct intc_desc_int *d,
1902be6bb0cSPaul Mundt 			      intc_enum enum_id, int enable);
1912be6bb0cSPaul Mundt 
192*1d6a21b0SPaul Mundt /* irqdomain.c */
193*1d6a21b0SPaul Mundt void intc_irq_domain_init(struct intc_desc_int *d, struct intc_hw_desc *hw);
194*1d6a21b0SPaul Mundt 
1952be6bb0cSPaul Mundt /* virq.c */
1962be6bb0cSPaul Mundt void intc_subgroup_init(struct intc_desc *desc, struct intc_desc_int *d);
1972be6bb0cSPaul Mundt void intc_irq_xlate_set(unsigned int irq, intc_enum id, struct intc_desc_int *d);
1982be6bb0cSPaul Mundt struct intc_map_entry *intc_irq_xlate_get(unsigned int irq);
199