xref: /openbmc/linux/drivers/sh/intc/internals.h (revision 2be6bb0c79c7fbda3425b65ee51c558bbaf4cf91)
1*2be6bb0cSPaul Mundt #include <linux/sh_intc.h>
2*2be6bb0cSPaul Mundt #include <linux/irq.h>
3*2be6bb0cSPaul Mundt #include <linux/list.h>
4*2be6bb0cSPaul Mundt #include <linux/kernel.h>
5*2be6bb0cSPaul Mundt #include <linux/types.h>
6*2be6bb0cSPaul Mundt #include <linux/radix-tree.h>
7*2be6bb0cSPaul Mundt #include <linux/sysdev.h>
8*2be6bb0cSPaul Mundt 
9*2be6bb0cSPaul Mundt #define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \
10*2be6bb0cSPaul Mundt 	((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \
11*2be6bb0cSPaul Mundt 	 ((addr_e) << 16) | ((addr_d << 24)))
12*2be6bb0cSPaul Mundt 
13*2be6bb0cSPaul Mundt #define _INTC_SHIFT(h)		(h & 0x1f)
14*2be6bb0cSPaul Mundt #define _INTC_WIDTH(h)		((h >> 5) & 0xf)
15*2be6bb0cSPaul Mundt #define _INTC_FN(h)		((h >> 9) & 0xf)
16*2be6bb0cSPaul Mundt #define _INTC_MODE(h)		((h >> 13) & 0x7)
17*2be6bb0cSPaul Mundt #define _INTC_ADDR_E(h)		((h >> 16) & 0xff)
18*2be6bb0cSPaul Mundt #define _INTC_ADDR_D(h)		((h >> 24) & 0xff)
19*2be6bb0cSPaul Mundt 
20*2be6bb0cSPaul Mundt #ifdef CONFIG_SMP
21*2be6bb0cSPaul Mundt #define IS_SMP(x)		(x.smp)
22*2be6bb0cSPaul Mundt #define INTC_REG(d, x, c)	(d->reg[(x)] + ((d->smp[(x)] & 0xff) * c))
23*2be6bb0cSPaul Mundt #define SMP_NR(d, x)		((d->smp[(x)] >> 8) ? (d->smp[(x)] >> 8) : 1)
24*2be6bb0cSPaul Mundt #else
25*2be6bb0cSPaul Mundt #define IS_SMP(x)		0
26*2be6bb0cSPaul Mundt #define INTC_REG(d, x, c)	(d->reg[(x)])
27*2be6bb0cSPaul Mundt #define SMP_NR(d, x)		1
28*2be6bb0cSPaul Mundt #endif
29*2be6bb0cSPaul Mundt 
30*2be6bb0cSPaul Mundt struct intc_handle_int {
31*2be6bb0cSPaul Mundt 	unsigned int irq;
32*2be6bb0cSPaul Mundt 	unsigned long handle;
33*2be6bb0cSPaul Mundt };
34*2be6bb0cSPaul Mundt 
35*2be6bb0cSPaul Mundt struct intc_window {
36*2be6bb0cSPaul Mundt 	phys_addr_t phys;
37*2be6bb0cSPaul Mundt 	void __iomem *virt;
38*2be6bb0cSPaul Mundt 	unsigned long size;
39*2be6bb0cSPaul Mundt };
40*2be6bb0cSPaul Mundt 
41*2be6bb0cSPaul Mundt struct intc_map_entry {
42*2be6bb0cSPaul Mundt 	intc_enum enum_id;
43*2be6bb0cSPaul Mundt 	struct intc_desc_int *desc;
44*2be6bb0cSPaul Mundt };
45*2be6bb0cSPaul Mundt 
46*2be6bb0cSPaul Mundt struct intc_subgroup_entry {
47*2be6bb0cSPaul Mundt 	unsigned int pirq;
48*2be6bb0cSPaul Mundt 	intc_enum enum_id;
49*2be6bb0cSPaul Mundt 	unsigned long handle;
50*2be6bb0cSPaul Mundt };
51*2be6bb0cSPaul Mundt 
52*2be6bb0cSPaul Mundt struct intc_desc_int {
53*2be6bb0cSPaul Mundt 	struct list_head list;
54*2be6bb0cSPaul Mundt 	struct sys_device sysdev;
55*2be6bb0cSPaul Mundt 	struct radix_tree_root tree;
56*2be6bb0cSPaul Mundt 	pm_message_t state;
57*2be6bb0cSPaul Mundt 	raw_spinlock_t lock;
58*2be6bb0cSPaul Mundt 	unsigned int index;
59*2be6bb0cSPaul Mundt 	unsigned long *reg;
60*2be6bb0cSPaul Mundt #ifdef CONFIG_SMP
61*2be6bb0cSPaul Mundt 	unsigned long *smp;
62*2be6bb0cSPaul Mundt #endif
63*2be6bb0cSPaul Mundt 	unsigned int nr_reg;
64*2be6bb0cSPaul Mundt 	struct intc_handle_int *prio;
65*2be6bb0cSPaul Mundt 	unsigned int nr_prio;
66*2be6bb0cSPaul Mundt 	struct intc_handle_int *sense;
67*2be6bb0cSPaul Mundt 	unsigned int nr_sense;
68*2be6bb0cSPaul Mundt 	struct intc_window *window;
69*2be6bb0cSPaul Mundt 	unsigned int nr_windows;
70*2be6bb0cSPaul Mundt 	struct irq_chip chip;
71*2be6bb0cSPaul Mundt };
72*2be6bb0cSPaul Mundt 
73*2be6bb0cSPaul Mundt 
74*2be6bb0cSPaul Mundt enum {
75*2be6bb0cSPaul Mundt 	REG_FN_ERR = 0,
76*2be6bb0cSPaul Mundt 	REG_FN_TEST_BASE = 1,
77*2be6bb0cSPaul Mundt 	REG_FN_WRITE_BASE = 5,
78*2be6bb0cSPaul Mundt 	REG_FN_MODIFY_BASE = 9
79*2be6bb0cSPaul Mundt };
80*2be6bb0cSPaul Mundt 
81*2be6bb0cSPaul Mundt enum {	MODE_ENABLE_REG = 0, /* Bit(s) set -> interrupt enabled */
82*2be6bb0cSPaul Mundt 	MODE_MASK_REG,       /* Bit(s) set -> interrupt disabled */
83*2be6bb0cSPaul Mundt 	MODE_DUAL_REG,       /* Two registers, set bit to enable / disable */
84*2be6bb0cSPaul Mundt 	MODE_PRIO_REG,       /* Priority value written to enable interrupt */
85*2be6bb0cSPaul Mundt 	MODE_PCLR_REG,       /* Above plus all bits set to disable interrupt */
86*2be6bb0cSPaul Mundt };
87*2be6bb0cSPaul Mundt 
88*2be6bb0cSPaul Mundt static inline struct intc_desc_int *get_intc_desc(unsigned int irq)
89*2be6bb0cSPaul Mundt {
90*2be6bb0cSPaul Mundt 	struct irq_chip *chip = get_irq_chip(irq);
91*2be6bb0cSPaul Mundt 
92*2be6bb0cSPaul Mundt 	return container_of(chip, struct intc_desc_int, chip);
93*2be6bb0cSPaul Mundt }
94*2be6bb0cSPaul Mundt 
95*2be6bb0cSPaul Mundt /*
96*2be6bb0cSPaul Mundt  * Grumble.
97*2be6bb0cSPaul Mundt  */
98*2be6bb0cSPaul Mundt static inline void activate_irq(int irq)
99*2be6bb0cSPaul Mundt {
100*2be6bb0cSPaul Mundt #ifdef CONFIG_ARM
101*2be6bb0cSPaul Mundt 	/* ARM requires an extra step to clear IRQ_NOREQUEST, which it
102*2be6bb0cSPaul Mundt 	 * sets on behalf of every irq_chip.  Also sets IRQ_NOPROBE.
103*2be6bb0cSPaul Mundt 	 */
104*2be6bb0cSPaul Mundt 	set_irq_flags(irq, IRQF_VALID);
105*2be6bb0cSPaul Mundt #else
106*2be6bb0cSPaul Mundt 	/* same effect on other architectures */
107*2be6bb0cSPaul Mundt 	set_irq_noprobe(irq);
108*2be6bb0cSPaul Mundt #endif
109*2be6bb0cSPaul Mundt }
110*2be6bb0cSPaul Mundt 
111*2be6bb0cSPaul Mundt /* access.c */
112*2be6bb0cSPaul Mundt extern unsigned long
113*2be6bb0cSPaul Mundt (*intc_reg_fns[])(unsigned long addr, unsigned long h, unsigned long data);
114*2be6bb0cSPaul Mundt 
115*2be6bb0cSPaul Mundt extern unsigned long
116*2be6bb0cSPaul Mundt (*intc_enable_fns[])(unsigned long addr, unsigned long handle,
117*2be6bb0cSPaul Mundt 		     unsigned long (*fn)(unsigned long,
118*2be6bb0cSPaul Mundt 				unsigned long, unsigned long),
119*2be6bb0cSPaul Mundt 		     unsigned int irq);
120*2be6bb0cSPaul Mundt extern unsigned long
121*2be6bb0cSPaul Mundt (*intc_disable_fns[])(unsigned long addr, unsigned long handle,
122*2be6bb0cSPaul Mundt 		      unsigned long (*fn)(unsigned long,
123*2be6bb0cSPaul Mundt 				unsigned long, unsigned long),
124*2be6bb0cSPaul Mundt 		      unsigned int irq);
125*2be6bb0cSPaul Mundt extern unsigned long
126*2be6bb0cSPaul Mundt (*intc_enable_noprio_fns[])(unsigned long addr, unsigned long handle,
127*2be6bb0cSPaul Mundt 		            unsigned long (*fn)(unsigned long,
128*2be6bb0cSPaul Mundt 				unsigned long, unsigned long),
129*2be6bb0cSPaul Mundt 			    unsigned int irq);
130*2be6bb0cSPaul Mundt 
131*2be6bb0cSPaul Mundt unsigned long intc_phys_to_virt(struct intc_desc_int *d, unsigned long address);
132*2be6bb0cSPaul Mundt unsigned int intc_get_reg(struct intc_desc_int *d, unsigned long address);
133*2be6bb0cSPaul Mundt unsigned int intc_set_field_from_handle(unsigned int value,
134*2be6bb0cSPaul Mundt 			    unsigned int field_value,
135*2be6bb0cSPaul Mundt 			    unsigned int handle);
136*2be6bb0cSPaul Mundt unsigned long intc_get_field_from_handle(unsigned int value,
137*2be6bb0cSPaul Mundt 					 unsigned int handle);
138*2be6bb0cSPaul Mundt 
139*2be6bb0cSPaul Mundt /* balancing.c */
140*2be6bb0cSPaul Mundt #ifdef CONFIG_INTC_BALANCING
141*2be6bb0cSPaul Mundt void intc_balancing_enable(unsigned int irq);
142*2be6bb0cSPaul Mundt void intc_balancing_disable(unsigned int irq);
143*2be6bb0cSPaul Mundt void intc_set_dist_handle(unsigned int irq, struct intc_desc *desc,
144*2be6bb0cSPaul Mundt 			  struct intc_desc_int *d, intc_enum id);
145*2be6bb0cSPaul Mundt #else
146*2be6bb0cSPaul Mundt void intc_balancing_enable(unsigned int irq) { }
147*2be6bb0cSPaul Mundt void intc_balancing_disable(unsigned int irq) { }
148*2be6bb0cSPaul Mundt void intc_set_dist_handle(unsigned int irq, struct intc_desc *desc,
149*2be6bb0cSPaul Mundt 			  struct intc_desc_int *d, intc_enum id) { }
150*2be6bb0cSPaul Mundt #endif
151*2be6bb0cSPaul Mundt 
152*2be6bb0cSPaul Mundt /* chip.c */
153*2be6bb0cSPaul Mundt extern struct irq_chip intc_irq_chip;
154*2be6bb0cSPaul Mundt void _intc_enable(unsigned int irq, unsigned long handle);
155*2be6bb0cSPaul Mundt 
156*2be6bb0cSPaul Mundt /* core.c */
157*2be6bb0cSPaul Mundt extern struct list_head intc_list;
158*2be6bb0cSPaul Mundt extern raw_spinlock_t intc_big_lock;
159*2be6bb0cSPaul Mundt extern unsigned int nr_intc_controllers;
160*2be6bb0cSPaul Mundt extern struct sysdev_class intc_sysdev_class;
161*2be6bb0cSPaul Mundt 
162*2be6bb0cSPaul Mundt unsigned int intc_get_dfl_prio_level(void);
163*2be6bb0cSPaul Mundt unsigned int intc_get_prio_level(unsigned int irq);
164*2be6bb0cSPaul Mundt void intc_set_prio_level(unsigned int irq, unsigned int level);
165*2be6bb0cSPaul Mundt 
166*2be6bb0cSPaul Mundt /* handle.c */
167*2be6bb0cSPaul Mundt unsigned int intc_get_mask_handle(struct intc_desc *desc,
168*2be6bb0cSPaul Mundt 				  struct intc_desc_int *d,
169*2be6bb0cSPaul Mundt 				  intc_enum enum_id, int do_grps);
170*2be6bb0cSPaul Mundt unsigned int intc_get_prio_handle(struct intc_desc *desc,
171*2be6bb0cSPaul Mundt 				  struct intc_desc_int *d,
172*2be6bb0cSPaul Mundt 				  intc_enum enum_id, int do_grps);
173*2be6bb0cSPaul Mundt unsigned int intc_get_sense_handle(struct intc_desc *desc,
174*2be6bb0cSPaul Mundt 				   struct intc_desc_int *d,
175*2be6bb0cSPaul Mundt 				   intc_enum enum_id);
176*2be6bb0cSPaul Mundt void intc_set_ack_handle(unsigned int irq, struct intc_desc *desc,
177*2be6bb0cSPaul Mundt 			 struct intc_desc_int *d, intc_enum id);
178*2be6bb0cSPaul Mundt unsigned long intc_get_ack_handle(unsigned int irq);
179*2be6bb0cSPaul Mundt void intc_enable_disable_enum(struct intc_desc *desc, struct intc_desc_int *d,
180*2be6bb0cSPaul Mundt 			      intc_enum enum_id, int enable);
181*2be6bb0cSPaul Mundt 
182*2be6bb0cSPaul Mundt /* virq.c */
183*2be6bb0cSPaul Mundt void intc_subgroup_init(struct intc_desc *desc, struct intc_desc_int *d);
184*2be6bb0cSPaul Mundt void intc_irq_xlate_set(unsigned int irq, intc_enum id, struct intc_desc_int *d);
185*2be6bb0cSPaul Mundt struct intc_map_entry *intc_irq_xlate_get(unsigned int irq);
186